github.com/lulzWill/go-agent@v2.1.2+incompatible/internal/sysinfo/usage_posix.go (about) 1 // +build !windows 2 3 package sysinfo 4 5 import ( 6 "syscall" 7 "time" 8 ) 9 10 func timevalToDuration(tv syscall.Timeval) time.Duration { 11 return time.Duration(tv.Nano()) * time.Nanosecond 12 } 13 14 // GetUsage gathers process times. 15 func GetUsage() (Usage, error) { 16 ru := syscall.Rusage{} 17 err := syscall.Getrusage(syscall.RUSAGE_SELF, &ru) 18 if err != nil { 19 return Usage{}, err 20 } 21 22 return Usage{ 23 System: timevalToDuration(ru.Stime), 24 User: timevalToDuration(ru.Utime), 25 }, nil 26 }