Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / core / platform / cros_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 from telemetry.core.platform import proc_supporting_platform_backend
6 from telemetry.core.platform import ps_util
7 from telemetry.core.platform.power_monitor import cros_power_monitor
8
9
10 class CrosPlatformBackend(
11     proc_supporting_platform_backend.ProcSupportingPlatformBackend):
12
13   def __init__(self, cri):
14     super(CrosPlatformBackend, self).__init__()
15     self._cri = cri
16     self._powermonitor = cros_power_monitor.CrosPowerMonitor(cri)
17
18   def StartRawDisplayFrameRateMeasurement(self):
19     raise NotImplementedError()
20
21   def StopRawDisplayFrameRateMeasurement(self):
22     raise NotImplementedError()
23
24   def GetRawDisplayFrameRateMeasurements(self):
25     raise NotImplementedError()
26
27   def IsThermallyThrottled(self):
28     raise NotImplementedError()
29
30   def HasBeenThermallyThrottled(self):
31     raise NotImplementedError()
32
33   def _RunCommand(self, args):
34     return self._cri.RunCmdOnDevice(args)[0]
35
36   def _GetFileContents(self, filename):
37     try:
38       return self._cri.RunCmdOnDevice(['cat', filename])[0]
39     except AssertionError:
40       return ''
41
42   def GetIOStats(self, pid):
43     # There is no '/proc/<pid>/io' file on CrOS platforms
44     # Returns empty dict as it does in PlatformBackend.
45     return {}
46
47   def GetOSName(self):
48     return 'chromeos'
49
50   def GetOSVersionName(self):
51     return ''  # TODO: Implement this.
52
53   def GetChildPids(self, pid):
54     """Returns a list of child pids of |pid|."""
55     all_process_info = self._cri.ListProcesses()
56     processes = [(curr_pid, curr_ppid, curr_state)
57                  for curr_pid, _, curr_ppid, curr_state in all_process_info]
58     return ps_util.GetChildPids(processes, pid)
59
60   def GetCommandLine(self, pid):
61     procs = self._cri.ListProcesses()
62     return next((proc[1] for proc in procs if proc[0] == pid), None)
63
64   def CanFlushIndividualFilesFromSystemCache(self):
65     return True
66
67   def FlushEntireSystemCache(self):
68     raise NotImplementedError()
69
70   def FlushSystemCacheForDirectory(self, directory, ignoring=None):
71     raise NotImplementedError()
72
73   def CanMonitorPower(self):
74     return self._powermonitor.CanMonitorPower()
75
76   def StartMonitoringPower(self, browser):
77     self._powermonitor.StartMonitoringPower(browser)
78
79   def StopMonitoringPower(self):
80     return self._powermonitor.StopMonitoringPower()