Index: base/trace_event/trace_event_unittest.cc |
diff --git a/base/trace_event/trace_event_unittest.cc b/base/trace_event/trace_event_unittest.cc |
index d03224301cdffd3367bf85165832ff2e901f7152..5eca5c61b232d6079de09ffcef12c1ec71c785b8 100644 |
--- a/base/trace_event/trace_event_unittest.cc |
+++ b/base/trace_event/trace_event_unittest.cc |
@@ -86,6 +86,7 @@ class TraceEventTestFixture : public testing::Test { |
} |
void EndTraceAndFlush() { |
+ num_flush_callbacks_ = 0; |
WaitableEvent flush_complete_event(false, false); |
EndTraceAndFlushAsync(&flush_complete_event); |
flush_complete_event.Wait(); |
@@ -150,6 +151,7 @@ class TraceEventTestFixture : public testing::Test { |
TraceResultBuffer trace_buffer_; |
TraceResultBuffer::SimpleOutput json_output_; |
int event_watch_notification_; |
+ size_t num_flush_callbacks_; |
private: |
// We want our singleton torn down after each test. |
@@ -161,6 +163,10 @@ void TraceEventTestFixture::OnTraceDataCollected( |
WaitableEvent* flush_complete_event, |
const scoped_refptr<base::RefCountedString>& events_str, |
bool has_more_events) { |
+ num_flush_callbacks_++; |
+ if (num_flush_callbacks_ > 1) { |
+ EXPECT_FALSE(events_str->data().empty()); |
+ } |
AutoLock lock(lock_); |
json_output_.json_output.clear(); |
trace_buffer_.Start(); |
@@ -1076,6 +1082,49 @@ TEST_F(TraceEventTestFixture, NewTraceRecording) { |
EndTraceAndFlush(); |
} |
+TEST_F(TraceEventTestFixture, TestTraceFlush) { |
+ size_t min_traces = 1; |
+ size_t max_traces = 1; |
+ do { |
+ max_traces *= 2; |
+ TraceLog::GetInstance()->SetEnabled( |
+ CategoryFilter("*"), |
+ TraceLog::RECORDING_MODE, |
+ TraceOptions()); |
+ for (size_t i = 0; i < max_traces; i++) { |
+ TRACE_EVENT_INSTANT0("x", "y", TRACE_EVENT_SCOPE_THREAD); |
+ } |
+ EndTraceAndFlush(); |
+ } while (num_flush_callbacks_ < 2); |
+ |
+ while (min_traces + 50 < max_traces) { |
+ size_t traces = (min_traces + max_traces) / 2; |
+ TraceLog::GetInstance()->SetEnabled( |
+ CategoryFilter("*"), |
+ TraceLog::RECORDING_MODE, |
+ TraceOptions()); |
+ for (size_t i = 0; i < traces; i++) { |
+ TRACE_EVENT_INSTANT0("x", "y", TRACE_EVENT_SCOPE_THREAD); |
+ } |
+ EndTraceAndFlush(); |
+ if (num_flush_callbacks_ < 2) { |
+ min_traces = traces - 10; |
+ } else { |
+ max_traces = traces + 10; |
+ } |
+ } |
+ |
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
|
+ for (size_t traces = min_traces; traces < max_traces; traces++) { |
+ TraceLog::GetInstance()->SetEnabled( |
+ CategoryFilter("*"), |
+ TraceLog::RECORDING_MODE, |
+ TraceOptions()); |
+ for (size_t i = 0; i < traces; i++) { |
+ TRACE_EVENT_INSTANT0("x", "y", TRACE_EVENT_SCOPE_THREAD); |
+ } |
+ EndTraceAndFlush(); |
+ } |
+} |
// Test that categories work. |
TEST_F(TraceEventTestFixture, Categories) { |