Skip to content

Commit

Permalink
add system cpu usage
Browse files Browse the repository at this point in the history
  • Loading branch information
aoliaoaoaojiao committed Jan 12, 2023
1 parent 2a753f3 commit 1e1e85c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/entity/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type SystemCPUInfo struct {
SoftIrq float32 `json:"softIrq"`
Steal float32 `json:"steal"`
Guest float32 `json:"guest"`
Usage float32 `json:"cpuUsage"`
}

type SystemMemInfo struct {
Expand Down
4 changes: 4 additions & 0 deletions src/perfmonUtil/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ func getCPU(client *adb.Device, stats *entity.SystemInfo) (err error) {
cpu.Irq = float32(nowCPU.Irq-preCPU.Irq) / total * 100
cpu.SoftIrq = float32(nowCPU.SoftIrq-preCPU.SoftIrq) / total * 100
cpu.Guest = float32(nowCPU.Guest-preCPU.Guest) / total * 100
var cpuNowTime = float32(nowCPU.User + nowCPU.Nice + nowCPU.System + nowCPU.Iowait + nowCPU.Irq + nowCPU.SoftIrq)
var cpuPreTime = float32(preCPU.User + preCPU.Nice + preCPU.System + preCPU.Iowait + preCPU.Irq + preCPU.SoftIrq)

cpu.Usage = (cpuNowTime - cpuPreTime) / ((cpuNowTime + float32(nowCPU.Idle)) - (cpuPreTime + float32(preCPU.Idle)))
stats.CPU[fields[0]] = cpu
}
}
Expand Down

0 comments on commit 1e1e85c

Please sign in to comment.