| 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 std::unique_ptr<MemoryDumpProvider> mdp); | 107 std::unique_ptr<MemoryDumpProvider> mdp); |
| 108 | 108 |
| 109 // Requests a memory dump. The dump might happen or not depending on the | 109 // Requests a memory dump. The dump might happen or not depending on the |
| 110 // filters and categories specified when enabling tracing. | 110 // filters and categories specified when enabling tracing. |
| 111 // The optional |callback| is executed asynchronously, on an arbitrary thread, | 111 // The optional |callback| is executed asynchronously, on an arbitrary thread, |
| 112 // to notify about the completion of the global dump (i.e. after all the | 112 // to notify about the completion of the global dump (i.e. after all the |
| 113 // 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 |
| 114 // successful). | 114 // successful). |
| 115 void RequestGlobalDump(MemoryDumpType dump_type, | 115 void RequestGlobalDump(MemoryDumpType dump_type, |
| 116 MemoryDumpLevelOfDetail level_of_detail, | 116 MemoryDumpLevelOfDetail level_of_detail, |
| 117 const MemoryDumpCallback& callback); | 117 const GlobalMemoryDumpCallback& callback); |
| 118 | 118 |
| 119 // Same as above (still asynchronous), but without callback. | 119 // Same as above (still asynchronous), but without callback. |
| 120 void RequestGlobalDump(MemoryDumpType dump_type, | 120 void RequestGlobalDump(MemoryDumpType dump_type, |
| 121 MemoryDumpLevelOfDetail level_of_detail); | 121 MemoryDumpLevelOfDetail level_of_detail); |
| 122 | 122 |
| 123 // TraceLog::EnabledStateObserver implementation. | 123 // TraceLog::EnabledStateObserver implementation. |
| 124 void OnTraceLogEnabled() override; | 124 void OnTraceLogEnabled() override; |
| 125 void OnTraceLogDisabled() override; | 125 void OnTraceLogDisabled() override; |
| 126 | 126 |
| 127 // Enable heap profiling if kEnableHeapProfiling is specified. | 127 // Enable heap profiling if kEnableHeapProfiling is specified. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 | 173 |
| 174 // 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 |
| 175 // across task runners in order to fulfil an asynchronous CreateProcessDump() | 175 // across task runners in order to fulfil an asynchronous CreateProcessDump() |
| 176 // request. At any time exactly one task runner owns a | 176 // request. At any time exactly one task runner owns a |
| 177 // ProcessMemoryDumpAsyncState. | 177 // ProcessMemoryDumpAsyncState. |
| 178 struct ProcessMemoryDumpAsyncState { | 178 struct ProcessMemoryDumpAsyncState { |
| 179 ProcessMemoryDumpAsyncState( | 179 ProcessMemoryDumpAsyncState( |
| 180 MemoryDumpRequestArgs req_args, | 180 MemoryDumpRequestArgs req_args, |
| 181 const MemoryDumpProviderInfo::OrderedSet& dump_providers, | 181 const MemoryDumpProviderInfo::OrderedSet& dump_providers, |
| 182 scoped_refptr<MemoryDumpSessionState> session_state, | 182 scoped_refptr<MemoryDumpSessionState> session_state, |
| 183 MemoryDumpCallback callback, | 183 ProcessMemoryDumpCallback callback, |
| 184 scoped_refptr<SingleThreadTaskRunner> dump_thread_task_runner); | 184 scoped_refptr<SingleThreadTaskRunner> dump_thread_task_runner); |
| 185 ~ProcessMemoryDumpAsyncState(); | 185 ~ProcessMemoryDumpAsyncState(); |
| 186 | 186 |
| 187 // Gets or creates the memory dump container for the given target process. | 187 // Gets or creates the memory dump container for the given target process. |
| 188 ProcessMemoryDump* GetOrCreateMemoryDumpContainerForProcess( | 188 ProcessMemoryDump* GetOrCreateMemoryDumpContainerForProcess( |
| 189 ProcessId pid, | 189 ProcessId pid, |
| 190 const MemoryDumpArgs& dump_args); | 190 const MemoryDumpArgs& dump_args); |
| 191 | 191 |
| 192 // A map of ProcessId -> ProcessMemoryDump, one for each target process | 192 // A map of ProcessId -> ProcessMemoryDump, one for each target process |
| 193 // being dumped from the current process. Typically each process dumps only | 193 // being dumped from the current process. Typically each process dumps only |
| 194 // for itself, unless dump providers specify a different |target_process| in | 194 // for itself, unless dump providers specify a different |target_process| in |
| 195 // MemoryDumpProvider::Options. | 195 // MemoryDumpProvider::Options. |
| 196 std::map<ProcessId, std::unique_ptr<ProcessMemoryDump>> process_dumps; | 196 std::map<ProcessId, std::unique_ptr<ProcessMemoryDump>> process_dumps; |
| 197 | 197 |
| 198 // The arguments passed to the initial CreateProcessDump() request. | 198 // The arguments passed to the initial CreateProcessDump() request. |
| 199 const MemoryDumpRequestArgs req_args; | 199 const MemoryDumpRequestArgs req_args; |
| 200 | 200 |
| 201 // An ordered sequence of dump providers that have to be invoked to complete | 201 // An ordered sequence of dump providers that have to be invoked to complete |
| 202 // the dump. This is a copy of |dump_providers_| at the beginning of a dump | 202 // the dump. This is a copy of |dump_providers_| at the beginning of a dump |
| 203 // and becomes empty at the end, when all dump providers have been invoked. | 203 // and becomes empty at the end, when all dump providers have been invoked. |
| 204 std::vector<scoped_refptr<MemoryDumpProviderInfo>> pending_dump_providers; | 204 std::vector<scoped_refptr<MemoryDumpProviderInfo>> pending_dump_providers; |
| 205 | 205 |
| 206 // The trace-global session state. | 206 // The trace-global session state. |
| 207 scoped_refptr<MemoryDumpSessionState> session_state; | 207 scoped_refptr<MemoryDumpSessionState> session_state; |
| 208 | 208 |
| 209 // Callback passed to the initial call to CreateProcessDump(). | 209 // Callback passed to the initial call to CreateProcessDump(). |
| 210 MemoryDumpCallback callback; | 210 ProcessMemoryDumpCallback callback; |
| 211 | 211 |
| 212 // The |success| field that will be passed as argument to the |callback|. | 212 // The |success| field that will be passed as argument to the |callback|. |
| 213 bool dump_successful; | 213 bool dump_successful; |
| 214 | 214 |
| 215 // The thread on which FinalizeDumpAndAddToTrace() (and hence |callback|) | 215 // The thread on which FinalizeDumpAndAddToTrace() (and hence |callback|) |
| 216 // should be invoked. This is the thread on which the initial | 216 // should be invoked. This is the thread on which the initial |
| 217 // CreateProcessDump() request was called. | 217 // CreateProcessDump() request was called. |
| 218 const scoped_refptr<SingleThreadTaskRunner> callback_task_runner; | 218 const scoped_refptr<SingleThreadTaskRunner> callback_task_runner; |
| 219 | 219 |
| 220 // The thread on which unbound dump providers should be invoked. | 220 // The thread on which unbound dump providers should be invoked. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 237 static void SetInstanceForTesting(MemoryDumpManager* instance); | 237 static void SetInstanceForTesting(MemoryDumpManager* instance); |
| 238 static uint32_t GetDumpsSumKb(const std::string&, const ProcessMemoryDump*); | 238 static uint32_t GetDumpsSumKb(const std::string&, const ProcessMemoryDump*); |
| 239 static void FinalizeDumpAndAddToTrace( | 239 static void FinalizeDumpAndAddToTrace( |
| 240 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state); | 240 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state); |
| 241 | 241 |
| 242 // Internal, used only by MemoryDumpManagerDelegate. | 242 // Internal, used only by MemoryDumpManagerDelegate. |
| 243 // 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. |
| 244 // |callback| will be invoked asynchronously upon completion on the same | 244 // |callback| will be invoked asynchronously upon completion on the same |
| 245 // thread on which CreateProcessDump() was called. | 245 // thread on which CreateProcessDump() was called. |
| 246 void CreateProcessDump(const MemoryDumpRequestArgs& args, | 246 void CreateProcessDump(const MemoryDumpRequestArgs& args, |
| 247 const MemoryDumpCallback& callback); | 247 const ProcessMemoryDumpCallback& callback); |
| 248 | 248 |
| 249 // Calls InvokeOnMemoryDump() for the next MDP on the task runner specified by | 249 // Calls InvokeOnMemoryDump() for the next MDP on the task runner specified by |
| 250 // the MDP while registration. On failure to do so, skips and continues to | 250 // the MDP while registration. On failure to do so, skips and continues to |
| 251 // next MDP. | 251 // next MDP. |
| 252 void SetupNextMemoryDump( | 252 void SetupNextMemoryDump( |
| 253 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state); | 253 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state); |
| 254 | 254 |
| 255 // Invokes OnMemoryDump() of the next MDP and calls SetupNextMemoryDump() at | 255 // Invokes OnMemoryDump() of the next MDP and calls SetupNextMemoryDump() at |
| 256 // the end to continue the ProcessMemoryDump. Should be called on the MDP task | 256 // the end to continue the ProcessMemoryDump. Should be called on the MDP task |
| 257 // runner. | 257 // runner. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManager); | 326 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManager); |
| 327 }; | 327 }; |
| 328 | 328 |
| 329 // The delegate is supposed to be long lived (read: a Singleton) and thread | 329 // The delegate is supposed to be long lived (read: a Singleton) and thread |
| 330 // safe (i.e. should expect calls from any thread and handle thread hopping). | 330 // safe (i.e. should expect calls from any thread and handle thread hopping). |
| 331 class BASE_EXPORT MemoryDumpManagerDelegate { | 331 class BASE_EXPORT MemoryDumpManagerDelegate { |
| 332 public: | 332 public: |
| 333 MemoryDumpManagerDelegate() {} | 333 MemoryDumpManagerDelegate() {} |
| 334 virtual ~MemoryDumpManagerDelegate() {} | 334 virtual ~MemoryDumpManagerDelegate() {} |
| 335 | 335 |
| 336 virtual void RequestGlobalMemoryDump(const MemoryDumpRequestArgs& args, | 336 virtual void RequestGlobalMemoryDump( |
| 337 const MemoryDumpCallback& callback) = 0; | 337 const MemoryDumpRequestArgs& args, |
| 338 const GlobalMemoryDumpCallback& callback) = 0; |
| 338 | 339 |
| 339 virtual bool IsCoordinator() const = 0; | 340 virtual bool IsCoordinator() const = 0; |
| 340 | 341 |
| 341 protected: | 342 protected: |
| 342 void CreateProcessDump(const MemoryDumpRequestArgs& args, | 343 void CreateProcessDump(const MemoryDumpRequestArgs& args, |
| 343 const MemoryDumpCallback& callback) { | 344 const ProcessMemoryDumpCallback& callback) { |
| 344 MemoryDumpManager::GetInstance()->CreateProcessDump(args, callback); | 345 MemoryDumpManager::GetInstance()->CreateProcessDump(args, callback); |
| 345 } | 346 } |
| 346 | 347 |
| 347 private: | 348 private: |
| 348 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); | 349 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); |
| 349 }; | 350 }; |
| 350 | 351 |
| 351 } // namespace trace_event | 352 } // namespace trace_event |
| 352 } // namespace base | 353 } // namespace base |
| 353 | 354 |
| 354 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ | 355 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ |
| OLD | NEW |