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 | 8 |
9 #include "base/atomic_sequence_num.h" | 9 #include "base/atomic_sequence_num.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/hash.h" | |
12 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
13 #include "base/trace_event/memory_dump_provider.h" | 12 #include "base/trace_event/memory_dump_provider.h" |
14 #include "base/trace_event/memory_dump_session_state.h" | 13 #include "base/trace_event/memory_dump_session_state.h" |
15 #include "base/trace_event/process_memory_dump.h" | 14 #include "base/trace_event/process_memory_dump.h" |
16 #include "base/trace_event/trace_event_argument.h" | 15 #include "base/trace_event/trace_event_argument.h" |
17 #include "build/build_config.h" | 16 #include "build/build_config.h" |
18 | 17 |
19 #if !defined(OS_NACL) | 18 #if !defined(OS_NACL) |
20 #include "base/trace_event/process_memory_totals_dump_provider.h" | 19 #include "base/trace_event/process_memory_totals_dump_provider.h" |
21 #endif | 20 #endif |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 | 125 |
127 MemoryDumpManager::GetInstance()->RequestGlobalDump(dump_type); | 126 MemoryDumpManager::GetInstance()->RequestGlobalDump(dump_type); |
128 } | 127 } |
129 | 128 |
130 void InitializeThreadLocalEventBufferIfSupported() { | 129 void InitializeThreadLocalEventBufferIfSupported() { |
131 TraceLog::GetInstance()->InitializeThreadLocalEventBufferIfSupported(); | 130 TraceLog::GetInstance()->InitializeThreadLocalEventBufferIfSupported(); |
132 } | 131 } |
133 | 132 |
134 } // namespace | 133 } // namespace |
135 | 134 |
136 // The value -1 is not used as child process id. | |
137 const int MemoryDumpManager::kInvalidTracingProcessId = | |
138 MemoryDumpManager::ChildProcessIdToTracingProcessId(-1); | |
139 | |
140 // static | 135 // static |
141 const char* const MemoryDumpManager::kTraceCategoryForTesting = kTraceCategory; | 136 const char* const MemoryDumpManager::kTraceCategoryForTesting = kTraceCategory; |
142 | 137 |
143 // static | 138 // static |
144 const int MemoryDumpManager::kMaxConsecutiveFailuresCount = 3; | 139 const int MemoryDumpManager::kMaxConsecutiveFailuresCount = 3; |
145 | 140 |
146 // static | 141 // static |
147 MemoryDumpManager* MemoryDumpManager::GetInstance() { | 142 MemoryDumpManager* MemoryDumpManager::GetInstance() { |
148 if (g_instance_for_testing) | 143 if (g_instance_for_testing) |
149 return g_instance_for_testing; | 144 return g_instance_for_testing; |
150 | 145 |
151 return Singleton<MemoryDumpManager, | 146 return Singleton<MemoryDumpManager, |
152 LeakySingletonTraits<MemoryDumpManager>>::get(); | 147 LeakySingletonTraits<MemoryDumpManager>>::get(); |
153 } | 148 } |
154 | 149 |
155 // static | 150 // static |
156 void MemoryDumpManager::SetInstanceForTesting(MemoryDumpManager* instance) { | 151 void MemoryDumpManager::SetInstanceForTesting(MemoryDumpManager* instance) { |
157 if (instance) | 152 if (instance) |
158 instance->skip_core_dumpers_auto_registration_for_testing_ = true; | 153 instance->skip_core_dumpers_auto_registration_for_testing_ = true; |
159 g_instance_for_testing = instance; | 154 g_instance_for_testing = instance; |
160 } | 155 } |
161 | 156 |
162 MemoryDumpManager::MemoryDumpManager() | 157 MemoryDumpManager::MemoryDumpManager() |
163 : delegate_(nullptr), | 158 : delegate_(nullptr), |
164 memory_tracing_enabled_(0), | 159 memory_tracing_enabled_(0), |
165 tracing_process_id_(kInvalidTracingProcessId), | |
166 skip_core_dumpers_auto_registration_for_testing_(false) { | 160 skip_core_dumpers_auto_registration_for_testing_(false) { |
167 g_next_guid.GetNext(); // Make sure that first guid is not zero. | 161 g_next_guid.GetNext(); // Make sure that first guid is not zero. |
168 } | 162 } |
169 | 163 |
170 MemoryDumpManager::~MemoryDumpManager() { | 164 MemoryDumpManager::~MemoryDumpManager() { |
171 base::trace_event::TraceLog::GetInstance()->RemoveEnabledStateObserver(this); | 165 base::trace_event::TraceLog::GetInstance()->RemoveEnabledStateObserver(this); |
172 } | 166 } |
173 | 167 |
174 void MemoryDumpManager::Initialize() { | 168 void MemoryDumpManager::Initialize() { |
175 TRACE_EVENT0(kTraceCategory, "init"); // Add to trace-viewer category list. | 169 TRACE_EVENT0(kTraceCategory, "init"); // Add to trace-viewer category list. |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 } | 425 } |
432 } | 426 } |
433 | 427 |
434 void MemoryDumpManager::OnTraceLogDisabled() { | 428 void MemoryDumpManager::OnTraceLogDisabled() { |
435 AutoLock lock(lock_); | 429 AutoLock lock(lock_); |
436 periodic_dump_timer_.Stop(); | 430 periodic_dump_timer_.Stop(); |
437 subtle::NoBarrier_Store(&memory_tracing_enabled_, 0); | 431 subtle::NoBarrier_Store(&memory_tracing_enabled_, 0); |
438 session_state_ = nullptr; | 432 session_state_ = nullptr; |
439 } | 433 } |
440 | 434 |
441 // static | |
442 int MemoryDumpManager::ChildProcessIdToTracingProcessId(int child_process_id) { | |
443 return Hash(reinterpret_cast<const char*>(&child_process_id), | |
444 sizeof(child_process_id)); | |
445 } | |
446 | |
447 MemoryDumpManager::MemoryDumpProviderInfo::MemoryDumpProviderInfo( | 435 MemoryDumpManager::MemoryDumpProviderInfo::MemoryDumpProviderInfo( |
448 const scoped_refptr<SingleThreadTaskRunner>& task_runner) | 436 const scoped_refptr<SingleThreadTaskRunner>& task_runner) |
449 : task_runner(task_runner), consecutive_failures(0), disabled(false) { | 437 : task_runner(task_runner), consecutive_failures(0), disabled(false) { |
450 } | 438 } |
451 MemoryDumpManager::MemoryDumpProviderInfo::~MemoryDumpProviderInfo() { | 439 MemoryDumpManager::MemoryDumpProviderInfo::~MemoryDumpProviderInfo() { |
452 } | 440 } |
453 | 441 |
454 } // namespace trace_event | 442 } // namespace trace_event |
455 } // namespace base | 443 } // namespace base |
OLD | NEW |