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 #ifndef BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ | 5 #ifndef BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ |
6 #define BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ | 6 #define BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/atomicops.h" | 10 #include "base/atomicops.h" |
11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
15 #include "base/timer/timer.h" | 15 #include "base/timer/timer.h" |
16 #include "base/trace_event/memory_dump_request_args.h" | 16 #include "base/trace_event/memory_dump_request_args.h" |
17 #include "base/trace_event/process_memory_dump.h" | 17 #include "base/trace_event/process_memory_dump.h" |
18 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
19 | 19 |
20 namespace content { | |
21 class MemoryTracingTest; | |
Primiano Tucci (use gerrit)
2015/08/24 17:23:34
Hmm no, base should never know anything about cont
Ruud van Asseldonk
2015/08/25 09:51:17
I made |ignore_dumper_registrations_for_testing()|
| |
22 } | |
23 | |
20 namespace base { | 24 namespace base { |
21 | 25 |
22 class SingleThreadTaskRunner; | 26 class SingleThreadTaskRunner; |
23 | 27 |
24 namespace trace_event { | 28 namespace trace_event { |
25 | 29 |
26 class MemoryDumpManagerDelegate; | 30 class MemoryDumpManagerDelegate; |
27 class MemoryDumpProvider; | 31 class MemoryDumpProvider; |
28 class MemoryDumpSessionState; | 32 class MemoryDumpSessionState; |
29 | 33 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 // Tells the initialization phase to skip scheduling periodic memory dumps. | 104 // Tells the initialization phase to skip scheduling periodic memory dumps. |
101 void DisablePeriodicDumpsForTesting() { | 105 void DisablePeriodicDumpsForTesting() { |
102 disable_periodic_dumps_for_testing_ = true; | 106 disable_periodic_dumps_for_testing_ = true; |
103 } | 107 } |
104 | 108 |
105 private: | 109 private: |
106 friend struct DefaultDeleter<MemoryDumpManager>; // For the testing instance. | 110 friend struct DefaultDeleter<MemoryDumpManager>; // For the testing instance. |
107 friend struct DefaultSingletonTraits<MemoryDumpManager>; | 111 friend struct DefaultSingletonTraits<MemoryDumpManager>; |
108 friend class MemoryDumpManagerDelegate; | 112 friend class MemoryDumpManagerDelegate; |
109 friend class MemoryDumpManagerTest; | 113 friend class MemoryDumpManagerTest; |
114 friend class content::MemoryTracingTest; | |
110 FRIEND_TEST_ALL_PREFIXES(MemoryDumpManagerTest, DisableFailingDumpers); | 115 FRIEND_TEST_ALL_PREFIXES(MemoryDumpManagerTest, DisableFailingDumpers); |
111 FRIEND_TEST_ALL_PREFIXES(MemoryDumpManagerTest, | 116 FRIEND_TEST_ALL_PREFIXES(MemoryDumpManagerTest, |
112 UnregisterDumperFromThreadWhileDumping); | 117 UnregisterDumperFromThreadWhileDumping); |
113 | 118 |
114 // Descriptor struct used to hold information about registered MDPs. It is | 119 // Descriptor struct used to hold information about registered MDPs. It is |
115 // deliberately copyable, in order to allow it to be used as std::set value. | 120 // deliberately copyable, in order to allow it to be used as std::set value. |
116 struct MemoryDumpProviderInfo { | 121 struct MemoryDumpProviderInfo { |
117 MemoryDumpProviderInfo( | 122 MemoryDumpProviderInfo( |
118 MemoryDumpProvider* dump_provider, | 123 MemoryDumpProvider* dump_provider, |
119 const scoped_refptr<SingleThreadTaskRunner>& task_runner); | 124 const scoped_refptr<SingleThreadTaskRunner>& task_runner); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 // affinity (MDPs belonging to the same thread are adjacent). | 206 // affinity (MDPs belonging to the same thread are adjacent). |
202 MemoryDumpProviderInfoSet dump_providers_; | 207 MemoryDumpProviderInfoSet dump_providers_; |
203 | 208 |
204 // Shared among all the PMDs to keep state scoped to the tracing session. | 209 // Shared among all the PMDs to keep state scoped to the tracing session. |
205 scoped_refptr<MemoryDumpSessionState> session_state_; | 210 scoped_refptr<MemoryDumpSessionState> session_state_; |
206 | 211 |
207 MemoryDumpManagerDelegate* delegate_; // Not owned. | 212 MemoryDumpManagerDelegate* delegate_; // Not owned. |
208 | 213 |
209 // Protects from concurrent accesses to the |dump_providers_*| and |delegate_| | 214 // Protects from concurrent accesses to the |dump_providers_*| and |delegate_| |
210 // to guard against disabling logging while dumping on another thread. | 215 // to guard against disabling logging while dumping on another thread. |
211 Lock lock_; | 216 mutable Lock lock_; |
Primiano Tucci (use gerrit)
2015/08/24 17:23:34
See comment below, you don't need to use the lock
| |
212 | 217 |
213 // Optimization to avoid attempting any memory dump (i.e. to not walk an empty | 218 // Optimization to avoid attempting any memory dump (i.e. to not walk an empty |
214 // dump_providers_enabled_ list) when tracing is not enabled. | 219 // dump_providers_enabled_ list) when tracing is not enabled. |
215 subtle::AtomicWord memory_tracing_enabled_; | 220 subtle::AtomicWord memory_tracing_enabled_; |
216 | 221 |
217 // For time-triggered periodic dumps. | 222 // For time-triggered periodic dumps. |
218 RepeatingTimer<MemoryDumpManager> periodic_dump_timer_; | 223 RepeatingTimer<MemoryDumpManager> periodic_dump_timer_; |
219 | 224 |
220 // The unique id of the child process. This is created only for tracing and is | 225 // The unique id of the child process. This is created only for tracing and is |
221 // expected to be valid only when tracing is enabled. | 226 // expected to be valid only when tracing is enabled. |
222 uint64 tracing_process_id_; | 227 uint64 tracing_process_id_; |
223 | 228 |
224 // Name of the allocated_objects dump. | 229 // Name of the allocated_objects dump. |
225 const char* system_allocator_pool_name_; | 230 const char* system_allocator_pool_name_; |
226 | 231 |
227 // Skips the auto-registration of the core dumpers during Initialize(). | 232 // When true, calling RegisterMemoryDumpProvider is a no-op. |
228 bool skip_core_dumpers_auto_registration_for_testing_; | 233 bool ignore_registrations_for_testing_; |
Primiano Tucci (use gerrit)
2015/08/24 17:23:34
I'd name this (and the setter) ignore_dumper_regis
Ruud van Asseldonk
2015/08/25 09:51:17
Done.
| |
234 | |
235 bool ignore_registrations_for_testing() const { | |
236 AutoLock lock(lock_); | |
Primiano Tucci (use gerrit)
2015/08/24 17:23:34
If this was production code would have been fine.
Ruud van Asseldonk
2015/08/25 09:51:17
It is used in |MemoryDumpManagerTest::EnableTracin
| |
237 return ignore_registrations_for_testing_; | |
238 } | |
239 | |
240 void set_ignore_registrations_for_testing(bool ignore) { | |
241 AutoLock lock(lock_); | |
242 ignore_registrations_for_testing_ = ignore; | |
243 } | |
229 | 244 |
230 // When true, the initialization phase does not start the periodic memory | 245 // When true, the initialization phase does not start the periodic memory |
231 // dumps. | 246 // dumps. |
232 // TODO(primiano): This should go into TraceConfig. https://goo.gl/5Hj3o0. | 247 // TODO(primiano): This should go into TraceConfig. https://goo.gl/5Hj3o0. |
233 bool disable_periodic_dumps_for_testing_; | 248 bool disable_periodic_dumps_for_testing_; |
234 | 249 |
235 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManager); | 250 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManager); |
236 }; | 251 }; |
237 | 252 |
238 // The delegate is supposed to be long lived (read: a Singleton) and thread | 253 // The delegate is supposed to be long lived (read: a Singleton) and thread |
(...skipping 21 matching lines...) Expand all Loading... | |
260 } | 275 } |
261 | 276 |
262 private: | 277 private: |
263 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); | 278 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); |
264 }; | 279 }; |
265 | 280 |
266 } // namespace trace_event | 281 } // namespace trace_event |
267 } // namespace base | 282 } // namespace base |
268 | 283 |
269 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ | 284 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ |
OLD | NEW |