Skip to content

Commit

Permalink
Optimize performance output
Browse files Browse the repository at this point in the history
  • Loading branch information
aoliaoaoaojiao committed Jan 11, 2023
1 parent 7aaad2b commit 199e507
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 24 deletions.
16 changes: 8 additions & 8 deletions src/entity/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
}

Expand Down
33 changes: 20 additions & 13 deletions src/perfmonUtil/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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) {
Expand Down
13 changes: 10 additions & 3 deletions src/perfmonUtil/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,21 @@ 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
}
}

if perfOptions.SystemMem {
if stats == nil {
stats = &entity.SystemInfo{}
}
stats.MemInfo = &entity.SystemMemInfo{}
err = getMemInfo(client, stats)
if err != nil {
Expand All @@ -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
Expand Down

0 comments on commit 199e507

Please sign in to comment.