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
3 # found in the LICENSE file.
7 from telemetry.core.platform import profiling_controller_backend
8 from telemetry.core.platform import tracing_controller_backend
11 # pylint: disable=W0613
13 # pylint: disable=W0212
15 def __new__(cls, friendly_name, sortable_name, *args, **kwargs):
16 version = str.__new__(cls, friendly_name)
17 version._sortable_name = sortable_name
20 def __lt__(self, other):
21 return self._sortable_name < other._sortable_name
23 def __gt__(self, other):
24 return self._sortable_name > other._sortable_name
26 def __le__(self, other):
27 return self._sortable_name <= other._sortable_name
29 def __ge__(self, other):
30 return self._sortable_name >= other._sortable_name
33 XP = OSVersion('xp', 5.1)
34 VISTA = OSVersion('vista', 6.0)
35 WIN7 = OSVersion('win7', 6.1)
36 WIN8 = OSVersion('win8', 6.2)
38 LEOPARD = OSVersion('leopard', 105)
39 SNOWLEOPARD = OSVersion('snowleopard', 106)
40 LION = OSVersion('lion', 107)
41 MOUNTAINLION = OSVersion('mountainlion', 108)
42 MAVERICKS = OSVersion('mavericks', 109)
43 YOSEMITE = OSVersion('yosemite', 1010)
46 class PlatformBackend(object):
48 def __init__(self, device=None):
49 """ Initalize an instance of PlatformBackend from a device optionally.
50 Call sites need to use SupportsDevice before intialization to check
51 whether this platform backend supports the device.
52 If device is None, this constructor returns the host platform backend
53 which telemetry is running on.
56 device: an instance of telemetry.core.platform.device.Device.
58 if device and not self.SupportsDevice(device):
59 raise ValueError('Unsupported device: %s' % device.name)
61 self._running_browser_backends = weakref.WeakSet()
62 self._tracing_controller_backend = (
63 tracing_controller_backend.TracingControllerBackend(self))
64 self._profiling_controller_backend = (
65 profiling_controller_backend.ProfilingControllerBackend(self))
68 def SupportsDevice(cls, device):
69 """ Returns whether this platform backend supports intialization from the
73 def SetPlatform(self, platform):
74 assert self._platform == None
75 self._platform = platform
82 def running_browser_backends(self):
83 return list(self._running_browser_backends)
86 def tracing_controller_backend(self):
87 return self._tracing_controller_backend
90 def profiling_controller_backend(self):
91 return self._profiling_controller_backend
93 def DidCreateBrowser(self, browser, browser_backend):
94 self.SetFullPerformanceModeEnabled(True)
96 def DidStartBrowser(self, browser, browser_backend):
97 assert browser not in self._running_browser_backends
98 self._running_browser_backends.add(browser_backend)
99 self._tracing_controller_backend.DidStartBrowser(
100 browser, browser_backend)
102 def WillCloseBrowser(self, browser, browser_backend):
103 self._tracing_controller_backend.WillCloseBrowser(
104 browser, browser_backend)
105 self._profiling_controller_backend.WillCloseBrowser(
108 is_last_browser = len(self._running_browser_backends) == 1
110 self.SetFullPerformanceModeEnabled(False)
112 self._running_browser_backends.remove(browser_backend)
114 def GetBackendForBrowser(self, browser):
115 matches = [x for x in self._running_browser_backends
116 if x.browser == browser]
117 if len(matches) == 0:
118 raise Exception('No browser found')
119 assert len(matches) == 1
122 def IsRawDisplayFrameRateSupported(self):
125 def StartRawDisplayFrameRateMeasurement(self):
126 raise NotImplementedError()
128 def StopRawDisplayFrameRateMeasurement(self):
129 raise NotImplementedError()
131 def GetRawDisplayFrameRateMeasurements(self):
132 raise NotImplementedError()
134 def SetFullPerformanceModeEnabled(self, enabled):
137 def CanMonitorThermalThrottling(self):
140 def IsThermallyThrottled(self):
141 raise NotImplementedError()
143 def HasBeenThermallyThrottled(self):
144 raise NotImplementedError()
146 def GetSystemCommitCharge(self):
147 raise NotImplementedError()
149 def GetSystemTotalPhysicalMemory(self):
150 raise NotImplementedError()
152 def GetCpuStats(self, pid):
155 def GetCpuTimestamp(self):
158 def PurgeUnpinnedMemory(self):
161 def GetMemoryStats(self, pid):
164 def GetIOStats(self, pid):
167 def GetChildPids(self, pid):
168 raise NotImplementedError()
170 def GetCommandLine(self, pid):
171 raise NotImplementedError()
174 raise NotImplementedError()
176 def GetOSVersionName(self):
177 raise NotImplementedError()
179 def CanFlushIndividualFilesFromSystemCache(self):
180 raise NotImplementedError()
182 def FlushEntireSystemCache(self):
183 raise NotImplementedError()
185 def FlushSystemCacheForDirectory(self, directory, ignoring=None):
186 raise NotImplementedError()
188 def FlushDnsCache(self):
191 def LaunchApplication(
192 self, application, parameters=None, elevate_privilege=False):
193 raise NotImplementedError()
195 def IsApplicationRunning(self, application):
196 raise NotImplementedError()
198 def CanLaunchApplication(self, application):
201 def InstallApplication(self, application):
202 raise NotImplementedError()
204 def CanCaptureVideo(self):
207 def StartVideoCapture(self, min_bitrate_mbps):
208 raise NotImplementedError()
211 def is_video_capture_running(self):
214 def StopVideoCapture(self):
215 raise NotImplementedError()
217 def CanMonitorPower(self):
220 def CanMeasurePerApplicationPower(self):
223 def StartMonitoringPower(self, browser):
224 raise NotImplementedError()
226 def StopMonitoringPower(self):
227 raise NotImplementedError()
229 def ReadMsr(self, msr_number, start=0, length=64):
230 """Read a CPU model-specific register (MSR).
232 Which MSRs are available depends on the CPU model.
233 On systems with multiple CPUs, this function may run on any CPU.
236 msr_number: The number of the register to read.
237 start: The least significant bit to read, zero-indexed.
238 (Said another way, the number of bits to right-shift the MSR value.)
239 length: The number of bits to read. MSRs are 64 bits, even on 32-bit CPUs.
241 raise NotImplementedError()