Index: base/process/process_metrics_linux.cc |
diff --git a/base/process/process_metrics_linux.cc b/base/process/process_metrics_linux.cc |
index bcebcf5729fda730528c49119c3c58c19e0ac6dc..c556b4f7c1378ff9df223c4189656e8c40f0d5c5 100644 |
--- a/base/process/process_metrics_linux.cc |
+++ b/base/process/process_metrics_linux.cc |
@@ -53,16 +53,20 @@ static uint64_t ReadFileToUint64(const FilePath file) { |
} |
#endif |
-// Read /proc/<pid>/status and return the value for |field|, or 0 on failure. |
-// Only works for fields in the form of "Field: value kB". |
-size_t ReadProcStatusAndGetFieldAsSizeT(pid_t pid, const std::string& field) { |
+// Read /proc/<pid>/status and writes the value for |field| into |result|. |
+// Returns true on success. Only works for fields in the form of |
+// "Field: value kB". |
+bool ReadProcStatusAndGetFieldAsSizeT(pid_t pid, |
+ const std::string& field, |
+ size_t* result) { |
+ *result = 0; |
std::string status; |
{ |
// Synchronously reading files in /proc does not hit the disk. |
ThreadRestrictions::ScopedAllowIO allow_io; |
FilePath stat_file = internal::GetProcPidDir(pid).Append("status"); |
if (!ReadFileToString(stat_file, &status)) |
- return 0; |
+ return false; |
} |
StringPairs pairs; |
@@ -76,18 +80,16 @@ size_t ReadProcStatusAndGetFieldAsSizeT(pid_t pid, const std::string& field) { |
value_str, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
if (split_value_str.size() != 2 || split_value_str[1] != "kB") { |
NOTREACHED(); |
- return 0; |
+ return false; |
} |
- size_t value; |
- if (!StringToSizeT(split_value_str[0], &value)) { |
+ if (!StringToSizeT(split_value_str[0], result)) { |
NOTREACHED(); |
- return 0; |
+ return false; |
} |
- return value; |
+ return true; |
} |
} |
- NOTREACHED(); |
- return 0; |
+ return false; |
} |
#if defined(OS_LINUX) |
@@ -174,7 +176,10 @@ size_t ProcessMetrics::GetPagefileUsage() const { |
// On linux, we return the high water mark of vsize. |
size_t ProcessMetrics::GetPeakPagefileUsage() const { |
- return ReadProcStatusAndGetFieldAsSizeT(process_, "VmPeak") * 1024; |
+ size_t value = 0; |
+ bool res = ReadProcStatusAndGetFieldAsSizeT(process_, "VmPeak", &value); |
+ DCHECK(res); |
+ return value * 1024; |
} |
// On linux, we return RSS. |
@@ -185,7 +190,9 @@ size_t ProcessMetrics::GetWorkingSetSize() const { |
// On linux, we return the high water mark of RSS. |
size_t ProcessMetrics::GetPeakWorkingSetSize() const { |
- return ReadProcStatusAndGetFieldAsSizeT(process_, "VmHWM") * 1024; |
+ size_t value = 0; |
Primiano Tucci (use gerrit)
2016/01/07 11:34:35
Oooh I see, you still cannot have the DCHECK here.
ssid
2016/01/07 13:03:09
Done.
|
+ ReadProcStatusAndGetFieldAsSizeT(process_, "VmHWM", &value); |
+ return value * 1024; |
} |
bool ProcessMetrics::GetMemoryBytes(size_t* private_bytes, |