| 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 #include "base/trace_event/memory_dump_manager.h" | 5 #include "base/trace_event/memory_dump_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/allocator/features.h" | 10 #include "base/allocator/features.h" |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 scoped_refptr<SequencedTaskRunner> task_runner, | 270 scoped_refptr<SequencedTaskRunner> task_runner, |
| 271 const MemoryDumpProvider::Options& options) { | 271 const MemoryDumpProvider::Options& options) { |
| 272 if (dumper_registrations_ignored_for_testing_) | 272 if (dumper_registrations_ignored_for_testing_) |
| 273 return; | 273 return; |
| 274 | 274 |
| 275 bool whitelisted_for_background_mode = IsMemoryDumpProviderWhitelisted(name); | 275 bool whitelisted_for_background_mode = IsMemoryDumpProviderWhitelisted(name); |
| 276 scoped_refptr<MemoryDumpProviderInfo> mdpinfo = | 276 scoped_refptr<MemoryDumpProviderInfo> mdpinfo = |
| 277 new MemoryDumpProviderInfo(mdp, name, std::move(task_runner), options, | 277 new MemoryDumpProviderInfo(mdp, name, std::move(task_runner), options, |
| 278 whitelisted_for_background_mode); | 278 whitelisted_for_background_mode); |
| 279 | 279 |
| 280 if (options.is_fast_polling_supported) { |
| 281 DCHECK(!mdpinfo->task_runner) << "MemoryDumpProviders capable of fast " |
| 282 "polling must NOT be thread bound."; |
| 283 } |
| 284 |
| 280 { | 285 { |
| 281 AutoLock lock(lock_); | 286 AutoLock lock(lock_); |
| 282 bool already_registered = !dump_providers_.insert(mdpinfo).second; | 287 bool already_registered = !dump_providers_.insert(mdpinfo).second; |
| 283 // This actually happens in some tests which don't have a clean tear-down | 288 // This actually happens in some tests which don't have a clean tear-down |
| 284 // path for RenderThreadImpl::Init(). | 289 // path for RenderThreadImpl::Init(). |
| 285 if (already_registered) | 290 if (already_registered) |
| 286 return; | 291 return; |
| 287 | 292 |
| 288 // The list of polling MDPs is populated OnTraceLogEnabled(). This code | 293 // The list of polling MDPs is populated OnTraceLogEnabled(). This code |
| 289 // deals with the case of a MDP capable of fast polling that is registered | 294 // deals with the case of a MDP capable of fast polling that is registered |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 // transferred via UnregisterAndDeleteDumpProviderSoon(). | 349 // transferred via UnregisterAndDeleteDumpProviderSoon(). |
| 345 // In all the other cases, it is not possible to guarantee that the | 350 // In all the other cases, it is not possible to guarantee that the |
| 346 // unregistration will not race with OnMemoryDump() calls. | 351 // unregistration will not race with OnMemoryDump() calls. |
| 347 DCHECK((*mdp_iter)->task_runner && | 352 DCHECK((*mdp_iter)->task_runner && |
| 348 (*mdp_iter)->task_runner->RunsTasksOnCurrentThread()) | 353 (*mdp_iter)->task_runner->RunsTasksOnCurrentThread()) |
| 349 << "MemoryDumpProvider \"" << (*mdp_iter)->name << "\" attempted to " | 354 << "MemoryDumpProvider \"" << (*mdp_iter)->name << "\" attempted to " |
| 350 << "unregister itself in a racy way. Please file a crbug."; | 355 << "unregister itself in a racy way. Please file a crbug."; |
| 351 } | 356 } |
| 352 | 357 |
| 353 if ((*mdp_iter)->options.is_fast_polling_supported && dump_thread_) { | 358 if ((*mdp_iter)->options.is_fast_polling_supported && dump_thread_) { |
| 354 DCHECK(take_mdp_ownership_and_delete_async) | 359 DCHECK(take_mdp_ownership_and_delete_async); |
| 355 << "MemoryDumpProviders capable of fast polling must NOT be thread " | |
| 356 "bound and hence must be destroyed using " | |
| 357 "UnregisterAndDeleteDumpProviderSoon()"; | |
| 358 dump_thread_->task_runner()->PostTask( | 360 dump_thread_->task_runner()->PostTask( |
| 359 FROM_HERE, Bind(&MemoryDumpManager::UnregisterPollingMDPOnDumpThread, | 361 FROM_HERE, Bind(&MemoryDumpManager::UnregisterPollingMDPOnDumpThread, |
| 360 Unretained(this), *mdp_iter)); | 362 Unretained(this), *mdp_iter)); |
| 361 } | 363 } |
| 362 | 364 |
| 363 // The MDPInfo instance can still be referenced by the | 365 // The MDPInfo instance can still be referenced by the |
| 364 // |ProcessMemoryDumpAsyncState.pending_dump_providers|. For this reason | 366 // |ProcessMemoryDumpAsyncState.pending_dump_providers|. For this reason |
| 365 // the MDPInfo is flagged as disabled. It will cause InvokeOnMemoryDump() | 367 // the MDPInfo is flagged as disabled. It will cause InvokeOnMemoryDump() |
| 366 // to just skip it, without actually invoking the |mdp|, which might be | 368 // to just skip it, without actually invoking the |mdp|, which might be |
| 367 // destroyed by the caller soon after this method returns. | 369 // destroyed by the caller soon after this method returns. |
| 368 (*mdp_iter)->disabled = true; | 370 (*mdp_iter)->disabled = true; |
| 369 dump_providers_.erase(mdp_iter); | 371 dump_providers_.erase(mdp_iter); |
| 370 } | 372 } |
| 371 | 373 |
| 372 void MemoryDumpManager::RegisterPollingMDPOnDumpThread( | 374 void MemoryDumpManager::RegisterPollingMDPOnDumpThread( |
| 373 scoped_refptr<MemoryDumpManager::MemoryDumpProviderInfo> mdpinfo) { | 375 scoped_refptr<MemoryDumpManager::MemoryDumpProviderInfo> mdpinfo) { |
| 374 DCHECK(!mdpinfo->task_runner); | |
| 375 AutoLock lock(lock_); | 376 AutoLock lock(lock_); |
| 376 dump_providers_for_polling_.insert(mdpinfo); | 377 dump_providers_for_polling_.insert(mdpinfo); |
| 377 } | 378 } |
| 378 | 379 |
| 379 void MemoryDumpManager::UnregisterPollingMDPOnDumpThread( | 380 void MemoryDumpManager::UnregisterPollingMDPOnDumpThread( |
| 380 scoped_refptr<MemoryDumpManager::MemoryDumpProviderInfo> mdpinfo) { | 381 scoped_refptr<MemoryDumpManager::MemoryDumpProviderInfo> mdpinfo) { |
| 381 mdpinfo->dump_provider->SuspendFastMemoryPolling(); | 382 mdpinfo->dump_provider->SuspendFastMemoryPolling(); |
| 382 | 383 |
| 383 AutoLock lock(lock_); | 384 AutoLock lock(lock_); |
| 384 dump_providers_for_polling_.erase(mdpinfo); | 385 dump_providers_for_polling_.erase(mdpinfo); |
| (...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 if (heavy_dump_rate_ > 0 && periodic_dumps_count_ % heavy_dump_rate_ == 0) | 956 if (heavy_dump_rate_ > 0 && periodic_dumps_count_ % heavy_dump_rate_ == 0) |
| 956 level_of_detail = MemoryDumpLevelOfDetail::DETAILED; | 957 level_of_detail = MemoryDumpLevelOfDetail::DETAILED; |
| 957 ++periodic_dumps_count_; | 958 ++periodic_dumps_count_; |
| 958 | 959 |
| 959 MemoryDumpManager::GetInstance()->RequestGlobalDump( | 960 MemoryDumpManager::GetInstance()->RequestGlobalDump( |
| 960 MemoryDumpType::PERIODIC_INTERVAL, level_of_detail); | 961 MemoryDumpType::PERIODIC_INTERVAL, level_of_detail); |
| 961 } | 962 } |
| 962 | 963 |
| 963 } // namespace trace_event | 964 } // namespace trace_event |
| 964 } // namespace base | 965 } // namespace base |
| OLD | NEW |