Merge branch 'separate_directories'

Conflicts:
	README.rst
tags/1.0.0^0 1.0.0
Shirou WAKAYAMA 11 years ago
commit ce433bf86e

1
.gitignore vendored

@ -1,2 +1,3 @@
*~
#*
_obj

@ -13,7 +13,11 @@ psutil functions on some architectures...
.. highlights:: Package Structure Changed!
Package (a.k.a. directory) structure has been changed!! see `#24 <https://github.com/shirou/gopsutil/issues/24`_
Package (a.k.a. directory) structure has been changed!! see `issue 24 <https://github.com/shirou/gopsutil/issues/24>`_
.. highlights:: golang 1.4 will become REQUIRED!
Since syscall package becomes frozen, we should use golang/x/sys of golang 1.4 as soon as possible.
Available Architectures
@ -23,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.
@ -125,57 +127,57 @@ Current Status
- x: work
- b: almost work but something broken
================= ========= ========= =========== ====== =======
name Linux 686 Linux ARM FreeBSD 686 MacOSX Windows
cpu_times x 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
virtual_memory x x x x x
swap_memory x x x x
disk_partitions x x x x
disk_io_counters x x
disk_usage 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
pids x x x x x
pid_exists x x x x x
================= =========== ========= ============= ====== =======
name Linux amd64 Linux ARM FreeBSD amd64 MacOSX Windows
cpu_times x x x
cpu_count 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 x
net_io_counters x x x x x
boot_time x x x x b
users x x x x x
pids x x x x x
pid_exists x x x x x
net_connections
================= ========= ========= =========== ====== =======
================= =========== ========= ============= ====== =======
Process class
^^^^^^^^^^^^^^^
================ ========= ========= =========== ====== =======
name Linux 686 Linux ARM FreeBSD 686 MacOSX Windows
pid x x x x x
ppid x x x x x
name x x x x
cmdline x x
create_time x x
status x x x x
cwd x x
exe x x x x
uids x x x x
gids x x x x
terminal x x x x
io_counters x x
nice x x
num_fds x x
num_ctx_switches x x
num_threads x x x x
cpu_times x x
memory_info x x x x
memory_info_ex x x
memory_maps x x
open_files x x
send_signal x x x x
suspend x x x x
resume x x x x
terminate x x x x
kill x x x x
username x x x x
================ =========== ========= ============= ====== =======
name Linux amd64 Linux ARM FreeBSD amd64 MacOSX Windows
pid x x x x x
ppid x x x x x
name x x x x
cmdline x x
create_time x x
status x x x x
cwd x x
exe x x x x
uids x x x x
gids x x x x
terminal x x x x
io_counters x x
nice x x
num_fds x x
num_ctx_switches x x
num_threads x x x x
cpu_times x x
memory_info x x x x
memory_info_ex x x
memory_maps x x
open_files x x
send_signal x x x x
suspend x x x x
resume x x x x
terminate x x x x
kill x x x x
username x x x x
ionice
rlimit
num_handlres
@ -186,41 +188,41 @@ memory_percent
children
connections
is_running
================ ========= ========= =========== ====== =======
================ =========== ========= ============= ====== =======
Original Metrics
^^^^^^^^^^^^^^^^^^^
================== ========= ========= =========== ====== =======
item Linux 686 Linux ARM FreeBSD 686 MacOSX Windows
================== =========== ========= ============= ====== =======
item Linux amd64 Linux ARM FreeBSD amd64 MacOSX Windows
**HostInfo**
hostname x x x
uptime x x x
proces x x x
os x x x x x
platform x x x
platformfamiliy x x x
virtualization x x
hostname x x x x x
uptime x x x x
proces x x x
os x x x x x
platform x x x x
platformfamiliy x x x x
virtualization x x
**CPU**
VendorID x x
Family x x
Model x x
Stepping x x
PhysicalID x x
CoreID x x
Cores x x
ModelName x x
VendorID x x x x
Family x x x x
Model x x x x
Stepping x x x x
PhysicalID x x
CoreID x x
Cores x x
ModelName x x x x
**LoadAvg**
Load1 x x x
Load5 x x x
Load15 x x x
Load1 x x x x
Load5 x x x x
Load15 x x x x
**GetDockerID**
container id x x
container id x x no no no
**CgroupsCPU**
user x x
system x x
user x x no no no
system x x no no no
**CgroupsMem**
various x x
================== ========= ========= =========== ====== =======
various x x no no no
================== =========== ========= ============= ====== =======
- future work

