| 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 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 } // namespace memory_instrumentation | 33 } // namespace memory_instrumentation |
| 34 | 34 |
| 35 namespace base { | 35 namespace base { |
| 36 | 36 |
| 37 class SingleThreadTaskRunner; | 37 class SingleThreadTaskRunner; |
| 38 class Thread; | 38 class Thread; |
| 39 | 39 |
| 40 namespace trace_event { | 40 namespace trace_event { |
| 41 | 41 |
| 42 class MemoryTracingObserver; |
| 42 class MemoryDumpManagerDelegate; | 43 class MemoryDumpManagerDelegate; |
| 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 |
| 47 // memory tracing. The main entry point for clients is represented by | 48 // memory tracing. The main entry point for clients is represented by |
| 48 // RequestDumpPoint(). The extension by Un(RegisterDumpProvider). | 49 // RequestDumpPoint(). The extension by Un(RegisterDumpProvider). |
| 49 class BASE_EXPORT MemoryDumpManager : public TraceLog::EnabledStateObserver { | 50 class BASE_EXPORT MemoryDumpManager { |
| 50 public: | 51 public: |
| 51 static const char* const kTraceCategory; | 52 static const char* const kTraceCategory; |
| 52 static const char* const kLogPrefix; | 53 static const char* const kLogPrefix; |
| 53 | 54 |
| 54 // This value is returned as the tracing id of the child processes by | 55 // This value is returned as the tracing id of the child processes by |
| 55 // GetTracingProcessId() when tracing is not enabled. | 56 // GetTracingProcessId() when tracing is not enabled. |
| 56 static const uint64_t kInvalidTracingProcessId; | 57 static const uint64_t kInvalidTracingProcessId; |
| 57 | 58 |
| 58 static MemoryDumpManager* GetInstance(); | 59 static MemoryDumpManager* GetInstance(); |
| 59 | 60 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 // processes have dumped) and its success (true iff all the dumps were | 113 // processes have dumped) and its success (true iff all the dumps were |
| 113 // successful). | 114 // successful). |
| 114 void RequestGlobalDump(MemoryDumpType dump_type, | 115 void RequestGlobalDump(MemoryDumpType dump_type, |
| 115 MemoryDumpLevelOfDetail level_of_detail, | 116 MemoryDumpLevelOfDetail level_of_detail, |
| 116 const GlobalMemoryDumpCallback& callback); | 117 const GlobalMemoryDumpCallback& callback); |
| 117 | 118 |
| 118 // Same as above (still asynchronous), but without callback. | 119 // Same as above (still asynchronous), but without callback. |
| 119 void RequestGlobalDump(MemoryDumpType dump_type, | 120 void RequestGlobalDump(MemoryDumpType dump_type, |
| 120 MemoryDumpLevelOfDetail level_of_detail); | 121 MemoryDumpLevelOfDetail level_of_detail); |
| 121 | 122 |
| 122 // TraceLog::EnabledStateObserver implementation. | 123 // Prepare MemoryDumpManager for RequestGlobalMemoryDump calls. |
| 123 void OnTraceLogEnabled() override; | 124 // Starts the MemoryDumpManager thread. |
| 124 void OnTraceLogDisabled() override; | 125 // Also uses the given config to initialize the peak detector, |
| 126 // scheduler and heap profiler. |
| 127 void Enable(const TraceConfig::MemoryDumpConfig&); |
| 128 |
| 129 // Tearsdown the MemoryDumpManager thread and various other state set up by |
| 130 // Enable. |
| 131 void Disable(); |
| 125 | 132 |
| 126 // Enable heap profiling if kEnableHeapProfiling is specified. | 133 // Enable heap profiling if kEnableHeapProfiling is specified. |
| 127 void EnableHeapProfilingIfNeeded(); | 134 void EnableHeapProfilingIfNeeded(); |
| 128 | 135 |
| 129 // Returns true if the dump mode is allowed for current tracing session. | 136 // Returns true if the dump mode is allowed for current tracing session. |
| 130 bool IsDumpModeAllowed(MemoryDumpLevelOfDetail dump_mode); | 137 bool IsDumpModeAllowed(MemoryDumpLevelOfDetail dump_mode); |
| 131 | 138 |
| 132 // Lets tests see if a dump provider is registered. | 139 // Lets tests see if a dump provider is registered. |
| 133 bool IsDumpProviderRegisteredForTesting(MemoryDumpProvider*); | 140 bool IsDumpProviderRegisteredForTesting(MemoryDumpProvider*); |
| 134 | 141 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 const scoped_refptr<SingleThreadTaskRunner> dump_thread_task_runner; | 230 const scoped_refptr<SingleThreadTaskRunner> dump_thread_task_runner; |
| 224 | 231 |
| 225 private: | 232 private: |
| 226 DISALLOW_COPY_AND_ASSIGN(ProcessMemoryDumpAsyncState); | 233 DISALLOW_COPY_AND_ASSIGN(ProcessMemoryDumpAsyncState); |
| 227 }; | 234 }; |
| 228 | 235 |
| 229 static const int kMaxConsecutiveFailuresCount; | 236 static const int kMaxConsecutiveFailuresCount; |
| 230 static const char* const kSystemAllocatorPoolName; | 237 static const char* const kSystemAllocatorPoolName; |
| 231 | 238 |
| 232 MemoryDumpManager(); | 239 MemoryDumpManager(); |
| 233 ~MemoryDumpManager() override; | 240 virtual ~MemoryDumpManager(); |
| 234 | 241 |
| 235 static void SetInstanceForTesting(MemoryDumpManager* instance); | 242 static void SetInstanceForTesting(MemoryDumpManager* instance); |
| 236 static uint32_t GetDumpsSumKb(const std::string&, const ProcessMemoryDump*); | 243 static uint32_t GetDumpsSumKb(const std::string&, const ProcessMemoryDump*); |
| 237 static void FinalizeDumpAndAddToTrace( | 244 |
| 245 void FinalizeDumpAndAddToTrace( |
| 238 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state); | 246 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state); |
| 239 | 247 |
| 240 // Internal, used only by MemoryDumpManagerDelegate. | 248 // Internal, used only by MemoryDumpManagerDelegate. |
| 241 // Creates a memory dump for the current process and appends it to the trace. | 249 // Creates a memory dump for the current process and appends it to the trace. |
| 242 // |callback| will be invoked asynchronously upon completion on the same | 250 // |callback| will be invoked asynchronously upon completion on the same |
| 243 // thread on which CreateProcessDump() was called. | 251 // thread on which CreateProcessDump() was called. |
| 244 void CreateProcessDump(const MemoryDumpRequestArgs& args, | 252 void CreateProcessDump(const MemoryDumpRequestArgs& args, |
| 245 const ProcessMemoryDumpCallback& callback); | 253 const ProcessMemoryDumpCallback& callback); |
| 246 | 254 |
| 247 // Calls InvokeOnMemoryDump() for the next MDP on the task runner specified by | 255 // Calls InvokeOnMemoryDump() for the next MDP on the task runner specified by |
| (...skipping 29 matching lines...) Expand all Loading... |
| 277 | 285 |
| 278 // Shared among all the PMDs to keep state scoped to the tracing session. | 286 // Shared among all the PMDs to keep state scoped to the tracing session. |
| 279 scoped_refptr<MemoryDumpSessionState> session_state_; | 287 scoped_refptr<MemoryDumpSessionState> session_state_; |
| 280 | 288 |
| 281 // The list of names of dump providers that are blacklisted from strict thread | 289 // The list of names of dump providers that are blacklisted from strict thread |
| 282 // affinity check on unregistration. | 290 // affinity check on unregistration. |
| 283 std::unordered_set<StringPiece, StringPieceHash> | 291 std::unordered_set<StringPiece, StringPieceHash> |
| 284 strict_thread_check_blacklist_; | 292 strict_thread_check_blacklist_; |
| 285 | 293 |
| 286 std::unique_ptr<MemoryDumpManagerDelegate> delegate_; | 294 std::unique_ptr<MemoryDumpManagerDelegate> delegate_; |
| 295 std::unique_ptr<MemoryTracingObserver> tracing_observer_; |
| 287 | 296 |
| 288 // Protects from concurrent accesses to the |dump_providers_*| and |delegate_| | 297 // Protects from concurrent accesses to the |dump_providers_*| and |delegate_| |
| 289 // to guard against disabling logging while dumping on another thread. | 298 // to guard against disabling logging while dumping on another thread. |
| 290 Lock lock_; | 299 Lock lock_; |
| 291 | 300 |
| 292 // Optimization to avoid attempting any memory dump (i.e. to not walk an empty | 301 // Optimization to avoid attempting any memory dump (i.e. to not walk an empty |
| 293 // dump_providers_enabled_ list) when tracing is not enabled. | 302 // dump_providers_enabled_ list) when tracing is not enabled. |
| 294 subtle::AtomicWord memory_tracing_enabled_; | 303 subtle::AtomicWord memory_tracing_enabled_; |
| 295 | 304 |
| 296 // Thread used for MemoryDumpProviders which don't specify a task runner | 305 // Thread used for MemoryDumpProviders which don't specify a task runner |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 } | 339 } |
| 331 | 340 |
| 332 private: | 341 private: |
| 333 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); | 342 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); |
| 334 }; | 343 }; |
| 335 | 344 |
| 336 } // namespace trace_event | 345 } // namespace trace_event |
| 337 } // namespace base | 346 } // namespace base |
| 338 | 347 |
| 339 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ | 348 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ |
| OLD | NEW |