Index: base/trace_event/memory_dump_manager.h |
diff --git a/base/trace_event/memory_dump_manager.h b/base/trace_event/memory_dump_manager.h |
index d359a8c3e9722f8441c907d06a2ae3b91cc8b7c8..f29c68ad6c1a3064eea6f28f96b870b6c72954d5 100644 |
--- a/base/trace_event/memory_dump_manager.h |
+++ b/base/trace_event/memory_dump_manager.h |
@@ -24,11 +24,11 @@ |
#include "base/trace_event/process_memory_dump.h" |
#include "base/trace_event/trace_event.h" |
-// Forward declare |MemoryDumpManagerDelegateImplTest| so that we can make it a |
+// Forward declare |ProcessLocalDumpManagerImplTest| so that we can make it a |
// friend of |MemoryDumpManager| and give it access to |SetInstanceForTesting|. |
namespace memory_instrumentation { |
-class MemoryDumpManagerDelegateImplTest; |
+class ProcessLocalDumpManagerImplTest; |
} // namespace memory_instrumentation |
@@ -39,7 +39,6 @@ class Thread; |
namespace trace_event { |
-class MemoryDumpManagerDelegate; |
class MemoryDumpProvider; |
class MemoryDumpSessionState; |
@@ -48,6 +47,10 @@ class MemoryDumpSessionState; |
// RequestDumpPoint(). The extension by Un(RegisterDumpProvider). |
class BASE_EXPORT MemoryDumpManager : public TraceLog::EnabledStateObserver { |
public: |
+ using RequestGlobalDumpFunction = |
+ RepeatingCallback<void(const MemoryDumpRequestArgs& args, |
+ const GlobalMemoryDumpCallback& callback)>; |
+ |
static const char* const kTraceCategory; |
static const char* const kLogPrefix; |
@@ -63,10 +66,12 @@ class BASE_EXPORT MemoryDumpManager : public TraceLog::EnabledStateObserver { |
// On the other side, the MemoryDumpManager will not be fully operational |
// (i.e. will NACK any RequestGlobalMemoryDump()) until initialized. |
// Arguments: |
- // delegate: inversion-of-control interface for embedder-specific behaviors |
- // (multiprocess handshaking). See the lifetime and thread-safety |
- // requirements in the |MemoryDumpManagerDelegate| docstring. |
- void Initialize(std::unique_ptr<MemoryDumpManagerDelegate> delegate); |
+ // request_dump_function: Function to invoke a global dump. Global dump |
+ // involves embedder-specific behaviors like multiprocess handshaking. |
+ // is_coordinator: True when current process coodinates the periodic dump |
+ // triggering. |
+ void Initialize(RequestGlobalDumpFunction request_dump_function, |
+ bool is_coordinator); |
// (Un)Registers a MemoryDumpProvider instance. |
// Args: |
@@ -119,6 +124,14 @@ class BASE_EXPORT MemoryDumpManager : public TraceLog::EnabledStateObserver { |
void RequestGlobalDump(MemoryDumpType dump_type, |
MemoryDumpLevelOfDetail level_of_detail); |
+ // NOTE: Use RequestGlobalDump() to create memory dumps. Creates a memory dump |
+ // for the current process and appends it to the trace. |callback| will be |
+ // invoked asynchronously upon completion on the same thread on which |
+ // CreateProcessDump() was called. This method should only be used by the |
+ // embedder while creating a global memory dump. |
+ void CreateProcessDump(const MemoryDumpRequestArgs& args, |
+ const ProcessMemoryDumpCallback& callback); |
+ |
// TraceLog::EnabledStateObserver implementation. |
void OnTraceLogEnabled() override; |
void OnTraceLogDisabled() override; |
@@ -165,9 +178,8 @@ class BASE_EXPORT MemoryDumpManager : public TraceLog::EnabledStateObserver { |
private: |
friend std::default_delete<MemoryDumpManager>; // For the testing instance. |
friend struct DefaultSingletonTraits<MemoryDumpManager>; |
- friend class MemoryDumpManagerDelegate; |
friend class MemoryDumpManagerTest; |
- friend class memory_instrumentation::MemoryDumpManagerDelegateImplTest; |
+ friend class memory_instrumentation::ProcessLocalDumpManagerImplTest; |
// Holds the state of a process memory dump that needs to be carried over |
// across task runners in order to fulfil an asynchronous CreateProcessDump() |
@@ -237,13 +249,6 @@ class BASE_EXPORT MemoryDumpManager : public TraceLog::EnabledStateObserver { |
static void FinalizeDumpAndAddToTrace( |
std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state); |
- // Internal, used only by MemoryDumpManagerDelegate. |
- // Creates a memory dump for the current process and appends it to the trace. |
- // |callback| will be invoked asynchronously upon completion on the same |
- // thread on which CreateProcessDump() was called. |
- void CreateProcessDump(const MemoryDumpRequestArgs& args, |
- const ProcessMemoryDumpCallback& callback); |
- |
// Calls InvokeOnMemoryDump() for the next MDP on the task runner specified by |
// the MDP while registration. On failure to do so, skips and continues to |
// next MDP. |
@@ -283,10 +288,14 @@ class BASE_EXPORT MemoryDumpManager : public TraceLog::EnabledStateObserver { |
std::unordered_set<StringPiece, StringPieceHash> |
strict_thread_check_blacklist_; |
- std::unique_ptr<MemoryDumpManagerDelegate> delegate_; |
+ // Function provided by the embedder to handle global dump requests. |
+ RequestGlobalDumpFunction request_dump_function_; |
- // Protects from concurrent accesses to the |dump_providers_*| and |delegate_| |
- // to guard against disabling logging while dumping on another thread. |
+ // True when current process coordinates the periodic dump triggering. |
+ bool is_coordinator_; |
+ |
+ // Protects from concurrent accesses to the local state, eg: to guard against |
+ // disabling logging while dumping on another thread. |
Lock lock_; |
// Optimization to avoid attempting any memory dump (i.e. to not walk an empty |
@@ -310,29 +319,6 @@ class BASE_EXPORT MemoryDumpManager : public TraceLog::EnabledStateObserver { |
DISALLOW_COPY_AND_ASSIGN(MemoryDumpManager); |
}; |
-// The delegate is supposed to be long lived (read: a Singleton) and thread |
-// safe (i.e. should expect calls from any thread and handle thread hopping). |
-class BASE_EXPORT MemoryDumpManagerDelegate { |
- public: |
- MemoryDumpManagerDelegate() {} |
- virtual ~MemoryDumpManagerDelegate() {} |
- |
- virtual void RequestGlobalMemoryDump( |
- const MemoryDumpRequestArgs& args, |
- const GlobalMemoryDumpCallback& callback) = 0; |
- |
- virtual bool IsCoordinator() const = 0; |
- |
- protected: |
- void CreateProcessDump(const MemoryDumpRequestArgs& args, |
- const ProcessMemoryDumpCallback& callback) { |
- MemoryDumpManager::GetInstance()->CreateProcessDump(args, callback); |
- } |
- |
- private: |
- DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); |
-}; |
- |
} // namespace trace_event |
} // namespace base |