summaryrefslogtreecommitdiffstats
path: root/base/trace_event
diff options
context:
space:
mode:
authorloislo <loislo@chromium.org>2015-02-12 12:11:55 -0800
committerCommit bot <commit-bot@chromium.org>2015-02-12 20:12:47 +0000
commitd46e145dc210a5c71e3663de30a37373bca05872 (patch)
tree59b4eefb9edbff551017aa1a1bf4c167fff93c27 /base/trace_event
parent430dd40660ff8e834e91c178feb3078d134b9f8b (diff)
downloadchromium_src-d46e145dc210a5c71e3663de30a37373bca05872.zip
chromium_src-d46e145dc210a5c71e3663de30a37373bca05872.tar.gz
chromium_src-d46e145dc210a5c71e3663de30a37373bca05872.tar.bz2
Revert of DevTools: Parallelize trace messages serialization. (patchset #8 id:160001 of https://codereview.chromium.org/750183008/)
Reason for revert: looks like it breaks image_decoding_measurements http://build.chromium.org/p/chromium.perf/builders/Win%20XP%20Perf%20%283%29/builds/4285 Original issue's description: > DevTools: Parallelize trace messages serialization. > > Move serialization into a worker thread. As a result > IO thread will be able to send messages to the browser. > > The original implementation did serialization on IO thread > and was not able to send the messages because ipc had > is_blocked_on_write_ = true and had no chance to check > the actual state of the channel. So the messages were > collected in output_queue. Also the messages could be quite > big and could block the IO thread for a long time. > > BUG= > > Committed: https://crrev.com/d58e06aafd6572e681f9d30f313bf5393db9f2bc > Cr-Commit-Position: refs/heads/master@{#308773} > > Committed: https://crrev.com/e7d8d8b60e331469a7af4936e9fcc16630fb8fdf > Cr-Commit-Position: refs/heads/master@{#315957} TBR=nduca@chromium.org,pfeldman@chromium.org,caseq@chromium.org,yurys@chromium.org,wangxianzhu@chromium.org,skyostil@google.com,dsinclair@chromium.org,skyostil@chromium.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG= Review URL: https://codereview.chromium.org/923693002 Cr-Commit-Position: refs/heads/master@{#316038}
Diffstat (limited to 'base/trace_event')
-rw-r--r--base/trace_event/trace_event_impl.cc31
-rw-r--r--base/trace_event/trace_event_impl.h10
2 files changed, 12 insertions, 29 deletions
diff --git a/base/trace_event/trace_event_impl.cc b/base/trace_event/trace_event_impl.cc
index 763ff46..95cf06d 100644
--- a/base/trace_event/trace_event_impl.cc
+++ b/base/trace_event/trace_event_impl.cc
@@ -30,7 +30,6 @@
#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"
#include "base/trace_event/trace_event.h"
#include "base/trace_event/trace_event_synthetic_delay.h"
@@ -74,7 +73,7 @@ const size_t kTraceEventVectorBigBufferChunks =
512000000 / kTraceBufferChunkSize;
const size_t kTraceEventVectorBufferChunks = 256000 / kTraceBufferChunkSize;
const size_t kTraceEventRingBufferChunks = kTraceEventVectorBufferChunks / 4;
-const size_t kTraceEventBufferSizeInBytes = 10 * 1024 * 1024;
+const size_t kTraceEventBatchChunks = 1000 / kTraceBufferChunkSize;
// 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.
@@ -1212,8 +1211,7 @@ TraceLog::TraceLog()
event_callback_category_filter_(
CategoryFilter::kDefaultCategoryFilterString),
thread_shared_chunk_index_(0),
- generation_(0),
- use_worker_thread_(false) {
+ generation_(0) {
// Trace is enabled or disabled on one thread while other threads are
// accessing the enabled flag. We don't care whether edge-case events are
// traced or not, so we allow races on the enabled flag to keep the trace
@@ -1686,9 +1684,7 @@ void TraceLog::SetEventCallbackDisabled() {
// - The message loop will be removed from thread_message_loops_;
// If this is the last message loop, finish the flush;
// 4. If any thread hasn't finish its flush in time, finish the flush.
-void TraceLog::Flush(const TraceLog::OutputCallback& cb,
- bool use_worker_thread) {
- use_worker_thread_ = use_worker_thread;
+void TraceLog::Flush(const TraceLog::OutputCallback& cb) {
if (IsEnabled()) {
// Can't flush when tracing is enabled because otherwise PostTask would
// - generate more trace events;
@@ -1742,7 +1738,6 @@ 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) {
@@ -1757,17 +1752,19 @@ void TraceLog::ConvertTraceEventsToTraceFormat(
scoped_refptr<RefCountedString> json_events_str_ptr =
new RefCountedString();
- while (json_events_str_ptr->size() < kTraceEventBufferSizeInBytes) {
+ for (size_t i = 0; i < kTraceEventBatchChunks; ++i) {
const TraceBufferChunk* chunk = logged_events->NextChunk();
- has_more_events = chunk != NULL;
- if (!chunk)
+ if (!chunk) {
+ has_more_events = false;
break;
+ }
for (size_t j = 0; j < chunk->size(); ++j) {
- if (json_events_str_ptr->size())
+ if (i > 0 || j > 0)
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);
}
@@ -1791,16 +1788,6 @@ void TraceLog::FinishFlush(int generation) {
flush_output_callback_.Reset();
}
- if (use_worker_thread_ &&
- WorkerPool::PostTask(
- FROM_HERE,
- Bind(&TraceLog::ConvertTraceEventsToTraceFormat,
- Passed(&previous_logged_events),
- flush_output_callback),
- true)) {
- return;
- }
-
ConvertTraceEventsToTraceFormat(previous_logged_events.Pass(),
flush_output_callback);
}
diff --git a/base/trace_event/trace_event_impl.h b/base/trace_event/trace_event_impl.h
index c3da0b5e..efa20c4 100644
--- a/base/trace_event/trace_event_impl.h
+++ b/base/trace_event/trace_event_impl.h
@@ -538,11 +538,10 @@ class BASE_EXPORT TraceLog {
// Due to the implementation of thread-local buffers, flush can't be
// done when tracing is enabled. If called when tracing is enabled, the
// callback will be called directly with (empty_string, false) to indicate
- // the end of this unsuccessful flush. Flush does the serialization
- // on the same thread if the caller doesn't set use_worker_thread explicitly.
+ // the end of this unsuccessful flush.
typedef base::Callback<void(const scoped_refptr<base::RefCountedString>&,
bool has_more_events)> OutputCallback;
- void Flush(const OutputCallback& cb, bool use_worker_thread = false);
+ void Flush(const OutputCallback& cb);
void FlushButLeaveBufferIntact(const OutputCallback& flush_output_callback);
// Called by TRACE_EVENT* macros, don't call this directly.
@@ -711,9 +710,7 @@ class BASE_EXPORT TraceLog {
// |generation| is used in the following callbacks to check if the callback
// is called for the flush of the current |logged_events_|.
void FlushCurrentThread(int generation);
- // Usually it runs on a different thread.
- static void ConvertTraceEventsToTraceFormat(
- scoped_ptr<TraceBuffer> logged_events,
+ void ConvertTraceEventsToTraceFormat(scoped_ptr<TraceBuffer> logged_events,
const TraceLog::OutputCallback& flush_output_callback);
void FinishFlush(int generation);
void OnFlushTimeout(int generation);
@@ -806,7 +803,6 @@ class BASE_EXPORT TraceLog {
OutputCallback flush_output_callback_;
scoped_refptr<MessageLoopProxy> flush_message_loop_proxy_;
subtle::AtomicWord generation_;
- bool use_worker_thread_;
DISALLOW_COPY_AND_ASSIGN(TraceLog);
};