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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 MemoryDumpProvider* mdp, | 77 MemoryDumpProvider* mdp, |
78 const char* name, | 78 const char* name, |
79 const scoped_refptr<SingleThreadTaskRunner>& task_runner); | 79 const scoped_refptr<SingleThreadTaskRunner>& task_runner); |
80 void RegisterDumpProvider( | 80 void RegisterDumpProvider( |
81 MemoryDumpProvider* mdp, | 81 MemoryDumpProvider* mdp, |
82 const char* name, | 82 const char* name, |
83 const scoped_refptr<SingleThreadTaskRunner>& task_runner, | 83 const scoped_refptr<SingleThreadTaskRunner>& task_runner, |
84 const MemoryDumpProvider::Options& options); | 84 const MemoryDumpProvider::Options& options); |
85 void UnregisterDumpProvider(MemoryDumpProvider* mdp); | 85 void UnregisterDumpProvider(MemoryDumpProvider* mdp); |
86 | 86 |
| 87 // Unregisters an unbound dump provider and takes care about its deletion |
| 88 // asynchronously. Can be used only for for dump providers with no |
| 89 // task-runner affinity. |
| 90 // This method takes ownership of the dump provider and guarantees that: |
| 91 // - The |mdp| will be deleted at some point in the near future. |
| 92 // - Its deletion will not happen concurrently with the OnMemoryDump() call. |
| 93 // Note that OnMemoryDump() calls can still happen after this method returns. |
| 94 void UnregisterAndDeleteDumpProviderSoon(scoped_ptr<MemoryDumpProvider> mdp); |
| 95 |
87 // Requests a memory dump. The dump might happen or not depending on the | 96 // Requests a memory dump. The dump might happen or not depending on the |
88 // filters and categories specified when enabling tracing. | 97 // filters and categories specified when enabling tracing. |
89 // The optional |callback| is executed asynchronously, on an arbitrary thread, | 98 // The optional |callback| is executed asynchronously, on an arbitrary thread, |
90 // to notify about the completion of the global dump (i.e. after all the | 99 // to notify about the completion of the global dump (i.e. after all the |
91 // processes have dumped) and its success (true iff all the dumps were | 100 // processes have dumped) and its success (true iff all the dumps were |
92 // successful). | 101 // successful). |
93 void RequestGlobalDump(MemoryDumpType dump_type, | 102 void RequestGlobalDump(MemoryDumpType dump_type, |
94 MemoryDumpLevelOfDetail level_of_detail, | 103 MemoryDumpLevelOfDetail level_of_detail, |
95 const MemoryDumpCallback& callback); | 104 const MemoryDumpCallback& callback); |
96 | 105 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 friend class MemoryDumpManagerTest; | 144 friend class MemoryDumpManagerTest; |
136 | 145 |
137 // Descriptor used to hold information about registered MDPs. | 146 // Descriptor used to hold information about registered MDPs. |
138 // Some important considerations about lifetime of this object: | 147 // Some important considerations about lifetime of this object: |
139 // - In nominal conditions, all the MemoryDumpProviderInfo instances live in | 148 // - In nominal conditions, all the MemoryDumpProviderInfo instances live in |
140 // the |dump_providers_| collection (% unregistration while dumping). | 149 // the |dump_providers_| collection (% unregistration while dumping). |
141 // - Upon each dump they (actually their scoped_refptr-s) are copied into | 150 // - Upon each dump they (actually their scoped_refptr-s) are copied into |
142 // the ProcessMemoryDumpAsyncState. This is to allow removal (see below). | 151 // the ProcessMemoryDumpAsyncState. This is to allow removal (see below). |
143 // - When the MDP.OnMemoryDump() is invoked, the corresponding MDPInfo copy | 152 // - When the MDP.OnMemoryDump() is invoked, the corresponding MDPInfo copy |
144 // inside ProcessMemoryDumpAsyncState is removed. | 153 // inside ProcessMemoryDumpAsyncState is removed. |
145 // - In nominal conditions, the MDPInfo is destroyed in the | 154 // - In most cases, the MDPInfo is destroyed within UnregisterDumpProvider(). |
146 // UnregisterDumpProvider() call. | |
147 // - If UnregisterDumpProvider() is called while a dump is in progress, the | 155 // - If UnregisterDumpProvider() is called while a dump is in progress, the |
148 // MDPInfo is destroyed in the epilogue of ContinueAsyncProcessDump(), when | 156 // MDPInfo is destroyed in the epilogue of ContinueAsyncProcessDump(), when |
149 // the copy inside ProcessMemoryDumpAsyncState is erase()-d. | 157 // the copy inside ProcessMemoryDumpAsyncState is erase()-d. |
150 // - The non-const fields of MemoryDumpProviderInfo are safe to access only | 158 // - The non-const fields of MemoryDumpProviderInfo are safe to access only |
151 // in the |task_runner| thread, unless the thread has been destroyed. | 159 // in the |task_runner| thread, unless the thread has been destroyed. |
152 struct MemoryDumpProviderInfo | 160 struct MemoryDumpProviderInfo |
153 : public RefCountedThreadSafe<MemoryDumpProviderInfo> { | 161 : public RefCountedThreadSafe<MemoryDumpProviderInfo> { |
154 // Define a total order based on the thread (i.e. |task_runner|) affinity, | 162 // Define a total order based on the thread (i.e. |task_runner|) affinity, |
155 // so that all MDP belonging to the same thread are adjacent in the set. | 163 // so that all MDP belonging to the same thread are adjacent in the set. |
156 struct Comparator { | 164 struct Comparator { |
157 bool operator()(const scoped_refptr<MemoryDumpProviderInfo>& a, | 165 bool operator()(const scoped_refptr<MemoryDumpProviderInfo>& a, |
158 const scoped_refptr<MemoryDumpProviderInfo>& b) const; | 166 const scoped_refptr<MemoryDumpProviderInfo>& b) const; |
159 }; | 167 }; |
160 using OrderedSet = | 168 using OrderedSet = |
161 std::set<scoped_refptr<MemoryDumpProviderInfo>, Comparator>; | 169 std::set<scoped_refptr<MemoryDumpProviderInfo>, Comparator>; |
162 | 170 |
163 MemoryDumpProviderInfo( | 171 MemoryDumpProviderInfo( |
164 MemoryDumpProvider* dump_provider, | 172 MemoryDumpProvider* dump_provider, |
165 const char* name, | 173 const char* name, |
166 const scoped_refptr<SingleThreadTaskRunner>& task_runner, | 174 const scoped_refptr<SingleThreadTaskRunner>& task_runner, |
167 const MemoryDumpProvider::Options& options); | 175 const MemoryDumpProvider::Options& options); |
168 | 176 |
169 MemoryDumpProvider* const dump_provider; | 177 MemoryDumpProvider* const dump_provider; |
170 | 178 |
| 179 // Used to transfer ownership for UnregisterAndDeleteDumpProviderSoon(). |
| 180 // nullptr in all other cases. |
| 181 scoped_ptr<MemoryDumpProvider> owned_dump_provider; |
| 182 |
171 // Human readable name, for debugging and testing. Not necessarily unique. | 183 // Human readable name, for debugging and testing. Not necessarily unique. |
172 const char* const name; | 184 const char* const name; |
173 | 185 |
174 // The task_runner affinity. Can be nullptr, in which case the dump provider | 186 // The task_runner affinity. Can be nullptr, in which case the dump provider |
175 // will be invoked on |dump_thread_|. | 187 // will be invoked on |dump_thread_|. |
176 const scoped_refptr<SingleThreadTaskRunner> task_runner; | 188 const scoped_refptr<SingleThreadTaskRunner> task_runner; |
177 | 189 |
178 // The |options| arg passed to RegisterDumpProvider(). | 190 // The |options| arg passed to RegisterDumpProvider(). |
179 const MemoryDumpProvider::Options options; | 191 const MemoryDumpProvider::Options options; |
180 | 192 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 // |callback| will be invoked asynchronously upon completion on the same | 269 // |callback| will be invoked asynchronously upon completion on the same |
258 // thread on which CreateProcessDump() was called. | 270 // thread on which CreateProcessDump() was called. |
259 void CreateProcessDump(const MemoryDumpRequestArgs& args, | 271 void CreateProcessDump(const MemoryDumpRequestArgs& args, |
260 const MemoryDumpCallback& callback); | 272 const MemoryDumpCallback& callback); |
261 | 273 |
262 // Continues the ProcessMemoryDump started by CreateProcessDump(), hopping | 274 // Continues the ProcessMemoryDump started by CreateProcessDump(), hopping |
263 // across threads as needed as specified by MDPs in RegisterDumpProvider(). | 275 // across threads as needed as specified by MDPs in RegisterDumpProvider(). |
264 void ContinueAsyncProcessDump( | 276 void ContinueAsyncProcessDump( |
265 ProcessMemoryDumpAsyncState* owned_pmd_async_state); | 277 ProcessMemoryDumpAsyncState* owned_pmd_async_state); |
266 | 278 |
| 279 // Helper for the public UnregisterDumpProvider* functions. |
| 280 void UnregisterDumpProviderInternal(MemoryDumpProvider* mdp, |
| 281 bool take_mdp_ownership_and_delete_async); |
| 282 |
267 // An ordererd set of registered MemoryDumpProviderInfo(s), sorted by thread | 283 // An ordererd set of registered MemoryDumpProviderInfo(s), sorted by thread |
268 // affinity (MDPs belonging to the same thread are adjacent). | 284 // affinity (MDPs belonging to the same thread are adjacent). |
269 MemoryDumpProviderInfo::OrderedSet dump_providers_; | 285 MemoryDumpProviderInfo::OrderedSet dump_providers_; |
270 | 286 |
271 // Shared among all the PMDs to keep state scoped to the tracing session. | 287 // Shared among all the PMDs to keep state scoped to the tracing session. |
272 scoped_refptr<MemoryDumpSessionState> session_state_; | 288 scoped_refptr<MemoryDumpSessionState> session_state_; |
273 | 289 |
274 MemoryDumpManagerDelegate* delegate_; // Not owned. | 290 MemoryDumpManagerDelegate* delegate_; // Not owned. |
275 | 291 |
276 // When true, this instance is in charge of coordinating periodic dumps. | 292 // When true, this instance is in charge of coordinating periodic dumps. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 } | 340 } |
325 | 341 |
326 private: | 342 private: |
327 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); | 343 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); |
328 }; | 344 }; |
329 | 345 |
330 } // namespace trace_event | 346 } // namespace trace_event |
331 } // namespace base | 347 } // namespace base |
332 | 348 |
333 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ | 349 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ |
OLD | NEW |