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

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

Issue 1131543003: Avoid emptry tracing callbacks when possible. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merged & tested Created 5 years, 6 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
« no previous file with comments | « base/trace_event/trace_event_impl.cc ('k') | 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <math.h> 5 #include <math.h>
6 #include <cstdlib> 6 #include <cstdlib>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 BeginSpecificTrace("*"); 81 BeginSpecificTrace("*");
82 } 82 }
83 83
84 void BeginSpecificTrace(const std::string& filter) { 84 void BeginSpecificTrace(const std::string& filter) {
85 event_watch_notification_ = 0; 85 event_watch_notification_ = 0;
86 TraceLog::GetInstance()->SetEnabled(TraceConfig(filter, ""), 86 TraceLog::GetInstance()->SetEnabled(TraceConfig(filter, ""),
87 TraceLog::RECORDING_MODE); 87 TraceLog::RECORDING_MODE);
88 } 88 }
89 89
90 void EndTraceAndFlush() { 90 void EndTraceAndFlush() {
91 num_flush_callbacks_ = 0;
91 WaitableEvent flush_complete_event(false, false); 92 WaitableEvent flush_complete_event(false, false);
92 EndTraceAndFlushAsync(&flush_complete_event); 93 EndTraceAndFlushAsync(&flush_complete_event);
93 flush_complete_event.Wait(); 94 flush_complete_event.Wait();
94 } 95 }
95 96
96 // Used when testing thread-local buffers which requires the thread initiating 97 // Used when testing thread-local buffers which requires the thread initiating
97 // flush to have a message loop. 98 // flush to have a message loop.
98 void EndTraceAndFlushInThreadWithMessageLoop() { 99 void EndTraceAndFlushInThreadWithMessageLoop() {
99 WaitableEvent flush_complete_event(false, false); 100 WaitableEvent flush_complete_event(false, false);
100 Thread flush_thread("flush"); 101 Thread flush_thread("flush");
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 old_thread_name_ = NULL; 146 old_thread_name_ = NULL;
146 // We want our singleton torn down after each test. 147 // We want our singleton torn down after each test.
147 TraceLog::DeleteForTesting(); 148 TraceLog::DeleteForTesting();
148 } 149 }
149 150
150 char* old_thread_name_; 151 char* old_thread_name_;
151 ListValue trace_parsed_; 152 ListValue trace_parsed_;
152 TraceResultBuffer trace_buffer_; 153 TraceResultBuffer trace_buffer_;
153 TraceResultBuffer::SimpleOutput json_output_; 154 TraceResultBuffer::SimpleOutput json_output_;
154 int event_watch_notification_; 155 int event_watch_notification_;
156 size_t num_flush_callbacks_;
155 157
156 private: 158 private:
157 // We want our singleton torn down after each test. 159 // We want our singleton torn down after each test.
158 ShadowingAtExitManager at_exit_manager_; 160 ShadowingAtExitManager at_exit_manager_;
159 Lock lock_; 161 Lock lock_;
160 }; 162 };
161 163
162 void TraceEventTestFixture::OnTraceDataCollected( 164 void TraceEventTestFixture::OnTraceDataCollected(
163 WaitableEvent* flush_complete_event, 165 WaitableEvent* flush_complete_event,
164 const scoped_refptr<base::RefCountedString>& events_str, 166 const scoped_refptr<base::RefCountedString>& events_str,
165 bool has_more_events) { 167 bool has_more_events) {
168 num_flush_callbacks_++;
169 if (num_flush_callbacks_ > 1) {
170 EXPECT_FALSE(events_str->data().empty());
171 }
166 AutoLock lock(lock_); 172 AutoLock lock(lock_);
167 json_output_.json_output.clear(); 173 json_output_.json_output.clear();
168 trace_buffer_.Start(); 174 trace_buffer_.Start();
169 trace_buffer_.AddFragment(events_str->data()); 175 trace_buffer_.AddFragment(events_str->data());
170 trace_buffer_.Finish(); 176 trace_buffer_.Finish();
171 177
172 scoped_ptr<Value> root; 178 scoped_ptr<Value> root;
173 root.reset(base::JSONReader::DeprecatedRead( 179 root.reset(base::JSONReader::DeprecatedRead(
174 json_output_.json_output, JSON_PARSE_RFC | JSON_DETACHABLE_CHILDREN)); 180 json_output_.json_output, JSON_PARSE_RFC | JSON_DETACHABLE_CHILDREN));
175 181
(...skipping 888 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 // before. 1070 // before.
1065 TraceLog::GetInstance()->SetEnabled(TraceConfig(kRecordAllCategoryFilter, ""), 1071 TraceLog::GetInstance()->SetEnabled(TraceConfig(kRecordAllCategoryFilter, ""),
1066 TraceLog::RECORDING_MODE); 1072 TraceLog::RECORDING_MODE);
1067 ASSERT_TRUE(IsNewTrace()); 1073 ASSERT_TRUE(IsNewTrace());
1068 ASSERT_FALSE(IsNewTrace()); 1074 ASSERT_FALSE(IsNewTrace());
1069 1075
1070 // Cleanup. 1076 // Cleanup.
1071 EndTraceAndFlush(); 1077 EndTraceAndFlush();
1072 } 1078 }
1073 1079
1080 TEST_F(TraceEventTestFixture, TestTraceFlush) {
1081 size_t min_traces = 1;
1082 size_t max_traces = 1;
1083 do {
1084 max_traces *= 2;
1085 TraceLog::GetInstance()->SetEnabled(TraceConfig(),
1086 TraceLog::RECORDING_MODE);
1087 for (size_t i = 0; i < max_traces; i++) {
1088 TRACE_EVENT_INSTANT0("x", "y", TRACE_EVENT_SCOPE_THREAD);
1089 }
1090 EndTraceAndFlush();
1091 } while (num_flush_callbacks_ < 2);
1092
1093 while (min_traces + 50 < max_traces) {
1094 size_t traces = (min_traces + max_traces) / 2;
1095 TraceLog::GetInstance()->SetEnabled(TraceConfig(),
1096 TraceLog::RECORDING_MODE);
1097 for (size_t i = 0; i < traces; i++) {
1098 TRACE_EVENT_INSTANT0("x", "y", TRACE_EVENT_SCOPE_THREAD);
1099 }
1100 EndTraceAndFlush();
1101 if (num_flush_callbacks_ < 2) {
1102 min_traces = traces - 10;
1103 } else {
1104 max_traces = traces + 10;
1105 }
1106 }
1107
1108 for (size_t traces = min_traces; traces < max_traces; traces++) {
1109 TraceLog::GetInstance()->SetEnabled(TraceConfig(),
1110 TraceLog::RECORDING_MODE);
1111 for (size_t i = 0; i < traces; i++) {
1112 TRACE_EVENT_INSTANT0("x", "y", TRACE_EVENT_SCOPE_THREAD);
1113 }
1114 EndTraceAndFlush();
1115 }
1116 }
1074 1117
1075 // Test that categories work. 1118 // Test that categories work.
1076 TEST_F(TraceEventTestFixture, Categories) { 1119 TEST_F(TraceEventTestFixture, Categories) {
1077 // Test that categories that are used can be retrieved whether trace was 1120 // Test that categories that are used can be retrieved whether trace was
1078 // enabled or disabled when the trace event was encountered. 1121 // enabled or disabled when the trace event was encountered.
1079 TRACE_EVENT_INSTANT0("c1", "name", TRACE_EVENT_SCOPE_THREAD); 1122 TRACE_EVENT_INSTANT0("c1", "name", TRACE_EVENT_SCOPE_THREAD);
1080 TRACE_EVENT_INSTANT0("c2", "name", TRACE_EVENT_SCOPE_THREAD); 1123 TRACE_EVENT_INSTANT0("c2", "name", TRACE_EVENT_SCOPE_THREAD);
1081 BeginTrace(); 1124 BeginTrace();
1082 TRACE_EVENT_INSTANT0("c3", "name", TRACE_EVENT_SCOPE_THREAD); 1125 TRACE_EVENT_INSTANT0("c3", "name", TRACE_EVENT_SCOPE_THREAD);
1083 TRACE_EVENT_INSTANT0("c4", "name", TRACE_EVENT_SCOPE_THREAD); 1126 TRACE_EVENT_INSTANT0("c4", "name", TRACE_EVENT_SCOPE_THREAD);
(...skipping 1804 matching lines...) Expand 10 before | Expand all | Expand 10 after
2888 } 2931 }
2889 2932
2890 TEST_F(TraceEventTestFixture, SyntheticDelayConfigurationToString) { 2933 TEST_F(TraceEventTestFixture, SyntheticDelayConfigurationToString) {
2891 const char filter[] = "DELAY(test.Delay;16;oneshot)"; 2934 const char filter[] = "DELAY(test.Delay;16;oneshot)";
2892 TraceConfig config(filter, ""); 2935 TraceConfig config(filter, "");
2893 EXPECT_EQ(filter, config.ToCategoryFilterString()); 2936 EXPECT_EQ(filter, config.ToCategoryFilterString());
2894 } 2937 }
2895 2938
2896 } // namespace trace_event 2939 } // namespace trace_event
2897 } // namespace base 2940 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/trace_event_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698