Skip to content

Commit

Permalink
Change to adapt current cpu.Times API for per cpu and core time stats
Browse files Browse the repository at this point in the history
  • Loading branch information
RajGupta-Continuum committed Jun 5, 2017
1 parent ea683cd commit 2d2db42
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion cpu/cpu_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ type Win32_PerfFormattedData_PerfOS_System struct {

// TODO: Get percpu
func Times(percpu bool) ([]TimesStat, error) {
var ret []TimesStat
if percpu {
return perCPUTimes()
}

var ret []TimesStat
var lpIdleTime common.FILETIME
var lpKernelTime common.FILETIME
var lpUserTime common.FILETIME
Expand Down Expand Up @@ -122,3 +125,22 @@ func ProcInfo() ([]Win32_PerfFormattedData_PerfOS_System, error) {
err := wmi.Query(q, &ret)
return ret, err
}

func perCPUTimes() ([]TimesStat, error) {
var ret []TimesStat
stats, err := PerfInfo()
if err != nil {
return nil, err
}
for _, v := range stats {
c := TimesStat{
CPU: v.Name,
User: float64(v.PercentUserTime),
System: float64(v.PercentPrivilegedTime),
Idle: float64(v.PercentIdleTime),
Irq: float64(v.PercentInterruptTime),
}
ret = append(ret, c)
}
return ret, nil
}

0 comments on commit 2d2db42

Please sign in to comment.