| 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 // Test that normal string arguments are copied. |
| 476 tracer->SetEnabled(true); |
| 477 TRACE_EVENT2("cat", "name1", "arg1", "argval", "arg2", "argval"); |
| 478 size_t num_events = tracer->GetEventsSize(); |
| 479 EXPECT_GT(num_events, 0u); |
| 480 const TraceEvent& event = tracer->GetEventAt(num_events - 1); |
| 481 EXPECT_STREQ("name1", event.name()); |
| 482 EXPECT_TRUE(event.parameter_copy_storage() != NULL); |
| 483 EXPECT_GT(event.parameter_copy_storage()->size(), 0u); |
| 484 tracer->SetEnabled(false); |
| 485 } |
| 486 |
| 487 { |
| 488 // Test that static string arguments are not copied. |
| 489 tracer->SetEnabled(true); |
| 490 TRACE_EVENT2("cat", "name2", "arg1", TRACE_STATIC_STR("argval"), |
| 491 "arg2", TRACE_STATIC_STR("argval")); |
| 492 size_t num_events = tracer->GetEventsSize(); |
| 493 EXPECT_GT(num_events, 0u); |
| 494 const TraceEvent& event = tracer->GetEventAt(num_events - 1); |
| 495 EXPECT_STREQ("name2", event.name()); |
| 496 EXPECT_TRUE(event.parameter_copy_storage() == NULL); |
| 497 tracer->SetEnabled(false); |
| 498 } |
| 499 } |
| 500 |
| 465 // Test that data sent from other threads is gathered | 501 // Test that data sent from other threads is gathered |
| 466 TEST_F(TraceEventTestFixture, DataCapturedOnThread) { | 502 TEST_F(TraceEventTestFixture, DataCapturedOnThread) { |
| 467 ManualTestSetUp(); | 503 ManualTestSetUp(); |
| 468 TraceLog::GetInstance()->SetEnabled(true); | 504 TraceLog::GetInstance()->SetEnabled(true); |
| 469 | 505 |
| 470 Thread thread("1"); | 506 Thread thread("1"); |
| 471 WaitableEvent task_complete_event(false, false); | 507 WaitableEvent task_complete_event(false, false); |
| 472 thread.Start(); | 508 thread.Start(); |
| 473 | 509 |
| 474 thread.message_loop()->PostTask( | 510 thread.message_loop()->PostTask( |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 | 746 |
| 711 std::string s; | 747 std::string s; |
| 712 EXPECT_TRUE(entry3->GetString("args.arg1", &s)); | 748 EXPECT_TRUE(entry3->GetString("args.arg1", &s)); |
| 713 EXPECT_EQ("val1", s); | 749 EXPECT_EQ("val1", s); |
| 714 EXPECT_TRUE(entry3->GetString("args.arg2", &s)); | 750 EXPECT_TRUE(entry3->GetString("args.arg2", &s)); |
| 715 EXPECT_EQ("val2", s); | 751 EXPECT_EQ("val2", s); |
| 716 } | 752 } |
| 717 | 753 |
| 718 } // namespace debug | 754 } // namespace debug |
| 719 } // namespace base | 755 } // namespace base |
| OLD | NEW |