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

Unified Diff: base/trace_event/trace_event_impl.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/trace_event/trace_event_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/trace_event/trace_event_impl.cc
diff --git a/base/trace_event/trace_event_impl.cc b/base/trace_event/trace_event_impl.cc
index b5d4298e653027c20bfd52b7806aaac90f1e928a..5882333c1714385d343be54791629c67031772fa 100644
--- a/base/trace_event/trace_event_impl.cc
+++ b/base/trace_event/trace_event_impl.cc
@@ -1815,25 +1815,21 @@ void TraceLog::ConvertTraceEventsToTraceFormat(
// The callback need to be called at least once even if there is no events
// to let the caller know the completion of flush.
- bool has_more_events = true;
- do {
- scoped_refptr<RefCountedString> json_events_str_ptr =
- new RefCountedString();
-
- while (json_events_str_ptr->size() < kTraceEventBufferSizeInBytes) {
- const TraceBufferChunk* chunk = logged_events->NextChunk();
- has_more_events = chunk != NULL;
- if (!chunk)
- break;
- for (size_t j = 0; j < chunk->size(); ++j) {
- if (json_events_str_ptr->size())
- json_events_str_ptr->data().append(",\n");
- chunk->GetEventAt(j)->AppendAsJSON(&(json_events_str_ptr->data()),
- argument_filter_predicate);
+ scoped_refptr<RefCountedString> json_events_str_ptr = new RefCountedString();
+ while (const TraceBufferChunk* chunk = logged_events->NextChunk()) {
+ for (size_t j = 0; j < chunk->size(); ++j) {
+ size_t size = json_events_str_ptr->size();
+ if (size > kTraceEventBufferSizeInBytes) {
+ flush_output_callback.Run(json_events_str_ptr, true);
+ json_events_str_ptr = new RefCountedString();
+ } else if (size) {
+ json_events_str_ptr->data().append(",\n");
}
+ chunk->GetEventAt(j)->AppendAsJSON(&(json_events_str_ptr->data()),
+ argument_filter_predicate);
}
- flush_output_callback.Run(json_events_str_ptr, has_more_events);
- } while (has_more_events);
+ }
+ flush_output_callback.Run(json_events_str_ptr, false);
}
void TraceLog::FinishFlush(int generation) {
« no previous file with comments | « no previous file | base/trace_event/trace_event_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698