cmd/trace: Record mark assists in execution traces

During the mark phase of garbage collection, goroutines that allocate
may be recruited to assist. This change creates trace events for mark
assists and displays them similarly to sweep assists in the trace
viewer.

Mark assists are different than sweeps in that they can be preempted, so
displaying them in the trace viewer is a little tricky -- we may need to
synthesize multiple slices for one mark assist. This could have been
done in the parser instead, but I thought it might be preferable to keep
the parser as true to the event stream as possible.

Change-Id: I381dcb1027a187a354b1858537851fa68a620ea7
Reviewed-on: https://go-review.googlesource.com/36015
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
diff --git a/src/runtime/mgcmark.go b/src/runtime/mgcmark.go
index 85130bf..7f47044 100644
--- a/src/runtime/mgcmark.go
+++ b/src/runtime/mgcmark.go
@@ -415,6 +415,10 @@
 		return
 	}
 
+	if trace.enabled {
+		traceGCMarkAssistStart()
+	}
+
 retry:
 	// Compute the amount of scan work we need to do to make the
 	// balance positive. When the required amount of work is low,
@@ -450,6 +454,9 @@
 		if scanWork == 0 {
 			// We were able to steal all of the credit we
 			// needed.
+			if trace.enabled {
+				traceGCMarkAssistDone()
+			}
 			return
 		}
 	}
@@ -496,6 +503,9 @@
 		// At this point either background GC has satisfied
 		// this G's assist debt, or the GC cycle is over.
 	}
+	if trace.enabled {
+		traceGCMarkAssistDone()
+	}
 }
 
 // gcAssistAlloc1 is the part of gcAssistAlloc that runs on the system