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

Unified Diff: base/process_util_linux.cc

Issue 6492: Port parts of base/process_util to Linux. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 12 years, 2 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
« no previous file with comments | « base/process_util.h ('k') | base/process_util_posix.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « base/process_util.h ('k') | base/process_util_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698