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 "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 1745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1756 // Usually it runs on a different thread. | 1756 // Usually it runs on a different thread. |
1757 void TraceLog::ConvertTraceEventsToTraceFormat( | 1757 void TraceLog::ConvertTraceEventsToTraceFormat( |
1758 scoped_ptr<TraceBuffer> logged_events, | 1758 scoped_ptr<TraceBuffer> logged_events, |
1759 const TraceLog::OutputCallback& flush_output_callback) { | 1759 const TraceLog::OutputCallback& flush_output_callback) { |
1760 | 1760 |
1761 if (flush_output_callback.is_null()) | 1761 if (flush_output_callback.is_null()) |
1762 return; | 1762 return; |
1763 | 1763 |
1764 // The callback need to be called at least once even if there is no events | 1764 // The callback need to be called at least once even if there is no events |
1765 // to let the caller know the completion of flush. | 1765 // to let the caller know the completion of flush. |
1766 bool has_more_events = true; | 1766 scoped_refptr<RefCountedString> json_events_str_ptr = new RefCountedString(); |
1767 do { | 1767 while (const TraceBufferChunk* chunk = logged_events->NextChunk()) { |
1768 scoped_refptr<RefCountedString> json_events_str_ptr = | 1768 for (size_t j = 0; j < chunk->size(); ++j) { |
1769 new RefCountedString(); | 1769 size_t size = json_events_str_ptr->size(); |
1770 | 1770 if (size > kTraceEventBufferSizeInBytes) { |
1771 while (json_events_str_ptr->size() < kTraceEventBufferSizeInBytes) { | 1771 flush_output_callback.Run(json_events_str_ptr, true); |
1772 const TraceBufferChunk* chunk = logged_events->NextChunk(); | 1772 json_events_str_ptr = new RefCountedString(); |
1773 has_more_events = chunk != NULL; | 1773 } else if (size) { |
1774 if (!chunk) | 1774 json_events_str_ptr->data().append(",\n"); |
1775 break; | |
1776 for (size_t j = 0; j < chunk->size(); ++j) { | |
1777 if (json_events_str_ptr->size()) | |
1778 json_events_str_ptr->data().append(",\n"); | |
1779 chunk->GetEventAt(j)->AppendAsJSON(&(json_events_str_ptr->data())); | |
1780 } | 1775 } |
1776 chunk->GetEventAt(j)->AppendAsJSON(&(json_events_str_ptr->data())); | |
1781 } | 1777 } |
1782 flush_output_callback.Run(json_events_str_ptr, has_more_events); | 1778 } |
1783 } while (has_more_events); | 1779 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
| |
1784 } | 1780 } |
1785 | 1781 |
1786 void TraceLog::FinishFlush(int generation) { | 1782 void TraceLog::FinishFlush(int generation) { |
1787 scoped_ptr<TraceBuffer> previous_logged_events; | 1783 scoped_ptr<TraceBuffer> previous_logged_events; |
1788 OutputCallback flush_output_callback; | 1784 OutputCallback flush_output_callback; |
1789 | 1785 |
1790 if (!CheckGeneration(generation)) | 1786 if (!CheckGeneration(generation)) |
1791 return; | 1787 return; |
1792 | 1788 |
1793 { | 1789 { |
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2641 } | 2637 } |
2642 | 2638 |
2643 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { | 2639 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { |
2644 if (*category_group_enabled_) { | 2640 if (*category_group_enabled_) { |
2645 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, | 2641 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, |
2646 name_, event_handle_); | 2642 name_, event_handle_); |
2647 } | 2643 } |
2648 } | 2644 } |
2649 | 2645 |
2650 } // namespace trace_event_internal | 2646 } // namespace trace_event_internal |
OLD | NEW |