From 29fdbcfea37f3bf519f678b1426277b70406c029 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Mon, 27 Feb 2017 10:46:12 -0500 Subject: [PATCH] runtime: track forced GCs independent of gcMode Currently gcMode != gcBackgroundMode implies this was a user-forced GC cycle. This is no longer going to be true when we make runtime.GC() trigger a concurrent GC, so replace this with an explicit work.userForced bit. For #18216. Change-Id: If7d71bbca78b5f0b35641b070f9d457f5c9a52bd Reviewed-on: https://go-review.googlesource.com/37519 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Rick Hudson --- src/runtime/mgc.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/runtime/mgc.go b/src/runtime/mgc.go index bcd43d8f34..ba7cf9cb14 100644 --- a/src/runtime/mgc.go +++ b/src/runtime/mgc.go @@ -857,6 +857,10 @@ var work struct { // mode is the concurrency mode of the current GC cycle. mode gcMode + // userForced indicates the current GC cycle was forced by an + // explicit user call. + userForced bool + // totaltime is the CPU nanoseconds spent in GC since the // program started if debug.gctrace > 0. totaltime int64 @@ -992,7 +996,7 @@ func gcStart(mode gcMode, trigger gcTrigger) { } // For stats, check if this GC was forced by the user. - forced := trigger.kind == gcTriggerAlways + work.userForced = trigger.kind == gcTriggerAlways // In gcstoptheworld debug mode, upgrade the mode accordingly. // We do this after re-checking the transition condition so @@ -1087,10 +1091,6 @@ func gcStart(mode gcMode, trigger gcTrigger) { work.tMark, work.tMarkTerm = t, t work.heapGoal = work.heap0 - if forced { - memstats.numforcedgc++ - } - // Perform mark termination. This will restart the world. gcMarkTermination() } @@ -1330,6 +1330,10 @@ func gcMarkTermination() { sweep.nbgsweep = 0 sweep.npausesweep = 0 + if work.userForced { + memstats.numforcedgc++ + } + // Finish the current heap profiling cycle and start a new // heap profiling cycle. We do this before starting the world // so events don't leak into the wrong cycle. @@ -1378,7 +1382,7 @@ func gcMarkTermination() { work.heap0>>20, "->", work.heap1>>20, "->", work.heap2>>20, " MB, ", work.heapGoal>>20, " MB goal, ", work.maxprocs, " P") - if work.mode != gcBackgroundMode { + if work.userForced { print(" (forced)") } print("\n") -- 2.48.1