1 # Copyright (c) 2012 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 linux_platform_backend
8 from telemetry.core.platform import mac_platform_backend
9 from telemetry.core.platform import win_platform_backend
11 class Platform(object):
12 """The platform that the target browser is running on.
14 Provides a limited interface to interact with the platform itself, where
15 possible. It's important to note that platforms may not provide a specific
16 API, so check with IsFooBar() for availability.
18 def __init__(self, platform_backend):
19 self._platform_backend = platform_backend
21 def IsRawDisplayFrameRateSupported(self):
22 """Platforms may be able to collect GL surface stats."""
23 return self._platform_backend.IsRawDisplayFrameRateSupported()
25 def StartRawDisplayFrameRateMeasurement(self):
26 """Start measuring GL surface stats."""
27 return self._platform_backend.StartRawDisplayFrameRateMeasurement()
29 def StopRawDisplayFrameRateMeasurement(self):
30 """Stop measuring GL surface stats."""
31 return self._platform_backend.StopRawDisplayFrameRateMeasurement()
33 class RawDisplayFrameRateMeasurement(object):
34 def __init__(self, name, value, unit):
51 def GetRawDisplayFrameRateMeasurements(self):
52 """Returns a list of RawDisplayFrameRateMeasurement."""
53 return self._platform_backend.GetRawDisplayFrameRateMeasurements()
55 def SetFullPerformanceModeEnabled(self, enabled):
56 """Platforms may tweak their CPU governor, system status, etc.
58 Most platforms can operate in a battery saving mode. While good for battery
59 life, this can cause confusing performance results and add noise. Turning
60 full performance mode on disables these features, which is useful for
63 return self._platform_backend.SetFullPerformanceModeEnabled(enabled)
65 def CanMonitorThermalThrottling(self):
66 """Platforms may be able to detect thermal throttling.
68 Some fan-less computers go into a reduced performance mode when their heat
69 exceeds a certain threshold. Performance tests in particular should use this
70 API to detect if this has happened and interpret results accordingly.
72 return self._platform_backend.CanMonitorThermalThrottling()
74 def IsThermallyThrottled(self):
75 """Returns True if the device is currently thermally throttled."""
76 return self._platform_backend.IsThermallyThrottled()
78 def HasBeenThermallyThrottled(self):
79 """Returns True if the device has been thermally throttled."""
80 return self._platform_backend.HasBeenThermallyThrottled()
83 """Returns a string description of the Platform OS.
85 Examples: WIN, MAC, LINUX, CHROMEOS"""
86 return self._platform_backend.GetOSName()
88 def GetOSVersionName(self):
89 """Returns a string description of the Platform OS version.
91 Examples: VISTA, WIN7, LION, MOUNTAINLION"""
92 return self._platform_backend.GetOSVersionName()
94 def CanFlushIndividualFilesFromSystemCache(self):
95 """Returns true if the disk cache can be flushed for specific files."""
96 return self._platform_backend.CanFlushIndividualFilesFromSystemCache()
98 def FlushEntireSystemCache(self):
99 """Flushes the OS's file cache completely.
101 This function may require root or administrator access."""
102 return self._platform_backend.FlushEntireSystemCache()
104 def FlushSystemCacheForDirectory(self, directory, ignoring=None):
105 """Flushes the OS's file cache for the specified directory.
107 Any files or directories inside |directory| matching a name in the
108 |ignoring| list will be skipped.
110 This function does not require root or administrator access."""
111 return self._platform_backend.FlushSystemCacheForDirectory(
112 directory, ignoring=ignoring)
114 def LaunchApplication(self, application, parameters=None):
115 """"Launchs a given application on the OS."""
116 return self._platform_backend.LaunchApplication(application,
119 def IsApplicationRunning(self, application):
120 """Returns whether an application is currently running."""
121 return self._platform_backend.IsApplicationLaunchning(application)
123 def CanLaunchApplication(self, application):
124 """Returns whether the platform can launch the given application."""
125 return self._platform_backend.CanLaunchApplication(application)
128 def CreatePlatformBackendForCurrentOS():
129 if sys.platform.startswith('linux'):
130 return linux_platform_backend.LinuxPlatformBackend()
131 elif sys.platform == 'darwin':
132 return mac_platform_backend.MacPlatformBackend()
133 elif sys.platform == 'win32':
134 return win_platform_backend.WinPlatformBackend()
136 raise NotImplementedError()