diff options
author | haraken@chromium.org <haraken@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-28 06:04:28 +0000 |
---|---|---|
committer | haraken@chromium.org <haraken@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-28 06:04:28 +0000 |
commit | 462ceb0a79acbd01421795bf2391643ca6d73f78 (patch) | |
tree | 5524511c651043c49986d3b5669b7d9305cc6c98 /base/debug | |
parent | f5f22386b9413ce39b7e3cc7e718f652969f01e2 (diff) | |
download | chromium_src-462ceb0a79acbd01421795bf2391643ca6d73f78.zip chromium_src-462ceb0a79acbd01421795bf2391643ca6d73f78.tar.gz chromium_src-462ceb0a79acbd01421795bf2391643ca6d73f78.tar.bz2 |
Implement sampling profiler (chromium side change)
Trace-viewer side change is here: https://codereview.appspot.com/39310043
Screenshot of the profiler: http://haraken.info/null/sampling_tracing.png
Design document: https://docs.google.com/a/google.com/document/d/1j39sbA9ECTwFFlxbhSD1EvJnGfYeS5EUJ05yxuku6VY/edit
TBR=phajdan.jr
NOTRY=true
Review URL: https://codereview.chromium.org/109933006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@242671 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/debug')
-rw-r--r-- | base/debug/trace_event.h | 14 | ||||
-rw-r--r-- | base/debug/trace_event_android.cc | 1 | ||||
-rw-r--r-- | base/debug/trace_event_impl.cc | 38 | ||||
-rw-r--r-- | base/debug/trace_event_impl.h | 31 | ||||
-rw-r--r-- | base/debug/trace_event_unittest.cc | 92 |
5 files changed, 127 insertions, 49 deletions
diff --git a/base/debug/trace_event.h b/base/debug/trace_event.h index 18feb33..b753963 100644 --- a/base/debug/trace_event.h +++ b/base/debug/trace_event.h @@ -725,12 +725,16 @@ INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_DELETE_OBJECT, \ category_group, name, TRACE_ID_DONT_MANGLE(id), TRACE_EVENT_FLAG_NONE) +#define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE() \ + *INTERNAL_TRACE_EVENT_UID(category_group_enabled) & \ + (base::debug::TraceLog::ENABLED_FOR_RECORDING | \ + base::debug::TraceLog::ENABLED_FOR_EVENT_CALLBACK) // Macro to efficiently determine if a given category group is enabled. #define TRACE_EVENT_CATEGORY_GROUP_ENABLED(category_group, ret) \ do { \ INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ - if (*INTERNAL_TRACE_EVENT_UID(category_group_enabled)) { \ + if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ *ret = true; \ } else { \ *ret = false; \ @@ -870,7 +874,7 @@ TRACE_EVENT_API_CLASS_EXPORT extern \ #define INTERNAL_TRACE_EVENT_ADD(phase, category_group, name, flags, ...) \ do { \ INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ - if (*INTERNAL_TRACE_EVENT_UID(category_group_enabled)) { \ + if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ trace_event_internal::AddTraceEvent( \ phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ trace_event_internal::kNoEventId, flags, ##__VA_ARGS__); \ @@ -883,7 +887,7 @@ TRACE_EVENT_API_CLASS_EXPORT extern \ #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, ...) \ INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ trace_event_internal::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \ - if (*INTERNAL_TRACE_EVENT_UID(category_group_enabled)) { \ + if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ base::debug::TraceEventHandle h = trace_event_internal::AddTraceEvent( \ TRACE_EVENT_PHASE_COMPLETE, \ INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ @@ -899,7 +903,7 @@ TRACE_EVENT_API_CLASS_EXPORT extern \ flags, ...) \ do { \ INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ - if (*INTERNAL_TRACE_EVENT_UID(category_group_enabled)) { \ + if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ unsigned char trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ trace_event_internal::TraceID trace_event_trace_id( \ id, &trace_event_flags); \ @@ -916,7 +920,7 @@ TRACE_EVENT_API_CLASS_EXPORT extern \ category_group, name, id, thread_id, timestamp, flags, ...) \ do { \ INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ - if (*INTERNAL_TRACE_EVENT_UID(category_group_enabled)) { \ + if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ unsigned char trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ trace_event_internal::TraceID trace_event_trace_id( \ id, &trace_event_flags); \ diff --git a/base/debug/trace_event_android.cc b/base/debug/trace_event_android.cc index 567c48e..ed6b20d 100644 --- a/base/debug/trace_event_android.cc +++ b/base/debug/trace_event_android.cc @@ -97,6 +97,7 @@ void TraceLog::StartATrace() { return; } SetEnabled(CategoryFilter(CategoryFilter::kDefaultCategoryFilterString), + base::debug::TraceLog::RECORDING_MODE, RECORD_CONTINUOUSLY); } 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; diff --git a/base/debug/trace_event_impl.h b/base/debug/trace_event_impl.h index 6179480..7dd4a00 100644 --- a/base/debug/trace_event_impl.h +++ b/base/debug/trace_event_impl.h @@ -354,6 +354,12 @@ class TraceSamplingThread; class BASE_EXPORT TraceLog { public: + enum Mode { + DISABLED = 0, + RECORDING_MODE, + MONITORING_MODE, + }; + // Options determines how the trace buffer stores data. enum Options { // Record until the trace buffer is full. @@ -366,21 +372,21 @@ class BASE_EXPORT TraceLog { // Enable the sampling profiler in the recording mode. ENABLE_SAMPLING = 1 << 2, - // Enable the sampling profiler in the monitoring mode. - MONITOR_SAMPLING = 1 << 3, - // Echo to console. Events are discarded. - ECHO_TO_CONSOLE = 1 << 4, + ECHO_TO_CONSOLE = 1 << 3, }; // The pointer returned from GetCategoryGroupEnabledInternal() points to a // value with zero or more of the following bits. Used in this class only. // The TRACE_EVENT macros should only use the value as a bool. + // These values must be in sync with macro values in TraceEvent.h in Blink. enum CategoryGroupEnabledFlags { - // Normal enabled flag for category groups enabled by SetEnabled(). + // Category group enabled for the recording mode. ENABLED_FOR_RECORDING = 1 << 0, + // Category group enabled for the monitoring mode. + ENABLED_FOR_MONITORING = 1 << 1, // Category group enabled by SetEventCallbackEnabled(). - ENABLED_FOR_EVENT_CALLBACK = 1 << 1, + ENABLED_FOR_EVENT_CALLBACK = 1 << 2, }; static TraceLog* GetInstance(); @@ -400,12 +406,13 @@ class BASE_EXPORT TraceLog { // See CategoryFilter comments for details on how to control what categories // will be traced. If tracing has already been enabled, |category_filter| will // be merged into the current category filter. - void SetEnabled(const CategoryFilter& category_filter, Options options); + void SetEnabled(const CategoryFilter& category_filter, + Mode mode, Options options); // Disables normal tracing for all categories. void SetDisabled(); - bool IsEnabled() { return enabled_; } + bool IsEnabled() { return mode_ != DISABLED; } // The number of times we have begun recording traces. If tracing is off, // returns -1. If tracing is on, then it returns the number of times we have @@ -426,7 +433,7 @@ class BASE_EXPORT TraceLog { class EnabledStateObserver { public: // Called just after the tracing system becomes enabled, outside of the - // |lock_|. TraceLog::IsEnabled() is true at this point. + // |lock_|. TraceLog::IsEnabled() is true at this point. virtual void OnTraceLogEnabled() = 0; // Called just after the tracing system disables, outside of the |lock_|. @@ -591,9 +598,9 @@ class BASE_EXPORT TraceLog { // by the Singleton class. friend struct DefaultSingletonTraits<TraceLog>; - // Enable/disable each category group based on the current enabled_, + // Enable/disable each category group based on the current mode_, // category_filter_, event_callback_ and event_callback_category_filter_. - // Enable the category group if enabled_ is true and category_filter_ matches + // Enable the category group in the enabled mode if category_filter_ matches // the category group, or event_callback_ is not null and // event_callback_category_filter_ matches the category group. void UpdateCategoryGroupEnabledFlags(); @@ -652,7 +659,7 @@ class BASE_EXPORT TraceLog { // and thread_colors_. Lock thread_info_lock_; int locked_line_; - bool enabled_; + Mode mode_; int num_traces_recorded_; scoped_ptr<TraceBuffer> logged_events_; subtle::AtomicWord /* EventCallback */ event_callback_; diff --git a/base/debug/trace_event_unittest.cc b/base/debug/trace_event_unittest.cc index aef2c43..d71b242 100644 --- a/base/debug/trace_event_unittest.cc +++ b/base/debug/trace_event_unittest.cc @@ -78,6 +78,7 @@ class TraceEventTestFixture : public testing::Test { void BeginSpecificTrace(const std::string& filter) { event_watch_notification_ = 0; TraceLog::GetInstance()->SetEnabled(CategoryFilter(filter), + base::debug::TraceLog::RECORDING_MODE, TraceLog::RECORD_UNTIL_FULL); } @@ -853,6 +854,7 @@ void HighResSleepForTraceTest(base::TimeDelta elapsed) { // Simple Test for emitting data and validating it was received. TEST_F(TraceEventTestFixture, DataCaptured) { TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"), + base::debug::TraceLog::RECORDING_MODE, TraceLog::RECORD_UNTIL_FULL); TraceWithAllMacroVariants(NULL); @@ -876,6 +878,7 @@ TEST_F(TraceEventTestFixture, EnabledObserverFiresOnEnable) { EXPECT_CALL(observer, OnTraceLogEnabled()) .Times(1); TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"), + base::debug::TraceLog::RECORDING_MODE, TraceLog::RECORD_UNTIL_FULL); testing::Mock::VerifyAndClear(&observer); EXPECT_TRUE(TraceLog::GetInstance()->IsEnabled()); @@ -887,6 +890,7 @@ TEST_F(TraceEventTestFixture, EnabledObserverFiresOnEnable) { TEST_F(TraceEventTestFixture, EnabledObserverDoesntFireOnSecondEnable) { TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"), + base::debug::TraceLog::RECORDING_MODE, TraceLog::RECORD_UNTIL_FULL); testing::StrictMock<MockEnabledStateChangedObserver> observer; @@ -897,6 +901,7 @@ TEST_F(TraceEventTestFixture, EnabledObserverDoesntFireOnSecondEnable) { EXPECT_CALL(observer, OnTraceLogDisabled()) .Times(0); TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"), + base::debug::TraceLog::RECORDING_MODE, TraceLog::RECORD_UNTIL_FULL); testing::Mock::VerifyAndClear(&observer); EXPECT_TRUE(TraceLog::GetInstance()->IsEnabled()); @@ -909,8 +914,12 @@ TEST_F(TraceEventTestFixture, EnabledObserverDoesntFireOnSecondEnable) { TEST_F(TraceEventTestFixture, EnabledObserverFiresOnFirstDisable) { CategoryFilter cf_inc_all("*"); - TraceLog::GetInstance()->SetEnabled(cf_inc_all, TraceLog::RECORD_UNTIL_FULL); - TraceLog::GetInstance()->SetEnabled(cf_inc_all, TraceLog::RECORD_UNTIL_FULL); + TraceLog::GetInstance()->SetEnabled(cf_inc_all, + base::debug::TraceLog::RECORDING_MODE, + TraceLog::RECORD_UNTIL_FULL); + TraceLog::GetInstance()->SetEnabled(cf_inc_all, + base::debug::TraceLog::RECORDING_MODE, + TraceLog::RECORD_UNTIL_FULL); testing::StrictMock<MockEnabledStateChangedObserver> observer; TraceLog::GetInstance()->AddEnabledStateObserver(&observer); @@ -929,6 +938,7 @@ TEST_F(TraceEventTestFixture, EnabledObserverFiresOnFirstDisable) { TEST_F(TraceEventTestFixture, EnabledObserverFiresOnDisable) { TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"), + base::debug::TraceLog::RECORDING_MODE, TraceLog::RECORD_UNTIL_FULL); MockEnabledStateChangedObserver observer; @@ -965,6 +975,7 @@ TEST_F(TraceEventTestFixture, ObserversFireAfterStateChange) { TraceLog::GetInstance()->AddEnabledStateObserver(&observer); TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"), + base::debug::TraceLog::RECORDING_MODE, TraceLog::RECORD_UNTIL_FULL); EXPECT_TRUE(TraceLog::GetInstance()->IsEnabled()); @@ -997,6 +1008,7 @@ TEST_F(TraceEventTestFixture, SelfRemovingObserver) { EXPECT_EQ(1u, TraceLog::GetInstance()->GetObserverCountForTest()); TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"), + base::debug::TraceLog::RECORDING_MODE, TraceLog::RECORD_UNTIL_FULL); TraceLog::GetInstance()->SetDisabled(); // The observer removed itself on disable. @@ -1012,6 +1024,7 @@ bool IsNewTrace() { TEST_F(TraceEventTestFixture, NewTraceRecording) { ASSERT_FALSE(IsNewTrace()); TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"), + base::debug::TraceLog::RECORDING_MODE, TraceLog::RECORD_UNTIL_FULL); // First call to IsNewTrace() should succeed. But, the second shouldn't. ASSERT_TRUE(IsNewTrace()); @@ -1024,6 +1037,7 @@ TEST_F(TraceEventTestFixture, NewTraceRecording) { // Start another trace. IsNewTrace() should become true again, briefly, as // before. TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"), + base::debug::TraceLog::RECORDING_MODE, TraceLog::RECORD_UNTIL_FULL); ASSERT_TRUE(IsNewTrace()); ASSERT_FALSE(IsNewTrace()); @@ -1080,6 +1094,7 @@ TEST_F(TraceEventTestFixture, Categories) { Clear(); included_categories.clear(); TraceLog::GetInstance()->SetEnabled(CategoryFilter("not_found823564786"), + base::debug::TraceLog::RECORDING_MODE, TraceLog::RECORD_UNTIL_FULL); TRACE_EVENT_INSTANT0("cat1", "name", TRACE_EVENT_SCOPE_THREAD); TRACE_EVENT_INSTANT0("cat2", "name", TRACE_EVENT_SCOPE_THREAD); @@ -1090,6 +1105,7 @@ TEST_F(TraceEventTestFixture, Categories) { Clear(); included_categories.clear(); TraceLog::GetInstance()->SetEnabled(CategoryFilter("inc"), + base::debug::TraceLog::RECORDING_MODE, TraceLog::RECORD_UNTIL_FULL); TRACE_EVENT_INSTANT0("inc", "name", TRACE_EVENT_SCOPE_THREAD); TRACE_EVENT_INSTANT0("inc2", "name", TRACE_EVENT_SCOPE_THREAD); @@ -1102,6 +1118,7 @@ TEST_F(TraceEventTestFixture, Categories) { included_categories.clear(); TraceLog::GetInstance()->SetEnabled( CategoryFilter("inc_wildcard_*,inc_wildchar_?_end"), + base::debug::TraceLog::RECORDING_MODE, TraceLog::RECORD_UNTIL_FULL); TRACE_EVENT_INSTANT0("inc_wildcard_abc", "included", TRACE_EVENT_SCOPE_THREAD); @@ -1131,6 +1148,7 @@ TEST_F(TraceEventTestFixture, Categories) { // Exclude nonexistent category -> all events Clear(); TraceLog::GetInstance()->SetEnabled(CategoryFilter("-not_found823564786"), + base::debug::TraceLog::RECORDING_MODE, TraceLog::RECORD_UNTIL_FULL); TRACE_EVENT_INSTANT0("cat1", "name", TRACE_EVENT_SCOPE_THREAD); TRACE_EVENT_INSTANT0("cat2", "name", TRACE_EVENT_SCOPE_THREAD); @@ -1143,6 +1161,7 @@ TEST_F(TraceEventTestFixture, Categories) { // Exclude existent category -> only events of other categories Clear(); TraceLog::GetInstance()->SetEnabled(CategoryFilter("-inc"), + base::debug::TraceLog::RECORDING_MODE, TraceLog::RECORD_UNTIL_FULL); TRACE_EVENT_INSTANT0("inc", "name", TRACE_EVENT_SCOPE_THREAD); TRACE_EVENT_INSTANT0("inc2", "name", TRACE_EVENT_SCOPE_THREAD); @@ -1158,6 +1177,7 @@ TEST_F(TraceEventTestFixture, Categories) { Clear(); TraceLog::GetInstance()->SetEnabled( CategoryFilter("-inc_wildcard_*,-inc_wildchar_?_end"), + base::debug::TraceLog::RECORDING_MODE, TraceLog::RECORD_UNTIL_FULL); TRACE_EVENT_INSTANT0("inc_wildcard_abc", "not_inc", TRACE_EVENT_SCOPE_THREAD); @@ -1665,15 +1685,21 @@ TEST_F(TraceEventTestFixture, TracingIsLazy) { TEST_F(TraceEventTestFixture, TraceEnableDisable) { TraceLog* trace_log = TraceLog::GetInstance(); CategoryFilter cf_inc_all("*"); - trace_log->SetEnabled(cf_inc_all, TraceLog::RECORD_UNTIL_FULL); + trace_log->SetEnabled(cf_inc_all, + base::debug::TraceLog::RECORDING_MODE, + TraceLog::RECORD_UNTIL_FULL); EXPECT_TRUE(trace_log->IsEnabled()); trace_log->SetDisabled(); EXPECT_FALSE(trace_log->IsEnabled()); - trace_log->SetEnabled(cf_inc_all, TraceLog::RECORD_UNTIL_FULL); + trace_log->SetEnabled(cf_inc_all, + base::debug::TraceLog::RECORDING_MODE, + TraceLog::RECORD_UNTIL_FULL); EXPECT_TRUE(trace_log->IsEnabled()); const std::vector<std::string> empty; - trace_log->SetEnabled(CategoryFilter(""), TraceLog::RECORD_UNTIL_FULL); + trace_log->SetEnabled(CategoryFilter(""), + base::debug::TraceLog::RECORDING_MODE, + TraceLog::RECORD_UNTIL_FULL); EXPECT_TRUE(trace_log->IsEnabled()); trace_log->SetDisabled(); EXPECT_FALSE(trace_log->IsEnabled()); @@ -1683,15 +1709,21 @@ TEST_F(TraceEventTestFixture, TraceEnableDisable) { TEST_F(TraceEventTestFixture, TraceCategoriesAfterNestedEnable) { TraceLog* trace_log = TraceLog::GetInstance(); - trace_log->SetEnabled(CategoryFilter("foo,bar"), TraceLog::RECORD_UNTIL_FULL); + trace_log->SetEnabled(CategoryFilter("foo,bar"), + base::debug::TraceLog::RECORDING_MODE, + TraceLog::RECORD_UNTIL_FULL); EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("foo")); EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("bar")); EXPECT_FALSE(*trace_log->GetCategoryGroupEnabled("baz")); - trace_log->SetEnabled(CategoryFilter("foo2"), TraceLog::RECORD_UNTIL_FULL); + trace_log->SetEnabled(CategoryFilter("foo2"), + base::debug::TraceLog::RECORDING_MODE, + TraceLog::RECORD_UNTIL_FULL); EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("foo2")); EXPECT_FALSE(*trace_log->GetCategoryGroupEnabled("baz")); // The "" becomes the default catergory set when applied. - trace_log->SetEnabled(CategoryFilter(""), TraceLog::RECORD_UNTIL_FULL); + trace_log->SetEnabled(CategoryFilter(""), + base::debug::TraceLog::RECORDING_MODE, + TraceLog::RECORD_UNTIL_FULL); EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("foo")); EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("baz")); EXPECT_STREQ("-*Debug,-*Test", @@ -1703,10 +1735,13 @@ TEST_F(TraceEventTestFixture, TraceCategoriesAfterNestedEnable) { EXPECT_FALSE(*trace_log->GetCategoryGroupEnabled("baz")); trace_log->SetEnabled(CategoryFilter("-foo,-bar"), + base::debug::TraceLog::RECORDING_MODE, TraceLog::RECORD_UNTIL_FULL); EXPECT_FALSE(*trace_log->GetCategoryGroupEnabled("foo")); EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("baz")); - trace_log->SetEnabled(CategoryFilter("moo"), TraceLog::RECORD_UNTIL_FULL); + trace_log->SetEnabled(CategoryFilter("moo"), + base::debug::TraceLog::RECORDING_MODE, + TraceLog::RECORD_UNTIL_FULL); EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("baz")); EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("moo")); EXPECT_FALSE(*trace_log->GetCategoryGroupEnabled("foo")); @@ -1717,9 +1752,11 @@ TEST_F(TraceEventTestFixture, TraceCategoriesAfterNestedEnable) { // Make sure disabled categories aren't cleared if we set in the second. trace_log->SetEnabled(CategoryFilter("disabled-by-default-cc,foo"), + base::debug::TraceLog::RECORDING_MODE, TraceLog::RECORD_UNTIL_FULL); EXPECT_FALSE(*trace_log->GetCategoryGroupEnabled("bar")); trace_log->SetEnabled(CategoryFilter("disabled-by-default-gpu"), + base::debug::TraceLog::RECORDING_MODE, TraceLog::RECORD_UNTIL_FULL); EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("disabled-by-default-cc")); EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("disabled-by-default-gpu")); @@ -1733,6 +1770,7 @@ TEST_F(TraceEventTestFixture, TraceCategoriesAfterNestedEnable) { TEST_F(TraceEventTestFixture, TraceSampling) { TraceLog::GetInstance()->SetEnabled( CategoryFilter("*"), + base::debug::TraceLog::RECORDING_MODE, TraceLog::Options(TraceLog::RECORD_UNTIL_FULL | TraceLog::ENABLE_SAMPLING)); @@ -1751,6 +1789,7 @@ TEST_F(TraceEventTestFixture, TraceSampling) { TEST_F(TraceEventTestFixture, TraceSamplingScope) { TraceLog::GetInstance()->SetEnabled( CategoryFilter("*"), + base::debug::TraceLog::RECORDING_MODE, TraceLog::Options(TraceLog::RECORD_UNTIL_FULL | TraceLog::ENABLE_SAMPLING)); @@ -1785,7 +1824,8 @@ TEST_F(TraceEventTestFixture, TraceSamplingScope) { TEST_F(TraceEventTestFixture, TraceContinuousSampling) { TraceLog::GetInstance()->SetEnabled( CategoryFilter("*"), - TraceLog::Options(TraceLog::MONITOR_SAMPLING)); + base::debug::TraceLog::MONITORING_MODE, + TraceLog::Options(TraceLog::ENABLE_SAMPLING)); TRACE_EVENT_SET_SAMPLING_STATE_FOR_BUCKET(1, "category", "AAA"); TraceLog::GetInstance()->WaitSamplingEventForTesting(); @@ -1843,6 +1883,7 @@ class MyData : public base::debug::ConvertableToTraceFormat { TEST_F(TraceEventTestFixture, ConvertableTypes) { TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"), + base::debug::TraceLog::RECORDING_MODE, TraceLog::RECORD_UNTIL_FULL); scoped_refptr<ConvertableToTraceFormat> data(new MyData()); @@ -2046,6 +2087,7 @@ TEST_F(TraceEventCallbackTest, TraceEventCallback) { TEST_F(TraceEventCallbackTest, TraceEventCallbackWhileFull) { TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"), + base::debug::TraceLog::RECORDING_MODE, TraceLog::RECORD_UNTIL_FULL); do { TRACE_EVENT_INSTANT0("all", "badger badger", TRACE_EVENT_SCOPE_GLOBAL); @@ -2066,8 +2108,9 @@ TEST_F(TraceEventCallbackTest, TraceEventCallbackAndRecording1) { Callback); TRACE_EVENT_INSTANT0("recording", "no", TRACE_EVENT_SCOPE_GLOBAL); TRACE_EVENT_INSTANT0("callback", "yes", TRACE_EVENT_SCOPE_GLOBAL); - TraceLog::GetInstance()->SetEnabled( - CategoryFilter("recording"), TraceLog::RECORD_UNTIL_FULL); + TraceLog::GetInstance()->SetEnabled(CategoryFilter("recording"), + base::debug::TraceLog::RECORDING_MODE, + TraceLog::RECORD_UNTIL_FULL); TRACE_EVENT_INSTANT0("recording", "yes", TRACE_EVENT_SCOPE_GLOBAL); TRACE_EVENT_INSTANT0("callback", "yes", TRACE_EVENT_SCOPE_GLOBAL); TraceLog::GetInstance()->SetEventCallbackDisabled(); @@ -2088,8 +2131,9 @@ TEST_F(TraceEventCallbackTest, TraceEventCallbackAndRecording2) { Callback); TRACE_EVENT_INSTANT0("recording", "no", TRACE_EVENT_SCOPE_GLOBAL); TRACE_EVENT_INSTANT0("callback", "yes", TRACE_EVENT_SCOPE_GLOBAL); - TraceLog::GetInstance()->SetEnabled( - CategoryFilter("recording"), TraceLog::RECORD_UNTIL_FULL); + TraceLog::GetInstance()->SetEnabled(CategoryFilter("recording"), + base::debug::TraceLog::RECORDING_MODE, + TraceLog::RECORD_UNTIL_FULL); TRACE_EVENT_INSTANT0("recording", "yes", TRACE_EVENT_SCOPE_GLOBAL); TRACE_EVENT_INSTANT0("callback", "yes", TRACE_EVENT_SCOPE_GLOBAL); EndTraceAndFlush(); @@ -2106,8 +2150,9 @@ TEST_F(TraceEventCallbackTest, TraceEventCallbackAndRecording2) { TEST_F(TraceEventCallbackTest, TraceEventCallbackAndRecording3) { TRACE_EVENT_INSTANT0("recording", "no", TRACE_EVENT_SCOPE_GLOBAL); TRACE_EVENT_INSTANT0("callback", "no", TRACE_EVENT_SCOPE_GLOBAL); - TraceLog::GetInstance()->SetEnabled( - CategoryFilter("recording"), TraceLog::RECORD_UNTIL_FULL); + TraceLog::GetInstance()->SetEnabled(CategoryFilter("recording"), + base::debug::TraceLog::RECORDING_MODE, + TraceLog::RECORD_UNTIL_FULL); TRACE_EVENT_INSTANT0("recording", "yes", TRACE_EVENT_SCOPE_GLOBAL); TRACE_EVENT_INSTANT0("callback", "no", TRACE_EVENT_SCOPE_GLOBAL); TraceLog::GetInstance()->SetEventCallbackEnabled(CategoryFilter("callback"), @@ -2128,8 +2173,9 @@ TEST_F(TraceEventCallbackTest, TraceEventCallbackAndRecording3) { TEST_F(TraceEventCallbackTest, TraceEventCallbackAndRecording4) { TRACE_EVENT_INSTANT0("recording", "no", TRACE_EVENT_SCOPE_GLOBAL); TRACE_EVENT_INSTANT0("callback", "no", TRACE_EVENT_SCOPE_GLOBAL); - TraceLog::GetInstance()->SetEnabled( - CategoryFilter("recording"), TraceLog::RECORD_UNTIL_FULL); + TraceLog::GetInstance()->SetEnabled(CategoryFilter("recording"), + base::debug::TraceLog::RECORDING_MODE, + TraceLog::RECORD_UNTIL_FULL); TRACE_EVENT_INSTANT0("recording", "yes", TRACE_EVENT_SCOPE_GLOBAL); TRACE_EVENT_INSTANT0("callback", "no", TRACE_EVENT_SCOPE_GLOBAL); TraceLog::GetInstance()->SetEventCallbackEnabled(CategoryFilter("callback"), @@ -2151,8 +2197,9 @@ TEST_F(TraceEventCallbackTest, TraceEventCallbackAndRecordingDuration) { Callback); { TRACE_EVENT0("callback", "duration1"); - TraceLog::GetInstance()->SetEnabled( - CategoryFilter("*"), TraceLog::RECORD_UNTIL_FULL); + TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"), + base::debug::TraceLog::RECORDING_MODE, + TraceLog::RECORD_UNTIL_FULL); TRACE_EVENT0("callback", "duration2"); EndTraceAndFlush(); TRACE_EVENT0("callback", "duration3"); @@ -2170,6 +2217,7 @@ TEST_F(TraceEventCallbackTest, TraceEventCallbackAndRecordingDuration) { TEST_F(TraceEventTestFixture, TraceBufferRingBufferGetReturnChunk) { TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"), + base::debug::TraceLog::RECORDING_MODE, TraceLog::RECORD_CONTINUOUSLY); TraceBuffer* buffer = TraceLog::GetInstance()->trace_buffer(); size_t capacity = buffer->Capacity(); @@ -2229,6 +2277,7 @@ TEST_F(TraceEventTestFixture, TraceBufferRingBufferGetReturnChunk) { TEST_F(TraceEventTestFixture, TraceBufferRingBufferHalfIteration) { TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"), + base::debug::TraceLog::RECORDING_MODE, TraceLog::RECORD_CONTINUOUSLY); TraceBuffer* buffer = TraceLog::GetInstance()->trace_buffer(); size_t capacity = buffer->Capacity(); @@ -2256,6 +2305,7 @@ TEST_F(TraceEventTestFixture, TraceBufferRingBufferHalfIteration) { TEST_F(TraceEventTestFixture, TraceBufferRingBufferFullIteration) { TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"), + base::debug::TraceLog::RECORDING_MODE, TraceLog::RECORD_CONTINUOUSLY); TraceBuffer* buffer = TraceLog::GetInstance()->trace_buffer(); size_t capacity = buffer->Capacity(); @@ -2504,6 +2554,7 @@ TEST_F(TraceEventTestFixture, EchoToConsole) { logging::SetLogMessageHandler(MockLogMessageHandler); TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"), + base::debug::TraceLog::RECORDING_MODE, TraceLog::ECHO_TO_CONSOLE); TRACE_EVENT_BEGIN0("a", "begin_end"); { @@ -2539,6 +2590,7 @@ TEST_F(TraceEventTestFixture, EchoToConsoleTraceEventRecursion) { logging::SetLogMessageHandler(LogMessageHandlerWithTraceEvent); TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"), + base::debug::TraceLog::RECORDING_MODE, TraceLog::ECHO_TO_CONSOLE); { // This should not cause deadlock or infinite recursion. |