OLD | NEW |
---|---|
1 # Copyright 2012 The Chromium Authors. All rights reserved. | 1 # Copyright 2012 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 from telemetry.core.platform import factory | 5 import sys |
6 | 6 |
7 def _CreateHostPlatformBackend(): | |
8 if sys.platform.startswith('linux'): | |
9 from telemetry.core.platform import linux_platform_backend | |
10 return linux_platform_backend.LinuxPlatformBackend() | |
11 elif sys.platform == 'darwin': | |
12 from telemetry.core.platform import mac_platform_backend | |
13 return mac_platform_backend.MacPlatformBackend() | |
14 elif sys.platform == 'win32': | |
15 from telemetry.core.platform import win_platform_backend | |
16 return win_platform_backend.WinPlatformBackend() | |
17 else: | |
18 raise NotImplementedError() | |
19 | |
20 _host_platform = None | |
21 | |
22 def ResetHostPlatformSingleton(): | |
tonyg
2014/08/02 15:58:18
What's the use case for resetting? I can't think o
| |
23 global _host_platform | |
24 if _host_platform: | |
25 _host_platform.Close() | |
26 _host_platform = None | |
27 | |
28 def GetHostPlatformName(): | |
29 if sys.platform.startswith('linux'): | |
30 return 'linux' | |
tonyg
2014/08/02 15:58:18
This ends up duplicating strings from the platform
| |
31 elif sys.platform == 'darwin': | |
32 return 'mac' | |
33 elif sys.platform == 'win32': | |
34 return 'win' | |
35 else: | |
36 raise NotImplementedError() | |
7 | 37 |
8 def GetHostPlatform(): | 38 def GetHostPlatform(): |
9 return Platform(factory.GetPlatformBackendForCurrentOS()) | 39 global _host_platform |
10 | 40 if not _host_platform: |
41 _host_platform = Platform(_CreateHostPlatformBackend()) | |
42 return _host_platform | |
11 | 43 |
12 class Platform(object): | 44 class Platform(object): |
13 """The platform that the target browser is running on. | 45 """The platform that the target browser is running on. |
14 | 46 |
15 Provides a limited interface to interact with the platform itself, where | 47 Provides a limited interface to interact with the platform itself, where |
16 possible. It's important to note that platforms may not provide a specific | 48 possible. It's important to note that platforms may not provide a specific |
17 API, so check with IsFooBar() for availability. | 49 API, so check with IsFooBar() for availability. |
18 """ | 50 """ |
19 def __init__(self, platform_backend): | 51 def __init__(self, platform_backend): |
20 self._platform_backend = platform_backend | 52 self._platform_backend = platform_backend |
53 self._platform_backend.SetPlatform(self) | |
54 | |
55 def Close(self): | |
56 pass | |
21 | 57 |
22 def IsRawDisplayFrameRateSupported(self): | 58 def IsRawDisplayFrameRateSupported(self): |
23 """Platforms may be able to collect GL surface stats.""" | 59 """Platforms may be able to collect GL surface stats.""" |
24 return self._platform_backend.IsRawDisplayFrameRateSupported() | 60 return self._platform_backend.IsRawDisplayFrameRateSupported() |
25 | 61 |
26 def StartRawDisplayFrameRateMeasurement(self): | 62 def StartRawDisplayFrameRateMeasurement(self): |
27 """Start measuring GL surface stats.""" | 63 """Start measuring GL surface stats.""" |
28 return self._platform_backend.StartRawDisplayFrameRateMeasurement() | 64 return self._platform_backend.StartRawDisplayFrameRateMeasurement() |
29 | 65 |
30 def StopRawDisplayFrameRateMeasurement(self): | 66 def StopRawDisplayFrameRateMeasurement(self): |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 'average_temperature_c': c, | 264 'average_temperature_c': c, |
229 | 265 |
230 ... | 266 ... |
231 } | 267 } |
232 | 268 |
233 ... | 269 ... |
234 } | 270 } |
235 } | 271 } |
236 """ | 272 """ |
237 return self._platform_backend.StopMonitoringPower() | 273 return self._platform_backend.StopMonitoringPower() |
274 | |
275 def GetChildPids(self, pid): | |
tonyg
2014/08/02 15:58:18
Isn't this a backendy thing? Are we really exposin
| |
276 return self._platform_backend.GetChildPids(pid) | |
277 | |
278 def GetCommandLine(self, pid): | |
279 return self._platform_backend.GetCommandLine(pid) | |
280 | |
281 def WillGetMemoryStats(self): | |
tonyg
2014/08/02 15:58:18
Seems like another good thing to hide from the API
| |
282 self._platform_backend.PurgeUnpinnedMemory() | |
283 | |
284 def GetMemoryStats(self, pid): | |
285 return self._platform_backend.GetMemoryStats(pid) | |
286 | |
287 def GetSystemCommitCharge(self): | |
288 return self._platform_backend.GetSystemCommitCharge() | |
289 | |
290 def GetSystemTotalPhysicalMemory(self): | |
291 return self._platform_backend.GetSystemTotalPhysicalMemory() | |
292 | |
293 def GetCpuStats(self, pid): | |
294 return self._platform_backend.GetCpuStats(pid) | |
295 | |
296 def GetIOStats(self, pid): | |
297 return self._platform.GetIOStats(pid) | |
298 | |
299 def InstantiateProfiler(self, profiler_class, browser_backend, | |
300 base_output_file, state): | |
301 return profiler_class(browser_backend, self, base_output_file, state) | |
302 | |
303 def WillCloseBrowser(self, browser_backend, profiler_classes): | |
304 for cls in profiler_classes: | |
305 cls.WillCloseBrowser(browser_backend, self._platform_backend) | |
OLD | NEW |