Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / core / platform / platform_backend.py
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.
4
5 import weakref
6
7 from telemetry.core.platform import tracing_controller_backend
8
9
10 # pylint: disable=W0613
11
12 # pylint: disable=W0212
13 class OSVersion(str):
14   def __new__(cls, friendly_name, sortable_name, *args, **kwargs):
15     version = str.__new__(cls, friendly_name)
16     version._sortable_name = sortable_name
17     return version
18
19   def __lt__(self, other):
20     return self._sortable_name < other._sortable_name
21
22   def __gt__(self, other):
23     return self._sortable_name > other._sortable_name
24
25   def __le__(self, other):
26     return self._sortable_name <= other._sortable_name
27
28   def __ge__(self, other):
29     return self._sortable_name >= other._sortable_name
30
31
32 XP =           OSVersion('xp',            5.1)
33 VISTA =        OSVersion('vista',         6.0)
34 WIN7 =         OSVersion('win7',          6.1)
35 WIN8 =         OSVersion('win8',          6.2)
36
37 LEOPARD =      OSVersion('leopard',      10.5)
38 SNOWLEOPARD =  OSVersion('snowleopard',  10.6)
39 LION =         OSVersion('lion',         10.7)
40 MOUNTAINLION = OSVersion('mountainlion', 10.8)
41 MAVERICKS =    OSVersion('mavericks',    10.9)
42
43
44 class PlatformBackend(object):
45   def __init__(self):
46     self._platform = None
47     self._running_browser_backends = weakref.WeakSet()
48     self._tracing_controller_backend = \
49         tracing_controller_backend.TracingControllerBackend(self)
50
51   def SetPlatform(self, platform):
52     assert self._platform == None
53     self._platform = platform
54
55   @property
56   def platform(self):
57     return self._platform
58
59   @property
60   def running_browser_backends(self):
61     return list(self._running_browser_backends)
62
63   @property
64   def tracing_controller_backend(self):
65     return self._tracing_controller_backend
66
67   def DidCreateBrowser(self, browser, browser_backend):
68     self.SetFullPerformanceModeEnabled(True)
69
70   def DidStartBrowser(self, browser, browser_backend):
71     assert browser not in self._running_browser_backends
72     self._running_browser_backends.add(browser_backend)
73     self._tracing_controller_backend.DidStartBrowser(
74         browser, browser_backend)
75
76   def WillCloseBrowser(self, browser, browser_backend):
77     self._tracing_controller_backend.WillCloseBrowser(
78         browser, browser_backend)
79
80     is_last_browser = len(self._running_browser_backends) == 1
81     if is_last_browser:
82       self.SetFullPerformanceModeEnabled(False)
83
84     self._running_browser_backends.remove(browser_backend)
85
86   def GetBackendForBrowser(self, browser):
87     matches = [x for x in self._running_browser_backends
88                if x.browser == browser]
89     if len(matches) == 0:
90       raise Exception('No browser found')
91     assert len(matches) == 1
92     return matches[0]
93
94   def IsRawDisplayFrameRateSupported(self):
95     return False
96
97   def StartRawDisplayFrameRateMeasurement(self):
98     raise NotImplementedError()
99
100   def StopRawDisplayFrameRateMeasurement(self):
101     raise NotImplementedError()
102
103   def GetRawDisplayFrameRateMeasurements(self):
104     raise NotImplementedError()
105
106   def SetFullPerformanceModeEnabled(self, enabled):
107     pass
108
109   def CanMonitorThermalThrottling(self):
110     return False
111
112   def IsThermallyThrottled(self):
113     raise NotImplementedError()
114
115   def HasBeenThermallyThrottled(self):
116     raise NotImplementedError()
117
118   def GetSystemCommitCharge(self):
119     raise NotImplementedError()
120
121   def GetSystemTotalPhysicalMemory(self):
122     raise NotImplementedError()
123
124   def GetCpuStats(self, pid):
125     return {}
126
127   def GetCpuTimestamp(self):
128     return {}
129
130   def PurgeUnpinnedMemory(self):
131     pass
132
133   def GetMemoryStats(self, pid):
134     return {}
135
136   def GetIOStats(self, pid):
137     return {}
138
139   def GetChildPids(self, pid):
140     raise NotImplementedError()
141
142   def GetCommandLine(self, pid):
143     raise NotImplementedError()
144
145   def GetOSName(self):
146     raise NotImplementedError()
147
148   def GetOSVersionName(self):
149     raise NotImplementedError()
150
151   def CanFlushIndividualFilesFromSystemCache(self):
152     raise NotImplementedError()
153
154   def FlushEntireSystemCache(self):
155     raise NotImplementedError()
156
157   def FlushSystemCacheForDirectory(self, directory, ignoring=None):
158     raise NotImplementedError()
159
160   def FlushDnsCache(self):
161     pass
162
163   def LaunchApplication(
164       self, application, parameters=None, elevate_privilege=False):
165     raise NotImplementedError()
166
167   def IsApplicationRunning(self, application):
168     raise NotImplementedError()
169
170   def CanLaunchApplication(self, application):
171     return False
172
173   def InstallApplication(self, application):
174     raise NotImplementedError()
175
176   def CanCaptureVideo(self):
177     return False
178
179   def StartVideoCapture(self, min_bitrate_mbps):
180     raise NotImplementedError()
181
182   @property
183   def is_video_capture_running(self):
184     return False
185
186   def StopVideoCapture(self):
187     raise NotImplementedError()
188
189   def CanMonitorPower(self):
190     return False
191
192   def CanMeasurePerApplicationPower(self):
193     return False
194
195   def StartMonitoringPower(self, browser):
196     raise NotImplementedError()
197
198   def StopMonitoringPower(self):
199     raise NotImplementedError()