Skip to content

Commit

Permalink
feat: add mem pss total
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhouYixun committed Feb 3, 2023
1 parent 356c0b9 commit 97ebec9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/entity/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
32 changes: 32 additions & 0 deletions src/perfmonUtil/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 97ebec9

Please sign in to comment.