func StupidGetMemory(proc *process.Process) (ms *MemoryStat, err error) { ms = &MemoryStat{} memStat, err := proc.MemoryInfoEx() if err != nil { return nil, err } ms.VSS = memStat.VMS ms.RSS = memStat.RSS // PSS from dumpsys appname, _ := proc.Cmdline() cmd := exec.Command("/system/bin/dumpsys", "meminfo", appname) if data, er := cmd.CombinedOutput(); er == nil { res1 := ptn1.FindStringSubmatch(string(data)) if len(res1) != 0 { fmt.Sscanf(res1[1], "%d", &ms.PSS) } else { res2 := ptn2.FindStringSubmatch(string(data)) if len(res2) == 0 { return ms, nil } fmt.Sscanf(res2[1], "%d", &ms.PSS) } ms.PSS <<= 10 } return ms, nil }
func isMatch(proc *process.Process, search string) bool { cmdline, _ := proc.Cmdline() if fmt.Sprintf("pid:%d", proc.Pid) == search { return true } if "cmdline:"+cmdline == search { return true } exe, _ := proc.Exe() if "exe:"+exe == search { return true } name, _ := proc.Name() if "name:"+name == search { return true } return false }