OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/process_util.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "base/file_util.h" | |
10 #include "base/logging.h" | |
11 #include "base/string_tokenizer.h" | |
12 #include "base/string_util.h" | |
13 | |
14 namespace { | |
15 | |
16 enum ParsingState { | |
17 KEY_NAME, | |
18 KEY_VALUE | |
19 }; | |
20 | |
21 } // namespace | |
22 | |
23 namespace process_util { | |
24 | |
25 // To have /proc/self/io file you must enable CONFIG_TASK_IO_ACCOUNTING | |
26 // in your kernel configuration. | |
27 bool ProcessMetrics::GetIOCounters(IoCounters* io_counters) { | |
28 std::string proc_io_contents; | |
29 if (!file_util::ReadFileToString(L"/proc/self/io", &proc_io_contents)) | |
30 return false; | |
31 | |
32 (*io_counters).OtherOperationCount = 0; | |
33 (*io_counters).OtherTransferCount = 0; | |
34 | |
35 StringTokenizer tokenizer(proc_io_contents, ": \n"); | |
36 ParsingState state = KEY_NAME; | |
37 std::string last_key_name; | |
38 while (tokenizer.GetNext()) { | |
39 switch (state) { | |
40 case KEY_NAME: | |
41 last_key_name = tokenizer.token(); | |
42 state = KEY_VALUE; | |
43 break; | |
44 case KEY_VALUE: | |
45 DCHECK(!last_key_name.empty()); | |
46 if (last_key_name == "syscr") { | |
Evan Stade
2008/10/13 22:28:11
maybe pull these string literals out and store the
| |
47 (*io_counters).ReadOperationCount = StringToInt64(tokenizer.token()); | |
48 } else if (last_key_name == "syscw") { | |
49 (*io_counters).WriteOperationCount = StringToInt64(tokenizer.token()); | |
50 } else if (last_key_name == "rchar") { | |
51 (*io_counters).ReadTransferCount = StringToInt64(tokenizer.token()); | |
52 } else if (last_key_name == "wchar") { | |
53 (*io_counters).WriteTransferCount = StringToInt64(tokenizer.token()); | |
54 } | |
55 state = KEY_NAME; | |
56 break; | |
57 } | |
58 } | |
59 return true; | |
60 } | |
61 | |
62 } // namespace process_util | |
OLD | NEW |