shirou_gopsutil/cpu/cpu_windows.go

46 lines
1.1 KiB
Go
Raw Normal View History

2014-04-18 20:28:00 +08:00
// +build windows
2014-04-22 08:44:22 +08:00
package gopsutil
2014-04-18 20:28:00 +08:00
import (
"syscall"
"unsafe"
2014-11-27 21:28:05 +08:00
common "github.com/shirou/gopsutil/common"
2014-04-18 20:28:00 +08:00
)
2014-11-09 05:39:06 +08:00
// TODO: Get percpu
2014-04-30 14:32:05 +08:00
func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
var ret []CPUTimesStat
2014-04-18 20:28:00 +08:00
2014-11-27 21:28:05 +08:00
var lpIdleTime common.FILETIME
var lpKernelTime common.FILETIME
var lpUserTime common.FILETIME
r, _, _ := common.ProcGetSystemTimes.Call(
uintptr(unsafe.Pointer(&lpIdleTime)),
uintptr(unsafe.Pointer(&lpKernelTime)),
uintptr(unsafe.Pointer(&lpUserTime)))
if r == 0 {
return ret, syscall.GetLastError()
}
2014-04-30 14:32:05 +08:00
LOT := float64(0.0000001)
HIT := (LOT * 4294967296.0)
idle := ((HIT * float64(lpIdleTime.DwHighDateTime)) + (LOT * float64(lpIdleTime.DwLowDateTime)))
user := ((HIT * float64(lpUserTime.DwHighDateTime)) + (LOT * float64(lpUserTime.DwLowDateTime)))
kernel := ((HIT * float64(lpKernelTime.DwHighDateTime)) + (LOT * float64(lpKernelTime.DwLowDateTime)))
system := (kernel - idle)
2014-04-30 14:32:05 +08:00
ret = append(ret, CPUTimesStat{
2014-04-24 15:15:57 +08:00
Idle: float32(idle),
User: float32(user),
System: float32(system),
})
2014-04-18 20:28:00 +08:00
return ret, nil
}
2014-05-16 17:42:37 +08:00
func CPUInfo() ([]CPUInfoStat, error) {
var ret []CPUInfoStat
return ret, nil
}