summaryrefslogtreecommitdiffstats
path: root/base/process_util_linux.cc
diff options
context:
space:
mode:
authorevanm@google.com <evanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-14 20:49:16 +0000
committerevanm@google.com <evanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-14 20:49:16 +0000
commit0b100bc8b653af9c1a12794a7508d1269fafc156 (patch)
treed78f750536d7f60cdf460fdbc5bb39f74e9af29c /base/process_util_linux.cc
parent36b147bd8298c28e8ba4e7ab529b199aa3cce680 (diff)
downloadchromium_src-0b100bc8b653af9c1a12794a7508d1269fafc156.zip
chromium_src-0b100bc8b653af9c1a12794a7508d1269fafc156.tar.gz
chromium_src-0b100bc8b653af9c1a12794a7508d1269fafc156.tar.bz2
Port parts of base/process_util to Linux.
Review URL: http://codereview.chromium.org/6492 Patch from Paweł Hajdan jr <phajdan.jr@gmail.com>. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3363 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/process_util_linux.cc')
-rw-r--r--base/process_util_linux.cc62
1 files changed, 62 insertions, 0 deletions
diff --git a/base/process_util_linux.cc b/base/process_util_linux.cc
new file mode 100644
index 0000000..e5bc5db
--- /dev/null
+++ b/base/process_util_linux.cc
@@ -0,0 +1,62 @@
+// Copyright (c) 2008 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.
+
+#include "base/process_util.h"
+
+#include <string>
+
+#include "base/file_util.h"
+#include "base/logging.h"
+#include "base/string_tokenizer.h"
+#include "base/string_util.h"
+
+namespace {
+
+enum ParsingState {
+ KEY_NAME,
+ KEY_VALUE
+};
+
+} // namespace
+
+namespace process_util {
+
+// To have /proc/self/io file you must enable CONFIG_TASK_IO_ACCOUNTING
+// in your kernel configuration.
+bool ProcessMetrics::GetIOCounters(IoCounters* io_counters) {
+ std::string proc_io_contents;
+ if (!file_util::ReadFileToString(L"/proc/self/io", &proc_io_contents))
+ return false;
+
+ (*io_counters).OtherOperationCount = 0;
+ (*io_counters).OtherTransferCount = 0;
+
+ StringTokenizer tokenizer(proc_io_contents, ": \n");
+ ParsingState state = KEY_NAME;
+ std::string last_key_name;
+ while (tokenizer.GetNext()) {
+ switch (state) {
+ case KEY_NAME:
+ last_key_name = tokenizer.token();
+ state = KEY_VALUE;
+ break;
+ case KEY_VALUE:
+ DCHECK(!last_key_name.empty());
+ if (last_key_name == "syscr") {
+ (*io_counters).ReadOperationCount = StringToInt64(tokenizer.token());
+ } else if (last_key_name == "syscw") {
+ (*io_counters).WriteOperationCount = StringToInt64(tokenizer.token());
+ } else if (last_key_name == "rchar") {
+ (*io_counters).ReadTransferCount = StringToInt64(tokenizer.token());
+ } else if (last_key_name == "wchar") {
+ (*io_counters).WriteTransferCount = StringToInt64(tokenizer.token());
+ }
+ state = KEY_NAME;
+ break;
+ }
+ }
+ return true;
+}
+
+} // namespace process_util