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

Unified Diff: base/trace_event/process_memory_totals_dump_provider.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: Change the api. 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/trace_event/process_memory_totals_dump_provider.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/trace_event/process_memory_totals_dump_provider.cc
diff --git a/base/trace_event/process_memory_totals_dump_provider.cc b/base/trace_event/process_memory_totals_dump_provider.cc
index a8617207dcfc35350496ebf7b27c8d758c891679..a425c322aa841b826df54bd4e10382b2c924a2f9 100644
--- a/base/trace_event/process_memory_totals_dump_provider.cc
+++ b/base/trace_event/process_memory_totals_dump_provider.cc
@@ -34,6 +34,20 @@ ProcessMetrics* CreateProcessMetricsForCurrentProcess() {
return ProcessMetrics::CreateProcessMetrics(GetCurrentProcessHandle(), NULL);
#endif
}
+
+bool ReadStatusFile(FILE* status_file, std::string* data) {
+ if (fseek(status_file, 0, SEEK_SET))
+ return false;
+ char buffer[4096];
+ buffer[0] = '\0';
+ int ret = fread(buffer, 1, sizeof(buffer), status_file);
Primiano Tucci (use gerrit) 2015/10/07 10:25:34 Use base::ReadFromFD, which is protected from EINT
+ if (ret <= 0)
+ return false;
+ data->clear();
+ data->append(buffer, ret);
+ return true;
+}
+
} // namespace
// static
@@ -55,14 +69,29 @@ ProcessMemoryTotalsDumpProvider::~ProcessMemoryTotalsDumpProvider() {
// the current process.
bool ProcessMemoryTotalsDumpProvider::OnMemoryDump(const MemoryDumpArgs& args,
ProcessMemoryDump* pmd) {
- const uint64 rss_bytes = rss_bytes_for_testing
- ? rss_bytes_for_testing
- : process_metrics_->GetWorkingSetSize();
-
+ uint64 rss_bytes;
uint64 peak_rss_bytes = 0;
-
+ std::string status_contents;
+
+ if (UNLIKELY(rss_bytes_for_testing)) {
+ rss_bytes = rss_bytes_for_testing;
+ } else if (proc_status_file &&
+ ReadStatusFile(proc_status_file.get(), &status_contents)) {
+#if defined(OS_LINUX) || defeind(OS_ANDROID)
+ int res = ParseProcStatusAndGetField(status_contents, "VmRSS", &rss_bytes);
+ DCHECK(res);
+ res = ParseProcStatusAndGetField(status_contents, "VmHWM", &peak_rss_bytes);
+ DCHECK(res);
+#else
+ NOTREACHED();
+#endif
+ } else {
+ rss_bytes = process_metrics_->GetWorkingSetSize();
#if !defined(OS_IOS)
- peak_rss_bytes = process_metrics_->GetPeakWorkingSetSize();
+ peak_rss_bytes = process_metrics_->GetPeakWorkingSetSize();
+#endif
+ }
+
#if defined(OS_LINUX) || defined(OS_ANDROID)
if (kernel_supports_rss_peak_reset) {
// TODO(ssid): Fix crbug.com/461788 to write to the file from sandboxed
@@ -78,7 +107,6 @@ bool ProcessMemoryTotalsDumpProvider::OnMemoryDump(const MemoryDumpArgs& args,
close(clear_refs_fd);
}
#endif // defined(OS_LINUX) || defined(OS_ANDROID)
-#endif // !defined(OS_IOS)
if (rss_bytes > 0) {
pmd->process_totals()->set_resident_set_bytes(rss_bytes);
« no previous file with comments | « base/trace_event/process_memory_totals_dump_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698