| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_tracing_observer.h" | 5 #include "base/trace_event/memory_tracing_observer.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/trace_event/memory_dump_manager.h" | 8 #include "base/trace_event/memory_dump_manager.h" |
| 9 #include "base/trace_event/trace_event_argument.h" | 9 #include "base/trace_event/trace_event_argument.h" |
| 10 | 10 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 | 42 |
| 43 MemoryTracingObserver::~MemoryTracingObserver() { | 43 MemoryTracingObserver::~MemoryTracingObserver() { |
| 44 trace_log_->RemoveEnabledStateObserver(this); | 44 trace_log_->RemoveEnabledStateObserver(this); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void MemoryTracingObserver::OnTraceLogEnabled() { | 47 void MemoryTracingObserver::OnTraceLogEnabled() { |
| 48 if (!IsMemoryInfraTracingEnabled()) | 48 if (!IsMemoryInfraTracingEnabled()) |
| 49 return; | 49 return; |
| 50 | 50 |
| 51 // Initialize the TraceLog for the current thread. This is to avoids that the | 51 // Initialize the TraceLog for the current thread. This is to avoids that the |
| 52 // TraceLog memory dump provider is registered lazily during the MDM Enable() | 52 // TraceLog memory dump provider is registered lazily during the MDM |
| 53 // SetupForTracing(). |
| 53 TraceLog::GetInstance()->InitializeThreadLocalEventBufferIfSupported(); | 54 TraceLog::GetInstance()->InitializeThreadLocalEventBufferIfSupported(); |
| 54 | 55 |
| 55 const TraceConfig& trace_config = | 56 const TraceConfig& trace_config = |
| 56 TraceLog::GetInstance()->GetCurrentTraceConfig(); | 57 TraceLog::GetInstance()->GetCurrentTraceConfig(); |
| 57 const TraceConfig::MemoryDumpConfig& memory_dump_config = | 58 const TraceConfig::MemoryDumpConfig& memory_dump_config = |
| 58 trace_config.memory_dump_config(); | 59 trace_config.memory_dump_config(); |
| 59 | 60 |
| 60 memory_dump_config_ = | 61 memory_dump_config_ = |
| 61 MakeUnique<TraceConfig::MemoryDumpConfig>(memory_dump_config); | 62 MakeUnique<TraceConfig::MemoryDumpConfig>(memory_dump_config); |
| 62 | 63 |
| 63 memory_dump_manager_->Enable(memory_dump_config); | 64 memory_dump_manager_->SetupForTracing(memory_dump_config); |
| 64 } | 65 } |
| 65 | 66 |
| 66 void MemoryTracingObserver::OnTraceLogDisabled() { | 67 void MemoryTracingObserver::OnTraceLogDisabled() { |
| 67 memory_dump_manager_->Disable(); | 68 memory_dump_manager_->TeardownForTracing(); |
| 68 memory_dump_config_.reset(); | 69 memory_dump_config_.reset(); |
| 69 } | 70 } |
| 70 | 71 |
| 71 bool MemoryTracingObserver::AddDumpToTraceIfEnabled( | 72 bool MemoryTracingObserver::AddDumpToTraceIfEnabled( |
| 72 const MemoryDumpRequestArgs* req_args, | 73 const MemoryDumpRequestArgs* req_args, |
| 73 const ProcessId pid, | 74 const ProcessId pid, |
| 74 const ProcessMemoryDump* process_memory_dump) { | 75 const ProcessMemoryDump* process_memory_dump) { |
| 75 // If tracing has been disabled early out to avoid the cost of serializing the | 76 // If tracing has been disabled early out to avoid the cost of serializing the |
| 76 // dump then ignoring the result. | 77 // dump then ignoring the result. |
| 77 if (!IsMemoryInfraTracingEnabled()) | 78 if (!IsMemoryInfraTracingEnabled()) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 105 | 106 |
| 106 bool MemoryTracingObserver::IsDumpModeAllowed( | 107 bool MemoryTracingObserver::IsDumpModeAllowed( |
| 107 MemoryDumpLevelOfDetail dump_mode) const { | 108 MemoryDumpLevelOfDetail dump_mode) const { |
| 108 if (!memory_dump_config_) | 109 if (!memory_dump_config_) |
| 109 return false; | 110 return false; |
| 110 return memory_dump_config_->allowed_dump_modes.count(dump_mode) != 0; | 111 return memory_dump_config_->allowed_dump_modes.count(dump_mode) != 0; |
| 111 } | 112 } |
| 112 | 113 |
| 113 } // namespace trace_event | 114 } // namespace trace_event |
| 114 } // namespace base | 115 } // namespace base |
| OLD | NEW |