diff options
Diffstat (limited to 'base/debug/trace_event_impl.cc')
-rw-r--r-- | base/debug/trace_event_impl.cc | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/base/debug/trace_event_impl.cc b/base/debug/trace_event_impl.cc index e774f62..03a4ae3 100644 --- a/base/debug/trace_event_impl.cc +++ b/base/debug/trace_event_impl.cc @@ -1094,7 +1094,7 @@ void TraceLog::ThreadLocalEventBuffer::FlushWhileLocked() { trace_log_->lock_.AssertAcquired(); if (trace_log_->CheckGeneration(generation_)) { - // Return the chunk to the buffer only if the generation matches, + // Return the chunk to the buffer only if the generation matches. trace_log_->logged_events_->ReturnChunk(chunk_index_, chunk_.Pass()); } // Otherwise this method may be called from the destructor, or TraceLog will @@ -1107,7 +1107,7 @@ TraceLog* TraceLog::GetInstance() { } TraceLog::TraceLog() - : enabled_(false), + : mode_(DISABLED), num_traces_recorded_(0), event_callback_(0), dispatching_to_observer_list_(false), @@ -1153,7 +1153,7 @@ TraceLog::TraceLog() LOG(ERROR) << "Start " << switches::kTraceToConsole << " with CategoryFilter '" << filter << "'."; - SetEnabled(CategoryFilter(filter), ECHO_TO_CONSOLE); + SetEnabled(CategoryFilter(filter), RECORDING_MODE, ECHO_TO_CONSOLE); } #endif @@ -1192,8 +1192,12 @@ const char* TraceLog::GetCategoryGroupName( void TraceLog::UpdateCategoryGroupEnabledFlag(int category_index) { unsigned char enabled_flag = 0; const char* category_group = g_category_groups[category_index]; - if (enabled_ && category_filter_.IsCategoryGroupEnabled(category_group)) + if (mode_ == RECORDING_MODE && + category_filter_.IsCategoryGroupEnabled(category_group)) enabled_flag |= ENABLED_FOR_RECORDING; + else if (mode_ == MONITORING_MODE && + category_filter_.IsCategoryGroupEnabled(category_group)) + enabled_flag |= ENABLED_FOR_MONITORING; if (event_callback_ && event_callback_category_filter_.IsCategoryGroupEnabled(category_group)) enabled_flag |= ENABLED_FOR_EVENT_CALLBACK; @@ -1256,6 +1260,7 @@ void TraceLog::GetKnownCategoryGroups( } void TraceLog::SetEnabled(const CategoryFilter& category_filter, + Mode mode, Options options) { std::vector<EnabledStateObserver*> observer_list; { @@ -1266,12 +1271,16 @@ void TraceLog::SetEnabled(const CategoryFilter& category_filter, Options old_options = trace_options(); - if (enabled_) { + if (IsEnabled()) { if (options != old_options) { DLOG(ERROR) << "Attemting to re-enable tracing with a different " << "set of options."; } + if (mode != mode_) { + DLOG(ERROR) << "Attemting to re-enable tracing with a different mode."; + } + category_filter_.Merge(category_filter); UpdateCategoryGroupEnabledFlags(); return; @@ -1283,7 +1292,7 @@ void TraceLog::SetEnabled(const CategoryFilter& category_filter, return; } - enabled_ = true; + mode_ = mode; if (options != old_options) { subtle::NoBarrier_Store(&trace_options_, options); @@ -1295,7 +1304,7 @@ void TraceLog::SetEnabled(const CategoryFilter& category_filter, category_filter_ = CategoryFilter(category_filter); UpdateCategoryGroupEnabledFlags(); - if ((options & ENABLE_SAMPLING) || (options & MONITOR_SAMPLING)) { + if (options & ENABLE_SAMPLING) { sampling_thread_.reset(new TraceSamplingThread); sampling_thread_->RegisterSampleBucket( &g_trace_state[0], @@ -1341,7 +1350,7 @@ void TraceLog::SetDisabled() { void TraceLog::SetDisabledWhileLocked() { lock_.AssertAcquired(); - if (!enabled_) + if (!IsEnabled()) return; if (dispatching_to_observer_list_) { @@ -1350,9 +1359,11 @@ void TraceLog::SetDisabledWhileLocked() { return; } - enabled_ = false; + mode_ = DISABLED; if (sampling_thread_.get()) { + base::ThreadRestrictions::SetIOAllowed(true); + // Stop the sampling thread. sampling_thread_->Stop(); lock_.Release(); @@ -1360,6 +1371,8 @@ void TraceLog::SetDisabledWhileLocked() { lock_.Acquire(); sampling_thread_handle_ = PlatformThreadHandle(); sampling_thread_.reset(); + + base::ThreadRestrictions::SetIOAllowed(false); } category_filter_.Clear(); @@ -1384,7 +1397,7 @@ void TraceLog::SetDisabledWhileLocked() { int TraceLog::GetNumTracesRecorded() { AutoLock lock(lock_); - if (!enabled_) + if (!IsEnabled()) return -1; return num_traces_recorded_; } @@ -1425,7 +1438,7 @@ TraceBuffer* TraceLog::CreateTraceBuffer() { Options options = trace_options(); if (options & RECORD_CONTINUOUSLY) return new TraceBufferRingBuffer(kTraceEventRingBufferChunks); - else if (options & MONITOR_SAMPLING) + else if ((options & ENABLE_SAMPLING) && mode_ == MONITORING_MODE) return new TraceBufferRingBuffer(kMonitorTraceEventBufferChunks); else if (options & ECHO_TO_CONSOLE) return new TraceBufferRingBuffer(kEchoToConsoleTraceEventBufferChunks); @@ -1769,7 +1782,8 @@ TraceEventHandle TraceLog::AddTraceEventWithThreadIdAndTimestamp( } std::string console_message; - if ((*category_group_enabled & ENABLED_FOR_RECORDING)) { + if (*category_group_enabled & + (ENABLED_FOR_RECORDING | ENABLED_FOR_MONITORING)) { OptionalAutoLock lock(lock_); TraceEvent* trace_event = NULL; |