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 <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <set> | 10 #include <set> |
11 #include <vector> | |
11 | 12 |
12 #include "base/atomicops.h" | 13 #include "base/atomicops.h" |
13 #include "base/containers/hash_tables.h" | 14 #include "base/containers/hash_tables.h" |
14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
15 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
16 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
17 #include "base/timer/timer.h" | 18 #include "base/timer/timer.h" |
18 #include "base/trace_event/memory_dump_request_args.h" | 19 #include "base/trace_event/memory_dump_request_args.h" |
19 #include "base/trace_event/process_memory_dump.h" | 20 #include "base/trace_event/process_memory_dump.h" |
20 #include "base/trace_event/trace_event.h" | 21 #include "base/trace_event/trace_event.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 MemoryDumpProvider* mdp, | 74 MemoryDumpProvider* mdp, |
74 const char* name, | 75 const char* name, |
75 const scoped_refptr<SingleThreadTaskRunner>& task_runner); | 76 const scoped_refptr<SingleThreadTaskRunner>& task_runner); |
76 void RegisterDumpProvider( | 77 void RegisterDumpProvider( |
77 MemoryDumpProvider* mdp, | 78 MemoryDumpProvider* mdp, |
78 const char* name, | 79 const char* name, |
79 const scoped_refptr<SingleThreadTaskRunner>& task_runner, | 80 const scoped_refptr<SingleThreadTaskRunner>& task_runner, |
80 const MemoryDumpProvider::Options& options); | 81 const MemoryDumpProvider::Options& options); |
81 void UnregisterDumpProvider(MemoryDumpProvider* mdp); | 82 void UnregisterDumpProvider(MemoryDumpProvider* mdp); |
82 | 83 |
84 // Unregisters an unbound (no task_runner affinity) dump provider and takes | |
85 // care about its deletion asynchronously. | |
86 // Can be used only for for dump providers with no task-runner affinity. | |
87 // This method takes ownership of the dump provider and guarantees that: | |
88 // - The |mdp| will be deleted at some point in the near future. | |
89 // - Its deletion will not happen concurrently with the OnMemoryDump() call. | |
Ruud van Asseldonk
2015/12/14 16:25:49
/s/concurrently/in parallel/?
| |
90 // Note that OnMemoryDump() calls can still happen after this method returns. | |
91 void UnregisterAndDeleteDumpProviderAsync(scoped_ptr<MemoryDumpProvider> mdp); | |
Ruud van Asseldonk
2015/12/14 16:25:48
This feels like an awkward API. It looks like what
| |
92 | |
83 // Requests a memory dump. The dump might happen or not depending on the | 93 // Requests a memory dump. The dump might happen or not depending on the |
84 // filters and categories specified when enabling tracing. | 94 // filters and categories specified when enabling tracing. |
85 // The optional |callback| is executed asynchronously, on an arbitrary thread, | 95 // The optional |callback| is executed asynchronously, on an arbitrary thread, |
86 // to notify about the completion of the global dump (i.e. after all the | 96 // to notify about the completion of the global dump (i.e. after all the |
87 // processes have dumped) and its success (true iff all the dumps were | 97 // processes have dumped) and its success (true iff all the dumps were |
88 // successful). | 98 // successful). |
89 void RequestGlobalDump(MemoryDumpType dump_type, | 99 void RequestGlobalDump(MemoryDumpType dump_type, |
90 MemoryDumpLevelOfDetail level_of_detail, | 100 MemoryDumpLevelOfDetail level_of_detail, |
91 const MemoryDumpCallback& callback); | 101 const MemoryDumpCallback& callback); |
92 | 102 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 | 229 |
220 static const int kMaxConsecutiveFailuresCount; | 230 static const int kMaxConsecutiveFailuresCount; |
221 static const char* const kSystemAllocatorPoolName; | 231 static const char* const kSystemAllocatorPoolName; |
222 | 232 |
223 MemoryDumpManager(); | 233 MemoryDumpManager(); |
224 ~MemoryDumpManager() override; | 234 ~MemoryDumpManager() override; |
225 | 235 |
226 static void SetInstanceForTesting(MemoryDumpManager* instance); | 236 static void SetInstanceForTesting(MemoryDumpManager* instance); |
227 static void FinalizeDumpAndAddToTrace( | 237 static void FinalizeDumpAndAddToTrace( |
228 scoped_ptr<ProcessMemoryDumpAsyncState> pmd_async_state); | 238 scoped_ptr<ProcessMemoryDumpAsyncState> pmd_async_state); |
229 static void AbortDumpLocked(MemoryDumpCallback callback, | |
230 scoped_refptr<SingleThreadTaskRunner> task_runner, | |
231 uint64_t dump_guid); | |
232 | 239 |
233 // Internal, used only by MemoryDumpManagerDelegate. | 240 // Internal, used only by MemoryDumpManagerDelegate. |
234 // Creates a memory dump for the current process and appends it to the trace. | 241 // Creates a memory dump for the current process and appends it to the trace. |
235 // |callback| will be invoked asynchronously upon completion on the same | 242 // |callback| will be invoked asynchronously upon completion on the same |
236 // thread on which CreateProcessDump() was called. | 243 // thread on which CreateProcessDump() was called. |
237 void CreateProcessDump(const MemoryDumpRequestArgs& args, | 244 void CreateProcessDump(const MemoryDumpRequestArgs& args, |
238 const MemoryDumpCallback& callback); | 245 const MemoryDumpCallback& callback); |
239 | 246 |
240 // Continues the ProcessMemoryDump started by CreateProcessDump(), hopping | 247 // Continues the ProcessMemoryDump started by CreateProcessDump(), hopping |
241 // across threads as needed as specified by MDPs in RegisterDumpProvider(). | 248 // across threads as needed as specified by MDPs in RegisterDumpProvider(). |
242 void ContinueAsyncProcessDump( | 249 void ContinueAsyncProcessDump( |
243 scoped_ptr<ProcessMemoryDumpAsyncState> pmd_async_state); | 250 ProcessMemoryDumpAsyncState* owned_pmd_async_state); |
251 | |
252 void UnregisterDumpProviderInternal(MemoryDumpProvider* mdp, | |
253 bool delete_async); | |
Ruud van Asseldonk
2015/12/14 16:25:48
This is ambiguous; does |delete_async = false| mea
| |
244 | 254 |
245 // An ordererd set of registered MemoryDumpProviderInfo(s), sorted by thread | 255 // An ordererd set of registered MemoryDumpProviderInfo(s), sorted by thread |
246 // affinity (MDPs belonging to the same thread are adjacent). | 256 // affinity (MDPs belonging to the same thread are adjacent). |
247 MemoryDumpProviderInfoSet dump_providers_; | 257 MemoryDumpProviderInfoSet dump_providers_; |
248 | 258 |
249 // Shared among all the PMDs to keep state scoped to the tracing session. | 259 // Shared among all the PMDs to keep state scoped to the tracing session. |
250 scoped_refptr<MemoryDumpSessionState> session_state_; | 260 scoped_refptr<MemoryDumpSessionState> session_state_; |
251 | 261 |
252 MemoryDumpManagerDelegate* delegate_; // Not owned. | 262 MemoryDumpManagerDelegate* delegate_; // Not owned. |
253 | 263 |
254 // When true, this instance is in charge of coordinating periodic dumps. | 264 // When true, this instance is in charge of coordinating periodic dumps. |
255 bool is_coordinator_; | 265 bool is_coordinator_; |
256 | 266 |
267 // Contains one entry per each dump that has been started (via | |
Ruud van Asseldonk
2015/12/14 16:25:49
Nit: "per" or "for each", not "per each".
| |
268 // CreateProcessDump()) and is not completed yet. | |
269 // Only the const members of the stores ProcessMemoryDumpAsyncState are safe | |
Ruud van Asseldonk
2015/12/14 16:25:49
/s/stores/stored/?
| |
270 // to read and only while holding the |lock_|. | |
Ruud van Asseldonk
2015/12/14 16:25:49
That is a violation of the general |const| contrac
| |
271 std::vector<const ProcessMemoryDumpAsyncState*> outstanding_dumps_; | |
272 | |
257 // Protects from concurrent accesses to the |dump_providers_*| and |delegate_| | 273 // Protects from concurrent accesses to the |dump_providers_*| and |delegate_| |
258 // to guard against disabling logging while dumping on another thread. | 274 // to guard against disabling logging while dumping on another thread. |
259 Lock lock_; | 275 Lock lock_; |
260 | 276 |
261 // Optimization to avoid attempting any memory dump (i.e. to not walk an empty | 277 // Optimization to avoid attempting any memory dump (i.e. to not walk an empty |
262 // dump_providers_enabled_ list) when tracing is not enabled. | 278 // dump_providers_enabled_ list) when tracing is not enabled. |
263 subtle::AtomicWord memory_tracing_enabled_; | 279 subtle::AtomicWord memory_tracing_enabled_; |
264 | 280 |
265 // For time-triggered periodic dumps. | 281 // For time-triggered periodic dumps. |
266 RepeatingTimer periodic_dump_timer_; | 282 RepeatingTimer periodic_dump_timer_; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
302 } | 318 } |
303 | 319 |
304 private: | 320 private: |
305 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); | 321 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); |
306 }; | 322 }; |
307 | 323 |
308 } // namespace trace_event | 324 } // namespace trace_event |
309 } // namespace base | 325 } // namespace base |
310 | 326 |
311 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ | 327 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ |
OLD | NEW |