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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/tracing/process_metrics_memory_dump_provider.h"
6
7 #include "base/process/process_metrics.h"
8 #include "base/trace_event/process_memory_dump.h"
9 #include "base/trace_event/process_memory_totals.h"
10
11 namespace tracing {
12
13 namespace {
14
15 base::ProcessMetrics* CreateProcessMetrics(base::ProcessHandle process) {
16 if (process == base::kNullProcessHandle)
17 process = base::GetCurrentProcessHandle();
18 #if !defined(OS_MACOSX) || defined(OS_IOS)
19 return base::ProcessMetrics::CreateProcessMetrics(process);
20 #else
21 return base::ProcessMetrics::CreateProcessMetrics(process, NULL);
22 #endif
23 }
24
25 } // namespace
26
27 // static
28 uint64 ProcessMetricsMemoryDumpProvider::rss_bytes_for_testing = 0;
29
30 ProcessMetricsMemoryDumpProvider::ProcessMetricsMemoryDumpProvider(
31 base::ProcessHandle process)
32 : process_(process), process_metrics_(CreateProcessMetrics(process)) {}
33
34 ProcessMetricsMemoryDumpProvider::~ProcessMetricsMemoryDumpProvider() {}
35
36 // Called at trace dump point time. Creates a snapshot of the memory maps for
37 // the current process.
38 bool ProcessMetricsMemoryDumpProvider::OnMemoryDump(
39 const base::trace_event::MemoryDumpArgs& args,
40 base::trace_event::ProcessMemoryDump* pmd) {
41 DumpProcessTotals(args, pmd);
42
43 #if defined(OS_LINUX) || defined(OS_ANDROID)
44 DumpProcessMemoryMaps(args, pmd);
45 #endif
46 return true;
47 }
48
49 #if !defined(OS_LINUX) && !defined(OS_ANDROID)
50 void ProcessMetricsMemoryDumpProvider::DumpProcessTotals(
51 const base::trace_event::MemoryDumpArgs& args,
52 base::trace_event::ProcessMemoryDump* pmd) {
53 const uint64 rss_bytes = rss_bytes_for_testing
54 ? rss_bytes_for_testing
55 : process_metrics_->GetWorkingSetSize();
56
57 uint64 peak_rss_bytes = 0;
58
59 #if !defined(OS_IOS)
60 peak_rss_bytes = process_metrics_->GetPeakWorkingSetSize();
61 #if defined(MACOSX)
62 size_t private_bytes;
63 bool res = process_metrics_->GetMemoryBytes(&private_bytes,
64 nullptr /* shared_bytes */);
65 if (res) {
66 pmd->process_totals()->SetExtraFieldInBytes("private_bytes", private_bytes);
67 }
68 #endif // defined(MACOSX)
69 #endif // !defined(OS_IOS)
70
71 DCHECK(rss_bytes);
72 pmd->process_totals()->set_resident_set_bytes(rss_bytes);
73 pmd->process_totals()->set_peak_resident_set_bytes(peak_rss_bytes);
74 pmd->set_has_process_totals();
75 }
76 #endif // !defined(OS_LINUX) && !defined(OS_ANDROID)
77
78 } // namespace tracing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698