sing-box/debug_unix.go

26 lines
449 B
Go
Raw Permalink Normal View History

2023-12-27 17:33:07 +08:00
//go:build linux || darwin
2023-04-22 15:58:25 +08:00
package box
2022-08-11 12:41:54 +08:00
import (
"runtime"
"syscall"
)
func rusageMaxRSS() float64 {
ru := syscall.Rusage{}
err := syscall.Getrusage(syscall.RUSAGE_SELF, &ru)
if err != nil {
return 0
}
rss := float64(ru.Maxrss)
if runtime.GOOS == "darwin" || runtime.GOOS == "ios" {
rss /= 1 << 20 // ru_maxrss is bytes on darwin
} else {
// ru_maxrss is kilobytes elsewhere (linux, openbsd, etc)
rss /= 1 << 10
}
return rss
}