From 1be3e76e7628cae8500c0c1f3aa620638aec351d Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Wed, 1 Mar 2017 21:03:20 -0500 Subject: [PATCH] runtime: simplify heap profile flushing Currently the heap profile is flushed by *either* gcSweep in STW mode or by gcMarkTermination in concurrent mode. Simplify this by making gcMarkTermination always flush the heap profile and by making gcSweep do one extra flush (instead of two) in STW mode. Change-Id: I62147afb2a128e1f3d92ef4bb8144c8a345f53c4 Reviewed-on: https://go-review.googlesource.com/37715 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Rick Hudson --- src/runtime/mgc.go | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/runtime/mgc.go b/src/runtime/mgc.go index 31e8e4caee..0d4178dd9e 100644 --- a/src/runtime/mgc.go +++ b/src/runtime/mgc.go @@ -1302,23 +1302,17 @@ func gcMarkTermination() { sweep.nbgsweep = 0 sweep.npausesweep = 0 - // If gcSweep didn't do it, 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. - needProfCycle := _ConcurrentSweep && work.mode != gcForceBlockMode - if needProfCycle { - mProf_NextCycle() - } + // 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. + mProf_NextCycle() systemstack(startTheWorldWithSema) // Flush the heap profile so we can start a new cycle next GC. // This is relatively expensive, so we don't do it with the // world stopped. - if needProfCycle { - mProf_Flush() - } + mProf_Flush() // Free stack spans. This must be done between GC cycles. systemstack(freeStackSpans) @@ -1763,10 +1757,9 @@ func gcSweep(mode gcMode) { for sweepone() != ^uintptr(0) { sweep.npausesweep++ } - // All "free" events are now real, so flush everything - // into the published profile. - mProf_NextCycle() - mProf_Flush() + // All "free" events for this mark/sweep cycle have + // now happened, so we can make this profile cycle + // available immediately. mProf_NextCycle() mProf_Flush() return -- 2.48.1