From 97ebec99081f664261fc7faad5224080f9155a96 Mon Sep 17 00:00:00 2001 From: Eason <291028775@qq.com> Date: Fri, 3 Feb 2023 23:42:48 +0800 Subject: [PATCH] feat: add mem pss total --- src/entity/process.go | 1 + src/perfmonUtil/process.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/entity/process.go b/src/entity/process.go index 5b94f4b..f701493 100644 --- a/src/entity/process.go +++ b/src/entity/process.go @@ -109,6 +109,7 @@ type ProcessInfo struct { Name string `json:"name"` Pid string `json:"pid"` CpuUtilization *float64 `json:"cpuUtilization,omitempty"` + TotalPSS *int `json:"totalPSS,omitempty"` PhyRSS *int `json:"phyRSS,omitempty"` VmSize *int `json:"vmRSS,omitempty"` Threads *int `json:"threadCount,omitempty"` diff --git a/src/perfmonUtil/process.go b/src/perfmonUtil/process.go index 48cc5bd..e5e5914 100644 --- a/src/perfmonUtil/process.go +++ b/src/perfmonUtil/process.go @@ -66,6 +66,36 @@ func GetPidOnPackageName(client *adb.Device, appName string) (pid string, err er return regResultSplit[len(regResultSplit)-1][4:], nil } +func getMemTotalPSS(client *adb.Device, packageName string) (result int, err error) { + lines, err := client.OpenShell(fmt.Sprintf("dumpsys meminfo %s", packageName)) + if err != nil { + return + } + scanner := bufio.NewScanner(lines) + for scanner.Scan() { + line := scanner.Text() + if strings.Contains(line, "TOTAL") { + s := strings.Split(line, " ") + flag := false + for _, v := range s { + if len(v) == 0 { + continue + } + if v == "TOTAL" { + flag = true + continue + } + if flag { + result, _ = strconv.Atoi(v) + break + } + } + break + } + } + return +} + func getStatusOnPid(client *adb.Device, pid string) (status *entity.ProcessStatus, err error) { lines, err1 := client.OpenShell(fmt.Sprintf("cat /proc/%s/status", pid)) if err1 != nil { @@ -362,6 +392,8 @@ func GetProcessInfo(client *adb.Device, pid string, packageName string, perfOpti } processInfo.PhyRSS = &stat.Rss processInfo.VmSize = &stat.Vsize + pss, _ := getMemTotalPSS(client, packageName) + processInfo.TotalPSS = &pss } if perfOptions.ProcCPU {