Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit f7a2a92

Browse files
fix meminfo parse bug
1 parent f9db905 commit f7a2a92

1 file changed

Lines changed: 35 additions & 5 deletions

File tree

src/perfmonUtil/process.go

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,41 @@ func getMemTotalPSS(client *adb.Device, pid string) (result int, err error) {
7777
return 0, errors.New(string(data))
7878
}
7979
s := strings.Split(string(data), "\n")
80-
for _, v := range s {
81-
if strings.Contains(v, "TOTAL:") {
82-
result, _ = strconv.Atoi(strings.TrimSpace(
83-
v[strings.Index(v, "TOTAL:")+6 : strings.LastIndex(v, "TOTAL")]))
84-
break
80+
81+
isGetMem := false
82+
maxLineLen := 0
83+
for i, v := range s {
84+
v = strings.ReplaceAll(v, "\n", "")
85+
v = strings.ReplaceAll(v, "\r", "")
86+
if strings.Contains(v, "App Summary") {
87+
if i+1 < len(s) {
88+
v = strings.ReplaceAll(s[i+1], "\n", "")
89+
v = strings.ReplaceAll(v, "\r", "")
90+
}
91+
maxLineLen = len(v)
92+
isGetMem = true
93+
continue
94+
}
95+
96+
if isGetMem && strings.Contains(v, ":") {
97+
if strings.Contains(v, "TOTAL") {
98+
continue
99+
}
100+
temp := strings.Split(v, ":")
101+
if len(temp) < 1 {
102+
continue
103+
}
104+
value := strings.Split(strings.TrimLeft(temp[1], " "), " ")[0]
105+
lastIndex := strings.LastIndex(v, value)
106+
// if the maximum length is reached skip directly
107+
if lastIndex+len(value) >= maxLineLen {
108+
continue
109+
}
110+
memValue, err1 := strconv.Atoi(value)
111+
if err1 != nil {
112+
panic(err1)
113+
}
114+
result += memValue
85115
}
86116
}
87117
return

0 commit comments

Comments
 (0)