feat: improve getMemoryUsage()

This commit is contained in:
Yang Luo
2025-06-09 20:08:55 +08:00
parent 855bdf47e8
commit 64a4956c42

View File

@ -30,6 +30,7 @@ import (
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/mem"
"github.com/shirou/gopsutil/process"
)
type SystemInfo struct {
@ -60,7 +61,17 @@ func getMemoryUsage() (uint64, uint64, error) {
var m runtime.MemStats
runtime.ReadMemStats(&m)
return m.Sys, virtualMem.Total, nil
proc, err := process.NewProcess(int32(os.Getpid()))
if err != nil {
return 0, 0, err
}
memInfo, err := proc.MemoryInfo()
if err != nil {
return 0, 0, err
}
return memInfo.RSS, virtualMem.Total, nil
}
func GetSystemInfo() (*SystemInfo, error) {