2022-09-13 03:06:27 +03:00
|
|
|
//go:build linux || darwin
|
2016-08-27 00:18:35 +03:00
|
|
|
|
2018-10-29 01:49:45 +03:00
|
|
|
package server
|
2016-08-27 00:18:35 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
2019-10-30 20:17:59 +03:00
|
|
|
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),
|
|
|
|
)
|
|
|
|
}
|