summaryrefslogtreecommitdiffstats
path: root/base/message_loop.cc
diff options
context:
space:
mode:
authorjbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-18 03:41:29 +0000
committerjbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-18 03:41:29 +0000
commit2c391df878dc6187bbb8a26d34260ed46f18d139 (patch)
treee50370b6faf481726d7b7810f4b89dd55be7d494 /base/message_loop.cc
parent108a0513d108857ba2e943b8f70bd68dc3a98a18 (diff)
downloadchromium_src-2c391df878dc6187bbb8a26d34260ed46f18d139.zip
chromium_src-2c391df878dc6187bbb8a26d34260ed46f18d139.tar.gz
chromium_src-2c391df878dc6187bbb8a26d34260ed46f18d139.tar.bz2
Trace PostTasks from post to run.
To do this properly, we need a new type of trace event "FLOW" which will be drawn as lines in about:tracing from BEGIN to END. Also instruments SequencedWorkerPool and ChannelReader::DispatchInputData, which were not currently traced. BUG=79942 Review URL: https://codereview.chromium.org/10913242 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@157288 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/message_loop.cc')
-rw-r--r--base/message_loop.cc27
1 files changed, 20 insertions, 7 deletions
diff --git a/base/message_loop.cc b/base/message_loop.cc
index 32994bf..21108eb 100644
--- a/base/message_loop.cc
+++ b/base/message_loop.cc
@@ -91,6 +91,14 @@ bool enable_histogrammer_ = false;
MessageLoop::MessagePumpFactory* message_pump_for_ui_factory_ = NULL;
+// Create a process-wide unique ID to represent this task in trace events. This
+// will be mangled with a Process ID hash to reduce the likelyhood of colliding
+// with MessageLoop pointers on other processes.
+uint64 GetTaskTraceID(const PendingTask& task, MessageLoop* loop) {
+ return (static_cast<uint64>(task.sequence_num) << 32) |
+ static_cast<uint64>(reinterpret_cast<intptr_t>(loop));
+}
+
} // namespace
//------------------------------------------------------------------------------
@@ -434,6 +442,8 @@ bool MessageLoop::ProcessNextDelayedNonNestableTask() {
}
void MessageLoop::RunTask(const PendingTask& pending_task) {
+ TRACE_EVENT_FLOW_END0("task", "MessageLoop::PostTask",
+ TRACE_ID_MANGLE(GetTaskTraceID(pending_task, this)));
TRACE_EVENT2("task", "MessageLoop::RunTask",
"src_file", pending_task.posted_from.file_name(),
"src_func", pending_task.posted_from.function_name());
@@ -482,13 +492,8 @@ bool MessageLoop::DeferOrRunPendingTask(const PendingTask& pending_task) {
}
void MessageLoop::AddToDelayedWorkQueue(const PendingTask& pending_task) {
- // Move to the delayed work queue. Initialize the sequence number
- // before inserting into the delayed_work_queue_. The sequence number
- // is used to faciliate FIFO sorting when two tasks have the same
- // delayed_run_time value.
- PendingTask new_pending_task(pending_task);
- new_pending_task.sequence_num = next_sequence_num_++;
- delayed_work_queue_.push(new_pending_task);
+ // Move to the delayed work queue.
+ delayed_work_queue_.push(pending_task);
}
void MessageLoop::ReloadWorkQueue() {
@@ -586,6 +591,14 @@ void MessageLoop::AddToIncomingQueue(PendingTask* pending_task) {
{
base::AutoLock locked(incoming_queue_lock_);
+ // Initialize the sequence number. The sequence number is used for delayed
+ // tasks (to faciliate FIFO sorting when two tasks have the same
+ // delayed_run_time value) and for identifying the task in about:tracing.
+ pending_task->sequence_num = next_sequence_num_++;
+
+ TRACE_EVENT_FLOW_BEGIN0("task", "MessageLoop::PostTask",
+ TRACE_ID_MANGLE(GetTaskTraceID(*pending_task, this)));
+
bool was_empty = incoming_queue_.empty();
incoming_queue_.push(*pending_task);
pending_task->task.Reset();