Merge branch 'master' of github.com:shirou/gopsutil

pull/4/head
Shirou WAKAYAMA 11 years ago
commit 6d7ad643fb

@ -9,3 +9,8 @@ import (
var ( var (
modKernel32 = syscall.NewLazyDLL("kernel32.dll") modKernel32 = syscall.NewLazyDLL("kernel32.dll")
) )
type FILETIME struct {
DwLowDateTime uint32
DwHighDateTime uint32
}

@ -12,11 +12,6 @@ var (
procGetSystemTimes = modkernel32.NewProc("GetSystemTimes") procGetSystemTimes = modkernel32.NewProc("GetSystemTimes")
) )
type FILETIME struct {
DwLowDateTime uint32
DwHighDateTime uint32
}
func Cpu_times() ([]CPU_TimesStat, error) { func Cpu_times() ([]CPU_TimesStat, error) {
ret := make([]CPU_TimesStat, 0) ret := make([]CPU_TimesStat, 0)

@ -20,8 +20,8 @@ var (
FILE_READ_ONLY_VOLUME = int64(524288) // 0x00080000 FILE_READ_ONLY_VOLUME = int64(524288) // 0x00080000
) )
func (d Disk) Disk_usage(path string) (Disk_usage, error) { func Disk_usage(path string) (Disk_usageStat, error) {
ret := Disk_usage{} ret := Disk_usageStat{}
ret.Path = path ret.Path = path
lpFreeBytesAvailable := int64(0) lpFreeBytesAvailable := int64(0)
@ -44,8 +44,8 @@ func (d Disk) Disk_usage(path string) (Disk_usage, error) {
return ret, nil return ret, nil
} }
func (d Disk) Disk_partitions() ([]Disk_partition, error) { func Disk_partitions() ([]Disk_partitionStat, error) {
ret := make([]Disk_partition, 0) ret := make([]Disk_partitionStat, 0)
lpBuffer := make([]byte, 254) lpBuffer := make([]byte, 254)
diskret, _, err := procGetLogicalDriveStringsW.Call( diskret, _, err := procGetLogicalDriveStringsW.Call(
uintptr(len(lpBuffer)), uintptr(len(lpBuffer)),
@ -93,7 +93,7 @@ func (d Disk) Disk_partitions() ([]Disk_partition, error) {
opts += ".compress" opts += ".compress"
} }
d := Disk_partition{ d := Disk_partitionStat{
Mountpoint: path, Mountpoint: path,
Device: path, Device: path,
Fstype: string(bytes.Replace(lpFileSystemNameBuffer, []byte("\x00"), []byte(""), -1)), Fstype: string(bytes.Replace(lpFileSystemNameBuffer, []byte("\x00"), []byte(""), -1)),

@ -6,6 +6,12 @@ import (
"github.com/mitchellh/go-ps" "github.com/mitchellh/go-ps"
"os" "os"
"syscall" "syscall"
"unsafe"
)
var (
procGetSystemTimeAsFileTime = modKernel32.NewProc("GetSystemTimeAsFileTime")
procGetTickCount = modKernel32.NewProc("GetTickCount")
) )
func HostInfo() (HostInfoStat, error) { func HostInfo() (HostInfoStat, error) {
@ -37,3 +43,30 @@ func HostInfo() (HostInfoStat, error) {
return ret, nil return ret, nil
} }
func Boot_time() (int64, error) {
var lpSystemTimeAsFileTime FILETIME
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) {
ret := make([]UserStat, 0)
return ret, nil
}

@ -2,8 +2,8 @@
package gopsutil package gopsutil
func (l Load) LoadAvg() (LoadAvg, error) { func LoadAvg() (LoadAvgStat, error) {
ret := LoadAvg{} ret := LoadAvgStat{}
return ret, nil return ret, nil
} }

@ -23,8 +23,8 @@ type MEMORYSTATUSEX struct {
ullAvailExtendedVirtual uint64 ullAvailExtendedVirtual uint64
} }
func Virtual_memory() (Virtual_memory, error) { func Virtual_memory() (Virtual_memoryStat, error) {
ret := Virtual_memory{} ret := Virtual_memoryStat{}
var memInfo MEMORYSTATUSEX var memInfo MEMORYSTATUSEX
memInfo.cbSize = uint32(unsafe.Sizeof(memInfo)) memInfo.cbSize = uint32(unsafe.Sizeof(memInfo))
@ -40,8 +40,8 @@ func Virtual_memory() (Virtual_memory, error) {
return ret, nil return ret, nil
} }
func Swap_memory() (Swap_memory, error) { func Swap_memory() (Swap_memoryStat, error) {
ret := Swap_memory{} ret := Swap_memoryStat{}
return ret, nil return ret, nil
} }

Loading…
Cancel
Save