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

Side by Side Diff: base/debug/trace_event_unittest.cc

Issue 7767014: Added support to trace_event for passing static string arguments without copy (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . 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/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
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 string arguments are copied.
476 tracer->SetEnabled(true);
477 TRACE_EVENT2("cat", "name1",
478 "arg1", std::string("argval"), "arg2", std::string("argval"));
479 size_t num_events = tracer->GetEventsSize();
480 EXPECT_GT(num_events, 0u);
481 const TraceEvent& event = tracer->GetEventAt(num_events - 1);
482 EXPECT_STREQ("name1", event.name());
483 EXPECT_TRUE(event.parameter_copy_storage() != NULL);
484 EXPECT_GT(event.parameter_copy_storage()->size(), 0u);
485 tracer->SetEnabled(false);
486 }
487
488 {
489 // Test that static literal string arguments are not copied.
490 tracer->SetEnabled(true);
491 TRACE_EVENT2("cat", "name2",
492 "arg1", "argval", "arg2", "argval");
493 size_t num_events = tracer->GetEventsSize();
494 EXPECT_GT(num_events, 0u);
495 const TraceEvent& event = tracer->GetEventAt(num_events - 1);
496 EXPECT_STREQ("name2", event.name());
497 EXPECT_TRUE(event.parameter_copy_storage() == NULL);
498 tracer->SetEnabled(false);
499 }
500 }
501
465 // Test that data sent from other threads is gathered 502 // Test that data sent from other threads is gathered
466 TEST_F(TraceEventTestFixture, DataCapturedOnThread) { 503 TEST_F(TraceEventTestFixture, DataCapturedOnThread) {
467 ManualTestSetUp(); 504 ManualTestSetUp();
468 TraceLog::GetInstance()->SetEnabled(true); 505 TraceLog::GetInstance()->SetEnabled(true);
469 506
470 Thread thread("1"); 507 Thread thread("1");
471 WaitableEvent task_complete_event(false, false); 508 WaitableEvent task_complete_event(false, false);
472 thread.Start(); 509 thread.Start();
473 510
474 thread.message_loop()->PostTask( 511 thread.message_loop()->PostTask(
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 std::string arg1("arg1"); 714 std::string arg1("arg1");
678 std::string arg2("arg2"); 715 std::string arg2("arg2");
679 std::string val1("val1"); 716 std::string val1("val1");
680 std::string val2("val2"); 717 std::string val2("val2");
681 718
682 TraceLog::GetInstance()->SetEnabled(true); 719 TraceLog::GetInstance()->SetEnabled(true);
683 TRACE_EVENT_COPY_INSTANT0("category", name1.c_str()); 720 TRACE_EVENT_COPY_INSTANT0("category", name1.c_str());
684 TRACE_EVENT_COPY_BEGIN1("category", name2.c_str(), 721 TRACE_EVENT_COPY_BEGIN1("category", name2.c_str(),
685 arg1.c_str(), 5); 722 arg1.c_str(), 5);
686 TRACE_EVENT_COPY_END2("category", name3.c_str(), 723 TRACE_EVENT_COPY_END2("category", name3.c_str(),
687 arg1.c_str(), val1.c_str(), 724 arg1.c_str(), val1,
688 arg2.c_str(), val2.c_str()); 725 arg2.c_str(), val2);
689 726
690 // As per NormallyNoDeepCopy, modify the strings in place. 727 // As per NormallyNoDeepCopy, modify the strings in place.
691 name1[0] = name2[0] = name3[0] = arg1[0] = arg2[0] = val1[0] = val2[0] = '@'; 728 name1[0] = name2[0] = name3[0] = arg1[0] = arg2[0] = val1[0] = val2[0] = '@';
692 729
693 TraceLog::GetInstance()->SetEnabled(false); 730 TraceLog::GetInstance()->SetEnabled(false);
694 731
695 EXPECT_FALSE(FindTraceEntry(trace_parsed_, name1.c_str())); 732 EXPECT_FALSE(FindTraceEntry(trace_parsed_, name1.c_str()));
696 EXPECT_FALSE(FindTraceEntry(trace_parsed_, name2.c_str())); 733 EXPECT_FALSE(FindTraceEntry(trace_parsed_, name2.c_str()));
697 EXPECT_FALSE(FindTraceEntry(trace_parsed_, name3.c_str())); 734 EXPECT_FALSE(FindTraceEntry(trace_parsed_, name3.c_str()));
698 735
(...skipping 11 matching lines...) Expand all
710 747
711 std::string s; 748 std::string s;
712 EXPECT_TRUE(entry3->GetString("args.arg1", &s)); 749 EXPECT_TRUE(entry3->GetString("args.arg1", &s));
713 EXPECT_EQ("val1", s); 750 EXPECT_EQ("val1", s);
714 EXPECT_TRUE(entry3->GetString("args.arg2", &s)); 751 EXPECT_TRUE(entry3->GetString("args.arg2", &s));
715 EXPECT_EQ("val2", s); 752 EXPECT_EQ("val2", s);
716 } 753 }
717 754
718 } // namespace debug 755 } // namespace debug
719 } // namespace base 756 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698