Created
June 11, 2012 09:52
-
-
Save thomas11/2909362 to your computer and use it in GitHub Desktop.
Log memory usage every n seconds in Go #golang
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
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