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/memory_dump_manager.h" | 5 #include "base/trace_event/memory_dump_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/atomic_sequence_num.h" | 9 #include "base/atomic_sequence_num.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 | 49 |
50 void RequestPeriodicGlobalDump() { | 50 void RequestPeriodicGlobalDump() { |
51 MemoryDumpArgs::LevelOfDetail dump_level_of_detail; | 51 MemoryDumpArgs::LevelOfDetail dump_level_of_detail; |
52 if (g_heavy_dumps_rate == 0) { | 52 if (g_heavy_dumps_rate == 0) { |
53 dump_level_of_detail = MemoryDumpArgs::LevelOfDetail::LOW; | 53 dump_level_of_detail = MemoryDumpArgs::LevelOfDetail::LOW; |
54 } else { | 54 } else { |
55 dump_level_of_detail = g_periodic_dumps_count == 0 | 55 dump_level_of_detail = g_periodic_dumps_count == 0 |
56 ? MemoryDumpArgs::LevelOfDetail::HIGH | 56 ? MemoryDumpArgs::LevelOfDetail::HIGH |
57 : MemoryDumpArgs::LevelOfDetail::LOW; | 57 : MemoryDumpArgs::LevelOfDetail::LOW; |
58 | 58 |
59 if (++g_periodic_dumps_count == g_heavy_dumps_rate) | 59 if (++g_periodic_dumps_count == g_heavy_dumps_rate - 1) |
60 g_periodic_dumps_count = 0; | 60 g_periodic_dumps_count = 0; |
61 } | 61 } |
62 | 62 |
63 MemoryDumpArgs dump_args = {dump_level_of_detail}; | 63 MemoryDumpArgs dump_args = {dump_level_of_detail}; |
64 MemoryDumpManager::GetInstance()->RequestGlobalDump( | 64 MemoryDumpManager::GetInstance()->RequestGlobalDump( |
65 MemoryDumpType::PERIODIC_INTERVAL, dump_args); | 65 MemoryDumpType::PERIODIC_INTERVAL, dump_args); |
66 } | 66 } |
67 | 67 |
68 } // namespace | 68 } // namespace |
69 | 69 |
70 // static | 70 // static |
71 const char* const MemoryDumpManager::kTraceCategory = | 71 const char* const MemoryDumpManager::kTraceCategory = |
72 TRACE_DISABLED_BY_DEFAULT("memory-infra"); | 72 TRACE_DISABLED_BY_DEFAULT("memory-infra"); |
73 | 73 |
74 // static | 74 // static |
75 const int MemoryDumpManager::kMaxConsecutiveFailuresCount = 3; | 75 const int MemoryDumpManager::kMaxConsecutiveFailuresCount = 3; |
76 | 76 |
77 // static | 77 // static |
78 const uint64 MemoryDumpManager::kInvalidTracingProcessId = 0; | 78 const uint64 MemoryDumpManager::kInvalidTracingProcessId = 0; |
79 | 79 |
80 // static | 80 // static |
| 81 const char* const MemoryDumpManager::kSystemAllocatorPoolName = |
| 82 #if defined(OS_LINUX) || defined(OS_ANDROID) |
| 83 MallocDumpProvider::kAllocatedObjects; |
| 84 #elif defined(OS_WIN) |
| 85 WinHeapDumpProvider::kAllocatedObjects; |
| 86 #else |
| 87 nullptr; |
| 88 #endif |
| 89 |
| 90 |
| 91 // static |
81 MemoryDumpManager* MemoryDumpManager::GetInstance() { | 92 MemoryDumpManager* MemoryDumpManager::GetInstance() { |
82 if (g_instance_for_testing) | 93 if (g_instance_for_testing) |
83 return g_instance_for_testing; | 94 return g_instance_for_testing; |
84 | 95 |
85 return Singleton<MemoryDumpManager, | 96 return Singleton<MemoryDumpManager, |
86 LeakySingletonTraits<MemoryDumpManager>>::get(); | 97 LeakySingletonTraits<MemoryDumpManager>>::get(); |
87 } | 98 } |
88 | 99 |
89 // static | 100 // static |
90 void MemoryDumpManager::SetInstanceForTesting(MemoryDumpManager* instance) { | 101 void MemoryDumpManager::SetInstanceForTesting(MemoryDumpManager* instance) { |
91 if (instance) | 102 if (instance) |
92 instance->skip_core_dumpers_auto_registration_for_testing_ = true; | 103 instance->skip_core_dumpers_auto_registration_for_testing_ = true; |
93 g_instance_for_testing = instance; | 104 g_instance_for_testing = instance; |
94 } | 105 } |
95 | 106 |
96 MemoryDumpManager::MemoryDumpManager() | 107 MemoryDumpManager::MemoryDumpManager() |
97 : delegate_(nullptr), | 108 : delegate_(nullptr), |
98 memory_tracing_enabled_(0), | 109 memory_tracing_enabled_(0), |
99 tracing_process_id_(kInvalidTracingProcessId), | 110 tracing_process_id_(kInvalidTracingProcessId), |
100 system_allocator_pool_name_(nullptr), | |
101 skip_core_dumpers_auto_registration_for_testing_(false), | 111 skip_core_dumpers_auto_registration_for_testing_(false), |
102 disable_periodic_dumps_for_testing_(false) { | 112 disable_periodic_dumps_for_testing_(false) { |
103 g_next_guid.GetNext(); // Make sure that first guid is not zero. | 113 g_next_guid.GetNext(); // Make sure that first guid is not zero. |
104 } | 114 } |
105 | 115 |
106 MemoryDumpManager::~MemoryDumpManager() { | 116 MemoryDumpManager::~MemoryDumpManager() { |
107 base::trace_event::TraceLog::GetInstance()->RemoveEnabledStateObserver(this); | 117 TraceLog::GetInstance()->RemoveEnabledStateObserver(this); |
108 } | 118 } |
109 | 119 |
110 void MemoryDumpManager::Initialize() { | 120 void MemoryDumpManager::Initialize() { |
111 TRACE_EVENT0(kTraceCategory, "init"); // Add to trace-viewer category list. | 121 TRACE_EVENT0(kTraceCategory, "init"); // Add to trace-viewer category list. |
112 trace_event::TraceLog::GetInstance()->AddEnabledStateObserver(this); | |
113 | 122 |
114 if (skip_core_dumpers_auto_registration_for_testing_) | 123 TraceLog::GetInstance()->AddEnabledStateObserver(this); |
115 return; | |
116 | 124 |
117 // Enable the core dump providers. | 125 // Enable the core dump providers. |
| 126 if (!skip_core_dumpers_auto_registration_for_testing_) { |
118 #if !defined(OS_NACL) | 127 #if !defined(OS_NACL) |
119 RegisterDumpProvider(ProcessMemoryTotalsDumpProvider::GetInstance()); | 128 RegisterDumpProvider(ProcessMemoryTotalsDumpProvider::GetInstance()); |
120 #endif | 129 #endif |
121 | 130 |
122 #if defined(OS_LINUX) || defined(OS_ANDROID) | 131 #if defined(OS_LINUX) || defined(OS_ANDROID) |
123 RegisterDumpProvider(ProcessMemoryMapsDumpProvider::GetInstance()); | 132 RegisterDumpProvider(ProcessMemoryMapsDumpProvider::GetInstance()); |
124 RegisterDumpProvider(MallocDumpProvider::GetInstance()); | 133 RegisterDumpProvider(MallocDumpProvider::GetInstance()); |
125 system_allocator_pool_name_ = MallocDumpProvider::kAllocatedObjects; | |
126 #endif | 134 #endif |
127 | 135 |
128 #if defined(OS_ANDROID) | 136 #if defined(OS_ANDROID) |
129 RegisterDumpProvider(JavaHeapDumpProvider::GetInstance()); | 137 RegisterDumpProvider(JavaHeapDumpProvider::GetInstance()); |
130 #endif | 138 #endif |
131 | 139 |
132 #if defined(OS_WIN) | 140 #if defined(OS_WIN) |
133 RegisterDumpProvider(WinHeapDumpProvider::GetInstance()); | 141 RegisterDumpProvider(WinHeapDumpProvider::GetInstance()); |
134 system_allocator_pool_name_ = WinHeapDumpProvider::kAllocatedObjects; | |
135 #endif | 142 #endif |
| 143 } // !skip_core_dumpers_auto_registration_for_testing_ |
136 } | 144 } |
137 | 145 |
138 void MemoryDumpManager::SetDelegate(MemoryDumpManagerDelegate* delegate) { | 146 void MemoryDumpManager::SetDelegate(MemoryDumpManagerDelegate* delegate) { |
139 AutoLock lock(lock_); | 147 AutoLock lock(lock_); |
140 DCHECK_EQ(static_cast<MemoryDumpManagerDelegate*>(nullptr), delegate_); | 148 DCHECK_EQ(static_cast<MemoryDumpManagerDelegate*>(nullptr), delegate_); |
141 delegate_ = delegate; | 149 delegate_ = delegate; |
142 } | 150 } |
143 | 151 |
144 void MemoryDumpManager::RegisterDumpProvider( | 152 void MemoryDumpManager::RegisterDumpProvider( |
145 MemoryDumpProvider* mdp, | 153 MemoryDumpProvider* mdp, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 if (!UNLIKELY(subtle::NoBarrier_Load(&memory_tracing_enabled_))) { | 204 if (!UNLIKELY(subtle::NoBarrier_Load(&memory_tracing_enabled_))) { |
197 if (!callback.is_null()) | 205 if (!callback.is_null()) |
198 callback.Run(0u /* guid */, false /* success */); | 206 callback.Run(0u /* guid */, false /* success */); |
199 return; | 207 return; |
200 } | 208 } |
201 | 209 |
202 const uint64 guid = | 210 const uint64 guid = |
203 TraceLog::GetInstance()->MangleEventId(g_next_guid.GetNext()); | 211 TraceLog::GetInstance()->MangleEventId(g_next_guid.GetNext()); |
204 | 212 |
205 // The delegate_ is supposed to be thread safe, immutable and long lived. | 213 // The delegate_ is supposed to be thread safe, immutable and long lived. |
206 // No need to keep the lock after we ensure that a delegate has been set. | 214 // No need to keep the lock after we ensured that a delegate has been set. |
207 MemoryDumpManagerDelegate* delegate; | 215 MemoryDumpManagerDelegate* delegate; |
208 { | 216 { |
209 AutoLock lock(lock_); | 217 AutoLock lock(lock_); |
210 delegate = delegate_; | 218 delegate = delegate_; |
211 } | 219 } |
212 | 220 |
213 if (delegate) { | 221 if (delegate) { |
214 // The delegate is in charge to coordinate the request among all the | 222 // The delegate is in charge to coordinate the request among all the |
215 // processes and call the CreateLocalDumpPoint on the local process. | 223 // processes and call the CreateLocalDumpPoint on the local process. |
216 MemoryDumpRequestArgs args = {guid, dump_type, dump_args}; | 224 MemoryDumpRequestArgs args = {guid, dump_type, dump_args}; |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 next_dump_provider(next_dump_provider), | 504 next_dump_provider(next_dump_provider), |
497 callback(callback), | 505 callback(callback), |
498 task_runner(MessageLoop::current()->task_runner()) { | 506 task_runner(MessageLoop::current()->task_runner()) { |
499 } | 507 } |
500 | 508 |
501 MemoryDumpManager::ProcessMemoryDumpAsyncState::~ProcessMemoryDumpAsyncState() { | 509 MemoryDumpManager::ProcessMemoryDumpAsyncState::~ProcessMemoryDumpAsyncState() { |
502 } | 510 } |
503 | 511 |
504 } // namespace trace_event | 512 } // namespace trace_event |
505 } // namespace base | 513 } // namespace base |
OLD | NEW |