diff --git a/base/debug/trace_event_impl.cc b/base/debug/trace_event_impl.cc index ce62766da3df55..1a64eb0f6edc25 100644 --- a/base/debug/trace_event_impl.cc +++ b/base/debug/trace_event_impl.cc @@ -1185,6 +1185,12 @@ void TraceLog::ThreadLocalEventBuffer::FlushWhileLocked() { // find the generation mismatch and delete this buffer soon. } +TraceLogStatus::TraceLogStatus() : event_capacity(0), event_count(0) { +} + +TraceLogStatus::~TraceLogStatus() { +} + // static TraceLog* TraceLog::GetInstance() { return Singleton >::get(); @@ -1586,10 +1592,12 @@ bool TraceLog::HasEnabledStateObserver(EnabledStateObserver* listener) const { return it != enabled_state_observer_list_.end(); } -float TraceLog::GetBufferPercentFull() const { +TraceLogStatus TraceLog::GetStatus() const { AutoLock lock(lock_); - return static_cast(static_cast(logged_events_->Size()) / - logged_events_->Capacity()); + TraceLogStatus result; + result.event_capacity = logged_events_->Capacity(); + result.event_count = logged_events_->Size(); + return result; } bool TraceLog::BufferIsFull() const { diff --git a/base/debug/trace_event_impl.h b/base/debug/trace_event_impl.h index 6075e2dee78698..ce2e0178641e27 100644 --- a/base/debug/trace_event_impl.h +++ b/base/debug/trace_event_impl.h @@ -420,6 +420,13 @@ struct BASE_EXPORT TraceOptions { bool enable_systrace; }; +struct BASE_EXPORT TraceLogStatus { + TraceLogStatus(); + ~TraceLogStatus(); + size_t event_capacity; + size_t event_count; +}; + class BASE_EXPORT TraceLog { public: enum Mode { @@ -495,7 +502,7 @@ class BASE_EXPORT TraceLog { void RemoveEnabledStateObserver(EnabledStateObserver* listener); bool HasEnabledStateObserver(EnabledStateObserver* listener) const; - float GetBufferPercentFull() const; + TraceLogStatus GetStatus() const; bool BufferIsFull() const; // Not using base::Callback because of its limited by 7 parameters. @@ -603,7 +610,6 @@ class BASE_EXPORT TraceLog { static void DeleteForTesting(); // Allow tests to inspect TraceEvents. - size_t GetEventsSize() const { return logged_events_->Size(); } TraceEvent* GetEventByHandle(TraceEventHandle handle); void SetProcessID(int process_id); diff --git a/base/debug/trace_event_unittest.cc b/base/debug/trace_event_unittest.cc index 69b574305e2868..090495480e7a80 100644 --- a/base/debug/trace_event_unittest.cc +++ b/base/debug/trace_event_unittest.cc @@ -1366,8 +1366,7 @@ TEST_F(TraceEventTestFixture, AsyncBeginEndPointerMangling) { TEST_F(TraceEventTestFixture, StaticStringVsString) { TraceLog* tracer = TraceLog::GetInstance(); // Make sure old events are flushed: - EndTraceAndFlush(); - EXPECT_EQ(0u, tracer->GetEventsSize()); + EXPECT_EQ(0u, tracer->GetStatus().event_count); const unsigned char* category_group_enabled = TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED("cat"); @@ -1384,8 +1383,7 @@ TEST_F(TraceEventTestFixture, StaticStringVsString) { TRACE_EVENT_PHASE_INSTANT, category_group_enabled, "name2", 0, 0, "arg1", TRACE_STR_COPY("argval"), "arg2", TRACE_STR_COPY("argval")); - size_t num_events = tracer->GetEventsSize(); - EXPECT_GT(num_events, 1u); + EXPECT_GT(tracer->GetStatus().event_count, 1u); const TraceEvent* event1 = tracer->GetEventByHandle(handle1); const TraceEvent* event2 = tracer->GetEventByHandle(handle2); ASSERT_TRUE(event1); @@ -1414,8 +1412,7 @@ TEST_F(TraceEventTestFixture, StaticStringVsString) { TRACE_EVENT_PHASE_INSTANT, category_group_enabled, "name2", 0, 0, "arg1", TRACE_STR_COPY(str1), "arg2", TRACE_STR_COPY(str2)); - size_t num_events = tracer->GetEventsSize(); - EXPECT_GT(num_events, 1u); + EXPECT_GT(tracer->GetStatus().event_count, 1u); const TraceEvent* event1 = tracer->GetEventByHandle(handle1); const TraceEvent* event2 = tracer->GetEventByHandle(handle2); ASSERT_TRUE(event1); diff --git a/components/tracing/child_trace_message_filter.cc b/components/tracing/child_trace_message_filter.cc index fe13ff57dd08ca..54782a52401245 100644 --- a/components/tracing/child_trace_message_filter.cc +++ b/components/tracing/child_trace_message_filter.cc @@ -36,8 +36,7 @@ bool ChildTraceMessageFilter::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(TracingMsg_DisableMonitoring, OnDisableMonitoring) IPC_MESSAGE_HANDLER(TracingMsg_CaptureMonitoringSnapshot, OnCaptureMonitoringSnapshot) - IPC_MESSAGE_HANDLER(TracingMsg_GetTraceBufferPercentFull, - OnGetTraceBufferPercentFull) + IPC_MESSAGE_HANDLER(TracingMsg_GetTraceLogStatus, OnGetTraceLogStatus) IPC_MESSAGE_HANDLER(TracingMsg_SetWatchEvent, OnSetWatchEvent) IPC_MESSAGE_HANDLER(TracingMsg_CancelWatchEvent, OnCancelWatchEvent) IPC_MESSAGE_UNHANDLED(handled = false) @@ -105,10 +104,9 @@ void ChildTraceMessageFilter::OnCaptureMonitoringSnapshot() { this)); } -void ChildTraceMessageFilter::OnGetTraceBufferPercentFull() { - float bpf = TraceLog::GetInstance()->GetBufferPercentFull(); - - sender_->Send(new TracingHostMsg_TraceBufferPercentFullReply(bpf)); +void ChildTraceMessageFilter::OnGetTraceLogStatus() { + sender_->Send(new TracingHostMsg_TraceLogStatusReply( + TraceLog::GetInstance()->GetStatus())); } void ChildTraceMessageFilter::OnSetWatchEvent(const std::string& category_name, diff --git a/components/tracing/child_trace_message_filter.h b/components/tracing/child_trace_message_filter.h index daa00ee3bdad0d..75ab067c745308 100644 --- a/components/tracing/child_trace_message_filter.h +++ b/components/tracing/child_trace_message_filter.h @@ -39,7 +39,7 @@ class ChildTraceMessageFilter : public IPC::MessageFilter { const std::string& options); void OnDisableMonitoring(); void OnCaptureMonitoringSnapshot(); - void OnGetTraceBufferPercentFull(); + void OnGetTraceLogStatus(); void OnSetWatchEvent(const std::string& category_name, const std::string& event_name); void OnCancelWatchEvent(); diff --git a/components/tracing/tracing_messages.h b/components/tracing/tracing_messages.h index ff891a0edaab76..18041cc6797c36 100644 --- a/components/tracing/tracing_messages.h +++ b/components/tracing/tracing_messages.h @@ -7,6 +7,7 @@ #include #include "base/basictypes.h" +#include "base/debug/trace_event_impl.h" #include "base/sync_socket.h" #include "ipc/ipc_channel_handle.h" #include "ipc/ipc_message_macros.h" @@ -15,6 +16,11 @@ #define IPC_MESSAGE_START TracingMsgStart +IPC_STRUCT_TRAITS_BEGIN(base::debug::TraceLogStatus) +IPC_STRUCT_TRAITS_MEMBER(event_capacity) +IPC_STRUCT_TRAITS_MEMBER(event_count) +IPC_STRUCT_TRAITS_END() + // Sent to all child processes to enable trace event recording. IPC_MESSAGE_CONTROL3(TracingMsg_BeginTracing, std::string /* category_filter_str */, @@ -37,7 +43,7 @@ IPC_MESSAGE_CONTROL0(TracingMsg_DisableMonitoring) IPC_MESSAGE_CONTROL0(TracingMsg_CaptureMonitoringSnapshot) // Sent to all child processes to get trace buffer fullness. -IPC_MESSAGE_CONTROL0(TracingMsg_GetTraceBufferPercentFull) +IPC_MESSAGE_CONTROL0(TracingMsg_GetTraceLogStatus) // Sent to all child processes to set watch event. IPC_MESSAGE_CONTROL2(TracingMsg_SetWatchEvent, @@ -69,7 +75,6 @@ IPC_MESSAGE_CONTROL1(TracingHostMsg_TraceDataCollected, IPC_MESSAGE_CONTROL1(TracingHostMsg_MonitoringTraceDataCollected, std::string /*json trace data*/) -// Reply to TracingMsg_GetTraceBufferPercentFull. -IPC_MESSAGE_CONTROL1(TracingHostMsg_TraceBufferPercentFullReply, - float /*trace buffer percent full*/) - +// Reply to TracingMsg_GetTraceLogStatus. +IPC_MESSAGE_CONTROL1(TracingHostMsg_TraceLogStatusReply, + base::debug::TraceLogStatus /*status of the trace log*/) diff --git a/content/browser/browser_shutdown_profile_dumper.cc b/content/browser/browser_shutdown_profile_dumper.cc index c2533a09604cbe..0197093db152c3 100644 --- a/content/browser/browser_shutdown_profile_dumper.cc +++ b/content/browser/browser_shutdown_profile_dumper.cc @@ -29,14 +29,20 @@ BrowserShutdownProfileDumper::~BrowserShutdownProfileDumper() { WriteTracesToDisc(); } +static float GetTraceBufferPercentFull() { + base::debug::TraceLogStatus status = + base::debug::TraceLog::GetInstance()->GetStatus(); + return 100 * static_cast(static_cast(status.event_count) / + status.event_capacity); +} + void BrowserShutdownProfileDumper::WriteTracesToDisc() { // Note: I have seen a usage of 0.000xx% when dumping - which fits easily. // Since the tracer stops when the trace buffer is filled, we'd rather save // what we have than nothing since we might see from the amount of events // that caused the problem. - DVLOG(1) << "Flushing shutdown traces to disc. The buffer is %" << - base::debug::TraceLog::GetInstance()->GetBufferPercentFull() << - " full."; + DVLOG(1) << "Flushing shutdown traces to disc. The buffer is " + << GetTraceBufferPercentFull() << "% full."; DCHECK(!dump_file_); dump_file_ = base::OpenFile(dump_file_name_, "w+"); if (!IsFileValid()) { diff --git a/content/browser/devtools/protocol/tracing_handler.cc b/content/browser/devtools/protocol/tracing_handler.cc index 6e9fa55aa48cce..b86d07b7728799 100644 --- a/content/browser/devtools/protocol/tracing_handler.cc +++ b/content/browser/devtools/protocol/tracing_handler.cc @@ -142,8 +142,9 @@ void TracingHandler::OnRecordingEnabled( client_->SendStartResponse(command, StartResponse::Create()); } -void TracingHandler::OnBufferUsage(float usage) { - client_->BufferUsage(BufferUsageParams::Create()->set_value(usage)); +void TracingHandler::OnBufferUsage(float percent_full, + size_t approximate_event_count) { + client_->BufferUsage(BufferUsageParams::Create()->set_value(percent_full)); } void TracingHandler::OnCategoriesReceived( @@ -189,13 +190,11 @@ void TracingHandler::SetupTimer(double usage_reporting_interval) { base::TimeDelta interval = base::TimeDelta::FromMilliseconds( std::ceil(usage_reporting_interval)); buffer_usage_poll_timer_.reset(new base::Timer( - FROM_HERE, - interval, - base::Bind( - base::IgnoreResult(&TracingController::GetTraceBufferPercentFull), - base::Unretained(TracingController::GetInstance()), - base::Bind(&TracingHandler::OnBufferUsage, - weak_factory_.GetWeakPtr())), + FROM_HERE, interval, + base::Bind(base::IgnoreResult(&TracingController::GetTraceBufferUsage), + base::Unretained(TracingController::GetInstance()), + base::Bind(&TracingHandler::OnBufferUsage, + weak_factory_.GetWeakPtr())), true)); buffer_usage_poll_timer_->Reset(); } diff --git a/content/browser/devtools/protocol/tracing_handler.h b/content/browser/devtools/protocol/tracing_handler.h index b20e5854a3b455..29da1d6f7f7ce9 100644 --- a/content/browser/devtools/protocol/tracing_handler.h +++ b/content/browser/devtools/protocol/tracing_handler.h @@ -49,7 +49,7 @@ class TracingHandler { private: void OnRecordingEnabled(scoped_refptr command); - void OnBufferUsage(float usage); + void OnBufferUsage(float percent_full, size_t approximate_event_count); void OnCategoriesReceived(scoped_refptr command, const std::set& category_set); diff --git a/content/browser/tracing/trace_message_filter.cc b/content/browser/tracing/trace_message_filter.cc index e74ca96caa65dc..96721d2d0c36b2 100644 --- a/content/browser/tracing/trace_message_filter.cc +++ b/content/browser/tracing/trace_message_filter.cc @@ -28,7 +28,7 @@ void TraceMessageFilter::OnChannelClosing() { OnCaptureMonitoringSnapshotAcked(); if (is_awaiting_buffer_percent_full_ack_) - OnTraceBufferPercentFullReply(0.0f); + OnTraceLogStatusReply(base::debug::TraceLogStatus()); TracingControllerImpl::GetInstance()->RemoveTraceMessageFilter(this); } @@ -49,8 +49,8 @@ bool TraceMessageFilter::OnMessageReceived(const IPC::Message& message) { OnMonitoringTraceDataCollected) IPC_MESSAGE_HANDLER(TracingHostMsg_WatchEventMatched, OnWatchEventMatched) - IPC_MESSAGE_HANDLER(TracingHostMsg_TraceBufferPercentFullReply, - OnTraceBufferPercentFullReply) + IPC_MESSAGE_HANDLER(TracingHostMsg_TraceLogStatusReply, + OnTraceLogStatusReply) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() return handled; @@ -93,11 +93,11 @@ void TraceMessageFilter::SendCaptureMonitoringSnapshot() { Send(new TracingMsg_CaptureMonitoringSnapshot); } -void TraceMessageFilter::SendGetTraceBufferPercentFull() { +void TraceMessageFilter::SendGetTraceLogStatus() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(!is_awaiting_buffer_percent_full_ack_); is_awaiting_buffer_percent_full_ack_ = true; - Send(new TracingMsg_GetTraceBufferPercentFull); + Send(new TracingMsg_GetTraceLogStatus); } void TraceMessageFilter::SendSetWatchEvent(const std::string& category_name, @@ -157,11 +157,11 @@ void TraceMessageFilter::OnWatchEventMatched() { TracingControllerImpl::GetInstance()->OnWatchEventMatched(); } -void TraceMessageFilter::OnTraceBufferPercentFullReply(float percent_full) { +void TraceMessageFilter::OnTraceLogStatusReply( + const base::debug::TraceLogStatus& status) { if (is_awaiting_buffer_percent_full_ack_) { is_awaiting_buffer_percent_full_ack_ = false; - TracingControllerImpl::GetInstance()->OnTraceBufferPercentFullReply( - this, percent_full); + TracingControllerImpl::GetInstance()->OnTraceLogStatusReply(this, status); } else { NOTREACHED(); } diff --git a/content/browser/tracing/trace_message_filter.h b/content/browser/tracing/trace_message_filter.h index 3d12d76d300d23..aba87968e99fe8 100644 --- a/content/browser/tracing/trace_message_filter.h +++ b/content/browser/tracing/trace_message_filter.h @@ -31,7 +31,7 @@ class TraceMessageFilter : public BrowserMessageFilter { const base::debug::TraceOptions& options); void SendDisableMonitoring(); void SendCaptureMonitoringSnapshot(); - void SendGetTraceBufferPercentFull(); + void SendGetTraceLogStatus(); void SendSetWatchEvent(const std::string& category_name, const std::string& event_name); void SendCancelWatchEvent(); @@ -45,7 +45,7 @@ class TraceMessageFilter : public BrowserMessageFilter { void OnEndTracingAck(const std::vector& known_categories); void OnCaptureMonitoringSnapshotAcked(); void OnWatchEventMatched(); - void OnTraceBufferPercentFullReply(float percent_full); + void OnTraceLogStatusReply(const base::debug::TraceLogStatus& status); void OnTraceDataCollected(const std::string& data); void OnMonitoringTraceDataCollected(const std::string& data); @@ -56,7 +56,7 @@ class TraceMessageFilter : public BrowserMessageFilter { bool is_awaiting_end_ack_; // Awaiting ack for previously sent SendCaptureMonitoringSnapshot bool is_awaiting_capture_monitoring_snapshot_ack_; - // Awaiting ack for previously sent SendGetTraceBufferPercentFull + // Awaiting ack for previously sent SendGetTraceLogStatus bool is_awaiting_buffer_percent_full_ack_; DISALLOW_COPY_AND_ASSIGN(TraceMessageFilter); diff --git a/content/browser/tracing/tracing_controller_impl.cc b/content/browser/tracing/tracing_controller_impl.cc index 3e8e1ac7cd1c0f..22de3f21037adb 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_log_status_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,35 @@ 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_log_status_ack_count_, acked below. + pending_trace_log_status_ack_count_ = trace_message_filters_.size() + 1; + pending_trace_log_status_filters_ = trace_message_filters_; + maximum_trace_buffer_usage_ = 0; + approximate_event_count_ = 0; - // Call OnTraceBufferPercentFullReply unconditionally for the browser process. + base::debug::TraceLogStatus status = TraceLog::GetInstance()->GetStatus(); + // Call OnTraceLogStatusReply 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(), - TraceLog::GetInstance()->GetBufferPercentFull())); + BrowserThread::PostTask( + BrowserThread::UI, FROM_HERE, + base::Bind(&TracingControllerImpl::OnTraceLogStatusReply, + base::Unretained(this), scoped_refptr(), + status)); // Notify all child processes. for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin(); it != trace_message_filters_.end(); ++it) { - it->get()->SendGetTraceBufferPercentFull(); + it->get()->SendGetTraceLogStatus(); } return true; } @@ -632,15 +634,16 @@ void TracingControllerImpl::RemoveTraceMessageFilter( make_scoped_refptr(trace_message_filter))); } } - if (pending_trace_buffer_percent_full_ack_count_ > 0) { + if (pending_trace_log_status_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_log_status_filters_.find(trace_message_filter); + if (it != pending_trace_log_status_filters_.end()) { + BrowserThread::PostTask( + BrowserThread::UI, FROM_HERE, + base::Bind(&TracingControllerImpl::OnTraceLogStatusReply, base::Unretained(this), make_scoped_refptr(trace_message_filter), - 0)); + base::debug::TraceLogStatus())); } } @@ -815,35 +818,38 @@ void TracingControllerImpl::OnLocalMonitoringTraceDataCollected( OnCaptureMonitoringSnapshotAcked(NULL); } -void TracingControllerImpl::OnTraceBufferPercentFullReply( +void TracingControllerImpl::OnTraceLogStatusReply( TraceMessageFilter* trace_message_filter, - float percent_full) { + const base::debug::TraceLogStatus& status) { if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { - BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, - base::Bind(&TracingControllerImpl::OnTraceBufferPercentFullReply, + BrowserThread::PostTask( + BrowserThread::UI, FROM_HERE, + base::Bind(&TracingControllerImpl::OnTraceLogStatusReply, base::Unretained(this), - make_scoped_refptr(trace_message_filter), - percent_full)); + make_scoped_refptr(trace_message_filter), status)); return; } - if (pending_trace_buffer_percent_full_ack_count_ == 0) + if (pending_trace_log_status_ack_count_ == 0) return; if (trace_message_filter && - !pending_trace_buffer_percent_full_filters_.erase(trace_message_filter)) { + !pending_trace_log_status_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( + static_cast(status.event_count) / status.event_capacity); + maximum_trace_buffer_usage_ = + std::max(maximum_trace_buffer_usage_, percent_full); + approximate_event_count_ += status.event_count; - if (--pending_trace_buffer_percent_full_ack_count_ == 0) { + if (--pending_trace_log_status_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(); } } diff --git a/content/browser/tracing/tracing_controller_impl.h b/content/browser/tracing/tracing_controller_impl.h index 9bd84200d45f27..330b9287466a8f 100644 --- a/content/browser/tracing/tracing_controller_impl.h +++ b/content/browser/tracing/tracing_controller_impl.h @@ -43,8 +43,8 @@ class TracingControllerImpl : public TracingController { base::debug::TraceOptions* out_trace_options) override; bool CaptureMonitoringSnapshot( const scoped_refptr& sink) override; - bool GetTraceBufferPercentFull( - const GetTraceBufferPercentFullCallback& callback) override; + bool GetTraceBufferUsage( + const GetTraceBufferUsageCallback& callback) override; bool SetWatchEvent(const std::string& category_name, const std::string& event_name, const WatchEventCallback& callback) override; @@ -78,8 +78,8 @@ class TracingControllerImpl : public TracingController { return is_monitoring_ && !monitoring_data_sink_.get(); } - bool can_get_trace_buffer_percent_full() const { - return pending_trace_buffer_percent_full_callback_.is_null(); + bool can_get_trace_buffer_usage() const { + return pending_trace_buffer_usage_callback_.is_null(); } bool can_cancel_watch_event() const { @@ -116,9 +116,8 @@ class TracingControllerImpl : public TracingController { void OnCaptureMonitoringSnapshotAcked( TraceMessageFilter* trace_message_filter); - void OnTraceBufferPercentFullReply( - TraceMessageFilter* trace_message_filter, - float percent_full); + void OnTraceLogStatusReply(TraceMessageFilter* trace_message_filter, + const base::debug::TraceLogStatus& status); void OnWatchEventMatched(); @@ -148,10 +147,11 @@ class TracingControllerImpl : public TracingController { // Pending acks for CaptureMonitoringSnapshot. int pending_capture_monitoring_snapshot_ack_count_; TraceMessageFilterSet pending_capture_monitoring_filters_; - // Pending acks for GetTraceBufferPercentFull. - int pending_trace_buffer_percent_full_ack_count_; - TraceMessageFilterSet pending_trace_buffer_percent_full_filters_; - float maximum_trace_buffer_percent_full_; + // Pending acks for GetTraceLogStatus. + int pending_trace_log_status_ack_count_; + TraceMessageFilterSet pending_trace_log_status_filters_; + float maximum_trace_buffer_usage_; + size_t approximate_event_count_; #if defined(OS_CHROMEOS) || defined(OS_WIN) bool is_system_tracing_; @@ -161,7 +161,7 @@ class TracingControllerImpl : public TracingController { base::debug::TraceOptions trace_options_; GetCategoriesDoneCallback pending_get_categories_done_callback_; - GetTraceBufferPercentFullCallback pending_trace_buffer_percent_full_callback_; + GetTraceBufferUsageCallback pending_trace_buffer_usage_callback_; std::string watch_category_name_; std::string watch_event_name_; diff --git a/content/browser/tracing/tracing_ui.cc b/content/browser/tracing/tracing_ui.cc index 95e3ab92cdec6c..bb04de079be1cc 100644 --- a/content/browser/tracing/tracing_ui.cc +++ b/content/browser/tracing/tracing_ui.cc @@ -129,12 +129,28 @@ void OnRecordingEnabledAck(const WebUIDataSource::GotDataCallback& callback) { callback.Run(res); } -void OnTraceBufferPercentFullResult( - const WebUIDataSource::GotDataCallback& callback, float result) { - std::string str = base::DoubleToString(result); +void OnTraceBufferUsageResult(const WebUIDataSource::GotDataCallback& callback, + float percent_full, + size_t approximate_event_count) { + std::string str = base::DoubleToString(percent_full); callback.Run(base::RefCountedString::TakeString(&str)); } +void OnTraceBufferStatusResult(const WebUIDataSource::GotDataCallback& callback, + float percent_full, + size_t approximate_event_count) { + scoped_ptr status(new base::DictionaryValue()); + status->SetDouble("percentFull", percent_full); + status->SetInteger("approximateEventCount", approximate_event_count); + + std::string status_json; + base::JSONWriter::Write(status.get(), &status_json); + + base::RefCountedString* status_base64 = new base::RefCountedString(); + base::Base64Encode(status_json, &status_base64->data()); + callback.Run(status_base64); +} + void OnMonitoringEnabledAck(const WebUIDataSource::GotDataCallback& callback); bool EnableMonitoring(const std::string& data64, @@ -205,8 +221,12 @@ bool OnBeginJSONRequest(const std::string& path, return BeginRecording(data, callback); } if (path == "json/get_buffer_percent_full") { - return TracingController::GetInstance()->GetTraceBufferPercentFull( - base::Bind(OnTraceBufferPercentFullResult, callback)); + return TracingController::GetInstance()->GetTraceBufferUsage( + base::Bind(OnTraceBufferUsageResult, callback)); + } + if (path == "json/get_buffer_status") { + return TracingController::GetInstance()->GetTraceBufferUsage( + base::Bind(OnTraceBufferStatusResult, callback)); } if (path == "json/end_recording") { return TracingController::GetInstance()->DisableRecording( diff --git a/content/public/browser/tracing_controller.h b/content/public/browser/tracing_controller.h index 5b3eb4e4873abf..2ce14c9c4b09b0 100644 --- a/content/public/browser/tracing_controller.h +++ b/content/public/browser/tracing_controller.h @@ -161,11 +161,11 @@ class TracingController { const scoped_refptr& trace_data_sink) = 0; // Get the maximum across processes of trace buffer percent full state. - // When the TraceBufferPercentFull value is determined, the callback is + // When the TraceBufferUsage value is determined, the callback is // called. - typedef base::Callback GetTraceBufferPercentFullCallback; - virtual bool GetTraceBufferPercentFull( - const GetTraceBufferPercentFullCallback& callback) = 0; + typedef base::Callback GetTraceBufferUsageCallback; + virtual bool GetTraceBufferUsage( + const GetTraceBufferUsageCallback& callback) = 0; // |callback| will will be called every time the given event occurs on any // process.