Skip to content

Instantly share code, notes, and snippets.

@vadviktor
Forked from thomas11/gist:2909362
Created April 25, 2018 06:32
Show Gist options
  • Save vadviktor/d888b13139c17dc0040add879264b313 to your computer and use it in GitHub Desktop.
Save vadviktor/d888b13139c17dc0040add879264b313 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