| OLD | NEW |
| 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/test/trace_event_analyzer.h" |
| 6 |
| 5 #include <stddef.h> | 7 #include <stddef.h> |
| 6 #include <stdint.h> | 8 #include <stdint.h> |
| 7 | 9 |
| 8 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/memory/ptr_util.h" |
| 9 #include "base/memory/ref_counted_memory.h" | 12 #include "base/memory/ref_counted_memory.h" |
| 10 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
| 11 #include "base/test/trace_event_analyzer.h" | |
| 12 #include "base/threading/platform_thread.h" | 14 #include "base/threading/platform_thread.h" |
| 13 #include "base/trace_event/trace_buffer.h" | 15 #include "base/trace_event/trace_buffer.h" |
| 14 #include "base/trace_event/trace_event_argument.h" | 16 #include "base/trace_event/trace_event_argument.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 19 |
| 18 namespace trace_analyzer { | 20 namespace trace_analyzer { |
| 19 | 21 |
| 20 namespace { | 22 namespace { |
| 21 | 23 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 71 |
| 70 } // namespace | 72 } // namespace |
| 71 | 73 |
| 72 TEST_F(TraceEventAnalyzerTest, NoEvents) { | 74 TEST_F(TraceEventAnalyzerTest, NoEvents) { |
| 73 ManualSetUp(); | 75 ManualSetUp(); |
| 74 | 76 |
| 75 // Create an empty JSON event string: | 77 // Create an empty JSON event string: |
| 76 buffer_.Start(); | 78 buffer_.Start(); |
| 77 buffer_.Finish(); | 79 buffer_.Finish(); |
| 78 | 80 |
| 79 scoped_ptr<TraceAnalyzer> | 81 std::unique_ptr<TraceAnalyzer> analyzer( |
| 80 analyzer(TraceAnalyzer::Create(output_.json_output)); | 82 TraceAnalyzer::Create(output_.json_output)); |
| 81 ASSERT_TRUE(analyzer.get()); | 83 ASSERT_TRUE(analyzer.get()); |
| 82 | 84 |
| 83 // Search for all events and verify that nothing is returned. | 85 // Search for all events and verify that nothing is returned. |
| 84 TraceEventVector found; | 86 TraceEventVector found; |
| 85 analyzer->FindEvents(Query::Bool(true), &found); | 87 analyzer->FindEvents(Query::Bool(true), &found); |
| 86 EXPECT_EQ(0u, found.size()); | 88 EXPECT_EQ(0u, found.size()); |
| 87 } | 89 } |
| 88 | 90 |
| 89 TEST_F(TraceEventAnalyzerTest, TraceEvent) { | 91 TEST_F(TraceEventAnalyzerTest, TraceEvent) { |
| 90 ManualSetUp(); | 92 ManualSetUp(); |
| 91 | 93 |
| 92 int int_num = 2; | 94 int int_num = 2; |
| 93 double double_num = 3.5; | 95 double double_num = 3.5; |
| 94 const char str[] = "the string"; | 96 const char str[] = "the string"; |
| 95 | 97 |
| 96 TraceEvent event; | 98 TraceEvent event; |
| 97 event.arg_numbers["false"] = 0.0; | 99 event.arg_numbers["false"] = 0.0; |
| 98 event.arg_numbers["true"] = 1.0; | 100 event.arg_numbers["true"] = 1.0; |
| 99 event.arg_numbers["int"] = static_cast<double>(int_num); | 101 event.arg_numbers["int"] = static_cast<double>(int_num); |
| 100 event.arg_numbers["double"] = double_num; | 102 event.arg_numbers["double"] = double_num; |
| 101 event.arg_strings["string"] = str; | 103 event.arg_strings["string"] = str; |
| 102 event.arg_values["dict"] = make_scoped_ptr(new base::DictionaryValue()); | 104 event.arg_values["dict"] = base::WrapUnique(new base::DictionaryValue()); |
| 103 | 105 |
| 104 ASSERT_TRUE(event.HasNumberArg("false")); | 106 ASSERT_TRUE(event.HasNumberArg("false")); |
| 105 ASSERT_TRUE(event.HasNumberArg("true")); | 107 ASSERT_TRUE(event.HasNumberArg("true")); |
| 106 ASSERT_TRUE(event.HasNumberArg("int")); | 108 ASSERT_TRUE(event.HasNumberArg("int")); |
| 107 ASSERT_TRUE(event.HasNumberArg("double")); | 109 ASSERT_TRUE(event.HasNumberArg("double")); |
| 108 ASSERT_TRUE(event.HasStringArg("string")); | 110 ASSERT_TRUE(event.HasStringArg("string")); |
| 109 ASSERT_FALSE(event.HasNumberArg("notfound")); | 111 ASSERT_FALSE(event.HasNumberArg("notfound")); |
| 110 ASSERT_FALSE(event.HasStringArg("notfound")); | 112 ASSERT_FALSE(event.HasStringArg("notfound")); |
| 111 ASSERT_TRUE(event.HasArg("dict")); | 113 ASSERT_TRUE(event.HasArg("dict")); |
| 112 ASSERT_FALSE(event.HasArg("notfound")); | 114 ASSERT_FALSE(event.HasArg("notfound")); |
| 113 | 115 |
| 114 EXPECT_FALSE(event.GetKnownArgAsBool("false")); | 116 EXPECT_FALSE(event.GetKnownArgAsBool("false")); |
| 115 EXPECT_TRUE(event.GetKnownArgAsBool("true")); | 117 EXPECT_TRUE(event.GetKnownArgAsBool("true")); |
| 116 EXPECT_EQ(int_num, event.GetKnownArgAsInt("int")); | 118 EXPECT_EQ(int_num, event.GetKnownArgAsInt("int")); |
| 117 EXPECT_EQ(double_num, event.GetKnownArgAsDouble("double")); | 119 EXPECT_EQ(double_num, event.GetKnownArgAsDouble("double")); |
| 118 EXPECT_STREQ(str, event.GetKnownArgAsString("string").c_str()); | 120 EXPECT_STREQ(str, event.GetKnownArgAsString("string").c_str()); |
| 119 | 121 |
| 120 scoped_ptr<base::Value> arg; | 122 std::unique_ptr<base::Value> arg; |
| 121 EXPECT_TRUE(event.GetArgAsValue("dict", &arg)); | 123 EXPECT_TRUE(event.GetArgAsValue("dict", &arg)); |
| 122 EXPECT_EQ(base::Value::TYPE_DICTIONARY, arg->GetType()); | 124 EXPECT_EQ(base::Value::TYPE_DICTIONARY, arg->GetType()); |
| 123 } | 125 } |
| 124 | 126 |
| 125 TEST_F(TraceEventAnalyzerTest, QueryEventMember) { | 127 TEST_F(TraceEventAnalyzerTest, QueryEventMember) { |
| 126 ManualSetUp(); | 128 ManualSetUp(); |
| 127 | 129 |
| 128 TraceEvent event; | 130 TraceEvent event; |
| 129 event.thread.process_id = 3; | 131 event.thread.process_id = 3; |
| 130 event.thread.thread_id = 4; | 132 event.thread.thread_id = 4; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 | 230 |
| 229 BeginTracing(); | 231 BeginTracing(); |
| 230 { | 232 { |
| 231 TRACE_EVENT_INSTANT1("cat1", "name1", TRACE_EVENT_SCOPE_THREAD, "num", 1); | 233 TRACE_EVENT_INSTANT1("cat1", "name1", TRACE_EVENT_SCOPE_THREAD, "num", 1); |
| 232 TRACE_EVENT_INSTANT1("cat1", "name2", TRACE_EVENT_SCOPE_THREAD, "num", 2); | 234 TRACE_EVENT_INSTANT1("cat1", "name2", TRACE_EVENT_SCOPE_THREAD, "num", 2); |
| 233 TRACE_EVENT_INSTANT1("cat2", "name3", TRACE_EVENT_SCOPE_THREAD, "num", 3); | 235 TRACE_EVENT_INSTANT1("cat2", "name3", TRACE_EVENT_SCOPE_THREAD, "num", 3); |
| 234 TRACE_EVENT_INSTANT1("cat2", "name4", TRACE_EVENT_SCOPE_THREAD, "num", 4); | 236 TRACE_EVENT_INSTANT1("cat2", "name4", TRACE_EVENT_SCOPE_THREAD, "num", 4); |
| 235 } | 237 } |
| 236 EndTracing(); | 238 EndTracing(); |
| 237 | 239 |
| 238 scoped_ptr<TraceAnalyzer> | 240 std::unique_ptr<TraceAnalyzer> analyzer( |
| 239 analyzer(TraceAnalyzer::Create(output_.json_output)); | 241 TraceAnalyzer::Create(output_.json_output)); |
| 240 ASSERT_TRUE(analyzer); | 242 ASSERT_TRUE(analyzer); |
| 241 analyzer->SetIgnoreMetadataEvents(true); | 243 analyzer->SetIgnoreMetadataEvents(true); |
| 242 | 244 |
| 243 TraceEventVector found; | 245 TraceEventVector found; |
| 244 | 246 |
| 245 // == | 247 // == |
| 246 | 248 |
| 247 analyzer->FindEvents(Query::EventCategory() == Query::String("cat1"), &found); | 249 analyzer->FindEvents(Query::EventCategory() == Query::String("cat1"), &found); |
| 248 ASSERT_EQ(2u, found.size()); | 250 ASSERT_EQ(2u, found.size()); |
| 249 EXPECT_STREQ("name1", found[0]->name.c_str()); | 251 EXPECT_STREQ("name1", found[0]->name.c_str()); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 TRACE_EVENT_INSTANT2("cat1", "math2", TRACE_EVENT_SCOPE_THREAD, | 321 TRACE_EVENT_INSTANT2("cat1", "math2", TRACE_EVENT_SCOPE_THREAD, |
| 320 "a", 10, "b", 10); | 322 "a", 10, "b", 10); |
| 321 // Extra events that never match, for noise: | 323 // Extra events that never match, for noise: |
| 322 TRACE_EVENT_INSTANT2("noise", "math3", TRACE_EVENT_SCOPE_THREAD, | 324 TRACE_EVENT_INSTANT2("noise", "math3", TRACE_EVENT_SCOPE_THREAD, |
| 323 "a", 1, "b", 3); | 325 "a", 1, "b", 3); |
| 324 TRACE_EVENT_INSTANT2("noise", "math4", TRACE_EVENT_SCOPE_THREAD, | 326 TRACE_EVENT_INSTANT2("noise", "math4", TRACE_EVENT_SCOPE_THREAD, |
| 325 "c", 10, "d", 5); | 327 "c", 10, "d", 5); |
| 326 } | 328 } |
| 327 EndTracing(); | 329 EndTracing(); |
| 328 | 330 |
| 329 scoped_ptr<TraceAnalyzer> | 331 std::unique_ptr<TraceAnalyzer> analyzer( |
| 330 analyzer(TraceAnalyzer::Create(output_.json_output)); | 332 TraceAnalyzer::Create(output_.json_output)); |
| 331 ASSERT_TRUE(analyzer.get()); | 333 ASSERT_TRUE(analyzer.get()); |
| 332 | 334 |
| 333 TraceEventVector found; | 335 TraceEventVector found; |
| 334 | 336 |
| 335 // Verify that arithmetic operators function: | 337 // Verify that arithmetic operators function: |
| 336 | 338 |
| 337 // + | 339 // + |
| 338 analyzer->FindEvents(Query::EventArg("a") + Query::EventArg("b") == | 340 analyzer->FindEvents(Query::EventArg("a") + Query::EventArg("b") == |
| 339 Query::Int(20), &found); | 341 Query::Int(20), &found); |
| 340 EXPECT_EQ(1u, found.size()); | 342 EXPECT_EQ(1u, found.size()); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 | 376 |
| 375 BeginTracing(); | 377 BeginTracing(); |
| 376 { | 378 { |
| 377 TRACE_EVENT_INSTANT0("cat1", "name1", TRACE_EVENT_SCOPE_THREAD); | 379 TRACE_EVENT_INSTANT0("cat1", "name1", TRACE_EVENT_SCOPE_THREAD); |
| 378 TRACE_EVENT_INSTANT0("cat1", "name2", TRACE_EVENT_SCOPE_THREAD); | 380 TRACE_EVENT_INSTANT0("cat1", "name2", TRACE_EVENT_SCOPE_THREAD); |
| 379 TRACE_EVENT_INSTANT0("cat1", "no match", TRACE_EVENT_SCOPE_THREAD); | 381 TRACE_EVENT_INSTANT0("cat1", "no match", TRACE_EVENT_SCOPE_THREAD); |
| 380 TRACE_EVENT_INSTANT0("cat1", "name3x", TRACE_EVENT_SCOPE_THREAD); | 382 TRACE_EVENT_INSTANT0("cat1", "name3x", TRACE_EVENT_SCOPE_THREAD); |
| 381 } | 383 } |
| 382 EndTracing(); | 384 EndTracing(); |
| 383 | 385 |
| 384 scoped_ptr<TraceAnalyzer> | 386 std::unique_ptr<TraceAnalyzer> analyzer( |
| 385 analyzer(TraceAnalyzer::Create(output_.json_output)); | 387 TraceAnalyzer::Create(output_.json_output)); |
| 386 ASSERT_TRUE(analyzer.get()); | 388 ASSERT_TRUE(analyzer.get()); |
| 387 analyzer->SetIgnoreMetadataEvents(true); | 389 analyzer->SetIgnoreMetadataEvents(true); |
| 388 | 390 |
| 389 TraceEventVector found; | 391 TraceEventVector found; |
| 390 | 392 |
| 391 analyzer->FindEvents(Query::EventName() == Query::Pattern("name?"), &found); | 393 analyzer->FindEvents(Query::EventName() == Query::Pattern("name?"), &found); |
| 392 ASSERT_EQ(2u, found.size()); | 394 ASSERT_EQ(2u, found.size()); |
| 393 EXPECT_STREQ("name1", found[0]->name.c_str()); | 395 EXPECT_STREQ("name1", found[0]->name.c_str()); |
| 394 EXPECT_STREQ("name2", found[1]->name.c_str()); | 396 EXPECT_STREQ("name2", found[1]->name.c_str()); |
| 395 | 397 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 424 base::PlatformThread::Sleep(kSleepTime); | 426 base::PlatformThread::Sleep(kSleepTime); |
| 425 TRACE_EVENT_BEGIN0("cat2", "name5"); // not found (duration too short) | 427 TRACE_EVENT_BEGIN0("cat2", "name5"); // not found (duration too short) |
| 426 TRACE_EVENT_END0("cat2", "name5"); // not found (duration too short) | 428 TRACE_EVENT_END0("cat2", "name5"); // not found (duration too short) |
| 427 TRACE_EVENT_END0("cat2", "name3"); // found by duration query | 429 TRACE_EVENT_END0("cat2", "name3"); // found by duration query |
| 428 } | 430 } |
| 429 TRACE_EVENT_END0("noise", "name2"); // not searched for, just noise | 431 TRACE_EVENT_END0("noise", "name2"); // not searched for, just noise |
| 430 TRACE_EVENT_END0("cat1", "name1"); // found by duration query | 432 TRACE_EVENT_END0("cat1", "name1"); // found by duration query |
| 431 } | 433 } |
| 432 EndTracing(); | 434 EndTracing(); |
| 433 | 435 |
| 434 scoped_ptr<TraceAnalyzer> | 436 std::unique_ptr<TraceAnalyzer> analyzer( |
| 435 analyzer(TraceAnalyzer::Create(output_.json_output)); | 437 TraceAnalyzer::Create(output_.json_output)); |
| 436 ASSERT_TRUE(analyzer.get()); | 438 ASSERT_TRUE(analyzer.get()); |
| 437 analyzer->AssociateBeginEndEvents(); | 439 analyzer->AssociateBeginEndEvents(); |
| 438 | 440 |
| 439 TraceEventVector found; | 441 TraceEventVector found; |
| 440 analyzer->FindEvents( | 442 analyzer->FindEvents( |
| 441 Query::MatchBeginWithEnd() && | 443 Query::MatchBeginWithEnd() && |
| 442 Query::EventDuration() > | 444 Query::EventDuration() > |
| 443 Query::Int(static_cast<int>(duration_cutoff_us)) && | 445 Query::Int(static_cast<int>(duration_cutoff_us)) && |
| 444 (Query::EventCategory() == Query::String("cat1") || | 446 (Query::EventCategory() == Query::String("cat1") || |
| 445 Query::EventCategory() == Query::String("cat2") || | 447 Query::EventCategory() == Query::String("cat2") || |
| (...skipping 20 matching lines...) Expand all Loading... |
| 466 { | 468 { |
| 467 TRACE_EVENT0("cat2", "name3"); // found by duration query | 469 TRACE_EVENT0("cat2", "name3"); // found by duration query |
| 468 // next event not searched for, just noise | 470 // next event not searched for, just noise |
| 469 TRACE_EVENT_INSTANT0("noise", "name4", TRACE_EVENT_SCOPE_THREAD); | 471 TRACE_EVENT_INSTANT0("noise", "name4", TRACE_EVENT_SCOPE_THREAD); |
| 470 base::PlatformThread::Sleep(kSleepTime); | 472 base::PlatformThread::Sleep(kSleepTime); |
| 471 TRACE_EVENT0("cat2", "name5"); // not found (duration too short) | 473 TRACE_EVENT0("cat2", "name5"); // not found (duration too short) |
| 472 } | 474 } |
| 473 } | 475 } |
| 474 EndTracing(); | 476 EndTracing(); |
| 475 | 477 |
| 476 scoped_ptr<TraceAnalyzer> | 478 std::unique_ptr<TraceAnalyzer> analyzer( |
| 477 analyzer(TraceAnalyzer::Create(output_.json_output)); | 479 TraceAnalyzer::Create(output_.json_output)); |
| 478 ASSERT_TRUE(analyzer.get()); | 480 ASSERT_TRUE(analyzer.get()); |
| 479 analyzer->AssociateBeginEndEvents(); | 481 analyzer->AssociateBeginEndEvents(); |
| 480 | 482 |
| 481 TraceEventVector found; | 483 TraceEventVector found; |
| 482 analyzer->FindEvents( | 484 analyzer->FindEvents( |
| 483 Query::EventCompleteDuration() > | 485 Query::EventCompleteDuration() > |
| 484 Query::Int(static_cast<int>(duration_cutoff_us)) && | 486 Query::Int(static_cast<int>(duration_cutoff_us)) && |
| 485 (Query::EventCategory() == Query::String("cat1") || | 487 (Query::EventCategory() == Query::String("cat1") || |
| 486 Query::EventCategory() == Query::String("cat2") || | 488 Query::EventCategory() == Query::String("cat2") || |
| 487 Query::EventCategory() == Query::String("cat3")), | 489 Query::EventCategory() == Query::String("cat3")), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 498 BeginTracing(); | 500 BeginTracing(); |
| 499 { | 501 { |
| 500 TRACE_EVENT_END0("cat1", "name1"); // does not match out of order begin | 502 TRACE_EVENT_END0("cat1", "name1"); // does not match out of order begin |
| 501 TRACE_EVENT_BEGIN0("cat1", "name2"); | 503 TRACE_EVENT_BEGIN0("cat1", "name2"); |
| 502 TRACE_EVENT_INSTANT0("cat1", "name3", TRACE_EVENT_SCOPE_THREAD); | 504 TRACE_EVENT_INSTANT0("cat1", "name3", TRACE_EVENT_SCOPE_THREAD); |
| 503 TRACE_EVENT_BEGIN0("cat1", "name1"); | 505 TRACE_EVENT_BEGIN0("cat1", "name1"); |
| 504 TRACE_EVENT_END0("cat1", "name2"); | 506 TRACE_EVENT_END0("cat1", "name2"); |
| 505 } | 507 } |
| 506 EndTracing(); | 508 EndTracing(); |
| 507 | 509 |
| 508 scoped_ptr<TraceAnalyzer> | 510 std::unique_ptr<TraceAnalyzer> analyzer( |
| 509 analyzer(TraceAnalyzer::Create(output_.json_output)); | 511 TraceAnalyzer::Create(output_.json_output)); |
| 510 ASSERT_TRUE(analyzer.get()); | 512 ASSERT_TRUE(analyzer.get()); |
| 511 analyzer->AssociateBeginEndEvents(); | 513 analyzer->AssociateBeginEndEvents(); |
| 512 | 514 |
| 513 TraceEventVector found; | 515 TraceEventVector found; |
| 514 analyzer->FindEvents(Query::MatchBeginWithEnd(), &found); | 516 analyzer->FindEvents(Query::MatchBeginWithEnd(), &found); |
| 515 ASSERT_EQ(1u, found.size()); | 517 ASSERT_EQ(1u, found.size()); |
| 516 EXPECT_STREQ("name2", found[0]->name.c_str()); | 518 EXPECT_STREQ("name2", found[0]->name.c_str()); |
| 517 } | 519 } |
| 518 | 520 |
| 519 // Test MergeAssociatedEventArgs | 521 // Test MergeAssociatedEventArgs |
| 520 TEST_F(TraceEventAnalyzerTest, MergeAssociatedEventArgs) { | 522 TEST_F(TraceEventAnalyzerTest, MergeAssociatedEventArgs) { |
| 521 ManualSetUp(); | 523 ManualSetUp(); |
| 522 | 524 |
| 523 const char arg_string[] = "arg_string"; | 525 const char arg_string[] = "arg_string"; |
| 524 BeginTracing(); | 526 BeginTracing(); |
| 525 { | 527 { |
| 526 TRACE_EVENT_BEGIN0("cat1", "name1"); | 528 TRACE_EVENT_BEGIN0("cat1", "name1"); |
| 527 TRACE_EVENT_END1("cat1", "name1", "arg", arg_string); | 529 TRACE_EVENT_END1("cat1", "name1", "arg", arg_string); |
| 528 } | 530 } |
| 529 EndTracing(); | 531 EndTracing(); |
| 530 | 532 |
| 531 scoped_ptr<TraceAnalyzer> | 533 std::unique_ptr<TraceAnalyzer> analyzer( |
| 532 analyzer(TraceAnalyzer::Create(output_.json_output)); | 534 TraceAnalyzer::Create(output_.json_output)); |
| 533 ASSERT_TRUE(analyzer.get()); | 535 ASSERT_TRUE(analyzer.get()); |
| 534 analyzer->AssociateBeginEndEvents(); | 536 analyzer->AssociateBeginEndEvents(); |
| 535 | 537 |
| 536 TraceEventVector found; | 538 TraceEventVector found; |
| 537 analyzer->FindEvents(Query::MatchBeginName("name1"), &found); | 539 analyzer->FindEvents(Query::MatchBeginName("name1"), &found); |
| 538 ASSERT_EQ(1u, found.size()); | 540 ASSERT_EQ(1u, found.size()); |
| 539 std::string arg_actual; | 541 std::string arg_actual; |
| 540 EXPECT_FALSE(found[0]->GetArgAsString("arg", &arg_actual)); | 542 EXPECT_FALSE(found[0]->GetArgAsString("arg", &arg_actual)); |
| 541 | 543 |
| 542 analyzer->MergeAssociatedEventArgs(); | 544 analyzer->MergeAssociatedEventArgs(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 554 TRACE_EVENT_ASYNC_BEGIN0("cat1", "name1", 0xB); | 556 TRACE_EVENT_ASYNC_BEGIN0("cat1", "name1", 0xB); |
| 555 TRACE_EVENT_ASYNC_BEGIN0("cat1", "name1", 0xC); | 557 TRACE_EVENT_ASYNC_BEGIN0("cat1", "name1", 0xC); |
| 556 TRACE_EVENT_INSTANT0("cat1", "name1", TRACE_EVENT_SCOPE_THREAD); // noise | 558 TRACE_EVENT_INSTANT0("cat1", "name1", TRACE_EVENT_SCOPE_THREAD); // noise |
| 557 TRACE_EVENT0("cat1", "name1"); // noise | 559 TRACE_EVENT0("cat1", "name1"); // noise |
| 558 TRACE_EVENT_ASYNC_END0("cat1", "name1", 0xB); | 560 TRACE_EVENT_ASYNC_END0("cat1", "name1", 0xB); |
| 559 TRACE_EVENT_ASYNC_END0("cat1", "name1", 0xC); | 561 TRACE_EVENT_ASYNC_END0("cat1", "name1", 0xC); |
| 560 TRACE_EVENT_ASYNC_BEGIN0("cat1", "name1", 0xA); // no match / out of order | 562 TRACE_EVENT_ASYNC_BEGIN0("cat1", "name1", 0xA); // no match / out of order |
| 561 } | 563 } |
| 562 EndTracing(); | 564 EndTracing(); |
| 563 | 565 |
| 564 scoped_ptr<TraceAnalyzer> | 566 std::unique_ptr<TraceAnalyzer> analyzer( |
| 565 analyzer(TraceAnalyzer::Create(output_.json_output)); | 567 TraceAnalyzer::Create(output_.json_output)); |
| 566 ASSERT_TRUE(analyzer.get()); | 568 ASSERT_TRUE(analyzer.get()); |
| 567 analyzer->AssociateAsyncBeginEndEvents(); | 569 analyzer->AssociateAsyncBeginEndEvents(); |
| 568 | 570 |
| 569 TraceEventVector found; | 571 TraceEventVector found; |
| 570 analyzer->FindEvents(Query::MatchAsyncBeginWithNext(), &found); | 572 analyzer->FindEvents(Query::MatchAsyncBeginWithNext(), &found); |
| 571 ASSERT_EQ(2u, found.size()); | 573 ASSERT_EQ(2u, found.size()); |
| 572 EXPECT_STRCASEEQ("0xb", found[0]->id.c_str()); | 574 EXPECT_STRCASEEQ("0xb", found[0]->id.c_str()); |
| 573 EXPECT_STRCASEEQ("0xc", found[1]->id.c_str()); | 575 EXPECT_STRCASEEQ("0xc", found[1]->id.c_str()); |
| 574 } | 576 } |
| 575 | 577 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 586 TRACE_EVENT_ASYNC_STEP_PAST0("c", "n", 0xB, "s1"); | 588 TRACE_EVENT_ASYNC_STEP_PAST0("c", "n", 0xB, "s1"); |
| 587 TRACE_EVENT_ASYNC_STEP_INTO0("c", "n", 0xC, "s1"); | 589 TRACE_EVENT_ASYNC_STEP_INTO0("c", "n", 0xC, "s1"); |
| 588 TRACE_EVENT_ASYNC_STEP_INTO1("c", "n", 0xC, "s2", "a", 1); | 590 TRACE_EVENT_ASYNC_STEP_INTO1("c", "n", 0xC, "s2", "a", 1); |
| 589 TRACE_EVENT_ASYNC_END0("c", "n", 0xB); | 591 TRACE_EVENT_ASYNC_END0("c", "n", 0xB); |
| 590 TRACE_EVENT_ASYNC_END0("c", "n", 0xC); | 592 TRACE_EVENT_ASYNC_END0("c", "n", 0xC); |
| 591 TRACE_EVENT_ASYNC_BEGIN0("c", "n", 0xA); | 593 TRACE_EVENT_ASYNC_BEGIN0("c", "n", 0xA); |
| 592 TRACE_EVENT_ASYNC_STEP_INTO0("c", "n", 0xA, "s2"); | 594 TRACE_EVENT_ASYNC_STEP_INTO0("c", "n", 0xA, "s2"); |
| 593 } | 595 } |
| 594 EndTracing(); | 596 EndTracing(); |
| 595 | 597 |
| 596 scoped_ptr<TraceAnalyzer> | 598 std::unique_ptr<TraceAnalyzer> analyzer( |
| 597 analyzer(TraceAnalyzer::Create(output_.json_output)); | 599 TraceAnalyzer::Create(output_.json_output)); |
| 598 ASSERT_TRUE(analyzer.get()); | 600 ASSERT_TRUE(analyzer.get()); |
| 599 analyzer->AssociateAsyncBeginEndEvents(); | 601 analyzer->AssociateAsyncBeginEndEvents(); |
| 600 | 602 |
| 601 TraceEventVector found; | 603 TraceEventVector found; |
| 602 analyzer->FindEvents(Query::MatchAsyncBeginWithNext(), &found); | 604 analyzer->FindEvents(Query::MatchAsyncBeginWithNext(), &found); |
| 603 ASSERT_EQ(3u, found.size()); | 605 ASSERT_EQ(3u, found.size()); |
| 604 | 606 |
| 605 EXPECT_STRCASEEQ("0xb", found[0]->id.c_str()); | 607 EXPECT_STRCASEEQ("0xb", found[0]->id.c_str()); |
| 606 EXPECT_EQ(TRACE_EVENT_PHASE_ASYNC_STEP_PAST, found[0]->other_event->phase); | 608 EXPECT_EQ(TRACE_EVENT_PHASE_ASYNC_STEP_PAST, found[0]->other_event->phase); |
| 607 EXPECT_TRUE(found[0]->other_event->other_event); | 609 EXPECT_TRUE(found[0]->other_event->other_event); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 TRACE_EVENT_INSTANT1("cat2", "begin", TRACE_EVENT_SCOPE_THREAD, "id", 2); | 641 TRACE_EVENT_INSTANT1("cat2", "begin", TRACE_EVENT_SCOPE_THREAD, "id", 2); |
| 640 // end is cat5 | 642 // end is cat5 |
| 641 TRACE_EVENT_INSTANT1("cat3", "begin", TRACE_EVENT_SCOPE_THREAD, "id", 3); | 643 TRACE_EVENT_INSTANT1("cat3", "begin", TRACE_EVENT_SCOPE_THREAD, "id", 3); |
| 642 TRACE_EVENT_INSTANT1("cat4", "end", TRACE_EVENT_SCOPE_THREAD, "id", 2); | 644 TRACE_EVENT_INSTANT1("cat4", "end", TRACE_EVENT_SCOPE_THREAD, "id", 2); |
| 643 TRACE_EVENT_INSTANT1("cat5", "end", TRACE_EVENT_SCOPE_THREAD, "id", 3); | 645 TRACE_EVENT_INSTANT1("cat5", "end", TRACE_EVENT_SCOPE_THREAD, "id", 3); |
| 644 // no end match | 646 // no end match |
| 645 TRACE_EVENT_INSTANT1("cat6", "begin", TRACE_EVENT_SCOPE_THREAD, "id", 1); | 647 TRACE_EVENT_INSTANT1("cat6", "begin", TRACE_EVENT_SCOPE_THREAD, "id", 1); |
| 646 } | 648 } |
| 647 EndTracing(); | 649 EndTracing(); |
| 648 | 650 |
| 649 scoped_ptr<TraceAnalyzer> | 651 std::unique_ptr<TraceAnalyzer> analyzer( |
| 650 analyzer(TraceAnalyzer::Create(output_.json_output)); | 652 TraceAnalyzer::Create(output_.json_output)); |
| 651 ASSERT_TRUE(analyzer.get()); | 653 ASSERT_TRUE(analyzer.get()); |
| 652 | 654 |
| 653 // begin, end, and match queries to find proper begin/end pairs. | 655 // begin, end, and match queries to find proper begin/end pairs. |
| 654 Query begin(Query::EventName() == Query::String("begin")); | 656 Query begin(Query::EventName() == Query::String("begin")); |
| 655 Query end(Query::EventName() == Query::String("end")); | 657 Query end(Query::EventName() == Query::String("end")); |
| 656 Query match(Query::EventArg("id") == Query::OtherArg("id")); | 658 Query match(Query::EventArg("id") == Query::OtherArg("id")); |
| 657 analyzer->AssociateEvents(begin, end, match); | 659 analyzer->AssociateEvents(begin, end, match); |
| 658 | 660 |
| 659 TraceEventVector found; | 661 TraceEventVector found; |
| 660 | 662 |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 913 EXPECT_EQ(1u, CountMatches(event_ptrs, query_one)); | 915 EXPECT_EQ(1u, CountMatches(event_ptrs, query_one)); |
| 914 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, !query_one)); | 916 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, !query_one)); |
| 915 EXPECT_EQ(num_named, CountMatches(event_ptrs, query_named)); | 917 EXPECT_EQ(num_named, CountMatches(event_ptrs, query_named)); |
| 916 } | 918 } |
| 917 | 919 |
| 918 TEST_F(TraceEventAnalyzerTest, ComplexArgument) { | 920 TEST_F(TraceEventAnalyzerTest, ComplexArgument) { |
| 919 ManualSetUp(); | 921 ManualSetUp(); |
| 920 | 922 |
| 921 BeginTracing(); | 923 BeginTracing(); |
| 922 { | 924 { |
| 923 scoped_ptr<base::trace_event::TracedValue> value( | 925 std::unique_ptr<base::trace_event::TracedValue> value( |
| 924 new base::trace_event::TracedValue); | 926 new base::trace_event::TracedValue); |
| 925 value->SetString("property", "value"); | 927 value->SetString("property", "value"); |
| 926 TRACE_EVENT1("cat", "name", "arg", std::move(value)); | 928 TRACE_EVENT1("cat", "name", "arg", std::move(value)); |
| 927 } | 929 } |
| 928 EndTracing(); | 930 EndTracing(); |
| 929 | 931 |
| 930 scoped_ptr<TraceAnalyzer> analyzer( | 932 std::unique_ptr<TraceAnalyzer> analyzer( |
| 931 TraceAnalyzer::Create(output_.json_output)); | 933 TraceAnalyzer::Create(output_.json_output)); |
| 932 ASSERT_TRUE(analyzer.get()); | 934 ASSERT_TRUE(analyzer.get()); |
| 933 | 935 |
| 934 TraceEventVector events; | 936 TraceEventVector events; |
| 935 analyzer->FindEvents(Query::EventName() == Query::String("name"), &events); | 937 analyzer->FindEvents(Query::EventName() == Query::String("name"), &events); |
| 936 | 938 |
| 937 EXPECT_EQ(1u, events.size()); | 939 EXPECT_EQ(1u, events.size()); |
| 938 EXPECT_EQ("cat", events[0]->category); | 940 EXPECT_EQ("cat", events[0]->category); |
| 939 EXPECT_EQ("name", events[0]->name); | 941 EXPECT_EQ("name", events[0]->name); |
| 940 EXPECT_TRUE(events[0]->HasArg("arg")); | 942 EXPECT_TRUE(events[0]->HasArg("arg")); |
| 941 | 943 |
| 942 scoped_ptr<base::Value> arg; | 944 std::unique_ptr<base::Value> arg; |
| 943 events[0]->GetArgAsValue("arg", &arg); | 945 events[0]->GetArgAsValue("arg", &arg); |
| 944 base::DictionaryValue* arg_dict; | 946 base::DictionaryValue* arg_dict; |
| 945 EXPECT_TRUE(arg->GetAsDictionary(&arg_dict)); | 947 EXPECT_TRUE(arg->GetAsDictionary(&arg_dict)); |
| 946 std::string property; | 948 std::string property; |
| 947 EXPECT_TRUE(arg_dict->GetString("property", &property)); | 949 EXPECT_TRUE(arg_dict->GetString("property", &property)); |
| 948 EXPECT_EQ("value", property); | 950 EXPECT_EQ("value", property); |
| 949 } | 951 } |
| 950 | 952 |
| 951 } // namespace trace_analyzer | 953 } // namespace trace_analyzer |
| OLD | NEW |