1
0
mirror of https://github.com/shirou/gopsutil.git synced 2025-05-01 13:48:52 +08:00

move subdirectories. refer to issue #24

This commit is contained in:
Shirou WAKAYAMA 2014-11-27 10:18:15 +09:00
parent 2f128c3955
commit a4671fcc2a
60 changed files with 184 additions and 138 deletions

View File

@ -52,7 +52,7 @@ func readLinesOffsetN(filename string, offset uint, n int) ([]string, error) {
return ret, nil return ret, nil
} }
func byteToString(orig []byte) string { func ByteToString(orig []byte) string {
n := -1 n := -1
l := -1 l := -1
for i, b := range orig { for i, b := range orig {

View File

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

View File

@ -7,7 +7,7 @@ import (
"strings" "strings"
) )
func doSysctrl(mib string) ([]string, error) { func DoSysctrl(mib string) ([]string, error) {
out, err := exec.Command("/sbin/sysctl", "-n", mib).Output() out, err := exec.Command("/sbin/sysctl", "-n", mib).Output()
if err != nil { if err != nil {
return []string{}, err return []string{}, err

View File

@ -21,7 +21,7 @@ type FILETIME struct {
} }
// borrowed from net/interface_windows.go // borrowed from net/interface_windows.go
func bytePtrToString(p *uint8) string { func BytePtrToString(p *uint8) string {
a := (*[10000]uint8)(unsafe.Pointer(p)) a := (*[10000]uint8)(unsafe.Pointer(p))
i := 0 i := 0
for a[i] != 0 { for a[i] != 0 {

View File

View File

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

View File

@ -7,6 +7,8 @@ import (
"regexp" "regexp"
"strconv" "strconv"
"strings" "strings"
common "github.com/shirou/gopsutil/common"
) )
// sys/resource.h // sys/resource.h
@ -37,7 +39,7 @@ func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
ncpu = 1 ncpu = 1
} }
cpuTimes, err := doSysctrl(sysctlCall) cpuTimes, err := common.DoSysctrl(sysctlCall)
if err != nil { if err != nil {
return ret, err return ret, err
} }

View File

@ -2,11 +2,15 @@
package gopsutil package gopsutil
import (
common "github.com/shirou/gopsutil/common"
)
func DiskPartitions(all bool) ([]DiskPartitionStat, error) { func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
return nil, NotImplementedError return nil, common.NotImplementedError
} }
func DiskIOCounters() (map[string]DiskIOCountersStat, error) { func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
return nil, NotImplementedError return nil, common.NotImplementedError
} }

View File

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

View File

@ -6,6 +6,8 @@ import (
"bytes" "bytes"
"syscall" "syscall"
"unsafe" "unsafe"
common "github.com/shirou/gopsutil/common"
) )
var ( var (
@ -113,5 +115,5 @@ func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
func DiskIOCounters() (map[string]DiskIOCountersStat, error) { func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
ret := make(map[string]DiskIOCountersStat, 0) ret := make(map[string]DiskIOCountersStat, 0)
return ret, NotImplementedError return ret, common.NotImplementedError
} }

View File

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

View File

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

View File

@ -13,6 +13,8 @@ import (
"strings" "strings"
"syscall" "syscall"
"unsafe" "unsafe"
common "github.com/shirou/gopsutil/common"
) )
type LSB struct { type LSB struct {
@ -89,9 +91,9 @@ func Users() ([]UserStat, error) {
continue continue
} }
user := UserStat{ user := UserStat{
User: byteToString(u.UtUser[:]), User: common.ByteToString(u.UtUser[:]),
Terminal: byteToString(u.UtLine[:]), Terminal: common.ByteToString(u.UtLine[:]),
Host: byteToString(u.UtHost[:]), Host: common.ByteToString(u.UtHost[:]),
Started: int(u.UtTv.TvSec), Started: int(u.UtTv.TvSec),
} }
ret = append(ret, user) ret = append(ret, user)

View File

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

View File

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

View File

@ -2,8 +2,12 @@
package gopsutil package gopsutil
import (
common "github.com/shirou/gopsutil/common"
)
func LoadAvg() (*LoadAvgStat, error) { func LoadAvg() (*LoadAvgStat, error) {
ret := LoadAvgStat{} ret := LoadAvgStat{}
return &ret, NotImplementedError return &ret, common.NotImplementedError
} }

View File

View File

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

View File

@ -6,10 +6,12 @@ import (
"os/exec" "os/exec"
"strconv" "strconv"
"strings" "strings"
common "github.com/shirou/gopsutil/common"
) )
func VirtualMemory() (*VirtualMemoryStat, error) { 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 { if err != nil {
return nil, err return nil, err
} }
@ -18,31 +20,31 @@ func VirtualMemory() (*VirtualMemoryStat, error) {
return nil, err 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 { if err != nil {
return nil, err 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 { if err != nil {
return nil, err 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 { if err != nil {
return nil, err 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 { if err != nil {
return nil, err 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 { if err != nil {
return nil, err return nil, err
} }
buffer, err := doSysctrl("vfs.bufspace") buffer, err := common.DoSysctrl("vfs.bufspace")
if err != nil { if err != nil {
return nil, err 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 { if err != nil {
return nil, err return nil, err
} }

View File

View File

@ -7,6 +7,8 @@ import (
"os" "os"
"syscall" "syscall"
"unsafe" "unsafe"
common "github.com/shirou/gopsutil/common"
) )
var ( var (
@ -71,7 +73,7 @@ func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
func NetConnections(kind string) ([]NetConnectionStat, error) { func NetConnections(kind string) ([]NetConnectionStat, error) {
var ret []NetConnectionStat var ret []NetConnectionStat
return ret, NotImplementedError return ret, common.NotImplementedError
} }
// borrowed from src/pkg/net/interface_windows.go // borrowed from src/pkg/net/interface_windows.go

View File

@ -7,6 +7,10 @@ import (
"encoding/binary" "encoding/binary"
"syscall" "syscall"
"unsafe" "unsafe"
common "github.com/shirou/gopsutil/common"
cpu "github.com/shirou/gopsutil/cpu"
net "github.com/shirou/gopsutil/net"
) )
// MemoryInfoExStat is different between OSes // MemoryInfoExStat is different between OSes
@ -31,7 +35,7 @@ func Pids() ([]int32, error) {
} }
func (p *Process) Ppid() (int32, error) { func (p *Process) Ppid() (int32, error) {
return 0, NotImplementedError return 0, common.NotImplementedError
k, err := p.getKProc() k, err := p.getKProc()
if err != nil { if err != nil {
@ -49,19 +53,19 @@ func (p *Process) Name() (string, error) {
return string(k.KiComm[:]), nil return string(k.KiComm[:]), nil
} }
func (p *Process) Exe() (string, error) { func (p *Process) Exe() (string, error) {
return "", NotImplementedError return "", common.NotImplementedError
} }
func (p *Process) Cmdline() (string, error) { func (p *Process) Cmdline() (string, error) {
return "", NotImplementedError return "", common.NotImplementedError
} }
func (p *Process) CreateTime() (int64, error) { func (p *Process) CreateTime() (int64, error) {
return 0, NotImplementedError return 0, common.NotImplementedError
} }
func (p *Process) Cwd() (string, error) { func (p *Process) Cwd() (string, error) {
return "", NotImplementedError return "", common.NotImplementedError
} }
func (p *Process) Parent() (*Process, error) { func (p *Process) Parent() (*Process, error) {
return p, NotImplementedError return p, common.NotImplementedError
} }
func (p *Process) Status() (string, error) { func (p *Process) Status() (string, error) {
k, err := p.getKProc() k, err := p.getKProc()
@ -110,23 +114,23 @@ func (p *Process) Terminal() (string, error) {
return termmap[ttyNr], nil return termmap[ttyNr], nil
} }
func (p *Process) Nice() (int32, error) { func (p *Process) Nice() (int32, error) {
return 0, NotImplementedError return 0, common.NotImplementedError
} }
func (p *Process) IOnice() (int32, error) { func (p *Process) IOnice() (int32, error) {
return 0, NotImplementedError return 0, common.NotImplementedError
} }
func (p *Process) Rlimit() ([]RlimitStat, error) { func (p *Process) Rlimit() ([]RlimitStat, error) {
var rlimit []RlimitStat var rlimit []RlimitStat
return rlimit, NotImplementedError return rlimit, common.NotImplementedError
} }
func (p *Process) IOCounters() (*IOCountersStat, error) { func (p *Process) IOCounters() (*IOCountersStat, error) {
return nil, NotImplementedError return nil, common.NotImplementedError
} }
func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) { func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) {
return nil, NotImplementedError return nil, common.NotImplementedError
} }
func (p *Process) NumFDs() (int32, error) { func (p *Process) NumFDs() (int32, error) {
return 0, NotImplementedError return 0, common.NotImplementedError
} }
func (p *Process) NumThreads() (int32, error) { func (p *Process) NumThreads() (int32, error) {
k, err := p.getKProc() k, err := p.getKProc()
@ -138,16 +142,16 @@ func (p *Process) NumThreads() (int32, error) {
} }
func (p *Process) Threads() (map[string]string, error) { func (p *Process) Threads() (map[string]string, error) {
ret := make(map[string]string, 0) ret := make(map[string]string, 0)
return ret, NotImplementedError return ret, common.NotImplementedError
} }
func (p *Process) CPUTimes() (*CPUTimesStat, error) { func (p *Process) CPUTimes() (*cpu.CPUTimesStat, error) {
return nil, NotImplementedError return nil, common.NotImplementedError
} }
func (p *Process) CPUPercent() (int32, error) { func (p *Process) CPUPercent() (int32, error) {
return 0, NotImplementedError return 0, common.NotImplementedError
} }
func (p *Process) CPUAffinity() ([]int32, error) { func (p *Process) CPUAffinity() ([]int32, error) {
return nil, NotImplementedError return nil, common.NotImplementedError
} }
func (p *Process) MemoryInfo() (*MemoryInfoStat, error) { func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
k, err := p.getKProc() k, err := p.getKProc()
@ -163,30 +167,30 @@ func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
return ret, nil return ret, nil
} }
func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) { func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
return nil, NotImplementedError return nil, common.NotImplementedError
} }
func (p *Process) MemoryPercent() (float32, error) { func (p *Process) MemoryPercent() (float32, error) {
return 0, NotImplementedError return 0, common.NotImplementedError
} }
func (p *Process) Children() ([]*Process, error) { func (p *Process) Children() ([]*Process, error) {
return nil, NotImplementedError return nil, common.NotImplementedError
} }
func (p *Process) OpenFiles() ([]OpenFilesStat, error) { func (p *Process) OpenFiles() ([]OpenFilesStat, error) {
return nil, NotImplementedError return nil, common.NotImplementedError
} }
func (p *Process) Connections() ([]NetConnectionStat, error) { func (p *Process) Connections() ([]net.NetConnectionStat, error) {
return nil, NotImplementedError return nil, common.NotImplementedError
} }
func (p *Process) IsRunning() (bool, error) { func (p *Process) IsRunning() (bool, error) {
return true, NotImplementedError return true, common.NotImplementedError
} }
func (p *Process) MemoryMaps(grouped bool) (*[]MemoryMapsStat, error) { func (p *Process) MemoryMaps(grouped bool) (*[]MemoryMapsStat, error) {
var ret []MemoryMapsStat var ret []MemoryMapsStat
return &ret, NotImplementedError return &ret, common.NotImplementedError
} }
func copyParams(k *KinfoProc, p *Process) error { func copyParams(k *KinfoProc, p *Process) error {

View File

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

View File

@ -10,6 +10,10 @@ import (
"strconv" "strconv"
"strings" "strings"
"syscall" "syscall"
common "github.com/shirou/gopsutil/common"
cpu "github.com/shirou/gopsutil/cpu"
net "github.com/shirou/gopsutil/net"
) )
const ( const (
@ -89,7 +93,7 @@ func (p *Process) Cwd() (string, error) {
return p.fillFromCwd() return p.fillFromCwd()
} }
func (p *Process) Parent() (*Process, error) { func (p *Process) Parent() (*Process, error) {
return nil, NotImplementedError return nil, common.NotImplementedError
} }
func (p *Process) Status() (string, error) { func (p *Process) Status() (string, error) {
return p.status, nil return p.status, nil
@ -115,10 +119,10 @@ func (p *Process) Nice() (int32, error) {
return nice, nil return nice, nil
} }
func (p *Process) IOnice() (int32, error) { func (p *Process) IOnice() (int32, error) {
return 0, NotImplementedError return 0, common.NotImplementedError
} }
func (p *Process) Rlimit() ([]RlimitStat, error) { func (p *Process) Rlimit() ([]RlimitStat, error) {
return nil, NotImplementedError return nil, common.NotImplementedError
} }
func (p *Process) IOCounters() (*IOCountersStat, error) { func (p *Process) IOCounters() (*IOCountersStat, error) {
return p.fillFromIO() return p.fillFromIO()
@ -127,7 +131,7 @@ func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) {
return p.numCtxSwitches, nil return p.numCtxSwitches, nil
} }
func (p *Process) NumFDs() (int32, error) { func (p *Process) NumFDs() (int32, error) {
return 0, NotImplementedError return 0, common.NotImplementedError
} }
func (p *Process) NumThreads() (int32, error) { func (p *Process) NumThreads() (int32, error) {
return p.numThreads, nil return p.numThreads, nil
@ -136,7 +140,7 @@ func (p *Process) Threads() (map[string]string, error) {
ret := make(map[string]string, 0) ret := make(map[string]string, 0)
return ret, nil return ret, nil
} }
func (p *Process) CPUTimes() (*CPUTimesStat, error) { func (p *Process) CPUTimes() (*cpu.CPUTimesStat, error) {
_, _, cpuTimes, _, _, err := p.fillFromStat() _, _, cpuTimes, _, _, err := p.fillFromStat()
if err != nil { if err != nil {
return nil, err return nil, err
@ -144,10 +148,10 @@ func (p *Process) CPUTimes() (*CPUTimesStat, error) {
return cpuTimes, nil return cpuTimes, nil
} }
func (p *Process) CPUPercent() (int32, error) { func (p *Process) CPUPercent() (int32, error) {
return 0, NotImplementedError return 0, common.NotImplementedError
} }
func (p *Process) CPUAffinity() ([]int32, error) { func (p *Process) CPUAffinity() ([]int32, error) {
return nil, NotImplementedError return nil, common.NotImplementedError
} }
func (p *Process) MemoryInfo() (*MemoryInfoStat, error) { func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
return p.memInfo, nil return p.memInfo, nil
@ -160,23 +164,23 @@ func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
return memInfoEx, nil return memInfoEx, nil
} }
func (p *Process) MemoryPercent() (float32, error) { func (p *Process) MemoryPercent() (float32, error) {
return 0, NotImplementedError return 0, common.NotImplementedError
} }
func (p *Process) Children() ([]*Process, error) { func (p *Process) Children() ([]*Process, error) {
return nil, NotImplementedError return nil, common.NotImplementedError
} }
func (p *Process) OpenFiles() ([]OpenFilesStat, error) { func (p *Process) OpenFiles() ([]OpenFilesStat, error) {
return nil, NotImplementedError return nil, common.NotImplementedError
} }
func (p *Process) Connections() ([]NetConnectionStat, error) { func (p *Process) Connections() ([]net.NetConnectionStat, error) {
return nil, NotImplementedError return nil, common.NotImplementedError
} }
func (p *Process) IsRunning() (bool, error) { func (p *Process) IsRunning() (bool, error) {
return true, NotImplementedError return true, common.NotImplementedError
} }
// MemoryMaps get memory maps from /proc/(pid)/smaps // MemoryMaps get memory maps from /proc/(pid)/smaps
@ -513,7 +517,7 @@ func (p *Process) fillFromStatus() error {
return nil 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 pid := p.Pid
statPath := filepath.Join("/", "proc", strconv.Itoa(int(pid)), "stat") statPath := filepath.Join("/", "proc", strconv.Itoa(int(pid)), "stat")
contents, err := ioutil.ReadFile(statPath) contents, err := ioutil.ReadFile(statPath)
@ -545,7 +549,7 @@ func (p *Process) fillFromStat() (string, int32, *CPUTimesStat, int64, int32, er
return "", 0, nil, 0, 0, err return "", 0, nil, 0, 0, err
} }
cpuTimes := &CPUTimesStat{ cpuTimes := &cpu.CPUTimesStat{
CPU: "cpu", CPU: "cpu",
User: float32(utime * (1000 / ClockTicks)), User: float32(utime * (1000 / ClockTicks)),
System: float32(stime * (1000 / ClockTicks)), System: float32(stime * (1000 / ClockTicks)),

View File

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