mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-02-27 01:07:10 +00:00
chore: remove depend of gopsutil
This commit is contained in:
37
component/memory/memory_linux.go
Normal file
37
component/memory/memory_linux.go
Normal file
@@ -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