| 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/atomic_sequence_num.h" | 11 #include "base/atomic_sequence_num.h" |
| 11 #include "base/base_switches.h" | 12 #include "base/base_switches.h" |
| 12 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 13 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 14 #include "base/debug/debugging_flags.h" | 15 #include "base/debug/debugging_flags.h" |
| 15 #include "base/debug/stack_trace.h" | 16 #include "base/debug/stack_trace.h" |
| 16 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
| 17 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
| 18 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
| 19 #include "base/trace_event/heap_profiler.h" | 20 #include "base/trace_event/heap_profiler.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 const int MemoryDumpManager::kMaxConsecutiveFailuresCount = 3; | 105 const int MemoryDumpManager::kMaxConsecutiveFailuresCount = 3; |
| 105 | 106 |
| 106 // static | 107 // static |
| 107 const uint64_t MemoryDumpManager::kInvalidTracingProcessId = 0; | 108 const uint64_t MemoryDumpManager::kInvalidTracingProcessId = 0; |
| 108 | 109 |
| 109 // static | 110 // static |
| 110 const char* const MemoryDumpManager::kSystemAllocatorPoolName = | 111 const char* const MemoryDumpManager::kSystemAllocatorPoolName = |
| 111 #if defined(MALLOC_MEMORY_TRACING_SUPPORTED) | 112 #if defined(MALLOC_MEMORY_TRACING_SUPPORTED) |
| 112 MallocDumpProvider::kAllocatedObjects; | 113 MallocDumpProvider::kAllocatedObjects; |
| 113 #elif defined(OS_WIN) | 114 #elif defined(OS_WIN) |
| 115 // If the allocator shim is enabled, the malloc provider will do. |
| 116 #if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) |
| 117 MallocDumpProvider::kAllocatedObjects; |
| 118 #else |
| 114 WinHeapDumpProvider::kAllocatedObjects; | 119 WinHeapDumpProvider::kAllocatedObjects; |
| 120 #endif |
| 115 #else | 121 #else |
| 116 nullptr; | 122 nullptr; |
| 117 #endif | 123 #endif |
| 118 | 124 |
| 119 // static | 125 // static |
| 120 MemoryDumpManager* MemoryDumpManager::GetInstance() { | 126 MemoryDumpManager* MemoryDumpManager::GetInstance() { |
| 121 if (g_instance_for_testing) | 127 if (g_instance_for_testing) |
| 122 return g_instance_for_testing; | 128 return g_instance_for_testing; |
| 123 | 129 |
| 124 return Singleton<MemoryDumpManager, | 130 return Singleton<MemoryDumpManager, |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 #if defined(MALLOC_MEMORY_TRACING_SUPPORTED) | 206 #if defined(MALLOC_MEMORY_TRACING_SUPPORTED) |
| 201 RegisterDumpProvider(MallocDumpProvider::GetInstance(), "Malloc", nullptr); | 207 RegisterDumpProvider(MallocDumpProvider::GetInstance(), "Malloc", nullptr); |
| 202 #endif | 208 #endif |
| 203 | 209 |
| 204 #if defined(OS_ANDROID) | 210 #if defined(OS_ANDROID) |
| 205 RegisterDumpProvider(JavaHeapDumpProvider::GetInstance(), "JavaHeap", | 211 RegisterDumpProvider(JavaHeapDumpProvider::GetInstance(), "JavaHeap", |
| 206 nullptr); | 212 nullptr); |
| 207 #endif | 213 #endif |
| 208 | 214 |
| 209 #if defined(OS_WIN) | 215 #if defined(OS_WIN) |
| 216 // If the allocator shim is enabled, the malloc provider will do. |
| 217 #if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) |
| 218 RegisterDumpProvider(MallocDumpProvider::GetInstance(), "Malloc", nullptr); |
| 219 #else |
| 210 RegisterDumpProvider(WinHeapDumpProvider::GetInstance(), "WinHeap", nullptr); | 220 RegisterDumpProvider(WinHeapDumpProvider::GetInstance(), "WinHeap", nullptr); |
| 211 #endif | 221 #endif |
| 222 #endif |
| 212 | 223 |
| 213 // If tracing was enabled before initializing MemoryDumpManager, we missed the | 224 // If tracing was enabled before initializing MemoryDumpManager, we missed the |
| 214 // OnTraceLogEnabled() event. Synthetize it so we can late-join the party. | 225 // OnTraceLogEnabled() event. Synthetize it so we can late-join the party. |
| 215 bool is_tracing_already_enabled = TraceLog::GetInstance()->IsEnabled(); | 226 bool is_tracing_already_enabled = TraceLog::GetInstance()->IsEnabled(); |
| 216 TRACE_EVENT0(kTraceCategory, "init"); // Add to trace-viewer category list. | 227 TRACE_EVENT0(kTraceCategory, "init"); // Add to trace-viewer category list. |
| 217 TraceLog::GetInstance()->AddEnabledStateObserver(this); | 228 TraceLog::GetInstance()->AddEnabledStateObserver(this); |
| 218 if (is_tracing_already_enabled) | 229 if (is_tracing_already_enabled) |
| 219 OnTraceLogEnabled(); | 230 OnTraceLogEnabled(); |
| 220 } | 231 } |
| 221 | 232 |
| (...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 874 if (heavy_dump_rate_ > 0 && periodic_dumps_count_ % heavy_dump_rate_ == 0) | 885 if (heavy_dump_rate_ > 0 && periodic_dumps_count_ % heavy_dump_rate_ == 0) |
| 875 level_of_detail = MemoryDumpLevelOfDetail::DETAILED; | 886 level_of_detail = MemoryDumpLevelOfDetail::DETAILED; |
| 876 ++periodic_dumps_count_; | 887 ++periodic_dumps_count_; |
| 877 | 888 |
| 878 MemoryDumpManager::GetInstance()->RequestGlobalDump( | 889 MemoryDumpManager::GetInstance()->RequestGlobalDump( |
| 879 MemoryDumpType::PERIODIC_INTERVAL, level_of_detail); | 890 MemoryDumpType::PERIODIC_INTERVAL, level_of_detail); |
| 880 } | 891 } |
| 881 | 892 |
| 882 } // namespace trace_event | 893 } // namespace trace_event |
| 883 } // namespace base | 894 } // namespace base |
| OLD | NEW |