diff --git a/src/entity/process.go b/src/entity/process.go index 0e248ff..63f3314 100644 --- a/src/entity/process.go +++ b/src/entity/process.go @@ -106,13 +106,13 @@ type ProcessStatus struct { } type ProcessInfo struct { - Name string `json:"name"` - Pid string `json:"pid"` - CpuUtilization *float64 `json:"cpuUtilization"` - PhyRSS *int `json:"phyRSS"` - VmSize *int `json:"vmRSS"` - Threads *int `json:"threadCount"` - FPS *int `json:"fps"` + Name string `json:"name"` + Pid string `json:"pid"` + CpuUtilization *float64 `json:"cpuUtilization,omitempty"` + PhyRSS *int `json:"phyRSS,omitempty"` + VmSize *int `json:"vmRSS,omitempty"` + Threads *int `json:"threadCount,omitempty"` + FPS *int `json:"fps,omitempty"` } func (i *ProcessInfo) ToJson() string { @@ -125,7 +125,7 @@ func (i *ProcessInfo) ToFormat() string { return string(str) } -func (i *ProcessInfo) ToString() string{ +func (i *ProcessInfo) ToString() string { return i.ToJson() } diff --git a/src/perfmonUtil/process.go b/src/perfmonUtil/process.go index 3b2eae9..bdc88fb 100644 --- a/src/perfmonUtil/process.go +++ b/src/perfmonUtil/process.go @@ -332,24 +332,23 @@ var sleepTime = 1.0 // # seconds var HZ = 100.0 //# ticks/second var cpuUtilization = 0.0 -func GetProcessInfo(client *adb.Device, pid string, packageName string,perfOptions entity.PerfOption, interval int64) (*entity.ProcessInfo, error) { +func GetProcessInfo(client *adb.Device, pid string, packageName string, perfOptions entity.PerfOption, interval int64) (processInfo *entity.ProcessInfo, err error) { sleepTime = float64(interval) - - stat, err := getStatOnPid(client, pid) + var stat *entity.ProcessStat + stat, err = getStatOnPid(client, pid) if err != nil { return nil, err } - status, err := getStatusOnPid(client, pid) + var status *entity.ProcessStatus + status, err = getStatusOnPid(client, pid) if err != nil { return nil, err } - //ioData, err := getIoDataOnPid(client, pid) - //if err != nil { - // return nil, err - //} - var processInfo entity.ProcessInfo - if perfOptions.ProcThreads{ + if perfOptions.ProcThreads { + if processInfo == nil { + processInfo = &entity.ProcessInfo{} + } var threads int if threads, err = strconv.Atoi(status.Threads); err != nil { return nil, err @@ -358,17 +357,25 @@ func GetProcessInfo(client *adb.Device, pid string, packageName string,perfOptio } if perfOptions.ProcMem { + if processInfo == nil { + processInfo = &entity.ProcessInfo{} + } processInfo.PhyRSS = &stat.Rss processInfo.VmSize = &stat.Vsize } if perfOptions.ProcCPU { + if processInfo == nil { + processInfo = &entity.ProcessInfo{} + } getCpuUsage(client, pid) processInfo.CpuUtilization = &cpuUtilization } - - if perfOptions.ProcFPS{ + if perfOptions.ProcFPS { + if processInfo == nil { + processInfo = &entity.ProcessInfo{} + } var fps = 0 fps, err = getProcessFPSBySurfaceFlinger(client, packageName) @@ -382,7 +389,7 @@ func GetProcessInfo(client *adb.Device, pid string, packageName string,perfOptio processInfo.Name = status.Name processInfo.Pid = status.Pid - return &processInfo, nil + return } func getProcessFPSByGFXInfo(client *adb.Device, pid string) (result int, err error) { diff --git a/src/perfmonUtil/system.go b/src/perfmonUtil/system.go index 8fdd13c..0379f84 100644 --- a/src/perfmonUtil/system.go +++ b/src/perfmonUtil/system.go @@ -26,10 +26,11 @@ import ( "strings" ) -func GetSystemStats(client *adb.Device, perfOptions entity.PerfOption) (*entity.SystemInfo, error) { - stats := &entity.SystemInfo{} - var err error +func GetSystemStats(client *adb.Device, perfOptions entity.PerfOption) (stats *entity.SystemInfo, err error) { if perfOptions.SystemCPU { + if stats == nil { + stats = &entity.SystemInfo{} + } err = getCPU(client, stats) if err != nil { return nil, err @@ -37,6 +38,9 @@ func GetSystemStats(client *adb.Device, perfOptions entity.PerfOption) (*entity. } if perfOptions.SystemMem { + if stats == nil { + stats = &entity.SystemInfo{} + } stats.MemInfo = &entity.SystemMemInfo{} err = getMemInfo(client, stats) if err != nil { @@ -45,6 +49,9 @@ func GetSystemStats(client *adb.Device, perfOptions entity.PerfOption) (*entity. } if perfOptions.SystemNetWorking { + if stats == nil { + stats = &entity.SystemInfo{} + } err = getInterfaces(client, stats) if err != nil { return nil, err