Update mojo sdk to rev 1dc8a9a5db73d3718d99917fadf31f5fb2ebad4f
[chromium-blink-merge.git] / base / trace_event / process_memory_totals_dump_provider.cc
blob06b537c4188ada9420ae05c41064e5b8e4602100
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.
5 #include "base/trace_event/process_memory_totals_dump_provider.h"
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"
11 namespace base {
12 namespace trace_event {
14 // static
15 uint64 ProcessMemoryTotalsDumpProvider::rss_bytes_for_testing = 0;
17 namespace {
19 ProcessMetrics* CreateProcessMetricsForCurrentProcess() {
20 #if !defined(OS_MACOSX) || defined(OS_IOS)
21 return ProcessMetrics::CreateProcessMetrics(GetCurrentProcessHandle());
22 #else
23 return ProcessMetrics::CreateProcessMetrics(GetCurrentProcessHandle(), NULL);
24 #endif
26 } // namespace
28 // static
29 ProcessMemoryTotalsDumpProvider*
30 ProcessMemoryTotalsDumpProvider::GetInstance() {
31 return Singleton<
32 ProcessMemoryTotalsDumpProvider,
33 LeakySingletonTraits<ProcessMemoryTotalsDumpProvider>>::get();
36 ProcessMemoryTotalsDumpProvider::ProcessMemoryTotalsDumpProvider()
37 : process_metrics_(CreateProcessMetricsForCurrentProcess()) {
40 ProcessMemoryTotalsDumpProvider::~ProcessMemoryTotalsDumpProvider() {
43 // Called at trace dump point time. Creates a snapshot the memory counters for
44 // the current process.
45 bool ProcessMemoryTotalsDumpProvider::OnMemoryDump(ProcessMemoryDump* pmd) {
46 const uint64 rss_bytes = rss_bytes_for_testing
47 ? rss_bytes_for_testing
48 : process_metrics_->GetWorkingSetSize();
50 if (rss_bytes > 0) {
51 pmd->process_totals()->set_resident_set_bytes(rss_bytes);
52 pmd->set_has_process_totals();
53 return true;
56 return false;
59 } // namespace trace_event
60 } // namespace base