1
0
mirror of https://github.com/shirou/gopsutil.git synced 2025-04-24 13:48:56 +08:00

fix windows build.

This commit is contained in:
WAKAYAMA Shirou 2014-11-27 22:28:05 +09:00
parent a1c1d7b25f
commit 9f2c985a28
7 changed files with 30 additions and 21 deletions

View File

@ -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 {

View File

@ -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)))

View File

@ -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 (

View File

@ -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 {

View File

@ -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 {

View File

@ -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,
}

View File

@ -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)),