mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-12-06 03:48:31 +00:00
chore: remove depend of gopsutil
This commit is contained in:
1 parent
0c25831726
commit
0992ee8adf
19 files changed
+1424
-33
No files matched your search
@@ -0,0 +1,37 @@
|
||||
package memory
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var pageSize = uint64(os.Getpagesize())
|
||||
|
||||
func GetMemoryInfo(pid int32) (*MemoryInfoStat, error) {
|
||||
proc := os.Getenv("HOST_PROC")
|
||||
if proc == "" {
|
||||
proc = "/proc"
|
||||
}
|
||||
memPath := filepath.Join(proc, strconv.Itoa(int(pid)), "statm")
|
||||
contents, err := os.ReadFile(memPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fields := strings.Split(string(contents), " ")
|
||||
|
||||
vms, err := strconv.ParseUint(fields[0], 10, 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rss, err := strconv.ParseUint(fields[1], 10, 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
memInfo := &MemoryInfoStat{
|
||||
RSS: rss * pageSize,
|
||||
VMS: vms * pageSize,
|
||||
}
|
||||
return memInfo, nil
|
||||
}
|
||||
Reference in new issue
Block a user