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

Side by Side Diff: base/test/trace_event_analyzer_unittest.cc

Issue 9522010: Add ASYNC_STEP support to trace_event and change START to ASYNC_BEGIN. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: just a merge Created 8 years, 9 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/bind.h" 5 #include "base/bind.h"
6 #include "base/test/trace_event_analyzer.h" 6 #include "base/test/trace_event_analyzer.h"
7 #include "testing/gmock/include/gmock/gmock.h" 7 #include "testing/gmock/include/gmock/gmock.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace trace_analyzer { 10 namespace trace_analyzer {
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 EXPECT_STREQ("name2", found[0]->name.c_str()); 440 EXPECT_STREQ("name2", found[0]->name.c_str());
441 } 441 }
442 442
443 // Test MergeAssociatedEventArgs 443 // Test MergeAssociatedEventArgs
444 TEST_F(TraceEventAnalyzerTest, MergeAssociatedEventArgs) { 444 TEST_F(TraceEventAnalyzerTest, MergeAssociatedEventArgs) {
445 ManualSetUp(); 445 ManualSetUp();
446 446
447 const char* arg_string = "arg_string"; 447 const char* arg_string = "arg_string";
448 BeginTracing(); 448 BeginTracing();
449 { 449 {
450 TRACE_EVENT1("cat1", "name1", "arg", arg_string); 450 TRACE_EVENT_BEGIN0("cat1", "name1");
451 TRACE_EVENT_END1("cat1", "name1", "arg", arg_string);
451 } 452 }
452 EndTracing(); 453 EndTracing();
453 454
454 scoped_ptr<TraceAnalyzer> 455 scoped_ptr<TraceAnalyzer>
455 analyzer(TraceAnalyzer::Create(output_.json_output)); 456 analyzer(TraceAnalyzer::Create(output_.json_output));
456 ASSERT_TRUE(analyzer.get()); 457 ASSERT_TRUE(analyzer.get());
457 analyzer->AssociateBeginEndEvents(); 458 analyzer->AssociateBeginEndEvents();
458 459
459 TraceEventVector found; 460 TraceEventVector found;
460 analyzer->FindEvents(Query::EventName() == Query::String("name1") && 461 analyzer->FindEvents(Query::MatchBeginName("name1"), &found);
461 Query::EventPhase() == Query::Phase(TRACE_EVENT_PHASE_END), &found);
462 ASSERT_EQ(1u, found.size()); 462 ASSERT_EQ(1u, found.size());
463 std::string arg_actual; 463 std::string arg_actual;
464 EXPECT_FALSE(found[0]->GetArgAsString("arg", &arg_actual)); 464 EXPECT_FALSE(found[0]->GetArgAsString("arg", &arg_actual));
465 465
466 analyzer->MergeAssociatedEventArgs(); 466 analyzer->MergeAssociatedEventArgs();
467 EXPECT_TRUE(found[0]->GetArgAsString("arg", &arg_actual)); 467 EXPECT_TRUE(found[0]->GetArgAsString("arg", &arg_actual));
468 EXPECT_STREQ(arg_string, arg_actual.c_str()); 468 EXPECT_STREQ(arg_string, arg_actual.c_str());
469 } 469 }
470 470
471 // Test AssociateStartFinishEvents 471 // Test AssociateAsyncBeginEndEvents
472 TEST_F(TraceEventAnalyzerTest, StartFinishAssocations) { 472 TEST_F(TraceEventAnalyzerTest, AsyncBeginEndAssocations) {
473 ManualSetUp(); 473 ManualSetUp();
474 474
475 BeginTracing(); 475 BeginTracing();
476 { 476 {
477 TRACE_EVENT_FINISH0("cat1", "name1", 0xA); // does not match / out of order 477 TRACE_EVENT_ASYNC_END0("cat1", "name1", 0xA); // no match / out of order
478 TRACE_EVENT_START0("cat1", "name1", 0xB); 478 TRACE_EVENT_ASYNC_BEGIN0("cat1", "name1", 0xB);
479 TRACE_EVENT_START0("cat1", "name1", 0xC); 479 TRACE_EVENT_ASYNC_BEGIN0("cat1", "name1", 0xC);
480 TRACE_EVENT_INSTANT0("cat1", "name1"); // noise 480 TRACE_EVENT_INSTANT0("cat1", "name1"); // noise
481 TRACE_EVENT0("cat1", "name1"); // noise 481 TRACE_EVENT0("cat1", "name1"); // noise
482 TRACE_EVENT_FINISH0("cat1", "name1", 0xB); 482 TRACE_EVENT_ASYNC_END0("cat1", "name1", 0xB);
483 TRACE_EVENT_FINISH0("cat1", "name1", 0xC); 483 TRACE_EVENT_ASYNC_END0("cat1", "name1", 0xC);
484 TRACE_EVENT_START0("cat1", "name1", 0xA); // does not match / out of order 484 TRACE_EVENT_ASYNC_BEGIN0("cat1", "name1", 0xA); // no match / out of order
485 } 485 }
486 EndTracing(); 486 EndTracing();
487 487
488 scoped_ptr<TraceAnalyzer> 488 scoped_ptr<TraceAnalyzer>
489 analyzer(TraceAnalyzer::Create(output_.json_output)); 489 analyzer(TraceAnalyzer::Create(output_.json_output));
490 ASSERT_TRUE(analyzer.get()); 490 ASSERT_TRUE(analyzer.get());
491 analyzer->AssociateStartFinishEvents(); 491 analyzer->AssociateAsyncBeginEndEvents();
492 492
493 TraceEventVector found; 493 TraceEventVector found;
494 analyzer->FindEvents(Query::MatchStartWithFinish(), &found); 494 analyzer->FindEvents(Query::MatchAsyncBeginWithNext(), &found);
495 ASSERT_EQ(2u, found.size()); 495 ASSERT_EQ(2u, found.size());
496 EXPECT_STRCASEEQ("B", found[0]->id.c_str()); 496 EXPECT_STRCASEEQ("B", found[0]->id.c_str());
497 EXPECT_STRCASEEQ("C", found[1]->id.c_str()); 497 EXPECT_STRCASEEQ("C", found[1]->id.c_str());
498 } 498 }
499 499
500 // Test AssociateAsyncBeginEndEvents
501 TEST_F(TraceEventAnalyzerTest, AsyncBeginEndAssocationsWithSteps) {
502 ManualSetUp();
503
504 BeginTracing();
505 {
506 TRACE_EVENT_ASYNC_STEP0("c", "n", 0xA);
507 TRACE_EVENT_ASYNC_END0("c", "n", 0xA);
508 TRACE_EVENT_ASYNC_BEGIN0("c", "n", 0xB);
509 TRACE_EVENT_ASYNC_BEGIN0("c", "n", 0xC);
510 TRACE_EVENT_ASYNC_STEP0("c", "n", 0xB);
511 TRACE_EVENT_ASYNC_STEP0("c", "n", 0xC);
512 TRACE_EVENT_ASYNC_STEP1("c", "n", 0xC, "a", 1);
513 TRACE_EVENT_ASYNC_END0("c", "n", 0xB);
514 TRACE_EVENT_ASYNC_END0("c", "n", 0xC);
515 TRACE_EVENT_ASYNC_BEGIN0("c", "n", 0xA);
516 TRACE_EVENT_ASYNC_STEP0("c", "n", 0xA);
517 }
518 EndTracing();
519
520 scoped_ptr<TraceAnalyzer>
521 analyzer(TraceAnalyzer::Create(output_.json_output));
522 ASSERT_TRUE(analyzer.get());
523 analyzer->AssociateAsyncBeginEndEvents();
524
525 TraceEventVector found;
526 analyzer->FindEvents(Query::MatchAsyncBeginWithNext(), &found);
527 ASSERT_EQ(3u, found.size());
528
529 EXPECT_STRCASEEQ("B", found[0]->id.c_str());
530 EXPECT_EQ(TRACE_EVENT_PHASE_ASYNC_STEP, found[0]->other_event->phase);
531 EXPECT_TRUE(found[0]->other_event->other_event);
532 EXPECT_EQ(TRACE_EVENT_PHASE_ASYNC_END,
533 found[0]->other_event->other_event->phase);
534
535 EXPECT_STRCASEEQ("C", found[1]->id.c_str());
536 EXPECT_EQ(TRACE_EVENT_PHASE_ASYNC_STEP, found[1]->other_event->phase);
537 EXPECT_TRUE(found[1]->other_event->other_event);
538 EXPECT_EQ(TRACE_EVENT_PHASE_ASYNC_STEP,
539 found[1]->other_event->other_event->phase);
540 double arg_actual = 0;
541 EXPECT_TRUE(found[1]->other_event->other_event->GetArgAsNumber(
542 "a", &arg_actual));
543 EXPECT_EQ(1.0, arg_actual);
544 EXPECT_TRUE(found[1]->other_event->other_event->other_event);
545 EXPECT_EQ(TRACE_EVENT_PHASE_ASYNC_END,
546 found[1]->other_event->other_event->other_event->phase);
547
548 EXPECT_STRCASEEQ("A", found[2]->id.c_str());
549 EXPECT_EQ(TRACE_EVENT_PHASE_ASYNC_STEP, found[2]->other_event->phase);
550 }
551
500 // Test that the TraceAnalyzer custom associations work. 552 // Test that the TraceAnalyzer custom associations work.
501 TEST_F(TraceEventAnalyzerTest, CustomAssociations) { 553 TEST_F(TraceEventAnalyzerTest, CustomAssociations) {
502 ManualSetUp(); 554 ManualSetUp();
503 555
504 // Add events that begin/end in pipelined ordering with unique ID parameter 556 // Add events that begin/end in pipelined ordering with unique ID parameter
505 // to match up the begin/end pairs. 557 // to match up the begin/end pairs.
506 BeginTracing(); 558 BeginTracing();
507 { 559 {
508 TRACE_EVENT_INSTANT1("cat1", "end", "id", 1); // no begin match 560 TRACE_EVENT_INSTANT1("cat1", "end", "id", 1); // no begin match
509 TRACE_EVENT_INSTANT1("cat2", "begin", "id", 2); // end is cat4 561 TRACE_EVENT_INSTANT1("cat2", "begin", "id", 2); // end is cat4
(...skipping 24 matching lines...) Expand all
534 // cat1 has no other_event. 586 // cat1 has no other_event.
535 analyzer->FindEvents(Query::EventCategory() == Query::String("cat1") && 587 analyzer->FindEvents(Query::EventCategory() == Query::String("cat1") &&
536 !Query::EventHasOther(), &found); 588 !Query::EventHasOther(), &found);
537 EXPECT_EQ(1u, found.size()); 589 EXPECT_EQ(1u, found.size());
538 590
539 // cat6 has no other_event. 591 // cat6 has no other_event.
540 analyzer->FindEvents(Query::EventCategory() == Query::String("cat6") && 592 analyzer->FindEvents(Query::EventCategory() == Query::String("cat6") &&
541 !Query::EventHasOther(), &found); 593 !Query::EventHasOther(), &found);
542 EXPECT_EQ(1u, found.size()); 594 EXPECT_EQ(1u, found.size());
543 595
544 // cat2 and cat4 are a associated. 596 // cat2 and cat4 are associated.
545 analyzer->FindEvents(Query::EventCategory() == Query::String("cat2") && 597 analyzer->FindEvents(Query::EventCategory() == Query::String("cat2") &&
546 Query::OtherCategory() == Query::String("cat4"), &found); 598 Query::OtherCategory() == Query::String("cat4"), &found);
547 EXPECT_EQ(1u, found.size()); 599 EXPECT_EQ(1u, found.size());
548 600
549 // cat4 and cat2 are a associated. 601 // cat4 and cat2 are not associated.
550 analyzer->FindEvents(Query::EventCategory() == Query::String("cat4") && 602 analyzer->FindEvents(Query::EventCategory() == Query::String("cat4") &&
551 Query::OtherCategory() == Query::String("cat2"), &found); 603 Query::OtherCategory() == Query::String("cat2"), &found);
552 EXPECT_EQ(1u, found.size()); 604 EXPECT_EQ(0u, found.size());
553 605
554 // cat3 and cat5 are a associated. 606 // cat3 and cat5 are associated.
555 analyzer->FindEvents(Query::EventCategory() == Query::String("cat3") && 607 analyzer->FindEvents(Query::EventCategory() == Query::String("cat3") &&
556 Query::OtherCategory() == Query::String("cat5"), &found); 608 Query::OtherCategory() == Query::String("cat5"), &found);
557 EXPECT_EQ(1u, found.size()); 609 EXPECT_EQ(1u, found.size());
558 610
559 // cat5 and cat3 are a associated. 611 // cat5 and cat3 are not associated.
560 analyzer->FindEvents(Query::EventCategory() == Query::String("cat5") && 612 analyzer->FindEvents(Query::EventCategory() == Query::String("cat5") &&
561 Query::OtherCategory() == Query::String("cat3"), &found); 613 Query::OtherCategory() == Query::String("cat3"), &found);
562 EXPECT_EQ(1u, found.size()); 614 EXPECT_EQ(0u, found.size());
563 } 615 }
564 616
565 // Verify that Query literals and types are properly casted. 617 // Verify that Query literals and types are properly casted.
566 TEST_F(TraceEventAnalyzerTest, Literals) { 618 TEST_F(TraceEventAnalyzerTest, Literals) {
567 ManualSetUp(); 619 ManualSetUp();
568 620
569 // Since these queries don't refer to the event data, the dummy event below 621 // Since these queries don't refer to the event data, the dummy event below
570 // will never be accessed. 622 // will never be accessed.
571 TraceEvent dummy; 623 TraceEvent dummy;
572 char char_num = 5; 624 char char_num = 5;
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 EXPECT_EQ(num_events, CountMatches(event_ptrs, Query::Bool(true))); 785 EXPECT_EQ(num_events, CountMatches(event_ptrs, Query::Bool(true)));
734 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, Query::Bool(true), 786 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, Query::Bool(true),
735 1, num_events)); 787 1, num_events));
736 EXPECT_EQ(1u, CountMatches(event_ptrs, query_one)); 788 EXPECT_EQ(1u, CountMatches(event_ptrs, query_one));
737 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, !query_one)); 789 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, !query_one));
738 EXPECT_EQ(num_named, CountMatches(event_ptrs, query_named)); 790 EXPECT_EQ(num_named, CountMatches(event_ptrs, query_named));
739 } 791 }
740 792
741 793
742 } // namespace trace_analyzer 794 } // namespace trace_analyzer
OLDNEW
« no previous file with comments | « base/test/trace_event_analyzer.cc ('k') | chrome/browser/resources/tracing/tests/async_begin_end.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698