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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 // allocator registered (which is currently the case for Mac OS). | 134 // allocator registered (which is currently the case for Mac OS). |
135 const char* system_allocator_pool_name() const { | 135 const char* system_allocator_pool_name() const { |
136 return kSystemAllocatorPoolName; | 136 return kSystemAllocatorPoolName; |
137 }; | 137 }; |
138 | 138 |
139 // When set to true, calling |RegisterMemoryDumpProvider| is a no-op. | 139 // When set to true, calling |RegisterMemoryDumpProvider| is a no-op. |
140 void set_dumper_registrations_ignored_for_testing(bool ignored) { | 140 void set_dumper_registrations_ignored_for_testing(bool ignored) { |
141 dumper_registrations_ignored_for_testing_ = ignored; | 141 dumper_registrations_ignored_for_testing_ = ignored; |
142 } | 142 } |
143 | 143 |
| 144 // Resets the dump provider whitelist to the list given. |
| 145 void set_dump_provider_whitelist_for_testing(const char* const* list) { |
| 146 dump_provider_whitelist_ = list; |
| 147 } |
| 148 |
144 private: | 149 private: |
145 friend std::default_delete<MemoryDumpManager>; // For the testing instance. | 150 friend std::default_delete<MemoryDumpManager>; // For the testing instance. |
146 friend struct DefaultSingletonTraits<MemoryDumpManager>; | 151 friend struct DefaultSingletonTraits<MemoryDumpManager>; |
147 friend class MemoryDumpManagerDelegate; | 152 friend class MemoryDumpManagerDelegate; |
148 friend class MemoryDumpManagerTest; | 153 friend class MemoryDumpManagerTest; |
149 | 154 |
150 // Descriptor used to hold information about registered MDPs. | 155 // Descriptor used to hold information about registered MDPs. |
151 // Some important considerations about lifetime of this object: | 156 // Some important considerations about lifetime of this object: |
152 // - In nominal conditions, all the MemoryDumpProviderInfo instances live in | 157 // - In nominal conditions, all the MemoryDumpProviderInfo instances live in |
153 // the |dump_providers_| collection (% unregistration while dumping). | 158 // the |dump_providers_| collection (% unregistration while dumping). |
(...skipping 15 matching lines...) Expand all Loading... |
169 struct Comparator { | 174 struct Comparator { |
170 bool operator()(const scoped_refptr<MemoryDumpProviderInfo>& a, | 175 bool operator()(const scoped_refptr<MemoryDumpProviderInfo>& a, |
171 const scoped_refptr<MemoryDumpProviderInfo>& b) const; | 176 const scoped_refptr<MemoryDumpProviderInfo>& b) const; |
172 }; | 177 }; |
173 using OrderedSet = | 178 using OrderedSet = |
174 std::set<scoped_refptr<MemoryDumpProviderInfo>, Comparator>; | 179 std::set<scoped_refptr<MemoryDumpProviderInfo>, Comparator>; |
175 | 180 |
176 MemoryDumpProviderInfo(MemoryDumpProvider* dump_provider, | 181 MemoryDumpProviderInfo(MemoryDumpProvider* dump_provider, |
177 const char* name, | 182 const char* name, |
178 scoped_refptr<SequencedTaskRunner> task_runner, | 183 scoped_refptr<SequencedTaskRunner> task_runner, |
179 const MemoryDumpProvider::Options& options); | 184 const MemoryDumpProvider::Options& options, |
| 185 bool whitelisted_for_background_mode); |
180 | 186 |
181 MemoryDumpProvider* const dump_provider; | 187 MemoryDumpProvider* const dump_provider; |
182 | 188 |
183 // Used to transfer ownership for UnregisterAndDeleteDumpProviderSoon(). | 189 // Used to transfer ownership for UnregisterAndDeleteDumpProviderSoon(). |
184 // nullptr in all other cases. | 190 // nullptr in all other cases. |
185 std::unique_ptr<MemoryDumpProvider> owned_dump_provider; | 191 std::unique_ptr<MemoryDumpProvider> owned_dump_provider; |
186 | 192 |
187 // Human readable name, for debugging and testing. Not necessarily unique. | 193 // Human readable name, for debugging and testing. Not necessarily unique. |
188 const char* const name; | 194 const char* const name; |
189 | 195 |
190 // The task runner affinity. Can be nullptr, in which case the dump provider | 196 // The task runner affinity. Can be nullptr, in which case the dump provider |
191 // will be invoked on |dump_thread_|. | 197 // will be invoked on |dump_thread_|. |
192 const scoped_refptr<SequencedTaskRunner> task_runner; | 198 const scoped_refptr<SequencedTaskRunner> task_runner; |
193 | 199 |
194 // The |options| arg passed to RegisterDumpProvider(). | 200 // The |options| arg passed to RegisterDumpProvider(). |
195 const MemoryDumpProvider::Options options; | 201 const MemoryDumpProvider::Options options; |
196 | 202 |
197 // For fail-safe logic (auto-disable failing MDPs). | 203 // For fail-safe logic (auto-disable failing MDPs). |
198 int consecutive_failures; | 204 int consecutive_failures; |
199 | 205 |
200 // Flagged either by the auto-disable logic or during unregistration. | 206 // Flagged either by the auto-disable logic or during unregistration. |
201 bool disabled; | 207 bool disabled; |
202 | 208 |
| 209 // True if the dump provider is whitelisted for background mode. |
| 210 const bool whitelisted_for_background_mode; |
| 211 |
203 private: | 212 private: |
204 friend class base::RefCountedThreadSafe<MemoryDumpProviderInfo>; | 213 friend class base::RefCountedThreadSafe<MemoryDumpProviderInfo>; |
205 ~MemoryDumpProviderInfo(); | 214 ~MemoryDumpProviderInfo(); |
206 | 215 |
207 DISALLOW_COPY_AND_ASSIGN(MemoryDumpProviderInfo); | 216 DISALLOW_COPY_AND_ASSIGN(MemoryDumpProviderInfo); |
208 }; | 217 }; |
209 | 218 |
210 // Holds the state of a process memory dump that needs to be carried over | 219 // Holds the state of a process memory dump that needs to be carried over |
211 // across task runners in order to fulfil an asynchronous CreateProcessDump() | 220 // across task runners in order to fulfil an asynchronous CreateProcessDump() |
212 // request. At any time exactly one task runner owns a | 221 // request. At any time exactly one task runner owns a |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 // This is essentially |dump_thread_|.task_runner() but needs to be kept | 264 // This is essentially |dump_thread_|.task_runner() but needs to be kept |
256 // as a separate variable as it needs to be accessed by arbitrary dumpers' | 265 // as a separate variable as it needs to be accessed by arbitrary dumpers' |
257 // threads outside of the lock_ to avoid races when disabling tracing. | 266 // threads outside of the lock_ to avoid races when disabling tracing. |
258 // It is immutable for all the duration of a tracing session. | 267 // It is immutable for all the duration of a tracing session. |
259 const scoped_refptr<SingleThreadTaskRunner> dump_thread_task_runner; | 268 const scoped_refptr<SingleThreadTaskRunner> dump_thread_task_runner; |
260 | 269 |
261 private: | 270 private: |
262 DISALLOW_COPY_AND_ASSIGN(ProcessMemoryDumpAsyncState); | 271 DISALLOW_COPY_AND_ASSIGN(ProcessMemoryDumpAsyncState); |
263 }; | 272 }; |
264 | 273 |
| 274 // Sets up periodic memory dump timers to start global dump requests based on |
| 275 // the dump triggers from trace config. |
| 276 class BASE_EXPORT PeriodicGlobalDumpTimer { |
| 277 public: |
| 278 PeriodicGlobalDumpTimer(); |
| 279 ~PeriodicGlobalDumpTimer(); |
| 280 |
| 281 void Start(const std::vector<TraceConfig::MemoryDumpConfig::Trigger>& |
| 282 triggers_list); |
| 283 void Stop(); |
| 284 |
| 285 bool IsRunning(); |
| 286 |
| 287 private: |
| 288 // Periodically called by the timer. |
| 289 void RequestPeriodicGlobalDump(); |
| 290 |
| 291 RepeatingTimer timer_; |
| 292 uint32_t periodic_dumps_count_; |
| 293 uint32_t light_dump_rate_; |
| 294 uint32_t heavy_dump_rate_; |
| 295 |
| 296 DISALLOW_COPY_AND_ASSIGN(PeriodicGlobalDumpTimer); |
| 297 }; |
| 298 |
265 static const int kMaxConsecutiveFailuresCount; | 299 static const int kMaxConsecutiveFailuresCount; |
266 static const char* const kSystemAllocatorPoolName; | 300 static const char* const kSystemAllocatorPoolName; |
267 | 301 |
268 MemoryDumpManager(); | 302 MemoryDumpManager(); |
269 ~MemoryDumpManager() override; | 303 ~MemoryDumpManager() override; |
270 | 304 |
271 static void SetInstanceForTesting(MemoryDumpManager* instance); | 305 static void SetInstanceForTesting(MemoryDumpManager* instance); |
272 static void FinalizeDumpAndAddToTrace( | 306 static void FinalizeDumpAndAddToTrace( |
273 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state); | 307 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state); |
274 | 308 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 | 352 |
319 // Protects from concurrent accesses to the |dump_providers_*| and |delegate_| | 353 // Protects from concurrent accesses to the |dump_providers_*| and |delegate_| |
320 // to guard against disabling logging while dumping on another thread. | 354 // to guard against disabling logging while dumping on another thread. |
321 Lock lock_; | 355 Lock lock_; |
322 | 356 |
323 // Optimization to avoid attempting any memory dump (i.e. to not walk an empty | 357 // Optimization to avoid attempting any memory dump (i.e. to not walk an empty |
324 // dump_providers_enabled_ list) when tracing is not enabled. | 358 // dump_providers_enabled_ list) when tracing is not enabled. |
325 subtle::AtomicWord memory_tracing_enabled_; | 359 subtle::AtomicWord memory_tracing_enabled_; |
326 | 360 |
327 // For time-triggered periodic dumps. | 361 // For time-triggered periodic dumps. |
328 RepeatingTimer periodic_dump_timer_; | 362 PeriodicGlobalDumpTimer periodic_dump_timer_; |
329 | 363 |
330 // Thread used for MemoryDumpProviders which don't specify a task runner | 364 // Thread used for MemoryDumpProviders which don't specify a task runner |
331 // affinity. | 365 // affinity. |
332 std::unique_ptr<Thread> dump_thread_; | 366 std::unique_ptr<Thread> dump_thread_; |
333 | 367 |
| 368 // List of names of the dump providers whitelisted for background mode. |
| 369 const char* const* dump_provider_whitelist_; |
| 370 |
334 // The unique id of the child process. This is created only for tracing and is | 371 // The unique id of the child process. This is created only for tracing and is |
335 // expected to be valid only when tracing is enabled. | 372 // expected to be valid only when tracing is enabled. |
336 uint64_t tracing_process_id_; | 373 uint64_t tracing_process_id_; |
337 | 374 |
338 // When true, calling |RegisterMemoryDumpProvider| is a no-op. | 375 // When true, calling |RegisterMemoryDumpProvider| is a no-op. |
339 bool dumper_registrations_ignored_for_testing_; | 376 bool dumper_registrations_ignored_for_testing_; |
340 | 377 |
341 // Whether new memory dump providers should be told to enable heap profiling. | 378 // Whether new memory dump providers should be told to enable heap profiling. |
342 bool heap_profiling_enabled_; | 379 bool heap_profiling_enabled_; |
343 | 380 |
(...skipping 21 matching lines...) Expand all Loading... |
365 } | 402 } |
366 | 403 |
367 private: | 404 private: |
368 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); | 405 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); |
369 }; | 406 }; |
370 | 407 |
371 } // namespace trace_event | 408 } // namespace trace_event |
372 } // namespace base | 409 } // namespace base |
373 | 410 |
374 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ | 411 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ |
OLD | NEW |