From 8c3fc088fbe1a25be73430a20a0c76af3c68d2f5 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Thu, 2 Apr 2015 19:53:02 -0400 Subject: [PATCH] runtime: report marked heap size in gctrace When the gctrace GODEBUG option is enabled, it will now report three heap sizes: the heap size at the beginning of the GC cycle, the heap size at the end of the GC cycle before sweeping, and marked heap size, which is the amount of heap that will be retained until the next GC cycle. Change-Id: Ie13f8a6d5c609bc9cc47c7555960ab55b37b5f1c Reviewed-on: https://go-review.googlesource.com/8430 Reviewed-by: Rick Hudson --- src/runtime/mgc.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/runtime/mgc.go b/src/runtime/mgc.go index fc6fbd57682dfc..855430e48c7603 100644 --- a/src/runtime/mgc.go +++ b/src/runtime/mgc.go @@ -294,7 +294,7 @@ func gc(mode int) { // debug.gctrace variables var stwprocs, maxprocs int32 var tSweepTerm, tScan, tInstallWB, tMark, tMarkTerm int64 - var heap0, heap1 uint64 + var heap0, heap1, heap2 uint64 // Ok, we're doing it! Stop everybody else semacquire(&worldsema, false) @@ -414,6 +414,9 @@ func gc(mode int) { // need to switch to g0 so we can shrink the stack. systemstack(func() { gcMark(startTime) + if debug.gctrace > 0 { + heap2 = work.bytesMarked + } if debug.gccheckmark > 0 { // Run a full stop-the-world mark using checkmark bits, // to check that we didn't forget to mark anything during @@ -481,7 +484,6 @@ func gc(mode int) { memstats.numgc++ if debug.gctrace > 0 { - // TODO(austin): Marked heap size at end tEnd := nanotime() // Update work.totaltime @@ -512,7 +514,7 @@ func gc(mode int) { "+", installWBCpu/1e6, "+", markCpu/1e6, "+", markTermCpu/1e6, " ms cpu, ", - heap0>>20, "->", heap1>>20, " MB, ", + heap0>>20, "->", heap1>>20, "->", heap2>>20, " MB, ", maxprocs, " P") if mode != gcBackgroundMode { print(" (forced)")