Skip to content

Instantly share code, notes, and snippets.

@thomas11
Created June 11, 2012 09:52
Show Gist options
  • Star 25 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save thomas11/2909362 to your computer and use it in GitHub Desktop.
Save thomas11/2909362 to your computer and use it in GitHub Desktop.
Log memory usage every n seconds in Go #golang
import (
"runtime"
"time"
)
...
go func() {
for {
var m runtime.MemStats
runtime.ReadMemStats(&m)
log.Printf("\nAlloc = %v\nTotalAlloc = %v\nSys = %v\nNumGC = %v\n\n", m.Alloc / 1024, m.TotalAlloc / 1024, m.Sys / 1024, m.NumGC)
time.Sleep(5 * time.Second)
}
}()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment