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 <set> | 8 #include <set> |
9 | 9 |
10 #include "base/atomicops.h" | 10 #include "base/atomicops.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 const char* system_allocator_pool_name() const { | 96 const char* system_allocator_pool_name() const { |
97 return system_allocator_pool_name_; | 97 return system_allocator_pool_name_; |
98 }; | 98 }; |
99 | 99 |
100 private: | 100 private: |
101 friend struct DefaultDeleter<MemoryDumpManager>; // For the testing instance. | 101 friend struct DefaultDeleter<MemoryDumpManager>; // For the testing instance. |
102 friend struct DefaultSingletonTraits<MemoryDumpManager>; | 102 friend struct DefaultSingletonTraits<MemoryDumpManager>; |
103 friend class MemoryDumpManagerDelegate; | 103 friend class MemoryDumpManagerDelegate; |
104 friend class MemoryDumpManagerTest; | 104 friend class MemoryDumpManagerTest; |
105 FRIEND_TEST_ALL_PREFIXES(MemoryDumpManagerTest, DisableFailingDumpers); | 105 FRIEND_TEST_ALL_PREFIXES(MemoryDumpManagerTest, DisableFailingDumpers); |
| 106 FRIEND_TEST_ALL_PREFIXES(MemoryDumpManagerTest, |
| 107 UnregisterDumperFromThreadWhileDumping); |
106 | 108 |
107 // Descriptor struct used to hold information about registered MDPs. It is | 109 // Descriptor struct used to hold information about registered MDPs. It is |
108 // deliberately copyable, in order to allow it to be used as std::set value. | 110 // deliberately copyable, in order to allow it to be used as std::set value. |
109 struct MemoryDumpProviderInfo { | 111 struct MemoryDumpProviderInfo { |
110 MemoryDumpProviderInfo( | 112 MemoryDumpProviderInfo( |
111 MemoryDumpProvider* dump_provider, | 113 MemoryDumpProvider* dump_provider, |
112 const scoped_refptr<SingleThreadTaskRunner>& task_runner); | 114 const scoped_refptr<SingleThreadTaskRunner>& task_runner); |
113 ~MemoryDumpProviderInfo(); | 115 ~MemoryDumpProviderInfo(); |
114 | 116 |
115 // Define a total order based on the thread (i.e. |task_runner|) affinity, | 117 // Define a total order based on the thread (i.e. |task_runner|) affinity, |
116 // so that all MDP belonging to the same thread are adjacent in the set. | 118 // so that all MDP belonging to the same thread are adjacent in the set. |
117 bool operator<(const MemoryDumpProviderInfo& other) const; | 119 bool operator<(const MemoryDumpProviderInfo& other) const; |
118 | 120 |
119 MemoryDumpProvider* const dump_provider; | 121 MemoryDumpProvider* const dump_provider; |
120 scoped_refptr<SingleThreadTaskRunner> task_runner; // Optional. | 122 scoped_refptr<SingleThreadTaskRunner> task_runner; // Optional. |
121 | 123 |
122 // For fail-safe logic (auto-disable failing MDPs). These fields are mutable | 124 // For fail-safe logic (auto-disable failing MDPs). These fields are mutable |
123 // as can be safely changed without impacting the order within the set. | 125 // as can be safely changed without impacting the order within the set. |
124 mutable int consecutive_failures; | 126 mutable int consecutive_failures; |
125 mutable bool disabled; | 127 mutable bool disabled; |
| 128 |
| 129 // When a dump provider unregisters, it is flagged as |unregistered| and it |
| 130 // is removed only upon the next memory dump. This is to avoid altering the |
| 131 // |dump_providers_| collection while a dump is in progress. |
| 132 mutable bool unregistered; |
126 }; | 133 }; |
127 | 134 |
128 using MemoryDumpProviderInfoSet = std::set<MemoryDumpProviderInfo>; | 135 using MemoryDumpProviderInfoSet = std::set<MemoryDumpProviderInfo>; |
129 | 136 |
130 // Holds the state of a process memory dump that needs to be carried over | 137 // Holds the state of a process memory dump that needs to be carried over |
131 // across threads in order to fulfil an asynchronous CreateProcessDump() | 138 // across threads in order to fulfil an asynchronous CreateProcessDump() |
132 // request. At any time exactly one thread owns a ProcessMemoryDumpAsyncState. | 139 // request. At any time exactly one thread owns a ProcessMemoryDumpAsyncState. |
133 struct ProcessMemoryDumpAsyncState { | 140 struct ProcessMemoryDumpAsyncState { |
134 ProcessMemoryDumpAsyncState( | 141 ProcessMemoryDumpAsyncState( |
135 MemoryDumpRequestArgs req_args, | 142 MemoryDumpRequestArgs req_args, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 | 189 |
183 // Continues the ProcessMemoryDump started by CreateProcessDump(), hopping | 190 // Continues the ProcessMemoryDump started by CreateProcessDump(), hopping |
184 // across threads as needed as specified by MDPs in RegisterDumpProvider(). | 191 // across threads as needed as specified by MDPs in RegisterDumpProvider(). |
185 void ContinueAsyncProcessDump( | 192 void ContinueAsyncProcessDump( |
186 scoped_ptr<ProcessMemoryDumpAsyncState> pmd_async_state); | 193 scoped_ptr<ProcessMemoryDumpAsyncState> pmd_async_state); |
187 | 194 |
188 // An ordererd set of registered MemoryDumpProviderInfo(s), sorted by thread | 195 // An ordererd set of registered MemoryDumpProviderInfo(s), sorted by thread |
189 // affinity (MDPs belonging to the same thread are adjacent). | 196 // affinity (MDPs belonging to the same thread are adjacent). |
190 MemoryDumpProviderInfoSet dump_providers_; | 197 MemoryDumpProviderInfoSet dump_providers_; |
191 | 198 |
192 // Flag used to signal that some provider was removed from |dump_providers_| | |
193 // and therefore the current memory dump (if any) should be aborted. | |
194 bool did_unregister_dump_provider_; | |
195 | |
196 // Shared among all the PMDs to keep state scoped to the tracing session. | 199 // Shared among all the PMDs to keep state scoped to the tracing session. |
197 scoped_refptr<MemoryDumpSessionState> session_state_; | 200 scoped_refptr<MemoryDumpSessionState> session_state_; |
198 | 201 |
199 MemoryDumpManagerDelegate* delegate_; // Not owned. | 202 MemoryDumpManagerDelegate* delegate_; // Not owned. |
200 | 203 |
201 // Protects from concurrent accesses to the |dump_providers_*| and |delegate_| | 204 // Protects from concurrent accesses to the |dump_providers_*| and |delegate_| |
202 // to guard against disabling logging while dumping on another thread. | 205 // to guard against disabling logging while dumping on another thread. |
203 Lock lock_; | 206 Lock lock_; |
204 | 207 |
205 // Optimization to avoid attempting any memory dump (i.e. to not walk an empty | 208 // Optimization to avoid attempting any memory dump (i.e. to not walk an empty |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 } | 250 } |
248 | 251 |
249 private: | 252 private: |
250 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); | 253 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); |
251 }; | 254 }; |
252 | 255 |
253 } // namespace trace_event | 256 } // namespace trace_event |
254 } // namespace base | 257 } // namespace base |
255 | 258 |
256 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ | 259 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ |
OLD | NEW |