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

Side by Side Diff: base/trace_event/memory_dump_manager.h

Issue 1173263004: [tracing] Send unique tracing process id for cross-process memory dumps identification. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing DCHECK while setting id. Created 5 years, 6 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 unified diff | Download patch
OLDNEW
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 <vector> 8 #include <vector>
9 9
10 #include "base/atomicops.h" 10 #include "base/atomicops.h"
(...skipping 18 matching lines...) Expand all
29 class MemoryDumpManagerDelegate; 29 class MemoryDumpManagerDelegate;
30 class MemoryDumpProvider; 30 class MemoryDumpProvider;
31 class ProcessMemoryDump; 31 class ProcessMemoryDump;
32 class MemoryDumpSessionState; 32 class MemoryDumpSessionState;
33 33
34 // This is the interface exposed to the rest of the codebase to deal with 34 // This is the interface exposed to the rest of the codebase to deal with
35 // memory tracing. The main entry point for clients is represented by 35 // memory tracing. The main entry point for clients is represented by
36 // RequestDumpPoint(). The extension by Un(RegisterDumpProvider). 36 // RequestDumpPoint(). The extension by Un(RegisterDumpProvider).
37 class BASE_EXPORT MemoryDumpManager : public TraceLog::EnabledStateObserver { 37 class BASE_EXPORT MemoryDumpManager : public TraceLog::EnabledStateObserver {
38 public: 38 public:
39 static const int kInvalidTracingProcessId;
39 static const char* const kTraceCategoryForTesting; 40 static const char* const kTraceCategoryForTesting;
40 41
41 static MemoryDumpManager* GetInstance(); 42 static MemoryDumpManager* GetInstance();
42 43
43 // Invoked once per process to register the TraceLog observer. 44 // Invoked once per process to register the TraceLog observer.
44 void Initialize(); 45 void Initialize();
45 46
46 // See the lifetime and thread-safety requirements on the delegate below in 47 // See the lifetime and thread-safety requirements on the delegate below in
47 // the |MemoryDumpManagerDelegate| docstring. 48 // the |MemoryDumpManagerDelegate| docstring.
48 void SetDelegate(MemoryDumpManagerDelegate* delegate); 49 void SetDelegate(MemoryDumpManagerDelegate* delegate);
(...skipping 25 matching lines...) Expand all
74 void OnTraceLogEnabled() override; 75 void OnTraceLogEnabled() override;
75 void OnTraceLogDisabled() override; 76 void OnTraceLogDisabled() override;
76 77
77 // Returns the MemoryDumpSessionState object, which is shared by all the 78 // Returns the MemoryDumpSessionState object, which is shared by all the
78 // ProcessMemoryDump and MemoryAllocatorDump instances through all the tracing 79 // ProcessMemoryDump and MemoryAllocatorDump instances through all the tracing
79 // session lifetime. 80 // session lifetime.
80 const scoped_refptr<MemoryDumpSessionState>& session_state() const { 81 const scoped_refptr<MemoryDumpSessionState>& session_state() const {
81 return session_state_; 82 return session_state_;
82 } 83 }
83 84
85 // Derives a tracing process id from a child process id. Child process ids
86 // cannot be used directly in tracing for security reasons (see: discussion in
87 // crrev.com/1173263004). This method is meant to be used when dumping
88 // cross-process shared memory from a process which knows the child process id
89 // of its endpoints. The value returned by this method is guaranteed to be
90 // equal to the value returned by tracing_process_id() in the corresponding
91 // child process.
92 static int ChildProcessIdToTracingProcessId(int child_id);
93
94 // Returns a unique id for the current process. The id can be retrieved only
95 // by child processes and only when tracing is enabled. This is intended to
96 // express cross-process sharing of memory dumps on the child-process side,
97 // without having to know its own child process id.
98 int tracing_process_id() const {
99 DCHECK_NE(kInvalidTracingProcessId, tracing_process_id_);
100 return tracing_process_id_;
101 }
102
84 private: 103 private:
85 // Descriptor struct used to hold information about registered MDPs. It is 104 // Descriptor struct used to hold information about registered MDPs. It is
86 // deliberately copyable, in order to allow to be used as hash_map value. 105 // deliberately copyable, in order to allow to be used as hash_map value.
87 struct MemoryDumpProviderInfo { 106 struct MemoryDumpProviderInfo {
88 MemoryDumpProviderInfo( 107 MemoryDumpProviderInfo(
89 const scoped_refptr<SingleThreadTaskRunner>& task_runner); 108 const scoped_refptr<SingleThreadTaskRunner>& task_runner);
90 ~MemoryDumpProviderInfo(); 109 ~MemoryDumpProviderInfo();
91 110
92 scoped_refptr<SingleThreadTaskRunner> task_runner; // Optional. 111 scoped_refptr<SingleThreadTaskRunner> task_runner; // Optional.
93 int consecutive_failures; // Number of times the provider failed (to 112 int consecutive_failures; // Number of times the provider failed (to
(...skipping 20 matching lines...) Expand all
114 // thread on which CreateProcessDump() was called. 133 // thread on which CreateProcessDump() was called.
115 void CreateProcessDump(const MemoryDumpRequestArgs& args, 134 void CreateProcessDump(const MemoryDumpRequestArgs& args,
116 const MemoryDumpCallback& callback); 135 const MemoryDumpCallback& callback);
117 136
118 bool InvokeDumpProviderLocked(MemoryDumpProvider* mdp, 137 bool InvokeDumpProviderLocked(MemoryDumpProvider* mdp,
119 ProcessMemoryDump* pmd); 138 ProcessMemoryDump* pmd);
120 void ContinueAsyncProcessDump( 139 void ContinueAsyncProcessDump(
121 MemoryDumpProvider* mdp, 140 MemoryDumpProvider* mdp,
122 scoped_refptr<ProcessMemoryDumpHolder> pmd_holder); 141 scoped_refptr<ProcessMemoryDumpHolder> pmd_holder);
123 142
143 // Pass kInvalidTracingProcessId for invalidating the id.
144 void set_tracing_process_id(int id) {
145 DCHECK(tracing_process_id_ == kInvalidTracingProcessId ||
146 id == kInvalidTracingProcessId ||
147 tracing_process_id_ == id);
148 tracing_process_id_ = id;
149 }
150
124 hash_map<MemoryDumpProvider*, MemoryDumpProviderInfo> dump_providers_; 151 hash_map<MemoryDumpProvider*, MemoryDumpProviderInfo> dump_providers_;
125 152
126 // Shared among all the PMDs to keep state scoped to the tracing session. 153 // Shared among all the PMDs to keep state scoped to the tracing session.
127 scoped_refptr<MemoryDumpSessionState> session_state_; 154 scoped_refptr<MemoryDumpSessionState> session_state_;
128 155
129 MemoryDumpManagerDelegate* delegate_; // Not owned. 156 MemoryDumpManagerDelegate* delegate_; // Not owned.
130 157
131 // Protects from concurrent accesses to the |dump_providers_*| and |delegate_| 158 // Protects from concurrent accesses to the |dump_providers_*| and |delegate_|
132 // to guard against disabling logging while dumping on another thread. 159 // to guard against disabling logging while dumping on another thread.
133 Lock lock_; 160 Lock lock_;
134 161
135 // Optimization to avoid attempting any memory dump (i.e. to not walk an empty 162 // Optimization to avoid attempting any memory dump (i.e. to not walk an empty
136 // dump_providers_enabled_ list) when tracing is not enabled. 163 // dump_providers_enabled_ list) when tracing is not enabled.
137 subtle::AtomicWord memory_tracing_enabled_; 164 subtle::AtomicWord memory_tracing_enabled_;
138 165
139 // For time-triggered periodic dumps. 166 // For time-triggered periodic dumps.
140 RepeatingTimer<MemoryDumpManager> periodic_dump_timer_; 167 RepeatingTimer<MemoryDumpManager> periodic_dump_timer_;
141 168
169 // The unique id of the child process. This is created only for tracing and is
170 // expected to be valid only when tracing is enabled.
171 int tracing_process_id_;
172
142 // Skips the auto-registration of the core dumpers during Initialize(). 173 // Skips the auto-registration of the core dumpers during Initialize().
143 bool skip_core_dumpers_auto_registration_for_testing_; 174 bool skip_core_dumpers_auto_registration_for_testing_;
144 175
145 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManager); 176 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManager);
146 }; 177 };
147 178
148 // The delegate is supposed to be long lived (read: a Singleton) and thread 179 // The delegate is supposed to be long lived (read: a Singleton) and thread
149 // safe (i.e. should expect calls from any thread and handle thread hopping). 180 // safe (i.e. should expect calls from any thread and handle thread hopping).
150 class BASE_EXPORT MemoryDumpManagerDelegate { 181 class BASE_EXPORT MemoryDumpManagerDelegate {
151 public: 182 public:
152 virtual void RequestGlobalMemoryDump(const MemoryDumpRequestArgs& args, 183 virtual void RequestGlobalMemoryDump(const MemoryDumpRequestArgs& args,
153 const MemoryDumpCallback& callback) = 0; 184 const MemoryDumpCallback& callback) = 0;
154 185
155 // Determines whether the MemoryDumpManager instance should be the master 186 // Determines whether the MemoryDumpManager instance should be the master
156 // (the ones which initiates and coordinates the multiprocess dumps) or not. 187 // (the ones which initiates and coordinates the multiprocess dumps) or not.
157 virtual bool IsCoordinatorProcess() const = 0; 188 virtual bool IsCoordinatorProcess() const = 0;
158 189
159 protected: 190 protected:
160 MemoryDumpManagerDelegate() {} 191 MemoryDumpManagerDelegate() {}
161 virtual ~MemoryDumpManagerDelegate() {} 192 virtual ~MemoryDumpManagerDelegate() {}
162 193
163 void CreateProcessDump(const MemoryDumpRequestArgs& args, 194 void CreateProcessDump(const MemoryDumpRequestArgs& args,
164 const MemoryDumpCallback& callback) { 195 const MemoryDumpCallback& callback) {
165 MemoryDumpManager::GetInstance()->CreateProcessDump(args, callback); 196 MemoryDumpManager::GetInstance()->CreateProcessDump(args, callback);
166 } 197 }
167 198
199 void set_tracing_process_id(int id) {
200 MemoryDumpManager::GetInstance()->set_tracing_process_id(id);
201 }
202
168 private: 203 private:
169 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); 204 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate);
170 }; 205 };
171 206
172 } // namespace trace_event 207 } // namespace trace_event
173 } // namespace base 208 } // namespace base
174 209
175 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ 210 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_
OLDNEW
« no previous file with comments | « no previous file | base/trace_event/memory_dump_manager.cc » ('j') | base/trace_event/memory_dump_manager.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698