Skip to content

Instantly share code, notes, and snippets.

@bagasdisini
Last active June 7, 2024 06:31
Show Gist options
  • Save bagasdisini/5147e8a4abf058fda186c8bd8ef1c24b to your computer and use it in GitHub Desktop.
Save bagasdisini/5147e8a4abf058fda186c8bd8ef1c24b to your computer and use it in GitHub Desktop.
Go - Print Current Memory Usage
func PrintMemUsage() {
var m runtime.MemStats
runtime.ReadMemStats(&m)
fmt.Printf("Alloc = %v MiB", m.Alloc / 1024 / 1024)
fmt.Printf("\tTotalAlloc = %v MiB", m.TotalAlloc / 1024 / 1024)
fmt.Printf("\tSys = %v MiB", m.Sys / 1024 / 1024)
fmt.Printf("\tNumGC = %v\n", m.NumGC)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment