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

Unified Diff: base/debug/trace_event_impl.cc

Issue 67683003: Remove TraceController (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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: base/debug/trace_event_impl.cc
diff --git a/base/debug/trace_event_impl.cc b/base/debug/trace_event_impl.cc
index 9a75ad3db26d39032b6f1147b4877c9406a257d0..ca58710838ff4d47f1544cde6b3aad066b18c8c2 100644
--- a/base/debug/trace_event_impl.cc
+++ b/base/debug/trace_event_impl.cc
@@ -99,11 +99,6 @@ int g_category_index = g_num_builtin_categories; // Skip default categories.
LazyInstance<ThreadLocalPointer<const char> >::Leaky
g_current_thread_name = LAZY_INSTANCE_INITIALIZER;
-const char kRecordUntilFull[] = "record-until-full";
-const char kRecordContinuously[] = "record-continuously";
-const char kEnableSampling[] = "enable-sampling";
-const char kMonitorSampling[] = "monitor-sampling";
-
TimeTicks ThreadNow() {
return TimeTicks::IsThreadNowSupported() ?
TimeTicks::ThreadNow() : TimeTicks();
@@ -944,12 +939,10 @@ class TraceLog::ThreadLocalEventBuffer
ThreadLocalEventBuffer(TraceLog* trace_log);
virtual ~ThreadLocalEventBuffer();
- TraceEvent* AddTraceEvent(NotificationHelper* notifier,
- TraceEventHandle* handle);
+ TraceEvent* AddTraceEvent(TraceEventHandle* handle);
void ReportOverhead(const TimeTicks& event_timestamp,
- const TimeTicks& event_thread_timestamp,
- NotificationHelper* notifier);
+ const TimeTicks& event_thread_timestamp);
TraceEvent* GetEventByHandle(TraceEventHandle handle) {
if (!chunk_ || handle.chunk_seq != chunk_->seq() ||
@@ -1006,12 +999,10 @@ TraceLog::ThreadLocalEventBuffer::~ThreadLocalEventBuffer() {
// - the thread has no message loop;
// - trace_event_overhead is disabled.
if (event_count_) {
- NotificationHelper notifier(trace_log_);
- InitializeMetadataEvent(AddTraceEvent(&notifier, NULL),
+ InitializeMetadataEvent(AddTraceEvent(NULL),
static_cast<int>(base::PlatformThread::CurrentId()),
"overhead", "average_overhead",
overhead_.InMillisecondsF() / event_count_);
- notifier.SendNotificationIfAny();
}
{
@@ -1023,7 +1014,6 @@ TraceLog::ThreadLocalEventBuffer::~ThreadLocalEventBuffer() {
}
TraceEvent* TraceLog::ThreadLocalEventBuffer::AddTraceEvent(
- NotificationHelper* notifier,
TraceEventHandle* handle) {
CheckThisIsCurrentBuffer();
@@ -1035,7 +1025,7 @@ TraceEvent* TraceLog::ThreadLocalEventBuffer::AddTraceEvent(
if (!chunk_) {
AutoLock lock(trace_log_->lock_);
chunk_ = trace_log_->logged_events_->GetChunk(&chunk_index_);
- trace_log_->CheckIfBufferIsFullWhileLocked(notifier);
+ trace_log_->CheckIfBufferIsFullWhileLocked();
}
if (!chunk_)
return NULL;
@@ -1050,8 +1040,7 @@ TraceEvent* TraceLog::ThreadLocalEventBuffer::AddTraceEvent(
void TraceLog::ThreadLocalEventBuffer::ReportOverhead(
const TimeTicks& event_timestamp,
- const TimeTicks& event_thread_timestamp,
- NotificationHelper* notifier) {
+ const TimeTicks& event_thread_timestamp) {
if (!g_category_group_enabled[g_category_trace_event_overhead])
return;
@@ -1061,7 +1050,7 @@ void TraceLog::ThreadLocalEventBuffer::ReportOverhead(
TimeTicks now = trace_log_->OffsetNow();
TimeDelta overhead = now - event_timestamp;
if (overhead.InMicroseconds() >= kOverheadReportThresholdInMicroseconds) {
- TraceEvent* trace_event = AddTraceEvent(notifier, NULL);
+ TraceEvent* trace_event = AddTraceEvent(NULL);
if (trace_event) {
trace_event->Initialize(
static_cast<int>(PlatformThread::CurrentId()),
@@ -1092,66 +1081,14 @@ void TraceLog::ThreadLocalEventBuffer::FlushWhileLocked() {
// find the generation mismatch and delete this buffer soon.
}
-TraceLog::NotificationHelper::NotificationHelper(TraceLog* trace_log)
- : trace_log_(trace_log),
- notification_(0) {
-}
-
-TraceLog::NotificationHelper::~NotificationHelper() {
-}
-
-void TraceLog::NotificationHelper::AddNotificationWhileLocked(
- int notification) {
- trace_log_->lock_.AssertAcquired();
- if (trace_log_->notification_callback_.is_null())
- return;
- if (notification_ == 0)
- callback_copy_ = trace_log_->notification_callback_;
- notification_ |= notification;
-}
-
-void TraceLog::NotificationHelper::SendNotificationIfAny() {
- if (notification_)
- callback_copy_.Run(notification_);
-}
-
// static
TraceLog* TraceLog::GetInstance() {
return Singleton<TraceLog, LeakySingletonTraits<TraceLog> >::get();
}
-// static
-// Note, if you add more options here you also need to update:
-// content/browser/devtools/devtools_tracing_handler:TraceOptionsFromString
-TraceLog::Options TraceLog::TraceOptionsFromString(const std::string& options) {
- std::vector<std::string> split;
- base::SplitString(options, ',', &split);
- int ret = 0;
- for (std::vector<std::string>::iterator iter = split.begin();
- iter != split.end();
- ++iter) {
- if (*iter == kRecordUntilFull) {
- ret |= RECORD_UNTIL_FULL;
- } else if (*iter == kRecordContinuously) {
- ret |= RECORD_CONTINUOUSLY;
- } else if (*iter == kEnableSampling) {
- ret |= ENABLE_SAMPLING;
- } else if (*iter == kMonitorSampling) {
- ret |= MONITOR_SAMPLING;
- } else {
- NOTREACHED(); // Unknown option provided.
- }
- }
- if (!(ret & RECORD_UNTIL_FULL) && !(ret & RECORD_CONTINUOUSLY))
- ret |= RECORD_UNTIL_FULL; // Default when no options are specified.
-
- return static_cast<Options>(ret);
-}
-
TraceLog::TraceLog()
: enable_count_(0),
num_traces_recorded_(0),
- buffer_is_full_(0),
event_callback_(0),
dispatching_to_observer_list_(false),
process_sort_index_(0),
@@ -1314,7 +1251,6 @@ void TraceLog::SetEnabled(const CategoryFilter& category_filter,
subtle::NoBarrier_Store(&trace_options_, options);
logged_events_.reset(CreateTraceBuffer());
NextGeneration();
- subtle::NoBarrier_Store(&buffer_is_full_, 0);
}
if (dispatching_to_observer_list_) {
@@ -1442,14 +1378,14 @@ bool TraceLog::HasEnabledStateObserver(EnabledStateObserver* listener) const {
}
float TraceLog::GetBufferPercentFull() const {
+ AutoLock lock(lock_);
return static_cast<float>(static_cast<double>(logged_events_->Size()) /
logged_events_->Capacity());
}
-void TraceLog::SetNotificationCallback(
- const TraceLog::NotificationCallback& cb) {
+bool TraceLog::BufferIsFull() const {
AutoLock lock(lock_);
- notification_callback_ = cb;
+ return logged_events_->IsFull();
}
TraceBuffer* TraceLog::CreateTraceBuffer() {
@@ -1464,7 +1400,7 @@ TraceBuffer* TraceLog::CreateTraceBuffer() {
}
TraceEvent* TraceLog::AddEventToThreadSharedChunkWhileLocked(
- NotificationHelper* notifier, TraceEventHandle* handle) {
+ TraceEventHandle* handle) {
lock_.AssertAcquired();
if (thread_shared_chunk_ && thread_shared_chunk_->IsFull()) {
@@ -1475,8 +1411,7 @@ TraceEvent* TraceLog::AddEventToThreadSharedChunkWhileLocked(
if (!thread_shared_chunk_) {
thread_shared_chunk_ = logged_events_->GetChunk(
&thread_shared_chunk_index_);
- if (notifier)
- CheckIfBufferIsFullWhileLocked(notifier);
+ CheckIfBufferIsFullWhileLocked();
}
if (!thread_shared_chunk_)
return NULL;
@@ -1490,13 +1425,10 @@ TraceEvent* TraceLog::AddEventToThreadSharedChunkWhileLocked(
return trace_event;
}
-void TraceLog::CheckIfBufferIsFullWhileLocked(NotificationHelper* notifier) {
+void TraceLog::CheckIfBufferIsFullWhileLocked() {
lock_.AssertAcquired();
- if (!subtle::NoBarrier_Load(&buffer_is_full_) && logged_events_->IsFull()) {
- subtle::NoBarrier_Store(&buffer_is_full_,
- static_cast<subtle::AtomicWord>(1));
- notifier->AddNotificationWhileLocked(TRACE_BUFFER_FULL);
- }
+ if (logged_events_->IsFull())
+ SetDisabled();
}
void TraceLog::SetEventCallback(EventCallback cb) {
@@ -1603,7 +1535,6 @@ void TraceLog::FinishFlush(int generation) {
previous_logged_events.swap(logged_events_);
logged_events_.reset(CreateTraceBuffer());
NextGeneration();
- subtle::NoBarrier_Store(&buffer_is_full_, 0);
thread_message_loops_.clear();
flush_message_loop_proxy_ = NULL;
@@ -1726,8 +1657,6 @@ TraceEventHandle TraceLog::AddTraceEventWithThreadIdAndTimestamp(
TimeTicks now = OffsetTimestamp(timestamp);
TimeTicks thread_now = ThreadNow();
- NotificationHelper notifier(this);
-
ThreadLocalEventBuffer* thread_local_event_buffer = NULL;
// A ThreadLocalEventBuffer needs the message loop
// - to know when the thread exits;
@@ -1784,26 +1713,23 @@ TraceEventHandle TraceLog::AddTraceEventWithThreadIdAndTimestamp(
}
TraceEvent* trace_event = NULL;
- if (!subtle::NoBarrier_Load(&buffer_is_full_)) {
- if (thread_local_event_buffer) {
- lock.EnsureReleased();
- trace_event = thread_local_event_buffer->AddTraceEvent(&notifier,
- &handle);
- } else {
- lock.EnsureAcquired();
- trace_event = AddEventToThreadSharedChunkWhileLocked(&notifier, &handle);
- }
+ if (thread_local_event_buffer) {
+ lock.EnsureReleased();
+ trace_event = thread_local_event_buffer->AddTraceEvent(&handle);
+ } else {
+ lock.EnsureAcquired();
+ trace_event = AddEventToThreadSharedChunkWhileLocked(&handle);
+ }
- if (trace_event) {
- trace_event->Initialize(thread_id, now, thread_now, phase,
- category_group_enabled, name, id,
- num_args, arg_names, arg_types, arg_values,
- convertable_values, flags);
+ if (trace_event) {
+ trace_event->Initialize(thread_id, now, thread_now, phase,
+ category_group_enabled, name, id,
+ num_args, arg_names, arg_types, arg_values,
+ convertable_values, flags);
#if defined(OS_ANDROID)
- trace_event->SendToATrace();
+ trace_event->SendToATrace();
#endif
- }
}
if (trace_options() & ECHO_TO_CONSOLE) {
@@ -1816,8 +1742,12 @@ TraceEventHandle TraceLog::AddTraceEventWithThreadIdAndTimestamp(
if (reinterpret_cast<const unsigned char*>(subtle::NoBarrier_Load(
&watch_category_)) == category_group_enabled) {
lock.EnsureAcquired();
- if (watch_event_name_ == name)
- notifier.AddNotificationWhileLocked(EVENT_WATCH_NOTIFICATION);
+ if (watch_event_name_ == name) {
+ WatchEventCallback watch_event_callback_copy = watch_event_callback_;
+ lock.EnsureReleased();
+ if (!watch_event_callback_copy.is_null())
+ watch_event_callback_copy.Run();
+ }
}
lock.EnsureReleased();
@@ -1835,9 +1765,7 @@ TraceEventHandle TraceLog::AddTraceEventWithThreadIdAndTimestamp(
}
if (thread_local_event_buffer)
- thread_local_event_buffer->ReportOverhead(now, thread_now, &notifier);
-
- notifier.SendNotificationIfAny();
+ thread_local_event_buffer->ReportOverhead(now, thread_now);
return handle;
}
@@ -1947,19 +1875,22 @@ void TraceLog::UpdateTraceEventDuration(TraceEventHandle handle) {
}
void TraceLog::SetWatchEvent(const std::string& category_name,
- const std::string& event_name) {
+ const std::string& event_name,
+ const WatchEventCallback& callback) {
const unsigned char* category = GetCategoryGroupEnabled(
category_name.c_str());
AutoLock lock(lock_);
subtle::NoBarrier_Store(&watch_category_,
reinterpret_cast<subtle::AtomicWord>(category));
watch_event_name_ = event_name;
+ watch_event_callback_ = callback;
}
void TraceLog::CancelWatchEvent() {
AutoLock lock(lock_);
subtle::NoBarrier_Store(&watch_category_, 0);
watch_event_name_ = "";
+ watch_event_callback_.Reset();
}
void TraceLog::AddMetadataEventsWhileLocked() {
@@ -1967,14 +1898,14 @@ void TraceLog::AddMetadataEventsWhileLocked() {
int current_thread_id = static_cast<int>(base::PlatformThread::CurrentId());
if (process_sort_index_ != 0) {
- InitializeMetadataEvent(AddEventToThreadSharedChunkWhileLocked(NULL, NULL),
+ InitializeMetadataEvent(AddEventToThreadSharedChunkWhileLocked(NULL),
current_thread_id,
"process_sort_index", "sort_index",
process_sort_index_);
}
if (process_name_.size()) {
- InitializeMetadataEvent(AddEventToThreadSharedChunkWhileLocked(NULL, NULL),
+ InitializeMetadataEvent(AddEventToThreadSharedChunkWhileLocked(NULL),
current_thread_id,
"process_name", "name",
process_name_);
@@ -1987,7 +1918,7 @@ void TraceLog::AddMetadataEventsWhileLocked() {
it++) {
labels.push_back(it->second);
}
- InitializeMetadataEvent(AddEventToThreadSharedChunkWhileLocked(NULL, NULL),
+ InitializeMetadataEvent(AddEventToThreadSharedChunkWhileLocked(NULL),
current_thread_id,
"process_labels", "labels",
JoinString(labels, ','));
@@ -1999,7 +1930,7 @@ void TraceLog::AddMetadataEventsWhileLocked() {
it++) {
if (it->second == 0)
continue;
- InitializeMetadataEvent(AddEventToThreadSharedChunkWhileLocked(NULL, NULL),
+ InitializeMetadataEvent(AddEventToThreadSharedChunkWhileLocked(NULL),
it->first,
"thread_sort_index", "sort_index",
it->second);
@@ -2011,7 +1942,7 @@ void TraceLog::AddMetadataEventsWhileLocked() {
it++) {
if (it->second.empty())
continue;
- InitializeMetadataEvent(AddEventToThreadSharedChunkWhileLocked(NULL, NULL),
+ InitializeMetadataEvent(AddEventToThreadSharedChunkWhileLocked(NULL),
it->first,
"thread_name", "name",
it->second);

Powered by Google App Engine
This is Rietveld 408576698