Created
December 30, 2020 22:42
-
-
Save daehee/5cbbe44737b08b077782426307e24ec4 to your computer and use it in GitHub Desktop.
Go: PrintMemUsage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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