Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Unified Diff: base/trace_event/memory_dump_manager.h

Issue 1222153004: [tracing] Simplify and improve thread-hopping logic of memory-infra (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Re dsinclair #7 Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/trace_event/memory_dump_manager.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 0718d32e9525ad3527a4e914f2033b2f9d8ec623..92c5cb867dbd1f664abee0e3271238566c71ad15 100644
--- a/base/trace_event/memory_dump_manager.h
+++ b/base/trace_event/memory_dump_manager.h
@@ -5,7 +5,7 @@
#ifndef BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_
#define BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_
-#include <vector>
+#include <set>
#include "base/atomicops.h"
#include "base/containers/hash_tables.h"
@@ -14,6 +14,7 @@
#include "base/synchronization/lock.h"
#include "base/timer/timer.h"
#include "base/trace_event/memory_dump_request_args.h"
+#include "base/trace_event/process_memory_dump.h"
#include "base/trace_event/trace_event.h"
namespace base {
@@ -22,13 +23,8 @@ class SingleThreadTaskRunner;
namespace trace_event {
-namespace {
-class ProcessMemoryDumpHolder;
-}
-
class MemoryDumpManagerDelegate;
class MemoryDumpProvider;
-class ProcessMemoryDump;
class MemoryDumpSessionState;
// This is the interface exposed to the rest of the codebase to deal with
@@ -99,32 +95,81 @@ class BASE_EXPORT MemoryDumpManager : public TraceLog::EnabledStateObserver {
uint64 tracing_process_id() const { return tracing_process_id_; }
private:
+ friend struct DefaultDeleter<MemoryDumpManager>; // For the testing instance.
+ friend struct DefaultSingletonTraits<MemoryDumpManager>;
+ friend class MemoryDumpManagerDelegate;
+ friend class MemoryDumpManagerTest;
+ FRIEND_TEST_ALL_PREFIXES(MemoryDumpManagerTest, DisableFailingDumpers);
+
// Descriptor struct used to hold information about registered MDPs. It is
- // deliberately copyable, in order to allow to be used as hash_map value.
+ // deliberately copyable, in order to allow it to be used as std::set value.
struct MemoryDumpProviderInfo {
MemoryDumpProviderInfo(
+ MemoryDumpProvider* dump_provider,
const scoped_refptr<SingleThreadTaskRunner>& task_runner);
~MemoryDumpProviderInfo();
+ // Define a total order based on the thread (i.e. |task_runner|) affinity,
+ // so that all MDP belonging to the same thread are adjacent in the set.
+ bool operator<(const MemoryDumpProviderInfo& other) const;
+
+ MemoryDumpProvider* const dump_provider;
scoped_refptr<SingleThreadTaskRunner> task_runner; // Optional.
- int consecutive_failures; // Number of times the provider failed (to
- // disable the MDPs).
- bool disabled; // For fail-safe logic (auto-disable failing MDPs).
+
+ // For fail-safe logic (auto-disable failing MDPs). These fields are mutable
+ // as can be safely changed without impacting the order within the set.
+ mutable int consecutive_failures;
+ mutable bool disabled;
};
- friend struct DefaultDeleter<MemoryDumpManager>; // For the testing instance.
- friend struct DefaultSingletonTraits<MemoryDumpManager>;
- friend class MemoryDumpManagerDelegate;
- friend class MemoryDumpManagerTest;
- FRIEND_TEST_ALL_PREFIXES(MemoryDumpManagerTest, DisableFailingDumpers);
+ using MemoryDumpProviderInfoSet = std::set<MemoryDumpProviderInfo>;
- static const int kMaxConsecutiveFailuresCount;
+ // Holds the state of a process memory dump that needs to be carried over
+ // across threads in order to fulfil an asynchronous CreateProcessDump()
+ // request. At any time exactly one thread owns a ProcessMemoryDumpAsyncState.
+ struct ProcessMemoryDumpAsyncState {
+ ProcessMemoryDumpAsyncState(
+ MemoryDumpRequestArgs req_args,
+ MemoryDumpProviderInfoSet::iterator next_dump_provider,
+ const scoped_refptr<MemoryDumpSessionState>& session_state,
+ MemoryDumpCallback callback);
+ ~ProcessMemoryDumpAsyncState();
- static void SetInstanceForTesting(MemoryDumpManager* instance);
+ // The ProcessMemoryDump container, where each dump provider will dump its
+ // own MemoryAllocatorDump(s) upon the OnMemoryDump() call.
+ ProcessMemoryDump process_memory_dump;
+
+ // The arguments passed to the initial CreateProcessDump() request.
+ const MemoryDumpRequestArgs req_args;
+
+ // The |dump_providers_| iterator to the next dump provider that should be
+ // invoked (or dump_providers_.end() if at the end of the sequence).
+ MemoryDumpProviderInfoSet::iterator next_dump_provider;
+
+ // Callback passed to the initial call to CreateProcessDump().
+ MemoryDumpCallback callback;
+
+ // The thread on which FinalizeDumpAndAddToTrace() (and hence |callback|)
+ // should be invoked. This is the thread on which the initial
+ // CreateProcessDump() request was called.
+ const scoped_refptr<SingleThreadTaskRunner> task_runner;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ProcessMemoryDumpAsyncState);
+ };
+
+ static const int kMaxConsecutiveFailuresCount;
MemoryDumpManager();
virtual ~MemoryDumpManager();
+ static void SetInstanceForTesting(MemoryDumpManager* instance);
+ static void FinalizeDumpAndAddToTrace(
+ scoped_ptr<ProcessMemoryDumpAsyncState> pmd_async_state);
+ static void AbortDumpLocked(MemoryDumpCallback callback,
+ scoped_refptr<SingleThreadTaskRunner> task_runner,
+ uint64 dump_guid);
+
// 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
@@ -132,11 +177,10 @@ class BASE_EXPORT MemoryDumpManager : public TraceLog::EnabledStateObserver {
void CreateProcessDump(const MemoryDumpRequestArgs& args,
const MemoryDumpCallback& callback);
- bool InvokeDumpProviderLocked(MemoryDumpProvider* mdp,
- ProcessMemoryDump* pmd);
+ // Continues the ProcessMemoryDump started by CreateProcessDump(), hopping
+ // across threads as needed as specified by MDPs in RegisterDumpProvider().
void ContinueAsyncProcessDump(
- MemoryDumpProvider* mdp,
- scoped_refptr<ProcessMemoryDumpHolder> pmd_holder);
+ scoped_ptr<ProcessMemoryDumpAsyncState> pmd_async_state);
// Pass kInvalidTracingProcessId to invalidate the id.
void set_tracing_process_id(uint64 id) {
@@ -145,7 +189,13 @@ class BASE_EXPORT MemoryDumpManager : public TraceLog::EnabledStateObserver {
tracing_process_id_ = id;
}
- hash_map<MemoryDumpProvider*, MemoryDumpProviderInfo> dump_providers_;
+ // An ordererd set of registered MemoryDumpProviderInfo(s), sorted by thread
+ // affinity (MDPs belonging to the same thread are adjacent).
+ MemoryDumpProviderInfoSet dump_providers_;
+
+ // Flag used to signal that some provider was removed from |dump_providers_|
+ // and therefore the current memory dump (if any) should be aborted.
+ bool did_unregister_dump_provider_;
// Shared among all the PMDs to keep state scoped to the tracing session.
scoped_refptr<MemoryDumpSessionState> session_state_;
« no previous file with comments | « no previous file | base/trace_event/memory_dump_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698