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.
5 from telemetry.core.platform import platform_backend
6 from telemetry.core.platform import proc_util
9 class CrosPlatformBackend(platform_backend.PlatformBackend):
11 def __init__(self, cri):
12 super(CrosPlatformBackend, self).__init__()
15 def StartRawDisplayFrameRateMeasurement(self):
16 raise NotImplementedError()
18 def StopRawDisplayFrameRateMeasurement(self):
19 raise NotImplementedError()
21 def GetRawDisplayFrameRateMeasurements(self):
22 raise NotImplementedError()
24 def IsThermallyThrottled(self):
25 raise NotImplementedError()
27 def HasBeenThermallyThrottled(self):
28 raise NotImplementedError()
30 def _RunCommand(self, args):
31 return self._cri.RunCmdOnDevice(args)[0]
33 def _GetFileContents(self, filename):
35 return self._cri.RunCmdOnDevice(['cat', filename])[0]
36 except AssertionError:
39 def GetSystemCommitCharge(self):
40 meminfo_contents = self._GetFileContents('/proc/meminfo')
41 return proc_util.GetSystemCommitCharge(meminfo_contents)
43 def GetCpuStats(self, pid):
44 stats = self._GetFileContents('/proc/%s/stat' % pid).split()
45 return proc_util.GetCpuStats(stats)
47 def GetCpuTimestamp(self):
48 timer_list = self._GetFileContents('/proc/timer_list')
49 return proc_util.GetTimestampJiffies(timer_list)
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)
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.
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)
71 def GetCommandLine(self, pid):
72 command = self._GetFileContents('/proc/%s/cmdline' % pid)
73 return command if command else None
75 def CanFlushIndividualFilesFromSystemCache(self):
78 def FlushEntireSystemCache(self):
79 raise NotImplementedError()
81 def FlushSystemCacheForDirectory(self, directory, ignoring=None):
82 raise NotImplementedError()