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..658c4d8ebff0ed90ceec454aa810dc2756f3159b 100644 |
--- a/base/process/process_metrics_linux.cc |
+++ b/base/process/process_metrics_linux.cc |
@@ -59,30 +59,10 @@ 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; |
+ bool res = ParseProcStatusAndGetField(status, field, &value); |
+ DCHECK(res); |
+ return value; |
} |
#if defined(OS_LINUX) |
@@ -432,6 +412,31 @@ int ParseProcStatCPU(const std::string& input) { |
return -1; |
} |
+bool ParseProcStatusAndGetField(const StringPiece& 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) { |