Files
3x-ui-agent/internal/util/sys/procmem.go
T
Sanaei f727d04f65
Release 3X-UI for Docker / build (push) Canceled after 0s
Release 3X-UI / build (386) (push) Canceled after 0s
Release 3X-UI / build (amd64) (push) Canceled after 0s
Release 3X-UI / build (arm64) (push) Canceled after 0s
Release 3X-UI / build (armv5) (push) Canceled after 0s
Release 3X-UI / build (armv6) (push) Canceled after 0s
Release 3X-UI / build (armv7) (push) Canceled after 0s
Release 3X-UI / build (s390x) (push) Canceled after 0s
Release 3X-UI / Build for Windows (amd64) (push) Canceled after 0s
Release 3X-UI / Publish rolling dev release (push) Canceled after 0s
v3.7.0
2026-08-24 15:07:15 +02:00

35 lines
795 B
Go

package sys
import (
"os"
"sync"
"github.com/shirou/gopsutil/v4/process"
)
var (
selfProc *process.Process
selfProcOnce sync.Once
)
// SelfRSS returns the resident set size of the current process in bytes — the
// real physical memory the OS attributes to the panel. Unlike
// runtime.MemStats.Sys (a never-shrinking high-water mark of reserved address
// space that also counts memory already returned to the OS), RSS reflects current
// usage and drops as memory is released. Returns 0 when unavailable.
func SelfRSS() uint64 {
selfProcOnce.Do(func() {
if p, err := process.NewProcess(int32(os.Getpid())); err == nil {
selfProc = p
}
})
if selfProc == nil {
return 0
}
if mi, err := selfProc.MemoryInfo(); err == nil && mi != nil {
return mi.RSS
}
return 0
}