-
-
Save duhruh/6e61bf0f36f43a4c93c886d7ad5f7a1c to your computer and use it in GitHub Desktop.
Log memory usage every n seconds in Go #golang
This file contains hidden or 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