tile38/internal/server/stats_cpu_darlin.go

27 lines
674 B
Go
Raw Normal View History

2016-08-27 00:18:35 +03:00
// +build linux darwin
package server
2016-08-27 00:18:35 +03:00
import (
"bytes"
"fmt"
"syscall"
)
func (s *Server) writeInfoCPU(w *bytes.Buffer) {
2016-08-27 00:18:35 +03:00
var selfRu syscall.Rusage
var cRu syscall.Rusage
syscall.Getrusage(syscall.RUSAGE_SELF, &selfRu)
syscall.Getrusage(syscall.RUSAGE_CHILDREN, &cRu)
fmt.Fprintf(w,
"used_cpu_sys:%.2f\r\n"+
"used_cpu_user:%.2f\r\n"+
"used_cpu_sys_children:%.2f\r\n"+
"used_cpu_user_children:%.2f\r\n",
float64(selfRu.Stime.Sec)+float64(selfRu.Stime.Usec/1000000),
float64(selfRu.Utime.Sec)+float64(selfRu.Utime.Usec/1000000),
float64(cRu.Stime.Sec)+float64(cRu.Stime.Usec/1000000),
float64(cRu.Utime.Sec)+float64(cRu.Utime.Usec/1000000),
)
}