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

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

Issue 2741203002: memory-infra: Finish moving to Mojo (3nd attempt) (Closed)
Patch Set: rebase Created 3 years, 9 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 return Singleton<MemoryDumpManager, 148 return Singleton<MemoryDumpManager,
149 LeakySingletonTraits<MemoryDumpManager>>::get(); 149 LeakySingletonTraits<MemoryDumpManager>>::get();
150 } 150 }
151 151
152 // static 152 // static
153 void MemoryDumpManager::SetInstanceForTesting(MemoryDumpManager* instance) { 153 void MemoryDumpManager::SetInstanceForTesting(MemoryDumpManager* instance) {
154 g_instance_for_testing = instance; 154 g_instance_for_testing = instance;
155 } 155 }
156 156
157 MemoryDumpManager::MemoryDumpManager() 157 MemoryDumpManager::MemoryDumpManager()
158 : delegate_(nullptr), 158 : memory_tracing_enabled_(0),
159 is_coordinator_(false),
160 memory_tracing_enabled_(0),
161 tracing_process_id_(kInvalidTracingProcessId), 159 tracing_process_id_(kInvalidTracingProcessId),
162 dumper_registrations_ignored_for_testing_(false), 160 dumper_registrations_ignored_for_testing_(false),
163 heap_profiling_enabled_(false) { 161 heap_profiling_enabled_(false) {
164 g_next_guid.GetNext(); // Make sure that first guid is not zero. 162 g_next_guid.GetNext(); // Make sure that first guid is not zero.
165 163
166 // At this point the command line may not be initialized but we try to 164 // At this point the command line may not be initialized but we try to
167 // enable the heap profiler to capture allocations as soon as possible. 165 // enable the heap profiler to capture allocations as soon as possible.
168 EnableHeapProfilingIfNeeded(); 166 EnableHeapProfilingIfNeeded();
169 167
170 strict_thread_check_blacklist_.insert(std::begin(kStrictThreadCheckBlacklist), 168 strict_thread_check_blacklist_.insert(std::begin(kStrictThreadCheckBlacklist),
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 } else { 205 } else {
208 CHECK(false) << "Invalid mode '" << profiling_mode << "' for " 206 CHECK(false) << "Invalid mode '" << profiling_mode << "' for "
209 << switches::kEnableHeapProfiling << " flag."; 207 << switches::kEnableHeapProfiling << " flag.";
210 } 208 }
211 209
212 for (auto mdp : dump_providers_) 210 for (auto mdp : dump_providers_)
213 mdp->dump_provider->OnHeapProfilingEnabled(true); 211 mdp->dump_provider->OnHeapProfilingEnabled(true);
214 heap_profiling_enabled_ = true; 212 heap_profiling_enabled_ = true;
215 } 213 }
216 214
217 void MemoryDumpManager::Initialize(MemoryDumpManagerDelegate* delegate, 215 void MemoryDumpManager::Initialize(
218 bool is_coordinator) { 216 std::unique_ptr<MemoryDumpManagerDelegate> delegate) {
219 { 217 {
220 AutoLock lock(lock_); 218 AutoLock lock(lock_);
221 DCHECK(delegate); 219 DCHECK(delegate);
222 DCHECK(!delegate_); 220 DCHECK(!delegate_);
223 delegate_ = delegate; 221 delegate_ = std::move(delegate);
224 is_coordinator_ = is_coordinator;
225 EnableHeapProfilingIfNeeded(); 222 EnableHeapProfilingIfNeeded();
226 } 223 }
227 224
228 // Enable the core dump providers. 225 // Enable the core dump providers.
229 #if defined(MALLOC_MEMORY_TRACING_SUPPORTED) 226 #if defined(MALLOC_MEMORY_TRACING_SUPPORTED)
230 RegisterDumpProvider(MallocDumpProvider::GetInstance(), "Malloc", nullptr); 227 RegisterDumpProvider(MallocDumpProvider::GetInstance(), "Malloc", nullptr);
231 #endif 228 #endif
232 229
233 #if defined(OS_ANDROID) 230 #if defined(OS_ANDROID)
234 RegisterDumpProvider(JavaHeapDumpProvider::GetInstance(), "JavaHeap", 231 RegisterDumpProvider(JavaHeapDumpProvider::GetInstance(), "JavaHeap",
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 const uint64_t guid = 450 const uint64_t guid =
454 TraceLog::GetInstance()->MangleEventId(g_next_guid.GetNext()); 451 TraceLog::GetInstance()->MangleEventId(g_next_guid.GetNext());
455 452
456 // Creates an async event to keep track of the global dump evolution. 453 // Creates an async event to keep track of the global dump evolution.
457 // The |wrapped_callback| will generate the ASYNC_END event and then invoke 454 // The |wrapped_callback| will generate the ASYNC_END event and then invoke
458 // the real |callback| provided by the caller. 455 // the real |callback| provided by the caller.
459 TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(kTraceCategory, "GlobalMemoryDump", 456 TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(kTraceCategory, "GlobalMemoryDump",
460 TRACE_ID_MANGLE(guid)); 457 TRACE_ID_MANGLE(guid));
461 MemoryDumpCallback wrapped_callback = Bind(&OnGlobalDumpDone, callback); 458 MemoryDumpCallback wrapped_callback = Bind(&OnGlobalDumpDone, callback);
462 459
463 // Technically there is no need to grab the |lock_| here as the delegate is
464 // long-lived and can only be set by Initialize(), which is locked and
465 // necessarily happens before memory_tracing_enabled_ == true.
466 // Not taking the |lock_|, though, is lakely make TSan barf and, at this point
467 // (memory-infra is enabled) we're not in the fast-path anymore.
468 MemoryDumpManagerDelegate* delegate;
469 {
470 AutoLock lock(lock_);
471 delegate = delegate_;
472 }
473
474 // The delegate will coordinate the IPC broadcast and at some point invoke 460 // The delegate will coordinate the IPC broadcast and at some point invoke
475 // CreateProcessDump() to get a dump for the current process. 461 // CreateProcessDump() to get a dump for the current process.
476 MemoryDumpRequestArgs args = {guid, dump_type, level_of_detail}; 462 MemoryDumpRequestArgs args = {guid, dump_type, level_of_detail};
477 delegate->RequestGlobalMemoryDump(args, wrapped_callback); 463 delegate_->RequestGlobalMemoryDump(args, wrapped_callback);
478 } 464 }
479 465
480 void MemoryDumpManager::RequestGlobalDump( 466 void MemoryDumpManager::RequestGlobalDump(
481 MemoryDumpType dump_type, 467 MemoryDumpType dump_type,
482 MemoryDumpLevelOfDetail level_of_detail) { 468 MemoryDumpLevelOfDetail level_of_detail) {
483 RequestGlobalDump(dump_type, level_of_detail, MemoryDumpCallback()); 469 RequestGlobalDump(dump_type, level_of_detail, MemoryDumpCallback());
484 } 470 }
485 471
486 bool MemoryDumpManager::IsDumpProviderRegisteredForTesting( 472 bool MemoryDumpManager::IsDumpProviderRegisteredForTesting(
487 MemoryDumpProvider* provider) { 473 MemoryDumpProvider* provider) {
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 if (mdpinfo->options.is_fast_polling_supported) 855 if (mdpinfo->options.is_fast_polling_supported)
870 dump_providers_for_polling_.insert(mdpinfo); 856 dump_providers_for_polling_.insert(mdpinfo);
871 } 857 }
872 // Notify polling supported only if some polling supported provider was 858 // Notify polling supported only if some polling supported provider was
873 // registered, else RegisterPollingMDPOnDumpThread() will notify when first 859 // registered, else RegisterPollingMDPOnDumpThread() will notify when first
874 // polling MDP registers. 860 // polling MDP registers.
875 if (!dump_providers_for_polling_.empty()) 861 if (!dump_providers_for_polling_.empty())
876 dump_scheduler_->NotifyPollingSupported(); 862 dump_scheduler_->NotifyPollingSupported();
877 863
878 // Only coordinator process triggers periodic global memory dumps. 864 // Only coordinator process triggers periodic global memory dumps.
879 if (is_coordinator_) 865 if (delegate_->IsCoordinator())
880 dump_scheduler_->NotifyPeriodicTriggerSupported(); 866 dump_scheduler_->NotifyPeriodicTriggerSupported();
881 } 867 }
882 868
883 } 869 }
884 870
885 void MemoryDumpManager::OnTraceLogDisabled() { 871 void MemoryDumpManager::OnTraceLogDisabled() {
886 // There might be a memory dump in progress while this happens. Therefore, 872 // There might be a memory dump in progress while this happens. Therefore,
887 // ensure that the MDM state which depends on the tracing enabled / disabled 873 // ensure that the MDM state which depends on the tracing enabled / disabled
888 // state is always accessed by the dumping methods holding the |lock_|. 874 // state is always accessed by the dumping methods holding the |lock_|.
889 if (!subtle::NoBarrier_Load(&memory_tracing_enabled_)) 875 if (!subtle::NoBarrier_Load(&memory_tracing_enabled_))
(...skipping 24 matching lines...) Expand all
914 } 900 }
915 } 901 }
916 902
917 bool MemoryDumpManager::IsDumpModeAllowed(MemoryDumpLevelOfDetail dump_mode) { 903 bool MemoryDumpManager::IsDumpModeAllowed(MemoryDumpLevelOfDetail dump_mode) {
918 AutoLock lock(lock_); 904 AutoLock lock(lock_);
919 if (!session_state_) 905 if (!session_state_)
920 return false; 906 return false;
921 return session_state_->IsDumpModeAllowed(dump_mode); 907 return session_state_->IsDumpModeAllowed(dump_mode);
922 } 908 }
923 909
924 uint64_t MemoryDumpManager::GetTracingProcessId() const {
925 return delegate_->GetTracingProcessId();
926 }
927
928 MemoryDumpManager::MemoryDumpProviderInfo::MemoryDumpProviderInfo( 910 MemoryDumpManager::MemoryDumpProviderInfo::MemoryDumpProviderInfo(
929 MemoryDumpProvider* dump_provider, 911 MemoryDumpProvider* dump_provider,
930 const char* name, 912 const char* name,
931 scoped_refptr<SequencedTaskRunner> task_runner, 913 scoped_refptr<SequencedTaskRunner> task_runner,
932 const MemoryDumpProvider::Options& options, 914 const MemoryDumpProvider::Options& options,
933 bool whitelisted_for_background_mode) 915 bool whitelisted_for_background_mode)
934 : dump_provider(dump_provider), 916 : dump_provider(dump_provider),
935 name(name), 917 name(name),
936 task_runner(std::move(task_runner)), 918 task_runner(std::move(task_runner)),
937 options(options), 919 options(options),
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 if (iter == process_dumps.end()) { 961 if (iter == process_dumps.end()) {
980 std::unique_ptr<ProcessMemoryDump> new_pmd( 962 std::unique_ptr<ProcessMemoryDump> new_pmd(
981 new ProcessMemoryDump(session_state, dump_args)); 963 new ProcessMemoryDump(session_state, dump_args));
982 iter = process_dumps.insert(std::make_pair(pid, std::move(new_pmd))).first; 964 iter = process_dumps.insert(std::make_pair(pid, std::move(new_pmd))).first;
983 } 965 }
984 return iter->second.get(); 966 return iter->second.get();
985 } 967 }
986 968
987 } // namespace trace_event 969 } // namespace trace_event
988 } // namespace base 970 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/memory_dump_manager.h ('k') | base/trace_event/memory_dump_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698