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 network_controller_backend
8 from telemetry.core.platform import profiling_controller_backend
9 from telemetry.core.platform import tracing_controller_backend
12 # pylint: disable=W0613
14 # pylint: disable=W0212
16 def __new__(cls, friendly_name, sortable_name, *args, **kwargs):
17 version = str.__new__(cls, friendly_name)
18 version._sortable_name = sortable_name
21 def __lt__(self, other):
22 return self._sortable_name < other._sortable_name
24 def __gt__(self, other):
25 return self._sortable_name > other._sortable_name
27 def __le__(self, other):
28 return self._sortable_name <= other._sortable_name
30 def __ge__(self, other):
31 return self._sortable_name >= other._sortable_name
34 XP = OSVersion('xp', 5.1)
35 VISTA = OSVersion('vista', 6.0)
36 WIN7 = OSVersion('win7', 6.1)
37 WIN8 = OSVersion('win8', 6.2)
39 LEOPARD = OSVersion('leopard', 105)
40 SNOWLEOPARD = OSVersion('snowleopard', 106)
41 LION = OSVersion('lion', 107)
42 MOUNTAINLION = OSVersion('mountainlion', 108)
43 MAVERICKS = OSVersion('mavericks', 109)
44 YOSEMITE = OSVersion('yosemite', 1010)
47 class PlatformBackend(object):
49 def __init__(self, device=None):
50 """ Initalize an instance of PlatformBackend from a device optionally.
51 Call sites need to use SupportsDevice before intialization to check
52 whether this platform backend supports the device.
53 If device is None, this constructor returns the host platform backend
54 which telemetry is running on.
57 device: an instance of telemetry.core.platform.device.Device.
59 if device and not self.SupportsDevice(device):
60 raise ValueError('Unsupported device: %s' % device.name)
62 self._running_browser_backends = weakref.WeakSet()
63 self._network_controller_backend = (
64 network_controller_backend.NetworkControllerBackend(self))
65 self._tracing_controller_backend = (
66 tracing_controller_backend.TracingControllerBackend(self))
67 self._profiling_controller_backend = (
68 profiling_controller_backend.ProfilingControllerBackend(self))
71 def SupportsDevice(cls, device):
72 """ Returns whether this platform backend supports intialization from the
76 def SetPlatform(self, platform):
77 assert self._platform == None
78 self._platform = platform
85 def running_browser_backends(self):
86 return list(self._running_browser_backends)
89 def network_controller_backend(self):
90 return self._network_controller_backend
93 def tracing_controller_backend(self):
94 return self._tracing_controller_backend
97 def profiling_controller_backend(self):
98 return self._profiling_controller_backend
100 def DidCreateBrowser(self, browser, browser_backend):
101 self.SetFullPerformanceModeEnabled(True)
103 # TODO(slamm): Remove this call when replay browser_backend dependencies
104 # get moved to platform. https://crbug.com/423962
105 self._network_controller_backend.UpdateReplay(browser_backend)
107 def DidStartBrowser(self, browser, browser_backend):
108 assert browser not in self._running_browser_backends
109 self._running_browser_backends.add(browser_backend)
110 self._tracing_controller_backend.DidStartBrowser(
111 browser, browser_backend)
113 def WillCloseBrowser(self, browser, browser_backend):
114 self._tracing_controller_backend.WillCloseBrowser(
115 browser, browser_backend)
116 self._profiling_controller_backend.WillCloseBrowser(
118 # TODO(slamm): Move this call when replay's life cycle is no longer
119 # tied to the browser. https://crbug.com/424777
120 self._network_controller_backend.StopReplay()
122 is_last_browser = len(self._running_browser_backends) == 1
124 self.SetFullPerformanceModeEnabled(False)
126 self._running_browser_backends.remove(browser_backend)
128 def GetBackendForBrowser(self, browser):
129 matches = [x for x in self._running_browser_backends
130 if x.browser == browser]
131 if len(matches) == 0:
132 raise Exception('No browser found')
133 assert len(matches) == 1
136 def IsRawDisplayFrameRateSupported(self):
139 def StartRawDisplayFrameRateMeasurement(self):
140 raise NotImplementedError()
142 def StopRawDisplayFrameRateMeasurement(self):
143 raise NotImplementedError()
145 def GetRawDisplayFrameRateMeasurements(self):
146 raise NotImplementedError()
148 def SetFullPerformanceModeEnabled(self, enabled):
151 def CanMonitorThermalThrottling(self):
154 def IsThermallyThrottled(self):
155 raise NotImplementedError()
157 def HasBeenThermallyThrottled(self):
158 raise NotImplementedError()
160 def GetSystemCommitCharge(self):
161 raise NotImplementedError()
163 def GetSystemTotalPhysicalMemory(self):
164 raise NotImplementedError()
166 def GetCpuStats(self, pid):
169 def GetCpuTimestamp(self):
172 def PurgeUnpinnedMemory(self):
175 def GetMemoryStats(self, pid):
178 def GetIOStats(self, pid):
181 def GetChildPids(self, pid):
182 raise NotImplementedError()
184 def GetCommandLine(self, pid):
185 raise NotImplementedError()
187 def GetArchName(self):
188 raise NotImplementedError()
191 raise NotImplementedError()
193 def GetOSVersionName(self):
194 raise NotImplementedError()
196 def CanFlushIndividualFilesFromSystemCache(self):
197 raise NotImplementedError()
199 def FlushEntireSystemCache(self):
200 raise NotImplementedError()
202 def FlushSystemCacheForDirectory(self, directory, ignoring=None):
203 raise NotImplementedError()
205 def FlushDnsCache(self):
208 def LaunchApplication(
209 self, application, parameters=None, elevate_privilege=False):
210 raise NotImplementedError()
212 def IsApplicationRunning(self, application):
213 raise NotImplementedError()
215 def CanLaunchApplication(self, application):
218 def InstallApplication(self, application):
219 raise NotImplementedError()
221 def CanCaptureVideo(self):
224 def StartVideoCapture(self, min_bitrate_mbps):
225 raise NotImplementedError()
228 def is_video_capture_running(self):
231 def StopVideoCapture(self):
232 raise NotImplementedError()
234 def CanMonitorPower(self):
237 def CanMeasurePerApplicationPower(self):
240 def StartMonitoringPower(self, browser):
241 raise NotImplementedError()
243 def StopMonitoringPower(self):
244 raise NotImplementedError()
246 def ReadMsr(self, msr_number, start=0, length=64):
247 """Read a CPU model-specific register (MSR).
249 Which MSRs are available depends on the CPU model.
250 On systems with multiple CPUs, this function may run on any CPU.
253 msr_number: The number of the register to read.
254 start: The least significant bit to read, zero-indexed.
255 (Said another way, the number of bits to right-shift the MSR value.)
256 length: The number of bits to read. MSRs are 64 bits, even on 32-bit CPUs.
258 raise NotImplementedError()