OLD | NEW |
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/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| 11 #include "base/memory/ref_counted_memory.h" |
11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
12 #include "base/process_util.h" | 13 #include "base/process_util.h" |
13 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
14 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
15 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
16 #include "base/values.h" | 17 #include "base/values.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 | 20 |
20 namespace base { | 21 namespace base { |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 EXPECT_NOT_FIND_BE_("3thresholdlong2"); | 456 EXPECT_NOT_FIND_BE_("3thresholdlong2"); |
456 | 457 |
457 EXPECT_FIND_BE_("nonthreshold4"); | 458 EXPECT_FIND_BE_("nonthreshold4"); |
458 EXPECT_FIND_BE_("4threshold100"); | 459 EXPECT_FIND_BE_("4threshold100"); |
459 EXPECT_FIND_BE_("4threshold1000"); | 460 EXPECT_FIND_BE_("4threshold1000"); |
460 EXPECT_FIND_BE_("4threshold10000"); | 461 EXPECT_FIND_BE_("4threshold10000"); |
461 EXPECT_NOT_FIND_BE_("4thresholdlong1"); | 462 EXPECT_NOT_FIND_BE_("4thresholdlong1"); |
462 EXPECT_NOT_FIND_BE_("4thresholdlong2"); | 463 EXPECT_NOT_FIND_BE_("4thresholdlong2"); |
463 } | 464 } |
464 | 465 |
| 466 // Test that static strings are not copied. |
| 467 TEST_F(TraceEventTestFixture, StaticStringVsString) { |
| 468 ManualTestSetUp(); |
| 469 TraceLog* tracer = TraceLog::GetInstance(); |
| 470 // Make sure old events are flushed: |
| 471 tracer->SetEnabled(false); |
| 472 EXPECT_EQ(0u, tracer->GetEventsSize()); |
| 473 |
| 474 { |
| 475 tracer->SetEnabled(true); |
| 476 // Test that string arguments are copied. |
| 477 TRACE_EVENT2("cat", "name1", |
| 478 "arg1", std::string("argval"), "arg2", std::string("argval")); |
| 479 // Test that static TRACE_STR_COPY string arguments are copied. |
| 480 TRACE_EVENT2("cat", "name2", |
| 481 "arg1", TRACE_STR_COPY("argval"), |
| 482 "arg2", TRACE_STR_COPY("argval")); |
| 483 size_t num_events = tracer->GetEventsSize(); |
| 484 EXPECT_GT(num_events, 1u); |
| 485 const TraceEvent& event1 = tracer->GetEventAt(num_events - 2); |
| 486 const TraceEvent& event2 = tracer->GetEventAt(num_events - 1); |
| 487 EXPECT_STREQ("name1", event1.name()); |
| 488 EXPECT_STREQ("name2", event2.name()); |
| 489 EXPECT_TRUE(event1.parameter_copy_storage() != NULL); |
| 490 EXPECT_TRUE(event2.parameter_copy_storage() != NULL); |
| 491 EXPECT_GT(event1.parameter_copy_storage()->size(), 0u); |
| 492 EXPECT_GT(event2.parameter_copy_storage()->size(), 0u); |
| 493 tracer->SetEnabled(false); |
| 494 } |
| 495 |
| 496 { |
| 497 tracer->SetEnabled(true); |
| 498 // Test that static literal string arguments are not copied. |
| 499 TRACE_EVENT2("cat", "name1", |
| 500 "arg1", "argval", "arg2", "argval"); |
| 501 // Test that static TRACE_STR_COPY NULL string arguments are not copied. |
| 502 const char* str1 = NULL; |
| 503 const char* str2 = NULL; |
| 504 TRACE_EVENT2("cat", "name2", |
| 505 "arg1", TRACE_STR_COPY(str1), |
| 506 "arg2", TRACE_STR_COPY(str2)); |
| 507 size_t num_events = tracer->GetEventsSize(); |
| 508 EXPECT_GT(num_events, 1u); |
| 509 const TraceEvent& event1 = tracer->GetEventAt(num_events - 2); |
| 510 const TraceEvent& event2 = tracer->GetEventAt(num_events - 1); |
| 511 EXPECT_STREQ("name1", event1.name()); |
| 512 EXPECT_STREQ("name2", event2.name()); |
| 513 EXPECT_TRUE(event1.parameter_copy_storage() == NULL); |
| 514 EXPECT_TRUE(event2.parameter_copy_storage() == NULL); |
| 515 tracer->SetEnabled(false); |
| 516 } |
| 517 } |
| 518 |
465 // Test that data sent from other threads is gathered | 519 // Test that data sent from other threads is gathered |
466 TEST_F(TraceEventTestFixture, DataCapturedOnThread) { | 520 TEST_F(TraceEventTestFixture, DataCapturedOnThread) { |
467 ManualTestSetUp(); | 521 ManualTestSetUp(); |
468 TraceLog::GetInstance()->SetEnabled(true); | 522 TraceLog::GetInstance()->SetEnabled(true); |
469 | 523 |
470 Thread thread("1"); | 524 Thread thread("1"); |
471 WaitableEvent task_complete_event(false, false); | 525 WaitableEvent task_complete_event(false, false); |
472 thread.Start(); | 526 thread.Start(); |
473 | 527 |
474 thread.message_loop()->PostTask( | 528 thread.message_loop()->PostTask( |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 std::string arg1("arg1"); | 731 std::string arg1("arg1"); |
678 std::string arg2("arg2"); | 732 std::string arg2("arg2"); |
679 std::string val1("val1"); | 733 std::string val1("val1"); |
680 std::string val2("val2"); | 734 std::string val2("val2"); |
681 | 735 |
682 TraceLog::GetInstance()->SetEnabled(true); | 736 TraceLog::GetInstance()->SetEnabled(true); |
683 TRACE_EVENT_COPY_INSTANT0("category", name1.c_str()); | 737 TRACE_EVENT_COPY_INSTANT0("category", name1.c_str()); |
684 TRACE_EVENT_COPY_BEGIN1("category", name2.c_str(), | 738 TRACE_EVENT_COPY_BEGIN1("category", name2.c_str(), |
685 arg1.c_str(), 5); | 739 arg1.c_str(), 5); |
686 TRACE_EVENT_COPY_END2("category", name3.c_str(), | 740 TRACE_EVENT_COPY_END2("category", name3.c_str(), |
687 arg1.c_str(), val1.c_str(), | 741 arg1.c_str(), val1, |
688 arg2.c_str(), val2.c_str()); | 742 arg2.c_str(), val2); |
689 | 743 |
690 // As per NormallyNoDeepCopy, modify the strings in place. | 744 // As per NormallyNoDeepCopy, modify the strings in place. |
691 name1[0] = name2[0] = name3[0] = arg1[0] = arg2[0] = val1[0] = val2[0] = '@'; | 745 name1[0] = name2[0] = name3[0] = arg1[0] = arg2[0] = val1[0] = val2[0] = '@'; |
692 | 746 |
693 TraceLog::GetInstance()->SetEnabled(false); | 747 TraceLog::GetInstance()->SetEnabled(false); |
694 | 748 |
695 EXPECT_FALSE(FindTraceEntry(trace_parsed_, name1.c_str())); | 749 EXPECT_FALSE(FindTraceEntry(trace_parsed_, name1.c_str())); |
696 EXPECT_FALSE(FindTraceEntry(trace_parsed_, name2.c_str())); | 750 EXPECT_FALSE(FindTraceEntry(trace_parsed_, name2.c_str())); |
697 EXPECT_FALSE(FindTraceEntry(trace_parsed_, name3.c_str())); | 751 EXPECT_FALSE(FindTraceEntry(trace_parsed_, name3.c_str())); |
698 | 752 |
(...skipping 11 matching lines...) Expand all Loading... |
710 | 764 |
711 std::string s; | 765 std::string s; |
712 EXPECT_TRUE(entry3->GetString("args.arg1", &s)); | 766 EXPECT_TRUE(entry3->GetString("args.arg1", &s)); |
713 EXPECT_EQ("val1", s); | 767 EXPECT_EQ("val1", s); |
714 EXPECT_TRUE(entry3->GetString("args.arg2", &s)); | 768 EXPECT_TRUE(entry3->GetString("args.arg2", &s)); |
715 EXPECT_EQ("val2", s); | 769 EXPECT_EQ("val2", s); |
716 } | 770 } |
717 | 771 |
718 } // namespace debug | 772 } // namespace debug |
719 } // namespace base | 773 } // namespace base |
OLD | NEW |