2014-11-21 05:00:45 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2014-11-23 23:44:42 +03:00
|
|
|
"log"
|
|
|
|
"os"
|
2014-11-21 05:00:45 +03:00
|
|
|
"runtime"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2014-11-21 06:00:53 +03:00
|
|
|
const MEGABYTE = 1024 * 1024
|
|
|
|
|
2014-11-21 05:00:45 +03:00
|
|
|
func startRuntimeProfiler() {
|
2014-11-23 23:44:42 +03:00
|
|
|
go func() {
|
|
|
|
logger := log.New(os.Stdout, "", 0)
|
|
|
|
m := &runtime.MemStats{}
|
2014-11-21 05:00:45 +03:00
|
|
|
|
2014-11-23 23:44:42 +03:00
|
|
|
for {
|
|
|
|
runtime.ReadMemStats(m)
|
2014-11-21 05:00:45 +03:00
|
|
|
|
2014-11-23 23:44:42 +03:00
|
|
|
logger.Printf(
|
|
|
|
"[DEBUG] Goroutines: %v, Mem used: %v (%v mb), Mem acquired: %v (%v mb)\n",
|
|
|
|
runtime.NumGoroutine(),
|
|
|
|
m.Alloc, m.Alloc/MEGABYTE,
|
|
|
|
m.Sys, m.Sys/MEGABYTE,
|
|
|
|
)
|
2014-11-21 05:00:45 +03:00
|
|
|
|
2014-11-23 23:44:42 +03:00
|
|
|
time.Sleep(time.Second * 30)
|
|
|
|
}
|
|
|
|
}()
|
2014-11-21 05:00:45 +03:00
|
|
|
}
|