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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/tracing/tracing_controller_impl.cc
diff --git a/content/browser/tracing/tracing_controller_impl.cc b/content/browser/tracing/tracing_controller_impl.cc
index 3e8e1ac7cd1c0fc2d5aa5df1fbf84e88b5f626d9..d36c87c73e6277f16be05edb98678ccba717ddab 100644
--- a/content/browser/tracing/tracing_controller_impl.cc
+++ b/content/browser/tracing/tracing_controller_impl.cc
@@ -162,18 +162,19 @@ TracingController* TracingController::GetInstance() {
return TracingControllerImpl::GetInstance();
}
-TracingControllerImpl::TracingControllerImpl() :
- pending_disable_recording_ack_count_(0),
- pending_capture_monitoring_snapshot_ack_count_(0),
- pending_trace_buffer_percent_full_ack_count_(0),
- maximum_trace_buffer_percent_full_(0),
+TracingControllerImpl::TracingControllerImpl()
+ : pending_disable_recording_ack_count_(0),
+ pending_capture_monitoring_snapshot_ack_count_(0),
+ pending_trace_buffer_usage_ack_count_(0),
+ maximum_trace_buffer_usage_(0),
+ approximate_event_count_(0),
// Tracing may have been enabled by ContentMainRunner if kTraceStartup
// is specified in command line.
#if defined(OS_CHROMEOS) || defined(OS_WIN)
- is_system_tracing_(false),
+ is_system_tracing_(false),
#endif
- is_recording_(TraceLog::GetInstance()->IsEnabled()),
- is_monitoring_(false) {
+ is_recording_(TraceLog::GetInstance()->IsEnabled()),
+ is_monitoring_(false) {
}
TracingControllerImpl::~TracingControllerImpl() {
@@ -499,34 +500,36 @@ bool TracingControllerImpl::CaptureMonitoringSnapshot(
return true;
}
-bool TracingControllerImpl::GetTraceBufferPercentFull(
- const GetTraceBufferPercentFullCallback& callback) {
+bool TracingControllerImpl::GetTraceBufferUsage(
+ const GetTraceBufferUsageCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- if (!can_get_trace_buffer_percent_full() || callback.is_null())
+ if (!can_get_trace_buffer_usage() || callback.is_null())
return false;
- pending_trace_buffer_percent_full_callback_ = callback;
+ pending_trace_buffer_usage_callback_ = callback;
- // Count myself in pending_trace_buffer_percent_full_ack_count_, acked below.
- pending_trace_buffer_percent_full_ack_count_ =
- trace_message_filters_.size() + 1;
- pending_trace_buffer_percent_full_filters_ = trace_message_filters_;
- maximum_trace_buffer_percent_full_ = 0;
+ // Count myself in pending_trace_buffer_usage_ack_count_, acked below.
+ pending_trace_buffer_usage_ack_count_ = trace_message_filters_.size() + 1;
+ pending_trace_buffer_usage_filters_ = trace_message_filters_;
+ maximum_trace_buffer_usage_ = 0;
+ approximate_event_count_ = 0;
- // Call OnTraceBufferPercentFullReply unconditionally for the browser process.
+ TraceLog::BufferUsage buffer_usage =
+ TraceLog::GetInstance()->GetBufferUsage();
+ // Call OnTraceBufferUsageReply unconditionally for the browser process.
// This will result in immediate execution of the callback if there are no
// child processes.
- BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
- base::Bind(&TracingControllerImpl::OnTraceBufferPercentFullReply,
- base::Unretained(this),
- scoped_refptr<TraceMessageFilter>(),
- TraceLog::GetInstance()->GetBufferPercentFull()));
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&TracingControllerImpl::OnTraceBufferUsageReply,
+ base::Unretained(this), scoped_refptr<TraceMessageFilter>(),
+ buffer_usage.event_capacity, buffer_usage.event_count));
// Notify all child processes.
for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin();
it != trace_message_filters_.end(); ++it) {
- it->get()->SendGetTraceBufferPercentFull();
+ it->get()->SendGetTraceBufferUsage();
}
return true;
}
@@ -632,15 +635,15 @@ void TracingControllerImpl::RemoveTraceMessageFilter(
make_scoped_refptr(trace_message_filter)));
}
}
- if (pending_trace_buffer_percent_full_ack_count_ > 0) {
+ if (pending_trace_buffer_usage_ack_count_ > 0) {
TraceMessageFilterSet::const_iterator it =
- pending_trace_buffer_percent_full_filters_.find(trace_message_filter);
- if (it != pending_trace_buffer_percent_full_filters_.end()) {
- BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
- base::Bind(&TracingControllerImpl::OnTraceBufferPercentFullReply,
+ pending_trace_buffer_usage_filters_.find(trace_message_filter);
+ if (it != pending_trace_buffer_usage_filters_.end()) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&TracingControllerImpl::OnTraceBufferUsageReply,
base::Unretained(this),
- make_scoped_refptr(trace_message_filter),
- 0));
+ make_scoped_refptr(trace_message_filter), 0, 0));
}
}
@@ -815,35 +818,40 @@ void TracingControllerImpl::OnLocalMonitoringTraceDataCollected(
OnCaptureMonitoringSnapshotAcked(NULL);
}
-void TracingControllerImpl::OnTraceBufferPercentFullReply(
+void TracingControllerImpl::OnTraceBufferUsageReply(
TraceMessageFilter* trace_message_filter,
- float percent_full) {
+ size_t event_capacity,
+ size_t event_count) {
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
- BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
- base::Bind(&TracingControllerImpl::OnTraceBufferPercentFullReply,
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&TracingControllerImpl::OnTraceBufferUsageReply,
base::Unretained(this),
- make_scoped_refptr(trace_message_filter),
- percent_full));
+ make_scoped_refptr(trace_message_filter), event_capacity,
+ event_count));
return;
}
- if (pending_trace_buffer_percent_full_ack_count_ == 0)
+ if (pending_trace_buffer_usage_ack_count_ == 0)
return;
if (trace_message_filter &&
- !pending_trace_buffer_percent_full_filters_.erase(trace_message_filter)) {
+ !pending_trace_buffer_usage_filters_.erase(trace_message_filter)) {
// The response from the specified message filter has already been received.
return;
}
- maximum_trace_buffer_percent_full_ =
- std::max(maximum_trace_buffer_percent_full_, percent_full);
+ float percent_full =
+ static_cast<float>(static_cast<double>(event_count) / event_capacity);
+ maximum_trace_buffer_usage_ =
+ std::max(maximum_trace_buffer_usage_, percent_full);
+ approximate_event_count_ += event_count;
- if (--pending_trace_buffer_percent_full_ack_count_ == 0) {
+ if (--pending_trace_buffer_usage_ack_count_ == 0) {
// Trigger callback if one is set.
- pending_trace_buffer_percent_full_callback_.Run(
- maximum_trace_buffer_percent_full_);
- pending_trace_buffer_percent_full_callback_.Reset();
+ pending_trace_buffer_usage_callback_.Run(maximum_trace_buffer_usage_,
+ approximate_event_count_);
+ pending_trace_buffer_usage_callback_.Reset();
}
}

Powered by Google App Engine
This is Rietveld 408576698