| OLD | NEW |
| 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 16 matching lines...) Expand all Loading... |
| 27 // Forward declare |ProcessLocalDumpManagerImplTest| so that we can make it a | 27 // Forward declare |ProcessLocalDumpManagerImplTest| so that we can make it a |
| 28 // friend of |MemoryDumpManager| and give it access to |SetInstanceForTesting|. | 28 // friend of |MemoryDumpManager| and give it access to |SetInstanceForTesting|. |
| 29 namespace memory_instrumentation { | 29 namespace memory_instrumentation { |
| 30 | 30 |
| 31 class ProcessLocalDumpManagerImplTest; | 31 class ProcessLocalDumpManagerImplTest; |
| 32 | 32 |
| 33 } // namespace memory_instrumentation | 33 } // namespace memory_instrumentation |
| 34 | 34 |
| 35 namespace base { | 35 namespace base { |
| 36 | 36 |
| 37 class SequencedTaskRunner; |
| 37 class SingleThreadTaskRunner; | 38 class SingleThreadTaskRunner; |
| 38 class Thread; | 39 class Thread; |
| 39 | 40 |
| 40 namespace trace_event { | 41 namespace trace_event { |
| 41 | 42 |
| 42 class MemoryTracingObserver; | 43 class MemoryTracingObserver; |
| 43 class MemoryDumpProvider; | 44 class MemoryDumpProvider; |
| 44 class MemoryDumpSessionState; | 45 class MemoryDumpSessionState; |
| 45 | 46 |
| 46 // 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 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 // Holds the state of a process memory dump that needs to be carried over | 192 // Holds the state of a process memory dump that needs to be carried over |
| 192 // across task runners in order to fulfil an asynchronous CreateProcessDump() | 193 // across task runners in order to fulfil an asynchronous CreateProcessDump() |
| 193 // request. At any time exactly one task runner owns a | 194 // request. At any time exactly one task runner owns a |
| 194 // ProcessMemoryDumpAsyncState. | 195 // ProcessMemoryDumpAsyncState. |
| 195 struct ProcessMemoryDumpAsyncState { | 196 struct ProcessMemoryDumpAsyncState { |
| 196 ProcessMemoryDumpAsyncState( | 197 ProcessMemoryDumpAsyncState( |
| 197 MemoryDumpRequestArgs req_args, | 198 MemoryDumpRequestArgs req_args, |
| 198 const MemoryDumpProviderInfo::OrderedSet& dump_providers, | 199 const MemoryDumpProviderInfo::OrderedSet& dump_providers, |
| 199 scoped_refptr<MemoryDumpSessionState> session_state, | 200 scoped_refptr<MemoryDumpSessionState> session_state, |
| 200 ProcessMemoryDumpCallback callback, | 201 ProcessMemoryDumpCallback callback, |
| 201 scoped_refptr<SingleThreadTaskRunner> dump_thread_task_runner); | 202 scoped_refptr<SequencedTaskRunner> dump_thread_task_runner); |
| 202 ~ProcessMemoryDumpAsyncState(); | 203 ~ProcessMemoryDumpAsyncState(); |
| 203 | 204 |
| 204 // Gets or creates the memory dump container for the given target process. | 205 // Gets or creates the memory dump container for the given target process. |
| 205 ProcessMemoryDump* GetOrCreateMemoryDumpContainerForProcess( | 206 ProcessMemoryDump* GetOrCreateMemoryDumpContainerForProcess( |
| 206 ProcessId pid, | 207 ProcessId pid, |
| 207 const MemoryDumpArgs& dump_args); | 208 const MemoryDumpArgs& dump_args); |
| 208 | 209 |
| 209 // A map of ProcessId -> ProcessMemoryDump, one for each target process | 210 // A map of ProcessId -> ProcessMemoryDump, one for each target process |
| 210 // being dumped from the current process. Typically each process dumps only | 211 // being dumped from the current process. Typically each process dumps only |
| 211 // for itself, unless dump providers specify a different |target_process| in | 212 // for itself, unless dump providers specify a different |target_process| in |
| (...skipping 20 matching lines...) Expand all Loading... |
| 232 // The thread on which FinalizeDumpAndAddToTrace() (and hence |callback|) | 233 // The thread on which FinalizeDumpAndAddToTrace() (and hence |callback|) |
| 233 // should be invoked. This is the thread on which the initial | 234 // should be invoked. This is the thread on which the initial |
| 234 // CreateProcessDump() request was called. | 235 // CreateProcessDump() request was called. |
| 235 const scoped_refptr<SingleThreadTaskRunner> callback_task_runner; | 236 const scoped_refptr<SingleThreadTaskRunner> callback_task_runner; |
| 236 | 237 |
| 237 // The thread on which unbound dump providers should be invoked. | 238 // The thread on which unbound dump providers should be invoked. |
| 238 // This is essentially |dump_thread_|.task_runner() but needs to be kept | 239 // This is essentially |dump_thread_|.task_runner() but needs to be kept |
| 239 // as a separate variable as it needs to be accessed by arbitrary dumpers' | 240 // as a separate variable as it needs to be accessed by arbitrary dumpers' |
| 240 // threads outside of the lock_ to avoid races when disabling tracing. | 241 // threads outside of the lock_ to avoid races when disabling tracing. |
| 241 // It is immutable for all the duration of a tracing session. | 242 // It is immutable for all the duration of a tracing session. |
| 242 const scoped_refptr<SingleThreadTaskRunner> dump_thread_task_runner; | 243 const scoped_refptr<SequencedTaskRunner> dump_thread_task_runner; |
| 243 | 244 |
| 244 private: | 245 private: |
| 245 DISALLOW_COPY_AND_ASSIGN(ProcessMemoryDumpAsyncState); | 246 DISALLOW_COPY_AND_ASSIGN(ProcessMemoryDumpAsyncState); |
| 246 }; | 247 }; |
| 247 | 248 |
| 248 static const int kMaxConsecutiveFailuresCount; | 249 static const int kMaxConsecutiveFailuresCount; |
| 249 static const char* const kSystemAllocatorPoolName; | 250 static const char* const kSystemAllocatorPoolName; |
| 250 | 251 |
| 251 MemoryDumpManager(); | 252 MemoryDumpManager(); |
| 252 virtual ~MemoryDumpManager(); | 253 virtual ~MemoryDumpManager(); |
| 253 | 254 |
| 254 static void SetInstanceForTesting(MemoryDumpManager* instance); | 255 static void SetInstanceForTesting(MemoryDumpManager* instance); |
| 255 static uint32_t GetDumpsSumKb(const std::string&, const ProcessMemoryDump*); | 256 static uint32_t GetDumpsSumKb(const std::string&, const ProcessMemoryDump*); |
| 256 | 257 |
| 257 void FinalizeDumpAndAddToTrace( | 258 void FinalizeDumpAndAddToTrace( |
| 258 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state); | 259 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state); |
| 259 | 260 |
| 261 // Lazily initializes dump_thread_ and returns its TaskRunner. |
| 262 scoped_refptr<base::SequencedTaskRunner> GetOrCreateBgTaskRunnerLocked(); |
| 263 |
| 260 // Calls InvokeOnMemoryDump() for the next MDP on the task runner specified by | 264 // Calls InvokeOnMemoryDump() for the next MDP on the task runner specified by |
| 261 // the MDP while registration. On failure to do so, skips and continues to | 265 // the MDP while registration. On failure to do so, skips and continues to |
| 262 // next MDP. | 266 // next MDP. |
| 263 void SetupNextMemoryDump( | 267 void SetupNextMemoryDump( |
| 264 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state); | 268 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state); |
| 265 | 269 |
| 266 // Invokes OnMemoryDump() of the next MDP and calls SetupNextMemoryDump() at | 270 // Invokes OnMemoryDump() of the next MDP and calls SetupNextMemoryDump() at |
| 267 // the end to continue the ProcessMemoryDump. Should be called on the MDP task | 271 // the end to continue the ProcessMemoryDump. Should be called on the MDP task |
| 268 // runner. | 272 // runner. |
| 269 void InvokeOnMemoryDump(ProcessMemoryDumpAsyncState* owned_pmd_async_state); | 273 void InvokeOnMemoryDump(ProcessMemoryDumpAsyncState* owned_pmd_async_state); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 | 307 |
| 304 // True when current process coordinates the periodic dump triggering. | 308 // True when current process coordinates the periodic dump triggering. |
| 305 bool is_coordinator_; | 309 bool is_coordinator_; |
| 306 | 310 |
| 307 // Protects from concurrent accesses to the local state, eg: to guard against | 311 // Protects from concurrent accesses to the local state, eg: to guard against |
| 308 // disabling logging while dumping on another thread. | 312 // disabling logging while dumping on another thread. |
| 309 Lock lock_; | 313 Lock lock_; |
| 310 | 314 |
| 311 // Optimization to avoid attempting any memory dump (i.e. to not walk an empty | 315 // Optimization to avoid attempting any memory dump (i.e. to not walk an empty |
| 312 // dump_providers_enabled_ list) when tracing is not enabled. | 316 // dump_providers_enabled_ list) when tracing is not enabled. |
| 313 subtle::AtomicWord memory_tracing_enabled_; | 317 subtle::AtomicWord is_enabled_; |
| 314 | 318 |
| 315 // Thread used for MemoryDumpProviders which don't specify a task runner | 319 // Thread used for MemoryDumpProviders which don't specify a task runner |
| 316 // affinity. | 320 // affinity. |
| 317 std::unique_ptr<Thread> dump_thread_; | 321 std::unique_ptr<Thread> dump_thread_; |
| 318 | 322 |
| 319 // The unique id of the child process. This is created only for tracing and is | 323 // The unique id of the child process. This is created only for tracing and is |
| 320 // expected to be valid only when tracing is enabled. | 324 // expected to be valid only when tracing is enabled. |
| 321 uint64_t tracing_process_id_; | 325 uint64_t tracing_process_id_; |
| 322 | 326 |
| 323 // When true, calling |RegisterMemoryDumpProvider| is a no-op. | 327 // When true, calling |RegisterMemoryDumpProvider| is a no-op. |
| 324 bool dumper_registrations_ignored_for_testing_; | 328 bool dumper_registrations_ignored_for_testing_; |
| 325 | 329 |
| 326 // Whether new memory dump providers should be told to enable heap profiling. | 330 // Whether new memory dump providers should be told to enable heap profiling. |
| 327 bool heap_profiling_enabled_; | 331 bool heap_profiling_enabled_; |
| 328 | 332 |
| 329 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManager); | 333 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManager); |
| 330 }; | 334 }; |
| 331 | 335 |
| 332 } // namespace trace_event | 336 } // namespace trace_event |
| 333 } // namespace base | 337 } // namespace base |
| 334 | 338 |
| 335 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ | 339 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ |
| OLD | NEW |