OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/trace_event/process_memory_totals_dump_provider.h" | 5 #include "base/trace_event/process_memory_totals_dump_provider.h" |
6 | 6 |
7 #include "base/process/process_metrics.h" | 7 #include "base/process/process_metrics.h" |
8 #include "base/trace_event/process_memory_dump.h" | 8 #include "base/trace_event/process_memory_dump.h" |
9 #include "base/trace_event/process_memory_totals.h" | 9 #include "base/trace_event/process_memory_totals.h" |
10 | 10 |
11 namespace base { | 11 namespace base { |
12 namespace trace_event { | 12 namespace trace_event { |
13 | 13 |
14 // static | 14 // static |
15 uint64 ProcessMemoryTotalsDumpProvider::rss_bytes_for_testing = 0; | 15 uint64 ProcessMemoryTotalsDumpProvider::rss_bytes_for_testing = 0; |
16 | 16 |
17 namespace { | 17 namespace { |
| 18 |
| 19 const char kDumperFriendlyName[] = "ProcessMemoryTotals"; |
| 20 |
18 ProcessMetrics* CreateProcessMetricsForCurrentProcess() { | 21 ProcessMetrics* CreateProcessMetricsForCurrentProcess() { |
19 #if !defined(OS_MACOSX) || defined(OS_IOS) | 22 #if !defined(OS_MACOSX) || defined(OS_IOS) |
20 return ProcessMetrics::CreateProcessMetrics(GetCurrentProcessHandle()); | 23 return ProcessMetrics::CreateProcessMetrics(GetCurrentProcessHandle()); |
21 #else | 24 #else |
22 return ProcessMetrics::CreateProcessMetrics(GetCurrentProcessHandle(), NULL); | 25 return ProcessMetrics::CreateProcessMetrics(GetCurrentProcessHandle(), NULL); |
23 #endif | 26 #endif |
24 } | 27 } |
25 } // namespace | 28 } // namespace |
26 | 29 |
27 // static | 30 // static |
28 ProcessMemoryTotalsDumpProvider* | 31 ProcessMemoryTotalsDumpProvider* |
29 ProcessMemoryTotalsDumpProvider::GetInstance() { | 32 ProcessMemoryTotalsDumpProvider::GetInstance() { |
30 return Singleton< | 33 return Singleton< |
31 ProcessMemoryTotalsDumpProvider, | 34 ProcessMemoryTotalsDumpProvider, |
32 LeakySingletonTraits<ProcessMemoryTotalsDumpProvider>>::get(); | 35 LeakySingletonTraits<ProcessMemoryTotalsDumpProvider>>::get(); |
33 } | 36 } |
34 | 37 |
35 ProcessMemoryTotalsDumpProvider::ProcessMemoryTotalsDumpProvider() | 38 ProcessMemoryTotalsDumpProvider::ProcessMemoryTotalsDumpProvider() |
36 : process_metrics_(CreateProcessMetricsForCurrentProcess()) { | 39 : process_metrics_(CreateProcessMetricsForCurrentProcess()) { |
37 } | 40 } |
38 | 41 |
39 ProcessMemoryTotalsDumpProvider::~ProcessMemoryTotalsDumpProvider() { | 42 ProcessMemoryTotalsDumpProvider::~ProcessMemoryTotalsDumpProvider() { |
40 } | 43 } |
41 | 44 |
42 // Called at trace dump point time. Creates a snapshot the memory counters for | 45 // Called at trace dump point time. Creates a snapshot the memory counters for |
43 // the current process. | 46 // the current process. |
44 void ProcessMemoryTotalsDumpProvider::DumpInto(ProcessMemoryDump* pmd) { | 47 bool ProcessMemoryTotalsDumpProvider::DumpInto(ProcessMemoryDump* pmd) { |
45 const uint64 rss_bytes = rss_bytes_for_testing | 48 const uint64 rss_bytes = rss_bytes_for_testing |
46 ? rss_bytes_for_testing | 49 ? rss_bytes_for_testing |
47 : process_metrics_->GetWorkingSetSize(); | 50 : process_metrics_->GetWorkingSetSize(); |
48 pmd->process_totals()->set_resident_set_bytes(rss_bytes); | 51 |
49 pmd->set_has_process_totals(); | 52 if (rss_bytes > 0) { |
| 53 pmd->process_totals()->set_resident_set_bytes(rss_bytes); |
| 54 pmd->set_has_process_totals(); |
| 55 return true; |
| 56 } |
| 57 |
| 58 return false; |
| 59 } |
| 60 |
| 61 const char* ProcessMemoryTotalsDumpProvider::GetFriendlyName() const { |
| 62 return kDumperFriendlyName; |
50 } | 63 } |
51 | 64 |
52 } // namespace trace_event | 65 } // namespace trace_event |
53 } // namespace base | 66 } // namespace base |
OLD | NEW |