go.dedis.ch/onet/v4@v4.0.0-pre1/simul/monitor/rtime.go (about) 1 // +build freebsd linux darwin 2 3 package monitor 4 5 import ( 6 "syscall" 7 8 "go.dedis.ch/onet/v4/log" 9 ) 10 11 // Converts microseconds to seconds. 12 func iiToF(sec int64, usec int64) float64 { 13 return float64(sec) + float64(usec)/1000000.0 14 } 15 16 // Returns the system and the user CPU time used by the current process so far. 17 func getRTime() (tSys, tUsr float64) { 18 rusage := &syscall.Rusage{} 19 if err := syscall.Getrusage(syscall.RUSAGE_SELF, rusage); err != nil { 20 log.Error("Couldn't get rusage time:", err) 21 return -1, -1 22 } 23 s, u := rusage.Stime, rusage.Utime 24 return iiToF(int64(s.Sec), int64(s.Usec)), iiToF(int64(u.Sec), int64(u.Usec)) 25 }