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; |
120 bool operator==(const MemoryDumpProviderInfo& other) const; | |
118 | 121 |
119 MemoryDumpProvider* const dump_provider; | 122 MemoryDumpProvider* const dump_provider; |
120 scoped_refptr<SingleThreadTaskRunner> task_runner; // Optional. | 123 scoped_refptr<SingleThreadTaskRunner> task_runner; // Optional. |
121 | 124 |
122 // For fail-safe logic (auto-disable failing MDPs). These fields are mutable | 125 // 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. | 126 // as can be safely changed without impacting the order within the set. |
124 mutable int consecutive_failures; | 127 mutable int consecutive_failures; |
125 mutable bool disabled; | 128 mutable bool disabled; |
129 | |
130 // When unregistering, we do not remove the provider immediately because a | |
131 // dump may be happening which depends on the set order. Instead, we clean | |
132 // up the set after the dump. | |
133 mutable bool unregistered; | |
Primiano Tucci (use gerrit)
2015/08/21 09:00:31
I think you don't need this to be mutable.
Ruud van Asseldonk
2015/08/21 10:51:40
I does need to be mutable, for the same reason tha
Primiano Tucci (use gerrit)
2015/08/24 09:31:19
Ahh right.
| |
126 }; | 134 }; |
127 | 135 |
128 using MemoryDumpProviderInfoSet = std::set<MemoryDumpProviderInfo>; | 136 using MemoryDumpProviderInfoSet = std::set<MemoryDumpProviderInfo>; |
129 | 137 |
130 // Holds the state of a process memory dump that needs to be carried over | 138 // Holds the state of a process memory dump that needs to be carried over |
131 // across threads in order to fulfil an asynchronous CreateProcessDump() | 139 // across threads in order to fulfil an asynchronous CreateProcessDump() |
132 // request. At any time exactly one thread owns a ProcessMemoryDumpAsyncState. | 140 // request. At any time exactly one thread owns a ProcessMemoryDumpAsyncState. |
133 struct ProcessMemoryDumpAsyncState { | 141 struct ProcessMemoryDumpAsyncState { |
134 ProcessMemoryDumpAsyncState( | 142 ProcessMemoryDumpAsyncState( |
135 MemoryDumpRequestArgs req_args, | 143 MemoryDumpRequestArgs req_args, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 | 190 |
183 // Continues the ProcessMemoryDump started by CreateProcessDump(), hopping | 191 // Continues the ProcessMemoryDump started by CreateProcessDump(), hopping |
184 // across threads as needed as specified by MDPs in RegisterDumpProvider(). | 192 // across threads as needed as specified by MDPs in RegisterDumpProvider(). |
185 void ContinueAsyncProcessDump( | 193 void ContinueAsyncProcessDump( |
186 scoped_ptr<ProcessMemoryDumpAsyncState> pmd_async_state); | 194 scoped_ptr<ProcessMemoryDumpAsyncState> pmd_async_state); |
187 | 195 |
188 // An ordererd set of registered MemoryDumpProviderInfo(s), sorted by thread | 196 // An ordererd set of registered MemoryDumpProviderInfo(s), sorted by thread |
189 // affinity (MDPs belonging to the same thread are adjacent). | 197 // affinity (MDPs belonging to the same thread are adjacent). |
190 MemoryDumpProviderInfoSet dump_providers_; | 198 MemoryDumpProviderInfoSet dump_providers_; |
191 | 199 |
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. | 200 // Shared among all the PMDs to keep state scoped to the tracing session. |
197 scoped_refptr<MemoryDumpSessionState> session_state_; | 201 scoped_refptr<MemoryDumpSessionState> session_state_; |
198 | 202 |
199 MemoryDumpManagerDelegate* delegate_; // Not owned. | 203 MemoryDumpManagerDelegate* delegate_; // Not owned. |
200 | 204 |
201 // Protects from concurrent accesses to the |dump_providers_*| and |delegate_| | 205 // Protects from concurrent accesses to the |dump_providers_*| and |delegate_| |
202 // to guard against disabling logging while dumping on another thread. | 206 // to guard against disabling logging while dumping on another thread. |
203 Lock lock_; | 207 Lock lock_; |
204 | 208 |
205 // Optimization to avoid attempting any memory dump (i.e. to not walk an empty | 209 // 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 } | 251 } |
248 | 252 |
249 private: | 253 private: |
250 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); | 254 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); |
251 }; | 255 }; |
252 | 256 |
253 } // namespace trace_event | 257 } // namespace trace_event |
254 } // namespace base | 258 } // namespace base |
255 | 259 |
256 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ | 260 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ |
OLD | NEW |