Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Unified Diff: tools/telemetry/telemetry/core/platform/linux_based_platform_backend.py

Issue 684713003: Telemetry: Linux-based backends should return CPU results in seconds, not jiffies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add comment Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 cb031755c3588b3880e3f069b014bb2a0fb95d8f..ca819a5a45c5c6a2979ea9ead1aac2709c58ecf2 100644
--- a/tools/telemetry/telemetry/core/platform/linux_based_platform_backend.py
+++ b/tools/telemetry/telemetry/core/platform/linux_based_platform_backend.py
@@ -7,6 +7,7 @@ try:
except ImportError:
resource = None # Not available on all platforms
+import os
from telemetry import decorators
from telemetry.core import exceptions
from telemetry.core.platform import platform_backend
@@ -14,7 +15,9 @@ from telemetry.core.platform import platform_backend
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."""
@@ -38,19 +41,23 @@ class LinuxBasedPlatformBackend(platform_backend.PlatformBackend):
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')
@@ -84,6 +91,11 @@ class LinuxBasedPlatformBackend(platform_backend.PlatformBackend):
'ReadTransferCount': int(io['rchar']),
'WriteTransferCount': int(io['wchar'])}
+ @decorators.Cache
+ def GetClockTicks(self):
+ """Returns the number of clock ticks per second. It is never 0."""
+ return os.sysconf('SC_CLK_TCK')
+
def GetFileContents(self, filename):
raise NotImplementedError()

Powered by Google App Engine
This is Rietveld 408576698