Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: base/trace_event/memory_dump_manager.cc

Issue 2694083005: memory-infra: Finish moving memory_infra from TracingController (Closed)
Patch Set: review Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 return Singleton<MemoryDumpManager, 146 return Singleton<MemoryDumpManager,
147 LeakySingletonTraits<MemoryDumpManager>>::get(); 147 LeakySingletonTraits<MemoryDumpManager>>::get();
148 } 148 }
149 149
150 // static 150 // static
151 void MemoryDumpManager::SetInstanceForTesting(MemoryDumpManager* instance) { 151 void MemoryDumpManager::SetInstanceForTesting(MemoryDumpManager* instance) {
152 g_instance_for_testing = instance; 152 g_instance_for_testing = instance;
153 } 153 }
154 154
155 MemoryDumpManager::MemoryDumpManager() 155 MemoryDumpManager::MemoryDumpManager()
156 : delegate_(nullptr), 156 : memory_tracing_enabled_(0),
157 is_coordinator_(false),
158 memory_tracing_enabled_(0),
159 tracing_process_id_(kInvalidTracingProcessId), 157 tracing_process_id_(kInvalidTracingProcessId),
160 dumper_registrations_ignored_for_testing_(false), 158 dumper_registrations_ignored_for_testing_(false),
161 heap_profiling_enabled_(false) { 159 heap_profiling_enabled_(false) {
162 g_next_guid.GetNext(); // Make sure that first guid is not zero. 160 g_next_guid.GetNext(); // Make sure that first guid is not zero.
163 161
164 // At this point the command line may not be initialized but we try to 162 // At this point the command line may not be initialized but we try to
165 // enable the heap profiler to capture allocations as soon as possible. 163 // enable the heap profiler to capture allocations as soon as possible.
166 EnableHeapProfilingIfNeeded(); 164 EnableHeapProfilingIfNeeded();
167 165
168 strict_thread_check_blacklist_.insert(std::begin(kStrictThreadCheckBlacklist), 166 strict_thread_check_blacklist_.insert(std::begin(kStrictThreadCheckBlacklist),
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 } else { 203 } else {
206 CHECK(false) << "Invalid mode '" << profiling_mode << "' for " 204 CHECK(false) << "Invalid mode '" << profiling_mode << "' for "
207 << switches::kEnableHeapProfiling << " flag."; 205 << switches::kEnableHeapProfiling << " flag.";
208 } 206 }
209 207
210 for (auto mdp : dump_providers_) 208 for (auto mdp : dump_providers_)
211 mdp->dump_provider->OnHeapProfilingEnabled(true); 209 mdp->dump_provider->OnHeapProfilingEnabled(true);
212 heap_profiling_enabled_ = true; 210 heap_profiling_enabled_ = true;
213 } 211 }
214 212
215 void MemoryDumpManager::Initialize(MemoryDumpManagerDelegate* delegate, 213 void MemoryDumpManager::Initialize(
216 bool is_coordinator) { 214 std::unique_ptr<MemoryDumpManagerDelegate> delegate) {
217 { 215 {
218 AutoLock lock(lock_); 216 AutoLock lock(lock_);
219 DCHECK(delegate); 217 DCHECK(delegate);
220 DCHECK(!delegate_); 218 DCHECK(!delegate_);
221 delegate_ = delegate; 219 delegate_.swap(delegate);
Primiano Tucci (use gerrit) 2017/02/17 19:08:44 As commented above I think this doesn't need to be
chiniforooshan 2017/02/22 05:16:34 Done.
222 is_coordinator_ = is_coordinator;
223 EnableHeapProfilingIfNeeded(); 220 EnableHeapProfilingIfNeeded();
224 } 221 }
225 222
226 // Enable the core dump providers. 223 // Enable the core dump providers.
227 #if defined(MALLOC_MEMORY_TRACING_SUPPORTED) 224 #if defined(MALLOC_MEMORY_TRACING_SUPPORTED)
228 RegisterDumpProvider(MallocDumpProvider::GetInstance(), "Malloc", nullptr); 225 RegisterDumpProvider(MallocDumpProvider::GetInstance(), "Malloc", nullptr);
229 #endif 226 #endif
230 227
231 #if defined(OS_ANDROID) 228 #if defined(OS_ANDROID)
232 RegisterDumpProvider(JavaHeapDumpProvider::GetInstance(), "JavaHeap", 229 RegisterDumpProvider(JavaHeapDumpProvider::GetInstance(), "JavaHeap",
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 const uint64_t guid = 440 const uint64_t guid =
444 TraceLog::GetInstance()->MangleEventId(g_next_guid.GetNext()); 441 TraceLog::GetInstance()->MangleEventId(g_next_guid.GetNext());
445 442
446 // Creates an async event to keep track of the global dump evolution. 443 // Creates an async event to keep track of the global dump evolution.
447 // The |wrapped_callback| will generate the ASYNC_END event and then invoke 444 // The |wrapped_callback| will generate the ASYNC_END event and then invoke
448 // the real |callback| provided by the caller. 445 // the real |callback| provided by the caller.
449 TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(kTraceCategory, "GlobalMemoryDump", 446 TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(kTraceCategory, "GlobalMemoryDump",
450 TRACE_ID_MANGLE(guid)); 447 TRACE_ID_MANGLE(guid));
451 MemoryDumpCallback wrapped_callback = Bind(&OnGlobalDumpDone, callback); 448 MemoryDumpCallback wrapped_callback = Bind(&OnGlobalDumpDone, callback);
452 449
453 // Technically there is no need to grab the |lock_| here as the delegate is
454 // long-lived and can only be set by Initialize(), which is locked and
455 // necessarily happens before memory_tracing_enabled_ == true.
456 // Not taking the |lock_|, though, is lakely make TSan barf and, at this point
457 // (memory-infra is enabled) we're not in the fast-path anymore.
458 MemoryDumpManagerDelegate* delegate;
459 {
460 AutoLock lock(lock_);
461 delegate = delegate_;
462 }
463
464 // The delegate will coordinate the IPC broadcast and at some point invoke 450 // The delegate will coordinate the IPC broadcast and at some point invoke
465 // CreateProcessDump() to get a dump for the current process. 451 // CreateProcessDump() to get a dump for the current process.
466 MemoryDumpRequestArgs args = {guid, dump_type, level_of_detail}; 452 MemoryDumpRequestArgs args = {guid, dump_type, level_of_detail};
467 delegate->RequestGlobalMemoryDump(args, wrapped_callback); 453 delegate_->RequestGlobalMemoryDump(args, wrapped_callback);
468 } 454 }
469 455
470 void MemoryDumpManager::RequestGlobalDump( 456 void MemoryDumpManager::RequestGlobalDump(
471 MemoryDumpType dump_type, 457 MemoryDumpType dump_type,
472 MemoryDumpLevelOfDetail level_of_detail) { 458 MemoryDumpLevelOfDetail level_of_detail) {
473 RequestGlobalDump(dump_type, level_of_detail, MemoryDumpCallback()); 459 RequestGlobalDump(dump_type, level_of_detail, MemoryDumpCallback());
474 } 460 }
475 461
476 void MemoryDumpManager::CreateProcessDump(const MemoryDumpRequestArgs& args, 462 void MemoryDumpManager::CreateProcessDump(const MemoryDumpRequestArgs& args,
477 const MemoryDumpCallback& callback) { 463 const MemoryDumpCallback& callback) {
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 dump_thread_ = std::move(dump_thread); 789 dump_thread_ = std::move(dump_thread);
804 790
805 dump_providers_for_polling_.clear(); 791 dump_providers_for_polling_.clear();
806 for (const auto& mdpinfo : dump_providers_) { 792 for (const auto& mdpinfo : dump_providers_) {
807 if (mdpinfo->options.is_fast_polling_supported) 793 if (mdpinfo->options.is_fast_polling_supported)
808 dump_providers_for_polling_.insert(mdpinfo); 794 dump_providers_for_polling_.insert(mdpinfo);
809 } 795 }
810 796
811 subtle::NoBarrier_Store(&memory_tracing_enabled_, 1); 797 subtle::NoBarrier_Store(&memory_tracing_enabled_, 1);
812 798
813 if (!is_coordinator_) 799 if (!delegate_->IsCoordinator())
814 return; 800 return;
815 } 801 }
816 802
817 // Enable periodic dumps if necessary. 803 // Enable periodic dumps if necessary.
818 periodic_dump_timer_.Start(trace_config.memory_dump_config().triggers); 804 periodic_dump_timer_.Start(trace_config.memory_dump_config().triggers);
819 } 805 }
820 806
821 void MemoryDumpManager::OnTraceLogDisabled() { 807 void MemoryDumpManager::OnTraceLogDisabled() {
822 // There might be a memory dump in progress while this happens. Therefore, 808 // There might be a memory dump in progress while this happens. Therefore,
823 // ensure that the MDM state which depends on the tracing enabled / disabled 809 // ensure that the MDM state which depends on the tracing enabled / disabled
(...skipping 25 matching lines...) Expand all
849 } 835 }
850 836
851 bool MemoryDumpManager::IsDumpModeAllowed(MemoryDumpLevelOfDetail dump_mode) { 837 bool MemoryDumpManager::IsDumpModeAllowed(MemoryDumpLevelOfDetail dump_mode) {
852 AutoLock lock(lock_); 838 AutoLock lock(lock_);
853 if (!session_state_) 839 if (!session_state_)
854 return false; 840 return false;
855 return session_state_->memory_dump_config().allowed_dump_modes.count( 841 return session_state_->memory_dump_config().allowed_dump_modes.count(
856 dump_mode) != 0; 842 dump_mode) != 0;
857 } 843 }
858 844
859 uint64_t MemoryDumpManager::GetTracingProcessId() const {
860 return delegate_->GetTracingProcessId();
861 }
862
863 MemoryDumpManager::MemoryDumpProviderInfo::MemoryDumpProviderInfo( 845 MemoryDumpManager::MemoryDumpProviderInfo::MemoryDumpProviderInfo(
864 MemoryDumpProvider* dump_provider, 846 MemoryDumpProvider* dump_provider,
865 const char* name, 847 const char* name,
866 scoped_refptr<SequencedTaskRunner> task_runner, 848 scoped_refptr<SequencedTaskRunner> task_runner,
867 const MemoryDumpProvider::Options& options, 849 const MemoryDumpProvider::Options& options,
868 bool whitelisted_for_background_mode) 850 bool whitelisted_for_background_mode)
869 : dump_provider(dump_provider), 851 : dump_provider(dump_provider),
870 name(name), 852 name(name),
871 task_runner(std::move(task_runner)), 853 task_runner(std::move(task_runner)),
872 options(options), 854 options(options),
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 if (heavy_dump_rate_ > 0 && periodic_dumps_count_ % heavy_dump_rate_ == 0) 971 if (heavy_dump_rate_ > 0 && periodic_dumps_count_ % heavy_dump_rate_ == 0)
990 level_of_detail = MemoryDumpLevelOfDetail::DETAILED; 972 level_of_detail = MemoryDumpLevelOfDetail::DETAILED;
991 ++periodic_dumps_count_; 973 ++periodic_dumps_count_;
992 974
993 MemoryDumpManager::GetInstance()->RequestGlobalDump( 975 MemoryDumpManager::GetInstance()->RequestGlobalDump(
994 MemoryDumpType::PERIODIC_INTERVAL, level_of_detail); 976 MemoryDumpType::PERIODIC_INTERVAL, level_of_detail);
995 } 977 }
996 978
997 } // namespace trace_event 979 } // namespace trace_event
998 } // namespace base 980 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698