implement Boot_time on windows. But something is wrong. the returned value is not correct.
This commit is contained in:
parent
3d702e621d
commit
a3da73489b
|
@ -9,3 +9,8 @@ import (
|
|||
var (
|
||||
modKernel32 = syscall.NewLazyDLL("kernel32.dll")
|
||||
)
|
||||
|
||||
type FILETIME struct {
|
||||
DwLowDateTime uint32
|
||||
DwHighDateTime uint32
|
||||
}
|
||||
|
|
|
@ -12,11 +12,6 @@ var (
|
|||
procGetSystemTimes = modkernel32.NewProc("GetSystemTimes")
|
||||
)
|
||||
|
||||
type FILETIME struct {
|
||||
DwLowDateTime uint32
|
||||
DwHighDateTime uint32
|
||||
}
|
||||
|
||||
func Cpu_times() ([]CPU_TimesStat, error) {
|
||||
ret := make([]CPU_TimesStat, 0)
|
||||
|
||||
|
|
|
@ -6,6 +6,12 @@ import (
|
|||
"github.com/mitchellh/go-ps"
|
||||
"os"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var (
|
||||
procGetSystemTimeAsFileTime = modKernel32.NewProc("GetSystemTimeAsFileTime")
|
||||
procGetTickCount = modKernel32.NewProc("GetTickCount")
|
||||
)
|
||||
|
||||
func HostInfo() (HostInfoStat, error) {
|
||||
|
@ -39,8 +45,24 @@ func HostInfo() (HostInfoStat, error) {
|
|||
}
|
||||
|
||||
func Boot_time() (int64, error) {
|
||||
var lpSystemTimeAsFileTime FILETIME
|
||||
|
||||
return 0, nil
|
||||
r, _, _ := procGetSystemTimeAsFileTime.Call(uintptr(unsafe.Pointer(&lpSystemTimeAsFileTime)))
|
||||
if r == 0 {
|
||||
return 0, syscall.GetLastError()
|
||||
}
|
||||
|
||||
// TODO: This calc is wrong.
|
||||
ll := (uint32(lpSystemTimeAsFileTime.DwHighDateTime))<<32 + lpSystemTimeAsFileTime.DwLowDateTime
|
||||
pt := (uint64(ll) - 116444736000000000) / 10000000
|
||||
|
||||
u, _, _ := procGetTickCount.Call()
|
||||
if u == 0 {
|
||||
return 0, syscall.GetLastError()
|
||||
}
|
||||
uptime := uint64(u) / 1000
|
||||
|
||||
return int64(pt - uptime), nil
|
||||
}
|
||||
func Users() ([]UserStat, error) {
|
||||
|
||||
|
|
Loading…
Reference in New Issue