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/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/json/string_escape.h" | 9 #include "base/json/string_escape.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 155 |
156 DISALLOW_COPY_AND_ASSIGN(StringTraceDataSink); | 156 DISALLOW_COPY_AND_ASSIGN(StringTraceDataSink); |
157 }; | 157 }; |
158 | 158 |
159 } // namespace | 159 } // namespace |
160 | 160 |
161 TracingController* TracingController::GetInstance() { | 161 TracingController* TracingController::GetInstance() { |
162 return TracingControllerImpl::GetInstance(); | 162 return TracingControllerImpl::GetInstance(); |
163 } | 163 } |
164 | 164 |
165 TracingControllerImpl::TracingControllerImpl() : | 165 TracingControllerImpl::TracingControllerImpl() |
166 pending_disable_recording_ack_count_(0), | 166 : pending_disable_recording_ack_count_(0), |
167 pending_capture_monitoring_snapshot_ack_count_(0), | 167 pending_capture_monitoring_snapshot_ack_count_(0), |
168 pending_trace_buffer_percent_full_ack_count_(0), | 168 pending_trace_log_status_ack_count_(0), |
169 maximum_trace_buffer_percent_full_(0), | 169 maximum_trace_buffer_usage_(0), |
| 170 approximate_event_count_(0), |
170 // Tracing may have been enabled by ContentMainRunner if kTraceStartup | 171 // Tracing may have been enabled by ContentMainRunner if kTraceStartup |
171 // is specified in command line. | 172 // is specified in command line. |
172 #if defined(OS_CHROMEOS) || defined(OS_WIN) | 173 #if defined(OS_CHROMEOS) || defined(OS_WIN) |
173 is_system_tracing_(false), | 174 is_system_tracing_(false), |
174 #endif | 175 #endif |
175 is_recording_(TraceLog::GetInstance()->IsEnabled()), | 176 is_recording_(TraceLog::GetInstance()->IsEnabled()), |
176 is_monitoring_(false) { | 177 is_monitoring_(false) { |
177 } | 178 } |
178 | 179 |
179 TracingControllerImpl::~TracingControllerImpl() { | 180 TracingControllerImpl::~TracingControllerImpl() { |
180 // This is a Leaky instance. | 181 // This is a Leaky instance. |
181 NOTREACHED(); | 182 NOTREACHED(); |
182 } | 183 } |
183 | 184 |
184 TracingControllerImpl* TracingControllerImpl::GetInstance() { | 185 TracingControllerImpl* TracingControllerImpl::GetInstance() { |
185 return g_controller.Pointer(); | 186 return g_controller.Pointer(); |
186 } | 187 } |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 it->get()->SendCaptureMonitoringSnapshot(); | 493 it->get()->SendCaptureMonitoringSnapshot(); |
493 } | 494 } |
494 | 495 |
495 #if defined(OS_ANDROID) | 496 #if defined(OS_ANDROID) |
496 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); | 497 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); |
497 #endif | 498 #endif |
498 | 499 |
499 return true; | 500 return true; |
500 } | 501 } |
501 | 502 |
502 bool TracingControllerImpl::GetTraceBufferPercentFull( | 503 bool TracingControllerImpl::GetTraceBufferUsage( |
503 const GetTraceBufferPercentFullCallback& callback) { | 504 const GetTraceBufferUsageCallback& callback) { |
504 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 505 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
505 | 506 |
506 if (!can_get_trace_buffer_percent_full() || callback.is_null()) | 507 if (!can_get_trace_buffer_usage() || callback.is_null()) |
507 return false; | 508 return false; |
508 | 509 |
509 pending_trace_buffer_percent_full_callback_ = callback; | 510 pending_trace_buffer_usage_callback_ = callback; |
510 | 511 |
511 // Count myself in pending_trace_buffer_percent_full_ack_count_, acked below. | 512 // Count myself in pending_trace_log_status_ack_count_, acked below. |
512 pending_trace_buffer_percent_full_ack_count_ = | 513 pending_trace_log_status_ack_count_ = trace_message_filters_.size() + 1; |
513 trace_message_filters_.size() + 1; | 514 pending_trace_log_status_filters_ = trace_message_filters_; |
514 pending_trace_buffer_percent_full_filters_ = trace_message_filters_; | 515 maximum_trace_buffer_usage_ = 0; |
515 maximum_trace_buffer_percent_full_ = 0; | 516 approximate_event_count_ = 0; |
516 | 517 |
517 // Call OnTraceBufferPercentFullReply unconditionally for the browser process. | 518 base::debug::TraceLogStatus status = TraceLog::GetInstance()->GetStatus(); |
| 519 // Call OnTraceLogStatusReply unconditionally for the browser process. |
518 // This will result in immediate execution of the callback if there are no | 520 // This will result in immediate execution of the callback if there are no |
519 // child processes. | 521 // child processes. |
520 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 522 BrowserThread::PostTask( |
521 base::Bind(&TracingControllerImpl::OnTraceBufferPercentFullReply, | 523 BrowserThread::UI, FROM_HERE, |
522 base::Unretained(this), | 524 base::Bind(&TracingControllerImpl::OnTraceLogStatusReply, |
523 scoped_refptr<TraceMessageFilter>(), | 525 base::Unretained(this), scoped_refptr<TraceMessageFilter>(), |
524 TraceLog::GetInstance()->GetBufferPercentFull())); | 526 status)); |
525 | 527 |
526 // Notify all child processes. | 528 // Notify all child processes. |
527 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin(); | 529 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin(); |
528 it != trace_message_filters_.end(); ++it) { | 530 it != trace_message_filters_.end(); ++it) { |
529 it->get()->SendGetTraceBufferPercentFull(); | 531 it->get()->SendGetTraceLogStatus(); |
530 } | 532 } |
531 return true; | 533 return true; |
532 } | 534 } |
533 | 535 |
534 bool TracingControllerImpl::SetWatchEvent( | 536 bool TracingControllerImpl::SetWatchEvent( |
535 const std::string& category_name, | 537 const std::string& category_name, |
536 const std::string& event_name, | 538 const std::string& event_name, |
537 const WatchEventCallback& callback) { | 539 const WatchEventCallback& callback) { |
538 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 540 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
539 | 541 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 if (pending_capture_monitoring_snapshot_ack_count_ > 0) { | 627 if (pending_capture_monitoring_snapshot_ack_count_ > 0) { |
626 TraceMessageFilterSet::const_iterator it = | 628 TraceMessageFilterSet::const_iterator it = |
627 pending_capture_monitoring_filters_.find(trace_message_filter); | 629 pending_capture_monitoring_filters_.find(trace_message_filter); |
628 if (it != pending_capture_monitoring_filters_.end()) { | 630 if (it != pending_capture_monitoring_filters_.end()) { |
629 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 631 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
630 base::Bind(&TracingControllerImpl::OnCaptureMonitoringSnapshotAcked, | 632 base::Bind(&TracingControllerImpl::OnCaptureMonitoringSnapshotAcked, |
631 base::Unretained(this), | 633 base::Unretained(this), |
632 make_scoped_refptr(trace_message_filter))); | 634 make_scoped_refptr(trace_message_filter))); |
633 } | 635 } |
634 } | 636 } |
635 if (pending_trace_buffer_percent_full_ack_count_ > 0) { | 637 if (pending_trace_log_status_ack_count_ > 0) { |
636 TraceMessageFilterSet::const_iterator it = | 638 TraceMessageFilterSet::const_iterator it = |
637 pending_trace_buffer_percent_full_filters_.find(trace_message_filter); | 639 pending_trace_log_status_filters_.find(trace_message_filter); |
638 if (it != pending_trace_buffer_percent_full_filters_.end()) { | 640 if (it != pending_trace_log_status_filters_.end()) { |
639 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 641 BrowserThread::PostTask( |
640 base::Bind(&TracingControllerImpl::OnTraceBufferPercentFullReply, | 642 BrowserThread::UI, FROM_HERE, |
| 643 base::Bind(&TracingControllerImpl::OnTraceLogStatusReply, |
641 base::Unretained(this), | 644 base::Unretained(this), |
642 make_scoped_refptr(trace_message_filter), | 645 make_scoped_refptr(trace_message_filter), |
643 0)); | 646 base::debug::TraceLogStatus())); |
644 } | 647 } |
645 } | 648 } |
646 | 649 |
647 trace_message_filters_.erase(trace_message_filter); | 650 trace_message_filters_.erase(trace_message_filter); |
648 } | 651 } |
649 | 652 |
650 void TracingControllerImpl::OnDisableRecordingAcked( | 653 void TracingControllerImpl::OnDisableRecordingAcked( |
651 TraceMessageFilter* trace_message_filter, | 654 TraceMessageFilter* trace_message_filter, |
652 const std::vector<std::string>& known_category_groups) { | 655 const std::vector<std::string>& known_category_groups) { |
653 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 656 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 if (events_str_ptr->data().size()) | 811 if (events_str_ptr->data().size()) |
809 OnMonitoringTraceDataCollected(events_str_ptr); | 812 OnMonitoringTraceDataCollected(events_str_ptr); |
810 | 813 |
811 if (has_more_events) | 814 if (has_more_events) |
812 return; | 815 return; |
813 | 816 |
814 // Simulate an CaptureMonitoringSnapshotAcked for the local trace. | 817 // Simulate an CaptureMonitoringSnapshotAcked for the local trace. |
815 OnCaptureMonitoringSnapshotAcked(NULL); | 818 OnCaptureMonitoringSnapshotAcked(NULL); |
816 } | 819 } |
817 | 820 |
818 void TracingControllerImpl::OnTraceBufferPercentFullReply( | 821 void TracingControllerImpl::OnTraceLogStatusReply( |
819 TraceMessageFilter* trace_message_filter, | 822 TraceMessageFilter* trace_message_filter, |
820 float percent_full) { | 823 const base::debug::TraceLogStatus& status) { |
821 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 824 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
822 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 825 BrowserThread::PostTask( |
823 base::Bind(&TracingControllerImpl::OnTraceBufferPercentFullReply, | 826 BrowserThread::UI, FROM_HERE, |
| 827 base::Bind(&TracingControllerImpl::OnTraceLogStatusReply, |
824 base::Unretained(this), | 828 base::Unretained(this), |
825 make_scoped_refptr(trace_message_filter), | 829 make_scoped_refptr(trace_message_filter), status)); |
826 percent_full)); | |
827 return; | 830 return; |
828 } | 831 } |
829 | 832 |
830 if (pending_trace_buffer_percent_full_ack_count_ == 0) | 833 if (pending_trace_log_status_ack_count_ == 0) |
831 return; | 834 return; |
832 | 835 |
833 if (trace_message_filter && | 836 if (trace_message_filter && |
834 !pending_trace_buffer_percent_full_filters_.erase(trace_message_filter)) { | 837 !pending_trace_log_status_filters_.erase(trace_message_filter)) { |
835 // The response from the specified message filter has already been received. | 838 // The response from the specified message filter has already been received. |
836 return; | 839 return; |
837 } | 840 } |
838 | 841 |
839 maximum_trace_buffer_percent_full_ = | 842 float percent_full = static_cast<float>( |
840 std::max(maximum_trace_buffer_percent_full_, percent_full); | 843 static_cast<double>(status.event_count) / status.event_capacity); |
| 844 maximum_trace_buffer_usage_ = |
| 845 std::max(maximum_trace_buffer_usage_, percent_full); |
| 846 approximate_event_count_ += status.event_count; |
841 | 847 |
842 if (--pending_trace_buffer_percent_full_ack_count_ == 0) { | 848 if (--pending_trace_log_status_ack_count_ == 0) { |
843 // Trigger callback if one is set. | 849 // Trigger callback if one is set. |
844 pending_trace_buffer_percent_full_callback_.Run( | 850 pending_trace_buffer_usage_callback_.Run(maximum_trace_buffer_usage_, |
845 maximum_trace_buffer_percent_full_); | 851 approximate_event_count_); |
846 pending_trace_buffer_percent_full_callback_.Reset(); | 852 pending_trace_buffer_usage_callback_.Reset(); |
847 } | 853 } |
848 } | 854 } |
849 | 855 |
850 void TracingControllerImpl::OnWatchEventMatched() { | 856 void TracingControllerImpl::OnWatchEventMatched() { |
851 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 857 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
852 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 858 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
853 base::Bind(&TracingControllerImpl::OnWatchEventMatched, | 859 base::Bind(&TracingControllerImpl::OnWatchEventMatched, |
854 base::Unretained(this))); | 860 base::Unretained(this))); |
855 return; | 861 return; |
856 } | 862 } |
(...skipping 20 matching lines...) Expand all Loading... |
877 is_monitoring_ = is_monitoring; | 883 is_monitoring_ = is_monitoring; |
878 #if !defined(OS_ANDROID) | 884 #if !defined(OS_ANDROID) |
879 for (std::set<TracingUI*>::iterator it = tracing_uis_.begin(); | 885 for (std::set<TracingUI*>::iterator it = tracing_uis_.begin(); |
880 it != tracing_uis_.end(); it++) { | 886 it != tracing_uis_.end(); it++) { |
881 (*it)->OnMonitoringStateChanged(is_monitoring); | 887 (*it)->OnMonitoringStateChanged(is_monitoring); |
882 } | 888 } |
883 #endif | 889 #endif |
884 } | 890 } |
885 | 891 |
886 } // namespace content | 892 } // namespace content |
OLD | NEW |