From 9f2c985a28a0544f5bcba34b75e86451e48373c8 Mon Sep 17 00:00:00 2001 From: WAKAYAMA Shirou Date: Thu, 27 Nov 2014 22:28:05 +0900 Subject: [PATCH] fix windows build. --- common/common_windows.go | 8 ++++---- cpu/cpu_windows.go | 10 ++++++---- disk/disk_windows.go | 8 ++++---- host/host_windows.go | 11 +++++++---- mem/mem_windows.go | 4 +++- net/net_windows.go | 2 +- process/process_windows.go | 8 +++++--- 7 files changed, 30 insertions(+), 21 deletions(-) diff --git a/common/common_windows.go b/common/common_windows.go index af6b2e8e..534f4aa4 100644 --- a/common/common_windows.go +++ b/common/common_windows.go @@ -8,11 +8,11 @@ import ( ) var ( - modkernel32 = syscall.NewLazyDLL("kernel32.dll") - modNt = syscall.NewLazyDLL("ntdll.dll") + Modkernel32 = syscall.NewLazyDLL("kernel32.dll") + ModNt = syscall.NewLazyDLL("ntdll.dll") - procGetSystemTimes = modkernel32.NewProc("GetSystemTimes") - procNtQuerySystemInformation = modNt.NewProc("NtQuerySystemInformation") + ProcGetSystemTimes = Modkernel32.NewProc("GetSystemTimes") + ProcNtQuerySystemInformation = ModNt.NewProc("NtQuerySystemInformation") ) type FILETIME struct { diff --git a/cpu/cpu_windows.go b/cpu/cpu_windows.go index 1dd8cf6c..fde4635f 100644 --- a/cpu/cpu_windows.go +++ b/cpu/cpu_windows.go @@ -5,16 +5,18 @@ package gopsutil import ( "syscall" "unsafe" + + common "github.com/shirou/gopsutil/common" ) // TODO: Get percpu func CPUTimes(percpu bool) ([]CPUTimesStat, error) { var ret []CPUTimesStat - var lpIdleTime FILETIME - var lpKernelTime FILETIME - var lpUserTime FILETIME - r, _, _ := procGetSystemTimes.Call( + 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))) diff --git a/disk/disk_windows.go b/disk/disk_windows.go index cf8b2e21..39fb0490 100644 --- a/disk/disk_windows.go +++ b/disk/disk_windows.go @@ -11,10 +11,10 @@ import ( ) var ( - procGetDiskFreeSpaceExW = modkernel32.NewProc("GetDiskFreeSpaceExW") - procGetLogicalDriveStringsW = modkernel32.NewProc("GetLogicalDriveStringsW") - procGetDriveType = modkernel32.NewProc("GetDriveTypeW") - provGetVolumeInformation = modkernel32.NewProc("GetVolumeInformationW") + procGetDiskFreeSpaceExW = common.Modkernel32.NewProc("GetDiskFreeSpaceExW") + procGetLogicalDriveStringsW = common.Modkernel32.NewProc("GetLogicalDriveStringsW") + procGetDriveType = common.Modkernel32.NewProc("GetDriveTypeW") + provGetVolumeInformation = common.Modkernel32.NewProc("GetVolumeInformationW") ) var ( diff --git a/host/host_windows.go b/host/host_windows.go index 89211875..c7c7008b 100644 --- a/host/host_windows.go +++ b/host/host_windows.go @@ -6,11 +6,14 @@ import ( "os" "syscall" "unsafe" + + common "github.com/shirou/gopsutil/common" + process "github.com/shirou/gopsutil/process" ) var ( - procGetSystemTimeAsFileTime = modkernel32.NewProc("GetSystemTimeAsFileTime") - procGetTickCount = modkernel32.NewProc("GetTickCount") + procGetSystemTimeAsFileTime = common.Modkernel32.NewProc("GetSystemTimeAsFileTime") + procGetTickCount = common.Modkernel32.NewProc("GetTickCount") ) func HostInfo() (*HostInfoStat, error) { @@ -28,7 +31,7 @@ func HostInfo() (*HostInfoStat, error) { ret.Uptime = uint64(uptimemsec) / 1000 - procs, err := Pids() + procs, err := process.Pids() if err != nil { return ret, err } @@ -39,7 +42,7 @@ func HostInfo() (*HostInfoStat, error) { } func BootTime() (uint64, error) { - var lpSystemTimeAsFileTime FILETIME + var lpSystemTimeAsFileTime common.FILETIME r, _, _ := procGetSystemTimeAsFileTime.Call(uintptr(unsafe.Pointer(&lpSystemTimeAsFileTime))) if r == 0 { diff --git a/mem/mem_windows.go b/mem/mem_windows.go index 07d16e99..142c6505 100644 --- a/mem/mem_windows.go +++ b/mem/mem_windows.go @@ -5,10 +5,12 @@ package gopsutil import ( "syscall" "unsafe" + + common "github.com/shirou/gopsutil/common" ) var ( - procGlobalMemoryStatusEx = modkernel32.NewProc("GlobalMemoryStatusEx") + procGlobalMemoryStatusEx = common.Modkernel32.NewProc("GlobalMemoryStatusEx") ) type MEMORYSTATUSEX struct { diff --git a/net/net_windows.go b/net/net_windows.go index 918f4da8..f8bd4573 100644 --- a/net/net_windows.go +++ b/net/net_windows.go @@ -44,7 +44,7 @@ func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) { for _, ifi := range ifs { name := ifi.Name for ; ai != nil; ai = ai.Next { - name = bytePtrToString(&ai.Description[0]) + name = common.BytePtrToString(&ai.Description[0]) c := NetIOCountersStat{ Name: name, } diff --git a/process/process_windows.go b/process/process_windows.go index 7424f81d..b37f2e9b 100644 --- a/process/process_windows.go +++ b/process/process_windows.go @@ -10,6 +10,8 @@ import ( "github.com/shirou/w32" common "github.com/shirou/gopsutil/common" + cpu "github.com/shirou/gopsutil/cpu" + net "github.com/shirou/gopsutil/net" ) const ( @@ -130,7 +132,7 @@ func (p *Process) Threads() (map[string]string, error) { ret := make(map[string]string, 0) return ret, common.NotImplementedError } -func (p *Process) CPUTimes() (*CPUTimesStat, error) { +func (p *Process) CPUTimes() (*cpu.CPUTimesStat, error) { return nil, common.NotImplementedError } func (p *Process) CPUPercent() (int32, error) { @@ -157,7 +159,7 @@ func (p *Process) OpenFiles() ([]OpenFilesStat, error) { return nil, common.NotImplementedError } -func (p *Process) Connections() ([]NetConnectionStat, error) { +func (p *Process) Connections() ([]net.NetConnectionStat, error) { return nil, common.NotImplementedError } @@ -249,7 +251,7 @@ func getProcInfo(pid int32) (*SystemProcessInformation, error) { buffer := make([]byte, bufferSize) var sysProcInfo SystemProcessInformation - ret, _, _ := procNtQuerySystemInformation.Call( + ret, _, _ := common.ProcNtQuerySystemInformation.Call( uintptr(unsafe.Pointer(&sysProcInfo)), uintptr(unsafe.Pointer(&buffer[0])), uintptr(unsafe.Pointer(&bufferSize)),