- add sources.
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / core / platform / cros_platform_backend.py
1 # Copyright (c) 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 platform_backend
6 from telemetry.core.platform import proc_util
7
8
9 class CrosPlatformBackend(platform_backend.PlatformBackend):
10
11   def __init__(self, cri):
12     super(CrosPlatformBackend, self).__init__()
13     self._cri = cri
14
15   def StartRawDisplayFrameRateMeasurement(self):
16     raise NotImplementedError()
17
18   def StopRawDisplayFrameRateMeasurement(self):
19     raise NotImplementedError()
20
21   def GetRawDisplayFrameRateMeasurements(self):
22     raise NotImplementedError()
23
24   def IsThermallyThrottled(self):
25     raise NotImplementedError()
26
27   def HasBeenThermallyThrottled(self):
28     raise NotImplementedError()
29
30   def _RunCommand(self, args):
31     return self._cri.RunCmdOnDevice(args)[0]
32
33   def _GetFileContents(self, filename):
34     try:
35       return self._cri.RunCmdOnDevice(['cat', filename])[0]
36     except AssertionError:
37       return ''
38
39   def GetSystemCommitCharge(self):
40     meminfo_contents = self._GetFileContents('/proc/meminfo')
41     return proc_util.GetSystemCommitCharge(meminfo_contents)
42
43   def GetCpuStats(self, pid):
44     stats = self._GetFileContents('/proc/%s/stat' % pid).split()
45     return proc_util.GetCpuStats(stats)
46
47   def GetCpuTimestamp(self):
48     timer_list = self._GetFileContents('/proc/timer_list')
49     return proc_util.GetTimestampJiffies(timer_list)
50
51   def GetMemoryStats(self, pid):
52     status = self._GetFileContents('/proc/%s/status' % pid)
53     stats = self._GetFileContents('/proc/%s/stat' % pid).split()
54     return proc_util.GetMemoryStats(status, stats)
55
56   def GetIOStats(self, pid):
57     # There is no '/proc/<pid>/io' file on CrOS platforms
58     # Returns empty dict as it does in PlatformBackend.
59     return {}
60
61   def GetOSName(self):
62     return 'chromeos'
63
64   def GetChildPids(self, pid):
65     """Returns a list of child pids of |pid|."""
66     all_process_info = self._cri.ListProcesses()
67     processes = [(curr_pid, curr_ppid, curr_state)
68                  for curr_pid, _, curr_ppid, curr_state in all_process_info]
69     return proc_util.GetChildPids(processes, pid)
70
71   def GetCommandLine(self, pid):
72     command = self._GetFileContents('/proc/%s/cmdline' % pid)
73     return command if command else None
74
75   def CanFlushIndividualFilesFromSystemCache(self):
76     return True
77
78   def FlushEntireSystemCache(self):
79     raise NotImplementedError()
80
81   def FlushSystemCacheForDirectory(self, directory, ignoring=None):
82     raise NotImplementedError()