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 25 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); |
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 // session lifetime. | 122 // session lifetime. |
126 const scoped_refptr<MemoryDumpSessionState>& session_state_for_testing() | 123 const scoped_refptr<MemoryDumpSessionState>& session_state_for_testing() |
127 const { | 124 const { |
128 return session_state_; | 125 return session_state_; |
129 } | 126 } |
130 | 127 |
131 // Returns a unique id for identifying the processes. The id can be | 128 // Returns a unique id for identifying the processes. The id can be |
132 // retrieved by child processes only when tracing is enabled. This is | 129 // retrieved by child processes only when tracing is enabled. This is |
133 // intended to express cross-process sharing of memory dumps on the | 130 // intended to express cross-process sharing of memory dumps on the |
134 // child-process side, without having to know its own child process id. | 131 // child-process side, without having to know its own child process id. |
135 uint64_t GetTracingProcessId() const; | 132 uint64_t tracing_process_id() const; |
oystein (OOO til 10th of July)
2017/02/16 20:50:00
You can just inline these two.
chiniforooshan
2017/02/16 22:54:14
Done.
| |
133 void set_tracing_process_id(uint64_t tracing_process_id); | |
136 | 134 |
137 // Returns the name for a the allocated_objects dump. Use this to declare | 135 // Returns the name for a the allocated_objects dump. Use this to declare |
138 // suballocator dumps from other dump providers. | 136 // suballocator dumps from other dump providers. |
139 // It will return nullptr if there is no dump provider for the system | 137 // It will return nullptr if there is no dump provider for the system |
140 // allocator registered (which is currently the case for Mac OS). | 138 // allocator registered (which is currently the case for Mac OS). |
141 const char* system_allocator_pool_name() const { | 139 const char* system_allocator_pool_name() const { |
142 return kSystemAllocatorPoolName; | 140 return kSystemAllocatorPoolName; |
143 }; | 141 }; |
144 | 142 |
145 // When set to true, calling |RegisterMemoryDumpProvider| is a no-op. | 143 // When set to true, calling |RegisterMemoryDumpProvider| is a no-op. |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 MemoryDumpProviderInfo::OrderedSet dump_providers_for_polling_; | 362 MemoryDumpProviderInfo::OrderedSet dump_providers_for_polling_; |
365 | 363 |
366 // Shared among all the PMDs to keep state scoped to the tracing session. | 364 // Shared among all the PMDs to keep state scoped to the tracing session. |
367 scoped_refptr<MemoryDumpSessionState> session_state_; | 365 scoped_refptr<MemoryDumpSessionState> session_state_; |
368 | 366 |
369 // The list of names of dump providers that are blacklisted from strict thread | 367 // The list of names of dump providers that are blacklisted from strict thread |
370 // affinity check on unregistration. | 368 // affinity check on unregistration. |
371 std::unordered_set<StringPiece, StringPieceHash> | 369 std::unordered_set<StringPiece, StringPieceHash> |
372 strict_thread_check_blacklist_; | 370 strict_thread_check_blacklist_; |
373 | 371 |
374 MemoryDumpManagerDelegate* delegate_; // Not owned. | 372 std::unique_ptr<MemoryDumpManagerDelegate> delegate_; |
375 | |
376 // When true, this instance is in charge of coordinating periodic dumps. | |
377 bool is_coordinator_; | |
378 | 373 |
379 // Protects from concurrent accesses to the |dump_providers_*| and |delegate_| | 374 // Protects from concurrent accesses to the |dump_providers_*| and |delegate_| |
380 // to guard against disabling logging while dumping on another thread. | 375 // to guard against disabling logging while dumping on another thread. |
381 Lock lock_; | 376 Lock lock_; |
382 | 377 |
383 // Optimization to avoid attempting any memory dump (i.e. to not walk an empty | 378 // Optimization to avoid attempting any memory dump (i.e. to not walk an empty |
384 // dump_providers_enabled_ list) when tracing is not enabled. | 379 // dump_providers_enabled_ list) when tracing is not enabled. |
385 subtle::AtomicWord memory_tracing_enabled_; | 380 subtle::AtomicWord memory_tracing_enabled_; |
386 | 381 |
387 // For time-triggered periodic dumps. | 382 // For time-triggered periodic dumps. |
(...skipping 16 matching lines...) Expand all Loading... | |
404 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManager); | 399 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManager); |
405 }; | 400 }; |
406 | 401 |
407 // The delegate is supposed to be long lived (read: a Singleton) and thread | 402 // 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). | 403 // safe (i.e. should expect calls from any thread and handle thread hopping). |
409 class BASE_EXPORT MemoryDumpManagerDelegate { | 404 class BASE_EXPORT MemoryDumpManagerDelegate { |
410 public: | 405 public: |
411 virtual void RequestGlobalMemoryDump(const MemoryDumpRequestArgs& args, | 406 virtual void RequestGlobalMemoryDump(const MemoryDumpRequestArgs& args, |
412 const MemoryDumpCallback& callback) = 0; | 407 const MemoryDumpCallback& callback) = 0; |
413 | 408 |
414 // Returns tracing process id of the current process. This is used by | 409 virtual bool IsCoordinator() const = 0; |
415 // MemoryDumpManager::GetTracingProcessId. | |
416 virtual uint64_t GetTracingProcessId() const = 0; | |
417 | 410 |
418 protected: | 411 protected: |
412 friend std::default_delete<MemoryDumpManagerDelegate>; | |
413 | |
419 MemoryDumpManagerDelegate() {} | 414 MemoryDumpManagerDelegate() {} |
420 virtual ~MemoryDumpManagerDelegate() {} | 415 virtual ~MemoryDumpManagerDelegate() {} |
421 | 416 |
422 void CreateProcessDump(const MemoryDumpRequestArgs& args, | 417 void CreateProcessDump(const MemoryDumpRequestArgs& args, |
423 const MemoryDumpCallback& callback) { | 418 const MemoryDumpCallback& callback) { |
424 MemoryDumpManager::GetInstance()->CreateProcessDump(args, callback); | 419 MemoryDumpManager::GetInstance()->CreateProcessDump(args, callback); |
425 } | 420 } |
426 | 421 |
427 private: | 422 private: |
428 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); | 423 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); |
429 }; | 424 }; |
430 | 425 |
431 } // namespace trace_event | 426 } // namespace trace_event |
432 } // namespace base | 427 } // namespace base |
433 | 428 |
434 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ | 429 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ |
OLD | NEW |