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

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

Issue 20766003: [Telemetry] Add the ability to flush the system file cache to platform. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Simpler Android support Created 7 years, 5 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
new file mode 100644
index 0000000000000000000000000000000000000000..3f9b22b79024302e64f72d41c812afbb982d7054
--- /dev/null
+++ b/tools/telemetry/telemetry/core/platform/proc_util.py
@@ -0,0 +1,42 @@
+# Copyright (c) 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+try:
+ import resource # pylint: disable=F0401
+except ImportError:
+ resource = None # Not available on all platforms
+
+
+def _ConvertKbToByte(value):
+ return int(value.replace('kB','')) * 1024
+
+def _GetProcFileDict(contents):
+ retval = {}
+ for line in contents.splitlines():
+ key, value = line.split(':')
+ retval[key.strip()] = value.strip()
+ return retval
+
+def GetSystemCommitCharge(meminfo_contents):
+ meminfo = _GetProcFileDict(meminfo_contents)
+ return (_ConvertKbToByte(meminfo['MemTotal'])
+ - _ConvertKbToByte(meminfo['MemFree'])
+ - _ConvertKbToByte(meminfo['Buffers'])
+ - _ConvertKbToByte(meminfo['Cached']))
+
+def GetMemoryStats(status_contents, stats):
+ status = _GetProcFileDict(status_contents)
+ if not status or not stats or 'Z' in status['State']:
+ return {}
+ return {'VM': int(stats[22]),
+ 'VMPeak': _ConvertKbToByte(status['VmPeak']),
+ 'WorkingSetSize': int(stats[23]) * resource.getpagesize(),
+ 'WorkingSetSizePeak': _ConvertKbToByte(status['VmHWM'])}
+
+def GetIOStats(io_contents):
+ io = _GetProcFileDict(io_contents)
+ return {'ReadOperationCount': int(io['syscr']),
+ 'WriteOperationCount': int(io['syscw']),
+ 'ReadTransferCount': int(io['rchar']),
+ 'WriteTransferCount': int(io['wchar'])}

Powered by Google App Engine
This is Rietveld 408576698