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

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

Issue 1852433005: Convert //base to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase after r384946 Created 4 years, 8 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 MemoryDumpProvider::Options options); 87 MemoryDumpProvider::Options options);
88 void UnregisterDumpProvider(MemoryDumpProvider* mdp); 88 void UnregisterDumpProvider(MemoryDumpProvider* mdp);
89 89
90 // Unregisters an unbound dump provider and takes care about its deletion 90 // Unregisters an unbound dump provider and takes care about its deletion
91 // asynchronously. Can be used only for for dump providers with no 91 // asynchronously. Can be used only for for dump providers with no
92 // task-runner affinity. 92 // task-runner affinity.
93 // This method takes ownership of the dump provider and guarantees that: 93 // This method takes ownership of the dump provider and guarantees that:
94 // - The |mdp| will be deleted at some point in the near future. 94 // - The |mdp| will be deleted at some point in the near future.
95 // - Its deletion will not happen concurrently with the OnMemoryDump() call. 95 // - Its deletion will not happen concurrently with the OnMemoryDump() call.
96 // Note that OnMemoryDump() calls can still happen after this method returns. 96 // Note that OnMemoryDump() calls can still happen after this method returns.
97 void UnregisterAndDeleteDumpProviderSoon(scoped_ptr<MemoryDumpProvider> mdp); 97 void UnregisterAndDeleteDumpProviderSoon(
98 std::unique_ptr<MemoryDumpProvider> mdp);
98 99
99 // Requests a memory dump. The dump might happen or not depending on the 100 // Requests a memory dump. The dump might happen or not depending on the
100 // filters and categories specified when enabling tracing. 101 // filters and categories specified when enabling tracing.
101 // The optional |callback| is executed asynchronously, on an arbitrary thread, 102 // The optional |callback| is executed asynchronously, on an arbitrary thread,
102 // to notify about the completion of the global dump (i.e. after all the 103 // to notify about the completion of the global dump (i.e. after all the
103 // processes have dumped) and its success (true iff all the dumps were 104 // processes have dumped) and its success (true iff all the dumps were
104 // successful). 105 // successful).
105 void RequestGlobalDump(MemoryDumpType dump_type, 106 void RequestGlobalDump(MemoryDumpType dump_type,
106 MemoryDumpLevelOfDetail level_of_detail, 107 MemoryDumpLevelOfDetail level_of_detail,
107 const MemoryDumpCallback& callback); 108 const MemoryDumpCallback& callback);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 175
175 MemoryDumpProviderInfo(MemoryDumpProvider* dump_provider, 176 MemoryDumpProviderInfo(MemoryDumpProvider* dump_provider,
176 const char* name, 177 const char* name,
177 scoped_refptr<SequencedTaskRunner> task_runner, 178 scoped_refptr<SequencedTaskRunner> task_runner,
178 const MemoryDumpProvider::Options& options); 179 const MemoryDumpProvider::Options& options);
179 180
180 MemoryDumpProvider* const dump_provider; 181 MemoryDumpProvider* const dump_provider;
181 182
182 // Used to transfer ownership for UnregisterAndDeleteDumpProviderSoon(). 183 // Used to transfer ownership for UnregisterAndDeleteDumpProviderSoon().
183 // nullptr in all other cases. 184 // nullptr in all other cases.
184 scoped_ptr<MemoryDumpProvider> owned_dump_provider; 185 std::unique_ptr<MemoryDumpProvider> owned_dump_provider;
185 186
186 // Human readable name, for debugging and testing. Not necessarily unique. 187 // Human readable name, for debugging and testing. Not necessarily unique.
187 const char* const name; 188 const char* const name;
188 189
189 // The task runner affinity. Can be nullptr, in which case the dump provider 190 // The task runner affinity. Can be nullptr, in which case the dump provider
190 // will be invoked on |dump_thread_|. 191 // will be invoked on |dump_thread_|.
191 const scoped_refptr<SequencedTaskRunner> task_runner; 192 const scoped_refptr<SequencedTaskRunner> task_runner;
192 193
193 // The |options| arg passed to RegisterDumpProvider(). 194 // The |options| arg passed to RegisterDumpProvider().
194 const MemoryDumpProvider::Options options; 195 const MemoryDumpProvider::Options options;
(...skipping 24 matching lines...) Expand all
219 scoped_refptr<SingleThreadTaskRunner> dump_thread_task_runner); 220 scoped_refptr<SingleThreadTaskRunner> dump_thread_task_runner);
220 ~ProcessMemoryDumpAsyncState(); 221 ~ProcessMemoryDumpAsyncState();
221 222
222 // Gets or creates the memory dump container for the given target process. 223 // Gets or creates the memory dump container for the given target process.
223 ProcessMemoryDump* GetOrCreateMemoryDumpContainerForProcess(ProcessId pid); 224 ProcessMemoryDump* GetOrCreateMemoryDumpContainerForProcess(ProcessId pid);
224 225
225 // A map of ProcessId -> ProcessMemoryDump, one for each target process 226 // A map of ProcessId -> ProcessMemoryDump, one for each target process
226 // being dumped from the current process. Typically each process dumps only 227 // being dumped from the current process. Typically each process dumps only
227 // for itself, unless dump providers specify a different |target_process| in 228 // for itself, unless dump providers specify a different |target_process| in
228 // MemoryDumpProvider::Options. 229 // MemoryDumpProvider::Options.
229 std::map<ProcessId, scoped_ptr<ProcessMemoryDump>> process_dumps; 230 std::map<ProcessId, std::unique_ptr<ProcessMemoryDump>> process_dumps;
230 231
231 // The arguments passed to the initial CreateProcessDump() request. 232 // The arguments passed to the initial CreateProcessDump() request.
232 const MemoryDumpRequestArgs req_args; 233 const MemoryDumpRequestArgs req_args;
233 234
234 // An ordered sequence of dump providers that have to be invoked to complete 235 // An ordered sequence of dump providers that have to be invoked to complete
235 // the dump. This is a copy of |dump_providers_| at the beginning of a dump 236 // the dump. This is a copy of |dump_providers_| at the beginning of a dump
236 // and becomes empty at the end, when all dump providers have been invoked. 237 // and becomes empty at the end, when all dump providers have been invoked.
237 std::vector<scoped_refptr<MemoryDumpProviderInfo>> pending_dump_providers; 238 std::vector<scoped_refptr<MemoryDumpProviderInfo>> pending_dump_providers;
238 239
239 // The trace-global session state. 240 // The trace-global session state.
(...skipping 22 matching lines...) Expand all
262 }; 263 };
263 264
264 static const int kMaxConsecutiveFailuresCount; 265 static const int kMaxConsecutiveFailuresCount;
265 static const char* const kSystemAllocatorPoolName; 266 static const char* const kSystemAllocatorPoolName;
266 267
267 MemoryDumpManager(); 268 MemoryDumpManager();
268 ~MemoryDumpManager() override; 269 ~MemoryDumpManager() override;
269 270
270 static void SetInstanceForTesting(MemoryDumpManager* instance); 271 static void SetInstanceForTesting(MemoryDumpManager* instance);
271 static void FinalizeDumpAndAddToTrace( 272 static void FinalizeDumpAndAddToTrace(
272 scoped_ptr<ProcessMemoryDumpAsyncState> pmd_async_state); 273 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state);
273 274
274 // Enable heap profiling if kEnableHeapProfiling is specified. 275 // Enable heap profiling if kEnableHeapProfiling is specified.
275 void EnableHeapProfilingIfNeeded(); 276 void EnableHeapProfilingIfNeeded();
276 277
277 // Internal, used only by MemoryDumpManagerDelegate. 278 // Internal, used only by MemoryDumpManagerDelegate.
278 // Creates a memory dump for the current process and appends it to the trace. 279 // Creates a memory dump for the current process and appends it to the trace.
279 // |callback| will be invoked asynchronously upon completion on the same 280 // |callback| will be invoked asynchronously upon completion on the same
280 // thread on which CreateProcessDump() was called. 281 // thread on which CreateProcessDump() was called.
281 void CreateProcessDump(const MemoryDumpRequestArgs& args, 282 void CreateProcessDump(const MemoryDumpRequestArgs& args,
282 const MemoryDumpCallback& callback); 283 const MemoryDumpCallback& callback);
283 284
284 // Calls InvokeOnMemoryDump() for the next MDP on the task runner specified by 285 // Calls InvokeOnMemoryDump() for the next MDP on the task runner specified by
285 // the MDP while registration. On failure to do so, skips and continues to 286 // the MDP while registration. On failure to do so, skips and continues to
286 // next MDP. 287 // next MDP.
287 void SetupNextMemoryDump( 288 void SetupNextMemoryDump(
288 scoped_ptr<ProcessMemoryDumpAsyncState> pmd_async_state); 289 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state);
289 290
290 // Invokes OnMemoryDump() of the next MDP and calls SetupNextMemoryDump() at 291 // Invokes OnMemoryDump() of the next MDP and calls SetupNextMemoryDump() at
291 // the end to continue the ProcessMemoryDump. Should be called on the MDP task 292 // the end to continue the ProcessMemoryDump. Should be called on the MDP task
292 // runner. 293 // runner.
293 void InvokeOnMemoryDump(ProcessMemoryDumpAsyncState* owned_pmd_async_state); 294 void InvokeOnMemoryDump(ProcessMemoryDumpAsyncState* owned_pmd_async_state);
294 295
295 // Helper for RegierDumpProvider* functions. 296 // Helper for RegierDumpProvider* functions.
296 void RegisterDumpProviderInternal( 297 void RegisterDumpProviderInternal(
297 MemoryDumpProvider* mdp, 298 MemoryDumpProvider* mdp,
298 const char* name, 299 const char* name,
(...skipping 22 matching lines...) Expand all
321 322
322 // Optimization to avoid attempting any memory dump (i.e. to not walk an empty 323 // Optimization to avoid attempting any memory dump (i.e. to not walk an empty
323 // dump_providers_enabled_ list) when tracing is not enabled. 324 // dump_providers_enabled_ list) when tracing is not enabled.
324 subtle::AtomicWord memory_tracing_enabled_; 325 subtle::AtomicWord memory_tracing_enabled_;
325 326
326 // For time-triggered periodic dumps. 327 // For time-triggered periodic dumps.
327 RepeatingTimer periodic_dump_timer_; 328 RepeatingTimer periodic_dump_timer_;
328 329
329 // Thread used for MemoryDumpProviders which don't specify a task runner 330 // Thread used for MemoryDumpProviders which don't specify a task runner
330 // affinity. 331 // affinity.
331 scoped_ptr<Thread> dump_thread_; 332 std::unique_ptr<Thread> dump_thread_;
332 333
333 // The unique id of the child process. This is created only for tracing and is 334 // The unique id of the child process. This is created only for tracing and is
334 // expected to be valid only when tracing is enabled. 335 // expected to be valid only when tracing is enabled.
335 uint64_t tracing_process_id_; 336 uint64_t tracing_process_id_;
336 337
337 // When true, calling |RegisterMemoryDumpProvider| is a no-op. 338 // When true, calling |RegisterMemoryDumpProvider| is a no-op.
338 bool dumper_registrations_ignored_for_testing_; 339 bool dumper_registrations_ignored_for_testing_;
339 340
340 // Whether new memory dump providers should be told to enable heap profiling. 341 // Whether new memory dump providers should be told to enable heap profiling.
341 bool heap_profiling_enabled_; 342 bool heap_profiling_enabled_;
(...skipping 22 matching lines...) Expand all
364 } 365 }
365 366
366 private: 367 private:
367 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); 368 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate);
368 }; 369 };
369 370
370 } // namespace trace_event 371 } // namespace trace_event
371 } // namespace base 372 } // namespace base
372 373
373 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ 374 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_
OLDNEW
« no previous file with comments | « base/trace_event/memory_allocator_dump_unittest.cc ('k') | base/trace_event/memory_dump_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698