Add trace code to track all posted tasks in message_loop and WorkerThreads (non-official builds only).

It's very helpful to understand what chrome is doing at runtime. Sometimes a thread in chrome does something expensive that causes a frame hitch. With this change, any expensive task will show up clearly in traces, with the file/function of where the task was posted.

TEST=go to about:tracing, run a trace and notice that all tasks are traced.

Review URL: http://codereview.chromium.org/7778033

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@103740 0039d316-1c4b-4281-b951-d872f2087c98


CrOS-Libchrome-Original-Commit: 19d8a90fbc1fd7c26a873dc84fcbc875c509cf11
diff --git a/base/message_loop.cc b/base/message_loop.cc
index d96b57d..b4af87d 100644
--- a/base/message_loop.cc
+++ b/base/message_loop.cc
@@ -9,6 +9,7 @@
 #include "base/bind.h"
 #include "base/compiler_specific.h"
 #include "base/debug/alias.h"
+#include "base/debug/trace_event.h"
 #include "base/lazy_instance.h"
 #include "base/logging.h"
 #include "base/memory/scoped_ptr.h"
@@ -458,6 +459,9 @@
 }
 
 void MessageLoop::RunTask(const PendingTask& pending_task) {
+  UNSHIPPED_TRACE_EVENT2("task", "MessageLoop::RunTask",
+                         "src_file", pending_task.posted_from.file_name(),
+                         "src_func", pending_task.posted_from.function_name());
   DCHECK(nestable_tasks_allowed_);
   // Execute the task and assume the worst: It is probably not reentrant.
   nestable_tasks_allowed_ = false;
@@ -467,7 +471,8 @@
   // crashes. Be careful not to assume that the variable itself will have the
   // expected value when displayed by the optimizer in an optimized build.
   // Look at a memory dump of the stack.
-  const void* program_counter = pending_task.birth_program_counter;
+  const void* program_counter =
+      pending_task.posted_from.program_counter();
   base::debug::Alias(&program_counter);
 
   HistogramEvent(kTaskRunEvent);
@@ -765,9 +770,9 @@
     : task(task),
       time_posted(TimeTicks::Now()),
       delayed_run_time(delayed_run_time),
+      posted_from(posted_from),
       sequence_num(0),
-      nestable(nestable),
-      birth_program_counter(posted_from.program_counter()) {
+      nestable(nestable) {
 #if defined(TRACK_ALL_TASK_OBJECTS)
   post_births = tracked_objects::ThreadData::TallyABirthIfActive(posted_from);
 #endif  // defined(TRACK_ALL_TASK_OBJECTS)