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 #ifndef BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ |
| 6 #define BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "base/atomicops.h" |
| 11 #include "base/memory/singleton.h" |
| 12 #include "base/synchronization/lock.h" |
| 13 #include "base/trace_event/trace_event.h" |
| 14 |
| 15 namespace base { |
| 16 namespace trace_event { |
| 17 |
| 18 class MemoryDumpProvider; |
| 19 |
| 20 // Captures the reason why a dump point is being requested. This is to allow |
| 21 // selective enabling of dump points, filtering and post-processing. |
| 22 enum class DumpPointType { |
| 23 TASK_BEGIN, // Dumping memory at the beginning of a message-loop task. |
| 24 TASK_END, // Dumping memory at the ending of a message-loop task. |
| 25 PERIODIC_INTERVAL, // Dumping memory at periodic intervals. |
| 26 EXPLICITLY_TRIGGERED, // Non maskable dump request. |
| 27 }; |
| 28 |
| 29 // This is the interface exposed to the rest of the codebase to deal with |
| 30 // memory tracing. The main entry point for clients is represented by |
| 31 // RequestDumpPoint(). The extension by Un(RegisterDumpProvider). |
| 32 class BASE_EXPORT MemoryDumpManager : public TraceLog::EnabledStateObserver { |
| 33 public: |
| 34 static MemoryDumpManager* GetInstance(); |
| 35 |
| 36 // Invoked once per process to register the TraceLog observer. |
| 37 void Initialize(); |
| 38 |
| 39 // MemoryDumpManager does NOT take memory ownership of |mdp|, which is |
| 40 // expected to be a singleton. |
| 41 void RegisterDumpProvider(MemoryDumpProvider* mdp); |
| 42 void UnregisterDumpProvider(MemoryDumpProvider* mdp); |
| 43 |
| 44 // Requests a memory dump. The dump might happen or not depending on the |
| 45 // filters and categories specified when enabling tracing. |
| 46 void RequestDumpPoint(DumpPointType type); |
| 47 |
| 48 // TraceLog::EnabledStateObserver implementation. |
| 49 void OnTraceLogEnabled() override; |
| 50 void OnTraceLogDisabled() override; |
| 51 |
| 52 private: |
| 53 friend struct DefaultSingletonTraits<MemoryDumpManager>; |
| 54 friend class MemoryDumpManagerTest; |
| 55 |
| 56 static const char kTraceCategory[]; |
| 57 |
| 58 MemoryDumpManager(); |
| 59 virtual ~MemoryDumpManager(); |
| 60 |
| 61 // Tears down the singleton instance. |
| 62 static void DeleteForTesting(); |
| 63 |
| 64 // Broadcasts the dump requests to the other processes. |
| 65 void BroadcastDumpRequest(); |
| 66 |
| 67 // Creates a dump point for the current process and appends it to the trace. |
| 68 void CreateLocalDumpPoint(); |
| 69 |
| 70 std::vector<MemoryDumpProvider*> dump_providers_registered_; // Not owned. |
| 71 std::vector<MemoryDumpProvider*> dump_providers_enabled_; // Not owned. |
| 72 |
| 73 // Protects from concurrent accesses to the |dump_providers_*|, e.g., tearing |
| 74 // down logging while creating a dump point on another thread. |
| 75 Lock lock_; |
| 76 |
| 77 // Optimization to avoid attempting any dump point (i.e. to not walk an empty |
| 78 // dump_providers_enabled_ list) when tracing is not enabled. |
| 79 subtle::AtomicWord memory_tracing_enabled_; |
| 80 |
| 81 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManager); |
| 82 }; |
| 83 |
| 84 } // namespace trace_event |
| 85 } // namespace base |
| 86 |
| 87 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ |
OLD | NEW |