-
Notifications
You must be signed in to change notification settings - Fork 1
/
detect_pause.go
34 lines (30 loc) · 751 Bytes
/
detect_pause.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package util
import (
"runtime"
"time"
"fornaxian.tech/log"
)
// DetectPauses runs a continuous loop which detects stalls in the runtime and
// garbage collection cycles
func DetectPauses() {
var (
ticker = time.NewTicker(time.Second)
// GC data
mstat runtime.MemStats
prevPause uint64
)
for range ticker.C {
runtime.ReadMemStats(&mstat)
if mstat.PauseTotalNs != prevPause {
if mstat.PauseTotalNs-prevPause > 100e6 { // 100ms
log.Warn(
"Long GC detected: pause: %.2fms, total time spent collecting garbage: %0.2fms, heap size: %s",
float64(mstat.PauseTotalNs-prevPause)/1e6,
float64(mstat.PauseTotalNs)/1e6,
FormatData(int64(mstat.HeapInuse)),
)
}
prevPause = mstat.PauseTotalNs
}
}
}