| 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> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <unordered_set> | 12 #include <unordered_set> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/atomicops.h" | 15 #include "base/atomicops.h" |
| 16 #include "base/containers/hash_tables.h" | 16 #include "base/containers/hash_tables.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
| 19 #include "base/memory/singleton.h" | 19 #include "base/memory/singleton.h" |
| 20 #include "base/synchronization/lock.h" | 20 #include "base/synchronization/lock.h" |
| 21 #include "base/trace_event/memory_allocator_dump.h" | 21 #include "base/trace_event/memory_allocator_dump.h" |
| 22 #include "base/trace_event/memory_dump_provider_info.h" | 22 #include "base/trace_event/memory_dump_provider_info.h" |
| 23 #include "base/trace_event/memory_dump_request_args.h" | 23 #include "base/trace_event/memory_dump_request_args.h" |
| 24 #include "base/trace_event/process_memory_dump.h" | 24 #include "base/trace_event/process_memory_dump.h" |
| 25 #include "base/trace_event/trace_event.h" | 25 #include "base/trace_event/trace_event.h" |
| 26 | 26 |
| 27 // Forward declare |ProcessLocalDumpManagerImplTest| so that we can make it a | |
| 28 // friend of |MemoryDumpManager| and give it access to |SetInstanceForTesting|. | |
| 29 namespace memory_instrumentation { | |
| 30 | |
| 31 class ProcessLocalDumpManagerImplTest; | |
| 32 | |
| 33 } // namespace memory_instrumentation | |
| 34 | |
| 35 namespace base { | 27 namespace base { |
| 36 | 28 |
| 37 class SequencedTaskRunner; | 29 class SequencedTaskRunner; |
| 38 class SingleThreadTaskRunner; | 30 class SingleThreadTaskRunner; |
| 39 class Thread; | 31 class Thread; |
| 40 | 32 |
| 41 namespace trace_event { | 33 namespace trace_event { |
| 42 | 34 |
| 43 class MemoryTracingObserver; | 35 class MemoryTracingObserver; |
| 44 class MemoryDumpProvider; | 36 class MemoryDumpProvider; |
| 45 class HeapProfilerSerializationState; | 37 class HeapProfilerSerializationState; |
| 46 | 38 |
| 47 // This is the interface exposed to the rest of the codebase to deal with | 39 // 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 | 40 // memory tracing. The main entry point for clients is represented by |
| 49 // RequestDumpPoint(). The extension by Un(RegisterDumpProvider). | 41 // RequestDumpPoint(). The extension by Un(RegisterDumpProvider). |
| 50 class BASE_EXPORT MemoryDumpManager { | 42 class BASE_EXPORT MemoryDumpManager { |
| 51 public: | 43 public: |
| 52 using RequestGlobalDumpFunction = | 44 using RequestGlobalDumpFunction = |
| 53 RepeatingCallback<void(const MemoryDumpRequestArgs& args, | 45 RepeatingCallback<void(const MemoryDumpRequestArgs& args, |
| 54 const GlobalMemoryDumpCallback& callback)>; | 46 const GlobalMemoryDumpCallback& callback)>; |
| 55 | 47 |
| 56 static const char* const kTraceCategory; | 48 static const char* const kTraceCategory; |
| 57 static const char* const kLogPrefix; | 49 static const char* const kLogPrefix; |
| 58 | 50 |
| 59 // This value is returned as the tracing id of the child processes by | 51 // This value is returned as the tracing id of the child processes by |
| 60 // GetTracingProcessId() when tracing is not enabled. | 52 // GetTracingProcessId() when tracing is not enabled. |
| 61 static const uint64_t kInvalidTracingProcessId; | 53 static const uint64_t kInvalidTracingProcessId; |
| 62 | 54 |
| 63 static MemoryDumpManager* GetInstance(); | 55 static MemoryDumpManager* GetInstance(); |
| 56 static std::unique_ptr<MemoryDumpManager> CreateInstanceForTesting(); |
| 64 | 57 |
| 65 // Invoked once per process to listen to trace begin / end events. | 58 // Invoked once per process to listen to trace begin / end events. |
| 66 // Initialization can happen after (Un)RegisterMemoryDumpProvider() calls | 59 // Initialization can happen after (Un)RegisterMemoryDumpProvider() calls |
| 67 // and the MemoryDumpManager guarantees to support this. | 60 // and the MemoryDumpManager guarantees to support this. |
| 68 // On the other side, the MemoryDumpManager will not be fully operational | 61 // On the other side, the MemoryDumpManager will not be fully operational |
| 69 // (i.e. will NACK any RequestGlobalMemoryDump()) until initialized. | 62 // (i.e. will NACK any RequestGlobalMemoryDump()) until initialized. |
| 70 // Arguments: | 63 // Arguments: |
| 71 // request_dump_function: Function to invoke a global dump. Global dump | 64 // request_dump_function: Function to invoke a global dump. Global dump |
| 72 // involves embedder-specific behaviors like multiprocess handshaking. | 65 // involves embedder-specific behaviors like multiprocess handshaking. |
| 73 // is_coordinator: True when current process coodinates the periodic dump | 66 // is_coordinator: True when current process coodinates the periodic dump |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 | 169 |
| 177 // When set to true, calling |RegisterMemoryDumpProvider| is a no-op. | 170 // When set to true, calling |RegisterMemoryDumpProvider| is a no-op. |
| 178 void set_dumper_registrations_ignored_for_testing(bool ignored) { | 171 void set_dumper_registrations_ignored_for_testing(bool ignored) { |
| 179 dumper_registrations_ignored_for_testing_ = ignored; | 172 dumper_registrations_ignored_for_testing_ = ignored; |
| 180 } | 173 } |
| 181 | 174 |
| 182 private: | 175 private: |
| 183 friend std::default_delete<MemoryDumpManager>; // For the testing instance. | 176 friend std::default_delete<MemoryDumpManager>; // For the testing instance. |
| 184 friend struct DefaultSingletonTraits<MemoryDumpManager>; | 177 friend struct DefaultSingletonTraits<MemoryDumpManager>; |
| 185 friend class MemoryDumpManagerTest; | 178 friend class MemoryDumpManagerTest; |
| 186 friend class memory_instrumentation::ProcessLocalDumpManagerImplTest; | |
| 187 | 179 |
| 188 // Holds the state of a process memory dump that needs to be carried over | 180 // Holds the state of a process memory dump that needs to be carried over |
| 189 // across task runners in order to fulfil an asynchronous CreateProcessDump() | 181 // across task runners in order to fulfil an asynchronous CreateProcessDump() |
| 190 // request. At any time exactly one task runner owns a | 182 // request. At any time exactly one task runner owns a |
| 191 // ProcessMemoryDumpAsyncState. | 183 // ProcessMemoryDumpAsyncState. |
| 192 struct ProcessMemoryDumpAsyncState { | 184 struct ProcessMemoryDumpAsyncState { |
| 193 ProcessMemoryDumpAsyncState( | 185 ProcessMemoryDumpAsyncState( |
| 194 MemoryDumpRequestArgs req_args, | 186 MemoryDumpRequestArgs req_args, |
| 195 const MemoryDumpProviderInfo::OrderedSet& dump_providers, | 187 const MemoryDumpProviderInfo::OrderedSet& dump_providers, |
| 196 scoped_refptr<HeapProfilerSerializationState> | 188 scoped_refptr<HeapProfilerSerializationState> |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 // Whether new memory dump providers should be told to enable heap profiling. | 314 // Whether new memory dump providers should be told to enable heap profiling. |
| 323 bool heap_profiling_enabled_; | 315 bool heap_profiling_enabled_; |
| 324 | 316 |
| 325 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManager); | 317 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManager); |
| 326 }; | 318 }; |
| 327 | 319 |
| 328 } // namespace trace_event | 320 } // namespace trace_event |
| 329 } // namespace base | 321 } // namespace base |
| 330 | 322 |
| 331 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ | 323 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ |
| OLD | NEW |