Chromium Code Reviews| 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 MemoryDumpCallback& callback); | 117 const MemoryDumpCallback& 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 // Tearsdown the MemoryDumpManager thread and various other state set up by | |
|
Primiano Tucci (use gerrit)
2017/04/21 13:14:16
nit, use blank space to separate comments when yo
hjd
2017/04/21 13:42:32
done, thanks!
| |
| 129 // Enable. | |
| 130 void Disable(); | |
| 125 | 131 |
| 126 // Enable heap profiling if kEnableHeapProfiling is specified. | 132 // Enable heap profiling if kEnableHeapProfiling is specified. |
| 127 void EnableHeapProfilingIfNeeded(); | 133 void EnableHeapProfilingIfNeeded(); |
| 128 | 134 |
| 129 // Returns true if the dump mode is allowed for current tracing session. | 135 // Returns true if the dump mode is allowed for current tracing session. |
| 130 bool IsDumpModeAllowed(MemoryDumpLevelOfDetail dump_mode); | 136 bool IsDumpModeAllowed(MemoryDumpLevelOfDetail dump_mode); |
| 131 | 137 |
| 132 // Lets tests see if a dump provider is registered. | 138 // Lets tests see if a dump provider is registered. |
| 133 bool IsDumpProviderRegisteredForTesting(MemoryDumpProvider*); | 139 bool IsDumpProviderRegisteredForTesting(MemoryDumpProvider*); |
| 134 | 140 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 const scoped_refptr<SingleThreadTaskRunner> dump_thread_task_runner; | 229 const scoped_refptr<SingleThreadTaskRunner> dump_thread_task_runner; |
| 224 | 230 |
| 225 private: | 231 private: |
| 226 DISALLOW_COPY_AND_ASSIGN(ProcessMemoryDumpAsyncState); | 232 DISALLOW_COPY_AND_ASSIGN(ProcessMemoryDumpAsyncState); |
| 227 }; | 233 }; |
| 228 | 234 |
| 229 static const int kMaxConsecutiveFailuresCount; | 235 static const int kMaxConsecutiveFailuresCount; |
| 230 static const char* const kSystemAllocatorPoolName; | 236 static const char* const kSystemAllocatorPoolName; |
| 231 | 237 |
| 232 MemoryDumpManager(); | 238 MemoryDumpManager(); |
| 233 ~MemoryDumpManager() override; | 239 virtual ~MemoryDumpManager(); |
| 234 | 240 |
| 235 static void SetInstanceForTesting(MemoryDumpManager* instance); | 241 static void SetInstanceForTesting(MemoryDumpManager* instance); |
| 236 static uint32_t GetDumpsSumKb(const std::string&, const ProcessMemoryDump*); | 242 static uint32_t GetDumpsSumKb(const std::string&, const ProcessMemoryDump*); |
| 237 static void FinalizeDumpAndAddToTrace( | 243 |
| 244 void FinalizeDumpAndAddToTrace( | |
| 238 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state); | 245 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state); |
| 239 | 246 |
| 240 // Internal, used only by MemoryDumpManagerDelegate. | 247 // Internal, used only by MemoryDumpManagerDelegate. |
| 241 // Creates a memory dump for the current process and appends it to the trace. | 248 // 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 | 249 // |callback| will be invoked asynchronously upon completion on the same |
| 243 // thread on which CreateProcessDump() was called. | 250 // thread on which CreateProcessDump() was called. |
| 244 void CreateProcessDump(const MemoryDumpRequestArgs& args, | 251 void CreateProcessDump(const MemoryDumpRequestArgs& args, |
| 245 const MemoryDumpCallback& callback); | 252 const MemoryDumpCallback& callback); |
| 246 | 253 |
| 247 // Calls InvokeOnMemoryDump() for the next MDP on the task runner specified by | 254 // Calls InvokeOnMemoryDump() for the next MDP on the task runner specified by |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 277 | 284 |
| 278 // Shared among all the PMDs to keep state scoped to the tracing session. | 285 // Shared among all the PMDs to keep state scoped to the tracing session. |
| 279 scoped_refptr<MemoryDumpSessionState> session_state_; | 286 scoped_refptr<MemoryDumpSessionState> session_state_; |
| 280 | 287 |
| 281 // The list of names of dump providers that are blacklisted from strict thread | 288 // The list of names of dump providers that are blacklisted from strict thread |
| 282 // affinity check on unregistration. | 289 // affinity check on unregistration. |
| 283 std::unordered_set<StringPiece, StringPieceHash> | 290 std::unordered_set<StringPiece, StringPieceHash> |
| 284 strict_thread_check_blacklist_; | 291 strict_thread_check_blacklist_; |
| 285 | 292 |
| 286 std::unique_ptr<MemoryDumpManagerDelegate> delegate_; | 293 std::unique_ptr<MemoryDumpManagerDelegate> delegate_; |
| 294 std::unique_ptr<MemoryTracingObserver> tracing_observer_; | |
| 287 | 295 |
| 288 // Protects from concurrent accesses to the |dump_providers_*| and |delegate_| | 296 // Protects from concurrent accesses to the |dump_providers_*| and |delegate_| |
| 289 // to guard against disabling logging while dumping on another thread. | 297 // to guard against disabling logging while dumping on another thread. |
| 290 Lock lock_; | 298 Lock lock_; |
| 291 | 299 |
| 292 // Optimization to avoid attempting any memory dump (i.e. to not walk an empty | 300 // Optimization to avoid attempting any memory dump (i.e. to not walk an empty |
| 293 // dump_providers_enabled_ list) when tracing is not enabled. | 301 // dump_providers_enabled_ list) when tracing is not enabled. |
| 294 subtle::AtomicWord memory_tracing_enabled_; | 302 subtle::AtomicWord memory_tracing_enabled_; |
| 295 | 303 |
| 296 // Thread used for MemoryDumpProviders which don't specify a task runner | 304 // Thread used for MemoryDumpProviders which don't specify a task runner |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 } | 337 } |
| 330 | 338 |
| 331 private: | 339 private: |
| 332 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); | 340 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); |
| 333 }; | 341 }; |
| 334 | 342 |
| 335 } // namespace trace_event | 343 } // namespace trace_event |
| 336 } // namespace base | 344 } // namespace base |
| 337 | 345 |
| 338 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ | 346 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ |
| OLD | NEW |