summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authordsinclair@chromium.org <dsinclair@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-23 02:09:53 +0000
committerdsinclair@chromium.org <dsinclair@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-23 02:09:53 +0000
commitdcc7837317b2f78398461ae1cc78e14780222639 (patch)
tree837804f3c4ec78738648199193dd9948498bfa25 /base
parent9b5f0a4b60e2139bb6e80947f93f59164bb1ee17 (diff)
downloadchromium_src-dcc7837317b2f78398461ae1cc78e14780222639.zip
chromium_src-dcc7837317b2f78398461ae1cc78e14780222639.tar.gz
chromium_src-dcc7837317b2f78398461ae1cc78e14780222639.tar.bz2
Add a mode flag to the tracing framework.
The mode is provided when SetEnabled is called. Currently there is only one mode which is the trace until buffer is full mode. We will be adding a continuous tracing mode which this will support. BUG=156025 Review URL: https://chromiumcodereview.appspot.com/12302036 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@184258 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/debug/trace_event_impl.cc49
-rw-r--r--base/debug/trace_event_impl.h21
-rw-r--r--base/debug/trace_event_unittest.cc74
-rw-r--r--base/test/trace_event_analyzer_unittest.cc8
4 files changed, 111 insertions, 41 deletions
diff --git a/base/debug/trace_event_impl.cc b/base/debug/trace_event_impl.cc
index cbcf54b..5eafd52 100644
--- a/base/debug/trace_event_impl.cc
+++ b/base/debug/trace_event_impl.cc
@@ -14,6 +14,7 @@
#include "base/memory/singleton.h"
#include "base/process_util.h"
#include "base/stl_util.h"
+#include "base/string_split.h"
#include "base/string_util.h"
#include "base/stringprintf.h"
#include "base/strings/string_tokenizer.h"
@@ -72,6 +73,8 @@ int g_category_index = 3; // skip initial 3 categories
LazyInstance<ThreadLocalPointer<const char> >::Leaky
g_current_thread_name = LAZY_INSTANCE_INITIALIZER;
+const char kRecordUntilFull[] = "record-until-full";
+
} // namespace
////////////////////////////////////////////////////////////////////////////////
@@ -348,10 +351,37 @@ TraceLog* TraceLog::GetInstance() {
return Singleton<TraceLog, StaticMemorySingletonTraits<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 {
+ NOTREACHED(); // Unknown option provided.
+ }
+ }
+ // Check to see if any RECORD_* options are set, and if none, then provide
+ // a default.
+ // TODO(dsinclair): Remove this comment when we have more then one RECORD_*
+ // flag and the code's structure is then sensible.
+ if (!(ret & RECORD_UNTIL_FULL))
+ ret |= RECORD_UNTIL_FULL; // Default when no options are specified.
+
+ return static_cast<Options>(ret);
+}
+
TraceLog::TraceLog()
: enable_count_(0),
dispatching_to_observer_list_(false),
- watch_category_(NULL) {
+ watch_category_(NULL),
+ trace_options_(RECORD_UNTIL_FULL) {
// Trace is enabled or disabled on one thread while other threads are
// accessing the enabled flag. We don't care whether edge-case events are
// traced or not, so we allow races on the enabled flag to keep the trace
@@ -478,10 +508,16 @@ void TraceLog::GetKnownCategories(std::vector<std::string>* categories) {
}
void TraceLog::SetEnabled(const std::vector<std::string>& included_categories,
- const std::vector<std::string>& excluded_categories) {
+ const std::vector<std::string>& excluded_categories,
+ Options options) {
AutoLock lock(lock_);
if (enable_count_++ > 0) {
+ if (options != trace_options_) {
+ DLOG(ERROR) << "Attemting to re-enable tracing with a different "
+ << "set of options.";
+ }
+
// Tracing is already enabled, so just merge in enabled categories.
// We only expand the set of enabled categories upon nested SetEnable().
if (!included_categories_.empty() && !included_categories.empty()) {
@@ -497,6 +533,7 @@ void TraceLog::SetEnabled(const std::vector<std::string>& included_categories,
}
return;
}
+ trace_options_ = options;
if (dispatching_to_observer_list_) {
DLOG(ERROR) <<
@@ -520,7 +557,7 @@ void TraceLog::SetEnabled(const std::vector<std::string>& included_categories,
EnableMatchingCategories(excluded_categories_, 0, CATEGORY_ENABLED);
}
-void TraceLog::SetEnabled(const std::string& categories) {
+void TraceLog::SetEnabled(const std::string& categories, Options options) {
std::vector<std::string> included, excluded;
// Tokenize list of categories, delimited by ','.
StringTokenizer tokens(categories, ",");
@@ -538,7 +575,7 @@ void TraceLog::SetEnabled(const std::string& categories) {
else
excluded.push_back(category);
}
- SetEnabled(included, excluded);
+ SetEnabled(included, excluded, options);
}
void TraceLog::GetEnabledTraceCategories(
@@ -577,9 +614,9 @@ void TraceLog::SetDisabled() {
AddThreadNameMetadataEvents();
}
-void TraceLog::SetEnabled(bool enabled) {
+void TraceLog::SetEnabled(bool enabled, Options options) {
if (enabled)
- SetEnabled(std::vector<std::string>(), std::vector<std::string>());
+ SetEnabled(std::vector<std::string>(), std::vector<std::string>(), options);
else
SetDisabled();
}
diff --git a/base/debug/trace_event_impl.h b/base/debug/trace_event_impl.h
index f152b0a4..c73fbcb 100644
--- a/base/debug/trace_event_impl.h
+++ b/base/debug/trace_event_impl.h
@@ -157,7 +157,6 @@ class BASE_EXPORT TraceResultBuffer {
bool append_comma_;
};
-
class BASE_EXPORT TraceLog {
public:
// Notification is a mask of one or more of the following events.
@@ -170,8 +169,17 @@ class BASE_EXPORT TraceLog {
EVENT_WATCH_NOTIFICATION = 1 << 1
};
+ // Options determines how the trace buffer stores data.
+ enum Options {
+ RECORD_UNTIL_FULL = 1 << 0
+ };
+
static TraceLog* GetInstance();
+ // Convert the given string to trace options. Defaults to RECORD_UNTIL_FULL if
+ // the string does not provide valid options.
+ static Options TraceOptionsFromString(const std::string& str);
+
// Get set of known categories. This can change as new code paths are reached.
// The known categories are inserted into |categories|.
void GetKnownCategories(std::vector<std::string>* categories);
@@ -185,7 +193,8 @@ class BASE_EXPORT TraceLog {
// Else if excluded_categories is non-empty, everything but those are traced.
// Wildcards * and ? are supported (see MatchPattern in string_util.h).
void SetEnabled(const std::vector<std::string>& included_categories,
- const std::vector<std::string>& excluded_categories);
+ const std::vector<std::string>& excluded_categories,
+ Options options);
// |categories| is a comma-delimited list of category wildcards.
// A category can have an optional '-' prefix to make it an excluded category.
@@ -195,17 +204,19 @@ class BASE_EXPORT TraceLog {
// Example: SetEnabled("test_MyTest*");
// Example: SetEnabled("test_MyTest*,test_OtherStuff");
// Example: SetEnabled("-excluded_category1,-excluded_category2");
- void SetEnabled(const std::string& categories);
+ void SetEnabled(const std::string& categories, Options options);
// Retieves the categories set via a prior call to SetEnabled(). Only
// meaningful if |IsEnabled()| is true.
void GetEnabledTraceCategories(std::vector<std::string>* included_out,
std::vector<std::string>* excluded_out);
+ Options trace_options() const { return trace_options_; }
+
// Disable tracing for all categories.
void SetDisabled();
// Helper method to enable/disable tracing for all categories.
- void SetEnabled(bool enabled);
+ void SetEnabled(bool enabled, Options options);
bool IsEnabled() { return !!enable_count_; }
#if defined(OS_ANDROID)
@@ -400,6 +411,8 @@ class BASE_EXPORT TraceLog {
const unsigned char* watch_category_;
std::string watch_event_name_;
+ Options trace_options_;
+
DISALLOW_COPY_AND_ASSIGN(TraceLog);
};
diff --git a/base/debug/trace_event_unittest.cc b/base/debug/trace_event_unittest.cc
index 78bcc23..fd6bbd2 100644
--- a/base/debug/trace_event_unittest.cc
+++ b/base/debug/trace_event_unittest.cc
@@ -73,7 +73,8 @@ class TraceEventTestFixture : public testing::Test {
void BeginTrace() {
event_watch_notification_ = 0;
- TraceLog::GetInstance()->SetEnabled(std::string("*"));
+ TraceLog::GetInstance()->SetEnabled(std::string("*"),
+ TraceLog::RECORD_UNTIL_FULL);
}
void EndTraceAndFlush() {
@@ -714,7 +715,7 @@ void HighResSleepForTraceTest(base::TimeDelta elapsed) {
// Simple Test for emitting data and validating it was received.
TEST_F(TraceEventTestFixture, DataCaptured) {
ManualTestSetUp();
- TraceLog::GetInstance()->SetEnabled(true);
+ TraceLog::GetInstance()->SetEnabled(true, TraceLog::RECORD_UNTIL_FULL);
TraceWithAllMacroVariants(NULL);
@@ -738,18 +739,18 @@ TEST_F(TraceEventTestFixture, EnabledObserverFiresOnEnable) {
EXPECT_CALL(observer, OnTraceLogWillEnable())
.Times(1);
- TraceLog::GetInstance()->SetEnabled(true);
+ TraceLog::GetInstance()->SetEnabled(true, TraceLog::RECORD_UNTIL_FULL);
testing::Mock::VerifyAndClear(&observer);
// Cleanup.
TraceLog::GetInstance()->RemoveEnabledStateObserver(&observer);
- TraceLog::GetInstance()->SetEnabled(false);
+ TraceLog::GetInstance()->SetEnabled(false, TraceLog::RECORD_UNTIL_FULL);
}
TEST_F(TraceEventTestFixture, EnabledObserverDoesntFireOnSecondEnable) {
ManualTestSetUp();
- TraceLog::GetInstance()->SetEnabled(true);
+ TraceLog::GetInstance()->SetEnabled(true, TraceLog::RECORD_UNTIL_FULL);
testing::StrictMock<MockEnabledStateChangedObserver> observer;
TraceLog::GetInstance()->AddEnabledStateObserver(&observer);
@@ -758,20 +759,20 @@ TEST_F(TraceEventTestFixture, EnabledObserverDoesntFireOnSecondEnable) {
.Times(0);
EXPECT_CALL(observer, OnTraceLogWillDisable())
.Times(0);
- TraceLog::GetInstance()->SetEnabled(true);
+ TraceLog::GetInstance()->SetEnabled(true, TraceLog::RECORD_UNTIL_FULL);
testing::Mock::VerifyAndClear(&observer);
// Cleanup.
TraceLog::GetInstance()->RemoveEnabledStateObserver(&observer);
- TraceLog::GetInstance()->SetEnabled(false);
- TraceLog::GetInstance()->SetEnabled(false);
+ TraceLog::GetInstance()->SetEnabled(false, TraceLog::RECORD_UNTIL_FULL);
+ TraceLog::GetInstance()->SetEnabled(false, TraceLog::RECORD_UNTIL_FULL);
}
TEST_F(TraceEventTestFixture, EnabledObserverDoesntFireOnNestedDisable) {
ManualTestSetUp();
- TraceLog::GetInstance()->SetEnabled(true);
- TraceLog::GetInstance()->SetEnabled(true);
+ TraceLog::GetInstance()->SetEnabled(true, TraceLog::RECORD_UNTIL_FULL);
+ TraceLog::GetInstance()->SetEnabled(true, TraceLog::RECORD_UNTIL_FULL);
testing::StrictMock<MockEnabledStateChangedObserver> observer;
TraceLog::GetInstance()->AddEnabledStateObserver(&observer);
@@ -780,25 +781,25 @@ TEST_F(TraceEventTestFixture, EnabledObserverDoesntFireOnNestedDisable) {
.Times(0);
EXPECT_CALL(observer, OnTraceLogWillDisable())
.Times(0);
- TraceLog::GetInstance()->SetEnabled(false);
+ TraceLog::GetInstance()->SetEnabled(false, TraceLog::RECORD_UNTIL_FULL);
testing::Mock::VerifyAndClear(&observer);
// Cleanup.
TraceLog::GetInstance()->RemoveEnabledStateObserver(&observer);
- TraceLog::GetInstance()->SetEnabled(false);
+ TraceLog::GetInstance()->SetEnabled(false, TraceLog::RECORD_UNTIL_FULL);
}
TEST_F(TraceEventTestFixture, EnabledObserverFiresOnDisable) {
ManualTestSetUp();
- TraceLog::GetInstance()->SetEnabled(true);
+ TraceLog::GetInstance()->SetEnabled(true, TraceLog::RECORD_UNTIL_FULL);
MockEnabledStateChangedObserver observer;
TraceLog::GetInstance()->AddEnabledStateObserver(&observer);
EXPECT_CALL(observer, OnTraceLogWillDisable())
.Times(1);
- TraceLog::GetInstance()->SetEnabled(false);
+ TraceLog::GetInstance()->SetEnabled(false, TraceLog::RECORD_UNTIL_FULL);
testing::Mock::VerifyAndClear(&observer);
// Cleanup.
@@ -834,7 +835,8 @@ TEST_F(TraceEventTestFixture, Categories) {
Clear();
included_categories.clear();
included_categories.push_back("not_found823564786");
- TraceLog::GetInstance()->SetEnabled(included_categories, empty_categories);
+ TraceLog::GetInstance()->SetEnabled(included_categories, empty_categories,
+ TraceLog::RECORD_UNTIL_FULL);
TRACE_EVENT_INSTANT0("cat1", "name");
TRACE_EVENT_INSTANT0("cat2", "name");
EndTraceAndFlush();
@@ -844,7 +846,8 @@ TEST_F(TraceEventTestFixture, Categories) {
Clear();
included_categories.clear();
included_categories.push_back("inc");
- TraceLog::GetInstance()->SetEnabled(included_categories, empty_categories);
+ TraceLog::GetInstance()->SetEnabled(included_categories, empty_categories,
+ TraceLog::RECORD_UNTIL_FULL);
TRACE_EVENT_INSTANT0("inc", "name");
TRACE_EVENT_INSTANT0("inc2", "name");
EndTraceAndFlush();
@@ -856,7 +859,8 @@ TEST_F(TraceEventTestFixture, Categories) {
included_categories.clear();
included_categories.push_back("inc_wildcard_*");
included_categories.push_back("inc_wildchar_?_end");
- TraceLog::GetInstance()->SetEnabled(included_categories, empty_categories);
+ TraceLog::GetInstance()->SetEnabled(included_categories, empty_categories,
+ TraceLog::RECORD_UNTIL_FULL);
TRACE_EVENT_INSTANT0("inc_wildcard_abc", "included");
TRACE_EVENT_INSTANT0("inc_wildcard_", "included");
TRACE_EVENT_INSTANT0("inc_wildchar_x_end", "included");
@@ -875,7 +879,8 @@ TEST_F(TraceEventTestFixture, Categories) {
Clear();
excluded_categories.clear();
excluded_categories.push_back("not_found823564786");
- TraceLog::GetInstance()->SetEnabled(empty_categories, excluded_categories);
+ TraceLog::GetInstance()->SetEnabled(empty_categories, excluded_categories,
+ TraceLog::RECORD_UNTIL_FULL);
TRACE_EVENT_INSTANT0("cat1", "name");
TRACE_EVENT_INSTANT0("cat2", "name");
EndTraceAndFlush();
@@ -886,7 +891,8 @@ TEST_F(TraceEventTestFixture, Categories) {
Clear();
excluded_categories.clear();
excluded_categories.push_back("inc");
- TraceLog::GetInstance()->SetEnabled(empty_categories, excluded_categories);
+ TraceLog::GetInstance()->SetEnabled(empty_categories, excluded_categories,
+ TraceLog::RECORD_UNTIL_FULL);
TRACE_EVENT_INSTANT0("inc", "name");
TRACE_EVENT_INSTANT0("inc2", "name");
EndTraceAndFlush();
@@ -898,7 +904,8 @@ TEST_F(TraceEventTestFixture, Categories) {
excluded_categories.clear();
excluded_categories.push_back("inc_wildcard_*");
excluded_categories.push_back("inc_wildchar_?_end");
- TraceLog::GetInstance()->SetEnabled(empty_categories, excluded_categories);
+ TraceLog::GetInstance()->SetEnabled(empty_categories, excluded_categories,
+ TraceLog::RECORD_UNTIL_FULL);
TRACE_EVENT_INSTANT0("inc_wildcard_abc", "not_inc");
TRACE_EVENT_INSTANT0("inc_wildcard_", "not_inc");
TRACE_EVENT_INSTANT0("inc_wildchar_x_end", "not_inc");
@@ -1431,17 +1438,17 @@ TEST_F(TraceEventTestFixture, TraceEnableDisable) {
ManualTestSetUp();
TraceLog* trace_log = TraceLog::GetInstance();
- trace_log->SetEnabled(std::string());
+ trace_log->SetEnabled(std::string(), TraceLog::RECORD_UNTIL_FULL);
EXPECT_TRUE(trace_log->IsEnabled());
trace_log->SetDisabled();
EXPECT_FALSE(trace_log->IsEnabled());
- trace_log->SetEnabled(true);
+ trace_log->SetEnabled(true, TraceLog::RECORD_UNTIL_FULL);
EXPECT_TRUE(trace_log->IsEnabled());
const std::vector<std::string> empty;
- trace_log->SetEnabled(empty, empty);
+ trace_log->SetEnabled(empty, empty, TraceLog::RECORD_UNTIL_FULL);
EXPECT_TRUE(trace_log->IsEnabled());
- trace_log->SetEnabled(false);
+ trace_log->SetEnabled(false, TraceLog::RECORD_UNTIL_FULL);
EXPECT_TRUE(trace_log->IsEnabled());
trace_log->SetDisabled();
EXPECT_FALSE(trace_log->IsEnabled());
@@ -1451,14 +1458,14 @@ TEST_F(TraceEventTestFixture, TraceCategoriesAfterNestedEnable) {
ManualTestSetUp();
TraceLog* trace_log = TraceLog::GetInstance();
- trace_log->SetEnabled(std::string("foo,bar"));
+ trace_log->SetEnabled(std::string("foo,bar"), TraceLog::RECORD_UNTIL_FULL);
EXPECT_TRUE(*trace_log->GetCategoryEnabled("foo"));
EXPECT_TRUE(*trace_log->GetCategoryEnabled("bar"));
EXPECT_FALSE(*trace_log->GetCategoryEnabled("baz"));
- trace_log->SetEnabled(std::string("foo2"));
+ trace_log->SetEnabled(std::string("foo2"), TraceLog::RECORD_UNTIL_FULL);
EXPECT_TRUE(*trace_log->GetCategoryEnabled("foo2"));
EXPECT_FALSE(*trace_log->GetCategoryEnabled("baz"));
- trace_log->SetEnabled(std::string(""));
+ trace_log->SetEnabled(std::string(""), TraceLog::RECORD_UNTIL_FULL);
EXPECT_TRUE(*trace_log->GetCategoryEnabled("foo"));
EXPECT_TRUE(*trace_log->GetCategoryEnabled("baz"));
trace_log->SetDisabled();
@@ -1467,10 +1474,10 @@ TEST_F(TraceEventTestFixture, TraceCategoriesAfterNestedEnable) {
EXPECT_FALSE(*trace_log->GetCategoryEnabled("foo"));
EXPECT_FALSE(*trace_log->GetCategoryEnabled("baz"));
- trace_log->SetEnabled(std::string("-foo,-bar"));
+ trace_log->SetEnabled(std::string("-foo,-bar"), TraceLog::RECORD_UNTIL_FULL);
EXPECT_FALSE(*trace_log->GetCategoryEnabled("foo"));
EXPECT_TRUE(*trace_log->GetCategoryEnabled("baz"));
- trace_log->SetEnabled(std::string("moo"));
+ trace_log->SetEnabled(std::string("moo"), TraceLog::RECORD_UNTIL_FULL);
EXPECT_TRUE(*trace_log->GetCategoryEnabled("baz"));
EXPECT_TRUE(*trace_log->GetCategoryEnabled("moo"));
EXPECT_TRUE(*trace_log->GetCategoryEnabled("foo"));
@@ -1478,5 +1485,14 @@ TEST_F(TraceEventTestFixture, TraceCategoriesAfterNestedEnable) {
trace_log->SetDisabled();
}
+TEST_F(TraceEventTestFixture, TraceOptionsParsing) {
+ ManualTestSetUp();
+
+ EXPECT_EQ(TraceLog::RECORD_UNTIL_FULL, TraceLog::TraceOptionsFromString(""));
+
+ EXPECT_EQ(TraceLog::RECORD_UNTIL_FULL,
+ TraceLog::TraceOptionsFromString("record-until-full"));
+}
+
} // namespace debug
} // namespace base
diff --git a/base/test/trace_event_analyzer_unittest.cc b/base/test/trace_event_analyzer_unittest.cc
index eca2b70..6004341 100644
--- a/base/test/trace_event_analyzer_unittest.cc
+++ b/base/test/trace_event_analyzer_unittest.cc
@@ -39,11 +39,15 @@ void TraceEventAnalyzerTest::OnTraceDataCollected(
void TraceEventAnalyzerTest::BeginTracing() {
output_.json_output.clear();
buffer_.Start();
- base::debug::TraceLog::GetInstance()->SetEnabled(true);
+ base::debug::TraceLog::GetInstance()->SetEnabled(
+ true,
+ base::debug::TraceLog::RECORD_UNTIL_FULL);
}
void TraceEventAnalyzerTest::EndTracing() {
- base::debug::TraceLog::GetInstance()->SetEnabled(false);
+ base::debug::TraceLog::GetInstance()->SetEnabled(
+ false,
+ base::debug::TraceLog::RECORD_UNTIL_FULL);
base::debug::TraceLog::GetInstance()->Flush(
base::Bind(&TraceEventAnalyzerTest::OnTraceDataCollected,
base::Unretained(this)));