github.com/inazumav/sing-box@v0.0.0-20230926072359-ab51429a14f1/debug_linux.go (about)

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