Commit 4b71660c authored by Austin Clements's avatar Austin Clements

runtime: always capture GC phase transition times

Currently we only capture GC phase transition times if
debug.gctrace>0, but we're about to compute GC CPU utilization
regardless of whether debug.gctrace is set, so we need these
regardless of debug.gctrace.

Change-Id: If3acf16505a43d416e9a99753206f03287180660
Reviewed-on: https://go-review.googlesource.com/12843Reviewed-by: default avatarRuss Cox <rsc@golang.org>
Reviewed-by: default avatarRick Hudson <rlh@golang.org>
parent 87f97c73
...@@ -880,9 +880,11 @@ func backgroundgc() { ...@@ -880,9 +880,11 @@ func backgroundgc() {
} }
func gc(mode int) { func gc(mode int) {
// debug.gctrace variables // Timing/utilization tracking
var stwprocs, maxprocs int32 var stwprocs, maxprocs int32
var tSweepTerm, tScan, tInstallWB, tMark, tMarkTerm int64 var tSweepTerm, tScan, tInstallWB, tMark, tMarkTerm int64
// debug.gctrace variables
var heap0, heap1, heap2, heapGoal uint64 var heap0, heap1, heap2, heapGoal uint64
// memstats statistics // memstats statistics
...@@ -910,11 +912,9 @@ func gc(mode int) { ...@@ -910,11 +912,9 @@ func gc(mode int) {
gcBgMarkStartWorkers() gcBgMarkStartWorkers()
} }
now = nanotime() now = nanotime()
if debug.gctrace > 0 { stwprocs, maxprocs = gcprocs(), gomaxprocs
stwprocs, maxprocs = gcprocs(), gomaxprocs tSweepTerm = now
tSweepTerm = now heap0 = memstats.heap_live
heap0 = memstats.heap_live
}
pauseStart = now pauseStart = now
systemstack(stopTheWorldWithSema) systemstack(stopTheWorldWithSema)
...@@ -970,15 +970,11 @@ func gc(mode int) { ...@@ -970,15 +970,11 @@ func gc(mode int) {
startTheWorldWithSema() startTheWorldWithSema()
now = nanotime() now = nanotime()
pauseNS += now - pauseStart pauseNS += now - pauseStart
if debug.gctrace > 0 { tScan = now
tScan = now
}
gcscan_m() gcscan_m()
// Enter mark phase. // Enter mark phase.
if debug.gctrace > 0 { tInstallWB = nanotime()
tInstallWB = nanotime()
}
setGCPhase(_GCmark) setGCPhase(_GCmark)
// Ensure all Ps have observed the phase // Ensure all Ps have observed the phase
// change and have write barriers enabled // change and have write barriers enabled
...@@ -986,9 +982,7 @@ func gc(mode int) { ...@@ -986,9 +982,7 @@ func gc(mode int) {
forEachP(func(*p) {}) forEachP(func(*p) {})
}) })
// Concurrent mark. // Concurrent mark.
if debug.gctrace > 0 { tMark = nanotime()
tMark = nanotime()
}
// Enable background mark workers and wait for // Enable background mark workers and wait for
// background mark completion. // background mark completion.
...@@ -1022,9 +1016,7 @@ func gc(mode int) { ...@@ -1022,9 +1016,7 @@ func gc(mode int) {
// Begin mark termination. // Begin mark termination.
now = nanotime() now = nanotime()
if debug.gctrace > 0 { tMarkTerm = now
tMarkTerm = now
}
pauseStart = now pauseStart = now
systemstack(stopTheWorldWithSema) systemstack(stopTheWorldWithSema)
// The gcphase is _GCmark, it will transition to _GCmarktermination // The gcphase is _GCmark, it will transition to _GCmarktermination
...@@ -1043,11 +1035,9 @@ func gc(mode int) { ...@@ -1043,11 +1035,9 @@ func gc(mode int) {
// such that mark termination scans all stacks. // such that mark termination scans all stacks.
gcResetGState() gcResetGState()
if debug.gctrace > 0 { t := nanotime()
t := nanotime() tScan, tInstallWB, tMark, tMarkTerm = t, t, t, t
tScan, tInstallWB, tMark, tMarkTerm = t, t, t, t heapGoal = heap0
heapGoal = heap0
}
} }
// World is stopped. // World is stopped.
...@@ -1056,10 +1046,7 @@ func gc(mode int) { ...@@ -1056,10 +1046,7 @@ func gc(mode int) {
gcBlackenPromptly = false gcBlackenPromptly = false
setGCPhase(_GCmarktermination) setGCPhase(_GCmarktermination)
if debug.gctrace > 0 { heap1 = memstats.heap_live
heap1 = memstats.heap_live
}
startTime := nanotime() startTime := nanotime()
mp := acquirem() mp := acquirem()
...@@ -1077,9 +1064,7 @@ func gc(mode int) { ...@@ -1077,9 +1064,7 @@ func gc(mode int) {
// need to switch to g0 so we can shrink the stack. // need to switch to g0 so we can shrink the stack.
systemstack(func() { systemstack(func() {
gcMark(startTime) gcMark(startTime)
if debug.gctrace > 0 { heap2 = work.bytesMarked
heap2 = work.bytesMarked
}
if debug.gccheckmark > 0 { if debug.gccheckmark > 0 {
// Run a full stop-the-world mark using checkmark bits, // Run a full stop-the-world mark using checkmark bits,
// to check that we didn't forget to mark anything during // to check that we didn't forget to mark anything during
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment