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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | base/trace_event/trace_event_unittest.cc » ('j') | 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 "base/trace_event/trace_event_impl.h" 5 #include "base/trace_event/trace_event_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/base_switches.h" 10 #include "base/base_switches.h"
(...skipping 1797 matching lines...) Expand 10 before | Expand all | Expand 10 after
1808 // Usually it runs on a different thread. 1808 // Usually it runs on a different thread.
1809 void TraceLog::ConvertTraceEventsToTraceFormat( 1809 void TraceLog::ConvertTraceEventsToTraceFormat(
1810 scoped_ptr<TraceBuffer> logged_events, 1810 scoped_ptr<TraceBuffer> logged_events,
1811 const OutputCallback& flush_output_callback, 1811 const OutputCallback& flush_output_callback,
1812 const TraceEvent::ArgumentFilterPredicate& argument_filter_predicate) { 1812 const TraceEvent::ArgumentFilterPredicate& argument_filter_predicate) {
1813 if (flush_output_callback.is_null()) 1813 if (flush_output_callback.is_null())
1814 return; 1814 return;
1815 1815
1816 // The callback need to be called at least once even if there is no events 1816 // The callback need to be called at least once even if there is no events
1817 // to let the caller know the completion of flush. 1817 // to let the caller know the completion of flush.
1818 bool has_more_events = true; 1818 scoped_refptr<RefCountedString> json_events_str_ptr = new RefCountedString();
1819 do { 1819 while (const TraceBufferChunk* chunk = logged_events->NextChunk()) {
1820 scoped_refptr<RefCountedString> json_events_str_ptr = 1820 for (size_t j = 0; j < chunk->size(); ++j) {
1821 new RefCountedString(); 1821 size_t size = json_events_str_ptr->size();
1822 1822 if (size > kTraceEventBufferSizeInBytes) {
1823 while (json_events_str_ptr->size() < kTraceEventBufferSizeInBytes) { 1823 flush_output_callback.Run(json_events_str_ptr, true);
1824 const TraceBufferChunk* chunk = logged_events->NextChunk(); 1824 json_events_str_ptr = new RefCountedString();
1825 has_more_events = chunk != NULL; 1825 } else if (size) {
1826 if (!chunk) 1826 json_events_str_ptr->data().append(",\n");
1827 break;
1828 for (size_t j = 0; j < chunk->size(); ++j) {
1829 if (json_events_str_ptr->size())
1830 json_events_str_ptr->data().append(",\n");
1831 chunk->GetEventAt(j)->AppendAsJSON(&(json_events_str_ptr->data()),
1832 argument_filter_predicate);
1833 } 1827 }
1828 chunk->GetEventAt(j)->AppendAsJSON(&(json_events_str_ptr->data()),
1829 argument_filter_predicate);
1834 } 1830 }
1835 flush_output_callback.Run(json_events_str_ptr, has_more_events); 1831 }
1836 } while (has_more_events); 1832 flush_output_callback.Run(json_events_str_ptr, false);
1837 } 1833 }
1838 1834
1839 void TraceLog::FinishFlush(int generation) { 1835 void TraceLog::FinishFlush(int generation) {
1840 scoped_ptr<TraceBuffer> previous_logged_events; 1836 scoped_ptr<TraceBuffer> previous_logged_events;
1841 OutputCallback flush_output_callback; 1837 OutputCallback flush_output_callback;
1842 TraceEvent::ArgumentFilterPredicate argument_filter_predicate; 1838 TraceEvent::ArgumentFilterPredicate argument_filter_predicate;
1843 1839
1844 if (!CheckGeneration(generation)) 1840 if (!CheckGeneration(generation))
1845 return; 1841 return;
1846 1842
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
2486 } 2482 }
2487 2483
2488 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { 2484 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() {
2489 if (*category_group_enabled_) { 2485 if (*category_group_enabled_) {
2490 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, 2486 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_,
2491 name_, event_handle_); 2487 name_, event_handle_);
2492 } 2488 }
2493 } 2489 }
2494 2490
2495 } // namespace trace_event_internal 2491 } // namespace trace_event_internal
OLDNEW
« 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