OLD | NEW |
---|---|
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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 | 79 |
80 void BeginSpecificTrace(const std::string& filter) { | 80 void BeginSpecificTrace(const std::string& filter) { |
81 event_watch_notification_ = 0; | 81 event_watch_notification_ = 0; |
82 TraceLog::GetInstance()->SetEnabled( | 82 TraceLog::GetInstance()->SetEnabled( |
83 CategoryFilter(filter), | 83 CategoryFilter(filter), |
84 TraceLog::RECORDING_MODE, | 84 TraceLog::RECORDING_MODE, |
85 TraceOptions()); | 85 TraceOptions()); |
86 } | 86 } |
87 | 87 |
88 void EndTraceAndFlush() { | 88 void EndTraceAndFlush() { |
89 num_flush_callbacks_ = 0; | |
89 WaitableEvent flush_complete_event(false, false); | 90 WaitableEvent flush_complete_event(false, false); |
90 EndTraceAndFlushAsync(&flush_complete_event); | 91 EndTraceAndFlushAsync(&flush_complete_event); |
91 flush_complete_event.Wait(); | 92 flush_complete_event.Wait(); |
92 } | 93 } |
93 | 94 |
94 // Used when testing thread-local buffers which requires the thread initiating | 95 // Used when testing thread-local buffers which requires the thread initiating |
95 // flush to have a message loop. | 96 // flush to have a message loop. |
96 void EndTraceAndFlushInThreadWithMessageLoop() { | 97 void EndTraceAndFlushInThreadWithMessageLoop() { |
97 WaitableEvent flush_complete_event(false, false); | 98 WaitableEvent flush_complete_event(false, false); |
98 Thread flush_thread("flush"); | 99 Thread flush_thread("flush"); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 old_thread_name_ = NULL; | 144 old_thread_name_ = NULL; |
144 // We want our singleton torn down after each test. | 145 // We want our singleton torn down after each test. |
145 TraceLog::DeleteForTesting(); | 146 TraceLog::DeleteForTesting(); |
146 } | 147 } |
147 | 148 |
148 char* old_thread_name_; | 149 char* old_thread_name_; |
149 ListValue trace_parsed_; | 150 ListValue trace_parsed_; |
150 TraceResultBuffer trace_buffer_; | 151 TraceResultBuffer trace_buffer_; |
151 TraceResultBuffer::SimpleOutput json_output_; | 152 TraceResultBuffer::SimpleOutput json_output_; |
152 int event_watch_notification_; | 153 int event_watch_notification_; |
154 size_t num_flush_callbacks_; | |
153 | 155 |
154 private: | 156 private: |
155 // We want our singleton torn down after each test. | 157 // We want our singleton torn down after each test. |
156 ShadowingAtExitManager at_exit_manager_; | 158 ShadowingAtExitManager at_exit_manager_; |
157 Lock lock_; | 159 Lock lock_; |
158 }; | 160 }; |
159 | 161 |
160 void TraceEventTestFixture::OnTraceDataCollected( | 162 void TraceEventTestFixture::OnTraceDataCollected( |
161 WaitableEvent* flush_complete_event, | 163 WaitableEvent* flush_complete_event, |
162 const scoped_refptr<base::RefCountedString>& events_str, | 164 const scoped_refptr<base::RefCountedString>& events_str, |
163 bool has_more_events) { | 165 bool has_more_events) { |
166 num_flush_callbacks_++; | |
167 if (num_flush_callbacks_ > 1) { | |
168 EXPECT_FALSE(events_str->data().empty()); | |
169 } | |
164 AutoLock lock(lock_); | 170 AutoLock lock(lock_); |
165 json_output_.json_output.clear(); | 171 json_output_.json_output.clear(); |
166 trace_buffer_.Start(); | 172 trace_buffer_.Start(); |
167 trace_buffer_.AddFragment(events_str->data()); | 173 trace_buffer_.AddFragment(events_str->data()); |
168 trace_buffer_.Finish(); | 174 trace_buffer_.Finish(); |
169 | 175 |
170 scoped_ptr<Value> root; | 176 scoped_ptr<Value> root; |
171 root.reset(base::JSONReader::Read(json_output_.json_output, | 177 root.reset(base::JSONReader::Read(json_output_.json_output, |
172 JSON_PARSE_RFC | JSON_DETACHABLE_CHILDREN)); | 178 JSON_PARSE_RFC | JSON_DETACHABLE_CHILDREN)); |
173 | 179 |
(...skipping 895 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1069 CategoryFilter("*"), | 1075 CategoryFilter("*"), |
1070 TraceLog::RECORDING_MODE, | 1076 TraceLog::RECORDING_MODE, |
1071 TraceOptions()); | 1077 TraceOptions()); |
1072 ASSERT_TRUE(IsNewTrace()); | 1078 ASSERT_TRUE(IsNewTrace()); |
1073 ASSERT_FALSE(IsNewTrace()); | 1079 ASSERT_FALSE(IsNewTrace()); |
1074 | 1080 |
1075 // Cleanup. | 1081 // Cleanup. |
1076 EndTraceAndFlush(); | 1082 EndTraceAndFlush(); |
1077 } | 1083 } |
1078 | 1084 |
1085 TEST_F(TraceEventTestFixture, TestTraceFlush) { | |
1086 size_t min_traces = 1; | |
1087 size_t max_traces = 1; | |
1088 do { | |
1089 max_traces *= 2; | |
1090 TraceLog::GetInstance()->SetEnabled( | |
1091 CategoryFilter("*"), | |
1092 TraceLog::RECORDING_MODE, | |
1093 TraceOptions()); | |
1094 for (size_t i = 0; i < max_traces; i++) { | |
1095 TRACE_EVENT_INSTANT0("x", "y", TRACE_EVENT_SCOPE_THREAD); | |
1096 } | |
1097 EndTraceAndFlush(); | |
1098 } while (num_flush_callbacks_ < 2); | |
1099 | |
1100 while (min_traces + 50 < max_traces) { | |
1101 size_t traces = (min_traces + max_traces) / 2; | |
1102 TraceLog::GetInstance()->SetEnabled( | |
1103 CategoryFilter("*"), | |
1104 TraceLog::RECORDING_MODE, | |
1105 TraceOptions()); | |
1106 for (size_t i = 0; i < traces; i++) { | |
1107 TRACE_EVENT_INSTANT0("x", "y", TRACE_EVENT_SCOPE_THREAD); | |
1108 } | |
1109 EndTraceAndFlush(); | |
1110 if (num_flush_callbacks_ < 2) { | |
1111 min_traces = traces - 10; | |
1112 } else { | |
1113 max_traces = traces + 10; | |
1114 } | |
1115 } | |
1116 | |
dsinclair
2015/05/25 13:51:11
This test is .... complicated. Can we simplify it?
hubbe
2015/06/10 21:55:32
It's trying to make sure that we don't create an e
| |
1117 for (size_t traces = min_traces; traces < max_traces; traces++) { | |
1118 TraceLog::GetInstance()->SetEnabled( | |
1119 CategoryFilter("*"), | |
1120 TraceLog::RECORDING_MODE, | |
1121 TraceOptions()); | |
1122 for (size_t i = 0; i < traces; i++) { | |
1123 TRACE_EVENT_INSTANT0("x", "y", TRACE_EVENT_SCOPE_THREAD); | |
1124 } | |
1125 EndTraceAndFlush(); | |
1126 } | |
1127 } | |
1079 | 1128 |
1080 // Test that categories work. | 1129 // Test that categories work. |
1081 TEST_F(TraceEventTestFixture, Categories) { | 1130 TEST_F(TraceEventTestFixture, Categories) { |
1082 // Test that categories that are used can be retrieved whether trace was | 1131 // Test that categories that are used can be retrieved whether trace was |
1083 // enabled or disabled when the trace event was encountered. | 1132 // enabled or disabled when the trace event was encountered. |
1084 TRACE_EVENT_INSTANT0("c1", "name", TRACE_EVENT_SCOPE_THREAD); | 1133 TRACE_EVENT_INSTANT0("c1", "name", TRACE_EVENT_SCOPE_THREAD); |
1085 TRACE_EVENT_INSTANT0("c2", "name", TRACE_EVENT_SCOPE_THREAD); | 1134 TRACE_EVENT_INSTANT0("c2", "name", TRACE_EVENT_SCOPE_THREAD); |
1086 BeginTrace(); | 1135 BeginTrace(); |
1087 TRACE_EVENT_INSTANT0("c3", "name", TRACE_EVENT_SCOPE_THREAD); | 1136 TRACE_EVENT_INSTANT0("c3", "name", TRACE_EVENT_SCOPE_THREAD); |
1088 TRACE_EVENT_INSTANT0("c4", "name", TRACE_EVENT_SCOPE_THREAD); | 1137 TRACE_EVENT_INSTANT0("c4", "name", TRACE_EVENT_SCOPE_THREAD); |
(...skipping 1986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3075 EXPECT_EQ(original_option.record_mode, new_options.record_mode); | 3124 EXPECT_EQ(original_option.record_mode, new_options.record_mode); |
3076 EXPECT_EQ(original_option.enable_sampling, new_options.enable_sampling); | 3125 EXPECT_EQ(original_option.enable_sampling, new_options.enable_sampling); |
3077 EXPECT_EQ(original_option.enable_systrace, new_options.enable_systrace); | 3126 EXPECT_EQ(original_option.enable_systrace, new_options.enable_systrace); |
3078 } | 3127 } |
3079 } | 3128 } |
3080 } | 3129 } |
3081 } | 3130 } |
3082 | 3131 |
3083 } // namespace trace_event | 3132 } // namespace trace_event |
3084 } // namespace base | 3133 } // namespace base |
OLD | NEW |