Index: tools/telemetry/telemetry/core/platform/proc_util.py |
diff --git a/tools/telemetry/telemetry/core/platform/proc_util.py b/tools/telemetry/telemetry/core/platform/proc_util.py |
index 656eb846996b227b9d864798f4793191f2134b15..c337cecb47a4a7609ceff705bd1a1af889ccf60d 100644 |
--- a/tools/telemetry/telemetry/core/platform/proc_util.py |
+++ b/tools/telemetry/telemetry/core/platform/proc_util.py |
@@ -2,6 +2,8 @@ |
# Use of this source code is governed by a BSD-style license that can be |
# found in the LICENSE file. |
+import os |
+ |
from collections import defaultdict |
try: |
@@ -30,6 +32,26 @@ def GetSystemCommitCharge(meminfo_contents): |
- _ConvertKbToByte(meminfo['Cached'])) |
+def GetCpuStats(uptime, stats, add_children=False): |
+ uptime = float(uptime[0]) |
+ utime = float(stats[13]) |
+ stime = float(stats[14]) |
+ cutime = float(stats[15]) |
+ cstime = float(stats[16]) |
+ starttime = float(stats[21]) |
+ hertz = float(os.sysconf(os.sysconf_names['SC_CLK_TCK'])) or 100 |
tonyg
2013/09/05 15:20:14
Is there a way we can get the clock tick from proc
edmundyan
2013/09/05 18:11:19
From some googling, not easily. Atleast there is
|
+ |
+ cpu_process_time = utime + stime |
+ if add_children: |
+ cpu_process_time += cutime + cstime |
+ cpu_process_time_secs = cpu_process_time / hertz |
+ total_time_secs = uptime - (starttime / hertz) |
+ |
+ return {'CpuPercent': 100 * cpu_process_time_secs / total_time_secs, |
tonyg
2013/09/05 15:20:14
I don't think we should include this line because
edmundyan
2013/09/05 18:11:19
Shall we remove the browser unittest then?
|
+ 'CpuProcessTime': cpu_process_time_secs, |
+ 'ElapsedTotalTime': total_time_secs} |
+ |
+ |
def GetMemoryStats(status_contents, stats): |
status = _GetProcFileDict(status_contents) |
if not status or not stats or 'Z' in status['State']: |