-
Notifications
You must be signed in to change notification settings - Fork 381
/
sysutil_unix.go
37 lines (28 loc) · 1.07 KB
/
sysutil_unix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//go:build linux || darwin
// +build linux darwin
package sysutil
import (
"syscall"
"go.uber.org/multierr"
"berty.tech/berty/v2/go/pkg/protocoltypes"
)
func appendCustomSystemInfo(reply *protocoltypes.SystemInfo_Process) error {
var errs error
// rlimit
rlimitNofile := syscall.Rlimit{}
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlimitNofile)
errs = multierr.Append(errs, err)
reply.RlimitCur = rlimitNofile.Cur
reply.RlimitMax = rlimitNofile.Max
// rusage
rusage := syscall.Rusage{}
err = syscall.Getrusage(syscall.RUSAGE_SELF, &rusage)
errs = multierr.Append(errs, err)
reply.UserCPUTimeMS = int64(rusage.Utime.Sec*1000) + int64(rusage.Utime.Usec/1000) // nolint:unconvert // on some archs, those vars may be int32 instead of int64
reply.SystemCPUTimeMS = int64(rusage.Stime.Sec*1000) + int64(rusage.Stime.Usec/1000) // nolint:unconvert // on some archs, those vars may be int32 instead of int64
// process priority
prio, err := syscall.Getpriority(syscall.PRIO_PROCESS, 0)
errs = multierr.Append(errs, err)
reply.Priority = int64(prio)
return errs
}