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