Print runtime stats every minute when --debug flag is set

This commit is contained in:
Dan Sosedoff 2014-11-20 20:00:45 -06:00
parent 8c605dcd96
commit e1684fc8c0
2 changed files with 26 additions and 0 deletions

View File

@ -203,6 +203,10 @@ func main() {
gin.SetMode("release") gin.SetMode("release")
} }
if options.Debug {
go startRuntimeProfiler()
}
startServer() startServer()
openPage() openPage()
handleSignals() handleSignals()

22
utils.go Normal file
View File

@ -0,0 +1,22 @@
package main
import (
"fmt"
"runtime"
"time"
)
func startRuntimeProfiler() {
m := &runtime.MemStats{}
for {
runtime.ReadMemStats(m)
fmt.Println("-----------------------")
fmt.Println("Goroutines:", runtime.NumGoroutine())
fmt.Println("Memory acquired:", m.Sys)
fmt.Println("Memory used:", m.Alloc)
time.Sleep(time.Minute)
}
}