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

Side by Side Diff: components/tracing/test/trace_event_perftest.cc

Issue 2450953003: Tracing macros perftests. (Closed)
Patch Set: little fix Created 4 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/memory/ptr_util.h"
Primiano Tucci (use gerrit) 2016/11/14 22:28:01 what is this include for?
kraynov 2016/11/14 22:56:52 WrapUnique, MakeUnique
6 #include "base/memory/ref_counted_memory.h" 7 #include "base/memory/ref_counted_memory.h"
7 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/task_runner_util.h"
Primiano Tucci (use gerrit) 2016/11/14 22:28:01 I don't think you need this anymore
kraynov 2016/11/14 22:56:53 Done.
10 #include "base/threading/thread.h"
8 #include "base/trace_event/trace_event.h" 11 #include "base/trace_event/trace_event.h"
12 #include "base/trace_event/trace_event_argument.h"
9 #include "perf_test_helpers.h" 13 #include "perf_test_helpers.h"
10 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
11 15
12 namespace tracing { 16 namespace tracing {
13 namespace { 17 namespace {
14 18
19 using base::Bind;
20 using base::Thread;
21 using base::Unretained;
22 using base::WaitableEvent;
15 using base::trace_event::TraceConfig; 23 using base::trace_event::TraceConfig;
16 using base::trace_event::TraceLog; 24 using base::trace_event::TraceLog;
17 using base::trace_event::TraceRecordMode; 25 using base::trace_event::TraceRecordMode;
26 using base::trace_event::TracedValue;
18 27
19 const int kNumRuns = 100; 28 const int kNumRuns = 10;
20 29
21 class TraceEventPerfTest : public ::testing::Test { 30 class TraceEventPerfTest : public ::testing::Test {
22 public: 31 public:
23 void BeginTrace() { 32 void BeginTrace() {
24 TraceConfig config("*", ""); 33 TraceConfig config("*", "");
25 config.SetTraceRecordMode(TraceRecordMode::RECORD_CONTINUOUSLY); 34 config.SetTraceRecordMode(TraceRecordMode::RECORD_CONTINUOUSLY);
26 TraceLog::GetInstance()->SetEnabled(config, TraceLog::RECORDING_MODE); 35 TraceLog::GetInstance()->SetEnabled(config, TraceLog::RECORDING_MODE);
27 } 36 }
28 37
29 void EndTraceAndFlush() { 38 void EndTraceAndFlush() {
30 ScopedStopwatch stopwatch("flush"); 39 ScopedStopwatch stopwatch("flush");
31 base::RunLoop run_loop; 40 base::RunLoop run_loop;
32 TraceLog::GetInstance()->SetDisabled(); 41 TraceLog::GetInstance()->SetDisabled();
33 TraceLog::GetInstance()->Flush( 42 TraceLog::GetInstance()->Flush(
34 Bind(&OnTraceDataCollected, run_loop.QuitClosure())); 43 Bind(&OnTraceDataCollected, run_loop.QuitClosure()));
35 run_loop.Run(); 44 run_loop.Run();
36 } 45 }
37 46
38 static void OnTraceDataCollected( 47 static void OnTraceDataCollected(
39 base::Closure quit_closure, 48 base::Closure quit_closure,
40 const scoped_refptr<base::RefCountedString>& events_str, 49 const scoped_refptr<base::RefCountedString>& events_str,
41 bool has_more_events) { 50 bool has_more_events) {
42 51
43 if (!has_more_events) 52 if (!has_more_events)
44 quit_closure.Run(); 53 quit_closure.Run();
45 } 54 }
55
56 std::unique_ptr<TracedValue> MakeTracedValue(int counter) {
57 auto value = base::MakeUnique<TracedValue>();
58 value->SetInteger("counter", counter);
59 value->BeginDictionary("test_dict");
60 value->BeginArray("nodes");
61 for (int i = 0; i < 10; i++) {
62 value->BeginDictionary();
63 value->SetInteger("id", i);
64 value->SetBoolean("valid", true);
65 value->SetString("value", "foo");
66 value->EndDictionary();
67 }
68 value->EndArray();
69 value->SetInteger("count", 10);
70 value->EndDictionary();
71 return value;
72 }
73
74 static void SubmitTraceEventsAndSignal(WaitableEvent* complete) {
Primiano Tucci (use gerrit) 2016/11/14 22:28:00 variable/argument names should be nouns. Either s/
kraynov 2016/11/14 22:56:52 Done.
75 for (int i = 0; i < 10000; i++) {
76 TRACE_EVENT0("test_category", "some call");
77 }
78 complete->Signal();
79 }
80
81 private:
82 base::MessageLoop _message_loop;
46 }; 83 };
47 84
48 TEST_F(TraceEventPerfTest, Submit_10000_TRACE_EVENT0) { 85 TEST_F(TraceEventPerfTest, Submit_10000_TRACE_EVENT0) {
49 BeginTrace(); 86 BeginTrace();
50 IterableStopwatch stopwatch("events"); 87 IterableStopwatch stopwatch("events");
51 for (int lap = 0; lap < kNumRuns; lap++) { 88 for (int lap = 0; lap < kNumRuns; lap++) {
52 for (int i = 0; i < 10000; i++) { 89 for (int i = 0; i < 10000; i++) {
53 TRACE_EVENT0("test_category", "TRACE_EVENT0 call"); 90 TRACE_EVENT0("test_category", "TRACE_EVENT0 call");
54 } 91 }
55 stopwatch.NextLap(); 92 stopwatch.NextLap();
56 } 93 }
57 EndTraceAndFlush(); 94 EndTraceAndFlush();
58 } 95 }
59 96
97 TEST_F(TraceEventPerfTest, Long_TRACE_EVENT0) {
98 BeginTrace();
99 IterableStopwatch stopwatch("long_event");
100 for (int lap = 0; lap < kNumRuns; lap++) {
101 TRACE_EVENT0("test_category", "Outer event");
102 for (int i = 0; i < 10000; i++) {
103 TRACE_EVENT0("test_category", "TRACE_EVENT0 call");
104 }
105 stopwatch.NextLap();
106 }
107 EndTraceAndFlush();
108 }
109
110 TEST_F(TraceEventPerfTest, UsingTracedValue) {
Primiano Tucci (use gerrit) 2016/11/14 22:28:01 would be nice if the test name here also had the 1
kraynov 2016/11/14 22:56:53 Done.
111 BeginTrace();
112 std::unique_ptr<TracedValue> value;
113 {
114 ScopedStopwatch value_sw("create_traced_values");
Primiano Tucci (use gerrit) 2016/11/14 22:28:00 I think this loop should be in a different TEST_F,
kraynov 2016/11/14 22:56:53 Done.
115 for (int i = 0; i < 10000; i++) {
116 value = MakeTracedValue(i);
117 }
118 }
119
120 IterableStopwatch trace_sw("events_with_value");
121 for (int lap = 0; lap < kNumRuns; lap++) {
122 for (int i = 0; i < 10000; i++) {
123 TRACE_EVENT_INSTANT1("test_category", "event_with_value",
124 TRACE_EVENT_SCOPE_THREAD, "value", MakeTracedValue(i));
125 }
126 trace_sw.NextLap();
127 }
128 EndTraceAndFlush();
129 }
130
131 TEST_F(TraceEventPerfTest, Concurrent_TRACE_EVENT0) {
132 BeginTrace();
133 const int num_threads = 4;
Primiano Tucci (use gerrit) 2016/11/14 22:28:00 s/num_threads/kNumThreads/ according to our C++ co
kraynov 2016/11/14 22:56:53 Done.
134
135 std::vector<std::unique_ptr<Thread>> threads;
136 std::vector<std::unique_ptr<WaitableEvent>> complete_events;
137
138 for (int i = 0; i < num_threads; i++) {
139 Thread* thread = new Thread(std::string("thread_%d") + std::to_string(i));
140 WaitableEvent* complete_event =
141 new WaitableEvent(WaitableEvent::ResetPolicy::AUTOMATIC,
142 WaitableEvent::InitialState::NOT_SIGNALED);
143 threads.push_back(base::WrapUnique(thread));
144 complete_events.push_back(base::WrapUnique(complete_event));
145 thread->Start();
146 }
147
148 {
149 ScopedStopwatch stopwatch("events_over_multiple_threads");
150 for (int i = 0; i < num_threads; i++) {
151 threads[i]->task_runner()->PostTask(
152 FROM_HERE,
153 base::Bind(&SubmitTraceEventsAndSignal, complete_events[i].get()));
154 }
155 for (int i = 0; i < num_threads; i++) {
156 complete_events[i]->Wait();
157 }
158 }
159
160 EndTraceAndFlush();
161 for (int i = 0; i < num_threads; i++) {
162 threads[i]->Stop();
163 }
164 }
165
60 } // namespace 166 } // namespace
61 } // namespace tracing 167 } // namespace tracing
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698