Trace memory records source function for posted tasks instead of "RunTask"

The chrome://tracing system for memory intentionally only records two pieces
of data for each TRACE_EVENT - the category and name of the event. This keeps
its data structures small (since tcmalloc reads them frequently during heap
profiling) and is all that is needed for binning most allocations into groups.

However, grouping all memory allocated by posted tasks under "RunTask" isn't
useful - the user needs to know which task actually resulted in the memory
allocations. This patch attributes the allocations to the source function of
the task, allowing the user to find the actual source.

BUG=trace-viewer:331
TEST=manual, run chrome://tracing with memory checked, click on a sample in the heap row, the breakdown shows individual function names instead of "RunTask"

Review URL: https://chromiumcodereview.appspot.com/22909045

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


CrOS-Libchrome-Original-Commit: 746e78f600be8a863dd4850e56f97cb3f0571722
diff --git a/base/message_loop/message_loop.cc b/base/message_loop/message_loop.cc
index 92039e2..4fb13c2 100644
--- a/base/message_loop/message_loop.cc
+++ b/base/message_loop/message_loop.cc
@@ -458,9 +458,13 @@
       TRACE_ID_MANGLE(GetTaskTraceID(pending_task)),
       "queue_duration",
       (start_time - pending_task.EffectiveTimePosted()).InMilliseconds());
-  TRACE_EVENT2("task", "MessageLoop::RunTask",
-               "src_file", pending_task.posted_from.file_name(),
-               "src_func", pending_task.posted_from.function_name());
+  // When tracing memory for posted tasks it's more valuable to attribute the
+  // memory allocations to the source function than generically to "RunTask".
+  TRACE_EVENT_WITH_MEMORY_TAG2(
+      "task", "MessageLoop::RunTask",
+      pending_task.posted_from.function_name(),  // Name for memory tracking.
+      "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.