github.com/sagernet/sing-box@v1.9.0-rc.20/debug_unix.go (about)

     1  //go:build linux || darwin
     2  
     3  package box
     4  
     5  import (
     6  	"runtime"
     7  	"syscall"
     8  )
     9  
    10  func rusageMaxRSS() float64 {
    11  	ru := syscall.Rusage{}
    12  	err := syscall.Getrusage(syscall.RUSAGE_SELF, &ru)
    13  	if err != nil {
    14  		return 0
    15  	}
    16  
    17  	rss := float64(ru.Maxrss)
    18  	if runtime.GOOS == "darwin" || runtime.GOOS == "ios" {
    19  		rss /= 1 << 20 // ru_maxrss is bytes on darwin
    20  	} else {
    21  		// ru_maxrss is kilobytes elsewhere (linux, openbsd, etc)
    22  		rss /= 1 << 10
    23  	}
    24  	return rss
    25  }