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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/debug/trace_event.h" 5 #include "base/debug/trace_event.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/debug/trace_event_test_utils.h"
9 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
10 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
11 #include "base/memory/ref_counted_memory.h" 12 #include "base/memory/ref_counted_memory.h"
12 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
13 #include "base/process_util.h" 14 #include "base/process_util.h"
14 #include "base/stringprintf.h" 15 #include "base/stringprintf.h"
15 #include "base/synchronization/waitable_event.h" 16 #include "base/synchronization/waitable_event.h"
16 #include "base/threading/thread.h" 17 #include "base/threading/thread.h"
17 #include "base/values.h" 18 #include "base/values.h"
18 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 ManualTestSetUp(); 400 ManualTestSetUp();
400 TraceLog::GetInstance()->SetEnabled(true); 401 TraceLog::GetInstance()->SetEnabled(true);
401 402
402 TraceWithAllMacroVariants(NULL); 403 TraceWithAllMacroVariants(NULL);
403 404
404 TraceLog::GetInstance()->SetEnabled(false); 405 TraceLog::GetInstance()->SetEnabled(false);
405 406
406 ValidateAllTraceMacrosCreatedData(trace_parsed_, trace_string_); 407 ValidateAllTraceMacrosCreatedData(trace_parsed_, trace_string_);
407 } 408 }
408 409
410 // Test that the TraceAnalyzer works.
411 TEST_F(TraceEventTestFixture, TraceAnalyzer) {
412 using namespace base::debug::trace;
413 ManualTestSetUp();
414
415 Clear();
416 TraceLog::GetInstance()->SetEnabled(true);
417 {
418 TRACE_EVENT_END0("cat3", "name7");
419 TRACE_EVENT2("cat1", "name1", "arg1", 1111, "arg2", "string1");
420 {
421 TRACE_EVENT2("cat2", "name2", "arg1", 2222, "arg2", "string2");
422 TRACE_EVENT_INSTANT1("cat1", "name3", "arg1", 3333);
423 base::PlatformThread::Sleep(200);
424 TRACE_EVENT0("cat2", "name6");
425 }
426 TRACE_EVENT_INSTANT1("cat2", "name4", "arg1", 4444);
427 TRACE_EVENT_INSTANT1("cat2", "name5", "arg1", 1111);
428 TRACE_EVENT_BEGIN0("cat3", "name7");
429 }
430 TraceLog::GetInstance()->SetEnabled(false);
431
432 const TestTraceEvent* event = NULL;
433 TraceAnalyzer analyzer;
434 analyzer.SetEvents(trace_string_);
435
436 TraceAnalyzer::ConstEventPtrVector found;
437 analyzer.FindEvents(Query(EVENT_CATEGORY) == "cat1", &found);
438 EXPECT_EQ(3u, found.size());
439
440 found.clear();
441 analyzer.FindEvents(Query(EVENT_CATEGORY) == "cat1" &&
442 Query(EVENT_ARG, "arg1") == 1111, &found);
443 ASSERT_EQ(1u, found.size());
444 EXPECT_STREQ("name1", found.front()->name.c_str());
445
446 found.clear();
447 analyzer.FindEvents(Query(EVENT_ARG, "arg1") == 1111 ||
448 Query(EVENT_ARG, "arg1") == 2222, &found);
449 EXPECT_EQ(3u, found.size());
450
451 found.clear();
452 analyzer.FindEvents(Query(EVENT_ARG, "arg1") == 1111 &&
453 Query(EVENT_NAME) != "name1", &found);
454 ASSERT_EQ(1u, found.size());
455 EXPECT_STREQ("name5", found.front()->name.c_str());
456
457 found.clear();
458 analyzer.FindEvents(Query(EVENT_ARG, "arg1") == 1111 &&
459 !(Query(EVENT_NAME) != "name1"), &found);
460 ASSERT_EQ(1u, found.size());
461 EXPECT_STREQ("name1", found.front()->name.c_str());
462
463 found.clear();
464 analyzer.FindEvents(Query::MatchBeginWithEnd() &&
465 Query(EVENT_DURATION) > 180000 &&
466 (Query(EVENT_CATEGORY) == "cat1" ||
467 Query(EVENT_CATEGORY) == "cat2" ||
468 Query(EVENT_CATEGORY) == "cat3"), &found);
469 EXPECT_EQ(2u, found.size());
470
471 found.clear();
472 analyzer.FindEvents(Query(EVENT_ARG, "arg1") <= 3333, &found);
473 EXPECT_EQ(4u, found.size());
474
475 found.clear();
476 analyzer.FindEvents(Query(EVENT_ARG, "arg1") >= 3333, &found);
477 EXPECT_EQ(2u, found.size());
478
479 found.clear();
480 analyzer.FindEvents(Query(EVENT_HAS_ARG, "arg1"), &found);
481 EXPECT_EQ(5u, found.size());
482
483 found.clear();
484 analyzer.FindEvents(Query(EVENT_ARG, "arg2") == "string1", &found);
485 ASSERT_EQ(1u, found.size());
486 EXPECT_STREQ("name1", found.front()->name.c_str());
487
488 found.clear();
489 analyzer.FindEvents(Query(EVENT_ARG, "arg2") == Query::Pattern("string?"),
490 &found);
491 EXPECT_EQ(2u, found.size());
492
493 found.clear();
494 analyzer.FindEvents(Query(EVENT_CATEGORY) == Query::Pattern("cat?") &&
495 Query(EVENT_NAME) != Query::Pattern("*"),
496 &found);
497 EXPECT_EQ(0u, found.size());
498
499 found.clear();
500 analyzer.FindEvents(!Query(EVENT_HAS_OTHER) &&
501 Query(EVENT_CATEGORY) == "cat2", &found);
502 EXPECT_EQ(2u, found.size());
503
504 event = analyzer.FindEvent(Query(OTHER_ARG, "arg1") == 1111);
505 ASSERT_TRUE(event);
506 EXPECT_STREQ("name1", event->name.c_str());
507
508 // Verify that matching END..BEGIN does not get associated.
509 ASSERT_TRUE(!analyzer.FindEvent(Query::MatchBeginName("name7")));
510
511 ASSERT_TRUE(!analyzer.FindEvent(Query(EVENT_ARG, "arg1") < 1111));
512 }
513
409 // Test that categories work. 514 // Test that categories work.
410 TEST_F(TraceEventTestFixture, Categories) { 515 TEST_F(TraceEventTestFixture, Categories) {
411 ManualTestSetUp(); 516 ManualTestSetUp();
412 517
413 // Test that categories that are used can be retrieved whether trace was 518 // Test that categories that are used can be retrieved whether trace was
414 // enabled or disabled when the trace event was encountered. 519 // enabled or disabled when the trace event was encountered.
415 TRACE_EVENT_INSTANT0("c1", "name"); 520 TRACE_EVENT_INSTANT0("c1", "name");
416 TRACE_EVENT_INSTANT0("c2", "name"); 521 TRACE_EVENT_INSTANT0("c2", "name");
417 TraceLog::GetInstance()->SetEnabled(true); 522 TraceLog::GetInstance()->SetEnabled(true);
418 TRACE_EVENT_INSTANT0("c3", "name"); 523 TRACE_EVENT_INSTANT0("c3", "name");
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 1022
918 std::string s; 1023 std::string s;
919 EXPECT_TRUE(entry3->GetString("args.arg1", &s)); 1024 EXPECT_TRUE(entry3->GetString("args.arg1", &s));
920 EXPECT_EQ("val1", s); 1025 EXPECT_EQ("val1", s);
921 EXPECT_TRUE(entry3->GetString("args.arg2", &s)); 1026 EXPECT_TRUE(entry3->GetString("args.arg2", &s));
922 EXPECT_EQ("val2", s); 1027 EXPECT_EQ("val2", s);
923 } 1028 }
924 1029
925 } // namespace debug 1030 } // namespace debug
926 } // namespace base 1031 } // namespace base
OLDNEW
« 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