Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(443)

Side by Side Diff: content/browser/tracing/tracing_controller_impl.cc

Issue 717083003: Report trace buffer usage as number of events, not only percentage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 approximate_event_count_ = 0;
516 518
517 // Call OnTraceBufferPercentFullReply unconditionally for the browser process. 519 float buffer_percent_full;
520 size_t approximate_event_count;
521 TraceLog::GetInstance()->GetBufferUsage(&buffer_percent_full,
522 &approximate_event_count);
523 // Call OnTraceBufferUsageReply unconditionally for the browser process.
518 // This will result in immediate execution of the callback if there are no 524 // This will result in immediate execution of the callback if there are no
519 // child processes. 525 // child processes.
520 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 526 BrowserThread::PostTask(
521 base::Bind(&TracingControllerImpl::OnTraceBufferPercentFullReply, 527 BrowserThread::UI, FROM_HERE,
522 base::Unretained(this), 528 base::Bind(&TracingControllerImpl::OnTraceBufferUsageReply,
523 scoped_refptr<TraceMessageFilter>(), 529 base::Unretained(this), scoped_refptr<TraceMessageFilter>(),
524 TraceLog::GetInstance()->GetBufferPercentFull())); 530 buffer_percent_full, approximate_event_count));
525 531
526 // Notify all child processes. 532 // Notify all child processes.
527 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin(); 533 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin();
528 it != trace_message_filters_.end(); ++it) { 534 it != trace_message_filters_.end(); ++it) {
529 it->get()->SendGetTraceBufferPercentFull(); 535 it->get()->SendGetTraceBufferUsage();
530 } 536 }
531 return true; 537 return true;
532 } 538 }
533 539
534 bool TracingControllerImpl::SetWatchEvent( 540 bool TracingControllerImpl::SetWatchEvent(
535 const std::string& category_name, 541 const std::string& category_name,
536 const std::string& event_name, 542 const std::string& event_name,
537 const WatchEventCallback& callback) { 543 const WatchEventCallback& callback) {
538 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 544 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
539 545
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 635 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
630 base::Bind(&TracingControllerImpl::OnCaptureMonitoringSnapshotAcked, 636 base::Bind(&TracingControllerImpl::OnCaptureMonitoringSnapshotAcked,
631 base::Unretained(this), 637 base::Unretained(this),
632 make_scoped_refptr(trace_message_filter))); 638 make_scoped_refptr(trace_message_filter)));
633 } 639 }
634 } 640 }
635 if (pending_trace_buffer_percent_full_ack_count_ > 0) { 641 if (pending_trace_buffer_percent_full_ack_count_ > 0) {
636 TraceMessageFilterSet::const_iterator it = 642 TraceMessageFilterSet::const_iterator it =
637 pending_trace_buffer_percent_full_filters_.find(trace_message_filter); 643 pending_trace_buffer_percent_full_filters_.find(trace_message_filter);
638 if (it != pending_trace_buffer_percent_full_filters_.end()) { 644 if (it != pending_trace_buffer_percent_full_filters_.end()) {
639 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 645 BrowserThread::PostTask(
640 base::Bind(&TracingControllerImpl::OnTraceBufferPercentFullReply, 646 BrowserThread::UI, FROM_HERE,
647 base::Bind(&TracingControllerImpl::OnTraceBufferUsageReply,
641 base::Unretained(this), 648 base::Unretained(this),
642 make_scoped_refptr(trace_message_filter), 649 make_scoped_refptr(trace_message_filter), 0, 0));
643 0));
644 } 650 }
645 } 651 }
646 652
647 trace_message_filters_.erase(trace_message_filter); 653 trace_message_filters_.erase(trace_message_filter);
648 } 654 }
649 655
650 void TracingControllerImpl::OnDisableRecordingAcked( 656 void TracingControllerImpl::OnDisableRecordingAcked(
651 TraceMessageFilter* trace_message_filter, 657 TraceMessageFilter* trace_message_filter,
652 const std::vector<std::string>& known_category_groups) { 658 const std::vector<std::string>& known_category_groups) {
653 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 659 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 if (events_str_ptr->data().size()) 814 if (events_str_ptr->data().size())
809 OnMonitoringTraceDataCollected(events_str_ptr); 815 OnMonitoringTraceDataCollected(events_str_ptr);
810 816
811 if (has_more_events) 817 if (has_more_events)
812 return; 818 return;
813 819
814 // Simulate an CaptureMonitoringSnapshotAcked for the local trace. 820 // Simulate an CaptureMonitoringSnapshotAcked for the local trace.
815 OnCaptureMonitoringSnapshotAcked(NULL); 821 OnCaptureMonitoringSnapshotAcked(NULL);
816 } 822 }
817 823
818 void TracingControllerImpl::OnTraceBufferPercentFullReply( 824 void TracingControllerImpl::OnTraceBufferUsageReply(
819 TraceMessageFilter* trace_message_filter, 825 TraceMessageFilter* trace_message_filter,
820 float percent_full) { 826 float percent_full,
827 size_t approximate_event_count) {
821 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 828 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
822 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 829 BrowserThread::PostTask(
823 base::Bind(&TracingControllerImpl::OnTraceBufferPercentFullReply, 830 BrowserThread::UI, FROM_HERE,
831 base::Bind(&TracingControllerImpl::OnTraceBufferUsageReply,
824 base::Unretained(this), 832 base::Unretained(this),
825 make_scoped_refptr(trace_message_filter), 833 make_scoped_refptr(trace_message_filter), percent_full,
826 percent_full)); 834 approximate_event_count));
827 return; 835 return;
828 } 836 }
829 837
830 if (pending_trace_buffer_percent_full_ack_count_ == 0) 838 if (pending_trace_buffer_percent_full_ack_count_ == 0)
831 return; 839 return;
832 840
833 if (trace_message_filter && 841 if (trace_message_filter &&
834 !pending_trace_buffer_percent_full_filters_.erase(trace_message_filter)) { 842 !pending_trace_buffer_percent_full_filters_.erase(trace_message_filter)) {
835 // The response from the specified message filter has already been received. 843 // The response from the specified message filter has already been received.
836 return; 844 return;
837 } 845 }
838 846
839 maximum_trace_buffer_percent_full_ = 847 maximum_trace_buffer_percent_full_ =
840 std::max(maximum_trace_buffer_percent_full_, percent_full); 848 std::max(maximum_trace_buffer_percent_full_, percent_full);
849 approximate_event_count_ += approximate_event_count;
841 850
842 if (--pending_trace_buffer_percent_full_ack_count_ == 0) { 851 if (--pending_trace_buffer_percent_full_ack_count_ == 0) {
843 // Trigger callback if one is set. 852 // Trigger callback if one is set.
844 pending_trace_buffer_percent_full_callback_.Run( 853 pending_trace_buffer_percent_full_callback_.Run(
845 maximum_trace_buffer_percent_full_); 854 maximum_trace_buffer_percent_full_, approximate_event_count_);
846 pending_trace_buffer_percent_full_callback_.Reset(); 855 pending_trace_buffer_percent_full_callback_.Reset();
847 } 856 }
848 } 857 }
849 858
850 void TracingControllerImpl::OnWatchEventMatched() { 859 void TracingControllerImpl::OnWatchEventMatched() {
851 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 860 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
852 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 861 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
853 base::Bind(&TracingControllerImpl::OnWatchEventMatched, 862 base::Bind(&TracingControllerImpl::OnWatchEventMatched,
854 base::Unretained(this))); 863 base::Unretained(this)));
855 return; 864 return;
(...skipping 21 matching lines...) Expand all
877 is_monitoring_ = is_monitoring; 886 is_monitoring_ = is_monitoring;
878 #if !defined(OS_ANDROID) 887 #if !defined(OS_ANDROID)
879 for (std::set<TracingUI*>::iterator it = tracing_uis_.begin(); 888 for (std::set<TracingUI*>::iterator it = tracing_uis_.begin();
880 it != tracing_uis_.end(); it++) { 889 it != tracing_uis_.end(); it++) {
881 (*it)->OnMonitoringStateChanged(is_monitoring); 890 (*it)->OnMonitoringStateChanged(is_monitoring);
882 } 891 }
883 #endif 892 #endif
884 } 893 }
885 894
886 } // namespace content 895 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698