From f4b56b7100dbf7ddd022cb6d36eb0ee2ae7b4b98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=A5=E5=88=A9=E5=97=B7=E5=97=B7=E5=97=B7=E5=8F=AB?= Date: Wed, 8 Feb 2023 11:52:02 +0800 Subject: [PATCH] fix proc stat status parse error --- src/perfmonUtil/process.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/perfmonUtil/process.go b/src/perfmonUtil/process.go index 66a14bf..c4a6d8a 100644 --- a/src/perfmonUtil/process.go +++ b/src/perfmonUtil/process.go @@ -109,6 +109,9 @@ func getStatusOnPid(client *adb.Device, pid string) (status *entity.ProcessStatu for scanner.Scan() { line := scanner.Text() fields := strings.Fields(line) + if len(fields) < 2 { + continue + } var fieldName = strings.TrimRight(fields[0], ":") var value = strings.Join(fields[1:], " ") switch fieldName { @@ -256,7 +259,7 @@ func newProcessStat(statStr string) (*entity.ProcessStat, error) { if err1 != nil { return nil, err1 } - processStat.Cmajflt = num + processStat.Majflt = num case 13: num, err1 := strconv.Atoi(value) if err1 != nil { @@ -280,43 +283,43 @@ func newProcessStat(statStr string) (*entity.ProcessStat, error) { if err1 != nil { return nil, err1 } - processStat.Priority = num + processStat.Cstime = num case 17: num, err1 := strconv.Atoi(value) if err1 != nil { return nil, err1 } - processStat.Nice = num + processStat.Priority = num case 18: num, err1 := strconv.Atoi(value) if err1 != nil { return nil, err1 } - processStat.Num_threads = num + processStat.Nice = num case 19: num, err1 := strconv.Atoi(value) if err1 != nil { return nil, err1 } - processStat.Itrealvalue = num + processStat.Num_threads = num case 20: num, err1 := strconv.Atoi(value) if err1 != nil { return nil, err1 } - processStat.Starttime = num + processStat.Itrealvalue = num case 21: num, err1 := strconv.Atoi(value) if err1 != nil { return nil, err1 } - processStat.Vsize = num + processStat.Starttime = num case 22: num, err1 := strconv.Atoi(value) if err1 != nil { return nil, err1 } - processStat.Rss = num + processStat.Vsize = num case 23: num, err1 := strconv.Atoi(value) if err1 != nil {