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 28 matching lines...) Expand all Loading... | |
| 39 | 39 |
| 40 namespace trace_event { | 40 namespace trace_event { |
| 41 | 41 |
| 42 class MemoryDumpManagerDelegate; | 42 class MemoryDumpManagerDelegate; |
| 43 class MemoryDumpProvider; | 43 class MemoryDumpProvider; |
| 44 class MemoryDumpSessionState; | 44 class MemoryDumpSessionState; |
| 45 | 45 |
| 46 // This is the interface exposed to the rest of the codebase to deal with | 46 // 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 | 47 // memory tracing. The main entry point for clients is represented by |
| 48 // RequestDumpPoint(). The extension by Un(RegisterDumpProvider). | 48 // RequestDumpPoint(). The extension by Un(RegisterDumpProvider). |
| 49 class BASE_EXPORT MemoryDumpManager : public TraceLog::EnabledStateObserver { | 49 class BASE_EXPORT MemoryDumpManager { |
| 50 public: | 50 public: |
| 51 static const char* const kTraceCategory; | 51 static const char* const kTraceCategory; |
| 52 static const char* const kLogPrefix; | 52 static const char* const kLogPrefix; |
| 53 | 53 |
| 54 // This value is returned as the tracing id of the child processes by | 54 // This value is returned as the tracing id of the child processes by |
| 55 // GetTracingProcessId() when tracing is not enabled. | 55 // GetTracingProcessId() when tracing is not enabled. |
| 56 static const uint64_t kInvalidTracingProcessId; | 56 static const uint64_t kInvalidTracingProcessId; |
| 57 | 57 |
| 58 static MemoryDumpManager* GetInstance(); | 58 static MemoryDumpManager* GetInstance(); |
| 59 | 59 |
| (...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 | 112 // processes have dumped) and its success (true iff all the dumps were |
| 113 // successful). | 113 // successful). |
| 114 void RequestGlobalDump(MemoryDumpType dump_type, | 114 void RequestGlobalDump(MemoryDumpType dump_type, |
| 115 MemoryDumpLevelOfDetail level_of_detail, | 115 MemoryDumpLevelOfDetail level_of_detail, |
| 116 const MemoryDumpCallback& callback); | 116 const MemoryDumpCallback& callback); |
| 117 | 117 |
| 118 // Same as above (still asynchronous), but without callback. | 118 // Same as above (still asynchronous), but without callback. |
| 119 void RequestGlobalDump(MemoryDumpType dump_type, | 119 void RequestGlobalDump(MemoryDumpType dump_type, |
| 120 MemoryDumpLevelOfDetail level_of_detail); | 120 MemoryDumpLevelOfDetail level_of_detail); |
| 121 | 121 |
| 122 // TraceLog::EnabledStateObserver implementation. | 122 // XXX |
| 123 void OnTraceLogEnabled() override; | 123 virtual void Enable(); |
|
Primiano Tucci (use gerrit)
2017/04/13 15:22:37
out of cusiority, why virtual?
hjd
2017/04/13 16:32:18
So we can mock it in the frontend tests.
hjd
2017/04/19 09:54:56
If we don't want to test this for now I will undo
| |
| 124 void OnTraceLogDisabled() override; | 124 virtual void Disable(); |
| 125 | 125 |
| 126 // Enable heap profiling if kEnableHeapProfiling is specified. | 126 // Enable heap profiling if kEnableHeapProfiling is specified. |
| 127 void EnableHeapProfilingIfNeeded(); | 127 void EnableHeapProfilingIfNeeded(); |
| 128 | 128 |
| 129 // Returns true if the dump mode is allowed for current tracing session. | 129 // Returns true if the dump mode is allowed for current tracing session. |
| 130 bool IsDumpModeAllowed(MemoryDumpLevelOfDetail dump_mode); | 130 bool IsDumpModeAllowed(MemoryDumpLevelOfDetail dump_mode); |
| 131 | 131 |
| 132 // Lets tests see if a dump provider is registered. | 132 // Lets tests see if a dump provider is registered. |
| 133 bool IsDumpProviderRegisteredForTesting(MemoryDumpProvider*); | 133 bool IsDumpProviderRegisteredForTesting(MemoryDumpProvider*); |
| 134 | 134 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 160 // When set to true, calling |RegisterMemoryDumpProvider| is a no-op. | 160 // When set to true, calling |RegisterMemoryDumpProvider| is a no-op. |
| 161 void set_dumper_registrations_ignored_for_testing(bool ignored) { | 161 void set_dumper_registrations_ignored_for_testing(bool ignored) { |
| 162 dumper_registrations_ignored_for_testing_ = ignored; | 162 dumper_registrations_ignored_for_testing_ = ignored; |
| 163 } | 163 } |
| 164 | 164 |
| 165 private: | 165 private: |
| 166 friend std::default_delete<MemoryDumpManager>; // For the testing instance. | 166 friend std::default_delete<MemoryDumpManager>; // For the testing instance. |
| 167 friend struct DefaultSingletonTraits<MemoryDumpManager>; | 167 friend struct DefaultSingletonTraits<MemoryDumpManager>; |
| 168 friend class MemoryDumpManagerDelegate; | 168 friend class MemoryDumpManagerDelegate; |
| 169 friend class MemoryDumpManagerTest; | 169 friend class MemoryDumpManagerTest; |
| 170 friend class MemoryTracingFrontendTest; | |
| 171 friend class MockMemoryDumpManager; | |
| 170 friend class memory_instrumentation::MemoryDumpManagerDelegateImplTest; | 172 friend class memory_instrumentation::MemoryDumpManagerDelegateImplTest; |
| 171 | 173 |
| 172 // Holds the state of a process memory dump that needs to be carried over | 174 // Holds the state of a process memory dump that needs to be carried over |
| 173 // across task runners in order to fulfil an asynchronous CreateProcessDump() | 175 // across task runners in order to fulfil an asynchronous CreateProcessDump() |
| 174 // request. At any time exactly one task runner owns a | 176 // request. At any time exactly one task runner owns a |
| 175 // ProcessMemoryDumpAsyncState. | 177 // ProcessMemoryDumpAsyncState. |
| 176 struct ProcessMemoryDumpAsyncState { | 178 struct ProcessMemoryDumpAsyncState { |
| 177 ProcessMemoryDumpAsyncState( | 179 ProcessMemoryDumpAsyncState( |
| 178 MemoryDumpRequestArgs req_args, | 180 MemoryDumpRequestArgs req_args, |
| 179 const MemoryDumpProviderInfo::OrderedSet& dump_providers, | 181 const MemoryDumpProviderInfo::OrderedSet& dump_providers, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 const scoped_refptr<SingleThreadTaskRunner> dump_thread_task_runner; | 225 const scoped_refptr<SingleThreadTaskRunner> dump_thread_task_runner; |
| 224 | 226 |
| 225 private: | 227 private: |
| 226 DISALLOW_COPY_AND_ASSIGN(ProcessMemoryDumpAsyncState); | 228 DISALLOW_COPY_AND_ASSIGN(ProcessMemoryDumpAsyncState); |
| 227 }; | 229 }; |
| 228 | 230 |
| 229 static const int kMaxConsecutiveFailuresCount; | 231 static const int kMaxConsecutiveFailuresCount; |
| 230 static const char* const kSystemAllocatorPoolName; | 232 static const char* const kSystemAllocatorPoolName; |
| 231 | 233 |
| 232 MemoryDumpManager(); | 234 MemoryDumpManager(); |
| 233 ~MemoryDumpManager() override; | 235 virtual ~MemoryDumpManager(); |
| 234 | 236 |
| 235 static void SetInstanceForTesting(MemoryDumpManager* instance); | 237 static void SetInstanceForTesting(MemoryDumpManager* instance); |
| 236 static uint32_t GetDumpsSumKb(const std::string&, const ProcessMemoryDump*); | 238 static uint32_t GetDumpsSumKb(const std::string&, const ProcessMemoryDump*); |
| 237 static void FinalizeDumpAndAddToTrace( | 239 static void FinalizeDumpAndAddToTrace( |
| 238 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state); | 240 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state); |
| 239 | 241 |
| 240 // Internal, used only by MemoryDumpManagerDelegate. | 242 // Internal, used only by MemoryDumpManagerDelegate. |
| 241 // Creates a memory dump for the current process and appends it to the trace. | 243 // 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 | 244 // |callback| will be invoked asynchronously upon completion on the same |
| 243 // thread on which CreateProcessDump() was called. | 245 // thread on which CreateProcessDump() was called. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 } | 331 } |
| 330 | 332 |
| 331 private: | 333 private: |
| 332 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); | 334 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); |
| 333 }; | 335 }; |
| 334 | 336 |
| 335 } // namespace trace_event | 337 } // namespace trace_event |
| 336 } // namespace base | 338 } // namespace base |
| 337 | 339 |
| 338 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ | 340 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ |
| OLD | NEW |