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

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: test added Created 5 years, 7 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') | base/trace_event/trace_event_unittest.cc » ('J')
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 5ae7fb2572f7b16653f0360a322f62298541829e..369d874266bae8ba2dcc7818cbee9c89ee944b13 100644
--- a/base/trace_event/trace_event_impl.cc
+++ b/base/trace_event/trace_event_impl.cc
@@ -1763,24 +1763,20 @@ 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()));
+ 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()));
}
- flush_output_callback.Run(json_events_str_ptr, has_more_events);
- } while (has_more_events);
+ }
+ flush_output_callback.Run(json_events_str_ptr, false);
dsinclair 2015/06/11 13:54:39 Doesn't this new code do the same as the old code?
hubbe 2015/06/11 17:30:01 The new code will only create an empty callback if
dsinclair 2015/06/11 19:19:29 Right, but I don't see how the old code could prod
hubbe 2015/06/11 21:39:58 Apparently, it's been too long since I thought abo
dsinclair 2015/06/12 13:48:35 Ah, that makes a lot more sense, I can see how tha
}
void TraceLog::FinishFlush(int generation) {
« no previous file with comments | « no previous file | base/trace_event/trace_event_unittest.cc » ('j') | base/trace_event/trace_event_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698