Show memory stats in debug

This commit is contained in:
世界
2022-08-11 12:41:54 +08:00
parent 7b30815938
commit c9226aeaaf
6 changed files with 60 additions and 1 deletions

View File

@@ -0,0 +1,25 @@
//go:build debug
package main
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
}