OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
Primiano Tucci (use gerrit)
2017/02/17 19:08:44
note this cl will very likely need to be rebased o
chiniforooshan
2017/02/22 05:16:34
Acknowledged.
| |
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> |
11 #include <memory> | 11 #include <memory> |
(...skipping 24 matching lines...) Expand all Loading... | |
36 | 36 |
37 // This is the interface exposed to the rest of the codebase to deal with | 37 // This is the interface exposed to the rest of the codebase to deal with |
38 // memory tracing. The main entry point for clients is represented by | 38 // memory tracing. The main entry point for clients is represented by |
39 // RequestDumpPoint(). The extension by Un(RegisterDumpProvider). | 39 // RequestDumpPoint(). The extension by Un(RegisterDumpProvider). |
40 class BASE_EXPORT MemoryDumpManager : public TraceLog::EnabledStateObserver { | 40 class BASE_EXPORT MemoryDumpManager : public TraceLog::EnabledStateObserver { |
41 public: | 41 public: |
42 static const char* const kTraceCategory; | 42 static const char* const kTraceCategory; |
43 static const char* const kLogPrefix; | 43 static const char* const kLogPrefix; |
44 | 44 |
45 // This value is returned as the tracing id of the child processes by | 45 // This value is returned as the tracing id of the child processes by |
46 // GetTracingProcessId() when tracing is not enabled. | 46 // tracing_process_id() when tracing is not enabled. |
47 static const uint64_t kInvalidTracingProcessId; | 47 static const uint64_t kInvalidTracingProcessId; |
48 | 48 |
49 static MemoryDumpManager* GetInstance(); | 49 static MemoryDumpManager* GetInstance(); |
50 | 50 |
51 // Invoked once per process to listen to trace begin / end events. | 51 // Invoked once per process to listen to trace begin / end events. |
52 // Initialization can happen after (Un)RegisterMemoryDumpProvider() calls | 52 // Initialization can happen after (Un)RegisterMemoryDumpProvider() calls |
53 // and the MemoryDumpManager guarantees to support this. | 53 // and the MemoryDumpManager guarantees to support this. |
54 // On the other side, the MemoryDumpManager will not be fully operational | 54 // On the other side, the MemoryDumpManager will not be fully operational |
55 // (i.e. will NACK any RequestGlobalMemoryDump()) until initialized. | 55 // (i.e. will NACK any RequestGlobalMemoryDump()) until initialized. |
56 // Arguments: | 56 // Arguments: |
57 // is_coordinator: if true this MemoryDumpManager instance will act as a | |
58 // coordinator and schedule periodic dumps (if enabled via TraceConfig); | |
59 // false when the MemoryDumpManager is initialized in a slave process. | |
60 // delegate: inversion-of-control interface for embedder-specific behaviors | 57 // delegate: inversion-of-control interface for embedder-specific behaviors |
61 // (multiprocess handshaking). See the lifetime and thread-safety | 58 // (multiprocess handshaking). See the lifetime and thread-safety |
62 // requirements in the |MemoryDumpManagerDelegate| docstring. | 59 // requirements in the |MemoryDumpManagerDelegate| docstring. |
63 void Initialize(MemoryDumpManagerDelegate* delegate, bool is_coordinator); | 60 void Initialize(std::unique_ptr<MemoryDumpManagerDelegate> delegate); |
Primiano Tucci (use gerrit)
2017/02/17 19:08:44
the MDM is a leaky singleton, passing ownership of
chiniforooshan
2017/02/22 05:16:34
Done.
| |
64 | 61 |
65 // (Un)Registers a MemoryDumpProvider instance. | 62 // (Un)Registers a MemoryDumpProvider instance. |
66 // Args: | 63 // Args: |
67 // - mdp: the MemoryDumpProvider instance to be registered. MemoryDumpManager | 64 // - mdp: the MemoryDumpProvider instance to be registered. MemoryDumpManager |
68 // does NOT take memory ownership of |mdp|, which is expected to either | 65 // does NOT take memory ownership of |mdp|, which is expected to either |
69 // be a singleton or unregister itself. | 66 // be a singleton or unregister itself. |
70 // - name: a friendly name (duplicates allowed). Used for debugging and | 67 // - name: a friendly name (duplicates allowed). Used for debugging and |
71 // run-time profiling of memory-infra internals. Must be a long-lived | 68 // run-time profiling of memory-infra internals. Must be a long-lived |
72 // C string. | 69 // C string. |
73 // - task_runner: either a SingleThreadTaskRunner or SequencedTaskRunner. All | 70 // - task_runner: either a SingleThreadTaskRunner or SequencedTaskRunner. All |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 // session lifetime. | 125 // session lifetime. |
129 const scoped_refptr<MemoryDumpSessionState>& session_state_for_testing() | 126 const scoped_refptr<MemoryDumpSessionState>& session_state_for_testing() |
130 const { | 127 const { |
131 return session_state_; | 128 return session_state_; |
132 } | 129 } |
133 | 130 |
134 // Returns a unique id for identifying the processes. The id can be | 131 // Returns a unique id for identifying the processes. The id can be |
135 // retrieved by child processes only when tracing is enabled. This is | 132 // retrieved by child processes only when tracing is enabled. This is |
136 // intended to express cross-process sharing of memory dumps on the | 133 // intended to express cross-process sharing of memory dumps on the |
137 // child-process side, without having to know its own child process id. | 134 // child-process side, without having to know its own child process id. |
138 uint64_t GetTracingProcessId() const; | 135 uint64_t tracing_process_id() const { return tracing_process_id_; } |
Primiano Tucci (use gerrit)
2017/02/17 19:08:44
Renaming this getter will require you a lot more o
chiniforooshan
2017/02/22 05:16:34
Done.
| |
136 void set_tracing_process_id(uint64_t tracing_process_id) { | |
137 tracing_process_id_ = tracing_process_id; | |
138 } | |
139 | 139 |
140 // Returns the name for a the allocated_objects dump. Use this to declare | 140 // Returns the name for a the allocated_objects dump. Use this to declare |
141 // suballocator dumps from other dump providers. | 141 // suballocator dumps from other dump providers. |
142 // It will return nullptr if there is no dump provider for the system | 142 // It will return nullptr if there is no dump provider for the system |
143 // allocator registered (which is currently the case for Mac OS). | 143 // allocator registered (which is currently the case for Mac OS). |
144 const char* system_allocator_pool_name() const { | 144 const char* system_allocator_pool_name() const { |
145 return kSystemAllocatorPoolName; | 145 return kSystemAllocatorPoolName; |
146 }; | 146 }; |
147 | 147 |
148 // When set to true, calling |RegisterMemoryDumpProvider| is a no-op. | 148 // When set to true, calling |RegisterMemoryDumpProvider| is a no-op. |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 MemoryDumpProviderInfo::OrderedSet dump_providers_for_polling_; | 364 MemoryDumpProviderInfo::OrderedSet dump_providers_for_polling_; |
365 | 365 |
366 // Shared among all the PMDs to keep state scoped to the tracing session. | 366 // Shared among all the PMDs to keep state scoped to the tracing session. |
367 scoped_refptr<MemoryDumpSessionState> session_state_; | 367 scoped_refptr<MemoryDumpSessionState> session_state_; |
368 | 368 |
369 // The list of names of dump providers that are blacklisted from strict thread | 369 // The list of names of dump providers that are blacklisted from strict thread |
370 // affinity check on unregistration. | 370 // affinity check on unregistration. |
371 std::unordered_set<StringPiece, StringPieceHash> | 371 std::unordered_set<StringPiece, StringPieceHash> |
372 strict_thread_check_blacklist_; | 372 strict_thread_check_blacklist_; |
373 | 373 |
374 MemoryDumpManagerDelegate* delegate_; // Not owned. | 374 std::unique_ptr<MemoryDumpManagerDelegate> delegate_; |
375 | |
376 // When true, this instance is in charge of coordinating periodic dumps. | |
377 bool is_coordinator_; | |
378 | 375 |
379 // Protects from concurrent accesses to the |dump_providers_*| and |delegate_| | 376 // Protects from concurrent accesses to the |dump_providers_*| and |delegate_| |
380 // to guard against disabling logging while dumping on another thread. | 377 // to guard against disabling logging while dumping on another thread. |
381 Lock lock_; | 378 Lock lock_; |
382 | 379 |
383 // Optimization to avoid attempting any memory dump (i.e. to not walk an empty | 380 // Optimization to avoid attempting any memory dump (i.e. to not walk an empty |
384 // dump_providers_enabled_ list) when tracing is not enabled. | 381 // dump_providers_enabled_ list) when tracing is not enabled. |
385 subtle::AtomicWord memory_tracing_enabled_; | 382 subtle::AtomicWord memory_tracing_enabled_; |
386 | 383 |
387 // For time-triggered periodic dumps. | 384 // For time-triggered periodic dumps. |
(...skipping 16 matching lines...) Expand all Loading... | |
404 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManager); | 401 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManager); |
405 }; | 402 }; |
406 | 403 |
407 // The delegate is supposed to be long lived (read: a Singleton) and thread | 404 // The delegate is supposed to be long lived (read: a Singleton) and thread |
408 // safe (i.e. should expect calls from any thread and handle thread hopping). | 405 // safe (i.e. should expect calls from any thread and handle thread hopping). |
409 class BASE_EXPORT MemoryDumpManagerDelegate { | 406 class BASE_EXPORT MemoryDumpManagerDelegate { |
410 public: | 407 public: |
411 virtual void RequestGlobalMemoryDump(const MemoryDumpRequestArgs& args, | 408 virtual void RequestGlobalMemoryDump(const MemoryDumpRequestArgs& args, |
412 const MemoryDumpCallback& callback) = 0; | 409 const MemoryDumpCallback& callback) = 0; |
413 | 410 |
414 // Returns tracing process id of the current process. This is used by | 411 virtual bool IsCoordinator() const = 0; |
415 // MemoryDumpManager::GetTracingProcessId. | |
416 virtual uint64_t GetTracingProcessId() const = 0; | |
417 | 412 |
418 protected: | 413 protected: |
414 friend std::default_delete<MemoryDumpManagerDelegate>; | |
415 | |
419 MemoryDumpManagerDelegate() {} | 416 MemoryDumpManagerDelegate() {} |
420 virtual ~MemoryDumpManagerDelegate() {} | 417 virtual ~MemoryDumpManagerDelegate() {} |
421 | 418 |
422 void CreateProcessDump(const MemoryDumpRequestArgs& args, | 419 void CreateProcessDump(const MemoryDumpRequestArgs& args, |
423 const MemoryDumpCallback& callback) { | 420 const MemoryDumpCallback& callback) { |
424 MemoryDumpManager::GetInstance()->CreateProcessDump(args, callback); | 421 MemoryDumpManager::GetInstance()->CreateProcessDump(args, callback); |
425 } | 422 } |
426 | 423 |
427 private: | 424 private: |
428 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); | 425 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); |
429 }; | 426 }; |
430 | 427 |
431 } // namespace trace_event | 428 } // namespace trace_event |
432 } // namespace base | 429 } // namespace base |
433 | 430 |
434 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ | 431 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ |
OLD | NEW |