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

Unified Diff: base/trace_event/process_memory_totals_dump_provider.cc

Issue 1180693002: Update from https://crrev.com/333737 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: rebased Created 5 years, 6 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.cc ('k') | base/trace_event/trace_config.h » ('j') | 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 06b537c4188ada9420ae05c41064e5b8e4602100..37f9bed68c9b2b4e59e8b83b70fc776c5117906a 100644
--- a/base/trace_event/process_memory_totals_dump_provider.cc
+++ b/base/trace_event/process_memory_totals_dump_provider.cc
@@ -8,6 +8,17 @@
#include "base/trace_event/process_memory_dump.h"
#include "base/trace_event/process_memory_totals.h"
+#if defined(OS_LINUX) || defined(OS_ANDROID)
+#include <fcntl.h>
+
+#include "base/files/file_util.h"
+
+namespace {
+bool kernel_supports_rss_peak_reset = true;
+const char kClearPeakRssCommand[] = "5";
+}
+#endif
+
namespace base {
namespace trace_event {
@@ -47,8 +58,30 @@ bool ProcessMemoryTotalsDumpProvider::OnMemoryDump(ProcessMemoryDump* pmd) {
? rss_bytes_for_testing
: process_metrics_->GetWorkingSetSize();
+ uint64 peak_rss_bytes = 0;
+
+#if !defined(OS_IOS)
+ peak_rss_bytes = process_metrics_->GetPeakWorkingSetSize();
+#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
+ // processes.
+ int clear_refs_fd = open("/proc/self/clear_refs", O_WRONLY);
+ if (clear_refs_fd > 0 &&
+ WriteFileDescriptor(clear_refs_fd, kClearPeakRssCommand,
+ sizeof(kClearPeakRssCommand))) {
+ pmd->process_totals()->set_is_peak_rss_resetable(true);
+ } else {
+ kernel_supports_rss_peak_reset = false;
+ }
+ 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);
+ pmd->process_totals()->set_peak_resident_set_bytes(peak_rss_bytes);
pmd->set_has_process_totals();
return true;
}
« no previous file with comments | « base/trace_event/process_memory_totals.cc ('k') | base/trace_event/trace_config.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698