| 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_buffer_percent_full_ack_count_(0), |
| 169 maximum_trace_buffer_percent_full_(0), | 169 maximum_trace_buffer_percent_full_(0), |
| 170 total_trace_buffer_usage_(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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 if (!can_get_trace_buffer_percent_full() || callback.is_null()) | 507 if (!can_get_trace_buffer_percent_full() || callback.is_null()) |
| 507 return false; | 508 return false; |
| 508 | 509 |
| 509 pending_trace_buffer_percent_full_callback_ = callback; | 510 pending_trace_buffer_percent_full_callback_ = callback; |
| 510 | 511 |
| 511 // Count myself in pending_trace_buffer_percent_full_ack_count_, acked below. | 512 // Count myself in pending_trace_buffer_percent_full_ack_count_, acked below. |
| 512 pending_trace_buffer_percent_full_ack_count_ = | 513 pending_trace_buffer_percent_full_ack_count_ = |
| 513 trace_message_filters_.size() + 1; | 514 trace_message_filters_.size() + 1; |
| 514 pending_trace_buffer_percent_full_filters_ = trace_message_filters_; | 515 pending_trace_buffer_percent_full_filters_ = trace_message_filters_; |
| 515 maximum_trace_buffer_percent_full_ = 0; | 516 maximum_trace_buffer_percent_full_ = 0; |
| 517 total_trace_buffer_usage_ = 0; |
| 516 | 518 |
| 517 // Call OnTraceBufferPercentFullReply unconditionally for the browser process. | 519 // Call OnTraceBufferPercentFullReply 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( |
| 523 BrowserThread::UI, FROM_HERE, |
| 521 base::Bind(&TracingControllerImpl::OnTraceBufferPercentFullReply, | 524 base::Bind(&TracingControllerImpl::OnTraceBufferPercentFullReply, |
| 522 base::Unretained(this), | 525 base::Unretained(this), scoped_refptr<TraceMessageFilter>(), |
| 523 scoped_refptr<TraceMessageFilter>(), | 526 TraceLog::GetInstance()->GetBufferPercentFull(), |
| 524 TraceLog::GetInstance()->GetBufferPercentFull())); | 527 TraceLog::GetInstance()->GetBufferUsage())); |
| 525 | 528 |
| 526 // Notify all child processes. | 529 // Notify all child processes. |
| 527 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin(); | 530 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin(); |
| 528 it != trace_message_filters_.end(); ++it) { | 531 it != trace_message_filters_.end(); ++it) { |
| 529 it->get()->SendGetTraceBufferPercentFull(); | 532 it->get()->SendGetTraceBufferPercentFull(); |
| 530 } | 533 } |
| 531 return true; | 534 return true; |
| 532 } | 535 } |
| 533 | 536 |
| 534 bool TracingControllerImpl::SetWatchEvent( | 537 bool TracingControllerImpl::SetWatchEvent( |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 632 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 630 base::Bind(&TracingControllerImpl::OnCaptureMonitoringSnapshotAcked, | 633 base::Bind(&TracingControllerImpl::OnCaptureMonitoringSnapshotAcked, |
| 631 base::Unretained(this), | 634 base::Unretained(this), |
| 632 make_scoped_refptr(trace_message_filter))); | 635 make_scoped_refptr(trace_message_filter))); |
| 633 } | 636 } |
| 634 } | 637 } |
| 635 if (pending_trace_buffer_percent_full_ack_count_ > 0) { | 638 if (pending_trace_buffer_percent_full_ack_count_ > 0) { |
| 636 TraceMessageFilterSet::const_iterator it = | 639 TraceMessageFilterSet::const_iterator it = |
| 637 pending_trace_buffer_percent_full_filters_.find(trace_message_filter); | 640 pending_trace_buffer_percent_full_filters_.find(trace_message_filter); |
| 638 if (it != pending_trace_buffer_percent_full_filters_.end()) { | 641 if (it != pending_trace_buffer_percent_full_filters_.end()) { |
| 639 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 642 BrowserThread::PostTask( |
| 643 BrowserThread::UI, FROM_HERE, |
| 640 base::Bind(&TracingControllerImpl::OnTraceBufferPercentFullReply, | 644 base::Bind(&TracingControllerImpl::OnTraceBufferPercentFullReply, |
| 641 base::Unretained(this), | 645 base::Unretained(this), |
| 642 make_scoped_refptr(trace_message_filter), | 646 make_scoped_refptr(trace_message_filter), 0, 0)); |
| 643 0)); | |
| 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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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::OnTraceBufferPercentFullReply( |
| 819 TraceMessageFilter* trace_message_filter, | 822 TraceMessageFilter* trace_message_filter, |
| 820 float percent_full) { | 823 float percent_full, |
| 824 size_t buffer_usage) { |
| 821 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 825 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 822 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 826 BrowserThread::PostTask( |
| 827 BrowserThread::UI, FROM_HERE, |
| 823 base::Bind(&TracingControllerImpl::OnTraceBufferPercentFullReply, | 828 base::Bind(&TracingControllerImpl::OnTraceBufferPercentFullReply, |
| 824 base::Unretained(this), | 829 base::Unretained(this), |
| 825 make_scoped_refptr(trace_message_filter), | 830 make_scoped_refptr(trace_message_filter), percent_full, |
| 826 percent_full)); | 831 buffer_usage)); |
| 827 return; | 832 return; |
| 828 } | 833 } |
| 829 | 834 |
| 830 if (pending_trace_buffer_percent_full_ack_count_ == 0) | 835 if (pending_trace_buffer_percent_full_ack_count_ == 0) |
| 831 return; | 836 return; |
| 832 | 837 |
| 833 if (trace_message_filter && | 838 if (trace_message_filter && |
| 834 !pending_trace_buffer_percent_full_filters_.erase(trace_message_filter)) { | 839 !pending_trace_buffer_percent_full_filters_.erase(trace_message_filter)) { |
| 835 // The response from the specified message filter has already been received. | 840 // The response from the specified message filter has already been received. |
| 836 return; | 841 return; |
| 837 } | 842 } |
| 838 | 843 |
| 839 maximum_trace_buffer_percent_full_ = | 844 maximum_trace_buffer_percent_full_ = |
| 840 std::max(maximum_trace_buffer_percent_full_, percent_full); | 845 std::max(maximum_trace_buffer_percent_full_, percent_full); |
| 846 total_trace_buffer_usage_ += buffer_usage; |
| 841 | 847 |
| 842 if (--pending_trace_buffer_percent_full_ack_count_ == 0) { | 848 if (--pending_trace_buffer_percent_full_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_percent_full_callback_.Run( |
| 845 maximum_trace_buffer_percent_full_); | 851 maximum_trace_buffer_percent_full_, total_trace_buffer_usage_); |
| 846 pending_trace_buffer_percent_full_callback_.Reset(); | 852 pending_trace_buffer_percent_full_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; |
| (...skipping 21 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 |