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

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: Finalize jiffies. Remove unittests 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
« no previous file with comments | « tools/telemetry/telemetry/core/platform/platform_backend.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 from collections import defaultdict 5 from collections import defaultdict
6 6
7 try: 7 try:
8 import resource # pylint: disable=F0401 8 import resource # pylint: disable=F0401
9 except ImportError: 9 except ImportError:
10 resource = None # Not available on all platforms 10 resource = None # Not available on all platforms
11 11
12 12
13 def _ConvertKbToByte(value): 13 def _ConvertKbToByte(value):
14 return int(value.replace('kB','')) * 1024 14 return int(value.replace('kB','')) * 1024
15 15
16 16
17 def _GetProcFileDict(contents): 17 def _GetProcFileDict(contents):
18 retval = {} 18 retval = {}
19 for line in contents.splitlines(): 19 for line in contents.splitlines():
20 key, value = line.split(':') 20 key, value = line.split(':')
21 retval[key.strip()] = value.strip() 21 retval[key.strip()] = value.strip()
22 return retval 22 return retval
23 23
24 24
25 def _GetProcJiffies(timer_list):
26 """Parse '/proc/timer_list' output and returns the first jiffies attribute.
27
28 Multi-CPU machines will have multiple 'jiffies:' lines, all of which will be
29 essentially the same. Return the first one."""
30 for line in timer_list.splitlines():
31 if line.startswith('jiffies:'):
32 _, value = line.split(':')
33 return value
34 return 0
tonyg 2013/09/06 17:42:15 Should this raise?
edmundyan 2013/09/06 21:24:51 Done.
35
36
25 def GetSystemCommitCharge(meminfo_contents): 37 def GetSystemCommitCharge(meminfo_contents):
26 meminfo = _GetProcFileDict(meminfo_contents) 38 meminfo = _GetProcFileDict(meminfo_contents)
27 return (_ConvertKbToByte(meminfo['MemTotal']) 39 return (_ConvertKbToByte(meminfo['MemTotal'])
28 - _ConvertKbToByte(meminfo['MemFree']) 40 - _ConvertKbToByte(meminfo['MemFree'])
29 - _ConvertKbToByte(meminfo['Buffers']) 41 - _ConvertKbToByte(meminfo['Buffers'])
30 - _ConvertKbToByte(meminfo['Cached'])) 42 - _ConvertKbToByte(meminfo['Cached']))
31 43
32 44
45 def GetCpuStats(timer_list, stats, add_children=False):
46 utime = float(stats[13])
47 stime = float(stats[14])
48 cutime = float(stats[15])
49 cstime = float(stats[16])
50 total_jiffies = float(_GetProcJiffies(timer_list))
51
52 cpu_process_jiffies = utime + stime
53 if add_children:
54 cpu_process_jiffies += cutime + cstime
55
56 return {'CpuProcessTime': cpu_process_jiffies,
57 'TotalTime': total_jiffies}
58
59
33 def GetMemoryStats(status_contents, stats): 60 def GetMemoryStats(status_contents, stats):
34 status = _GetProcFileDict(status_contents) 61 status = _GetProcFileDict(status_contents)
35 if not status or not stats or 'Z' in status['State']: 62 if not status or not stats or 'Z' in status['State']:
36 return {} 63 return {}
37 return {'VM': int(stats[22]), 64 return {'VM': int(stats[22]),
38 'VMPeak': _ConvertKbToByte(status['VmPeak']), 65 'VMPeak': _ConvertKbToByte(status['VmPeak']),
39 'WorkingSetSize': int(stats[23]) * resource.getpagesize(), 66 'WorkingSetSize': int(stats[23]) * resource.getpagesize(),
40 'WorkingSetSizePeak': _ConvertKbToByte(status['VmHWM'])} 67 'WorkingSetSizePeak': _ConvertKbToByte(status['VmHWM'])}
41 68
42 69
(...skipping 13 matching lines...) Expand all
56 child_dict[int(curr_ppid)].append(int(curr_pid)) 83 child_dict[int(curr_ppid)].append(int(curr_pid))
57 queue = [pid] 84 queue = [pid]
58 child_ids = [] 85 child_ids = []
59 while queue: 86 while queue:
60 parent = queue.pop() 87 parent = queue.pop()
61 if parent in child_dict: 88 if parent in child_dict:
62 children = child_dict[parent] 89 children = child_dict[parent]
63 queue.extend(children) 90 queue.extend(children)
64 child_ids.extend(children) 91 child_ids.extend(children)
65 return child_ids 92 return child_ids
OLDNEW
« no previous file with comments | « tools/telemetry/telemetry/core/platform/platform_backend.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698