@ -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"
@ -17,18 +17,18 @@ import (
var NotImplementedError = errors.New("not implemented yet")
// readLines reads contents from file and splits them by new line.
// A convenience wrapper to readLinesOffsetN(filename, 0, -1).
func readLines(filename string) ([]string, error) {
return readLinesOffsetN(filename, 0, -1)
// ReadLines reads contents from file and splits them by new line.
// A convenience wrapper to ReadLinesOffsetN(filename, 0, -1).
func ReadLines(filename string) ([]string, error) {
return ReadLinesOffsetN(filename, 0, -1)
}
// readLines reads contents from file and splits them by new line.
// ReadLines reads contents from file and splits them by new line.
// The offset tells at which line number to start.
// The count determines the number of lines to read (starting from offset):
// n >= 0: at most n lines
// n < 0: whole file
func readLinesOffsetN(filename string, offset uint, n int) ([]string, error) {
func ReadLinesOffsetN(filename string, offset uint, n int) ([]string, error) {
f, err := os.Open(filename)
if err != nil {
return []string{""}, err
@ -52,7 +52,22 @@ func readLinesOffsetN(filename string, offset uint, n int) ([]string, error) {
return ret, nil
}
func byteToString(orig []byte) string {
func IntToString(orig []int8) string {
ret := make([]byte, len(orig))
size := 0
for i, o := range orig {
if o == 0 {
size = i
break
}
ret[i] = byte(o)
}
return string(ret[0:size])
}
func ByteToString(orig []byte) string {
n := -1
l := -1
for i, b := range orig {
@ -94,7 +109,7 @@ func mustParseFloat64(val string) float64 {
}
// Check the target string slice containes src or not
func stringContains(target []string, src string) bool {
func StringContains(target []string, src string) bool {
for _, t := range target {
if t == src {
return true
@ -126,7 +141,7 @@ func attributes(m interface{}) map[string]reflect.Type {
return attrs
}
func pathExists(filename string) bool {
func PathExists(filename string) bool {
if _, err := os.Stat(filename); err == nil {
return true
}

@ -1,13 +1,13 @@
// +build darwin
package gopsutil
package common
import (
"os/exec"
"strings"
)
func doSysctrl(mib string) ([]string, error) {
func DoSysctrl(mib string) ([]string, error) {
out, err := exec.Command("/usr/sbin/sysctl", "-n", mib).Output()
if err != nil {
return []string{}, err

@ -1,13 +1,13 @@
// +build freebsd
package gopsutil
package common
import (
"os/exec"
"strings"
)
func doSysctrl(mib string) ([]string, error) {
func DoSysctrl(mib string) ([]string, error) {
out, err := exec.Command("/sbin/sysctl", "-n", mib).Output()
if err != nil {
return []string{}, err

@ -1,6 +1,6 @@
// +build windows
package gopsutil
package common
import (
"syscall"
@ -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 {
@ -21,7 +21,7 @@ type FILETIME struct {
}
// borrowed from net/interface_windows.go
func bytePtrToString(p *uint8) string {
func BytePtrToString(p *uint8) string {
a := (*[10000]uint8)(unsafe.Pointer(p))
i := 0
for a[i] != 0 {

@ -1,4 +1,4 @@
package gopsutil
package cpu
import (
"encoding/json"

@ -1,12 +1,14 @@
// +build darwin
package gopsutil
package cpu
import (
"fmt"
"os/exec"
"strconv"
"strings"
common "github.com/shirou/gopsutil/common"
)
// sys/resource.h
@ -37,7 +39,7 @@ func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
ncpu = 1
}
cpuTimes, err := doSysctrl(sysctlCall)
cpuTimes, err := common.DoSysctrl(sysctlCall)
if err != nil {
return ret, err
}

@ -1,12 +1,14 @@
// +build freebsd
package gopsutil
package cpu
import (
"fmt"
"regexp"
"strconv"
"strings"
common "github.com/shirou/gopsutil/common"
)
// sys/resource.h
@ -37,7 +39,7 @@ func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
ncpu = 1
}
cpuTimes, err := doSysctrl(sysctlCall)
cpuTimes, err := common.DoSysctrl(sysctlCall)
if err != nil {
return ret, err
}
@ -87,7 +89,7 @@ func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
// Returns only one CPUInfoStat on FreeBSD
func CPUInfo() ([]CPUInfoStat, error) {
filename := "/var/run/dmesg.boot"
lines, _ := readLines(filename)
lines, _ := common.ReadLines(filename)
var ret []CPUInfoStat

@ -1,11 +1,13 @@
// +build linux
package gopsutil
package cpu
import (
"errors"
"strconv"
"strings"
common "github.com/shirou/gopsutil/common"
)
func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
@ -13,9 +15,9 @@ func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
var lines []string
if percpu {
ncpu, _ := CPUCounts(true)
lines, _ = readLinesOffsetN(filename, 1, ncpu)
lines, _ = common.ReadLinesOffsetN(filename, 1, ncpu)
} else {
lines, _ = readLinesOffsetN(filename, 0, 1)
lines, _ = common.ReadLinesOffsetN(filename, 0, 1)
}
ret := make([]CPUTimesStat, 0, len(lines))
@ -33,7 +35,7 @@ func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
func CPUInfo() ([]CPUInfoStat, error) {
filename := "/proc/cpuinfo"
lines, _ := readLines(filename)
lines, _ := common.ReadLines(filename)
var ret []CPUInfoStat

@ -1,4 +1,4 @@
package gopsutil
package cpu
import (
"fmt"

@ -1,20 +1,22 @@
// +build windows
package gopsutil
package cpu
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)))

@ -1,4 +1,4 @@
package gopsutil
package disk
import (
"encoding/json"

@ -0,0 +1,100 @@
// +build darwin
package disk
import (
"syscall"
"unsafe"
common "github.com/shirou/gopsutil/common"
)
func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
var ret []DiskPartitionStat
count, err := Getfsstat(nil, MntWait)
if err != nil {
return ret, err
}
fs := make([]Statfs_t, count)
_, err = Getfsstat(fs, MntWait)
for _, stat := range fs {
opts := "rw"
if stat.Flags&MntReadOnly != 0 {
opts = "ro"
}
if stat.Flags&MntSynchronous != 0 {
opts += ",sync"
}
if stat.Flags&MntNoExec != 0 {
opts += ",noexec"
}
if stat.Flags&MntNoSuid != 0 {
opts += ",nosuid"
}
if stat.Flags&MntUnion != 0 {
opts += ",union"
}
if stat.Flags&MntAsync != 0 {
opts += ",async"
}
if stat.Flags&MntSuidDir != 0 {
opts += ",suiddir"
}
if stat.Flags&MntSoftDep != 0 {
opts += ",softdep"
}
if stat.Flags&MntNoSymFollow != 0 {
opts += ",nosymfollow"
}
if stat.Flags&MntGEOMJournal != 0 {
opts += ",gjounalc"
}
if stat.Flags&MntMultilabel != 0 {
opts += ",multilabel"
}
if stat.Flags&MntACLs != 0 {
opts += ",acls"
}
if stat.Flags&MntNoATime != 0 {
opts += ",noattime"
}
if stat.Flags&MntClusterRead != 0 {
opts += ",nocluster"
}
if stat.Flags&MntClusterWrite != 0 {
opts += ",noclusterw"
}
if stat.Flags&MntNFS4ACLs != 0 {
opts += ",nfs4acls"
}
d := DiskPartitionStat{
Device: common.IntToString(stat.Mntfromname[:]),
Mountpoint: common.IntToString(stat.Mntonname[:]),
Fstype: common.IntToString(stat.Fstypename[:]),
Opts: opts,
}
ret = append(ret, d)
}
return ret, nil
}
func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
return nil, common.NotImplementedError
}
func Getfsstat(buf []Statfs_t, flags int) (n int, err error) {
var _p0 unsafe.Pointer
var bufsize uintptr
if len(buf) > 0 {
_p0 = unsafe.Pointer(&buf[0])
bufsize = unsafe.Sizeof(Statfs_t{}) * uintptr(len(buf))
}
r0, _, e1 := syscall.Syscall(SYS_GETFSSTAT64, uintptr(_p0), bufsize, uintptr(flags))
n = int(r0)
if e1 != 0 {
err = e1
}
return
}

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

@ -1,10 +1,12 @@
// +build freebsd
package gopsutil
package disk
import (
"syscall"
"unsafe"
common "github.com/shirou/gopsutil/common"
)
func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
@ -71,9 +73,9 @@ func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
}
d := DiskPartitionStat{
Device: byteToString(stat.FMntfromname[:]),
Mountpoint: byteToString(stat.FMntonname[:]),
Fstype: byteToString(stat.FFstypename[:]),
Device: common.ByteToString(stat.FMntfromname[:]),
Mountpoint: common.ByteToString(stat.FMntonname[:]),
Fstype: common.ByteToString(stat.FFstypename[:]),
Opts: opts,
}
ret = append(ret, d)
@ -83,7 +85,7 @@ func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
}
func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
return nil, NotImplementedError
return nil, common.NotImplementedError
// statinfo->devinfo->devstat
// /usr/include/devinfo.h
@ -99,7 +101,7 @@ func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
ret := make(map[string]DiskIOCountersStat, 0)
for _, stat := range fs {
name := byteToString(stat.FMntonname[:])
name := common.ByteToString(stat.FMntonname[:])
d := DiskIOCountersStat{
Name: name,
ReadCount: stat.FSyncwrites + stat.FAsyncwrites,

@ -1,7 +1,7 @@
// +build freebsd
// +build amd64
package gopsutil
package disk
const (
MntWait = 1

@ -1,12 +1,14 @@
// +build linux
package gopsutil
package disk
import (
"fmt"
"os/exec"
"strconv"
"strings"
common "github.com/shirou/gopsutil/common"
)
const (
@ -18,7 +20,7 @@ const (
func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
filename := "/etc/mtab"
lines, err := readLines(filename)
lines, err := common.ReadLines(filename)
if err != nil {
return nil, err
}
@ -41,7 +43,7 @@ func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
filename := "/proc/diskstats"
lines, err := readLines(filename)
lines, err := common.ReadLines(filename)
if err != nil {
return nil, err
}

@ -1,4 +1,4 @@
package gopsutil
package disk
import (
"fmt"

@ -1,6 +1,6 @@
// +build freebsd linux darwin
package gopsutil
package disk
import "syscall"

@ -1,18 +1,20 @@
// +build windows
package gopsutil
package disk
import (
"bytes"
"syscall"
"unsafe"
common "github.com/shirou/gopsutil/common"
)
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 (
@ -113,5 +115,5 @@ func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
ret := make(map[string]DiskIOCountersStat, 0)
return ret, NotImplementedError
return ret, common.NotImplementedError
}

@ -1,12 +0,0 @@
// +build darwin
package gopsutil
func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
return nil, NotImplementedError
}
func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
return nil, NotImplementedError
}

@ -1,6 +1,6 @@
// +build linux
package gopsutil
package docker
import (
"encoding/json"
@ -8,6 +8,9 @@ import (
"path"
"strconv"
"strings"
common "github.com/shirou/gopsutil/common"
cpu "github.com/shirou/gopsutil/cpu"
)
type CgroupMemStat struct {
@ -62,18 +65,18 @@ func GetDockerIDList() ([]string, error) {
// containerid is same as docker id if you use docker.
// If you use container via systemd.slice, you could use
// containerid = docker-<container id>.scope and base=/sys/fs/cgroup/cpuacct/system.slice/
func CgroupCPU(containerid string, base string) (*CPUTimesStat, error) {
func CgroupCPU(containerid string, base string) (*cpu.CPUTimesStat, error) {
if len(base) == 0 {
base = "/sys/fs/cgroup/cpuacct/docker"
}
path := path.Join(base, containerid, "cpuacct.stat")
lines, _ := readLines(path)
lines, _ := common.ReadLines(path)
// empty containerid means all cgroup
if len(containerid) == 0 {
containerid = "all"
}
ret := &CPUTimesStat{CPU: containerid}
ret := &cpu.CPUTimesStat{CPU: containerid}
for _, line := range lines {
fields := strings.Split(line, " ")
if fields[0] == "user" {
@ -93,7 +96,7 @@ func CgroupCPU(containerid string, base string) (*CPUTimesStat, error) {
return ret, nil
}
func CgroupCPUDocker(containerid string) (*CPUTimesStat, error) {
func CgroupCPUDocker(containerid string) (*cpu.CPUTimesStat, error) {
return CgroupCPU(containerid, "/sys/fs/cgroup/cpuacct/docker")
}
@ -106,7 +109,7 @@ func CgroupMem(containerid string, base string) (*CgroupMemStat, error) {
if len(containerid) == 0 {
containerid = "all"
}
lines, _ := readLines(path)
lines, _ := common.ReadLines(path)
ret := &CgroupMemStat{ContainerID: containerid}
for _, line := range lines {
fields := strings.Split(line, " ")

@ -1,6 +1,6 @@
// +build linux
package gopsutil
package docker
import (
"testing"

@ -1,4 +1,4 @@
package gopsutil
package host
import (
"encoding/json"

@ -1,6 +1,6 @@
// +build darwin
package gopsutil
package host
import (
"bytes"
@ -12,6 +12,8 @@ import (
"strconv"
"strings"
"unsafe"
common "github.com/shirou/gopsutil/common"
)
const (
@ -56,7 +58,7 @@ func HostInfo() (*HostInfoStat, error) {
ret.VirtualizationRole = role
}
values, err := doSysctrl("kern.boottime")
values, err := common.DoSysctrl("kern.boottime")
if err == nil {
// ex: { sec = 1392261637, usec = 627534 } Thu Feb 13 12:20:37 2014
v := strings.Replace(values[2], ",", "", 1)
@ -71,7 +73,7 @@ func HostInfo() (*HostInfoStat, error) {
}
func BootTime() (int64, error) {
values, err := doSysctrl("kern.boottime")
values, err := common.DoSysctrl("kern.boottime")
if err != nil {
return 0, err
}
@ -114,9 +116,9 @@ func Users() ([]UserStat, error) {
continue
}
user := UserStat{
User: byteToString(u.UtUser[:]),
// Terminal: byteToString(u.UtLine[:]),
Host: byteToString(u.UtHost[:]),
User: common.ByteToString(u.UtUser[:]),
// Terminal: ByteToString(u.UtLine[:]),
Host: common.ByteToString(u.UtHost[:]),
// Started: int(u.UtTime),
}
ret = append(ret, user)

@ -1,6 +1,6 @@
// +build freebsd
package gopsutil
package host
import (
"bytes"
@ -12,6 +12,14 @@ import (
"strconv"
"strings"
"unsafe"
common "github.com/shirou/gopsutil/common"
)
const (
UTNameSize = 16 /* see MAXLOGNAME in <sys/param.h> */
UTLineSize = 8
UTHostSize = 16
)
func HostInfo() (*HostInfoStat, error) {
@ -38,7 +46,7 @@ func HostInfo() (*HostInfoStat, error) {
ret.VirtualizationRole = role
}
values, err := doSysctrl("kern.boottime")
values, err := common.DoSysctrl("kern.boottime")
if err == nil {
// ex: { sec = 1392261637, usec = 627534 } Thu Feb 13 12:20:37 2014
v := strings.Replace(values[2], ",", "", 1)
@ -53,7 +61,7 @@ func HostInfo() (*HostInfoStat, error) {
}
func BootTime() (int64, error) {
values, err := doSysctrl("kern.boottime")
values, err := common.DoSysctrl("kern.boottime")
if err != nil {
return 0, err
}
@ -82,25 +90,26 @@ func Users() ([]UserStat, error) {
return ret, err
}
u := utmp{}
u := Utmp{}
entrySize := int(unsafe.Sizeof(u))
count := len(buf) / entrySize
for i := 0; i < count; i++ {
b := buf[i*entrySize : i*entrySize+entrySize]
var u utmp
var u Utmp
br := bytes.NewReader(b)
err := binary.Read(br, binary.LittleEndian, &u)
if err != nil {
if err != nil || u.Time == 0 {
continue
}
user := UserStat{
User: byteToString(u.UtName[:]),
Terminal: byteToString(u.UtLine[:]),
Host: byteToString(u.UtHost[:]),
Started: int(u.UtTime),
User: common.IntToString(u.Name[:]),
Terminal: common.IntToString(u.Line[:]),
Host: common.IntToString(u.Host[:]),
Started: int(u.Time),
}
ret = append(ret, user)
}

@ -0,0 +1,28 @@
// +build freebsd
// +build amd64
// Created by cgo -godefs - DO NOT EDIT
// cgo -godefs host/types_freebsd.go
package host
const (
sizeofPtr = 0x8
sizeofShort = 0x2
sizeofInt = 0x4
sizeofLong = 0x8
sizeofLongLong = 0x8
)
type (
_C_short int16
_C_int int32
_C_long int64
_C_long_long int64
)
type Utmp struct {
Line [8]int8
Name [16]int8
Host [16]int8
Time int32
}

@ -1,6 +1,6 @@
// +build linux
package gopsutil
package host
import (
"bytes"
@ -13,6 +13,8 @@ import (
"strings"
"syscall"
"unsafe"
common "github.com/shirou/gopsutil/common"
)
type LSB struct {
@ -89,10 +91,10 @@ func Users() ([]UserStat, error) {
continue
}
user := UserStat{
User: byteToString(u.UtUser[:]),
Terminal: byteToString(u.UtLine[:]),
Host: byteToString(u.UtHost[:]),
Started: int(u.UtTv.TvSec),
User: common.IntToString(u.User[:]),
Terminal: common.IntToString(u.Line[:]),
Host: common.IntToString(u.Host[:]),
Started: int(u.Tv.TvSec),
}
ret = append(ret, user)
}
@ -103,8 +105,8 @@ func Users() ([]UserStat, error) {
func getLSB() (*LSB, error) {
ret := &LSB{}
if pathExists("/etc/lsb-release") {
contents, err := readLines("/etc/lsb-release")
if common.PathExists("/etc/lsb-release") {
contents, err := common.ReadLines("/etc/lsb-release")
if err != nil {
return ret, err // return empty
}
@ -124,7 +126,7 @@ func getLSB() (*LSB, error) {
ret.Description = field[1]
}
}
} else if pathExists("/usr/bin/lsb_release") {
} else if common.PathExists("/usr/bin/lsb_release") {
out, err := exec.Command("/usr/bin/lsb_release").Output()
if err != nil {
return ret, err
@ -158,19 +160,19 @@ func GetPlatformInformation() (platform string, family string, version string, e
lsb = &LSB{}
}
if pathExists("/etc/oracle-release") {
if common.PathExists("/etc/oracle-release") {
platform = "oracle"
contents, err := readLines("/etc/oracle-release")
contents, err := common.ReadLines("/etc/oracle-release")
if err == nil {
version = getRedhatishVersion(contents)
}
} else if pathExists("/etc/enterprise-release") {
} else if common.PathExists("/etc/enterprise-release") {
platform = "oracle"
contents, err := readLines("/etc/enterprise-release")
contents, err := common.ReadLines("/etc/enterprise-release")
if err == nil {
version = getRedhatishVersion(contents)
}
} else if pathExists("/etc/debian_version") {
} else if common.PathExists("/etc/debian_version") {
if lsb.ID == "Ubuntu" {
platform = "ubuntu"
version = lsb.Release
@ -178,37 +180,37 @@ func GetPlatformInformation() (platform string, family string, version string, e
platform = "linuxmint"
version = lsb.Release
} else {
if pathExists("/usr/bin/raspi-config") {
if common.PathExists("/usr/bin/raspi-config") {
platform = "raspbian"
} else {
platform = "debian"
}
contents, err := readLines("/etc/debian_version")
contents, err := common.ReadLines("/etc/debian_version")
if err == nil {
version = contents[0]
}
}
} else if pathExists("/etc/redhat-release") {
contents, err := readLines("/etc/redhat-release")
} else if common.PathExists("/etc/redhat-release") {
contents, err := common.ReadLines("/etc/redhat-release")
if err == nil {
version = getRedhatishVersion(contents)
platform = getRedhatishPlatform(contents)
}
} else if pathExists("/etc/system-release") {
contents, err := readLines("/etc/system-release")
} else if common.PathExists("/etc/system-release") {
contents, err := common.ReadLines("/etc/system-release")
if err == nil {
version = getRedhatishVersion(contents)
platform = getRedhatishPlatform(contents)
}
} else if pathExists("/etc/gentoo-release") {
} else if common.PathExists("/etc/gentoo-release") {
platform = "gentoo"
contents, err := readLines("/etc/gentoo-release")
contents, err := common.ReadLines("/etc/gentoo-release")
if err == nil {
version = getRedhatishVersion(contents)
}
// TODO: suse detection
// TODO: slackware detecion
} else if pathExists("/etc/arch-release") {
} else if common.PathExists("/etc/arch-release") {
platform = "arch"
// TODO: exherbo detection
} else if lsb.ID == "RedHat" {
@ -278,78 +280,78 @@ func GetVirtualization() (string, string, error) {
var system string
var role string
if pathExists("/proc/xen") {
if common.PathExists("/proc/xen") {
system = "xen"
role = "guest" // assume guest
if pathExists("/proc/xen/capabilities") {
contents, err := readLines("/proc/xen/capabilities")
if common.PathExists("/proc/xen/capabilities") {
contents, err := common.ReadLines("/proc/xen/capabilities")
if err == nil {
if stringContains(contents, "control_d") {
if common.StringContains(contents, "control_d") {
role = "host"
}
}
}
}
if pathExists("/proc/modules") {
contents, err := readLines("/proc/modules")
if common.PathExists("/proc/modules") {
contents, err := common.ReadLines("/proc/modules")
if err == nil {
if stringContains(contents, "kvm") {
if common.StringContains(contents, "kvm") {
system = "kvm"
role = "host"
} else if stringContains(contents, "vboxdrv") {
} else if common.StringContains(contents, "vboxdrv") {
system = "vbox"
role = "host"
} else if stringContains(contents, "vboxguest") {
} else if common.StringContains(contents, "vboxguest") {
system = "vbox"
role = "guest"
}
}
}
if pathExists("/proc/cpuinfo") {
contents, err := readLines("/proc/cpuinfo")
if common.PathExists("/proc/cpuinfo") {
contents, err := common.ReadLines("/proc/cpuinfo")
if err == nil {
if stringContains(contents, "QEMU Virtual CPU") ||
stringContains(contents, "Common KVM processor") ||
stringContains(contents, "Common 32-bit KVM processor") {
if common.StringContains(contents, "QEMU Virtual CPU") ||
common.StringContains(contents, "Common KVM processor") ||
common.StringContains(contents, "Common 32-bit KVM processor") {
system = "kvm"
role = "guest"
}
}
}
if pathExists("/proc/bc/0") {
if common.PathExists("/proc/bc/0") {
system = "openvz"
role = "host"
} else if pathExists("/proc/vz") {
} else if common.PathExists("/proc/vz") {
system = "openvz"
role = "guest"
}
// not use dmidecode because it requires root
if pathExists("/proc/self/status") {
contents, err := readLines("/proc/self/status")
if common.PathExists("/proc/self/status") {
contents, err := common.ReadLines("/proc/self/status")
if err == nil {
if stringContains(contents, "s_context:") ||
stringContains(contents, "VxID:") {
if common.StringContains(contents, "s_context:") ||
common.StringContains(contents, "VxID:") {
system = "linux-vserver"
}
// TODO: guest or host
}
}
if pathExists("/proc/self/cgroup") {
contents, err := readLines("/proc/self/cgroup")
if common.PathExists("/proc/self/cgroup") {
contents, err := common.ReadLines("/proc/self/cgroup")
if err == nil {
if stringContains(contents, "lxc") ||
stringContains(contents, "docker") {
if common.StringContains(contents, "lxc") ||
common.StringContains(contents, "docker") {
system = "lxc"
role = "guest"
} else if pathExists("/usr/bin/lxc-version") { // TODO: which
} else if common.PathExists("/usr/bin/lxc-version") { // TODO: which
system = "lxc"
role = "host"
}

@ -0,0 +1,42 @@
// Created by cgo -godefs - DO NOT EDIT
// cgo -godefs types_linux.go
package host
const (
sizeofPtr = 0x8
sizeofShort = 0x2
sizeofInt = 0x4
sizeofLong = 0x8
sizeofLongLong = 0x8
)
type (
_C_short int16
_C_int int32
_C_long int64
_C_long_long int64
)
type utmp struct {
Type int16
Pad_cgo_0 [2]byte
Pid int32
Line [32]int8
Id [4]int8
User [32]int8
Host [256]int8
Exit exit_status
Session int32
Tv UtTv
Addr_v6 [4]int32
X__glibc_reserved [20]int8
}
type exit_status struct {
Termination int16
Exit int16
}
type UtTv struct {
TvSec int32
TvUsec int32
}

@ -0,0 +1,27 @@
// +build linux
// +build arm
package host
type exitStatus struct {
Etermination int16 // Process termination status.
Eexit int16 // Process exit status.
}
type timeval struct {
TvSec uint32 // Seconds.
TvUsec uint32 // Microseconds.
}
type utmp struct {
Type int16 // Type of login.
Pid int32 // Process ID of login process.
Line [32]byte // Devicename.
ID [4]byte // Inittab ID.
User [32]byte // Username.
Host [256]byte // Hostname for remote login.
Exit exitStatus // Exit status of a process marked
Session int32 // Session ID, used for windowing.
Tv timeval // Time entry was made.
AddrV6 [16]byte // Internet address of remote host.
Unused [20]byte // Reserved for future use. // original is 20
}

@ -1,6 +1,6 @@
// +build linux
package gopsutil
package host
import (
"testing"

@ -1,4 +1,4 @@
package gopsutil
package host
import (
"fmt"

@ -1,16 +1,19 @@
// +build windows
package gopsutil
package host
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 {

@ -0,0 +1,40 @@
// +build ignore
/*
Input to cgo -godefs.
*/
package host
/*
#define KERNEL
#include <sys/types.h>
#include <utmp.h>
enum {
sizeofPtr = sizeof(void*),
};
*/
import "C"
// Machine characteristics; for internal use.
const (
sizeofPtr = C.sizeofPtr
sizeofShort = C.sizeof_short
sizeofInt = C.sizeof_int
sizeofLong = C.sizeof_long
sizeofLongLong = C.sizeof_longlong
)
// Basic types
type (
_C_short C.short
_C_int C.int
_C_long C.long
_C_long_long C.longlong
)
type Utmp C.struct_utmp

@ -0,0 +1,45 @@
// +build ignore
/*
Input to cgo -godefs.
*/
package host
/*
#define KERNEL
#include <sys/types.h>
#include <utmp.h>
enum {
sizeofPtr = sizeof(void*),
};
*/
import "C"
// Machine characteristics; for internal use.
const (
sizeofPtr = C.sizeofPtr
sizeofShort = C.sizeof_short
sizeofInt = C.sizeof_int
sizeofLong = C.sizeof_long
sizeofLongLong = C.sizeof_longlong
)
// Basic types
type (
_C_short C.short
_C_int C.int
_C_long C.long
_C_long_long C.longlong
)
type utmp C.struct_utmp
type exit_status C.struct_exit_status
type UtTv struct {
TvSec int32
TvUsec int32
}

@ -1,17 +0,0 @@
// +build freebsd
// +build amd64
package gopsutil
const (
UTNameSize = 16 /* see MAXLOGNAME in <sys/param.h> */
UTLineSize = 8
UTHostSize = 16
)
type utmp struct {
UtLine [UTLineSize]byte
UtName [UTNameSize]byte
UtHost [UTHostSize]byte
UtTime int32
}

@ -1,27 +0,0 @@
// +build linux
// +build amd64
package gopsutil
type exitStatus struct {
Etermination int16 // Process termination status.
Eexit int16 // Process exit status.
}
type timeval struct {
TvSec uint32 // Seconds.
TvUsec uint32 // Microseconds.
}
type utmp struct {
UtType int16 // Type of login.
UtPid int32 // Process ID of login process.
UtLine [32]byte // Devicename.
UtID [4]byte // Inittab ID.
UtUser [32]byte // Username.
UtHost [256]byte // Hostname for remote login.
UtExit exitStatus // Exit status of a process marked
UtSession int32 // Session ID, used for windowing.
UtTv timeval // Time entry was made.
UtAddrV6 [16]byte // Internet address of remote host.
Unused [20]byte // Reserved for future use. // original is 20
}

@ -1,27 +0,0 @@
// +build linux
// +build arm
package gopsutil
type exitStatus struct {
Etermination int16 // Process termination status.
Eexit int16 // Process exit status.
}
type timeval struct {
TvSec uint32 // Seconds.
TvUsec uint32 // Microseconds.
}
type utmp struct {
UtType int16 // Type of login.
UtPid int32 // Process ID of login process.
UtLine [32]byte // Devicename.
UtID [4]byte // Inittab ID.
UtUser [32]byte // Username.
UtHost [256]byte // Hostname for remote login.
UtExit exitStatus // Exit status of a process marked
UtSession int32 // Session ID, used for windowing.
UtTv timeval // Time entry was made.
UtAddrV6 [16]byte // Internet address of remote host.
Unused [20]byte // Reserved for future use. // original is 20
}

@ -1,4 +1,4 @@
package gopsutil
package load
import (
"encoding/json"

@ -1,13 +1,15 @@
// +build darwin
package gopsutil
package load
import (
"strconv"
common "github.com/shirou/gopsutil/common"
)
func LoadAvg() (*LoadAvgStat, error) {
values, err := doSysctrl("vm.loadavg")
values, err := common.DoSysctrl("vm.loadavg")
if err != nil {
return nil, err
}

@ -1,13 +1,15 @@
// +build freebsd
package gopsutil
package load
import (
"strconv"
common "github.com/shirou/gopsutil/common"
)
func LoadAvg() (*LoadAvgStat, error) {
values, err := doSysctrl("vm.loadavg")
values, err := common.DoSysctrl("vm.loadavg")
if err != nil {
return nil, err
}

@ -1,6 +1,6 @@
// +build linux
package gopsutil
package load
import (
"io/ioutil"

@ -1,4 +1,4 @@
package gopsutil
package load
import (
"fmt"

@ -0,0 +1,13 @@
// +build windows
package load
import (
common "github.com/shirou/gopsutil/common"
)
func LoadAvg() (*LoadAvgStat, error) {
ret := LoadAvgStat{}
return &ret, common.NotImplementedError
}

@ -1,9 +0,0 @@
// +build windows
package gopsutil
func LoadAvg() (*LoadAvgStat, error) {
ret := LoadAvgStat{}
return &ret, NotImplementedError
}

@ -1,4 +1,4 @@
package gopsutil
package mem
import (
"encoding/json"

@ -1,11 +1,13 @@
// +build darwin
package gopsutil
package mem
import (
"os/exec"
"strconv"
"strings"
common "github.com/shirou/gopsutil/common"
)
func getPageSize() (uint64, error) {
@ -29,11 +31,11 @@ func VirtualMemory() (*VirtualMemoryStat, error) {
return nil, err
}
total, err := doSysctrl("hw.memsize")
total, err := common.DoSysctrl("hw.memsize")
if err != nil {
return nil, err
}
free, err := doSysctrl("vm.page_free_count")
free, err := common.DoSysctrl("vm.page_free_count")
if err != nil {
return nil, err
}
@ -68,7 +70,7 @@ func VirtualMemory() (*VirtualMemoryStat, error) {
func SwapMemory() (*SwapMemoryStat, error) {
var ret *SwapMemoryStat
swapUsage, err := doSysctrl("vm.swapusage")
swapUsage, err := common.DoSysctrl("vm.swapusage")
if err != nil {
return ret, err
}

@ -1,15 +1,17 @@
// +build freebsd
package gopsutil
package mem
import (
"os/exec"
"strconv"
"strings"
common "github.com/shirou/gopsutil/common"
)
func VirtualMemory() (*VirtualMemoryStat, error) {
pageSize, err := doSysctrl("vm.stats.vm.v_page_size")
pageSize, err := common.DoSysctrl("vm.stats.vm.v_page_size")
if err != nil {
return nil, err
}
@ -18,31 +20,31 @@ func VirtualMemory() (*VirtualMemoryStat, error) {
return nil, err
}
pageCount, err := doSysctrl("vm.stats.vm.v_page_count")
pageCount, err := common.DoSysctrl("vm.stats.vm.v_page_count")
if err != nil {
return nil, err
}
free, err := doSysctrl("vm.stats.vm.v_free_count")
free, err := common.DoSysctrl("vm.stats.vm.v_free_count")
if err != nil {
return nil, err
}
active, err := doSysctrl("vm.stats.vm.v_active_count")
active, err := common.DoSysctrl("vm.stats.vm.v_active_count")
if err != nil {
return nil, err
}
inactive, err := doSysctrl("vm.stats.vm.v_inactive_count")
inactive, err := common.DoSysctrl("vm.stats.vm.v_inactive_count")
if err != nil {
return nil, err
}
cache, err := doSysctrl("vm.stats.vm.v_cache_count")
cache, err := common.DoSysctrl("vm.stats.vm.v_cache_count")
if err != nil {
return nil, err
}
buffer, err := doSysctrl("vfs.bufspace")
buffer, err := common.DoSysctrl("vfs.bufspace")
if err != nil {
return nil, err
}
wired, err := doSysctrl("vm.stats.vm.v_wire_count")
wired, err := common.DoSysctrl("vm.stats.vm.v_wire_count")
if err != nil {
return nil, err
}

@ -1,16 +1,18 @@
// +build linux
package gopsutil
package mem
import (
"strconv"
"strings"
"syscall"
common "github.com/shirou/gopsutil/common"
)
func VirtualMemory() (*VirtualMemoryStat, error) {
filename := "/proc/meminfo"
lines, _ := readLines(filename)
lines, _ := common.ReadLines(filename)
ret := &VirtualMemoryStat{}
for _, line := range lines {
@ -65,7 +67,7 @@ func SwapMemory() (*SwapMemoryStat, error) {
} else {
ret.UsedPercent = 0
}
lines, _ := readLines("/proc/vmstat")
lines, _ := common.ReadLines("/proc/vmstat")
for _, l := range lines {
fields := strings.Fields(l)
if len(fields) < 2 {

@ -1,4 +1,4 @@
package gopsutil
package mem
import (
"fmt"

@ -1,14 +1,16 @@
// +build windows
package gopsutil
package mem
import (
"syscall"
"unsafe"
common "github.com/shirou/gopsutil/common"
)
var (
procGlobalMemoryStatusEx = modkernel32.NewProc("GlobalMemoryStatusEx")
procGlobalMemoryStatusEx = common.Modkernel32.NewProc("GlobalMemoryStatusEx")
)
type MEMORYSTATUSEX struct {

@ -0,0 +1,37 @@
DIRS="cpu disk docker host load mem net process"
GOOS=`uname | tr '[:upper:]' '[:lower:]'`
ARCH=`uname -m`
case $ARCH in
amd64)
GOARCH="amd64"
;;
x86_64)
GOARCH="amd64"
;;
i386)
GOARCH="386"
;;
i686)
GOARCH="386"
;;
arm)
GOARCH="arm"
;;
*)
echo "unknown arch: $ARCH"
exit 1
esac
for DIR in $DIRS
do
if [ -e ${DIR}/types_${GOOS}.go ]; then
echo "// +build $GOOS" > ${DIR}/${DIR}_${GOOS}_${GOARCH}.go
echo "// +build $GOARCH" >> ${DIR}/${DIR}_${GOOS}_${GOARCH}.go
go tool cgo -godefs ${DIR}/types_${GOOS}.go >> ${DIR}/${DIR}_${GOOS}_${GOARCH}.go
fi
done

@ -1,4 +1,4 @@
package gopsutil
package net
import (
"encoding/json"

@ -1,6 +1,6 @@
// +build darwin
package gopsutil
package net
import (
"os/exec"

@ -1,6 +1,6 @@
// +build freebsd
package gopsutil
package net
import (
"os/exec"

@ -1,15 +1,17 @@
// +build linux
package gopsutil
package net
import (
"strconv"
"strings"
common "github.com/shirou/gopsutil/common"
)
func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
filename := "/proc/net/dev"
lines, err := readLines(filename)
lines, err := common.ReadLines(filename)
if err != nil {
return nil, err
}

@ -1,4 +1,4 @@
package gopsutil
package net
import (
"fmt"

@ -1,12 +1,14 @@
// +build windows
package gopsutil
package net
import (
"net"
"os"
"syscall"
"unsafe"
common "github.com/shirou/gopsutil/common"
)
var (
@ -42,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,
}
@ -71,7 +73,7 @@ func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
func NetConnections(kind string) ([]NetConnectionStat, error) {
var ret []NetConnectionStat
return ret, NotImplementedError
return ret, common.NotImplementedError
}
// borrowed from src/pkg/net/interface_windows.go

@ -1,4 +1,4 @@
package gopsutil
package process
import (
"encoding/json"

@ -1,12 +1,26 @@
// +build darwin
package gopsutil
package process
import (
"bytes"
"encoding/binary"
"syscall"
"unsafe"
common "github.com/shirou/gopsutil/common"
cpu "github.com/shirou/gopsutil/cpu"
net "github.com/shirou/gopsutil/net"
)
// copied from sys/sysctl.h
const (
CTLKern = 1 // "high kernel": proc, limits
KernProc = 14 // struct: process entries
KernProcPID = 1 // by process id
KernProcProc = 8 // only return procs
KernProcAll = 0 // everything
KernProcPathname = 12 // path to executable
)
// MemoryInfoExStat is different between OSes
@ -31,14 +45,14 @@ func Pids() ([]int32, error) {
}
func (p *Process) Ppid() (int32, error) {
return 0, NotImplementedError
return 0, common.NotImplementedError
k, err := p.getKProc()
if err != nil {
return 0, err
}
return k.KiPpid, nil
return k.Proc.P_pid, nil
}
func (p *Process) Name() (string, error) {
k, err := p.getKProc()
@ -46,22 +60,22 @@ func (p *Process) Name() (string, error) {
return "", err
}
return string(k.KiComm[:]), nil
return common.IntToString(k.Proc.P_comm[:]), nil
}
func (p *Process) Exe() (string, error) {
return "", NotImplementedError
return "", common.NotImplementedError
}
func (p *Process) Cmdline() (string, error) {
return "", NotImplementedError
return "", common.NotImplementedError
}
func (p *Process) CreateTime() (int64, error) {
return 0, NotImplementedError
return 0, common.NotImplementedError
}
func (p *Process) Cwd() (string, error) {
return "", NotImplementedError
return "", common.NotImplementedError
}
func (p *Process) Parent() (*Process, error) {
return p, NotImplementedError
return p, common.NotImplementedError
}
func (p *Process) Status() (string, error) {
k, err := p.getKProc()
@ -69,7 +83,7 @@ func (p *Process) Status() (string, error) {
return "", err
}
return string(k.KiStat[:]), nil
return string(k.Proc.P_stat), nil // TODO
}
func (p *Process) Uids() ([]int32, error) {
k, err := p.getKProc()
@ -79,7 +93,7 @@ func (p *Process) Uids() ([]int32, error) {
uids := make([]int32, 0, 3)
uids = append(uids, int32(k.KiRuid), int32(k.KiUID), int32(k.KiSvuid))
uids = append(uids, int32(k.Eproc.Pcred.P_ruid), int32(k.Eproc.Ucred.Uid), int32(k.Eproc.Pcred.P_svuid))
return uids, nil
}
@ -90,7 +104,7 @@ func (p *Process) Gids() ([]int32, error) {
}
gids := make([]int32, 0, 3)
gids = append(gids, int32(k.KiRgid), int32(k.KiNgroups[0]), int32(k.KiSvuid))
gids = append(gids, int32(k.Eproc.Pcred.P_rgid), int32(k.Eproc.Ucred.Ngroups), int32(k.Eproc.Pcred.P_svgid))
return gids, nil
}
@ -100,7 +114,7 @@ func (p *Process) Terminal() (string, error) {
return "", err
}
ttyNr := uint64(k.KiTdev)
ttyNr := uint64(k.Eproc.Tdev)
termmap, err := getTerminalMap()
if err != nil {
@ -110,44 +124,48 @@ func (p *Process) Terminal() (string, error) {
return termmap[ttyNr], nil
}
func (p *Process) Nice() (int32, error) {
return 0, NotImplementedError
return 0, common.NotImplementedError
}
func (p *Process) IOnice() (int32, error) {
return 0, NotImplementedError
return 0, common.NotImplementedError
}
func (p *Process) Rlimit() ([]RlimitStat, error) {
var rlimit []RlimitStat
return rlimit, NotImplementedError
return rlimit, common.NotImplementedError
}
func (p *Process) IOCounters() (*IOCountersStat, error) {
return nil, NotImplementedError
return nil, common.NotImplementedError
}
func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) {
return nil, NotImplementedError
return nil, common.NotImplementedError
}
func (p *Process) NumFDs() (int32, error) {
return 0, NotImplementedError
return 0, common.NotImplementedError
}
func (p *Process) NumThreads() (int32, error) {
k, err := p.getKProc()
if err != nil {
return 0, err
}
return 0, common.NotImplementedError
/*
k, err := p.getKProc()
if err != nil {
return 0, err
}
return k.KiNumthreads, nil
return k.KiNumthreads, nil
*/
}
func (p *Process) Threads() (map[string]string, error) {
ret := make(map[string]string, 0)
return ret, NotImplementedError
return ret, common.NotImplementedError
}
func (p *Process) CPUTimes() (*CPUTimesStat, error) {
return nil, NotImplementedError
func (p *Process) CPUTimes() (*cpu.CPUTimesStat, error) {
return nil, common.NotImplementedError
}
func (p *Process) CPUPercent() (int32, error) {
return 0, NotImplementedError
return 0, common.NotImplementedError
}
func (p *Process) CPUAffinity() ([]int32, error) {
return nil, NotImplementedError
return nil, common.NotImplementedError
}
func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
k, err := p.getKProc()
@ -156,37 +174,37 @@ func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
}
ret := &MemoryInfoStat{
RSS: uint64(k.KiRssize),
VMS: uint64(k.KiSize),
RSS: uint64(k.Eproc.Xrssize),
VMS: uint64(k.Eproc.Xsize),
}
return ret, nil
}
func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
return nil, NotImplementedError
return nil, common.NotImplementedError
}
func (p *Process) MemoryPercent() (float32, error) {
return 0, NotImplementedError
return 0, common.NotImplementedError
}
func (p *Process) Children() ([]*Process, error) {
return nil, NotImplementedError
return nil, common.NotImplementedError
}
func (p *Process) OpenFiles() ([]OpenFilesStat, error) {
return nil, NotImplementedError
return nil, common.NotImplementedError
}
func (p *Process) Connections() ([]NetConnectionStat, error) {
return nil, NotImplementedError
func (p *Process) Connections() ([]net.NetConnectionStat, error) {
return nil, common.NotImplementedError
}
func (p *Process) IsRunning() (bool, error) {
return true, NotImplementedError
return true, common.NotImplementedError
}
func (p *Process) MemoryMaps(grouped bool) (*[]MemoryMapsStat, error) {
var ret []MemoryMapsStat
return &ret, NotImplementedError
return &ret, common.NotImplementedError
}
func copyParams(k *KinfoProc, p *Process) error {
@ -197,7 +215,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
@ -209,13 +227,14 @@ 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)
if err != nil {
continue
}
p, err := NewProcess(int32(k.KiPid))
p, err := NewProcess(int32(k.Proc.P_pid))
if err != nil {
continue
}
@ -230,6 +249,7 @@ func processes() ([]Process, error) {
func parseKinfoProc(buf []byte) (KinfoProc, error) {
var k KinfoProc
br := bytes.NewReader(buf)
err := binary.Read(br, binary.LittleEndian, &k)
if err != nil {
return k, err

@ -0,0 +1,236 @@
// +build darwin
// +build amd64
// Created by cgo -godefs - DO NOT EDIT
// cgo -godefs process/types_darwin.go
package process
const (
sizeofPtr = 0x8
sizeofShort = 0x2
sizeofInt = 0x4
sizeofLong = 0x8
sizeofLongLong = 0x8
)
type (
_C_short int16
_C_int int32
_C_long int64
_C_long_long int64
)
type Timespec struct {
Sec int64
Nsec int64
}
type Timeval struct {
Sec int64
Usec int32
Pad_cgo_0 [4]byte
}
type Rusage struct {
Utime Timeval
Stime Timeval
Maxrss int64
Ixrss int64
Idrss int64
Isrss int64
Minflt int64
Majflt int64
Nswap int64
Inblock int64
Oublock int64
Msgsnd int64
Msgrcv int64
Nsignals int64
Nvcsw int64
Nivcsw int64
}
type Rlimit struct {
Cur uint64
Max uint64
}
type UGid_t uint32
type KinfoProc struct {
Proc ExternProc
Eproc Eproc
}
type Eproc struct {
Paddr *Proc
Sess *Session
Pcred Upcred
Ucred Uucred
Pad_cgo_0 [4]byte
Vm Vmspace
Ppid int32
Pgid int32
Jobc int16
Pad_cgo_1 [2]byte
Tdev int32
Tpgid int32
Pad_cgo_2 [4]byte
Tsess *Session
Wmesg [8]int8
Xsize int32
Xrssize int16
Xccount int16
Xswrss int16
Pad_cgo_3 [2]byte
Flag int32
Login [12]int8
Spare [4]int32
Pad_cgo_4 [4]byte
}
type Proc struct{}
type Session struct{}
type ucred struct {
Link UcredQueue
Ref uint64
Posix Posix_cred
Label *Label
Audit Au_session
}
type Uucred struct {
Ref int32
Uid uint32
Ngroups int16
Pad_cgo_0 [2]byte
Groups [16]uint32
}
type Upcred struct {
Pc_lock [72]int8
Pc_ucred *ucred
P_ruid uint32
P_svuid uint32
P_rgid uint32
P_svgid uint32
P_refcnt int32
Pad_cgo_0 [4]byte
}
type Vmspace struct {
Dummy int32
Pad_cgo_0 [4]byte
Dummy2 *int8
Dummy3 [5]int32
Pad_cgo_1 [4]byte
Dummy4 [3]*int8
}
type Sigacts struct{}
type ExternProc struct {
P_un [16]byte
P_vmspace *Vmspace
P_sigacts *Sigacts
P_flag int32
P_stat int8
Pad_cgo_0 [3]byte
P_pid int32
P_oppid int32
P_dupfd int32
Pad_cgo_1 [4]byte
User_stack *int8
Exit_thread *byte
P_debugger int32
Sigwait int32
P_estcpu uint32
P_cpticks int32
P_pctcpu uint32
Pad_cgo_2 [4]byte
P_wchan *byte
P_wmesg *int8
P_swtime uint32
P_slptime uint32
P_realtimer Itimerval
P_rtime Timeval
P_uticks uint64
P_sticks uint64
P_iticks uint64
P_traceflag int32
Pad_cgo_3 [4]byte
P_tracep *Vnode
P_siglist int32
Pad_cgo_4 [4]byte
P_textvp *Vnode
P_holdcnt int32
P_sigmask uint32
P_sigignore uint32
P_sigcatch uint32
P_priority uint8
P_usrpri uint8
P_nice int8
P_comm [17]int8
Pad_cgo_5 [4]byte
P_pgrp *Pgrp
P_addr *UserStruct
P_xstat uint16
P_acflag uint16
Pad_cgo_6 [4]byte
P_ru *Rusage
}
type Itimerval struct {
Interval Timeval
Value Timeval
}
type Vnode struct{}
type Pgrp struct{}
type UserStruct struct{}
type Au_session struct {
Aia_p *AuditinfoAddr
Mask AuMask
}
type Posix_cred struct {
Uid uint32
Ruid uint32
Svuid uint32
Ngroups int16
Pad_cgo_0 [2]byte
Groups [16]uint32
Rgid uint32
Svgid uint32
Gmuid uint32
Flags int32
}
type Label struct{}
type AuditinfoAddr struct {
Auid uint32
Mask AuMask
Termid AuTidAddr
Asid int32
Flags uint64
}
type AuMask struct {
Success uint32
Failure uint32
}
type AuTidAddr struct {
Port int32
Type uint32
Addr [4]uint32
}
type UcredQueue struct {
Next *ucred
Prev **ucred
}

@ -1,12 +1,16 @@
// +build freebsd
package gopsutil
package process
import (
"bytes"
"encoding/binary"
"syscall"
"unsafe"
common "github.com/shirou/gopsutil/common"
cpu "github.com/shirou/gopsutil/cpu"
net "github.com/shirou/gopsutil/net"
)
// MemoryInfoExStat is different between OSes
@ -47,19 +51,19 @@ func (p *Process) Name() (string, error) {
return string(k.KiComm[:]), nil
}
func (p *Process) Exe() (string, error) {
return "", NotImplementedError
return "", common.NotImplementedError
}
func (p *Process) Cmdline() (string, error) {
return "", NotImplementedError
return "", common.NotImplementedError
}
func (p *Process) CreateTime() (int64, error) {
return 0, NotImplementedError
return 0, common.NotImplementedError
}
func (p *Process) Cwd() (string, error) {
return "", NotImplementedError
return "", common.NotImplementedError
}
func (p *Process) Parent() (*Process, error) {
return p, NotImplementedError
return p, common.NotImplementedError
}
func (p *Process) Status() (string, error) {
k, err := p.getKProc()
@ -108,23 +112,23 @@ func (p *Process) Terminal() (string, error) {
return termmap[ttyNr], nil
}
func (p *Process) Nice() (int32, error) {
return 0, NotImplementedError
return 0, common.NotImplementedError
}
func (p *Process) IOnice() (int32, error) {
return 0, NotImplementedError
return 0, common.NotImplementedError
}
func (p *Process) Rlimit() ([]RlimitStat, error) {
var rlimit []RlimitStat
return rlimit, NotImplementedError
return rlimit, common.NotImplementedError
}
func (p *Process) IOCounters() (*IOCountersStat, error) {
return nil, NotImplementedError
return nil, common.NotImplementedError
}
func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) {
return nil, NotImplementedError
return nil, common.NotImplementedError
}
func (p *Process) NumFDs() (int32, error) {
return 0, NotImplementedError
return 0, common.NotImplementedError
}
func (p *Process) NumThreads() (int32, error) {
k, err := p.getKProc()
@ -136,16 +140,16 @@ func (p *Process) NumThreads() (int32, error) {
}
func (p *Process) Threads() (map[string]string, error) {
ret := make(map[string]string, 0)
return ret, NotImplementedError
return ret, common.NotImplementedError
}
func (p *Process) CPUTimes() (*CPUTimesStat, error) {
return nil, NotImplementedError
func (p *Process) CPUTimes() (*cpu.CPUTimesStat, error) {
return nil, common.NotImplementedError
}
func (p *Process) CPUPercent() (int32, error) {
return 0, NotImplementedError
return 0, common.NotImplementedError
}
func (p *Process) CPUAffinity() ([]int32, error) {
return nil, NotImplementedError
return nil, common.NotImplementedError
}
func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
k, err := p.getKProc()
@ -161,30 +165,30 @@ func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
return ret, nil
}
func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
return nil, NotImplementedError
return nil, common.NotImplementedError
}
func (p *Process) MemoryPercent() (float32, error) {
return 0, NotImplementedError
return 0, common.NotImplementedError
}
func (p *Process) Children() ([]*Process, error) {
return nil, NotImplementedError
return nil, common.NotImplementedError
}
func (p *Process) OpenFiles() ([]OpenFilesStat, error) {
return nil, NotImplementedError
return nil, common.NotImplementedError
}
func (p *Process) Connections() ([]NetConnectionStat, error) {
return nil, NotImplementedError
func (p *Process) Connections() ([]net.NetConnectionStat, error) {
return nil, common.NotImplementedError
}
func (p *Process) IsRunning() (bool, error) {
return true, NotImplementedError
return true, common.NotImplementedError
}
func (p *Process) MemoryMaps(grouped bool) (*[]MemoryMapsStat, error) {
var ret []MemoryMapsStat
return &ret, NotImplementedError
return &ret, common.NotImplementedError
}
func copyParams(k *KinfoProc, p *Process) error {

@ -1,7 +1,7 @@
// +build freebsd
// +build amd64
package gopsutil
package process
// copied from sys/sysctl.h
const (

@ -1,6 +1,6 @@
// +build linux
package gopsutil
package process
import (
"encoding/json"
@ -10,6 +10,11 @@ import (
"strconv"
"strings"
"syscall"
common "github.com/shirou/gopsutil/common"
cpu "github.com/shirou/gopsutil/cpu"
host "github.com/shirou/gopsutil/host"
net "github.com/shirou/gopsutil/net"
)
const (
@ -89,7 +94,7 @@ func (p *Process) Cwd() (string, error) {
return p.fillFromCwd()
}
func (p *Process) Parent() (*Process, error) {
return nil, NotImplementedError
return nil, common.NotImplementedError
}
func (p *Process) Status() (string, error) {
return p.status, nil
@ -115,10 +120,10 @@ func (p *Process) Nice() (int32, error) {
return nice, nil
}
func (p *Process) IOnice() (int32, error) {
return 0, NotImplementedError
return 0, common.NotImplementedError
}
func (p *Process) Rlimit() ([]RlimitStat, error) {
return nil, NotImplementedError
return nil, common.NotImplementedError
}
func (p *Process) IOCounters() (*IOCountersStat, error) {
return p.fillFromIO()
@ -127,7 +132,7 @@ func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) {
return p.numCtxSwitches, nil
}
func (p *Process) NumFDs() (int32, error) {
return 0, NotImplementedError
return 0, common.NotImplementedError
}
func (p *Process) NumThreads() (int32, error) {
return p.numThreads, nil
@ -136,7 +141,7 @@ func (p *Process) Threads() (map[string]string, error) {
ret := make(map[string]string, 0)
return ret, nil
}
func (p *Process) CPUTimes() (*CPUTimesStat, error) {
func (p *Process) CPUTimes() (*cpu.CPUTimesStat, error) {
_, _, cpuTimes, _, _, err := p.fillFromStat()
if err != nil {
return nil, err
@ -144,10 +149,10 @@ func (p *Process) CPUTimes() (*CPUTimesStat, error) {
return cpuTimes, nil
}
func (p *Process) CPUPercent() (int32, error) {
return 0, NotImplementedError
return 0, common.NotImplementedError
}
func (p *Process) CPUAffinity() ([]int32, error) {
return nil, NotImplementedError
return nil, common.NotImplementedError
}
func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
return p.memInfo, nil
@ -160,23 +165,23 @@ func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
return memInfoEx, nil
}
func (p *Process) MemoryPercent() (float32, error) {
return 0, NotImplementedError
return 0, common.NotImplementedError
}
func (p *Process) Children() ([]*Process, error) {
return nil, NotImplementedError
return nil, common.NotImplementedError
}
func (p *Process) OpenFiles() ([]OpenFilesStat, error) {
return nil, NotImplementedError
return nil, common.NotImplementedError
}
func (p *Process) Connections() ([]NetConnectionStat, error) {
return nil, NotImplementedError
func (p *Process) Connections() ([]net.NetConnectionStat, error) {
return nil, common.NotImplementedError
}
func (p *Process) IsRunning() (bool, error) {
return true, NotImplementedError
return true, common.NotImplementedError
}
// MemoryMaps get memory maps from /proc/(pid)/smaps
@ -513,7 +518,7 @@ func (p *Process) fillFromStatus() error {
return nil
}
func (p *Process) fillFromStat() (string, int32, *CPUTimesStat, int64, int32, error) {
func (p *Process) fillFromStat() (string, int32, *cpu.CPUTimesStat, int64, int32, error) {
pid := p.Pid
statPath := filepath.Join("/", "proc", strconv.Itoa(int(pid)), "stat")
contents, err := ioutil.ReadFile(statPath)
@ -545,13 +550,13 @@ func (p *Process) fillFromStat() (string, int32, *CPUTimesStat, int64, int32, er
return "", 0, nil, 0, 0, err
}
cpuTimes := &CPUTimesStat{
cpuTimes := &cpu.CPUTimesStat{
CPU: "cpu",
User: float32(utime * (1000 / ClockTicks)),
System: float32(stime * (1000 / ClockTicks)),
}
bootTime, _ := BootTime()
bootTime, _ := host.BootTime()
t, err := strconv.ParseUint(fields[21], 10, 64)
if err != nil {
return "", 0, nil, 0, 0, err

@ -1,7 +1,7 @@
// +build linux
// +build amd64
package gopsutil
package process
const (
ClockTicks = 100 // C.sysconf(C._SC_CLK_TCK)

@ -1,7 +1,7 @@
// +build linux
// +build arm
package gopsutil
package process
const (
ClockTicks = 100 // C.sysconf(C._SC_CLK_TCK)

@ -1,6 +1,6 @@
// +build linux freebsd darwin
package gopsutil
package process
import (
"os"

@ -1,6 +1,6 @@
// +build linux freebsd
package gopsutil
package process
import (
"os"

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

@ -1,6 +1,6 @@
// +build windows
package gopsutil
package process
import (
"errors"
@ -8,6 +8,10 @@ import (
"unsafe"
"github.com/shirou/w32"
common "github.com/shirou/gopsutil/common"
cpu "github.com/shirou/gopsutil/cpu"
net "github.com/shirou/gopsutil/net"
)
const (
@ -61,7 +65,7 @@ func (p *Process) Ppid() (int32, error) {
}
func (p *Process) Name() (string, error) {
name := ""
return name, NotImplementedError
return name, common.NotImplementedError
}
func (p *Process) Exe() (string, error) {
_, _, ret, err := p.getFromSnapProcess(p.Pid)
@ -71,51 +75,51 @@ func (p *Process) Exe() (string, error) {
return ret, nil
}
func (p *Process) Cmdline() (string, error) {
return "", NotImplementedError
return "", common.NotImplementedError
}
func (p *Process) Cwd() (string, error) {
return "", NotImplementedError
return "", common.NotImplementedError
}
func (p *Process) Parent() (*Process, error) {
return p, NotImplementedError
return p, common.NotImplementedError
}
func (p *Process) Status() (string, error) {
return "", NotImplementedError
return "", common.NotImplementedError
}
func (p *Process) Username() (string, error) {
return "", NotImplementedError
return "", common.NotImplementedError
}
func (p *Process) Uids() ([]int32, error) {
var uids []int32
return uids, NotImplementedError
return uids, common.NotImplementedError
}
func (p *Process) Gids() ([]int32, error) {
var gids []int32
return gids, NotImplementedError
return gids, common.NotImplementedError
}
func (p *Process) Terminal() (string, error) {
return "", NotImplementedError
return "", common.NotImplementedError
}
func (p *Process) Nice() (int32, error) {
return 0, NotImplementedError
return 0, common.NotImplementedError
}
func (p *Process) IOnice() (int32, error) {
return 0, NotImplementedError
return 0, common.NotImplementedError
}
func (p *Process) Rlimit() ([]RlimitStat, error) {
var rlimit []RlimitStat
return rlimit, NotImplementedError
return rlimit, common.NotImplementedError
}
func (p *Process) IOCounters() (*IOCountersStat, error) {
return nil, NotImplementedError
return nil, common.NotImplementedError
}
func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) {
return nil, NotImplementedError
return nil, common.NotImplementedError
}
func (p *Process) NumFDs() (int32, error) {
return 0, NotImplementedError
return 0, common.NotImplementedError
}
func (p *Process) NumThreads() (int32, error) {
_, ret, _, err := p.getFromSnapProcess(p.Pid)
@ -126,46 +130,46 @@ func (p *Process) NumThreads() (int32, error) {
}
func (p *Process) Threads() (map[string]string, error) {
ret := make(map[string]string, 0)
return ret, NotImplementedError
return ret, common.NotImplementedError
}
func (p *Process) CPUTimes() (*CPUTimesStat, error) {
return nil, NotImplementedError
func (p *Process) CPUTimes() (*cpu.CPUTimesStat, error) {
return nil, common.NotImplementedError
}
func (p *Process) CPUPercent() (int32, error) {
return 0, NotImplementedError
return 0, common.NotImplementedError
}
func (p *Process) CPUAffinity() ([]int32, error) {
return nil, NotImplementedError
return nil, common.NotImplementedError
}
func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
return nil, NotImplementedError
return nil, common.NotImplementedError
}
func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
return nil, NotImplementedError
return nil, common.NotImplementedError
}
func (p *Process) MemoryPercent() (float32, error) {
return 0, NotImplementedError
return 0, common.NotImplementedError
}
func (p *Process) Children() ([]*Process, error) {
return nil, NotImplementedError
return nil, common.NotImplementedError
}
func (p *Process) OpenFiles() ([]OpenFilesStat, error) {
return nil, NotImplementedError
return nil, common.NotImplementedError
}
func (p *Process) Connections() ([]NetConnectionStat, error) {
return nil, NotImplementedError
func (p *Process) Connections() ([]net.NetConnectionStat, error) {
return nil, common.NotImplementedError
}
func (p *Process) IsRunning() (bool, error) {
return true, NotImplementedError
return true, common.NotImplementedError
}
func (p *Process) MemoryMaps(grouped bool) (*[]MemoryMapsStat, error) {
ret := make([]MemoryMapsStat, 0)
return &ret, NotImplementedError
return &ret, common.NotImplementedError
}
func NewProcess(pid int32) (*Process, error) {
@ -175,20 +179,20 @@ func NewProcess(pid int32) (*Process, error) {
}
func (p *Process) SendSignal(sig syscall.Signal) error {
return NotImplementedError
return common.NotImplementedError
}
func (p *Process) Suspend() error {
return NotImplementedError
return common.NotImplementedError
}
func (p *Process) Resume() error {
return NotImplementedError
return common.NotImplementedError
}
func (p *Process) Terminate() error {
return NotImplementedError
return common.NotImplementedError
}
func (p *Process) Kill() error {
return NotImplementedError
return common.NotImplementedError
}
func (p *Process) getFromSnapProcess(pid int32) (int32, int32, string, error) {
@ -247,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)),

@ -0,0 +1,157 @@
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build ignore
/*
Input to cgo -godefs.
*/
// +godefs map struct_in_addr [4]byte /* in_addr */
// +godefs map struct_in6_addr [16]byte /* in6_addr */
// +godefs map struct_ [16]byte /* in6_addr */
package process
/*
#define __DARWIN_UNIX03 0
#define KERNEL
#define _DARWIN_USE_64_BIT_INODE
#include <dirent.h>
#include <fcntl.h>
#include <signal.h>
#include <termios.h>
#include <unistd.h>
#include <mach/mach.h>
#include <mach/message.h>
#include <sys/event.h>
#include <sys/mman.h>
#include <sys/mount.h>
#include <sys/param.h>
#include <sys/ptrace.h>
#include <sys/resource.h>
#include <sys/select.h>
#include <sys/signal.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/un.h>
#include <net/bpf.h>
#include <net/if_dl.h>
#include <net/if_var.h>
#include <net/route.h>
#include <netinet/in.h>
#include <sys/sysctl.h>
#include <sys/ucred.h>
#include <sys/proc.h>
#include <sys/time.h>
#include <sys/_types/_timeval.h>
#include <sys/appleapiopts.h>
#include <sys/cdefs.h>
#include <sys/param.h>
#include <bsm/audit.h>
#include <sys/queue.h>
enum {
sizeofPtr = sizeof(void*),
};
union sockaddr_all {
struct sockaddr s1; // this one gets used for fields
struct sockaddr_in s2; // these pad it out
struct sockaddr_in6 s3;
struct sockaddr_un s4;
struct sockaddr_dl s5;
};
struct sockaddr_any {
struct sockaddr addr;
char pad[sizeof(union sockaddr_all) - sizeof(struct sockaddr)];
};
struct ucred_queue {
struct ucred *tqe_next;
struct ucred **tqe_prev;
TRACEBUF
};
*/
import "C"
// Machine characteristics; for internal use.
const (
sizeofPtr = C.sizeofPtr
sizeofShort = C.sizeof_short
sizeofInt = C.sizeof_int
sizeofLong = C.sizeof_long
sizeofLongLong = C.sizeof_longlong
)
// Basic types
type (
_C_short C.short
_C_int C.int
_C_long C.long
_C_long_long C.longlong
)
// Time
type Timespec C.struct_timespec
type Timeval C.struct_timeval
// Processes
type Rusage C.struct_rusage
type Rlimit C.struct_rlimit
type UGid_t C.gid_t
type KinfoProc C.struct_kinfo_proc
type Eproc C.struct_eproc
type Proc C.struct_proc
type Session C.struct_session
type ucred C.struct_ucred
type Uucred C.struct__ucred
type Upcred C.struct__pcred
type Vmspace C.struct_vmspace
type Sigacts C.struct_sigacts
type ExternProc C.struct_extern_proc
type Itimerval C.struct_itimerval
type Vnode C.struct_vnode
type Pgrp C.struct_pgrp
type UserStruct C.struct_user
type Au_session C.struct_au_session
type Posix_cred C.struct_posix_cred
type Label C.struct_label
type AuditinfoAddr C.struct_auditinfo_addr
type AuMask C.struct_au_mask
type AuTidAddr C.struct_au_tid_addr
// TAILQ(ucred)
type UcredQueue C.struct_ucred_queue

@ -1,96 +0,0 @@
// +build darwin
// +build amd64
package gopsutil
// copied from sys/sysctl.h
const (
CTLKern = 1 // "high kernel": proc, limits
KernProc = 14 // struct: process entries
KernProcPID = 1 // by process id
KernProcProc = 8 // only return procs
KernProcPathname = 12 // path to executable
)
// copied from sys/user.h
type KinfoProc struct {
KiStructsize int32
KiLayout int32
KiArgs int64
KiPaddr int64
KiAddr int64
KiTracep int64
KiTextvp int64
KiFd int64
KiVmspace int64
KiWchan int64
KiPid int32
KiPpid int32
KiPgid int32
KiTpgid int32
KiSid int32
KiTsid int32
KiJobc [2]byte
KiSpareShort1 [2]byte
KiTdev int32
KiSiglist [16]byte
KiSigmask [16]byte
KiSigignore [16]byte
KiSigcatch [16]byte
KiUID int32
KiRuid int32
KiSvuid int32
KiRgid int32
KiSvgid int32
KiNgroups [2]byte
KiSpareShort2 [2]byte
KiGroups [64]byte
KiSize int64
KiRssize int64
KiSwrss int64
KiTsize int64
KiDsize int64
KiSsize int64
KiXstat [2]byte
KiAcflag [2]byte
KiPctcpu int32
KiEstcpu int32
KiSlptime int32
KiSwtime int32
KiCow int32
KiRuntime int64
KiStart [16]byte
KiChildtime [16]byte
KiFlag int64
KiKflag int64
KiTraceflag int32
KiStat [1]byte
KiNice [1]byte
KiLock [1]byte
KiRqindex [1]byte
KiOncpu [1]byte
KiLastcpu [1]byte
KiOcomm [17]byte
KiWmesg [9]byte
KiLogin [18]byte
KiLockname [9]byte
KiComm [20]byte
KiEmul [17]byte
KiSparestrings [68]byte
KiSpareints [36]byte
KiCrFlags int32
KiJid int32
KiNumthreads int32
KiTid int32
KiPri int32
KiRusage [144]byte
KiRusageCh [144]byte
KiPcb int64
KiKstack int64
KiUdata int64
KiTdaddr int64
KiSpareptrs [48]byte
KiSpareint64s [96]byte
KiSflag int64
KiTdflags int64
}
Loading…
Cancel
Save