[vm] Add timeline events for GC phases.

Change-Id: I1c4b58f848d590b5dce751167a7bbb23db2cb26b
Reviewed-on: https://dart-review.googlesource.com/66862
Reviewed-by: Alexander Aprelev <aam@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
diff --git a/runtime/vm/heap/marker.cc b/runtime/vm/heap/marker.cc
index c352abd..d871b08 100644
--- a/runtime/vm/heap/marker.cc
+++ b/runtime/vm/heap/marker.cc
@@ -445,10 +445,12 @@
                             intptr_t num_slices) {
   ASSERT(0 <= slice_index && slice_index < num_slices);
   if ((slice_index == 0) || (num_slices <= 1)) {
+    TIMELINE_FUNCTION_GC_DURATION(Thread::Current(), "ProcessRoots");
     isolate->VisitObjectPointers(visitor,
                                  ValidationPolicy::kDontValidateFrames);
   }
   if ((slice_index == 1) || (num_slices <= 1)) {
+    TIMELINE_FUNCTION_GC_DURATION(Thread::Current(), "ProcessNewSpace");
     heap_->new_space()->VisitObjectPointers(visitor);
   }
 
@@ -666,6 +668,7 @@
     marked_bytes_ = 0;
     const int num_tasks = FLAG_marker_tasks;
     if (num_tasks == 0) {
+      TIMELINE_FUNCTION_GC_DURATION(thread, "Mark");
       // Mark everything on main thread.
       SkippedCodeFunctions* skipped_code_functions =
           collect_code ? new (zone) SkippedCodeFunctions() : NULL;
@@ -674,7 +677,7 @@
       IterateRoots(isolate, &mark, 0, 1);
       mark.DrainMarkingStack();
       {
-        TIMELINE_FUNCTION_GC_DURATION(thread, "WeakHandleProcessing");
+        TIMELINE_FUNCTION_GC_DURATION(thread, "ProcessWeakHandles");
         MarkingWeakVisitor mark_weak(thread);
         IterateWeakRoots(isolate, &mark_weak);
       }
@@ -716,7 +719,7 @@
 
       // Phase 2: Weak processing on main thread.
       {
-        TIMELINE_FUNCTION_GC_DURATION(thread, "WeakHandleProcessing");
+        TIMELINE_FUNCTION_GC_DURATION(thread, "ProcessWeakHandles");
         MarkingWeakVisitor mark_weak(thread);
         IterateWeakRoots(isolate, &mark_weak);
       }
diff --git a/runtime/vm/heap/pages.cc b/runtime/vm/heap/pages.cc
index 4ef0975..00186fa 100644
--- a/runtime/vm/heap/pages.cc
+++ b/runtime/vm/heap/pages.cc
@@ -979,6 +979,8 @@
         heap_->VerifyGC(kAllowMarked);
         OS::PrintErr(" done.\n");
       }
+
+      TIMELINE_FUNCTION_GC_DURATION(thread, "SweepLargeAndExecutablePages");
       GCSweeper sweeper;
 
       // During stop-the-world phases we should use bulk lock when adding
@@ -1075,6 +1077,8 @@
 }
 
 void PageSpace::BlockingSweep() {
+  TIMELINE_FUNCTION_GC_DURATION(Thread::Current(), "Sweep");
+
   MutexLocker mld(freelist_[HeapPage::kData].mutex());
   MutexLocker mle(freelist_[HeapPage::kExecutable].mutex());
 
diff --git a/runtime/vm/heap/scavenger.cc b/runtime/vm/heap/scavenger.cc
index 761539b..b9ca038 100644
--- a/runtime/vm/heap/scavenger.cc
+++ b/runtime/vm/heap/scavenger.cc
@@ -577,10 +577,18 @@
 }
 
 void Scavenger::IterateRoots(Isolate* isolate, ScavengerVisitor* visitor) {
+  NOT_IN_PRODUCT(Thread* thread = Thread::Current());
   int64_t start = OS::GetCurrentMonotonicMicros();
-  isolate->VisitObjectPointers(visitor, ValidationPolicy::kDontValidateFrames);
+  {
+    TIMELINE_FUNCTION_GC_DURATION(thread, "ProcessRoots");
+    isolate->VisitObjectPointers(visitor,
+                                 ValidationPolicy::kDontValidateFrames);
+  }
   int64_t middle = OS::GetCurrentMonotonicMicros();
-  IterateStoreBuffers(isolate, visitor);
+  {
+    TIMELINE_FUNCTION_GC_DURATION(thread, "ProcessRememberedSet");
+    IterateStoreBuffers(isolate, visitor);
+  }
   IterateObjectIdTable(isolate, visitor);
   int64_t end = OS::GetCurrentMonotonicMicros();
   heap_->RecordData(kToKBAfterStoreBuffer, RoundWordsToKB(UsedInWords()));
@@ -890,10 +898,13 @@
     page_space->AcquireDataLock();
     IterateRoots(isolate, &visitor);
     int64_t iterate_roots = OS::GetCurrentMonotonicMicros();
-    ProcessToSpace(&visitor);
+    {
+      TIMELINE_FUNCTION_GC_DURATION(thread, "ProcessToSpace");
+      ProcessToSpace(&visitor);
+    }
     int64_t process_to_space = OS::GetCurrentMonotonicMicros();
     {
-      TIMELINE_FUNCTION_GC_DURATION(thread, "WeakHandleProcessing");
+      TIMELINE_FUNCTION_GC_DURATION(thread, "ProcessWeakHandles");
       ScavengerWeakVisitor weak_visitor(thread, this);
       IterateWeakRoots(isolate, &weak_visitor);
     }