How to collect information about garbage collection?

Under runtime/debug package function GCStats collects information about recent garbage collections. And PrintStack prints to standard error the stack trace returned by runtime.Stack.
package main
import (
var (
	garPercent = flag.Int("garC", 50, "Collect information about recent garbage collections")
func main() {
	var garC debug.GCStats
	fmt.Printf("\nLastGC:\t%s", garC.LastGC) // time of last collection
	fmt.Printf("\nNumGC:\t%d", garC.NumGC) // number of garbage collections
	fmt.Printf("\nPauseTotal:\t%s", garC.PauseTotal) // total pause for all collections
	fmt.Printf("\nPause:\t%s", garC.Pause) // pause history, most recent first	
C:\golang\codes>go run example.go
goroutine 1 [running]:
runtime/debug.Stack(0x4122b6, 0x2, 0x0)
C:/Go/src/runtime/debug/stack.go:24 +0x64
C:/Go/src/runtime/debug/stack.go:16 +0x1a
C:/golang/codes/example.go:15 +0x2e

LastGC: 2017-10-29 13:54:12.9605418 +0530 IST
NumGC: 1
PauseTotal: 0s
Pause: [0s]

Thanks for reading. Please leave your valuable feedback and comments.

* Required Fields

No questions yet. Be the first to ask the question!