OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 collections | 5 import collections |
6 import ctypes | 6 import ctypes |
7 import platform | 7 import platform |
8 import re | 8 import re |
9 import subprocess | 9 import subprocess |
10 import time | 10 import time |
11 try: | 11 try: |
12 import pywintypes # pylint: disable=F0401 | 12 import pywintypes # pylint: disable=F0401 |
13 import win32api # pylint: disable=F0401 | 13 import win32api # pylint: disable=F0401 |
| 14 from win32com.shell import shell # pylint: disable=F0401 |
| 15 from win32com.shell import shellcon # pylint: disable=F0401 |
14 import win32con # pylint: disable=F0401 | 16 import win32con # pylint: disable=F0401 |
15 import win32process # pylint: disable=F0401 | 17 import win32process # pylint: disable=F0401 |
16 except ImportError: | 18 except ImportError: |
17 pywintypes = None | 19 pywintypes = None |
| 20 shell = None |
| 21 shellcon = None |
18 win32api = None | 22 win32api = None |
19 win32con = None | 23 win32con = None |
20 win32process = None | 24 win32process = None |
21 | 25 |
22 from telemetry import decorators | 26 from telemetry import decorators |
23 from telemetry.core import exceptions | 27 from telemetry.core import exceptions |
24 from telemetry.core.platform import desktop_platform_backend | 28 from telemetry.core.platform import desktop_platform_backend |
25 from telemetry.core.platform import platform_backend | 29 from telemetry.core.platform import platform_backend |
| 30 from telemetry.core.platform.power_monitor import ippet_power_monitor |
26 | 31 |
27 | 32 |
28 class WinPlatformBackend(desktop_platform_backend.DesktopPlatformBackend): | 33 class WinPlatformBackend(desktop_platform_backend.DesktopPlatformBackend): |
| 34 def __init__(self): |
| 35 super(WinPlatformBackend, self).__init__() |
| 36 self._power_monitor = ippet_power_monitor.IppetPowerMonitor(self) |
| 37 |
29 # pylint: disable=W0613 | 38 # pylint: disable=W0613 |
30 def StartRawDisplayFrameRateMeasurement(self): | 39 def StartRawDisplayFrameRateMeasurement(self): |
31 raise NotImplementedError() | 40 raise NotImplementedError() |
32 | 41 |
33 def StopRawDisplayFrameRateMeasurement(self): | 42 def StopRawDisplayFrameRateMeasurement(self): |
34 raise NotImplementedError() | 43 raise NotImplementedError() |
35 | 44 |
36 def GetRawDisplayFrameRateMeasurements(self): | 45 def GetRawDisplayFrameRateMeasurements(self): |
37 raise NotImplementedError() | 46 raise NotImplementedError() |
38 | 47 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 ('ThreadCount', ctypes.c_ulong)] | 203 ('ThreadCount', ctypes.c_ulong)] |
195 | 204 |
196 def __init__(self): | 205 def __init__(self): |
197 self.size = ctypes.sizeof(self) | 206 self.size = ctypes.sizeof(self) |
198 super(PerformanceInfo, self).__init__() | 207 super(PerformanceInfo, self).__init__() |
199 | 208 |
200 performance_info = PerformanceInfo() | 209 performance_info = PerformanceInfo() |
201 ctypes.windll.psapi.GetPerformanceInfo( | 210 ctypes.windll.psapi.GetPerformanceInfo( |
202 ctypes.byref(performance_info), performance_info.size) | 211 ctypes.byref(performance_info), performance_info.size) |
203 return performance_info | 212 return performance_info |
| 213 |
| 214 def LaunchApplication( |
| 215 self, application, parameters=None, elevate_privilege=False): |
| 216 """Launch an application. Returns a PyHANDLE object.""" |
| 217 |
| 218 # Use ShellExecuteEx() instead of subprocess.Popen()/OpenProcess() to |
| 219 # elevate privileges. A new console will be created if the new process has |
| 220 # different permissions than this process. |
| 221 proc_info = shell.ShellExecuteEx( |
| 222 fMask=shellcon.SEE_MASK_NOCLOSEPROCESS | shellcon.SEE_MASK_NO_CONSOLE, |
| 223 lpVerb='runas' if elevate_privilege else '', |
| 224 lpFile=application, |
| 225 lpParameters=' '.join(parameters) if parameters else '', |
| 226 nShow=win32con.SW_HIDE) |
| 227 if proc_info['hInstApp'] <= 32: |
| 228 raise Exception('Unable to launch %s' % application) |
| 229 return proc_info['hProcess'] |
| 230 |
| 231 def CanMonitorPower(self): |
| 232 return self._power_monitor.CanMonitorPower() |
| 233 |
| 234 def CanMeasurePerApplicationPower(self): |
| 235 return self._power_monitor.CanMeasurePerApplicationPower() |
| 236 |
| 237 def StartMonitoringPower(self, browser): |
| 238 self._power_monitor.StartMonitoringPower(browser) |
| 239 |
| 240 def StopMonitoringPower(self): |
| 241 return self._power_monitor.StopMonitoringPower() |
OLD | NEW |