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

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

Issue 2592093003: TRACE_TASK_EXECUTION case for tracing_perftests. (Closed)
Patch Set: Created 4 years 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" 6 #include "base/memory/ptr_util.h"
7 #include "base/memory/ref_counted_memory.h" 7 #include "base/memory/ref_counted_memory.h"
8 #include "base/pending_task.h"
8 #include "base/run_loop.h" 9 #include "base/run_loop.h"
9 #include "base/threading/thread.h" 10 #include "base/threading/thread.h"
10 #include "base/trace_event/trace_event.h" 11 #include "base/trace_event/trace_event.h"
11 #include "base/trace_event/trace_event_argument.h" 12 #include "base/trace_event/trace_event_argument.h"
12 #include "perf_test_helpers.h" 13 #include "perf_test_helpers.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 namespace tracing { 16 namespace tracing {
16 namespace { 17 namespace {
17 18
18 using base::Bind; 19 using base::Bind;
20 using base::Closure;
21 using base::RunLoop;
19 using base::Thread; 22 using base::Thread;
20 using base::Unretained; 23 using base::Unretained;
21 using base::WaitableEvent; 24 using base::WaitableEvent;
22 using base::trace_event::TraceConfig; 25 using base::trace_event::TraceConfig;
23 using base::trace_event::TraceLog; 26 using base::trace_event::TraceLog;
24 using base::trace_event::TraceRecordMode; 27 using base::trace_event::TraceRecordMode;
25 using base::trace_event::TracedValue; 28 using base::trace_event::TracedValue;
26 29
27 const int kNumRuns = 10; 30 const int kNumRuns = 10;
28 31
29 class TraceEventPerfTest : public ::testing::Test { 32 class TraceEventPerfTest : public ::testing::Test {
30 public: 33 public:
31 void BeginTrace() { 34 void BeginTrace() {
32 TraceConfig config("*", ""); 35 TraceConfig config("*", "");
33 config.SetTraceRecordMode(TraceRecordMode::RECORD_CONTINUOUSLY); 36 config.SetTraceRecordMode(TraceRecordMode::RECORD_CONTINUOUSLY);
34 TraceLog::GetInstance()->SetEnabled(config, TraceLog::RECORDING_MODE); 37 TraceLog::GetInstance()->SetEnabled(config, TraceLog::RECORDING_MODE);
35 } 38 }
36 39
37 void EndTraceAndFlush() { 40 void EndTraceAndFlush() {
38 ScopedStopwatch stopwatch("flush"); 41 ScopedStopwatch stopwatch("flush");
39 base::RunLoop run_loop; 42 base::RunLoop run_loop;
40 TraceLog::GetInstance()->SetDisabled(); 43 TraceLog::GetInstance()->SetDisabled();
41 TraceLog::GetInstance()->Flush( 44 TraceLog::GetInstance()->Flush(
42 Bind(&OnTraceDataCollected, run_loop.QuitClosure())); 45 Bind(&OnTraceDataCollected, run_loop.QuitClosure()));
43 run_loop.Run(); 46 run_loop.Run();
44 } 47 }
45 48
46 static void OnTraceDataCollected( 49 static void OnTraceDataCollected(
47 base::Closure quit_closure, 50 Closure quit_closure,
48 const scoped_refptr<base::RefCountedString>& events_str, 51 const scoped_refptr<base::RefCountedString>& events_str,
49 bool has_more_events) { 52 bool has_more_events) {
50 53
51 if (!has_more_events) 54 if (!has_more_events)
52 quit_closure.Run(); 55 quit_closure.Run();
53 } 56 }
54 57
55 std::unique_ptr<TracedValue> MakeTracedValue(int counter) { 58 std::unique_ptr<TracedValue> MakeTracedValue(int counter) {
56 auto value = base::MakeUnique<TracedValue>(); 59 auto value = base::MakeUnique<TracedValue>();
57 value->SetInteger("counter", counter); 60 value->SetInteger("counter", counter);
(...skipping 12 matching lines...) Expand all
70 return value; 73 return value;
71 } 74 }
72 75
73 static void SubmitTraceEventsAndSignal(WaitableEvent* complete_event) { 76 static void SubmitTraceEventsAndSignal(WaitableEvent* complete_event) {
74 for (int i = 0; i < 10000; i++) { 77 for (int i = 0; i < 10000; i++) {
75 TRACE_EVENT0("test_category", "some call"); 78 TRACE_EVENT0("test_category", "some call");
76 } 79 }
77 complete_event->Signal(); 80 complete_event->Signal();
78 } 81 }
79 82
83 static void SubmitTraceEvents(int count) {
84 for (int i = 0; i < count; i++) {
85 TRACE_EVENT0("test_category", "some call");
86 }
87 }
88
80 private: 89 private:
81 base::MessageLoop _message_loop; 90 base::MessageLoop _message_loop;
82 }; 91 };
83 92
84 TEST_F(TraceEventPerfTest, Submit_10000_TRACE_EVENT0) { 93 TEST_F(TraceEventPerfTest, Submit_10000_TRACE_EVENT0) {
85 BeginTrace(); 94 BeginTrace();
86 IterableStopwatch stopwatch("events"); 95 IterableStopwatch stopwatch("events");
87 for (int lap = 0; lap < kNumRuns; lap++) { 96 for (int lap = 0; lap < kNumRuns; lap++) {
88 for (int i = 0; i < 10000; i++) { 97 SubmitTraceEvents(10000);
89 TRACE_EVENT0("test_category", "TRACE_EVENT0 call");
90 }
91 stopwatch.NextLap(); 98 stopwatch.NextLap();
92 } 99 }
93 EndTraceAndFlush(); 100 EndTraceAndFlush();
94 } 101 }
95 102
96 TEST_F(TraceEventPerfTest, Long_TRACE_EVENT0) { 103 TEST_F(TraceEventPerfTest, Long_TRACE_EVENT0) {
97 BeginTrace(); 104 BeginTrace();
98 IterableStopwatch stopwatch("long_event"); 105 IterableStopwatch stopwatch("long_event");
99 for (int lap = 0; lap < kNumRuns; lap++) { 106 for (int lap = 0; lap < kNumRuns; lap++) {
100 TRACE_EVENT0("test_category", "Outer event"); 107 TRACE_EVENT0("test_category", "Outer event");
101 for (int i = 0; i < 10000; i++) { 108 SubmitTraceEvents(10000);
102 TRACE_EVENT0("test_category", "TRACE_EVENT0 call");
103 }
104 stopwatch.NextLap(); 109 stopwatch.NextLap();
105 } 110 }
106 EndTraceAndFlush(); 111 EndTraceAndFlush();
107 } 112 }
108 113
109 TEST_F(TraceEventPerfTest, Create_10000_TracedValue) { 114 TEST_F(TraceEventPerfTest, Create_10000_TracedValue) {
110 std::unique_ptr<TracedValue> value; 115 std::unique_ptr<TracedValue> value;
111 { 116 {
112 ScopedStopwatch value_sw("create_traced_values"); 117 ScopedStopwatch value_sw("create_traced_values");
113 for (int i = 0; i < 10000; i++) { 118 for (int i = 0; i < 10000; i++) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 complete_events[i]->Wait(); 163 complete_events[i]->Wait();
159 } 164 }
160 } 165 }
161 166
162 EndTraceAndFlush(); 167 EndTraceAndFlush();
163 for (int i = 0; i < kNumThreads; i++) { 168 for (int i = 0; i < kNumThreads; i++) {
164 threads[i]->Stop(); 169 threads[i]->Stop();
165 } 170 }
166 } 171 }
167 172
173 TEST_F(TraceEventPerfTest, Submit_10000_TRACE_EVENT0_in_traceable_tasks) {
174 BeginTrace();
175 std::unique_ptr<Thread> task_thread(new Thread("task_thread"));
Primiano Tucci (use gerrit) 2017/01/25 15:55:09 what is the purpose of this? seems unused
kraynov 2017/01/26 17:02:10 Done.
176 task_thread->Start();
177
178 IterableStopwatch task_sw("events_in_task");
179 for (int i = 0; i < 100; i++) {
180 base::PendingTask pending_task(FROM_HERE, Bind(&SubmitTraceEvents, 10000));
181 TRACE_TASK_EXECUTION("TraceEventPerfTest::PendingTask", pending_task);
182 std::move(pending_task.task).Run();
183 task_sw.NextLap();
184 }
185 EndTraceAndFlush();
186 }
187
188 TEST_F(TraceEventPerfTest, Submit_10000_TRACE_EVENT0_with_tracing_disabled) {
189 ScopedStopwatch stopwatch("events");
190 SubmitTraceEvents(10000);
191 }
192
168 } // namespace 193 } // namespace
169 } // namespace tracing 194 } // 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