fixed loops for mem profiling

This commit is contained in:
Philipp Mieden 2019-05-21 17:29:16 +02:00
parent 1449d6902c
commit eca5e3b4f0

View File

@ -74,9 +74,12 @@ func main() {
if *flagFreeOSMem > 0 {
log.Notice("[INFO] freeing OS memory every ", *flagFreeOSMem, " minutes!")
go func() {
for _ = range time.After(time.Duration(*flagFreeOSMem) * time.Minute) {
log.Notice("FreeOSMemory")
debug.FreeOSMemory()
for {
select {
case <-time.After(time.Duration(*flagFreeOSMem) * time.Second):
log.Notice("FreeOSMemory")
debug.FreeOSMemory()
}
}
}()
}
@ -84,16 +87,19 @@ func main() {
if *flagHeapDump > 0 {
log.Notice("[INFO] dumping heap every ", *flagHeapDump, " minutes!")
go func() {
for _ = range time.After(time.Duration(*flagFreeOSMem) * time.Minute) {
log.Notice("HeapDump")
f, err := os.Create("heapdump")
if err != nil {
panic("failed to create heap dump file")
}
debug.WriteHeapDump(f.Fd())
err = f.Close()
if err != nil {
panic("failed to create heap dump file")
for {
select {
case <-time.After(time.Duration(*flagFreeOSMem) * time.Minute):
log.Notice("HeapDump")
f, err := os.Create("heapdump")
if err != nil {
panic("failed to create heap dump file")
}
debug.WriteHeapDump(f.Fd())
err = f.Close()
if err != nil {
panic("failed to create heap dump file")
}
}
}
}()