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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import os
6
5 from collections import defaultdict 7 from collections import defaultdict
6 8
7 try: 9 try:
8 import resource # pylint: disable=F0401 10 import resource # pylint: disable=F0401
9 except ImportError: 11 except ImportError:
10 resource = None # Not available on all platforms 12 resource = None # Not available on all platforms
11 13
12 14
13 def _ConvertKbToByte(value): 15 def _ConvertKbToByte(value):
14 return int(value.replace('kB','')) * 1024 16 return int(value.replace('kB','')) * 1024
15 17
16 18
17 def _GetProcFileDict(contents): 19 def _GetProcFileDict(contents):
18 retval = {} 20 retval = {}
19 for line in contents.splitlines(): 21 for line in contents.splitlines():
20 key, value = line.split(':') 22 key, value = line.split(':')
21 retval[key.strip()] = value.strip() 23 retval[key.strip()] = value.strip()
22 return retval 24 return retval
23 25
24 26
25 def GetSystemCommitCharge(meminfo_contents): 27 def GetSystemCommitCharge(meminfo_contents):
26 meminfo = _GetProcFileDict(meminfo_contents) 28 meminfo = _GetProcFileDict(meminfo_contents)
27 return (_ConvertKbToByte(meminfo['MemTotal']) 29 return (_ConvertKbToByte(meminfo['MemTotal'])
28 - _ConvertKbToByte(meminfo['MemFree']) 30 - _ConvertKbToByte(meminfo['MemFree'])
29 - _ConvertKbToByte(meminfo['Buffers']) 31 - _ConvertKbToByte(meminfo['Buffers'])
30 - _ConvertKbToByte(meminfo['Cached'])) 32 - _ConvertKbToByte(meminfo['Cached']))
31 33
32 34
35 def GetCpuStats(uptime, stats, add_children=False):
36 uptime = float(uptime[0])
37 utime = float(stats[13])
38 stime = float(stats[14])
39 cutime = float(stats[15])
40 cstime = float(stats[16])
41 starttime = float(stats[21])
42 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
43
44 cpu_process_time = utime + stime
45 if add_children:
46 cpu_process_time += cutime + cstime
47 cpu_process_time_secs = cpu_process_time / hertz
48 total_time_secs = uptime - (starttime / hertz)
49
50 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?
51 'CpuProcessTime': cpu_process_time_secs,
52 'ElapsedTotalTime': total_time_secs}
53
54
33 def GetMemoryStats(status_contents, stats): 55 def GetMemoryStats(status_contents, stats):
34 status = _GetProcFileDict(status_contents) 56 status = _GetProcFileDict(status_contents)
35 if not status or not stats or 'Z' in status['State']: 57 if not status or not stats or 'Z' in status['State']:
36 return {} 58 return {}
37 return {'VM': int(stats[22]), 59 return {'VM': int(stats[22]),
38 'VMPeak': _ConvertKbToByte(status['VmPeak']), 60 'VMPeak': _ConvertKbToByte(status['VmPeak']),
39 'WorkingSetSize': int(stats[23]) * resource.getpagesize(), 61 'WorkingSetSize': int(stats[23]) * resource.getpagesize(),
40 'WorkingSetSizePeak': _ConvertKbToByte(status['VmHWM'])} 62 'WorkingSetSizePeak': _ConvertKbToByte(status['VmHWM'])}
41 63
42 64
(...skipping 13 matching lines...) Expand all
56 child_dict[int(curr_ppid)].append(int(curr_pid)) 78 child_dict[int(curr_ppid)].append(int(curr_pid))
57 queue = [pid] 79 queue = [pid]
58 child_ids = [] 80 child_ids = []
59 while queue: 81 while queue:
60 parent = queue.pop() 82 parent = queue.pop()
61 if parent in child_dict: 83 if parent in child_dict:
62 children = child_dict[parent] 84 children = child_dict[parent]
63 queue.extend(children) 85 queue.extend(children)
64 child_ids.extend(children) 86 child_ids.extend(children)
65 return child_ids 87 return child_ids
OLDNEW
« 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