Refactor memory profiler, change output format
This commit is contained in:
parent
22bcfafa76
commit
4baa5ec3c6
2
main.go
2
main.go
@ -204,7 +204,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if options.Debug {
|
if options.Debug {
|
||||||
go startRuntimeProfiler()
|
startRuntimeProfiler()
|
||||||
}
|
}
|
||||||
|
|
||||||
startServer()
|
startServer()
|
||||||
|
26
utils.go
26
utils.go
@ -1,7 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"log"
|
||||||
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -9,16 +10,21 @@ import (
|
|||||||
const MEGABYTE = 1024 * 1024
|
const MEGABYTE = 1024 * 1024
|
||||||
|
|
||||||
func startRuntimeProfiler() {
|
func startRuntimeProfiler() {
|
||||||
m := &runtime.MemStats{}
|
go func() {
|
||||||
|
logger := log.New(os.Stdout, "", 0)
|
||||||
|
m := &runtime.MemStats{}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
runtime.ReadMemStats(m)
|
runtime.ReadMemStats(m)
|
||||||
|
|
||||||
fmt.Println("-----------------------")
|
logger.Printf(
|
||||||
fmt.Println("Goroutines:", runtime.NumGoroutine())
|
"[DEBUG] Goroutines: %v, Mem used: %v (%v mb), Mem acquired: %v (%v mb)\n",
|
||||||
fmt.Println("Memory acquired:", m.Sys, "bytes,", m.Sys/MEGABYTE, "mb")
|
runtime.NumGoroutine(),
|
||||||
fmt.Println("Memory used:", m.Alloc, "bytes,", m.Alloc/MEGABYTE, "mb")
|
m.Alloc, m.Alloc/MEGABYTE,
|
||||||
|
m.Sys, m.Sys/MEGABYTE,
|
||||||
|
)
|
||||||
|
|
||||||
time.Sleep(time.Second * 30)
|
time.Sleep(time.Second * 30)
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user