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"
12 namespace trace_event
{
15 uint64
ProcessMemoryTotalsDumpProvider::rss_bytes_for_testing
= 0;
19 ProcessMetrics
* CreateProcessMetricsForCurrentProcess() {
20 #if !defined(OS_MACOSX) || defined(OS_IOS)
21 return ProcessMetrics::CreateProcessMetrics(GetCurrentProcessHandle());
23 return ProcessMetrics::CreateProcessMetrics(GetCurrentProcessHandle(), NULL
);
29 ProcessMemoryTotalsDumpProvider
*
30 ProcessMemoryTotalsDumpProvider::GetInstance() {
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();
51 pmd
->process_totals()->set_resident_set_bytes(rss_bytes
);
52 pmd
->set_has_process_totals();
59 } // namespace trace_event