|
|
|
@ -23,21 +23,6 @@ type Win32_Processor struct {
|
|
|
|
|
MaxClockSpeed uint32
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// win32_PerfFormattedData_Counters_ProcessorInformation stores instance value of the perf counters
|
|
|
|
|
type win32_PerfFormattedData_Counters_ProcessorInformation struct {
|
|
|
|
|
Name string
|
|
|
|
|
PercentDPCTime uint64
|
|
|
|
|
PercentIdleTime uint64
|
|
|
|
|
PercentUserTime uint64
|
|
|
|
|
PercentProcessorTime uint64
|
|
|
|
|
PercentInterruptTime uint64
|
|
|
|
|
PercentPriorityTime uint64
|
|
|
|
|
PercentPrivilegedTime uint64
|
|
|
|
|
InterruptsPerSec uint32
|
|
|
|
|
ProcessorFrequency uint32
|
|
|
|
|
DPCRate uint32
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type win32_PerfRawData_Counters_ProcessorInformation struct {
|
|
|
|
|
Name string
|
|
|
|
|
PercentDPCTime uint64
|
|
|
|
@ -58,6 +43,10 @@ type Win32_PerfFormattedData_PerfOS_System struct {
|
|
|
|
|
ProcessorQueueLength uint32
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
win32_TicksPerSecond = 10000000.0
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Times returns times stat per cpu and combined for all CPUs
|
|
|
|
|
func Times(percpu bool) ([]TimesStat, error) {
|
|
|
|
|
return TimesWithContext(context.Background(), percpu)
|
|
|
|
@ -135,7 +124,6 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
|
|
|
|
|
// Name property is the key by which overall, per cpu and per core metric is known.
|
|
|
|
|
func perfInfoWithContext(ctx context.Context) ([]win32_PerfRawData_Counters_ProcessorInformation, error) {
|
|
|
|
|
var ret []win32_PerfRawData_Counters_ProcessorInformation
|
|
|
|
|
// Win32_PerfRawData_Counters_ProcessorInformation
|
|
|
|
|
|
|
|
|
|
q := wmi.CreateQuery(&ret, "WHERE NOT Name LIKE '%_Total'")
|
|
|
|
|
err := common.WMIQueryWithContext(ctx, q, &ret)
|
|
|
|
@ -172,10 +160,10 @@ func perCPUTimesWithContext(ctx context.Context) ([]TimesStat, error) {
|
|
|
|
|
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),
|
|
|
|
|
User: float64(v.PercentUserTime) / win32_TicksPerSecond,
|
|
|
|
|
System: float64(v.PercentPrivilegedTime) / win32_TicksPerSecond,
|
|
|
|
|
Idle: float64(v.PercentIdleTime) / win32_TicksPerSecond,
|
|
|
|
|
Irq: float64(v.PercentInterruptTime) / win32_TicksPerSecond,
|
|
|
|
|
}
|
|
|
|
|
ret = append(ret, c)
|
|
|
|
|
}
|
|
|
|
|