1
0
mirror of https://github.com/google/gops.git synced 2025-02-19 19:59:55 +02:00

fix gcstats output

This commit is contained in:
Jaana Burcu Dogan 2016-11-03 21:30:12 -07:00
parent 852c757979
commit 3a0975c5cf

View File

@ -12,6 +12,8 @@ import (
"net"
"os"
"runtime"
"runtime/debug"
"time"
)
const (
@ -20,6 +22,9 @@ const (
// GC runs the garbage collector.
GC = byte(0x2)
// GCStats prints GC stats.
GCStats = byte(0x3)
)
func init() {
@ -61,6 +66,14 @@ func handle(conn net.Conn, msg []byte) error {
runtime.GC()
_, err := conn.Write([]byte("ok"))
return err
case GCStats:
var stats debug.GCStats
debug.ReadGCStats(&stats)
fmt.Fprintf(conn, "Num GC: %v\n", stats.NumGC)
if stats.NumGC > 0 {
fmt.Fprintf(conn, "Last GC: %v ago\n", time.Now().Sub(stats.LastGC))
fmt.Fprintf(conn, "Total pause: %v\n", stats.PauseTotal)
}
}
return nil
}