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

Unified Diff: base/trace_event/trace_log.cc

Issue 2415183004: Revert of [tracing] Add filtering mode in TraceLog (Closed)
Patch Set: Created 4 years, 2 months 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
« no previous file with comments | « base/trace_event/trace_log.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/trace_event/trace_log.cc
diff --git a/base/trace_event/trace_log.cc b/base/trace_event/trace_log.cc
index a3d146ad51451be1fd15c4d1295f66eb325b383f..c56f5c7894cc9df80a22ff10d0b51870e4af10fc 100644
--- a/base/trace_event/trace_log.cc
+++ b/base/trace_event/trace_log.cc
@@ -462,7 +462,7 @@
}
TraceLog::TraceLog()
- : enabled_modes_(0),
+ : mode_(DISABLED),
num_traces_recorded_(0),
event_callback_(0),
dispatching_to_observer_list_(false),
@@ -560,7 +560,7 @@
void TraceLog::UpdateCategoryGroupEnabledFlag(size_t category_index) {
unsigned char enabled_flag = 0;
const char* category_group = g_category_groups[category_index];
- if (enabled_modes_ & RECORDING_MODE &&
+ if (mode_ == RECORDING_MODE &&
trace_config_.IsCategoryGroupEnabled(category_group)) {
enabled_flag |= ENABLED_FOR_RECORDING;
}
@@ -580,12 +580,12 @@
// TODO(primiano): this is a temporary workaround for catapult:#2341,
// to guarantee that metadata events are always added even if the category
// filter is "-*". See crbug.com/618054 for more details and long-term fix.
- if (enabled_modes_ & RECORDING_MODE && !strcmp(category_group, "__metadata"))
+ if (mode_ == RECORDING_MODE && !strcmp(category_group, "__metadata"))
enabled_flag |= ENABLED_FOR_RECORDING;
uint32_t enabled_filters_bitmap = 0;
int index = 0;
- for (const auto& event_filter : enabled_event_filters_) {
+ for (const auto& event_filter : trace_config_.event_filters()) {
if (event_filter.IsCategoryGroupEnabled(category_group)) {
enabled_flag |= ENABLED_FOR_FILTERING;
DCHECK(g_category_group_filters.Get()[index]);
@@ -609,15 +609,12 @@
}
void TraceLog::CreateFiltersForTraceConfig() {
- if (!(enabled_modes_ & FILTERING_MODE))
- return;
-
// Filters were already added and tracing could be enabled. Filters list
// cannot be changed when trace events are using them.
if (g_category_group_filters.Get().size())
return;
- for (auto& event_filter : enabled_event_filters_) {
+ for (auto& event_filter : trace_config_.event_filters()) {
if (g_category_group_filters.Get().size() >= MAX_TRACE_EVENT_FILTERS) {
NOTREACHED()
<< "Too many trace event filters installed in the current session";
@@ -730,8 +727,7 @@
category_groups->push_back(g_category_groups[i]);
}
-void TraceLog::SetEnabled(const TraceConfig& trace_config,
- uint8_t modes_to_enable) {
+void TraceLog::SetEnabled(const TraceConfig& trace_config, Mode mode) {
std::vector<EnabledStateObserver*> observer_list;
std::map<AsyncEnabledStateObserver*, RegisteredAsyncObserver> observer_map;
{
@@ -745,65 +741,46 @@
InternalTraceOptions old_options = trace_options();
+ if (IsEnabled()) {
+ if (new_options != old_options) {
+ DLOG(ERROR) << "Attempting to re-enable tracing with a different "
+ << "set of options.";
+ }
+
+ if (mode != mode_) {
+ DLOG(ERROR) << "Attempting to re-enable tracing with a different mode.";
+ }
+
+ DCHECK(!trace_config.event_filters().size())
+ << "Adding new filters while tracing was already enabled is not "
+ "supported.";
+
+ trace_config_.Merge(trace_config);
+ UpdateCategoryGroupEnabledFlags();
+ return;
+ }
+
if (dispatching_to_observer_list_) {
- NOTREACHED()
+ DLOG(ERROR)
<< "Cannot manipulate TraceLog::Enabled state from an observer.";
return;
}
+
+ mode_ = mode;
+
+ if (new_options != old_options) {
+ subtle::NoBarrier_Store(&trace_options_, new_options);
+ UseNextTraceBuffer();
+ }
+
+ num_traces_recorded_++;
// Clear all filters from previous tracing session. These filters are not
// cleared at the end of tracing because some threads which hit trace event
// when disabling, could try to use the filters.
- if (!enabled_modes_)
- g_category_group_filters.Get().clear();
-
- // Update trace config for recording.
- const bool already_recording = enabled_modes_ & RECORDING_MODE;
- if (modes_to_enable & RECORDING_MODE) {
- if (already_recording) {
- // TODO(ssid): Stop suporting enabling of RECODING_MODE when already
- // enabled crbug.com/625170.
- DCHECK_EQ(new_options, old_options) << "Attempting to re-enable "
- "tracing with a different set "
- "of options.";
- trace_config_.Merge(trace_config);
- } else {
- trace_config_ = trace_config;
- }
- }
-
- // Update event filters.
- if (modes_to_enable & FILTERING_MODE) {
- DCHECK(!trace_config.event_filters().empty())
- << "Attempting to enable filtering without any filters";
- DCHECK(enabled_event_filters_.empty()) << "Attempting to re-enable "
- "filtering when filters are "
- "already enabled.";
-
- // Use the given event filters only if filtering was not enabled.
- if (enabled_event_filters_.empty())
- enabled_event_filters_ = trace_config.event_filters();
- }
- // Keep the |trace_config_| updated with only enabled filters in case anyone
- // tries to read it using |GetCurrentTraceConfig| (even if filters are
- // empty).
- trace_config_.SetEventFilters(enabled_event_filters_);
-
- enabled_modes_ |= modes_to_enable;
- UpdateCategoryGroupEnabledFlags();
-
- // Do not notify observers or create trace buffer if only enabled for
- // filtering or if recording was already enabled.
- if (!(modes_to_enable & RECORDING_MODE) || already_recording)
- return;
-
- if (new_options != old_options) {
- subtle::NoBarrier_Store(&trace_options_, new_options);
- UseNextTraceBuffer();
- }
-
- num_traces_recorded_++;
-
+ g_category_group_filters.Get().clear();
+
+ trace_config_ = TraceConfig(trace_config);
UpdateCategoryGroupEnabledFlags();
UpdateSyntheticDelaysFromTraceConfig();
@@ -860,47 +837,27 @@
void TraceLog::SetDisabled() {
AutoLock lock(lock_);
- SetDisabledWhileLocked(RECORDING_MODE);
-}
-
-void TraceLog::SetDisabled(uint8_t modes_to_disable) {
- AutoLock lock(lock_);
- SetDisabledWhileLocked(modes_to_disable);
-}
-
-void TraceLog::SetDisabledWhileLocked(uint8_t modes_to_disable) {
+ SetDisabledWhileLocked();
+}
+
+void TraceLog::SetDisabledWhileLocked() {
lock_.AssertAcquired();
- if (!(enabled_modes_ & modes_to_disable))
+ if (!IsEnabled())
return;
if (dispatching_to_observer_list_) {
- NOTREACHED()
+ DLOG(ERROR)
<< "Cannot manipulate TraceLog::Enabled state from an observer.";
return;
}
- bool is_recording_mode_disabled =
- (enabled_modes_ & RECORDING_MODE) && (modes_to_disable & RECORDING_MODE);
- enabled_modes_ &= ~modes_to_disable;
-
- if (modes_to_disable & FILTERING_MODE)
- enabled_event_filters_.clear();
-
- if (modes_to_disable & RECORDING_MODE) {
- trace_config_.Clear();
-
- subtle::NoBarrier_Store(&watch_category_, 0);
- watch_event_name_.clear();
- }
-
+ mode_ = DISABLED;
+
+ trace_config_.Clear();
+ subtle::NoBarrier_Store(&watch_category_, 0);
+ watch_event_name_.clear();
UpdateCategoryGroupEnabledFlags();
-
- // Add metadata events and notify observers only if recording mode was
- // disabled now.
- if (!is_recording_mode_disabled)
- return;
-
AddMetadataEventsWhileLocked();
// Remove metadata events so they will not get added to a subsequent trace.
@@ -1000,7 +957,7 @@
if (buffer_limit_reached_timestamp_.is_null()) {
buffer_limit_reached_timestamp_ = OffsetNow();
}
- SetDisabledWhileLocked(RECORDING_MODE);
+ SetDisabledWhileLocked();
}
}
@@ -1387,13 +1344,10 @@
TimeTicks offset_event_timestamp = OffsetTimestamp(timestamp);
ThreadTicks thread_now = ThreadNow();
- ThreadLocalEventBuffer* thread_local_event_buffer = nullptr;
- if (enabled_modes_ & RECORDING_MODE) {
- // |thread_local_event_buffer_| can be null if the current thread doesn't
- // have a message loop or the message loop is blocked.
- InitializeThreadLocalEventBufferIfSupported();
- thread_local_event_buffer = thread_local_event_buffer_.Get();
- }
+ // |thread_local_event_buffer_| can be null if the current thread doesn't have
+ // a message loop or the message loop is blocked.
+ InitializeThreadLocalEventBufferIfSupported();
+ auto* thread_local_event_buffer = thread_local_event_buffer_.Get();
// Check and update the current thread name only if the event is for the
// current thread to avoid locks in most cases.
« no previous file with comments | « base/trace_event/trace_log.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698