Enterprise policy: Ignore the deprecated ForceSafeSearch if ForceGoogleSafeSearch...
[chromium-blink-merge.git] / base / trace_event / process_memory_totals_dump_provider.cc
blob125be382d7bec74b9b70430c7d515b44e3ab590d
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 const char kDumperFriendlyName[] = "ProcessMemoryTotals";
21 ProcessMetrics* CreateProcessMetricsForCurrentProcess() {
22 #if !defined(OS_MACOSX) || defined(OS_IOS)
23 return ProcessMetrics::CreateProcessMetrics(GetCurrentProcessHandle());
24 #else
25 return ProcessMetrics::CreateProcessMetrics(GetCurrentProcessHandle(), NULL);
26 #endif
28 } // namespace
30 // static
31 ProcessMemoryTotalsDumpProvider*
32 ProcessMemoryTotalsDumpProvider::GetInstance() {
33 return Singleton<
34 ProcessMemoryTotalsDumpProvider,
35 LeakySingletonTraits<ProcessMemoryTotalsDumpProvider>>::get();
38 ProcessMemoryTotalsDumpProvider::ProcessMemoryTotalsDumpProvider()
39 : process_metrics_(CreateProcessMetricsForCurrentProcess()) {
42 ProcessMemoryTotalsDumpProvider::~ProcessMemoryTotalsDumpProvider() {
45 // Called at trace dump point time. Creates a snapshot the memory counters for
46 // the current process.
47 bool ProcessMemoryTotalsDumpProvider::DumpInto(ProcessMemoryDump* pmd) {
48 const uint64 rss_bytes = rss_bytes_for_testing
49 ? rss_bytes_for_testing
50 : process_metrics_->GetWorkingSetSize();
52 if (rss_bytes > 0) {
53 pmd->process_totals()->set_resident_set_bytes(rss_bytes);
54 pmd->set_has_process_totals();
55 return true;
58 return false;
61 const char* ProcessMemoryTotalsDumpProvider::GetFriendlyName() const {
62 return kDumperFriendlyName;
65 } // namespace trace_event
66 } // namespace base