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 <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 21 matching lines...) Expand all Loading... | |
32 | 32 |
33 } // namespace memory_instrumentation | 33 } // namespace memory_instrumentation |
34 | 34 |
35 namespace base { | 35 namespace base { |
36 | 36 |
37 class SingleThreadTaskRunner; | 37 class SingleThreadTaskRunner; |
38 class Thread; | 38 class Thread; |
39 | 39 |
40 namespace trace_event { | 40 namespace trace_event { |
41 | 41 |
42 class MemoryTracingObserver; | |
42 class MemoryDumpManagerDelegate; | 43 class MemoryDumpManagerDelegate; |
43 class MemoryDumpProvider; | 44 class MemoryDumpProvider; |
44 class MemoryDumpSessionState; | 45 class MemoryDumpSessionState; |
45 | 46 |
46 // This is the interface exposed to the rest of the codebase to deal with | 47 // This is the interface exposed to the rest of the codebase to deal with |
47 // memory tracing. The main entry point for clients is represented by | 48 // memory tracing. The main entry point for clients is represented by |
48 // RequestDumpPoint(). The extension by Un(RegisterDumpProvider). | 49 // RequestDumpPoint(). The extension by Un(RegisterDumpProvider). |
49 class BASE_EXPORT MemoryDumpManager : public TraceLog::EnabledStateObserver { | 50 class BASE_EXPORT MemoryDumpManager { |
50 public: | 51 public: |
51 static const char* const kTraceCategory; | 52 static const char* const kTraceCategory; |
52 static const char* const kLogPrefix; | 53 static const char* const kLogPrefix; |
53 | 54 |
54 // This value is returned as the tracing id of the child processes by | 55 // This value is returned as the tracing id of the child processes by |
55 // GetTracingProcessId() when tracing is not enabled. | 56 // GetTracingProcessId() when tracing is not enabled. |
56 static const uint64_t kInvalidTracingProcessId; | 57 static const uint64_t kInvalidTracingProcessId; |
57 | 58 |
58 static MemoryDumpManager* GetInstance(); | 59 static MemoryDumpManager* GetInstance(); |
59 | 60 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 // processes have dumped) and its success (true iff all the dumps were | 113 // processes have dumped) and its success (true iff all the dumps were |
113 // successful). | 114 // successful). |
114 void RequestGlobalDump(MemoryDumpType dump_type, | 115 void RequestGlobalDump(MemoryDumpType dump_type, |
115 MemoryDumpLevelOfDetail level_of_detail, | 116 MemoryDumpLevelOfDetail level_of_detail, |
116 const MemoryDumpCallback& callback); | 117 const MemoryDumpCallback& callback); |
117 | 118 |
118 // Same as above (still asynchronous), but without callback. | 119 // Same as above (still asynchronous), but without callback. |
119 void RequestGlobalDump(MemoryDumpType dump_type, | 120 void RequestGlobalDump(MemoryDumpType dump_type, |
120 MemoryDumpLevelOfDetail level_of_detail); | 121 MemoryDumpLevelOfDetail level_of_detail); |
121 | 122 |
122 // TraceLog::EnabledStateObserver implementation. | 123 // XXX |
Primiano Tucci (use gerrit)
2017/04/21 10:10:26
Can you add a comment explaining what Enable/Disab
hjd
2017/04/21 11:51:57
Done.
| |
123 void OnTraceLogEnabled() override; | 124 void Enable(const TraceConfig::MemoryDumpConfig&); |
124 void OnTraceLogDisabled() override; | 125 void Disable(); |
125 | 126 |
126 // Enable heap profiling if kEnableHeapProfiling is specified. | 127 // Enable heap profiling if kEnableHeapProfiling is specified. |
127 void EnableHeapProfilingIfNeeded(); | 128 void EnableHeapProfilingIfNeeded(); |
128 | 129 |
129 // Returns true if the dump mode is allowed for current tracing session. | 130 // Returns true if the dump mode is allowed for current tracing session. |
130 bool IsDumpModeAllowed(MemoryDumpLevelOfDetail dump_mode); | 131 bool IsDumpModeAllowed(MemoryDumpLevelOfDetail dump_mode); |
131 | 132 |
132 // Lets tests see if a dump provider is registered. | 133 // Lets tests see if a dump provider is registered. |
133 bool IsDumpProviderRegisteredForTesting(MemoryDumpProvider*); | 134 bool IsDumpProviderRegisteredForTesting(MemoryDumpProvider*); |
134 | 135 |
(...skipping 25 matching lines...) Expand all Loading... | |
160 // When set to true, calling |RegisterMemoryDumpProvider| is a no-op. | 161 // When set to true, calling |RegisterMemoryDumpProvider| is a no-op. |
161 void set_dumper_registrations_ignored_for_testing(bool ignored) { | 162 void set_dumper_registrations_ignored_for_testing(bool ignored) { |
162 dumper_registrations_ignored_for_testing_ = ignored; | 163 dumper_registrations_ignored_for_testing_ = ignored; |
163 } | 164 } |
164 | 165 |
165 private: | 166 private: |
166 friend std::default_delete<MemoryDumpManager>; // For the testing instance. | 167 friend std::default_delete<MemoryDumpManager>; // For the testing instance. |
167 friend struct DefaultSingletonTraits<MemoryDumpManager>; | 168 friend struct DefaultSingletonTraits<MemoryDumpManager>; |
168 friend class MemoryDumpManagerDelegate; | 169 friend class MemoryDumpManagerDelegate; |
169 friend class MemoryDumpManagerTest; | 170 friend class MemoryDumpManagerTest; |
171 friend class MockMemoryDumpManager; | |
Primiano Tucci (use gerrit)
2017/04/21 10:10:26
doesn't seem to be used anymore?
hjd
2017/04/21 11:51:57
Done.
| |
170 friend class memory_instrumentation::MemoryDumpManagerDelegateImplTest; | 172 friend class memory_instrumentation::MemoryDumpManagerDelegateImplTest; |
171 | 173 |
172 // Holds the state of a process memory dump that needs to be carried over | 174 // Holds the state of a process memory dump that needs to be carried over |
173 // across task runners in order to fulfil an asynchronous CreateProcessDump() | 175 // across task runners in order to fulfil an asynchronous CreateProcessDump() |
174 // request. At any time exactly one task runner owns a | 176 // request. At any time exactly one task runner owns a |
175 // ProcessMemoryDumpAsyncState. | 177 // ProcessMemoryDumpAsyncState. |
176 struct ProcessMemoryDumpAsyncState { | 178 struct ProcessMemoryDumpAsyncState { |
177 ProcessMemoryDumpAsyncState( | 179 ProcessMemoryDumpAsyncState( |
178 MemoryDumpRequestArgs req_args, | 180 MemoryDumpRequestArgs req_args, |
179 const MemoryDumpProviderInfo::OrderedSet& dump_providers, | 181 const MemoryDumpProviderInfo::OrderedSet& dump_providers, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 const scoped_refptr<SingleThreadTaskRunner> dump_thread_task_runner; | 225 const scoped_refptr<SingleThreadTaskRunner> dump_thread_task_runner; |
224 | 226 |
225 private: | 227 private: |
226 DISALLOW_COPY_AND_ASSIGN(ProcessMemoryDumpAsyncState); | 228 DISALLOW_COPY_AND_ASSIGN(ProcessMemoryDumpAsyncState); |
227 }; | 229 }; |
228 | 230 |
229 static const int kMaxConsecutiveFailuresCount; | 231 static const int kMaxConsecutiveFailuresCount; |
230 static const char* const kSystemAllocatorPoolName; | 232 static const char* const kSystemAllocatorPoolName; |
231 | 233 |
232 MemoryDumpManager(); | 234 MemoryDumpManager(); |
233 ~MemoryDumpManager() override; | 235 virtual ~MemoryDumpManager(); |
234 | 236 |
235 static void SetInstanceForTesting(MemoryDumpManager* instance); | 237 static void SetInstanceForTesting(MemoryDumpManager* instance); |
236 static uint32_t GetDumpsSumKb(const std::string&, const ProcessMemoryDump*); | 238 static uint32_t GetDumpsSumKb(const std::string&, const ProcessMemoryDump*); |
237 static void FinalizeDumpAndAddToTrace( | 239 static void FinalizeDumpAndAddToTrace( |
238 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state); | 240 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state); |
239 | 241 |
240 // Internal, used only by MemoryDumpManagerDelegate. | 242 // Internal, used only by MemoryDumpManagerDelegate. |
241 // Creates a memory dump for the current process and appends it to the trace. | 243 // Creates a memory dump for the current process and appends it to the trace. |
242 // |callback| will be invoked asynchronously upon completion on the same | 244 // |callback| will be invoked asynchronously upon completion on the same |
243 // thread on which CreateProcessDump() was called. | 245 // thread on which CreateProcessDump() was called. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 | 279 |
278 // Shared among all the PMDs to keep state scoped to the tracing session. | 280 // Shared among all the PMDs to keep state scoped to the tracing session. |
279 scoped_refptr<MemoryDumpSessionState> session_state_; | 281 scoped_refptr<MemoryDumpSessionState> session_state_; |
280 | 282 |
281 // The list of names of dump providers that are blacklisted from strict thread | 283 // The list of names of dump providers that are blacklisted from strict thread |
282 // affinity check on unregistration. | 284 // affinity check on unregistration. |
283 std::unordered_set<StringPiece, StringPieceHash> | 285 std::unordered_set<StringPiece, StringPieceHash> |
284 strict_thread_check_blacklist_; | 286 strict_thread_check_blacklist_; |
285 | 287 |
286 std::unique_ptr<MemoryDumpManagerDelegate> delegate_; | 288 std::unique_ptr<MemoryDumpManagerDelegate> delegate_; |
289 std::unique_ptr<MemoryTracingObserver> trace_log_observer_; | |
Primiano Tucci (use gerrit)
2017/04/21 10:10:26
I'd just call it tracing_observer_ to keep it cons
hjd
2017/04/21 11:51:57
Done.
| |
287 | 290 |
288 // Protects from concurrent accesses to the |dump_providers_*| and |delegate_| | 291 // Protects from concurrent accesses to the |dump_providers_*| and |delegate_| |
289 // to guard against disabling logging while dumping on another thread. | 292 // to guard against disabling logging while dumping on another thread. |
290 Lock lock_; | 293 Lock lock_; |
291 | 294 |
292 // Optimization to avoid attempting any memory dump (i.e. to not walk an empty | 295 // Optimization to avoid attempting any memory dump (i.e. to not walk an empty |
293 // dump_providers_enabled_ list) when tracing is not enabled. | 296 // dump_providers_enabled_ list) when tracing is not enabled. |
294 subtle::AtomicWord memory_tracing_enabled_; | 297 subtle::AtomicWord memory_tracing_enabled_; |
295 | 298 |
296 // Thread used for MemoryDumpProviders which don't specify a task runner | 299 // Thread used for MemoryDumpProviders which don't specify a task runner |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
329 } | 332 } |
330 | 333 |
331 private: | 334 private: |
332 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); | 335 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); |
333 }; | 336 }; |
334 | 337 |
335 } // namespace trace_event | 338 } // namespace trace_event |
336 } // namespace base | 339 } // namespace base |
337 | 340 |
338 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ | 341 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ |
OLD | NEW |