Chromium Code Reviews| Index: base/process/process_metrics_linux.cc |
| diff --git a/base/process/process_metrics_linux.cc b/base/process/process_metrics_linux.cc |
| index adca7c5ee23bd53914342cffd2aab166402fe920..375b9fbe6cf08b61187451c9e9a0df71e63e8cd9 100644 |
| --- a/base/process/process_metrics_linux.cc |
| +++ b/base/process/process_metrics_linux.cc |
| @@ -59,30 +59,9 @@ size_t ReadProcStatusAndGetFieldAsSizeT(pid_t pid, const std::string& field) { |
| if (!ReadFileToString(stat_file, &status)) |
| return 0; |
| } |
| - |
| - StringPairs pairs; |
| - SplitStringIntoKeyValuePairs(status, ':', '\n', &pairs); |
| - TrimKeyValuePairs(&pairs); |
| - for (size_t i = 0; i < pairs.size(); ++i) { |
| - const std::string& key = pairs[i].first; |
| - const std::string& value_str = pairs[i].second; |
| - if (key == field) { |
| - std::vector<StringPiece> split_value_str = SplitStringPiece( |
| - value_str, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| - if (split_value_str.size() != 2 || split_value_str[1] != "kB") { |
| - NOTREACHED(); |
| - return 0; |
| - } |
| - size_t value; |
| - if (!StringToSizeT(split_value_str[0], &value)) { |
| - NOTREACHED(); |
| - return 0; |
| - } |
| - return value; |
| - } |
| - } |
| - NOTREACHED(); |
| - return 0; |
| + size_t value; |
| + CHECK(ParseProcStatusAndGetField(status, field, &value)); |
|
Lei Zhang
2015/10/07 16:10:54
CHECK() is a bit strong. Any project that uses thi
ssid
2015/10/07 17:11:34
Sorry I beleived NOTREACHED was CHECK. Just realiz
|
| + return value; |
| } |
| #if defined(OS_LINUX) |
| @@ -432,6 +411,31 @@ int ParseProcStatCPU(const std::string& input) { |
| return -1; |
| } |
| +bool ParseProcStatusAndGetField(const std::string& proc_status_contents, |
| + const std::string& field, |
| + size_t* value) { |
| + StringPairs pairs; |
| + SplitStringIntoKeyValuePairs(proc_status_contents, ':', '\n', &pairs); |
| + TrimKeyValuePairs(&pairs); |
| + for (size_t i = 0; i < pairs.size(); ++i) { |
| + const std::string& key = pairs[i].first; |
| + const std::string& value_str = pairs[i].second; |
| + if (key == field) { |
| + std::vector<StringPiece> split_value_str = SplitStringPiece( |
| + value_str, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| + if (split_value_str.size() != 2 || split_value_str[1] != "kB") { |
| + return false; |
| + } |
| + if (StringToSizeT(split_value_str[0], value)) { |
| + *value *= 1024; |
| + return true; |
| + } |
| + return false; |
| + } |
| + } |
| + return false; |
| +} |
| + |
| const char kProcSelfExe[] = "/proc/self/exe"; |
| int GetNumberOfThreads(ProcessHandle process) { |