OLD | NEW |
(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 "base/trace_event/process_memory_totals_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 base { |
| 12 namespace trace_event { |
| 13 |
| 14 // static |
| 15 uint64 ProcessMemoryTotalsDumpProvider::rss_bytes_for_testing = 0; |
| 16 |
| 17 namespace { |
| 18 ProcessMetrics* CreateProcessMetricsForCurrentProcess() { |
| 19 #if !defined(OS_MACOSX) || defined(OS_IOS) |
| 20 return ProcessMetrics::CreateProcessMetrics(GetCurrentProcessHandle()); |
| 21 #else |
| 22 return ProcessMetrics::CreateProcessMetrics(GetCurrentProcessHandle(), NULL); |
| 23 #endif |
| 24 } |
| 25 } // namespace |
| 26 |
| 27 // static |
| 28 ProcessMemoryTotalsDumpProvider* |
| 29 ProcessMemoryTotalsDumpProvider::GetInstance() { |
| 30 return Singleton< |
| 31 ProcessMemoryTotalsDumpProvider, |
| 32 LeakySingletonTraits<ProcessMemoryTotalsDumpProvider>>::get(); |
| 33 } |
| 34 |
| 35 ProcessMemoryTotalsDumpProvider::ProcessMemoryTotalsDumpProvider() |
| 36 : process_metrics_(CreateProcessMetricsForCurrentProcess()) { |
| 37 } |
| 38 |
| 39 ProcessMemoryTotalsDumpProvider::~ProcessMemoryTotalsDumpProvider() { |
| 40 } |
| 41 |
| 42 // Called at trace dump point time. Creates a snapshot the memory counters for |
| 43 // the current process. |
| 44 void ProcessMemoryTotalsDumpProvider::DumpInto(ProcessMemoryDump* pmd) { |
| 45 const uint64 rss_bytes = rss_bytes_for_testing |
| 46 ? rss_bytes_for_testing |
| 47 : process_metrics_->GetWorkingSetSize(); |
| 48 pmd->process_totals()->set_resident_set_bytes(rss_bytes); |
| 49 pmd->set_has_process_totals(); |
| 50 } |
| 51 |
| 52 } // namespace trace_event |
| 53 } // namespace base |
OLD | NEW |