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

Unified Diff: base/process/process_metrics_linux.cc

Issue 1384363002: [NOT TO COMMIT YET] Using proc/pid/status file contents to get process metrics in linux. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@smaps_fscan
Patch Set: Fixes. Created 5 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/process_metrics.h ('k') | base/process/process_metrics_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
« no previous file with comments | « base/process/process_metrics.h ('k') | base/process/process_metrics_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698