Skip to content

Instantly share code, notes, and snippets.

@daehee
Created December 30, 2020 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daehee/5cbbe44737b08b077782426307e24ec4 to your computer and use it in GitHub Desktop.
Save daehee/5cbbe44737b08b077782426307e24ec4 to your computer and use it in GitHub Desktop.
Go: PrintMemUsage
func PrintMemUsage() {
var m runtime.MemStats
runtime.ReadMemStats(&m)
// For info on each, see: https://golang.org/pkg/runtime/#MemStats
fmt.Printf("Alloc = %v MiB", bToMb(m.Alloc))
fmt.Printf("\tTotalAlloc = %v MiB", bToMb(m.TotalAlloc))
fmt.Printf("\tSys = %v MiB", bToMb(m.Sys))
fmt.Printf("\tNumGC = %v\n", m.NumGC)
}
func bToMb(b uint64) uint64 {
return b / 1024 / 1024
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment