| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/process_util.h" | 5 #include "base/process_util.h" |
| 6 | 6 |
| 7 #include <ctype.h> | 7 #include <ctype.h> |
| 8 #include <dirent.h> | 8 #include <dirent.h> |
| 9 #include <dlfcn.h> | 9 #include <dlfcn.h> |
| 10 #include <errno.h> | 10 #include <errno.h> |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 116 |
| 117 FilePath stat_file("/proc"); | 117 FilePath stat_file("/proc"); |
| 118 stat_file = stat_file.Append(base::IntToString(process)); | 118 stat_file = stat_file.Append(base::IntToString(process)); |
| 119 stat_file = stat_file.Append("status"); | 119 stat_file = stat_file.Append("status"); |
| 120 std::string status; | 120 std::string status; |
| 121 if (!file_util::ReadFileToString(stat_file, &status)) | 121 if (!file_util::ReadFileToString(stat_file, &status)) |
| 122 return -1; | 122 return -1; |
| 123 | 123 |
| 124 StringTokenizer tokenizer(status, ":\n"); | 124 StringTokenizer tokenizer(status, ":\n"); |
| 125 ParsingState state = KEY_NAME; | 125 ParsingState state = KEY_NAME; |
| 126 std::string last_key_name; | 126 StringPiece last_key_name; |
| 127 while (tokenizer.GetNext()) { | 127 while (tokenizer.GetNext()) { |
| 128 switch (state) { | 128 switch (state) { |
| 129 case KEY_NAME: | 129 case KEY_NAME: |
| 130 last_key_name = tokenizer.token(); | 130 last_key_name = tokenizer.token_piece(); |
| 131 state = KEY_VALUE; | 131 state = KEY_VALUE; |
| 132 break; | 132 break; |
| 133 case KEY_VALUE: | 133 case KEY_VALUE: |
| 134 DCHECK(!last_key_name.empty()); | 134 DCHECK(!last_key_name.empty()); |
| 135 if (last_key_name == "PPid") { | 135 if (last_key_name == "PPid") { |
| 136 int ppid; | 136 int ppid; |
| 137 base::StringToInt(tokenizer.token(), &ppid); | 137 base::StringToInt(tokenizer.token_piece(), &ppid); |
| 138 return ppid; | 138 return ppid; |
| 139 } | 139 } |
| 140 state = KEY_NAME; | 140 state = KEY_NAME; |
| 141 break; | 141 break; |
| 142 } | 142 } |
| 143 } | 143 } |
| 144 NOTREACHED(); | 144 NOTREACHED(); |
| 145 return -1; | 145 return -1; |
| 146 } | 146 } |
| 147 | 147 |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 last_key_name = tokenizer.token_piece(); | 373 last_key_name = tokenizer.token_piece(); |
| 374 state = KEY_VALUE; | 374 state = KEY_VALUE; |
| 375 break; | 375 break; |
| 376 case KEY_VALUE: | 376 case KEY_VALUE: |
| 377 if (last_key_name.empty()) { | 377 if (last_key_name.empty()) { |
| 378 NOTREACHED(); | 378 NOTREACHED(); |
| 379 return false; | 379 return false; |
| 380 } | 380 } |
| 381 if (last_key_name.starts_with(private_prefix)) { | 381 if (last_key_name.starts_with(private_prefix)) { |
| 382 int cur; | 382 int cur; |
| 383 base::StringToInt(tokenizer.token(), &cur); | 383 base::StringToInt(tokenizer.token_piece(), &cur); |
| 384 private_kb += cur; | 384 private_kb += cur; |
| 385 } else if (last_key_name.starts_with(pss_prefix)) { | 385 } else if (last_key_name.starts_with(pss_prefix)) { |
| 386 have_pss = true; | 386 have_pss = true; |
| 387 int cur; | 387 int cur; |
| 388 base::StringToInt(tokenizer.token(), &cur); | 388 base::StringToInt(tokenizer.token_piece(), &cur); |
| 389 pss_kb += cur; | 389 pss_kb += cur; |
| 390 } | 390 } |
| 391 state = KEY_NAME; | 391 state = KEY_NAME; |
| 392 break; | 392 break; |
| 393 } | 393 } |
| 394 } | 394 } |
| 395 } else { | 395 } else { |
| 396 // Try statm if smaps is empty because of the SUID sandbox. | 396 // Try statm if smaps is empty because of the SUID sandbox. |
| 397 // First we need to get the page size though. | 397 // First we need to get the page size though. |
| 398 int page_size_kb = sysconf(_SC_PAGE_SIZE) / 1024; | 398 int page_size_kb = sysconf(_SC_PAGE_SIZE) / 1024; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 io_file = io_file.Append(base::IntToString(process_)); | 483 io_file = io_file.Append(base::IntToString(process_)); |
| 484 io_file = io_file.Append("io"); | 484 io_file = io_file.Append("io"); |
| 485 if (!file_util::ReadFileToString(io_file, &proc_io_contents)) | 485 if (!file_util::ReadFileToString(io_file, &proc_io_contents)) |
| 486 return false; | 486 return false; |
| 487 | 487 |
| 488 (*io_counters).OtherOperationCount = 0; | 488 (*io_counters).OtherOperationCount = 0; |
| 489 (*io_counters).OtherTransferCount = 0; | 489 (*io_counters).OtherTransferCount = 0; |
| 490 | 490 |
| 491 StringTokenizer tokenizer(proc_io_contents, ": \n"); | 491 StringTokenizer tokenizer(proc_io_contents, ": \n"); |
| 492 ParsingState state = KEY_NAME; | 492 ParsingState state = KEY_NAME; |
| 493 std::string last_key_name; | 493 StringPiece last_key_name; |
| 494 while (tokenizer.GetNext()) { | 494 while (tokenizer.GetNext()) { |
| 495 switch (state) { | 495 switch (state) { |
| 496 case KEY_NAME: | 496 case KEY_NAME: |
| 497 last_key_name = tokenizer.token(); | 497 last_key_name = tokenizer.token_piece(); |
| 498 state = KEY_VALUE; | 498 state = KEY_VALUE; |
| 499 break; | 499 break; |
| 500 case KEY_VALUE: | 500 case KEY_VALUE: |
| 501 DCHECK(!last_key_name.empty()); | 501 DCHECK(!last_key_name.empty()); |
| 502 if (last_key_name == "syscr") { | 502 if (last_key_name == "syscr") { |
| 503 base::StringToInt64(tokenizer.token(), | 503 base::StringToInt64(tokenizer.token_piece(), |
| 504 reinterpret_cast<int64*>(&(*io_counters).ReadOperationCount)); | 504 reinterpret_cast<int64*>(&(*io_counters).ReadOperationCount)); |
| 505 } else if (last_key_name == "syscw") { | 505 } else if (last_key_name == "syscw") { |
| 506 base::StringToInt64(tokenizer.token(), | 506 base::StringToInt64(tokenizer.token_piece(), |
| 507 reinterpret_cast<int64*>(&(*io_counters).WriteOperationCount)); | 507 reinterpret_cast<int64*>(&(*io_counters).WriteOperationCount)); |
| 508 } else if (last_key_name == "rchar") { | 508 } else if (last_key_name == "rchar") { |
| 509 base::StringToInt64(tokenizer.token(), | 509 base::StringToInt64(tokenizer.token_piece(), |
| 510 reinterpret_cast<int64*>(&(*io_counters).ReadTransferCount)); | 510 reinterpret_cast<int64*>(&(*io_counters).ReadTransferCount)); |
| 511 } else if (last_key_name == "wchar") { | 511 } else if (last_key_name == "wchar") { |
| 512 base::StringToInt64(tokenizer.token(), | 512 base::StringToInt64(tokenizer.token_piece(), |
| 513 reinterpret_cast<int64*>(&(*io_counters).WriteTransferCount)); | 513 reinterpret_cast<int64*>(&(*io_counters).WriteTransferCount)); |
| 514 } | 514 } |
| 515 state = KEY_NAME; | 515 state = KEY_NAME; |
| 516 break; | 516 break; |
| 517 } | 517 } |
| 518 } | 518 } |
| 519 return true; | 519 return true; |
| 520 } | 520 } |
| 521 | 521 |
| 522 ProcessMetrics::ProcessMetrics(ProcessHandle process) | 522 ProcessMetrics::ProcessMetrics(ProcessHandle process) |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 int score_len = static_cast<int>(score_str.length()); | 770 int score_len = static_cast<int>(score_str.length()); |
| 771 return (score_len == file_util::WriteFile(oom_file, | 771 return (score_len == file_util::WriteFile(oom_file, |
| 772 score_str.c_str(), | 772 score_str.c_str(), |
| 773 score_len)); | 773 score_len)); |
| 774 } | 774 } |
| 775 | 775 |
| 776 return false; | 776 return false; |
| 777 } | 777 } |
| 778 | 778 |
| 779 } // namespace base | 779 } // namespace base |
| OLD | NEW |