From 64a4956c42cb71ef14c58c2f0a88dac34ea80053 Mon Sep 17 00:00:00 2001 From: Yang Luo Date: Mon, 9 Jun 2025 20:08:55 +0800 Subject: [PATCH] feat: improve getMemoryUsage() --- util/system.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/util/system.go b/util/system.go index d646bda2..4dc1ed6f 100644 --- a/util/system.go +++ b/util/system.go @@ -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) {