| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 MemoryDumpProviderInfo::OrderedSet dump_providers_for_polling_; | 361 MemoryDumpProviderInfo::OrderedSet dump_providers_for_polling_; |
| 365 | 362 |
| 366 // Shared among all the PMDs to keep state scoped to the tracing session. | 363 // Shared among all the PMDs to keep state scoped to the tracing session. |
| 367 scoped_refptr<MemoryDumpSessionState> session_state_; | 364 scoped_refptr<MemoryDumpSessionState> session_state_; |
| 368 | 365 |
| 369 // The list of names of dump providers that are blacklisted from strict thread | 366 // The list of names of dump providers that are blacklisted from strict thread |
| 370 // affinity check on unregistration. | 367 // affinity check on unregistration. |
| 371 std::unordered_set<StringPiece, StringPieceHash> | 368 std::unordered_set<StringPiece, StringPieceHash> |
| 372 strict_thread_check_blacklist_; | 369 strict_thread_check_blacklist_; |
| 373 | 370 |
| 374 MemoryDumpManagerDelegate* delegate_; // Not owned. | 371 std::unique_ptr<MemoryDumpManagerDelegate> delegate_; |
| 375 | |
| 376 // When true, this instance is in charge of coordinating periodic dumps. | |
| 377 bool is_coordinator_; | |
| 378 | 372 |
| 379 // Protects from concurrent accesses to the |dump_providers_*| and |delegate_| | 373 // Protects from concurrent accesses to the |dump_providers_*| and |delegate_| |
| 380 // to guard against disabling logging while dumping on another thread. | 374 // to guard against disabling logging while dumping on another thread. |
| 381 Lock lock_; | 375 Lock lock_; |
| 382 | 376 |
| 383 // Optimization to avoid attempting any memory dump (i.e. to not walk an empty | 377 // Optimization to avoid attempting any memory dump (i.e. to not walk an empty |
| 384 // dump_providers_enabled_ list) when tracing is not enabled. | 378 // dump_providers_enabled_ list) when tracing is not enabled. |
| 385 subtle::AtomicWord memory_tracing_enabled_; | 379 subtle::AtomicWord memory_tracing_enabled_; |
| 386 | 380 |
| 387 // For time-triggered periodic dumps. | 381 // For time-triggered periodic dumps. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 404 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManager); | 398 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManager); |
| 405 }; | 399 }; |
| 406 | 400 |
| 407 // The delegate is supposed to be long lived (read: a Singleton) and thread | 401 // 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). | 402 // safe (i.e. should expect calls from any thread and handle thread hopping). |
| 409 class BASE_EXPORT MemoryDumpManagerDelegate { | 403 class BASE_EXPORT MemoryDumpManagerDelegate { |
| 410 public: | 404 public: |
| 411 virtual void RequestGlobalMemoryDump(const MemoryDumpRequestArgs& args, | 405 virtual void RequestGlobalMemoryDump(const MemoryDumpRequestArgs& args, |
| 412 const MemoryDumpCallback& callback) = 0; | 406 const MemoryDumpCallback& callback) = 0; |
| 413 | 407 |
| 408 virtual bool IsCoordinator() const = 0; |
| 409 |
| 414 // Returns tracing process id of the current process. This is used by | 410 // Returns tracing process id of the current process. This is used by |
| 415 // MemoryDumpManager::GetTracingProcessId. | 411 // MemoryDumpManager::GetTracingProcessId. |
| 416 virtual uint64_t GetTracingProcessId() const = 0; | 412 virtual uint64_t GetTracingProcessId() const = 0; |
| 417 | 413 |
| 418 protected: | 414 protected: |
| 415 friend std::default_delete<MemoryDumpManagerDelegate>; |
| 416 |
| 419 MemoryDumpManagerDelegate() {} | 417 MemoryDumpManagerDelegate() {} |
| 420 virtual ~MemoryDumpManagerDelegate() {} | 418 virtual ~MemoryDumpManagerDelegate() {} |
| 421 | 419 |
| 422 void CreateProcessDump(const MemoryDumpRequestArgs& args, | 420 void CreateProcessDump(const MemoryDumpRequestArgs& args, |
| 423 const MemoryDumpCallback& callback) { | 421 const MemoryDumpCallback& callback) { |
| 424 MemoryDumpManager::GetInstance()->CreateProcessDump(args, callback); | 422 MemoryDumpManager::GetInstance()->CreateProcessDump(args, callback); |
| 425 } | 423 } |
| 426 | 424 |
| 427 private: | 425 private: |
| 428 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); | 426 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); |
| 429 }; | 427 }; |
| 430 | 428 |
| 431 } // namespace trace_event | 429 } // namespace trace_event |
| 432 } // namespace base | 430 } // namespace base |
| 433 | 431 |
| 434 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ | 432 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ |
| OLD | NEW |