| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 // - mdp: the MemoryDumpProvider instance to be registered. MemoryDumpManager | 66 // - mdp: the MemoryDumpProvider instance to be registered. MemoryDumpManager |
| 67 // does NOT take memory ownership of |mdp|, which is expected to either | 67 // does NOT take memory ownership of |mdp|, which is expected to either |
| 68 // be a singleton or unregister itself. | 68 // be a singleton or unregister itself. |
| 69 // - name: a friendly name (duplicates allowed). Used for debugging and | 69 // - name: a friendly name (duplicates allowed). Used for debugging and |
| 70 // run-time profiling of memory-infra internals. Must be a long-lived | 70 // run-time profiling of memory-infra internals. Must be a long-lived |
| 71 // C string. | 71 // C string. |
| 72 // - task_runner: either a SingleThreadTaskRunner or SequencedTaskRunner. All | 72 // - task_runner: either a SingleThreadTaskRunner or SequencedTaskRunner. All |
| 73 // the calls to |mdp| will be run on the given |task_runner|. If passed | 73 // the calls to |mdp| will be run on the given |task_runner|. If passed |
| 74 // null |mdp| should be able to handle calls on arbitrary threads. | 74 // null |mdp| should be able to handle calls on arbitrary threads. |
| 75 // - options: extra optional arguments. See memory_dump_provider.h. | 75 // - options: extra optional arguments. See memory_dump_provider.h. |
| 76 void RegisterDumpProvider( | 76 void RegisterDumpProvider(MemoryDumpProvider* mdp, |
| 77 MemoryDumpProvider* mdp, | 77 const char* name, |
| 78 const char* name, | 78 scoped_refptr<SingleThreadTaskRunner> task_runner); |
| 79 const scoped_refptr<SingleThreadTaskRunner>& task_runner); | 79 void RegisterDumpProvider(MemoryDumpProvider* mdp, |
| 80 void RegisterDumpProvider( | 80 const char* name, |
| 81 MemoryDumpProvider* mdp, | 81 scoped_refptr<SingleThreadTaskRunner> task_runner, |
| 82 const char* name, | 82 MemoryDumpProvider::Options options); |
| 83 const scoped_refptr<SingleThreadTaskRunner>& task_runner, | |
| 84 MemoryDumpProvider::Options options); | |
| 85 void RegisterDumpProviderWithSequencedTaskRunner( | 83 void RegisterDumpProviderWithSequencedTaskRunner( |
| 86 MemoryDumpProvider* mdp, | 84 MemoryDumpProvider* mdp, |
| 87 const char* name, | 85 const char* name, |
| 88 const scoped_refptr<SequencedTaskRunner>& task_runner, | 86 scoped_refptr<SequencedTaskRunner> task_runner, |
| 89 MemoryDumpProvider::Options options); | 87 MemoryDumpProvider::Options options); |
| 90 void UnregisterDumpProvider(MemoryDumpProvider* mdp); | 88 void UnregisterDumpProvider(MemoryDumpProvider* mdp); |
| 91 | 89 |
| 92 // Unregisters an unbound dump provider and takes care about its deletion | 90 // Unregisters an unbound dump provider and takes care about its deletion |
| 93 // asynchronously. Can be used only for for dump providers with no | 91 // asynchronously. Can be used only for for dump providers with no |
| 94 // task-runner affinity. | 92 // task-runner affinity. |
| 95 // This method takes ownership of the dump provider and guarantees that: | 93 // This method takes ownership of the dump provider and guarantees that: |
| 96 // - The |mdp| will be deleted at some point in the near future. | 94 // - The |mdp| will be deleted at some point in the near future. |
| 97 // - Its deletion will not happen concurrently with the OnMemoryDump() call. | 95 // - Its deletion will not happen concurrently with the OnMemoryDump() call. |
| 98 // Note that OnMemoryDump() calls can still happen after this method returns. | 96 // Note that OnMemoryDump() calls can still happen after this method returns. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 : public RefCountedThreadSafe<MemoryDumpProviderInfo> { | 165 : public RefCountedThreadSafe<MemoryDumpProviderInfo> { |
| 168 // Define a total order based on the |task_runner| affinity, so that MDPs | 166 // Define a total order based on the |task_runner| affinity, so that MDPs |
| 169 // belonging to the same SequencedTaskRunner are adjacent in the set. | 167 // belonging to the same SequencedTaskRunner are adjacent in the set. |
| 170 struct Comparator { | 168 struct Comparator { |
| 171 bool operator()(const scoped_refptr<MemoryDumpProviderInfo>& a, | 169 bool operator()(const scoped_refptr<MemoryDumpProviderInfo>& a, |
| 172 const scoped_refptr<MemoryDumpProviderInfo>& b) const; | 170 const scoped_refptr<MemoryDumpProviderInfo>& b) const; |
| 173 }; | 171 }; |
| 174 using OrderedSet = | 172 using OrderedSet = |
| 175 std::set<scoped_refptr<MemoryDumpProviderInfo>, Comparator>; | 173 std::set<scoped_refptr<MemoryDumpProviderInfo>, Comparator>; |
| 176 | 174 |
| 177 MemoryDumpProviderInfo( | 175 MemoryDumpProviderInfo(MemoryDumpProvider* dump_provider, |
| 178 MemoryDumpProvider* dump_provider, | 176 const char* name, |
| 179 const char* name, | 177 scoped_refptr<SequencedTaskRunner> task_runner, |
| 180 const scoped_refptr<SequencedTaskRunner>& task_runner, | 178 const MemoryDumpProvider::Options& options); |
| 181 const MemoryDumpProvider::Options& options); | |
| 182 | 179 |
| 183 MemoryDumpProvider* const dump_provider; | 180 MemoryDumpProvider* const dump_provider; |
| 184 | 181 |
| 185 // Used to transfer ownership for UnregisterAndDeleteDumpProviderSoon(). | 182 // Used to transfer ownership for UnregisterAndDeleteDumpProviderSoon(). |
| 186 // nullptr in all other cases. | 183 // nullptr in all other cases. |
| 187 scoped_ptr<MemoryDumpProvider> owned_dump_provider; | 184 scoped_ptr<MemoryDumpProvider> owned_dump_provider; |
| 188 | 185 |
| 189 // Human readable name, for debugging and testing. Not necessarily unique. | 186 // Human readable name, for debugging and testing. Not necessarily unique. |
| 190 const char* const name; | 187 const char* const name; |
| 191 | 188 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 210 }; | 207 }; |
| 211 | 208 |
| 212 // Holds the state of a process memory dump that needs to be carried over | 209 // Holds the state of a process memory dump that needs to be carried over |
| 213 // across task runners in order to fulfil an asynchronous CreateProcessDump() | 210 // across task runners in order to fulfil an asynchronous CreateProcessDump() |
| 214 // request. At any time exactly one task runner owns a | 211 // request. At any time exactly one task runner owns a |
| 215 // ProcessMemoryDumpAsyncState. | 212 // ProcessMemoryDumpAsyncState. |
| 216 struct ProcessMemoryDumpAsyncState { | 213 struct ProcessMemoryDumpAsyncState { |
| 217 ProcessMemoryDumpAsyncState( | 214 ProcessMemoryDumpAsyncState( |
| 218 MemoryDumpRequestArgs req_args, | 215 MemoryDumpRequestArgs req_args, |
| 219 const MemoryDumpProviderInfo::OrderedSet& dump_providers, | 216 const MemoryDumpProviderInfo::OrderedSet& dump_providers, |
| 220 const scoped_refptr<MemoryDumpSessionState>& session_state, | 217 scoped_refptr<MemoryDumpSessionState> session_state, |
| 221 MemoryDumpCallback callback, | 218 MemoryDumpCallback callback, |
| 222 const scoped_refptr<SingleThreadTaskRunner>& dump_thread_task_runner); | 219 scoped_refptr<SingleThreadTaskRunner> dump_thread_task_runner); |
| 223 ~ProcessMemoryDumpAsyncState(); | 220 ~ProcessMemoryDumpAsyncState(); |
| 224 | 221 |
| 225 // Gets or creates the memory dump container for the given target process. | 222 // Gets or creates the memory dump container for the given target process. |
| 226 ProcessMemoryDump* GetOrCreateMemoryDumpContainerForProcess(ProcessId pid); | 223 ProcessMemoryDump* GetOrCreateMemoryDumpContainerForProcess(ProcessId pid); |
| 227 | 224 |
| 228 // A map of ProcessId -> ProcessMemoryDump, one for each target process | 225 // A map of ProcessId -> ProcessMemoryDump, one for each target process |
| 229 // being dumped from the current process. Typically each process dumps only | 226 // being dumped from the current process. Typically each process dumps only |
| 230 // for itself, unless dump providers specify a different |target_process| in | 227 // for itself, unless dump providers specify a different |target_process| in |
| 231 // MemoryDumpProvider::Options. | 228 // MemoryDumpProvider::Options. |
| 232 std::map<ProcessId, scoped_ptr<ProcessMemoryDump>> process_dumps; | 229 std::map<ProcessId, scoped_ptr<ProcessMemoryDump>> process_dumps; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 | 289 |
| 293 // Invokes OnMemoryDump() of the next MDP and calls SetupNextMemoryDump() at | 290 // Invokes OnMemoryDump() of the next MDP and calls SetupNextMemoryDump() at |
| 294 // the end to continue the ProcessMemoryDump. Should be called on the MDP task | 291 // the end to continue the ProcessMemoryDump. Should be called on the MDP task |
| 295 // runner. | 292 // runner. |
| 296 void InvokeOnMemoryDump(ProcessMemoryDumpAsyncState* owned_pmd_async_state); | 293 void InvokeOnMemoryDump(ProcessMemoryDumpAsyncState* owned_pmd_async_state); |
| 297 | 294 |
| 298 // Helper for RegierDumpProvider* functions. | 295 // Helper for RegierDumpProvider* functions. |
| 299 void RegisterDumpProviderInternal( | 296 void RegisterDumpProviderInternal( |
| 300 MemoryDumpProvider* mdp, | 297 MemoryDumpProvider* mdp, |
| 301 const char* name, | 298 const char* name, |
| 302 const scoped_refptr<SequencedTaskRunner>& task_runner, | 299 scoped_refptr<SequencedTaskRunner> task_runner, |
| 303 const MemoryDumpProvider::Options& options); | 300 const MemoryDumpProvider::Options& options); |
| 304 | 301 |
| 305 // Helper for the public UnregisterDumpProvider* functions. | 302 // Helper for the public UnregisterDumpProvider* functions. |
| 306 void UnregisterDumpProviderInternal(MemoryDumpProvider* mdp, | 303 void UnregisterDumpProviderInternal(MemoryDumpProvider* mdp, |
| 307 bool take_mdp_ownership_and_delete_async); | 304 bool take_mdp_ownership_and_delete_async); |
| 308 | 305 |
| 309 // An ordererd set of registered MemoryDumpProviderInfo(s), sorted by task | 306 // An ordererd set of registered MemoryDumpProviderInfo(s), sorted by task |
| 310 // runner affinity (MDPs belonging to the same task runners are adjacent). | 307 // runner affinity (MDPs belonging to the same task runners are adjacent). |
| 311 MemoryDumpProviderInfo::OrderedSet dump_providers_; | 308 MemoryDumpProviderInfo::OrderedSet dump_providers_; |
| 312 | 309 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 } | 364 } |
| 368 | 365 |
| 369 private: | 366 private: |
| 370 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); | 367 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); |
| 371 }; | 368 }; |
| 372 | 369 |
| 373 } // namespace trace_event | 370 } // namespace trace_event |
| 374 } // namespace base | 371 } // namespace base |
| 375 | 372 |
| 376 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ | 373 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ |
| OLD | NEW |