diff --git a/README.rst b/README.rst index f20f299..b5e50c7 100644 --- a/README.rst +++ b/README.rst @@ -27,9 +27,7 @@ Available Architectures - Linux/amd64 - Linux/arm (raspberry pi) - Windows/amd64 - -(I do not have a darwin machine) - +- Darwin/amd64 All works are implemented without cgo by porting c struct to golang struct. @@ -131,15 +129,15 @@ Current Status ================= =========== ========= ============= ====== ======= name Linux amd64 Linux ARM FreeBSD amd64 MacOSX Windows -cpu_times x x x x +cpu_times x x x cpu_count x x x x x -cpu_percent x x x x x -cpu_times_percent x x x x x +cpu_percent x x x x +cpu_times_percent x x x x virtual_memory x x x x x swap_memory x x x x disk_partitions x x x x x disk_io_counters x x -disk_usage x x x x +disk_usage x x x x x net_io_counters x x x x x boot_time x x x x b users x x x x x diff --git a/common/common.go b/common/common.go index c44bb2f..0f470d4 100644 --- a/common/common.go +++ b/common/common.go @@ -1,10 +1,10 @@ // -// gopsutil is a port of psutil(http://pythonhosted.org/psutil/). +// common is a port of psutil(http://pythonhosted.org/psutil/). // This covers these architectures. // - linux (amd64, arm) // - freebsd (amd64) // - windows (amd64) -package gopsutil +package common import ( "bufio" diff --git a/common/common_darwin.go b/common/common_darwin.go index 7a742bd..fa5b30f 100644 --- a/common/common_darwin.go +++ b/common/common_darwin.go @@ -1,6 +1,6 @@ // +build darwin -package gopsutil +package common import ( "os/exec" diff --git a/common/common_freebsd.go b/common/common_freebsd.go index 997bb78..7201082 100644 --- a/common/common_freebsd.go +++ b/common/common_freebsd.go @@ -1,6 +1,6 @@ // +build freebsd -package gopsutil +package common import ( "os/exec" diff --git a/common/common_windows.go b/common/common_windows.go index 534f4aa..8c5625e 100644 --- a/common/common_windows.go +++ b/common/common_windows.go @@ -1,6 +1,6 @@ // +build windows -package gopsutil +package common import ( "syscall" diff --git a/cpu/cpu.go b/cpu/cpu.go index 6b49e99..67b4fad 100644 --- a/cpu/cpu.go +++ b/cpu/cpu.go @@ -1,4 +1,4 @@ -package gopsutil +package cpu import ( "encoding/json" diff --git a/cpu/cpu_darwin.go b/cpu/cpu_darwin.go index cb03fb8..f40012e 100644 --- a/cpu/cpu_darwin.go +++ b/cpu/cpu_darwin.go @@ -1,6 +1,6 @@ // +build darwin -package gopsutil +package cpu import ( "fmt" diff --git a/cpu/cpu_freebsd.go b/cpu/cpu_freebsd.go index 29c8b7c..5ac4fc2 100644 --- a/cpu/cpu_freebsd.go +++ b/cpu/cpu_freebsd.go @@ -1,6 +1,6 @@ // +build freebsd -package gopsutil +package cpu import ( "fmt" diff --git a/cpu/cpu_linux.go b/cpu/cpu_linux.go index 8fb03c2..4a303ba 100644 --- a/cpu/cpu_linux.go +++ b/cpu/cpu_linux.go @@ -1,6 +1,6 @@ // +build linux -package gopsutil +package cpu import ( "errors" diff --git a/cpu/cpu_test.go b/cpu/cpu_test.go index 77aed44..00345cf 100644 --- a/cpu/cpu_test.go +++ b/cpu/cpu_test.go @@ -1,4 +1,4 @@ -package gopsutil +package cpu import ( "fmt" diff --git a/cpu/cpu_windows.go b/cpu/cpu_windows.go index fde4635..3a14943 100644 --- a/cpu/cpu_windows.go +++ b/cpu/cpu_windows.go @@ -1,6 +1,6 @@ // +build windows -package gopsutil +package cpu import ( "syscall" diff --git a/disk/disk.go b/disk/disk.go index 9800bea..fc2f796 100644 --- a/disk/disk.go +++ b/disk/disk.go @@ -1,4 +1,4 @@ -package gopsutil +package disk import ( "encoding/json" diff --git a/disk/disk_darwin.go b/disk/disk_darwin.go index 715fa9b..3aa85c8 100644 --- a/disk/disk_darwin.go +++ b/disk/disk_darwin.go @@ -1,6 +1,6 @@ // +build darwin -package gopsutil +package disk import ( "syscall" diff --git a/disk/disk_darwin_amd64.go b/disk/disk_darwin_amd64.go new file mode 100644 index 0000000..f58e213 --- /dev/null +++ b/disk/disk_darwin_amd64.go @@ -0,0 +1,58 @@ +// +build darwin +// +build amd64 + +package disk + +const ( + MntWait = 1 + MfsNameLen = 15 /* length of fs type name, not inc. nul */ + MNameLen = 90 /* length of buffer for returned name */ + + MFSTYPENAMELEN = 16 /* length of fs type name including null */ + MAXPATHLEN = 1024 + MNAMELEN = MAXPATHLEN + + SYS_GETFSSTAT64 = 347 +) + +type Fsid struct{ val [2]int32 } /* file system id type */ +type uid_t int32 + +// sys/mount.h +const ( + MntReadOnly = 0x00000001 /* read only filesystem */ + MntSynchronous = 0x00000002 /* filesystem written synchronously */ + MntNoExec = 0x00000004 /* can't exec from filesystem */ + MntNoSuid = 0x00000008 /* don't honor setuid bits on fs */ + MntUnion = 0x00000020 /* union with underlying filesystem */ + MntAsync = 0x00000040 /* filesystem written asynchronously */ + MntSuidDir = 0x00100000 /* special handling of SUID on dirs */ + MntSoftDep = 0x00200000 /* soft updates being done */ + MntNoSymFollow = 0x00400000 /* do not follow symlinks */ + MntGEOMJournal = 0x02000000 /* GEOM journal support enabled */ + MntMultilabel = 0x04000000 /* MAC support for individual objects */ + MntACLs = 0x08000000 /* ACL support enabled */ + MntNoATime = 0x10000000 /* disable update of file access time */ + MntClusterRead = 0x40000000 /* disable cluster read */ + MntClusterWrite = 0x80000000 /* disable cluster write */ + MntNFS4ACLs = 0x00000010 +) + +type Statfs_t struct { + Bsize uint32 + Iosize int32 + Blocks uint64 + Bfree uint64 + Bavail uint64 + Files uint64 + Ffree uint64 + Fsid Fsid + Owner uint32 + Type uint32 + Flags uint32 + Fssubtype uint32 + Fstypename [16]int8 + Mntonname [1024]int8 + Mntfromname [1024]int8 + Reserved [8]uint32 +} diff --git a/disk/disk_freebsd.go b/disk/disk_freebsd.go index 1c8d746..3d3fce0 100644 --- a/disk/disk_freebsd.go +++ b/disk/disk_freebsd.go @@ -1,6 +1,6 @@ // +build freebsd -package gopsutil +package disk import ( "syscall" diff --git a/disk/disk_freebsd_amd64.go b/disk/disk_freebsd_amd64.go index b02aa33..debc6b2 100644 --- a/disk/disk_freebsd_amd64.go +++ b/disk/disk_freebsd_amd64.go @@ -1,7 +1,7 @@ // +build freebsd // +build amd64 -package gopsutil +package disk const ( MntWait = 1 diff --git a/disk/disk_linux.go b/disk/disk_linux.go index 3f075ff..2ec2fcb 100644 --- a/disk/disk_linux.go +++ b/disk/disk_linux.go @@ -1,6 +1,6 @@ // +build linux -package gopsutil +package disk import ( "fmt" diff --git a/disk/disk_test.go b/disk/disk_test.go index 7f85a48..7c614c8 100644 --- a/disk/disk_test.go +++ b/disk/disk_test.go @@ -1,4 +1,4 @@ -package gopsutil +package disk import ( "fmt" diff --git a/disk/disk_unix.go b/disk/disk_unix.go index 036e4e0..bc53d40 100644 --- a/disk/disk_unix.go +++ b/disk/disk_unix.go @@ -1,6 +1,6 @@ // +build freebsd linux darwin -package gopsutil +package disk import "syscall" diff --git a/disk/disk_windows.go b/disk/disk_windows.go index 39fb049..cd1fe36 100644 --- a/disk/disk_windows.go +++ b/disk/disk_windows.go @@ -1,6 +1,6 @@ // +build windows -package gopsutil +package disk import ( "bytes" diff --git a/docker/docker_linux.go b/docker/docker_linux.go index 64181e0..0f783d7 100644 --- a/docker/docker_linux.go +++ b/docker/docker_linux.go @@ -1,6 +1,6 @@ // +build linux -package gopsutil +package docker import ( "encoding/json" diff --git a/docker/docker_linux_test.go b/docker/docker_linux_test.go index 285861e..d5504f7 100644 --- a/docker/docker_linux_test.go +++ b/docker/docker_linux_test.go @@ -1,6 +1,6 @@ // +build linux -package gopsutil +package docker import ( "testing" diff --git a/host/host.go b/host/host.go index 229c6ef..523b634 100644 --- a/host/host.go +++ b/host/host.go @@ -1,4 +1,4 @@ -package gopsutil +package host import ( "encoding/json" diff --git a/host/host_darwin.go b/host/host_darwin.go index ff9866e..f1e189e 100644 --- a/host/host_darwin.go +++ b/host/host_darwin.go @@ -1,6 +1,6 @@ // +build darwin -package gopsutil +package host import ( "bytes" diff --git a/host/host_freebsd.go b/host/host_freebsd.go index 6c3697d..47dfe50 100644 --- a/host/host_freebsd.go +++ b/host/host_freebsd.go @@ -1,6 +1,6 @@ // +build freebsd -package gopsutil +package host import ( "bytes" diff --git a/host/host_freebsd_amd64.go b/host/host_freebsd_amd64.go index efd1ade..fc8e521 100644 --- a/host/host_freebsd_amd64.go +++ b/host/host_freebsd_amd64.go @@ -1,7 +1,7 @@ // +build freebsd // +build amd64 -package gopsutil +package host const ( UTNameSize = 16 /* see MAXLOGNAME in <sys/param.h> */ diff --git a/host/host_linux.go b/host/host_linux.go index ebd0c0c..4964b92 100644 --- a/host/host_linux.go +++ b/host/host_linux.go @@ -1,6 +1,6 @@ // +build linux -package gopsutil +package host import ( "bytes" diff --git a/host/host_linux_amd64.go b/host/host_linux_amd64.go index 19ee586..bdd1600 100644 --- a/host/host_linux_amd64.go +++ b/host/host_linux_amd64.go @@ -1,7 +1,7 @@ // +build linux // +build amd64 -package gopsutil +package host type exitStatus struct { Etermination int16 // Process termination status. diff --git a/host/host_linux_arm.go b/host/host_linux_arm.go index b1371fd..b737d96 100644 --- a/host/host_linux_arm.go +++ b/host/host_linux_arm.go @@ -1,7 +1,7 @@ // +build linux // +build arm -package gopsutil +package host type exitStatus struct { Etermination int16 // Process termination status. diff --git a/host/host_linux_test.go b/host/host_linux_test.go index 56343aa..7808eee 100644 --- a/host/host_linux_test.go +++ b/host/host_linux_test.go @@ -1,6 +1,6 @@ // +build linux -package gopsutil +package host import ( "testing" diff --git a/host/host_test.go b/host/host_test.go index 1d6852e..4c6fbc9 100644 --- a/host/host_test.go +++ b/host/host_test.go @@ -1,4 +1,4 @@ -package gopsutil +package host import ( "fmt" diff --git a/host/host_windows.go b/host/host_windows.go index c7c7008..851c26d 100644 --- a/host/host_windows.go +++ b/host/host_windows.go @@ -1,6 +1,6 @@ // +build windows -package gopsutil +package host import ( "os" diff --git a/load/load.go b/load/load.go index 7b124d6..58746e7 100644 --- a/load/load.go +++ b/load/load.go @@ -1,4 +1,4 @@ -package gopsutil +package load import ( "encoding/json" diff --git a/load/load_darwin.go b/load/load_darwin.go index 6954f0d..d90a429 100644 --- a/load/load_darwin.go +++ b/load/load_darwin.go @@ -1,6 +1,6 @@ // +build darwin -package gopsutil +package load import ( "strconv" diff --git a/load/load_freebsd.go b/load/load_freebsd.go index 50196f6..d82afbe 100644 --- a/load/load_freebsd.go +++ b/load/load_freebsd.go @@ -1,6 +1,6 @@ // +build freebsd -package gopsutil +package load import ( "strconv" diff --git a/load/load_linux.go b/load/load_linux.go index 238ae30..6c9926b 100644 --- a/load/load_linux.go +++ b/load/load_linux.go @@ -1,6 +1,6 @@ // +build linux -package gopsutil +package load import ( "io/ioutil" diff --git a/load/load_test.go b/load/load_test.go index 660e940..39cee39 100644 --- a/load/load_test.go +++ b/load/load_test.go @@ -1,4 +1,4 @@ -package gopsutil +package load import ( "fmt" diff --git a/load/load_windows.go b/load/load_windows.go index 75f07ac..70ad565 100644 --- a/load/load_windows.go +++ b/load/load_windows.go @@ -1,6 +1,6 @@ // +build windows -package gopsutil +package load import ( common "github.com/shirou/gopsutil/common" diff --git a/mem/mem.go b/mem/mem.go index 63cfad4..67f8741 100644 --- a/mem/mem.go +++ b/mem/mem.go @@ -1,4 +1,4 @@ -package gopsutil +package mem import ( "encoding/json" diff --git a/mem/mem_darwin.go b/mem/mem_darwin.go index f6282e2..a454894 100644 --- a/mem/mem_darwin.go +++ b/mem/mem_darwin.go @@ -1,6 +1,6 @@ // +build darwin -package gopsutil +package mem import ( "os/exec" diff --git a/mem/mem_freebsd.go b/mem/mem_freebsd.go index 97dce78..a380519 100644 --- a/mem/mem_freebsd.go +++ b/mem/mem_freebsd.go @@ -1,6 +1,6 @@ // +build freebsd -package gopsutil +package mem import ( "os/exec" diff --git a/mem/mem_linux.go b/mem/mem_linux.go index aecdee1..00559c5 100644 --- a/mem/mem_linux.go +++ b/mem/mem_linux.go @@ -1,6 +1,6 @@ // +build linux -package gopsutil +package mem import ( "strconv" diff --git a/mem/mem_test.go b/mem/mem_test.go index 63421b3..2869357 100644 --- a/mem/mem_test.go +++ b/mem/mem_test.go @@ -1,4 +1,4 @@ -package gopsutil +package mem import ( "fmt" diff --git a/mem/mem_windows.go b/mem/mem_windows.go index 142c650..985ab8f 100644 --- a/mem/mem_windows.go +++ b/mem/mem_windows.go @@ -1,6 +1,6 @@ // +build windows -package gopsutil +package mem import ( "syscall" diff --git a/net/net.go b/net/net.go index de4f29f..d39ad49 100644 --- a/net/net.go +++ b/net/net.go @@ -1,4 +1,4 @@ -package gopsutil +package net import ( "encoding/json" diff --git a/net/net_darwin.go b/net/net_darwin.go index d65e116..2aa8184 100644 --- a/net/net_darwin.go +++ b/net/net_darwin.go @@ -1,6 +1,6 @@ // +build darwin -package gopsutil +package net import ( "os/exec" diff --git a/net/net_freebsd.go b/net/net_freebsd.go index bb1bd53..0778ea8 100644 --- a/net/net_freebsd.go +++ b/net/net_freebsd.go @@ -1,6 +1,6 @@ // +build freebsd -package gopsutil +package net import ( "os/exec" diff --git a/net/net_linux.go b/net/net_linux.go index 5ab58db..cea25fa 100644 --- a/net/net_linux.go +++ b/net/net_linux.go @@ -1,6 +1,6 @@ // +build linux -package gopsutil +package net import ( "strconv" diff --git a/net/net_test.go b/net/net_test.go index 1d3c47a..884c28f 100644 --- a/net/net_test.go +++ b/net/net_test.go @@ -1,4 +1,4 @@ -package gopsutil +package net import ( "fmt" diff --git a/net/net_windows.go b/net/net_windows.go index f8bd457..136221a 100644 --- a/net/net_windows.go +++ b/net/net_windows.go @@ -1,6 +1,6 @@ // +build windows -package gopsutil +package net import ( "net" diff --git a/process/process.go b/process/process.go index d403a58..14d7a83 100644 --- a/process/process.go +++ b/process/process.go @@ -1,4 +1,4 @@ -package gopsutil +package process import ( "encoding/json" diff --git a/process/process_darwin.go b/process/process_darwin.go index ab64886..8c62adf 100644 --- a/process/process_darwin.go +++ b/process/process_darwin.go @@ -1,6 +1,6 @@ // +build darwin -package gopsutil +package process import ( "bytes" @@ -201,7 +201,7 @@ func copyParams(k *KinfoProc, p *Process) error { func processes() ([]Process, error) { results := make([]Process, 0, 50) - mib := []int32{CTLKern, KernProc, KernProcProc, 0} + mib := []int32{CTLKern, KernProc, KernProcAll} buf, length, err := callSyscall(mib) if err != nil { return results, err @@ -213,6 +213,7 @@ func processes() ([]Process, error) { count := int(length / uint64(procinfoLen)) // parse buf to procs + for i := 0; i < count; i++ { b := buf[i*procinfoLen : i*procinfoLen+procinfoLen] k, err := parseKinfoProc(b) diff --git a/process/process_darwin_amd64.go b/process/process_darwin_amd64.go index 8fe4d6f..07308a6 100644 --- a/process/process_darwin_amd64.go +++ b/process/process_darwin_amd64.go @@ -1,7 +1,7 @@ // +build darwin // +build amd64 -package gopsutil +package process // copied from sys/sysctl.h const ( @@ -9,6 +9,7 @@ const ( KernProc = 14 // struct: process entries KernProcPID = 1 // by process id KernProcProc = 8 // only return procs + KernProcAll = 0 // everything KernProcPathname = 12 // path to executable ) diff --git a/process/process_freebsd.go b/process/process_freebsd.go index 95f76c7..b3b5069 100644 --- a/process/process_freebsd.go +++ b/process/process_freebsd.go @@ -1,6 +1,6 @@ // +build freebsd -package gopsutil +package process import ( "bytes" diff --git a/process/process_freebsd_amd64.go b/process/process_freebsd_amd64.go index 73bbab4..0dafda2 100644 --- a/process/process_freebsd_amd64.go +++ b/process/process_freebsd_amd64.go @@ -1,7 +1,7 @@ // +build freebsd // +build amd64 -package gopsutil +package process // copied from sys/sysctl.h const ( diff --git a/process/process_linux.go b/process/process_linux.go index e4bd597..e4b45b3 100644 --- a/process/process_linux.go +++ b/process/process_linux.go @@ -1,6 +1,6 @@ // +build linux -package gopsutil +package process import ( "encoding/json" diff --git a/process/process_linux_amd64.go b/process/process_linux_amd64.go index 29554db..b4a4ce8 100644 --- a/process/process_linux_amd64.go +++ b/process/process_linux_amd64.go @@ -1,7 +1,7 @@ // +build linux // +build amd64 -package gopsutil +package process const ( ClockTicks = 100 // C.sysconf(C._SC_CLK_TCK) diff --git a/process/process_linux_arm.go b/process/process_linux_arm.go index 4f915bb..c6123a4 100644 --- a/process/process_linux_arm.go +++ b/process/process_linux_arm.go @@ -1,7 +1,7 @@ // +build linux // +build arm -package gopsutil +package process const ( ClockTicks = 100 // C.sysconf(C._SC_CLK_TCK) diff --git a/process/process_posix.go b/process/process_posix.go index 4e2625a..38f06e9 100644 --- a/process/process_posix.go +++ b/process/process_posix.go @@ -1,6 +1,6 @@ // +build linux freebsd darwin -package gopsutil +package process import ( "os" diff --git a/process/process_posix_test.go b/process/process_posix_test.go index b45418a..eb91292 100644 --- a/process/process_posix_test.go +++ b/process/process_posix_test.go @@ -1,6 +1,6 @@ // +build linux freebsd -package gopsutil +package process import ( "os" diff --git a/process/process_test.go b/process/process_test.go index 2a14d12..ac7bf50 100644 --- a/process/process_test.go +++ b/process/process_test.go @@ -1,4 +1,4 @@ -package gopsutil +package process import ( "os" @@ -116,3 +116,13 @@ func Test_Process_NumCtx(t *testing.T) { return } } + +func Test_Process_Nice(t *testing.T) { + p := testGetProcess() + + _, err := p.Nice() + if err != nil { + t.Errorf("geting nice error %v", err) + return + } +} diff --git a/process/process_windows.go b/process/process_windows.go index b37f2e9..a6cbe79 100644 --- a/process/process_windows.go +++ b/process/process_windows.go @@ -1,6 +1,6 @@ // +build windows -package gopsutil +package process import ( "errors"