OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import logging | 5 import logging |
6 import platform | 6 import platform |
7 import re | 7 import re |
8 | 8 |
9 from telemetry import decorators | 9 from telemetry import decorators |
10 from telemetry.internal.platform import power_monitor | 10 from telemetry.internal.platform import power_monitor |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 89 |
90 if self._TemperatureCelsius() <= 0: | 90 if self._TemperatureCelsius() <= 0: |
91 logging.info('Cannot monitor power: no temperature readings.') | 91 logging.info('Cannot monitor power: no temperature readings.') |
92 return False | 92 return False |
93 except OSError as e: | 93 except OSError as e: |
94 logging.info('Cannot monitor power: %s' % e) | 94 logging.info('Cannot monitor power: %s' % e) |
95 return False | 95 return False |
96 return True | 96 return True |
97 | 97 |
98 | 98 |
99 class MsrPowerMonitorLinux(MsrPowerMonitor): | |
100 def CanMonitorPower(self): | |
101 vendor = None | |
102 family = None | |
103 model = None | |
104 cpuinfo = open('/proc/cpuinfo').read().splitlines() | |
105 for line in cpuinfo: | |
106 if vendor and family and model: | |
107 break | |
108 if line.startswith('vendor_id'): | |
109 vendor = line.split('\t')[1] | |
110 elif line.startswith('cpu family'): | |
111 family = int(line.split(' ')[2]) | |
112 elif line.startswith('model\t\t'): | |
113 model = int(line.split(' ')[1]) | |
114 if not _IsSandyBridgeOrLater(vendor, family, model): | |
115 logging.info('Cannot monitor power: pre-Sandy Bridge CPU.') | |
116 return False | |
117 | |
118 if not self._CheckMSRs(): | |
119 logging.info('Try running tools/telemetry/build/linux_setup_msr.py.') | |
120 return False | |
121 | |
122 return True | |
123 | |
124 | |
125 class MsrPowerMonitorWin(MsrPowerMonitor): | 99 class MsrPowerMonitorWin(MsrPowerMonitor): |
126 def CanMonitorPower(self): | 100 def CanMonitorPower(self): |
127 family, model = map(int, re.match( | 101 family, model = map(int, re.match( |
128 '.+ Family ([0-9]+) Model ([0-9]+)', | 102 '.+ Family ([0-9]+) Model ([0-9]+)', |
129 platform.processor()).groups()) | 103 platform.processor()).groups()) |
130 if not _IsSandyBridgeOrLater(platform.processor(), family, model): | 104 if not _IsSandyBridgeOrLater(platform.processor(), family, model): |
131 logging.info('Cannot monitor power: pre-Sandy Bridge CPU.') | 105 logging.info('Cannot monitor power: pre-Sandy Bridge CPU.') |
132 return False | 106 return False |
133 | 107 |
134 try: | 108 try: |
135 return self._CheckMSRs() | 109 return self._CheckMSRs() |
136 finally: | 110 finally: |
137 # Since _CheckMSRs() starts the MSR server on win platform, we must close | 111 # Since _CheckMSRs() starts the MSR server on win platform, we must close |
138 # it after checking to avoid leaking msr server process. | 112 # it after checking to avoid leaking msr server process. |
139 self._backend.CloseMsrServer() | 113 self._backend.CloseMsrServer() |
140 | 114 |
141 def StopMonitoringPower(self): | 115 def StopMonitoringPower(self): |
142 power_statistics = super(MsrPowerMonitorWin, self).StopMonitoringPower() | 116 power_statistics = super(MsrPowerMonitorWin, self).StopMonitoringPower() |
143 self._backend.CloseMsrServer() | 117 self._backend.CloseMsrServer() |
144 return power_statistics | 118 return power_statistics |
OLD | NEW |