Add cpu_stats for the browser

Implementing linux_backend for now.

BUG=263959

Review URL: https://chromiumcodereview.appspot.com/23717016

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221897 0039d316-1c4b-4281-b951-d872f2087c98
parent 141cb9d8
......@@ -167,6 +167,35 @@ class Browser(object):
self._platform_backend.GetSystemCommitCharge()
return result
@property
def cpu_stats(self):
"""Returns a dict of cpu statistics for the system.
{ 'Browser': {
'CpuProcessTime': S,
'TotalTime': T
},
'Gpu': {
'CpuProcessTime': S,
'TotalTime': T
},
'Renderer': {
'CpuProcessTime': S,
'TotalTime': T
}
}
Any of the above keys may be missing on a per-platform basis.
"""
result = self._GetStatsCommon(self._platform_backend.GetCpuStats)
del result['ProcessCount']
# We want a single time value, not the sum for all processes.
for process_type in result:
# Skip any process_types that are empty
if not len(result[process_type]):
continue
result[process_type].update(self._platform_backend.GetCpuTimestamp())
return result
@property
def io_stats(self):
"""Returns a dict of IO statistics for the browser:
......
......@@ -29,6 +29,14 @@ class LinuxPlatformBackend(posix_platform_backend.PosixPlatformBackend):
meminfo_contents = self._GetFileContents('/proc/meminfo')
return proc_util.GetSystemCommitCharge(meminfo_contents)
def GetCpuStats(self, pid=None):
stats = self._GetFileContents('/proc/%s/stat' % pid).split()
return proc_util.GetCpuStats(stats)
def GetCpuTimestamp(self):
timer_list = self._GetFileContents('/proc/timer_list')
return proc_util.GetTimestampJiffies(timer_list)
def GetMemoryStats(self, pid):
status = self._GetFileContents('/proc/%s/status' % pid)
stats = self._GetFileContents('/proc/%s/stat' % pid).split()
......
......@@ -31,6 +31,12 @@ class PlatformBackend(object):
def GetSystemCommitCharge(self):
raise NotImplementedError()
def GetCpuStats(self, pid): # pylint: disable=W0613
return {}
def GetCpuTimestamp(self): # pylint: disable=W0613
return {}
def GetMemoryStats(self, pid): # pylint: disable=W0613
return {}
......
......@@ -22,6 +22,18 @@ def _GetProcFileDict(contents):
return retval
def _GetProcJiffies(timer_list):
"""Parse '/proc/timer_list' output and returns the first jiffies attribute.
Multi-CPU machines will have multiple 'jiffies:' lines, all of which will be
essentially the same. Return the first one."""
for line in timer_list.splitlines():
if line.startswith('jiffies:'):
_, value = line.split(':')
return value
raise Exception('Unable to find jiffies from /proc/timer_list')
def GetSystemCommitCharge(meminfo_contents):
meminfo = _GetProcFileDict(meminfo_contents)
return (_ConvertKbToByte(meminfo['MemTotal'])
......@@ -30,6 +42,25 @@ def GetSystemCommitCharge(meminfo_contents):
- _ConvertKbToByte(meminfo['Cached']))
def GetCpuStats(stats, add_children=False):
utime = float(stats[13])
stime = float(stats[14])
cutime = float(stats[15])
cstime = float(stats[16])
cpu_process_jiffies = utime + stime
if add_children:
cpu_process_jiffies += cutime + cstime
return {'CpuProcessTime': cpu_process_jiffies}
def GetTimestampJiffies(timer_list):
"""Return timestamp of system in jiffies."""
total_jiffies = float(_GetProcJiffies(timer_list))
return {'TotalTime': total_jiffies}
def GetMemoryStats(status_contents, stats):
status = _GetProcFileDict(status_contents)
if not status or not stats or 'Z' in status['State']:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment