| Index: tools/telemetry/telemetry/core/platform/linux_based_platform_backend.py
|
| diff --git a/tools/telemetry/telemetry/core/platform/linux_based_platform_backend.py b/tools/telemetry/telemetry/core/platform/linux_based_platform_backend.py
|
| index 9255303fc027f09f22b0b5ab57a2d260e5129150..d595f7ab20aebcef0d636d503f9cf6cd70f30fb4 100644
|
| --- a/tools/telemetry/telemetry/core/platform/linux_based_platform_backend.py
|
| +++ b/tools/telemetry/telemetry/core/platform/linux_based_platform_backend.py
|
| @@ -10,6 +10,7 @@ except ImportError:
|
| from telemetry import decorators
|
| from telemetry.core import exceptions
|
| from telemetry.core.platform import platform_backend
|
| +from telemetry.core.platform import process_statistic_timeline_data
|
|
|
|
|
| class LinuxBasedPlatformBackend(platform_backend.PlatformBackend):
|
| @@ -50,6 +51,8 @@ class LinuxBasedPlatformBackend(platform_backend.PlatformBackend):
|
| cpu_process_jiffies = utime + stime
|
| clock_ticks = self.GetClockTicks()
|
| results.update({'CpuProcessTime': cpu_process_jiffies / clock_ticks})
|
| + if self.CanMeasureIdleWakeUps():
|
| + results.update({'IdleWakeupCount': self._GetIdleWakeupCount(pid)})
|
| return results
|
|
|
| def GetCpuTimestamp(self):
|
| @@ -109,6 +112,12 @@ class LinuxBasedPlatformBackend(platform_backend.PlatformBackend):
|
| def RunCommand(self, cmd):
|
| raise NotImplementedError()
|
|
|
| + def StartMeasuringIdleWakeUps(self):
|
| + self._EnableTimerStatsCollection(True)
|
| +
|
| + def StopMeasuringIdleWakeUps(self):
|
| + self._EnableTimerStatsCollection(False)
|
| +
|
| @staticmethod
|
| def ParseCStateSample(sample):
|
| """Parse a single c-state residency sample.
|
| @@ -129,6 +138,30 @@ class LinuxBasedPlatformBackend(platform_backend.PlatformBackend):
|
| assert pid, 'pid is required'
|
| return bool(self.GetPsOutput(['pid'], pid) == str(pid))
|
|
|
| + def _GetIdleWakeupCount(self, pid):
|
| + """Find the given pid in the timer_stats and sum up the wake-up count.
|
| +
|
| + Each row is in the form of: wake_up_count, pid process_name reason
|
| + Due to possibly multiple reasons, a given pid can appear in multiple rows.
|
| + """
|
| + contents = self.GetFileContents('/proc/timer_stats')
|
| + count = 0
|
| + split_lines = contents.splitlines()
|
| + for line in split_lines[:-1]:
|
| + line_split = line.split(',', 1)
|
| + if len(line_split) < 2:
|
| + continue
|
| + count_str, rest_str = line_split
|
| + current_pid = int(rest_str.strip().split(' ')[0])
|
| + if current_pid == pid:
|
| + count += int(count_str.strip())
|
| + return process_statistic_timeline_data.IdleWakeupTimelineData(pid, count)
|
| +
|
| + def _EnableTimerStatsCollection(self, enable):
|
| + """Writes to /proc/timer_stats to start/stop measuring process wakeups."""
|
| + # TODO(thestig) Implement on Linux and CrOS.
|
| + raise NotImplementedError()
|
| +
|
| def _GetProcFileForPid(self, pid, filename):
|
| try:
|
| return self.GetFileContents('/proc/%s/%s' % (pid, filename))
|
|
|