github.com/newrelic/go-agent@v3.26.0+incompatible/internal/sysinfo/usage_posix.go (about) 1 // Copyright 2020 New Relic Corporation. All rights reserved. 2 // SPDX-License-Identifier: Apache-2.0 3 4 // +build !windows 5 6 package sysinfo 7 8 import ( 9 "syscall" 10 "time" 11 ) 12 13 func timevalToDuration(tv syscall.Timeval) time.Duration { 14 return time.Duration(tv.Nano()) * time.Nanosecond 15 } 16 17 // GetUsage gathers process times. 18 func GetUsage() (Usage, error) { 19 ru := syscall.Rusage{} 20 err := syscall.Getrusage(syscall.RUSAGE_SELF, &ru) 21 if err != nil { 22 return Usage{}, err 23 } 24 25 return Usage{ 26 System: timevalToDuration(ru.Stime), 27 User: timevalToDuration(ru.Utime), 28 }, nil 29 }