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

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

Issue 2450953003: Tracing macros perftests. (Closed)
Patch Set: 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"
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"
8 #include "base/trace_event/trace_event.h" 9 #include "base/trace_event/trace_event.h"
10 #include "base/trace_event/trace_event_argument.h"
9 #include "perf_test_helpers.h" 11 #include "perf_test_helpers.h"
10 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
11 13
12 namespace tracing { 14 namespace tracing {
13 namespace { 15 namespace {
14 16
15 using base::trace_event::TraceConfig; 17 using base::trace_event::TraceConfig;
16 using base::trace_event::TraceLog; 18 using base::trace_event::TraceLog;
17 using base::trace_event::TraceRecordMode; 19 using base::trace_event::TraceRecordMode;
20 using base::trace_event::TracedValue;
18 21
19 const int kNumRuns = 100; 22 const int kNumRuns = 100;
20 23
21 class TraceEventPerfTest : public ::testing::Test { 24 class TraceEventPerfTest : public ::testing::Test {
22 public: 25 public:
23 void BeginTrace() { 26 void BeginTrace() {
24 TraceConfig config("*", ""); 27 TraceConfig config("*", "");
25 config.SetTraceRecordMode(TraceRecordMode::RECORD_CONTINUOUSLY); 28 config.SetTraceRecordMode(TraceRecordMode::RECORD_CONTINUOUSLY);
26 TraceLog::GetInstance()->SetEnabled(config, TraceLog::RECORDING_MODE); 29 TraceLog::GetInstance()->SetEnabled(config, TraceLog::RECORDING_MODE);
27 } 30 }
28 31
29 void EndTraceAndFlush() { 32 void EndTraceAndFlush() {
30 ScopedStopwatch stopwatch("flush"); 33 ScopedStopwatch stopwatch("flush");
31 base::RunLoop run_loop; 34 base::RunLoop run_loop;
32 TraceLog::GetInstance()->SetDisabled(); 35 TraceLog::GetInstance()->SetDisabled();
33 TraceLog::GetInstance()->Flush( 36 TraceLog::GetInstance()->Flush(
34 Bind(&OnTraceDataCollected, run_loop.QuitClosure())); 37 Bind(&OnTraceDataCollected, run_loop.QuitClosure()));
35 run_loop.Run(); 38 run_loop.Run();
36 } 39 }
37 40
41 std::unique_ptr<TracedValue> MakeTracedValue(int counter) {
42 auto value = base::WrapUnique(new TracedValue);
Primiano Tucci (use gerrit) 2016/10/28 09:43:11 I think MakeUnique is the preferred one for new in
43 value->SetInteger("counter", counter);
44 value->BeginDictionary("test_dict");
45 value->BeginArray("nodes");
46 for (int i = 0; i < 10; i++) {
47 value->BeginDictionary();
48 value->SetInteger("id", i);
49 value->SetBoolean("valid", true);
50 value->SetString("value", "foo");
51 value->EndDictionary();
52 }
53 value->EndArray();
54 value->SetInteger("count", 10);
55 value->EndDictionary();
56 return value;
57 }
58
38 static void OnTraceDataCollected( 59 static void OnTraceDataCollected(
39 base::Closure quit_closure, 60 base::Closure quit_closure,
40 const scoped_refptr<base::RefCountedString>& events_str, 61 const scoped_refptr<base::RefCountedString>& events_str,
41 bool has_more_events) { 62 bool has_more_events) {
42 63
43 if (!has_more_events) 64 if (!has_more_events)
44 quit_closure.Run(); 65 quit_closure.Run();
45 } 66 }
46 }; 67 };
47 68
48 TEST_F(TraceEventPerfTest, Submit_10000_TRACE_EVENT0) { 69 TEST_F(TraceEventPerfTest, Submit_10000_TRACE_EVENT0) {
49 BeginTrace(); 70 BeginTrace();
50 IterableStopwatch stopwatch("events"); 71 IterableStopwatch stopwatch("events");
51 for (int lap = 0; lap < kNumRuns; lap++) { 72 for (int lap = 0; lap < kNumRuns; lap++) {
52 for (int i = 0; i < 10000; i++) { 73 for (int i = 0; i < 10000; i++) {
53 TRACE_EVENT0("test_category", "TRACE_EVENT0 call"); 74 TRACE_EVENT0("test_category", "TRACE_EVENT0 call");
54 } 75 }
55 stopwatch.NextLap(); 76 stopwatch.NextLap();
56 } 77 }
57 EndTraceAndFlush(); 78 EndTraceAndFlush();
58 } 79 }
59 80
81 TEST_F(TraceEventPerfTest, Long_TRACE_EVENT0) {
82 BeginTrace();
83 IterableStopwatch stopwatch("long_event");
84 for (int lap = 0; lap < kNumRuns; lap++) {
85 TRACE_EVENT0("test_category", "Outter event");
Primiano Tucci (use gerrit) 2016/10/28 09:43:11 typo, extra t in outter
86 for (int i = 0; i < 10000; i++) {
87 TRACE_EVENT0("test_category", "TRACE_EVENT0 call");
88 }
89 stopwatch.NextLap();
90 }
91 EndTraceAndFlush();
92 }
93
94 TEST_F(TraceEventPerfTest, UsingTracedValue) {
95 BeginTrace();
96 std::unique_ptr<TracedValue> value;
97 {
98 ScopedStopwatch value_sw("create_traced_values");
99 for (int i = 0; i < 10000; i++) {
100 value = MakeTracedValue(i);
101 }
102 }
103
104 IterableStopwatch trace_sw("instant_events_with_value");
Primiano Tucci (use gerrit) 2016/10/28 09:43:11 i'd just drop instant_ here to keep the metric mor
105 for (int lap = 0; lap < kNumRuns; lap++) {
106 for (int i = 0; i < 10000; i++) {
107 TRACE_EVENT_INSTANT1("test_category", "event_with_value",
108 TRACE_EVENT_SCOPE_THREAD, "value", MakeTracedValue(i));
109 }
110 trace_sw.NextLap();
111 }
112 EndTraceAndFlush();
113 }
114
60 } // namespace 115 } // namespace
61 } // namespace tracing 116 } // 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