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

Side by Side Diff: base/debug/trace_event_impl.cc

Issue 750183008: DevTools: Parallelize trace messages serialization. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments addressed Created 6 years 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 | no next file » | 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/debug/trace_event_impl.h" 5 #include "base/debug/trace_event_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/base_switches.h" 9 #include "base/base_switches.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 14 matching lines...) Expand all
25 #include "base/strings/string_tokenizer.h" 25 #include "base/strings/string_tokenizer.h"
26 #include "base/strings/string_util.h" 26 #include "base/strings/string_util.h"
27 #include "base/strings/stringprintf.h" 27 #include "base/strings/stringprintf.h"
28 #include "base/strings/utf_string_conversions.h" 28 #include "base/strings/utf_string_conversions.h"
29 #include "base/synchronization/cancellation_flag.h" 29 #include "base/synchronization/cancellation_flag.h"
30 #include "base/synchronization/waitable_event.h" 30 #include "base/synchronization/waitable_event.h"
31 #include "base/sys_info.h" 31 #include "base/sys_info.h"
32 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 32 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
33 #include "base/threading/platform_thread.h" 33 #include "base/threading/platform_thread.h"
34 #include "base/threading/thread_id_name_manager.h" 34 #include "base/threading/thread_id_name_manager.h"
35 #include "base/threading/worker_pool.h"
35 #include "base/time/time.h" 36 #include "base/time/time.h"
36 37
37 #if defined(OS_WIN) 38 #if defined(OS_WIN)
38 #include "base/debug/trace_event_win.h" 39 #include "base/debug/trace_event_win.h"
39 #endif 40 #endif
40 41
41 class DeleteTraceLogForTesting { 42 class DeleteTraceLogForTesting {
42 public: 43 public:
43 static void Delete() { 44 static void Delete() {
44 Singleton<base::debug::TraceLog, 45 Singleton<base::debug::TraceLog,
(...skipping 21 matching lines...) Expand all
66 const char kEnableSampling[] = "enable-sampling"; 67 const char kEnableSampling[] = "enable-sampling";
67 const char kEnableSystrace[] = "enable-systrace"; 68 const char kEnableSystrace[] = "enable-systrace";
68 69
69 // Controls the number of trace events we will buffer in-memory 70 // Controls the number of trace events we will buffer in-memory
70 // before throwing them away. 71 // before throwing them away.
71 const size_t kTraceBufferChunkSize = TraceBufferChunk::kTraceBufferChunkSize; 72 const size_t kTraceBufferChunkSize = TraceBufferChunk::kTraceBufferChunkSize;
72 const size_t kTraceEventVectorBigBufferChunks = 73 const size_t kTraceEventVectorBigBufferChunks =
73 512000000 / kTraceBufferChunkSize; 74 512000000 / kTraceBufferChunkSize;
74 const size_t kTraceEventVectorBufferChunks = 256000 / kTraceBufferChunkSize; 75 const size_t kTraceEventVectorBufferChunks = 256000 / kTraceBufferChunkSize;
75 const size_t kTraceEventRingBufferChunks = kTraceEventVectorBufferChunks / 4; 76 const size_t kTraceEventRingBufferChunks = kTraceEventVectorBufferChunks / 4;
76 const size_t kTraceEventBatchChunks = 1000 / kTraceBufferChunkSize; 77 const size_t kTraceEventBufferSize = 10 * 1024 * 1024;
77 // Can store results for 30 seconds with 1 ms sampling interval. 78 // Can store results for 30 seconds with 1 ms sampling interval.
78 const size_t kMonitorTraceEventBufferChunks = 30000 / kTraceBufferChunkSize; 79 const size_t kMonitorTraceEventBufferChunks = 30000 / kTraceBufferChunkSize;
79 // ECHO_TO_CONSOLE needs a small buffer to hold the unfinished COMPLETE events. 80 // ECHO_TO_CONSOLE needs a small buffer to hold the unfinished COMPLETE events.
80 const size_t kEchoToConsoleTraceEventBufferChunks = 256; 81 const size_t kEchoToConsoleTraceEventBufferChunks = 256;
81 82
82 const int kThreadFlushTimeoutMs = 3000; 83 const int kThreadFlushTimeoutMs = 3000;
83 84
84 #if !defined(OS_NACL) 85 #if !defined(OS_NACL)
85 // These categories will cause deadlock when ECHO_TO_CONSOLE. crbug.com/325575. 86 // These categories will cause deadlock when ECHO_TO_CONSOLE. crbug.com/325575.
86 const char kEchoToConsoleCategoryFilter[] = "-ipc,-task"; 87 const char kEchoToConsoleCategoryFilter[] = "-ipc,-task";
(...skipping 1658 matching lines...) Expand 10 before | Expand all | Expand 10 after
1745 if (flush_output_callback.is_null()) 1746 if (flush_output_callback.is_null())
1746 return; 1747 return;
1747 1748
1748 // The callback need to be called at least once even if there is no events 1749 // The callback need to be called at least once even if there is no events
1749 // to let the caller know the completion of flush. 1750 // to let the caller know the completion of flush.
1750 bool has_more_events = true; 1751 bool has_more_events = true;
1751 do { 1752 do {
1752 scoped_refptr<RefCountedString> json_events_str_ptr = 1753 scoped_refptr<RefCountedString> json_events_str_ptr =
1753 new RefCountedString(); 1754 new RefCountedString();
1754 1755
1755 for (size_t i = 0; i < kTraceEventBatchChunks; ++i) { 1756 while (json_events_str_ptr->size() < kTraceEventBufferSize) {
1756 const TraceBufferChunk* chunk = logged_events->NextChunk(); 1757 const TraceBufferChunk* chunk = logged_events->NextChunk();
1757 if (!chunk) { 1758 has_more_events = chunk;
1758 has_more_events = false; 1759 if (!chunk)
1759 break; 1760 break;
1760 }
1761 for (size_t j = 0; j < chunk->size(); ++j) { 1761 for (size_t j = 0; j < chunk->size(); ++j) {
1762 if (i > 0 || j > 0) 1762 if (json_events_str_ptr->size())
1763 json_events_str_ptr->data().append(","); 1763 json_events_str_ptr->data().append(",");
1764 chunk->GetEventAt(j)->AppendAsJSON(&(json_events_str_ptr->data())); 1764 chunk->GetEventAt(j)->AppendAsJSON(&(json_events_str_ptr->data()));
1765 } 1765 }
1766 } 1766 }
1767
1768 flush_output_callback.Run(json_events_str_ptr, has_more_events); 1767 flush_output_callback.Run(json_events_str_ptr, has_more_events);
1769 } while (has_more_events); 1768 } while (has_more_events);
1770 } 1769 }
1771 1770
1772 void TraceLog::FinishFlush(int generation) { 1771 void TraceLog::FinishFlush(int generation) {
1773 scoped_ptr<TraceBuffer> previous_logged_events; 1772 scoped_ptr<TraceBuffer> previous_logged_events;
1774 OutputCallback flush_output_callback; 1773 OutputCallback flush_output_callback;
1775 1774
1776 if (!CheckGeneration(generation)) 1775 if (!CheckGeneration(generation))
1777 return; 1776 return;
1778 1777
1779 { 1778 {
1780 AutoLock lock(lock_); 1779 AutoLock lock(lock_);
1781 1780
1782 previous_logged_events.swap(logged_events_); 1781 previous_logged_events.swap(logged_events_);
1783 UseNextTraceBuffer(); 1782 UseNextTraceBuffer();
1784 thread_message_loops_.clear(); 1783 thread_message_loops_.clear();
1785 1784
1786 flush_message_loop_proxy_ = NULL; 1785 flush_message_loop_proxy_ = NULL;
1787 flush_output_callback = flush_output_callback_; 1786 flush_output_callback = flush_output_callback_;
1788 flush_output_callback_.Reset(); 1787 flush_output_callback_.Reset();
1789 } 1788 }
1790 1789
1791 ConvertTraceEventsToTraceFormat(previous_logged_events.Pass(), 1790 if (!WorkerPool::PostTask(
1792 flush_output_callback); 1791 FROM_HERE,
1792 Bind(&TraceLog::ConvertTraceEventsToTraceFormat,
Sami 2014/12/10 14:56:01 Could you turn ConvertTraceEventsToTraceFormat int
loislo 2014/12/10 15:31:38 Done.
1793 Unretained(this),
1794 Passed(&previous_logged_events),
1795 flush_output_callback),
1796 true)) {
1797 ConvertTraceEventsToTraceFormat(previous_logged_events.Pass(),
1798 flush_output_callback);
1799 }
1793 } 1800 }
1794 1801
1795 // Run in each thread holding a local event buffer. 1802 // Run in each thread holding a local event buffer.
1796 void TraceLog::FlushCurrentThread(int generation) { 1803 void TraceLog::FlushCurrentThread(int generation) {
1797 { 1804 {
1798 AutoLock lock(lock_); 1805 AutoLock lock(lock_);
1799 if (!CheckGeneration(generation) || !flush_message_loop_proxy_.get()) { 1806 if (!CheckGeneration(generation) || !flush_message_loop_proxy_.get()) {
1800 // This is late. The corresponding flush has finished. 1807 // This is late. The corresponding flush has finished.
1801 return; 1808 return;
1802 } 1809 }
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after
2572 } 2579 }
2573 2580
2574 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { 2581 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() {
2575 if (*category_group_enabled_) { 2582 if (*category_group_enabled_) {
2576 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, 2583 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_,
2577 name_, event_handle_); 2584 name_, event_handle_);
2578 } 2585 }
2579 } 2586 }
2580 2587
2581 } // namespace trace_event_internal 2588 } // namespace trace_event_internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698