Chromium Code Reviews| Index: base/debug/trace_event_impl.cc |
| diff --git a/base/debug/trace_event_impl.cc b/base/debug/trace_event_impl.cc |
| index 45912865b1511c8b39ee31df8fe6cf5374331106..3d39a4732ea07e0235fbca32a54fa58a68fd3367 100644 |
| --- a/base/debug/trace_event_impl.cc |
| +++ b/base/debug/trace_event_impl.cc |
| @@ -32,6 +32,7 @@ |
| #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| #include "base/threading/platform_thread.h" |
| #include "base/threading/thread_id_name_manager.h" |
| +#include "base/threading/worker_pool.h" |
| #include "base/time/time.h" |
| #if defined(OS_WIN) |
| @@ -73,7 +74,7 @@ const size_t kTraceEventVectorBigBufferChunks = |
| 512000000 / kTraceBufferChunkSize; |
| const size_t kTraceEventVectorBufferChunks = 256000 / kTraceBufferChunkSize; |
| const size_t kTraceEventRingBufferChunks = kTraceEventVectorBufferChunks / 4; |
| -const size_t kTraceEventBatchChunks = 1000 / kTraceBufferChunkSize; |
| +const size_t kTraceEventBufferSize = 10 * 1024 * 1024; |
|
yurys
2014/12/17 08:50:30
Can you rename it to kTraceEventBufferSizeInBytes
loislo
2014/12/17 08:56:45
Done.
|
| // Can store results for 30 seconds with 1 ms sampling interval. |
| const size_t kMonitorTraceEventBufferChunks = 30000 / kTraceBufferChunkSize; |
| // ECHO_TO_CONSOLE needs a small buffer to hold the unfinished COMPLETE events. |
| @@ -1738,6 +1739,7 @@ void TraceLog::Flush(const TraceLog::OutputCallback& cb) { |
| FinishFlush(generation); |
| } |
| +// Usually it runs on a different thread. |
| void TraceLog::ConvertTraceEventsToTraceFormat( |
| scoped_ptr<TraceBuffer> logged_events, |
| const TraceLog::OutputCallback& flush_output_callback) { |
| @@ -1752,19 +1754,17 @@ void TraceLog::ConvertTraceEventsToTraceFormat( |
| scoped_refptr<RefCountedString> json_events_str_ptr = |
| new RefCountedString(); |
| - for (size_t i = 0; i < kTraceEventBatchChunks; ++i) { |
| + while (json_events_str_ptr->size() < kTraceEventBufferSize) { |
| const TraceBufferChunk* chunk = logged_events->NextChunk(); |
| - if (!chunk) { |
| - has_more_events = false; |
| + has_more_events = chunk != NULL; |
| + if (!chunk) |
| break; |
| - } |
| for (size_t j = 0; j < chunk->size(); ++j) { |
| - if (i > 0 || j > 0) |
| + if (json_events_str_ptr->size()) |
| json_events_str_ptr->data().append(","); |
| chunk->GetEventAt(j)->AppendAsJSON(&(json_events_str_ptr->data())); |
| } |
| } |
| - |
| flush_output_callback.Run(json_events_str_ptr, has_more_events); |
|
yurys
2014/12/17 08:50:30
Is it OK to run this callback on a worker thread?
loislo
2014/12/17 08:56:45
Done.
|
| } while (has_more_events); |
| } |
| @@ -1788,8 +1788,15 @@ void TraceLog::FinishFlush(int generation) { |
| flush_output_callback_.Reset(); |
| } |
| - ConvertTraceEventsToTraceFormat(previous_logged_events.Pass(), |
| - flush_output_callback); |
| + if (!WorkerPool::PostTask( |
| + FROM_HERE, |
| + Bind(&TraceLog::ConvertTraceEventsToTraceFormat, |
| + Passed(&previous_logged_events), |
| + flush_output_callback), |
| + true)) { |
| + ConvertTraceEventsToTraceFormat(previous_logged_events.Pass(), |
| + flush_output_callback); |
| + } |
| } |
| // Run in each thread holding a local event buffer. |