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

Unified Diff: components/tracing/process_metrics_memory_dump_provider.cc

Issue 1417003003: [tracing] Dump child processes' memory metrics in browser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@web_cache2_base
Patch Set: dNits. Created 5 years, 1 month 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
Index: components/tracing/process_metrics_memory_dump_provider.cc
diff --git a/components/tracing/process_metrics_memory_dump_provider.cc b/components/tracing/process_metrics_memory_dump_provider.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a1518d6a79bf0b38e9116f459eb9f6e9971ee359
--- /dev/null
+++ b/components/tracing/process_metrics_memory_dump_provider.cc
@@ -0,0 +1,78 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/tracing/process_metrics_memory_dump_provider.h"
+
+#include "base/process/process_metrics.h"
+#include "base/trace_event/process_memory_dump.h"
+#include "base/trace_event/process_memory_totals.h"
+
+namespace tracing {
+
+namespace {
+
+base::ProcessMetrics* CreateProcessMetrics(base::ProcessHandle process) {
+ if (process == base::kNullProcessHandle)
+ process = base::GetCurrentProcessHandle();
+#if !defined(OS_MACOSX) || defined(OS_IOS)
+ return base::ProcessMetrics::CreateProcessMetrics(process);
+#else
+ return base::ProcessMetrics::CreateProcessMetrics(process, NULL);
+#endif
+}
+
+} // namespace
+
+// static
+uint64 ProcessMetricsMemoryDumpProvider::rss_bytes_for_testing = 0;
+
+ProcessMetricsMemoryDumpProvider::ProcessMetricsMemoryDumpProvider(
+ base::ProcessHandle process)
+ : process_(process), process_metrics_(CreateProcessMetrics(process)) {}
+
+ProcessMetricsMemoryDumpProvider::~ProcessMetricsMemoryDumpProvider() {}
+
+// Called at trace dump point time. Creates a snapshot of the memory maps for
+// the current process.
+bool ProcessMetricsMemoryDumpProvider::OnMemoryDump(
+ const base::trace_event::MemoryDumpArgs& args,
+ base::trace_event::ProcessMemoryDump* pmd) {
+ DumpProcessTotals(args, pmd);
+
+#if defined(OS_LINUX) || defined(OS_ANDROID)
+ DumpProcessMemoryMaps(args, pmd);
+#endif
+ return true;
+}
+
+#if !defined(OS_LINUX) && !defined(OS_ANDROID)
+void ProcessMetricsMemoryDumpProvider::DumpProcessTotals(
+ const base::trace_event::MemoryDumpArgs& args,
+ base::trace_event::ProcessMemoryDump* pmd) {
+ const uint64 rss_bytes = rss_bytes_for_testing
+ ? rss_bytes_for_testing
+ : process_metrics_->GetWorkingSetSize();
+
+ uint64 peak_rss_bytes = 0;
+
+#if !defined(OS_IOS)
+ peak_rss_bytes = process_metrics_->GetPeakWorkingSetSize();
+#if defined(MACOSX)
+ size_t private_bytes;
+ bool res = process_metrics_->GetMemoryBytes(&private_bytes,
+ nullptr /* shared_bytes */);
+ if (res) {
+ pmd->process_totals()->SetExtraFieldInBytes("private_bytes", private_bytes);
+ }
+#endif // defined(MACOSX)
+#endif // !defined(OS_IOS)
+
+ DCHECK(rss_bytes);
+ 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();
+}
+#endif // !defined(OS_LINUX) && !defined(OS_ANDROID)
+
+} // namespace tracing

Powered by Google App Engine
This is Rietveld 408576698