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

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

Issue 2861133002: memory-infra: Move dump level check to observer and rename session state (Closed)
Patch Set: move comment Created 3 years, 7 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 <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 24 matching lines...) Expand all
35 namespace base { 35 namespace base {
36 36
37 class SequencedTaskRunner; 37 class SequencedTaskRunner;
38 class SingleThreadTaskRunner; 38 class SingleThreadTaskRunner;
39 class Thread; 39 class Thread;
40 40
41 namespace trace_event { 41 namespace trace_event {
42 42
43 class MemoryTracingObserver; 43 class MemoryTracingObserver;
44 class MemoryDumpProvider; 44 class MemoryDumpProvider;
45 class MemoryDumpSessionState; 45 class HeapProfilerSerializationState;
46 46
47 // This is the interface exposed to the rest of the codebase to deal with 47 // This is the interface exposed to the rest of the codebase to deal with
48 // memory tracing. The main entry point for clients is represented by 48 // memory tracing. The main entry point for clients is represented by
49 // RequestDumpPoint(). The extension by Un(RegisterDumpProvider). 49 // RequestDumpPoint(). The extension by Un(RegisterDumpProvider).
50 class BASE_EXPORT MemoryDumpManager { 50 class BASE_EXPORT MemoryDumpManager {
51 public: 51 public:
52 using RequestGlobalDumpFunction = 52 using RequestGlobalDumpFunction =
53 RepeatingCallback<void(const MemoryDumpRequestArgs& args, 53 RepeatingCallback<void(const MemoryDumpRequestArgs& args,
54 const GlobalMemoryDumpCallback& callback)>; 54 const GlobalMemoryDumpCallback& callback)>;
55 55
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 // for the current process and appends it to the trace. |callback| will be 140 // for the current process and appends it to the trace. |callback| will be
141 // invoked asynchronously upon completion on the same thread on which 141 // invoked asynchronously upon completion on the same thread on which
142 // CreateProcessDump() was called. This method should only be used by the 142 // CreateProcessDump() was called. This method should only be used by the
143 // embedder while creating a global memory dump. 143 // embedder while creating a global memory dump.
144 void CreateProcessDump(const MemoryDumpRequestArgs& args, 144 void CreateProcessDump(const MemoryDumpRequestArgs& args,
145 const ProcessMemoryDumpCallback& callback); 145 const ProcessMemoryDumpCallback& callback);
146 146
147 // Enable heap profiling if kEnableHeapProfiling is specified. 147 // Enable heap profiling if kEnableHeapProfiling is specified.
148 void EnableHeapProfilingIfNeeded(); 148 void EnableHeapProfilingIfNeeded();
149 149
150 // Returns true if the dump mode is allowed for current tracing session.
151 bool IsDumpModeAllowed(MemoryDumpLevelOfDetail dump_mode);
152
153 // Lets tests see if a dump provider is registered. 150 // Lets tests see if a dump provider is registered.
154 bool IsDumpProviderRegisteredForTesting(MemoryDumpProvider*); 151 bool IsDumpProviderRegisteredForTesting(MemoryDumpProvider*);
155 152
156 // Returns the MemoryDumpSessionState object, which is shared by all the 153 const scoped_refptr<HeapProfilerSerializationState>&
157 // ProcessMemoryDump and MemoryAllocatorDump instances through all the tracing 154 heap_profiler_serialization_state_for_testing() const {
158 // session lifetime. 155 return heap_profiler_serialization_state_;
159 const scoped_refptr<MemoryDumpSessionState>& session_state_for_testing()
160 const {
161 return session_state_;
162 } 156 }
163 157
164 // Returns a unique id for identifying the processes. The id can be 158 // Returns a unique id for identifying the processes. The id can be
165 // retrieved by child processes only when tracing is enabled. This is 159 // retrieved by child processes only when tracing is enabled. This is
166 // intended to express cross-process sharing of memory dumps on the 160 // intended to express cross-process sharing of memory dumps on the
167 // child-process side, without having to know its own child process id. 161 // child-process side, without having to know its own child process id.
168 uint64_t GetTracingProcessId() const { return tracing_process_id_; } 162 uint64_t GetTracingProcessId() const { return tracing_process_id_; }
169 void set_tracing_process_id(uint64_t tracing_process_id) { 163 void set_tracing_process_id(uint64_t tracing_process_id) {
170 tracing_process_id_ = tracing_process_id; 164 tracing_process_id_ = tracing_process_id;
171 } 165 }
(...skipping 18 matching lines...) Expand all
190 friend class memory_instrumentation::ProcessLocalDumpManagerImplTest; 184 friend class memory_instrumentation::ProcessLocalDumpManagerImplTest;
191 185
192 // Holds the state of a process memory dump that needs to be carried over 186 // Holds the state of a process memory dump that needs to be carried over
193 // across task runners in order to fulfil an asynchronous CreateProcessDump() 187 // across task runners in order to fulfil an asynchronous CreateProcessDump()
194 // request. At any time exactly one task runner owns a 188 // request. At any time exactly one task runner owns a
195 // ProcessMemoryDumpAsyncState. 189 // ProcessMemoryDumpAsyncState.
196 struct ProcessMemoryDumpAsyncState { 190 struct ProcessMemoryDumpAsyncState {
197 ProcessMemoryDumpAsyncState( 191 ProcessMemoryDumpAsyncState(
198 MemoryDumpRequestArgs req_args, 192 MemoryDumpRequestArgs req_args,
199 const MemoryDumpProviderInfo::OrderedSet& dump_providers, 193 const MemoryDumpProviderInfo::OrderedSet& dump_providers,
200 scoped_refptr<MemoryDumpSessionState> session_state, 194 scoped_refptr<HeapProfilerSerializationState>
195 heap_profiler_serialization_state,
201 ProcessMemoryDumpCallback callback, 196 ProcessMemoryDumpCallback callback,
202 scoped_refptr<SequencedTaskRunner> dump_thread_task_runner); 197 scoped_refptr<SequencedTaskRunner> dump_thread_task_runner);
203 ~ProcessMemoryDumpAsyncState(); 198 ~ProcessMemoryDumpAsyncState();
204 199
205 // Gets or creates the memory dump container for the given target process. 200 // Gets or creates the memory dump container for the given target process.
206 ProcessMemoryDump* GetOrCreateMemoryDumpContainerForProcess( 201 ProcessMemoryDump* GetOrCreateMemoryDumpContainerForProcess(
207 ProcessId pid, 202 ProcessId pid,
208 const MemoryDumpArgs& dump_args); 203 const MemoryDumpArgs& dump_args);
209 204
210 // A map of ProcessId -> ProcessMemoryDump, one for each target process 205 // A map of ProcessId -> ProcessMemoryDump, one for each target process
211 // being dumped from the current process. Typically each process dumps only 206 // being dumped from the current process. Typically each process dumps only
212 // for itself, unless dump providers specify a different |target_process| in 207 // for itself, unless dump providers specify a different |target_process| in
213 // MemoryDumpProvider::Options. 208 // MemoryDumpProvider::Options.
214 std::map<ProcessId, std::unique_ptr<ProcessMemoryDump>> process_dumps; 209 std::map<ProcessId, std::unique_ptr<ProcessMemoryDump>> process_dumps;
215 210
216 // The arguments passed to the initial CreateProcessDump() request. 211 // The arguments passed to the initial CreateProcessDump() request.
217 const MemoryDumpRequestArgs req_args; 212 const MemoryDumpRequestArgs req_args;
218 213
219 // An ordered sequence of dump providers that have to be invoked to complete 214 // An ordered sequence of dump providers that have to be invoked to complete
220 // the dump. This is a copy of |dump_providers_| at the beginning of a dump 215 // the dump. This is a copy of |dump_providers_| at the beginning of a dump
221 // and becomes empty at the end, when all dump providers have been invoked. 216 // and becomes empty at the end, when all dump providers have been invoked.
222 std::vector<scoped_refptr<MemoryDumpProviderInfo>> pending_dump_providers; 217 std::vector<scoped_refptr<MemoryDumpProviderInfo>> pending_dump_providers;
223 218
224 // The trace-global session state. 219 // The HeapProfilerSerializationState object, which is shared by all
225 scoped_refptr<MemoryDumpSessionState> session_state; 220 // the ProcessMemoryDump and MemoryAllocatorDump instances through all the
221 // tracing session lifetime.
222 scoped_refptr<HeapProfilerSerializationState>
223 heap_profiler_serialization_state;
226 224
227 // Callback passed to the initial call to CreateProcessDump(). 225 // Callback passed to the initial call to CreateProcessDump().
228 ProcessMemoryDumpCallback callback; 226 ProcessMemoryDumpCallback callback;
229 227
230 // The |success| field that will be passed as argument to the |callback|. 228 // The |success| field that will be passed as argument to the |callback|.
231 bool dump_successful; 229 bool dump_successful;
232 230
233 // The thread on which FinalizeDumpAndAddToTrace() (and hence |callback|) 231 // The thread on which FinalizeDumpAndAddToTrace() (and hence |callback|)
234 // should be invoked. This is the thread on which the initial 232 // should be invoked. This is the thread on which the initial
235 // CreateProcessDump() request was called. 233 // CreateProcessDump() request was called.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 // Fills the passed vector with the subset of dump providers which were 284 // Fills the passed vector with the subset of dump providers which were
287 // registered with is_fast_polling_supported == true. 285 // registered with is_fast_polling_supported == true.
288 void GetDumpProvidersForPolling( 286 void GetDumpProvidersForPolling(
289 std::vector<scoped_refptr<MemoryDumpProviderInfo>>*); 287 std::vector<scoped_refptr<MemoryDumpProviderInfo>>*);
290 288
291 // An ordererd set of registered MemoryDumpProviderInfo(s), sorted by task 289 // An ordererd set of registered MemoryDumpProviderInfo(s), sorted by task
292 // runner affinity (MDPs belonging to the same task runners are adjacent). 290 // runner affinity (MDPs belonging to the same task runners are adjacent).
293 MemoryDumpProviderInfo::OrderedSet dump_providers_; 291 MemoryDumpProviderInfo::OrderedSet dump_providers_;
294 292
295 // Shared among all the PMDs to keep state scoped to the tracing session. 293 // Shared among all the PMDs to keep state scoped to the tracing session.
296 scoped_refptr<MemoryDumpSessionState> session_state_; 294 scoped_refptr<HeapProfilerSerializationState>
295 heap_profiler_serialization_state_;
297 296
298 std::unique_ptr<MemoryTracingObserver> tracing_observer_; 297 std::unique_ptr<MemoryTracingObserver> tracing_observer_;
299 298
300 // Function provided by the embedder to handle global dump requests. 299 // Function provided by the embedder to handle global dump requests.
301 RequestGlobalDumpFunction request_dump_function_; 300 RequestGlobalDumpFunction request_dump_function_;
302 301
303 // True when current process coordinates the periodic dump triggering. 302 // True when current process coordinates the periodic dump triggering.
304 bool is_coordinator_; 303 bool is_coordinator_;
305 304
306 // Protects from concurrent accesses to the local state, eg: to guard against 305 // Protects from concurrent accesses to the local state, eg: to guard against
(...skipping 18 matching lines...) Expand all
325 // Whether new memory dump providers should be told to enable heap profiling. 324 // Whether new memory dump providers should be told to enable heap profiling.
326 bool heap_profiling_enabled_; 325 bool heap_profiling_enabled_;
327 326
328 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManager); 327 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManager);
329 }; 328 };
330 329
331 } // namespace trace_event 330 } // namespace trace_event
332 } // namespace base 331 } // namespace base
333 332
334 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ 333 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698