OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #include "content/browser/tracing/tracing_controller_impl.h" | 4 #include "content/browser/tracing/tracing_controller_impl.h" |
5 | 5 |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/cpu.h" | 7 #include "base/cpu.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/guid.h" | 9 #include "base/guid.h" |
10 #include "base/json/string_escape.h" | 10 #include "base/json/string_escape.h" |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 | 189 |
190 TracingControllerImpl::TracingControllerImpl() | 190 TracingControllerImpl::TracingControllerImpl() |
191 : pending_start_tracing_ack_count_(0), | 191 : pending_start_tracing_ack_count_(0), |
192 pending_stop_tracing_ack_count_(0), | 192 pending_stop_tracing_ack_count_(0), |
193 pending_trace_log_status_ack_count_(0), | 193 pending_trace_log_status_ack_count_(0), |
194 maximum_trace_buffer_usage_(0), | 194 maximum_trace_buffer_usage_(0), |
195 approximate_event_count_(0), | 195 approximate_event_count_(0), |
196 pending_memory_dump_ack_count_(0), | 196 pending_memory_dump_ack_count_(0), |
197 failed_memory_dump_count_(0), | 197 failed_memory_dump_count_(0), |
198 pending_clock_sync_ack_count_(0), | 198 pending_clock_sync_ack_count_(0), |
199 is_tracing_(false) { | 199 enabled_tracing_modes_(0) { |
200 base::trace_event::MemoryDumpManager::GetInstance()->Initialize( | 200 base::trace_event::MemoryDumpManager::GetInstance()->Initialize( |
201 this /* delegate */, true /* is_coordinator */); | 201 this /* delegate */, true /* is_coordinator */); |
202 | 202 |
203 // Deliberately leaked, like this class. | 203 // Deliberately leaked, like this class. |
204 base::FileTracing::SetProvider(new FileTracingProviderImpl); | 204 base::FileTracing::SetProvider(new FileTracingProviderImpl); |
205 } | 205 } |
206 | 206 |
207 TracingControllerImpl::~TracingControllerImpl() { | 207 TracingControllerImpl::~TracingControllerImpl() { |
208 // This is a Leaky instance. | 208 // This is a Leaky instance. |
209 NOTREACHED(); | 209 NOTREACHED(); |
(...skipping 16 matching lines...) Expand all Loading... |
226 return false; | 226 return false; |
227 } | 227 } |
228 | 228 |
229 bool ok = StopTracing(NULL); | 229 bool ok = StopTracing(NULL); |
230 DCHECK(ok); | 230 DCHECK(ok); |
231 return true; | 231 return true; |
232 } | 232 } |
233 | 233 |
234 void TracingControllerImpl::SetEnabledOnFileThread( | 234 void TracingControllerImpl::SetEnabledOnFileThread( |
235 const TraceConfig& trace_config, | 235 const TraceConfig& trace_config, |
236 int mode, | |
237 const base::Closure& callback) { | 236 const base::Closure& callback) { |
238 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 237 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
239 | 238 |
240 TraceLog::GetInstance()->SetEnabled( | 239 TraceLog::GetInstance()->SetEnabled(trace_config, enabled_tracing_modes_); |
241 trace_config, static_cast<TraceLog::Mode>(mode)); | |
242 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); | 240 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); |
243 } | 241 } |
244 | 242 |
245 void TracingControllerImpl::SetDisabledOnFileThread( | 243 void TracingControllerImpl::SetDisabledOnFileThread( |
246 const base::Closure& callback) { | 244 const base::Closure& callback) { |
247 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 245 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
248 | 246 |
249 TraceLog::GetInstance()->SetDisabled(); | 247 DCHECK(enabled_tracing_modes_); |
| 248 TraceLog::GetInstance()->SetDisabled(enabled_tracing_modes_); |
250 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); | 249 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); |
251 } | 250 } |
252 | 251 |
253 bool TracingControllerImpl::StartTracing( | 252 bool TracingControllerImpl::StartTracing( |
254 const TraceConfig& trace_config, | 253 const TraceConfig& trace_config, |
255 const StartTracingDoneCallback& callback) { | 254 const StartTracingDoneCallback& callback) { |
256 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 255 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
257 DCHECK(additional_tracing_agents_.empty()); | 256 DCHECK(additional_tracing_agents_.empty()); |
258 | 257 |
259 if (!can_start_tracing()) | 258 if (!can_start_tracing()) |
260 return false; | 259 return false; |
261 is_tracing_ = true; | |
262 start_tracing_done_callback_ = callback; | 260 start_tracing_done_callback_ = callback; |
263 start_tracing_trace_config_.reset( | 261 start_tracing_trace_config_.reset( |
264 new base::trace_event::TraceConfig(trace_config)); | 262 new base::trace_event::TraceConfig(trace_config)); |
| 263 enabled_tracing_modes_ = TraceLog::RECORDING_MODE; |
| 264 if (!start_tracing_trace_config_->event_filters().empty()) |
| 265 enabled_tracing_modes_ |= TraceLog::FILTERING_MODE; |
265 metadata_.reset(new base::DictionaryValue()); | 266 metadata_.reset(new base::DictionaryValue()); |
266 pending_start_tracing_ack_count_ = 0; | 267 pending_start_tracing_ack_count_ = 0; |
267 | 268 |
268 #if defined(OS_ANDROID) | 269 #if defined(OS_ANDROID) |
269 if (pending_get_categories_done_callback_.is_null()) | 270 if (pending_get_categories_done_callback_.is_null()) |
270 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); | 271 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); |
271 #endif | 272 #endif |
272 | 273 |
273 if (trace_config.IsSystraceEnabled()) { | 274 if (trace_config.IsSystraceEnabled()) { |
274 #if defined(ENABLE_POWER_TRACING) | 275 #if defined(ENABLE_POWER_TRACING) |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 | 456 |
456 // Notify all child processes. | 457 // Notify all child processes. |
457 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin(); | 458 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin(); |
458 it != trace_message_filters_.end(); ++it) { | 459 it != trace_message_filters_.end(); ++it) { |
459 it->get()->SendGetTraceLogStatus(); | 460 it->get()->SendGetTraceLogStatus(); |
460 } | 461 } |
461 return true; | 462 return true; |
462 } | 463 } |
463 | 464 |
464 bool TracingControllerImpl::IsTracing() const { | 465 bool TracingControllerImpl::IsTracing() const { |
465 return is_tracing_; | 466 return !!enabled_tracing_modes_; |
466 } | 467 } |
467 | 468 |
468 void TracingControllerImpl::AddTraceMessageFilter( | 469 void TracingControllerImpl::AddTraceMessageFilter( |
469 TraceMessageFilter* trace_message_filter) { | 470 TraceMessageFilter* trace_message_filter) { |
470 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 471 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
471 BrowserThread::PostTask( | 472 BrowserThread::PostTask( |
472 BrowserThread::UI, FROM_HERE, | 473 BrowserThread::UI, FROM_HERE, |
473 base::Bind(&TracingControllerImpl::AddTraceMessageFilter, | 474 base::Bind(&TracingControllerImpl::AddTraceMessageFilter, |
474 base::Unretained(this), | 475 base::Unretained(this), |
475 base::RetainedRef(trace_message_filter))); | 476 base::RetainedRef(trace_message_filter))); |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 base::Unretained(this))); | 641 base::Unretained(this))); |
641 } | 642 } |
642 return; | 643 return; |
643 } | 644 } |
644 | 645 |
645 if (pending_stop_tracing_ack_count_ != 0) | 646 if (pending_stop_tracing_ack_count_ != 0) |
646 return; | 647 return; |
647 | 648 |
648 // All acks (including from the subprocesses and the local trace) have been | 649 // All acks (including from the subprocesses and the local trace) have been |
649 // received. | 650 // received. |
650 is_tracing_ = false; | 651 enabled_tracing_modes_ = 0; |
651 | 652 |
652 // Trigger callback if one is set. | 653 // Trigger callback if one is set. |
653 if (!pending_get_categories_done_callback_.is_null()) { | 654 if (!pending_get_categories_done_callback_.is_null()) { |
654 pending_get_categories_done_callback_.Run(known_category_groups_); | 655 pending_get_categories_done_callback_.Run(known_category_groups_); |
655 pending_get_categories_done_callback_.Reset(); | 656 pending_get_categories_done_callback_.Reset(); |
656 } else if (trace_data_sink_.get()) { | 657 } else if (trace_data_sink_.get()) { |
657 trace_data_sink_->Close(); | 658 trace_data_sink_->Close(); |
658 trace_data_sink_ = NULL; | 659 trace_data_sink_ = NULL; |
659 } | 660 } |
660 } | 661 } |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 const base::trace_event::TraceConfig& trace_config, | 770 const base::trace_event::TraceConfig& trace_config, |
770 const StartAgentTracingCallback& callback) { | 771 const StartAgentTracingCallback& callback) { |
771 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 772 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
772 | 773 |
773 base::Closure on_agent_started = | 774 base::Closure on_agent_started = |
774 base::Bind(callback, kChromeTracingAgentName, true); | 775 base::Bind(callback, kChromeTracingAgentName, true); |
775 if (!BrowserThread::PostTask( | 776 if (!BrowserThread::PostTask( |
776 BrowserThread::FILE, FROM_HERE, | 777 BrowserThread::FILE, FROM_HERE, |
777 base::Bind(&TracingControllerImpl::SetEnabledOnFileThread, | 778 base::Bind(&TracingControllerImpl::SetEnabledOnFileThread, |
778 base::Unretained(this), trace_config, | 779 base::Unretained(this), trace_config, |
779 base::trace_event::TraceLog::RECORDING_MODE, | |
780 on_agent_started))) { | 780 on_agent_started))) { |
781 // BrowserThread::PostTask fails if the threads haven't been created yet, | 781 // BrowserThread::PostTask fails if the threads haven't been created yet, |
782 // so it should be safe to just use TraceLog::SetEnabled directly. | 782 // so it should be safe to just use TraceLog::SetEnabled directly. |
783 base::trace_event::TraceLog::GetInstance()->SetEnabled( | 783 TraceLog::GetInstance()->SetEnabled(trace_config, enabled_tracing_modes_); |
784 trace_config, base::trace_event::TraceLog::RECORDING_MODE); | |
785 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, on_agent_started); | 784 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, on_agent_started); |
786 } | 785 } |
787 } | 786 } |
788 | 787 |
789 void TracingControllerImpl::StopAgentTracing( | 788 void TracingControllerImpl::StopAgentTracing( |
790 const StopAgentTracingCallback& callback) { | 789 const StopAgentTracingCallback& callback) { |
791 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 790 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
792 // Handle special case of zero child processes by immediately flushing the | 791 // Handle special case of zero child processes by immediately flushing the |
793 // trace log. Once the flush has completed the caller will be notified that | 792 // trace log. Once the flush has completed the caller will be notified that |
794 // tracing has ended. | 793 // tracing has ended. |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1061 // Schedule the next queued dump (if applicable). | 1060 // Schedule the next queued dump (if applicable). |
1062 if (!queued_memory_dump_requests_.empty()) { | 1061 if (!queued_memory_dump_requests_.empty()) { |
1063 BrowserThread::PostTask( | 1062 BrowserThread::PostTask( |
1064 BrowserThread::UI, FROM_HERE, | 1063 BrowserThread::UI, FROM_HERE, |
1065 base::Bind(&TracingControllerImpl::PerformNextQueuedGlobalMemoryDump, | 1064 base::Bind(&TracingControllerImpl::PerformNextQueuedGlobalMemoryDump, |
1066 base::Unretained(this))); | 1065 base::Unretained(this))); |
1067 } | 1066 } |
1068 } | 1067 } |
1069 | 1068 |
1070 } // namespace content | 1069 } // namespace content |
OLD | NEW |