| 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/atomic_sequence_num.h" | 10 #include "base/atomic_sequence_num.h" |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 // to just skip it, without actually invoking the |mdp|, which might be | 331 // to just skip it, without actually invoking the |mdp|, which might be |
| 332 // destroyed by the caller soon after this method returns. | 332 // destroyed by the caller soon after this method returns. |
| 333 (*mdp_iter)->disabled = true; | 333 (*mdp_iter)->disabled = true; |
| 334 dump_providers_.erase(mdp_iter); | 334 dump_providers_.erase(mdp_iter); |
| 335 } | 335 } |
| 336 | 336 |
| 337 void MemoryDumpManager::RequestGlobalDump( | 337 void MemoryDumpManager::RequestGlobalDump( |
| 338 MemoryDumpType dump_type, | 338 MemoryDumpType dump_type, |
| 339 MemoryDumpLevelOfDetail level_of_detail, | 339 MemoryDumpLevelOfDetail level_of_detail, |
| 340 const MemoryDumpCallback& callback) { | 340 const MemoryDumpCallback& callback) { |
| 341 // Bail out immediately if tracing is not enabled at all. | 341 // Bail out immediately if tracing is not enabled at all or if the dump mode |
| 342 if (!UNLIKELY(subtle::NoBarrier_Load(&memory_tracing_enabled_))) { | 342 // is not allowed. |
| 343 if (!UNLIKELY(subtle::NoBarrier_Load(&memory_tracing_enabled_)) || |
| 344 !IsDumpModeAllowed(level_of_detail)) { |
| 343 VLOG(1) << kLogPrefix << " failed because " << kTraceCategory | 345 VLOG(1) << kLogPrefix << " failed because " << kTraceCategory |
| 344 << " tracing category is not enabled"; | 346 << " tracing category is not enabled or the requested dump mode is " |
| 347 "not allowed by trace config."; |
| 345 if (!callback.is_null()) | 348 if (!callback.is_null()) |
| 346 callback.Run(0u /* guid */, false /* success */); | 349 callback.Run(0u /* guid */, false /* success */); |
| 347 return; | 350 return; |
| 348 } | 351 } |
| 349 | 352 |
| 350 const uint64_t guid = | 353 const uint64_t guid = |
| 351 TraceLog::GetInstance()->MangleEventId(g_next_guid.GetNext()); | 354 TraceLog::GetInstance()->MangleEventId(g_next_guid.GetNext()); |
| 352 | 355 |
| 353 // Creates an async event to keep track of the global dump evolution. | 356 // Creates an async event to keep track of the global dump evolution. |
| 354 // The |wrapped_callback| will generate the ASYNC_END event and then invoke | 357 // The |wrapped_callback| will generate the ASYNC_END event and then invoke |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 session_state_ = nullptr; | 710 session_state_ = nullptr; |
| 708 } | 711 } |
| 709 | 712 |
| 710 // Thread stops are blocking and must be performed outside of the |lock_| | 713 // Thread stops are blocking and must be performed outside of the |lock_| |
| 711 // or will deadlock (e.g., if SetupNextMemoryDump() tries to acquire it). | 714 // or will deadlock (e.g., if SetupNextMemoryDump() tries to acquire it). |
| 712 periodic_dump_timer_.Stop(); | 715 periodic_dump_timer_.Stop(); |
| 713 if (dump_thread) | 716 if (dump_thread) |
| 714 dump_thread->Stop(); | 717 dump_thread->Stop(); |
| 715 } | 718 } |
| 716 | 719 |
| 720 bool MemoryDumpManager::IsDumpModeAllowed(MemoryDumpLevelOfDetail dump_mode) { |
| 721 AutoLock lock(lock_); |
| 722 if (!session_state_) |
| 723 return false; |
| 724 return session_state_->memory_dump_config().allowed_dump_modes.count( |
| 725 dump_mode) != 0; |
| 726 } |
| 727 |
| 717 uint64_t MemoryDumpManager::GetTracingProcessId() const { | 728 uint64_t MemoryDumpManager::GetTracingProcessId() const { |
| 718 return delegate_->GetTracingProcessId(); | 729 return delegate_->GetTracingProcessId(); |
| 719 } | 730 } |
| 720 | 731 |
| 721 MemoryDumpManager::MemoryDumpProviderInfo::MemoryDumpProviderInfo( | 732 MemoryDumpManager::MemoryDumpProviderInfo::MemoryDumpProviderInfo( |
| 722 MemoryDumpProvider* dump_provider, | 733 MemoryDumpProvider* dump_provider, |
| 723 const char* name, | 734 const char* name, |
| 724 scoped_refptr<SequencedTaskRunner> task_runner, | 735 scoped_refptr<SequencedTaskRunner> task_runner, |
| 725 const MemoryDumpProvider::Options& options, | 736 const MemoryDumpProvider::Options& options, |
| 726 bool whitelisted_for_background_mode) | 737 bool whitelisted_for_background_mode) |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 return; | 800 return; |
| 790 | 801 |
| 791 // At the moment the periodic support is limited to at most one periodic | 802 // At the moment the periodic support is limited to at most one periodic |
| 792 // trigger per dump mode. All intervals should be an integer multiple of the | 803 // trigger per dump mode. All intervals should be an integer multiple of the |
| 793 // smallest interval specified. | 804 // smallest interval specified. |
| 794 periodic_dumps_count_ = 0; | 805 periodic_dumps_count_ = 0; |
| 795 uint32_t min_timer_period_ms = std::numeric_limits<uint32_t>::max(); | 806 uint32_t min_timer_period_ms = std::numeric_limits<uint32_t>::max(); |
| 796 uint32_t light_dump_period_ms = 0; | 807 uint32_t light_dump_period_ms = 0; |
| 797 uint32_t heavy_dump_period_ms = 0; | 808 uint32_t heavy_dump_period_ms = 0; |
| 798 DCHECK_LE(triggers_list.size(), 3u); | 809 DCHECK_LE(triggers_list.size(), 3u); |
| 810 auto mdm = MemoryDumpManager::GetInstance(); |
| 799 for (const TraceConfig::MemoryDumpConfig::Trigger& config : triggers_list) { | 811 for (const TraceConfig::MemoryDumpConfig::Trigger& config : triggers_list) { |
| 800 DCHECK_NE(0u, config.periodic_interval_ms); | 812 DCHECK_NE(0u, config.periodic_interval_ms); |
| 801 if (config.level_of_detail == MemoryDumpLevelOfDetail::LIGHT) { | 813 switch (config.level_of_detail) { |
| 802 DCHECK_EQ(0u, light_dump_period_ms); | 814 case MemoryDumpLevelOfDetail::BACKGROUND: |
| 803 light_dump_period_ms = config.periodic_interval_ms; | 815 DCHECK(mdm->IsDumpModeAllowed(MemoryDumpLevelOfDetail::BACKGROUND)); |
| 804 } else if (config.level_of_detail == MemoryDumpLevelOfDetail::DETAILED) { | 816 break; |
| 805 DCHECK_EQ(0u, heavy_dump_period_ms); | 817 case MemoryDumpLevelOfDetail::LIGHT: |
| 806 heavy_dump_period_ms = config.periodic_interval_ms; | 818 DCHECK_EQ(0u, light_dump_period_ms); |
| 819 DCHECK(mdm->IsDumpModeAllowed(MemoryDumpLevelOfDetail::LIGHT)); |
| 820 light_dump_period_ms = config.periodic_interval_ms; |
| 821 break; |
| 822 case MemoryDumpLevelOfDetail::DETAILED: |
| 823 DCHECK_EQ(0u, heavy_dump_period_ms); |
| 824 DCHECK(mdm->IsDumpModeAllowed(MemoryDumpLevelOfDetail::DETAILED)); |
| 825 heavy_dump_period_ms = config.periodic_interval_ms; |
| 826 break; |
| 807 } | 827 } |
| 808 min_timer_period_ms = | 828 min_timer_period_ms = |
| 809 std::min(min_timer_period_ms, config.periodic_interval_ms); | 829 std::min(min_timer_period_ms, config.periodic_interval_ms); |
| 810 } | 830 } |
| 811 | 831 |
| 812 DCHECK_EQ(0u, light_dump_period_ms % min_timer_period_ms); | 832 DCHECK_EQ(0u, light_dump_period_ms % min_timer_period_ms); |
| 813 light_dump_rate_ = light_dump_period_ms / min_timer_period_ms; | 833 light_dump_rate_ = light_dump_period_ms / min_timer_period_ms; |
| 814 DCHECK_EQ(0u, heavy_dump_period_ms % min_timer_period_ms); | 834 DCHECK_EQ(0u, heavy_dump_period_ms % min_timer_period_ms); |
| 815 heavy_dump_rate_ = heavy_dump_period_ms / min_timer_period_ms; | 835 heavy_dump_rate_ = heavy_dump_period_ms / min_timer_period_ms; |
| 816 | 836 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 836 if (heavy_dump_rate_ > 0 && periodic_dumps_count_ % heavy_dump_rate_ == 0) | 856 if (heavy_dump_rate_ > 0 && periodic_dumps_count_ % heavy_dump_rate_ == 0) |
| 837 level_of_detail = MemoryDumpLevelOfDetail::DETAILED; | 857 level_of_detail = MemoryDumpLevelOfDetail::DETAILED; |
| 838 ++periodic_dumps_count_; | 858 ++periodic_dumps_count_; |
| 839 | 859 |
| 840 MemoryDumpManager::GetInstance()->RequestGlobalDump( | 860 MemoryDumpManager::GetInstance()->RequestGlobalDump( |
| 841 MemoryDumpType::PERIODIC_INTERVAL, level_of_detail); | 861 MemoryDumpType::PERIODIC_INTERVAL, level_of_detail); |
| 842 } | 862 } |
| 843 | 863 |
| 844 } // namespace trace_event | 864 } // namespace trace_event |
| 845 } // namespace base | 865 } // namespace base |
| OLD | NEW |