Created
October 24, 2018 23:46
-
-
Save seanhagen/b21cfe15f8486735756c0e21c1b37e3e to your computer and use it in GitHub Desktop.
Golang func to print memory usage
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(id int, name string) { | |
var m runtime.MemStats | |
runtime.ReadMemStats(&m) | |
// For info on each, see: https://golang.org/pkg/runtime/#MemStats | |
fmt.Printf( | |
"Call %v from %v -- Alloc = %v MiB\tTotalAlloc = %v MiB\tSys = %v MiB\tNumGC = %v\n", | |
id, | |
name, | |
bToMb(m.Alloc), | |
bToMb(m.TotalAlloc), | |
bToMb(m.Sys), | |
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