mirror of https://github.com/shirou/gopsutil
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
11 years ago
|
// +build windows
|
||
|
|
||
11 years ago
|
package gopsutil
|
||
11 years ago
|
|
||
|
import (
|
||
11 years ago
|
"syscall"
|
||
|
"unsafe"
|
||
11 years ago
|
)
|
||
|
|
||
10 years ago
|
// TODO: Get percpu
|
||
11 years ago
|
func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
|
||
|
var ret []CPUTimesStat
|
||
11 years ago
|
|
||
11 years ago
|
var lpIdleTime FILETIME
|
||
|
var lpKernelTime FILETIME
|
||
|
var lpUserTime FILETIME
|
||
|
r, _, _ := procGetSystemTimes.Call(
|
||
|
uintptr(unsafe.Pointer(&lpIdleTime)),
|
||
|
uintptr(unsafe.Pointer(&lpKernelTime)),
|
||
|
uintptr(unsafe.Pointer(&lpUserTime)))
|
||
|
if r == 0 {
|
||
|
return ret, syscall.GetLastError()
|
||
|
}
|
||
|
|
||
11 years ago
|
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)))
|
||
11 years ago
|
system := (kernel - idle)
|
||
|
|
||
11 years ago
|
ret = append(ret, CPUTimesStat{
|
||
11 years ago
|
Idle: float32(idle),
|
||
|
User: float32(user),
|
||
|
System: float32(system),
|
||
11 years ago
|
})
|
||
11 years ago
|
return ret, nil
|
||
|
}
|
||
11 years ago
|
|
||
|
func CPUInfo() ([]CPUInfoStat, error) {
|
||
|
var ret []CPUInfoStat
|
||
|
return ret, nil
|
||
|
}
|