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

Unified Diff: base/debug/trace_event_unittest.cc

Issue 7866026: Added trace query code and wired tracing through BrowserProxy so tests can run traces. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments Created 9 years, 3 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/debug/trace_event_test_utils.cc ('k') | chrome/browser/automation/testing_automation_provider.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/debug/trace_event_unittest.cc
diff --git a/base/debug/trace_event_unittest.cc b/base/debug/trace_event_unittest.cc
index a5c889f5608f4f7758174ac835a3af64e9beb60b..f18704d73427c6654a98d4408d399956df6b30d0 100644
--- a/base/debug/trace_event_unittest.cc
+++ b/base/debug/trace_event_unittest.cc
@@ -6,6 +6,7 @@
#include "base/bind.h"
#include "base/command_line.h"
+#include "base/debug/trace_event_test_utils.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/memory/ref_counted_memory.h"
@@ -406,6 +407,110 @@ TEST_F(TraceEventTestFixture, DataCaptured) {
ValidateAllTraceMacrosCreatedData(trace_parsed_, trace_string_);
}
+// Test that the TraceAnalyzer works.
+TEST_F(TraceEventTestFixture, TraceAnalyzer) {
+ using namespace base::debug::trace;
+ ManualTestSetUp();
+
+ Clear();
+ TraceLog::GetInstance()->SetEnabled(true);
+ {
+ TRACE_EVENT_END0("cat3", "name7");
+ TRACE_EVENT2("cat1", "name1", "arg1", 1111, "arg2", "string1");
+ {
+ TRACE_EVENT2("cat2", "name2", "arg1", 2222, "arg2", "string2");
+ TRACE_EVENT_INSTANT1("cat1", "name3", "arg1", 3333);
+ base::PlatformThread::Sleep(200);
+ TRACE_EVENT0("cat2", "name6");
+ }
+ TRACE_EVENT_INSTANT1("cat2", "name4", "arg1", 4444);
+ TRACE_EVENT_INSTANT1("cat2", "name5", "arg1", 1111);
+ TRACE_EVENT_BEGIN0("cat3", "name7");
+ }
+ TraceLog::GetInstance()->SetEnabled(false);
+
+ const TestTraceEvent* event = NULL;
+ TraceAnalyzer analyzer;
+ analyzer.SetEvents(trace_string_);
+
+ TraceAnalyzer::ConstEventPtrVector found;
+ analyzer.FindEvents(Query(EVENT_CATEGORY) == "cat1", &found);
+ EXPECT_EQ(3u, found.size());
+
+ found.clear();
+ analyzer.FindEvents(Query(EVENT_CATEGORY) == "cat1" &&
+ Query(EVENT_ARG, "arg1") == 1111, &found);
+ ASSERT_EQ(1u, found.size());
+ EXPECT_STREQ("name1", found.front()->name.c_str());
+
+ found.clear();
+ analyzer.FindEvents(Query(EVENT_ARG, "arg1") == 1111 ||
+ Query(EVENT_ARG, "arg1") == 2222, &found);
+ EXPECT_EQ(3u, found.size());
+
+ found.clear();
+ analyzer.FindEvents(Query(EVENT_ARG, "arg1") == 1111 &&
+ Query(EVENT_NAME) != "name1", &found);
+ ASSERT_EQ(1u, found.size());
+ EXPECT_STREQ("name5", found.front()->name.c_str());
+
+ found.clear();
+ analyzer.FindEvents(Query(EVENT_ARG, "arg1") == 1111 &&
+ !(Query(EVENT_NAME) != "name1"), &found);
+ ASSERT_EQ(1u, found.size());
+ EXPECT_STREQ("name1", found.front()->name.c_str());
+
+ found.clear();
+ analyzer.FindEvents(Query::MatchBeginWithEnd() &&
+ Query(EVENT_DURATION) > 180000 &&
+ (Query(EVENT_CATEGORY) == "cat1" ||
+ Query(EVENT_CATEGORY) == "cat2" ||
+ Query(EVENT_CATEGORY) == "cat3"), &found);
+ EXPECT_EQ(2u, found.size());
+
+ found.clear();
+ analyzer.FindEvents(Query(EVENT_ARG, "arg1") <= 3333, &found);
+ EXPECT_EQ(4u, found.size());
+
+ found.clear();
+ analyzer.FindEvents(Query(EVENT_ARG, "arg1") >= 3333, &found);
+ EXPECT_EQ(2u, found.size());
+
+ found.clear();
+ analyzer.FindEvents(Query(EVENT_HAS_ARG, "arg1"), &found);
+ EXPECT_EQ(5u, found.size());
+
+ found.clear();
+ analyzer.FindEvents(Query(EVENT_ARG, "arg2") == "string1", &found);
+ ASSERT_EQ(1u, found.size());
+ EXPECT_STREQ("name1", found.front()->name.c_str());
+
+ found.clear();
+ analyzer.FindEvents(Query(EVENT_ARG, "arg2") == Query::Pattern("string?"),
+ &found);
+ EXPECT_EQ(2u, found.size());
+
+ found.clear();
+ analyzer.FindEvents(Query(EVENT_CATEGORY) == Query::Pattern("cat?") &&
+ Query(EVENT_NAME) != Query::Pattern("*"),
+ &found);
+ EXPECT_EQ(0u, found.size());
+
+ found.clear();
+ analyzer.FindEvents(!Query(EVENT_HAS_OTHER) &&
+ Query(EVENT_CATEGORY) == "cat2", &found);
+ EXPECT_EQ(2u, found.size());
+
+ event = analyzer.FindEvent(Query(OTHER_ARG, "arg1") == 1111);
+ ASSERT_TRUE(event);
+ EXPECT_STREQ("name1", event->name.c_str());
+
+ // Verify that matching END..BEGIN does not get associated.
+ ASSERT_TRUE(!analyzer.FindEvent(Query::MatchBeginName("name7")));
+
+ ASSERT_TRUE(!analyzer.FindEvent(Query(EVENT_ARG, "arg1") < 1111));
+}
+
// Test that categories work.
TEST_F(TraceEventTestFixture, Categories) {
ManualTestSetUp();
« no previous file with comments | « base/debug/trace_event_test_utils.cc ('k') | chrome/browser/automation/testing_automation_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698