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 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 base::Unretained(this), nullptr, status)); | 453 base::Unretained(this), nullptr, status)); |
454 | 454 |
455 // Notify all child processes. | 455 // Notify all child processes. |
456 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin(); | 456 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin(); |
457 it != trace_message_filters_.end(); ++it) { | 457 it != trace_message_filters_.end(); ++it) { |
458 it->get()->SendGetTraceLogStatus(); | 458 it->get()->SendGetTraceLogStatus(); |
459 } | 459 } |
460 return true; | 460 return true; |
461 } | 461 } |
462 | 462 |
463 bool TracingControllerImpl::SetWatchEvent( | |
464 const std::string& category_name, | |
465 const std::string& event_name, | |
466 const WatchEventCallback& callback) { | |
467 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
468 | |
469 if (callback.is_null()) | |
470 return false; | |
471 | |
472 watch_category_name_ = category_name; | |
473 watch_event_name_ = event_name; | |
474 watch_event_callback_ = callback; | |
475 | |
476 TraceLog::GetInstance()->SetWatchEvent( | |
477 category_name, event_name, | |
478 base::Bind(&TracingControllerImpl::OnWatchEventMatched, | |
479 base::Unretained(this))); | |
480 | |
481 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin(); | |
482 it != trace_message_filters_.end(); ++it) { | |
483 it->get()->SendSetWatchEvent(category_name, event_name); | |
484 } | |
485 return true; | |
486 } | |
487 | |
488 bool TracingControllerImpl::CancelWatchEvent() { | |
489 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
490 | |
491 if (!can_cancel_watch_event()) | |
492 return false; | |
493 | |
494 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin(); | |
495 it != trace_message_filters_.end(); ++it) { | |
496 it->get()->SendCancelWatchEvent(); | |
497 } | |
498 | |
499 watch_event_callback_.Reset(); | |
500 return true; | |
501 } | |
502 | |
503 bool TracingControllerImpl::IsTracing() const { | 463 bool TracingControllerImpl::IsTracing() const { |
504 return is_tracing_; | 464 return is_tracing_; |
505 } | 465 } |
506 | 466 |
507 void TracingControllerImpl::AddTraceMessageFilter( | 467 void TracingControllerImpl::AddTraceMessageFilter( |
508 TraceMessageFilter* trace_message_filter) { | 468 TraceMessageFilter* trace_message_filter) { |
509 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 469 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
510 BrowserThread::PostTask( | 470 BrowserThread::PostTask( |
511 BrowserThread::UI, FROM_HERE, | 471 BrowserThread::UI, FROM_HERE, |
512 base::Bind(&TracingControllerImpl::AddTraceMessageFilter, | 472 base::Bind(&TracingControllerImpl::AddTraceMessageFilter, |
513 base::Unretained(this), | 473 base::Unretained(this), |
514 base::RetainedRef(trace_message_filter))); | 474 base::RetainedRef(trace_message_filter))); |
515 return; | 475 return; |
516 } | 476 } |
517 | 477 |
518 #if defined(OS_LINUX) | 478 #if defined(OS_LINUX) |
519 // On Linux the browser process dumps process metrics for child process due to | 479 // On Linux the browser process dumps process metrics for child process due to |
520 // sandbox. | 480 // sandbox. |
521 tracing::ProcessMetricsMemoryDumpProvider::RegisterForProcess( | 481 tracing::ProcessMetricsMemoryDumpProvider::RegisterForProcess( |
522 trace_message_filter->peer_pid()); | 482 trace_message_filter->peer_pid()); |
523 #endif | 483 #endif |
524 | 484 |
525 trace_message_filters_.insert(trace_message_filter); | 485 trace_message_filters_.insert(trace_message_filter); |
526 if (can_cancel_watch_event()) { | |
527 trace_message_filter->SendSetWatchEvent(watch_category_name_, | |
528 watch_event_name_); | |
529 } | |
530 if (can_stop_tracing()) { | 486 if (can_stop_tracing()) { |
531 trace_message_filter->SendBeginTracing( | 487 trace_message_filter->SendBeginTracing( |
532 TraceLog::GetInstance()->GetCurrentTraceConfig()); | 488 TraceLog::GetInstance()->GetCurrentTraceConfig()); |
533 } | 489 } |
534 | 490 |
535 for (auto& observer : trace_message_filter_observers_) | 491 for (auto& observer : trace_message_filter_observers_) |
536 observer.OnTraceMessageFilterAdded(trace_message_filter); | 492 observer.OnTraceMessageFilterAdded(trace_message_filter); |
537 } | 493 } |
538 | 494 |
539 void TracingControllerImpl::RemoveTraceMessageFilter( | 495 void TracingControllerImpl::RemoveTraceMessageFilter( |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 approximate_event_count_ += status.event_count; | 738 approximate_event_count_ += status.event_count; |
783 | 739 |
784 if (--pending_trace_log_status_ack_count_ == 0) { | 740 if (--pending_trace_log_status_ack_count_ == 0) { |
785 // Trigger callback if one is set. | 741 // Trigger callback if one is set. |
786 pending_trace_buffer_usage_callback_.Run(maximum_trace_buffer_usage_, | 742 pending_trace_buffer_usage_callback_.Run(maximum_trace_buffer_usage_, |
787 approximate_event_count_); | 743 approximate_event_count_); |
788 pending_trace_buffer_usage_callback_.Reset(); | 744 pending_trace_buffer_usage_callback_.Reset(); |
789 } | 745 } |
790 } | 746 } |
791 | 747 |
792 void TracingControllerImpl::OnWatchEventMatched() { | |
793 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | |
794 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
795 base::Bind(&TracingControllerImpl::OnWatchEventMatched, | |
796 base::Unretained(this))); | |
797 return; | |
798 } | |
799 | |
800 if (!watch_event_callback_.is_null()) | |
801 watch_event_callback_.Run(); | |
802 } | |
803 | |
804 void TracingControllerImpl::RegisterTracingUI(TracingUI* tracing_ui) { | 748 void TracingControllerImpl::RegisterTracingUI(TracingUI* tracing_ui) { |
805 DCHECK(tracing_uis_.find(tracing_ui) == tracing_uis_.end()); | 749 DCHECK(tracing_uis_.find(tracing_ui) == tracing_uis_.end()); |
806 tracing_uis_.insert(tracing_ui); | 750 tracing_uis_.insert(tracing_ui); |
807 } | 751 } |
808 | 752 |
809 void TracingControllerImpl::UnregisterTracingUI(TracingUI* tracing_ui) { | 753 void TracingControllerImpl::UnregisterTracingUI(TracingUI* tracing_ui) { |
810 std::set<TracingUI*>::iterator it = tracing_uis_.find(tracing_ui); | 754 std::set<TracingUI*>::iterator it = tracing_uis_.find(tracing_ui); |
811 DCHECK(it != tracing_uis_.end()); | 755 DCHECK(it != tracing_uis_.end()); |
812 tracing_uis_.erase(it); | 756 tracing_uis_.erase(it); |
813 } | 757 } |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1116 // Schedule the next queued dump (if applicable). | 1060 // Schedule the next queued dump (if applicable). |
1117 if (!queued_memory_dump_requests_.empty()) { | 1061 if (!queued_memory_dump_requests_.empty()) { |
1118 BrowserThread::PostTask( | 1062 BrowserThread::PostTask( |
1119 BrowserThread::UI, FROM_HERE, | 1063 BrowserThread::UI, FROM_HERE, |
1120 base::Bind(&TracingControllerImpl::PerformNextQueuedGlobalMemoryDump, | 1064 base::Bind(&TracingControllerImpl::PerformNextQueuedGlobalMemoryDump, |
1121 base::Unretained(this))); | 1065 base::Unretained(this))); |
1122 } | 1066 } |
1123 } | 1067 } |
1124 | 1068 |
1125 } // namespace content | 1069 } // namespace content |
OLD | NEW |