Chromium Code Reviews| 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 <inttypes.h> | 7 #include <inttypes.h> |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" | 28 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" |
| 29 #include "base/trace_event/heap_profiler_event_filter.h" | 29 #include "base/trace_event/heap_profiler_event_filter.h" |
| 30 #include "base/trace_event/heap_profiler_stack_frame_deduplicator.h" | 30 #include "base/trace_event/heap_profiler_stack_frame_deduplicator.h" |
| 31 #include "base/trace_event/heap_profiler_type_name_deduplicator.h" | 31 #include "base/trace_event/heap_profiler_type_name_deduplicator.h" |
| 32 #include "base/trace_event/malloc_dump_provider.h" | 32 #include "base/trace_event/malloc_dump_provider.h" |
| 33 #include "base/trace_event/memory_dump_provider.h" | 33 #include "base/trace_event/memory_dump_provider.h" |
| 34 #include "base/trace_event/memory_dump_scheduler.h" | 34 #include "base/trace_event/memory_dump_scheduler.h" |
| 35 #include "base/trace_event/memory_dump_session_state.h" | 35 #include "base/trace_event/memory_dump_session_state.h" |
| 36 #include "base/trace_event/memory_infra_background_whitelist.h" | 36 #include "base/trace_event/memory_infra_background_whitelist.h" |
| 37 #include "base/trace_event/memory_peak_detector.h" | 37 #include "base/trace_event/memory_peak_detector.h" |
| 38 #include "base/trace_event/memory_tracing_frontend.h" | |
|
ssid
2017/04/14 23:33:09
Feels like this dependency shouldn't exist?
hjd
2017/04/19 09:54:56
Acknowledged. See message.
| |
| 38 #include "base/trace_event/process_memory_dump.h" | 39 #include "base/trace_event/process_memory_dump.h" |
| 39 #include "base/trace_event/trace_event.h" | 40 #include "base/trace_event/trace_event.h" |
| 40 #include "base/trace_event/trace_event_argument.h" | 41 #include "base/trace_event/trace_event_argument.h" |
| 41 #include "build/build_config.h" | 42 #include "build/build_config.h" |
| 42 | 43 |
| 43 #if defined(OS_ANDROID) | 44 #if defined(OS_ANDROID) |
| 44 #include "base/trace_event/java_heap_dump_provider_android.h" | 45 #include "base/trace_event/java_heap_dump_provider_android.h" |
| 45 #endif | 46 #endif |
| 46 | 47 |
| 47 namespace base { | 48 namespace base { |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 | 192 |
| 192 // At this point the command line may not be initialized but we try to | 193 // At this point the command line may not be initialized but we try to |
| 193 // enable the heap profiler to capture allocations as soon as possible. | 194 // enable the heap profiler to capture allocations as soon as possible. |
| 194 EnableHeapProfilingIfNeeded(); | 195 EnableHeapProfilingIfNeeded(); |
| 195 | 196 |
| 196 strict_thread_check_blacklist_.insert(std::begin(kStrictThreadCheckBlacklist), | 197 strict_thread_check_blacklist_.insert(std::begin(kStrictThreadCheckBlacklist), |
| 197 std::end(kStrictThreadCheckBlacklist)); | 198 std::end(kStrictThreadCheckBlacklist)); |
| 198 } | 199 } |
| 199 | 200 |
| 200 MemoryDumpManager::~MemoryDumpManager() { | 201 MemoryDumpManager::~MemoryDumpManager() { |
| 201 TraceLog::GetInstance()->RemoveEnabledStateObserver(this); | |
| 202 } | 202 } |
| 203 | 203 |
| 204 void MemoryDumpManager::EnableHeapProfilingIfNeeded() { | 204 void MemoryDumpManager::EnableHeapProfilingIfNeeded() { |
| 205 if (heap_profiling_enabled_) | 205 if (heap_profiling_enabled_) |
| 206 return; | 206 return; |
| 207 | 207 |
| 208 if (!CommandLine::InitializedForCurrentProcess() || | 208 if (!CommandLine::InitializedForCurrentProcess() || |
| 209 !CommandLine::ForCurrentProcess()->HasSwitch( | 209 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 210 switches::kEnableHeapProfiling)) | 210 switches::kEnableHeapProfiling)) |
| 211 return; | 211 return; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 heap_profiler_filter_config.SetCategoryFilter(category_filter); | 281 heap_profiler_filter_config.SetCategoryFilter(category_filter); |
| 282 | 282 |
| 283 TraceConfig::EventFilters filters; | 283 TraceConfig::EventFilters filters; |
| 284 filters.push_back(heap_profiler_filter_config); | 284 filters.push_back(heap_profiler_filter_config); |
| 285 TraceConfig filtering_trace_config; | 285 TraceConfig filtering_trace_config; |
| 286 filtering_trace_config.SetEventFilters(filters); | 286 filtering_trace_config.SetEventFilters(filters); |
| 287 | 287 |
| 288 TraceLog::GetInstance()->SetEnabled(filtering_trace_config, | 288 TraceLog::GetInstance()->SetEnabled(filtering_trace_config, |
| 289 TraceLog::FILTERING_MODE); | 289 TraceLog::FILTERING_MODE); |
| 290 } | 290 } |
| 291 | |
| 292 // If tracing was enabled before initializing MemoryDumpManager, we missed the | |
| 293 // OnTraceLogEnabled() event. Synthetize it so we can late-join the party. | |
| 294 // IsEnabled is called before adding observer to avoid calling | |
| 295 // OnTraceLogEnabled twice. | |
| 296 bool is_tracing_already_enabled = TraceLog::GetInstance()->IsEnabled(); | |
| 297 TraceLog::GetInstance()->AddEnabledStateObserver(this); | |
| 298 if (is_tracing_already_enabled) | |
| 299 OnTraceLogEnabled(); | |
| 300 } | 291 } |
| 301 | 292 |
| 302 void MemoryDumpManager::RegisterDumpProvider( | 293 void MemoryDumpManager::RegisterDumpProvider( |
| 303 MemoryDumpProvider* mdp, | 294 MemoryDumpProvider* mdp, |
| 304 const char* name, | 295 const char* name, |
| 305 scoped_refptr<SingleThreadTaskRunner> task_runner, | 296 scoped_refptr<SingleThreadTaskRunner> task_runner, |
| 306 MemoryDumpProvider::Options options) { | 297 MemoryDumpProvider::Options options) { |
| 307 options.dumps_on_single_thread_task_runner = true; | 298 options.dumps_on_single_thread_task_runner = true; |
| 308 RegisterDumpProviderInternal(mdp, name, std::move(task_runner), options); | 299 RegisterDumpProviderInternal(mdp, name, std::move(task_runner), options); |
| 309 } | 300 } |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 785 GetDumpsSumKb("partition_alloc/partitions/*", process_memory_dump); | 776 GetDumpsSumKb("partition_alloc/partitions/*", process_memory_dump); |
| 786 result.chrome_dump.blink_gc_total_kb = | 777 result.chrome_dump.blink_gc_total_kb = |
| 787 GetDumpsSumKb("blink_gc", process_memory_dump); | 778 GetDumpsSumKb("blink_gc", process_memory_dump); |
| 788 FillOsDumpFromProcessMemoryDump(process_memory_dump, &result.os_dump); | 779 FillOsDumpFromProcessMemoryDump(process_memory_dump, &result.os_dump); |
| 789 } else { | 780 } else { |
| 790 auto& os_dump = result.extra_processes_dump[pid]; | 781 auto& os_dump = result.extra_processes_dump[pid]; |
| 791 FillOsDumpFromProcessMemoryDump(process_memory_dump, &os_dump); | 782 FillOsDumpFromProcessMemoryDump(process_memory_dump, &os_dump); |
| 792 } | 783 } |
| 793 } | 784 } |
| 794 | 785 |
| 795 bool tracing_still_enabled; | |
| 796 TRACE_EVENT_CATEGORY_GROUP_ENABLED(kTraceCategory, &tracing_still_enabled); | |
| 797 if (!tracing_still_enabled) { | |
| 798 pmd_async_state->dump_successful = false; | |
| 799 VLOG(1) << kLogPrefix << " failed because tracing was disabled before" | |
| 800 << " the dump was completed"; | |
| 801 } | |
|
hjd
2017/04/13 14:16:59
Can we just remove this now?
ssid
2017/04/14 23:33:09
I think this can be removed along with TRACE_EVENT
hjd
2017/04/19 09:54:56
Okay, I've moved TRACE_EVENT_API_ADD_TRACE_EVENT_W
| |
| 802 | |
| 803 if (!pmd_async_state->callback.is_null()) { | 786 if (!pmd_async_state->callback.is_null()) { |
| 804 pmd_async_state->callback.Run(dump_guid, pmd_async_state->dump_successful); | 787 pmd_async_state->callback.Run(dump_guid, pmd_async_state->dump_successful); |
| 805 pmd_async_state->callback.Reset(); | 788 pmd_async_state->callback.Reset(); |
| 806 } | 789 } |
| 807 | 790 |
| 808 TRACE_EVENT_NESTABLE_ASYNC_END0(kTraceCategory, "ProcessMemoryDump", | 791 TRACE_EVENT_NESTABLE_ASYNC_END0(kTraceCategory, "ProcessMemoryDump", |
| 809 TRACE_ID_LOCAL(dump_guid)); | 792 TRACE_ID_LOCAL(dump_guid)); |
| 810 } | 793 } |
| 811 | 794 |
| 812 void MemoryDumpManager::OnTraceLogEnabled() { | 795 void MemoryDumpManager::Enable() { |
| 813 bool enabled; | |
| 814 TRACE_EVENT_CATEGORY_GROUP_ENABLED(kTraceCategory, &enabled); | |
| 815 if (!enabled) | |
| 816 return; | |
| 817 | |
| 818 // Initialize the TraceLog for the current thread. This is to avoid that the | 796 // Initialize the TraceLog for the current thread. This is to avoid that the |
| 819 // TraceLog memory dump provider is registered lazily in the PostTask() below | 797 // TraceLog memory dump provider is registered lazily in the PostTask() below |
| 820 // while the |lock_| is taken; | 798 // while the |lock_| is taken; |
| 821 TraceLog::GetInstance()->InitializeThreadLocalEventBufferIfSupported(); | 799 TraceLog::GetInstance()->InitializeThreadLocalEventBufferIfSupported(); |
| 822 | 800 |
| 823 // Spin-up the thread used to invoke unbound dump providers. | 801 // Spin-up the thread used to invoke unbound dump providers. |
| 824 std::unique_ptr<Thread> dump_thread(new Thread("MemoryInfra")); | 802 std::unique_ptr<Thread> dump_thread(new Thread("MemoryInfra")); |
| 825 if (!dump_thread->Start()) { | 803 if (!dump_thread->Start()) { |
| 826 LOG(ERROR) << "Failed to start the memory-infra thread for tracing"; | 804 LOG(ERROR) << "Failed to start the memory-infra thread for tracing"; |
| 827 return; | 805 return; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 908 } | 886 } |
| 909 } | 887 } |
| 910 | 888 |
| 911 // Only coordinator process triggers periodic global memory dumps. | 889 // Only coordinator process triggers periodic global memory dumps. |
| 912 if (delegate_->IsCoordinator() && !periodic_config.triggers.empty()) { | 890 if (delegate_->IsCoordinator() && !periodic_config.triggers.empty()) { |
| 913 MemoryDumpScheduler::GetInstance()->Start(periodic_config, | 891 MemoryDumpScheduler::GetInstance()->Start(periodic_config, |
| 914 dump_thread_->task_runner()); | 892 dump_thread_->task_runner()); |
| 915 } | 893 } |
| 916 } | 894 } |
| 917 | 895 |
| 918 void MemoryDumpManager::OnTraceLogDisabled() { | 896 void MemoryDumpManager::Disable() { |
| 919 // There might be a memory dump in progress while this happens. Therefore, | 897 // There might be a memory dump in progress while this happens. Therefore, |
| 920 // ensure that the MDM state which depends on the tracing enabled / disabled | 898 // ensure that the MDM state which depends on the tracing enabled / disabled |
| 921 // state is always accessed by the dumping methods holding the |lock_|. | 899 // state is always accessed by the dumping methods holding the |lock_|. |
| 922 if (!subtle::NoBarrier_Load(&memory_tracing_enabled_)) | 900 if (!subtle::NoBarrier_Load(&memory_tracing_enabled_)) |
| 923 return; | 901 return; |
| 924 subtle::NoBarrier_Store(&memory_tracing_enabled_, 0); | 902 subtle::NoBarrier_Store(&memory_tracing_enabled_, 0); |
| 925 std::unique_ptr<Thread> dump_thread; | 903 std::unique_ptr<Thread> dump_thread; |
| 926 { | 904 { |
| 927 AutoLock lock(lock_); | 905 AutoLock lock(lock_); |
| 928 MemoryDumpScheduler::GetInstance()->Stop(); | 906 MemoryDumpScheduler::GetInstance()->Stop(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 970 if (iter == process_dumps.end()) { | 948 if (iter == process_dumps.end()) { |
| 971 std::unique_ptr<ProcessMemoryDump> new_pmd( | 949 std::unique_ptr<ProcessMemoryDump> new_pmd( |
| 972 new ProcessMemoryDump(session_state, dump_args)); | 950 new ProcessMemoryDump(session_state, dump_args)); |
| 973 iter = process_dumps.insert(std::make_pair(pid, std::move(new_pmd))).first; | 951 iter = process_dumps.insert(std::make_pair(pid, std::move(new_pmd))).first; |
| 974 } | 952 } |
| 975 return iter->second.get(); | 953 return iter->second.get(); |
| 976 } | 954 } |
| 977 | 955 |
| 978 } // namespace trace_event | 956 } // namespace trace_event |
| 979 } // namespace base | 957 } // namespace base |
| OLD | NEW |