Index: base/process_util_linux.cc |
=================================================================== |
--- base/process_util_linux.cc (revision 0) |
+++ base/process_util_linux.cc (revision 0) |
@@ -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") { |
Evan Stade
2008/10/13 22:28:11
maybe pull these string literals out and store the
|
+ (*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 |