class LinuxBasedPlatformBackend(platform_backend.PlatformBackend):
- """Abstract platform containing functionality shared by all linux based OSes.
+ """Abstract platform containing functionality shared by all Linux based OSes.
+
+ This includes Android and ChromeOS.
Subclasses must implement RunCommand, GetFileContents, GetPsOutput, and
ParseCStateSample."""
return self._ConvertKbToByte(meminfo['MemTotal'])
def GetCpuStats(self, pid):
+ results = {}
stats = self._GetProcFileForPid(pid, 'stat')
if not stats:
- return {}
+ return results
stats = stats.split()
utime = float(stats[13])
stime = float(stats[14])
cpu_process_jiffies = utime + stime
- return {'CpuProcessTime': cpu_process_jiffies}
+ clock_ticks = self.GetClockTicks()
+ results.update({'CpuProcessTime': cpu_process_jiffies / clock_ticks})
+ return results
def GetCpuTimestamp(self):
timer_list = self.GetFileContents('/proc/timer_list')
total_jiffies = float(self._GetProcJiffies(timer_list))
- return {'TotalTime': total_jiffies}
+ clock_ticks = self.GetClockTicks()
+ return {'TotalTime': total_jiffies / clock_ticks}
def GetMemoryStats(self, pid):
status_contents = self._GetProcFileForPid(pid, 'status')
'ReadTransferCount': int(io['rchar']),
'WriteTransferCount': int(io['wchar'])}
+ @decorators.Cache
+ def GetClockTicks(self):
+ """Returns the number of clock ticks per second.
+
+ The proper way is to call os.sysconf('SC_CLK_TCK') but that is not easy to
+ do on Android/CrOS. In practice, nearly all Linux machines have a USER_HZ
+ of 100, so just return that.
+ """
+ return 100
+
def GetFileContents(self, filename):
raise NotImplementedError()