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

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

Issue 23717016: Add cpu_stats for the browser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Using /proc to get current CPU counters Created 7 years, 3 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/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']:
« no previous file with comments | « tools/telemetry/telemetry/core/platform/platform_backend.py ('k') | tools/telemetry/unittest_data/high_cpu.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698