Merge branch 'master' of github.com:shirou/gopsutil

pull/4/head
Shirou WAKAYAMA 11 years ago
commit 9a32bb9bd0

@ -4,7 +4,7 @@ import (
"runtime" "runtime"
) )
type CPU_TimesStat struct { type CPUTimesStat struct {
Cpu string `json:"cpu"` Cpu string `json:"cpu"`
User float32 `json:"user"` User float32 `json:"user"`
System float32 `json:"system"` System float32 `json:"system"`
@ -19,6 +19,6 @@ type CPU_TimesStat struct {
Stolen float32 `json:"stolen"` Stolen float32 `json:"stolen"`
} }
func Cpu_counts(logical bool) (int, error) { func CpuCounts(logical bool) (int, error) {
return runtime.NumCPU(), nil return runtime.NumCPU(), nil
} }

@ -22,7 +22,7 @@ const (
) )
// TODO: get per cpus // TODO: get per cpus
func Cpu_times(percpu bool) ([]CPU_TimesStat, error) { func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
ret := make([]CPU_TimesStat, 0) ret := make([]CPU_TimesStat, 0)
cpu_time, err := do_sysctrl("kern.cp_time") cpu_time, err := do_sysctrl("kern.cp_time")

@ -5,7 +5,7 @@ import (
) )
func TestCpu_times(t *testing.T) { func TestCpu_times(t *testing.T) {
v, err := Cpu_times(false) v, err := CPUTimes(false)
if err != nil { if err != nil {
t.Errorf("error %v", err) t.Errorf("error %v", err)
} }
@ -21,7 +21,7 @@ func TestCpu_times(t *testing.T) {
} }
func TestCpu_counts(t *testing.T) { func TestCpu_counts(t *testing.T) {
v, err := Cpu_counts(true) v, err := CpuCounts(true)
if err != nil { if err != nil {
t.Errorf("error %v", err) t.Errorf("error %v", err)
} }

@ -7,8 +7,8 @@ import (
"unsafe" "unsafe"
) )
func Cpu_times(percpu bool) ([]CPU_TimesStat, error) { func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
ret := make([]CPU_TimesStat, 0) var ret []CPUTimesStat
var lpIdleTime FILETIME var lpIdleTime FILETIME
var lpKernelTime FILETIME var lpKernelTime FILETIME
@ -21,14 +21,14 @@ func Cpu_times(percpu bool) ([]CPU_TimesStat, error) {
return ret, syscall.GetLastError() return ret, syscall.GetLastError()
} }
LO_T := float64(0.0000001) LOT := float64(0.0000001)
HI_T := (LO_T * 4294967296.0) HIT := (LOT * 4294967296.0)
idle := ((HI_T * float64(lpIdleTime.DwHighDateTime)) + (LO_T * float64(lpIdleTime.DwLowDateTime))) idle := ((HIT * float64(lpIdleTime.DwHighDateTime)) + (LOT * float64(lpIdleTime.DwLowDateTime)))
user := ((HI_T * float64(lpUserTime.DwHighDateTime)) + (LO_T * float64(lpUserTime.DwLowDateTime))) user := ((HIT * float64(lpUserTime.DwHighDateTime)) + (LOT * float64(lpUserTime.DwLowDateTime)))
kernel := ((HI_T * float64(lpKernelTime.DwHighDateTime)) + (LO_T * float64(lpKernelTime.DwLowDateTime))) kernel := ((HIT * float64(lpKernelTime.DwHighDateTime)) + (LOT * float64(lpKernelTime.DwLowDateTime)))
system := (kernel - idle) system := (kernel - idle)
ret = append(ret, CPU_TimesStat{ ret = append(ret, CPUTimesStat{
Idle: float32(idle), Idle: float32(idle),
User: float32(user), User: float32(user),
System: float32(system), System: float32(system),

@ -1,6 +1,6 @@
package gopsutil package gopsutil
type Disk_usageStat struct { type DiskUsageStat struct {
Path string `json:"path"` Path string `json:"path"`
Total uint64 `json:"total"` Total uint64 `json:"total"`
Free uint64 `json:"free"` Free uint64 `json:"free"`
@ -8,14 +8,14 @@ type Disk_usageStat struct {
UsedPercent float64 `json:"usedPercent"` UsedPercent float64 `json:"usedPercent"`
} }
type Disk_partitionStat struct { type DiskPartitionStat struct {
Device string `json:"device"` Device string `json:"device"`
Mountpoint string `json:"mountpoint"` Mountpoint string `json:"mountpoint"`
Fstype string `json:"fstype"` Fstype string `json:"fstype"`
Opts string `json:"opts"` Opts string `json:"opts"`
} }
type Disk_IO_CountersStat struct { type DiskIOCountersStat struct {
ReadCount uint64 `json:"readCount"` ReadCount uint64 `json:"readCount"`
WriteCount uint64 `json:"writeCount"` WriteCount uint64 `json:"writeCount"`
ReadBytes uint64 `json:"readBytes"` ReadBytes uint64 `json:"readBytes"`

@ -8,7 +8,7 @@ import (
"unsafe" "unsafe"
) )
func Disk_partitions(all bool) ([]Disk_partitionStat, error) { func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
ret := make([]Disk_partitionStat, 0) ret := make([]Disk_partitionStat, 0)
// get length // get length
@ -82,12 +82,12 @@ func Disk_partitions(all bool) ([]Disk_partitionStat, error) {
return ret, nil return ret, nil
} }
func Disk_io_counters() (map[string]Disk_IO_CountersStat, error) { func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
ret := make(map[string]Disk_IO_CountersStat, 0) ret := make(map[string]Disk_IO_CountersStat, 0)
return ret, errors.New("Not implemented yet") return ret, errors.New("not implemented yet")
} }
// This is borrowed from pkg/syscall/syscall_freebsd.go // Getfsstat is borrowed from pkg/syscall/syscall_freebsd.go
// change Statfs_t to Statfs in order to get more information // change Statfs_t to Statfs in order to get more information
func Getfsstat(buf []Statfs, flags int) (n int, err error) { func Getfsstat(buf []Statfs, flags int) (n int, err error) {
var _p0 unsafe.Pointer var _p0 unsafe.Pointer

@ -13,7 +13,7 @@ const (
// Get disk partitions. // Get disk partitions.
// should use setmntent(3) but this implement use /etc/mtab file // should use setmntent(3) but this implement use /etc/mtab file
func Disk_partitions(all bool) ([]Disk_partitionStat, error) { func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
ret := make([]Disk_partitionStat, 0) ret := make([]Disk_partitionStat, 0)
filename := "/etc/mtab" filename := "/etc/mtab"
@ -35,7 +35,7 @@ func Disk_partitions(all bool) ([]Disk_partitionStat, error) {
return ret, nil return ret, nil
} }
func Disk_io_counters() (map[string]Disk_IO_CountersStat, error) { func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
ret := make(map[string]Disk_IO_CountersStat, 0) ret := make(map[string]Disk_IO_CountersStat, 0)
// determine partitions we want to look for // determine partitions we want to look for

@ -11,7 +11,7 @@ func TestDisk_usage(t *testing.T) {
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
path = "C:" path = "C:"
} }
_, err := Disk_usage(path) _, err := DiskUsage(path)
if err != nil { if err != nil {
t.Errorf("error %v", err) t.Errorf("error %v", err)
} }
@ -20,14 +20,14 @@ func TestDisk_usage(t *testing.T) {
} }
func TestDisk_partitions(t *testing.T) { func TestDisk_partitions(t *testing.T) {
_, err := Disk_partitions(false) _, err := DiskPartitions(false)
if err != nil { if err != nil {
t.Errorf("error %v", err) t.Errorf("error %v", err)
} }
} }
func TestDisk_io_counters(t *testing.T) { func TestDisk_io_counters(t *testing.T) {
ret, err := Disk_io_counters() ret, err := DiskIOCounters()
if err != nil { if err != nil {
t.Errorf("error %v", err) t.Errorf("error %v", err)
} }

@ -4,7 +4,7 @@ package gopsutil
import "syscall" import "syscall"
func Disk_usage(path string) (Disk_usageStat, error) { func DiskUsage(path string) (DiskUsageStat, error) {
stat := syscall.Statfs_t{} stat := syscall.Statfs_t{}
err := syscall.Statfs(path, &stat) err := syscall.Statfs(path, &stat)
if err != nil { if err != nil {

@ -21,8 +21,8 @@ var (
FILE_READ_ONLY_VOLUME = int64(524288) // 0x00080000 FILE_READ_ONLY_VOLUME = int64(524288) // 0x00080000
) )
func Disk_usage(path string) (Disk_usageStat, error) { func DiskUsage(path string) (DiskUsageStat, error) {
ret := Disk_usageStat{} ret := DiskUsageStat{}
ret.Path = path ret.Path = path
lpFreeBytesAvailable := int64(0) lpFreeBytesAvailable := int64(0)
@ -45,8 +45,8 @@ func Disk_usage(path string) (Disk_usageStat, error) {
return ret, nil return ret, nil
} }
func Disk_partitions(all bool) ([]Disk_partitionStat, error) { func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
ret := make([]Disk_partitionStat, 0) ret := make([]DiskPartitionStat, 0)
lpBuffer := make([]byte, 254) lpBuffer := make([]byte, 254)
diskret, _, err := procGetLogicalDriveStringsW.Call( diskret, _, err := procGetLogicalDriveStringsW.Call(
uintptr(len(lpBuffer)), uintptr(len(lpBuffer)),
@ -94,7 +94,7 @@ func Disk_partitions(all bool) ([]Disk_partitionStat, error) {
opts += ".compress" opts += ".compress"
} }
d := Disk_partitionStat{ d := DiskPartitionStat{
Mountpoint: path, Mountpoint: path,
Device: path, Device: path,
Fstype: string(bytes.Replace(lpFileSystemNameBuffer, []byte("\x00"), []byte(""), -1)), Fstype: string(bytes.Replace(lpFileSystemNameBuffer, []byte("\x00"), []byte(""), -1)),
@ -107,7 +107,7 @@ func Disk_partitions(all bool) ([]Disk_partitionStat, error) {
return ret, nil return ret, nil
} }
func Disk_io_counters() (map[string]Disk_IO_CountersStat, error) { func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
ret := make(map[string]Disk_IO_CountersStat, 0) ret := make(map[string]DiskIOCountersStat, 0)
return ret, errors.New("Not implemented yet") return ret, errors.New("not implemented yet")
} }

@ -24,7 +24,7 @@ func HostInfo() (HostInfoStat, error) {
return ret, nil return ret, nil
} }
func Boot_time() (int64, error) { func BootTime() (int64, error) {
values, err := do_sysctrl("kern.boottime") values, err := do_sysctrl("kern.boottime")
if err != nil { if err != nil {
return 0, err return 0, err

@ -15,7 +15,7 @@ func TestHostInfo(t *testing.T) {
} }
func TestBoot_time(t *testing.T) { func TestBoot_time(t *testing.T) {
v, err := Boot_time() v, err := BootTime()
if err != nil { if err != nil {
t.Errorf("error %v", err) t.Errorf("error %v", err)
} }

@ -39,7 +39,7 @@ func HostInfo() (HostInfoStat, error) {
return ret, nil return ret, nil
} }
func Boot_time() (int64, error) { func BootTime() (int64, error) {
var lpSystemTimeAsFileTime FILETIME var lpSystemTimeAsFileTime FILETIME
r, _, _ := procGetSystemTimeAsFileTime.Call(uintptr(unsafe.Pointer(&lpSystemTimeAsFileTime))) r, _, _ := procGetSystemTimeAsFileTime.Call(uintptr(unsafe.Pointer(&lpSystemTimeAsFileTime)))
@ -61,7 +61,7 @@ func Boot_time() (int64, error) {
} }
func Users() ([]UserStat, error) { func Users() ([]UserStat, error) {
ret := make([]UserStat, 0) var ret []UserStat
return ret, nil return ret, nil
} }

@ -1,6 +1,6 @@
package gopsutil package gopsutil
type Virtual_memoryStat struct { type VirtualMemoryStat struct {
Total uint64 `json:"total"` Total uint64 `json:"total"`
Available uint64 `json:"available"` Available uint64 `json:"available"`
Used uint64 `json:"used"` Used uint64 `json:"used"`
@ -14,7 +14,7 @@ type Virtual_memoryStat struct {
Shared uint64 `json:"shared"` Shared uint64 `json:"shared"`
} }
type Swap_memoryStat struct { type SwapMemoryStat struct {
Total uint64 `json:"total"` Total uint64 `json:"total"`
Used uint64 `json:"used"` Used uint64 `json:"used"`
Free uint64 `json:"free"` Free uint64 `json:"free"`

@ -2,13 +2,13 @@
package gopsutil package gopsutil
func Virtual_memory() (Virtual_memoryStat, error) { func VirtualMemory() (VirtualMemoryStat, error) {
ret := Virtual_memoryStat{} ret := Virtual_memoryStat{}
return ret, nil return ret, nil
} }
func Swap_memory() (Swap_memoryStat, error) { func SwapMemory() (SwapMemoryStat, error) {
ret := Swap_memoryStat{} ret := Swap_memoryStat{}
return ret, nil return ret, nil

@ -6,7 +6,7 @@ import (
"syscall" "syscall"
) )
func Virtual_memory() (Virtual_memoryStat, error) { func VirtualMemory() (VirtualMemoryStat, error) {
ret := Virtual_memoryStat{} ret := Virtual_memoryStat{}
sysinfo := &syscall.Sysinfo_t{} sysinfo := &syscall.Sysinfo_t{}
@ -35,7 +35,7 @@ func Virtual_memory() (Virtual_memoryStat, error) {
return ret, nil return ret, nil
} }
func Swap_memory() (Swap_memoryStat, error) { func SwapMemory() (SwapMemoryStat, error) {
ret := Swap_memoryStat{} ret := Swap_memoryStat{}
sysinfo := &syscall.Sysinfo_t{} sysinfo := &syscall.Sysinfo_t{}

@ -7,7 +7,7 @@ import (
) )
func TestVirtual_memory(t *testing.T) { func TestVirtual_memory(t *testing.T) {
v, err := Virtual_memory() v, err := VirtualMemory()
if err != nil { if err != nil {
t.Errorf("error %v", err) t.Errorf("error %v", err)
} }
@ -16,7 +16,7 @@ func TestVirtual_memory(t *testing.T) {
} }
func TestSwap_memory(t *testing.T) { func TestSwap_memory(t *testing.T) {
v, err := Swap_memory() v, err := SwapMemory()
if err != nil { if err != nil {
t.Errorf("error %v", err) t.Errorf("error %v", err)
} }

@ -23,8 +23,8 @@ type MEMORYSTATUSEX struct {
ullAvailExtendedVirtual uint64 ullAvailExtendedVirtual uint64
} }
func Virtual_memory() (Virtual_memoryStat, error) { func VirtualMemory() (VirtualMemoryStat, error) {
ret := Virtual_memoryStat{} ret := VirtualMemoryStat{}
var memInfo MEMORYSTATUSEX var memInfo MEMORYSTATUSEX
memInfo.cbSize = uint32(unsafe.Sizeof(memInfo)) memInfo.cbSize = uint32(unsafe.Sizeof(memInfo))
@ -40,8 +40,8 @@ func Virtual_memory() (Virtual_memoryStat, error) {
return ret, nil return ret, nil
} }
func Swap_memory() (Swap_memoryStat, error) { func SwapMemory() (SwapMemoryStat, error) {
ret := Swap_memoryStat{} ret := SwapMemoryStat{}
return ret, nil return ret, nil
} }

@ -1,11 +1,11 @@
package gopsutil package gopsutil
type Net_io_countersStat struct { type NetIOCountersStat struct {
Name string `json:"name""` // interface name Name string `json:"name""` // interface name
Bytes_sent uint64 `json:"bytes_sent""` // number of bytes sent BytesSent uint64 `json:"bytes_sent""` // number of bytes sent
Bytes_recv uint64 `json:"bytes_recv"` // number of bytes received BytesRecv uint64 `json:"bytes_recv"` // number of bytes received
Packets_sent uint64 `json:"packets_sent"` // number of packets sent PacketsSent uint64 `json:"packets_sent"` // number of packets sent
Packets_recv uint64 `json:"packets_recv"` // number of packets received PacketsRecv uint64 `json:"packets_recv"` // number of packets received
Errin uint64 `json:"errin"` // total number of errors while receiving Errin uint64 `json:"errin"` // total number of errors while receiving
Errout uint64 `json:"errout"` // total number of errors while sending Errout uint64 `json:"errout"` // total number of errors while sending
Dropin uint64 `json:"dropin"` // total number of incoming packets which were dropped Dropin uint64 `json:"dropin"` // total number of incoming packets which were dropped
@ -17,7 +17,7 @@ type Addr struct {
Port uint32 `json:"port""` Port uint32 `json:"port""`
} }
type Net_connectionStat struct { type NetConnectionStat struct {
Fd uint32 `json:"fd""` Fd uint32 `json:"fd""`
Family uint32 `json:"family""` Family uint32 `json:"family""`
Type uint32 `json:"type""` Type uint32 `json:"type""`

@ -6,7 +6,7 @@ import (
"strings" "strings"
) )
func Net_io_counters() ([]Net_io_countersStat, error) { func NetIOCounters() ([]NetIOCountersStat, error) {
filename := "/proc/net/dev" filename := "/proc/net/dev"
lines, err := ReadLines(filename) lines, err := ReadLines(filename)
if err != nil { if err != nil {

@ -4,12 +4,12 @@ type Process struct {
Pid int32 `json:"pid"` Pid int32 `json:"pid"`
} }
type Open_filesStat struct { type OpenFilesStat struct {
Path string `json:"path"` Path string `json:"path"`
Fd uint64 `json:"fd"` Fd uint64 `json:"fd"`
} }
type Memory_infoStat struct { type MemoryInfoStat struct {
RSS uint64 `json:"rss"` // bytes RSS uint64 `json:"rss"` // bytes
VMS uint64 `json:"vms"` // bytes VMS uint64 `json:"vms"` // bytes
} }
@ -20,14 +20,14 @@ type RlimitStat struct {
Hard int32 `json:"hard"` Hard int32 `json:"hard"`
} }
type Io_countersStat struct { type IoCountersStat struct {
Read_count int32 `json:"read_count"` ReadCount int32 `json:"read_count"`
Write_count int32 `json:"write_count"` WriteCount int32 `json:"write_count"`
Read_bytes int32 `json:"read_bytes"` ReadBytes int32 `json:"read_bytes"`
Write_bytes int32 `json:"write_bytes"` WriteBytes int32 `json:"write_bytes"`
} }
func Pid_exists(pid int32) (bool, error) { func PidExists(pid int32) (bool, error) {
pids, err := Pids() pids, err := Pids()
if err != nil { if err != nil {
return false, err return false, err

@ -10,15 +10,15 @@ import (
"unsafe" "unsafe"
) )
// Memory_info_ex is different between OSes // MemoryInfoExStat is different between OSes
type Memory_info_exStat struct { type MemoryInfoExStat struct {
} }
type Memory_mapsStat struct { type MemoryMapsStat struct {
} }
func Pids() ([]int32, error) { func Pids() ([]int32, error) {
ret := make([]int32, 0) var ret []int32
procs, err := processes() procs, err := processes()
if err != nil { if err != nil {
return ret, nil return ret, nil
@ -32,107 +32,107 @@ func Pids() ([]int32, error) {
} }
func (p *Process) Ppid() (int32, error) { func (p *Process) Ppid() (int32, error) {
return 0, errors.New("Not implemented yet") return 0, errors.New("not implemented yet")
} }
func (p *Process) Name() (string, error) { func (p *Process) Name() (string, error) {
name := "" name := ""
return name, errors.New("Not implemented yet") return name, errors.New("not implemented yet")
} }
func (p *Process) Exe() (string, error) { func (p *Process) Exe() (string, error) {
return "", errors.New("Not implemented yet") return "", errors.New("not implemented yet")
} }
func (p *Process) Cmdline() (string, error) { func (p *Process) Cmdline() (string, error) {
return "", errors.New("Not implemented yet") return "", errors.New("not implemented yet")
} }
func (p *Process) Cwd() (string, error) { func (p *Process) Cwd() (string, error) {
return "", errors.New("Not implemented yet") return "", errors.New("not implemented yet")
} }
func (p *Process) Parent() (*Process, error) { func (p *Process) Parent() (*Process, error) {
return p, errors.New("Not implemented yet") return p, errors.New("not implemented yet")
} }
func (p *Process) Status() (string, error) { func (p *Process) Status() (string, error) {
return "", errors.New("Not implemented yet") return "", errors.New("not implemented yet")
} }
func (p *Process) Username() (string, error) { func (p *Process) Username() (string, error) {
return "", errors.New("Not implemented yet") return "", errors.New("not implemented yet")
} }
func (p *Process) Uids() ([]int32, error) { func (p *Process) Uids() ([]int32, error) {
uids := make([]int32, 0) var uids []int32
return uids, errors.New("Not implemented yet") return uids, errors.New("not implemented yet")
} }
func (p *Process) Gids() ([]int32, error) { func (p *Process) Gids() ([]int32, error) {
gids := make([]int32, 0) var gids []int32
return gids, errors.New("Not implemented yet") return gids, errors.New("not implemented yet")
} }
func (p *Process) Terminal() (string, error) { func (p *Process) Terminal() (string, error) {
return "", errors.New("Not implemented yet") return "", errors.New("not implemented yet")
} }
func (p *Process) Nice() (int32, error) { func (p *Process) Nice() (int32, error) {
return 0, errors.New("Not implemented yet") return 0, errors.New("not implemented yet")
} }
func (p *Process) Ionice() (int32, error) { func (p *Process) Ionice() (int32, error) {
return 0, errors.New("Not implemented yet") return 0, errors.New("not implemented yet")
} }
func (p *Process) Rlimit() ([]RlimitStat, error) { func (p *Process) Rlimit() ([]RlimitStat, error) {
rlimit := make([]RlimitStat, 0) var rlimit []RlimitStat
return rlimit, errors.New("Not implemented yet") return rlimit, errors.New("not implemented yet")
} }
func (p *Process) Io_counters() (*Io_countersStat, error) { func (p *Process) IOCounters() (*IOCountersStat, error) {
return nil, errors.New("Not implemented yet") return nil, errors.New("not implemented yet")
} }
func (p *Process) Num_ctx_switches() (int32, error) { func (p *Process) NumCtxSwitches() (int32, error) {
return 0, errors.New("Not implemented yet") return 0, errors.New("not implemented yet")
} }
func (p *Process) Num_fds() (int32, error) { func (p *Process) NumFDs() (int32, error) {
return 0, errors.New("Not implemented yet") return 0, errors.New("not implemented yet")
} }
func (p *Process) Num_Threads() (int32, error) { func (p *Process) NumThreads() (int32, error) {
return 0, errors.New("Not implemented yet") return 0, errors.New("not implemented yet")
} }
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, errors.New("Not implemented yet") return ret, errors.New("not implemented yet")
} }
func (p *Process) Cpu_times() (*CPU_TimesStat, error) { func (p *Process) CPUTimes() (*CPUTimesStat, error) {
return nil, errors.New("Not implemented yet") return nil, errors.New("not implemented yet")
} }
func (p *Process) Cpu_percent() (int32, error) { func (p *Process) CPUPercent() (int32, error) {
return 0, errors.New("Not implemented yet") return 0, errors.New("not implemented yet")
} }
func (p *Process) Cpu_affinity() ([]int32, error) { func (p *Process) CPUAffinity() ([]int32, error) {
return nil, errors.New("Not implemented yet") return nil, errors.New("not implemented yet")
} }
func (p *Process) Memory_info() (*Memory_infoStat, error) { func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
return nil, errors.New("Not implemented yet") return nil, errors.New("not implemented yet")
} }
func (p *Process) Memory_info_ex() (*Memory_info_exStat, error) { func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
return nil, errors.New("Not implemented yet") return nil, errors.New("not implemented yet")
} }
func (p *Process) Memory_percent() (float32, error) { func (p *Process) MemoryPercent() (float32, error) {
return 0, errors.New("Not implemented yet") return 0, errors.New("not implemented yet")
} }
func (p *Process) Children() ([]*Process, error) { func (p *Process) Children() ([]*Process, error) {
return nil, errors.New("Not implemented yet") return nil, errors.New("not implemented yet")
} }
func (p *Process) Open_files() ([]Open_filesStat, error) { func (p *Process) OpenFiles() ([]OpenFilesStat, error) {
return nil, errors.New("Not implemented yet") return nil, errors.New("not implemented yet")
} }
func (p *Process) Connections() ([]Net_connectionStat, error) { func (p *Process) Connections() ([]NetConnectionStat, error) {
return nil, errors.New("Not implemented yet") return nil, errors.New("not implemented yet")
} }
func (p *Process) Is_running() (bool, error) { func (p *Process) IsRunning() (bool, error) {
return true, errors.New("Not implemented yet") return true, errors.New("not implemented yet")
} }
func (p *Process) Memory_Maps(grouped bool) (*[]Memory_mapsStat, error) { func (p *Process) MemoryMaps(grouped bool) (*[]MemoryMapsStat, error) {
ret := make([]Memory_mapsStat, 0) var ret []MemoryMapsStat
return &ret, errors.New("Not implemented yet") return &ret, errors.New("not implemented yet")
} }
func copy_params(k *Kinfo_proc, p *Process) error { func copyParams(k *Kinfo_proc, p *Process) error {
return nil return nil
} }
@ -141,20 +141,20 @@ func processes() ([]Process, error) {
results := make([]Process, 0, 50) results := make([]Process, 0, 50)
mib := []int32{CTL_KERN, KERN_PROC, KERN_PROC_PROC, 0} mib := []int32{CTL_KERN, KERN_PROC, KERN_PROC_PROC, 0}
buf, length, err := call_syscall(mib) buf, length, err := callSyscall(mib)
if err != nil { if err != nil {
return results, err return results, err
} }
// get kinfo_proc size // get kinfo_proc size
k := Kinfo_proc{} k := Kinfo_proc{}
procinfo_len := int(unsafe.Sizeof(k)) procinfoLen := int(unsafe.Sizeof(k))
count := int(length / uint64(procinfo_len)) count := int(length / uint64(procinfoLen))
// parse buf to procs // parse buf to procs
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
b := buf[i*procinfo_len : i*procinfo_len+procinfo_len] b := buf[i*procinfoLen : i*procinfoLen+procinfoLen]
k, err := parse_kinfo_proc(b) k, err := parseKinfoProc(b)
if err != nil { if err != nil {
continue continue
} }
@ -162,7 +162,7 @@ func processes() ([]Process, error) {
if err != nil { if err != nil {
continue continue
} }
copy_params(&k, p) copyParams(&k, p)
results = append(results, *p) results = append(results, *p)
} }
@ -170,8 +170,8 @@ func processes() ([]Process, error) {
return results, nil return results, nil
} }
func parse_kinfo_proc(buf []byte) (Kinfo_proc, error) { func parseKinfoProc(buf []byte) (KinfoProc, error) {
var k Kinfo_proc var k KinfoProc
br := bytes.NewReader(buf) br := bytes.NewReader(buf)
err := binary.Read(br, binary.LittleEndian, &k) err := binary.Read(br, binary.LittleEndian, &k)
if err != nil { if err != nil {
@ -181,7 +181,7 @@ func parse_kinfo_proc(buf []byte) (Kinfo_proc, error) {
return k, nil return k, nil
} }
func call_syscall(mib []int32) ([]byte, uint64, error) { func callSyscall(mib []int32) ([]byte, uint64, error) {
miblen := uint64(len(mib)) miblen := uint64(len(mib))
// get required buffer size // get required buffer size
@ -195,11 +195,11 @@ func call_syscall(mib []int32) ([]byte, uint64, error) {
0, 0,
0) 0)
if err != 0 { if err != 0 {
b := make([]byte, 0) var b []byte
return b, length, err return b, length, err
} }
if length == 0 { if length == 0 {
b := make([]byte, 0) var b []byte
return b, length, err return b, length, err
} }
// get proc info itself // get proc info itself
@ -227,16 +227,16 @@ func NewProcess(pid int32) (*Process, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
proc_k := Kinfo_proc{} procK := KinfoProc{}
if length != uint64(unsafe.Sizeof(proc_k)) { if length != uint64(unsafe.Sizeof(procK)) {
return nil, err return nil, err
} }
k, err := parse_kinfo_proc(buf) k, err := parseKinfoProc(buf)
if err != nil { if err != nil {
return nil, err return nil, err
} }
copy_params(&k, p) copyParams(&k, p)
return p, nil return p, nil
} }

@ -16,8 +16,8 @@ const (
PRIO_PROCESS = 0 // linux/resource.h PRIO_PROCESS = 0 // linux/resource.h
) )
// Memory_info_ex is different between OSes // MemoryInfoExStat is different between OSes
type Memory_info_exStat struct { type MemoryInfoExStat struct {
RSS uint64 `json:"rss"` // bytes RSS uint64 `json:"rss"` // bytes
VMS uint64 `json:"vms"` // bytes VMS uint64 `json:"vms"` // bytes
Shared uint64 `json:"shared"` // bytes Shared uint64 `json:"shared"` // bytes
@ -27,15 +27,15 @@ type Memory_info_exStat struct {
Dirty uint64 `json:"dirty"` // bytes Dirty uint64 `json:"dirty"` // bytes
} }
type Memory_mapsStat struct { type MemoryMapsStat struct {
Path string `json:"path"` Path string `json:"path"`
Rss uint64 `json:"rss"` Rss uint64 `json:"rss"`
Size uint64 `json:"size"` Size uint64 `json:"size"`
Pss uint64 `json:"pss"` Pss uint64 `json:"pss"`
Shared_clean uint64 `json:"shared_clean"` SharedClean uint64 `json:"shared_clean"`
Shared_dirty uint64 `json:"shared_dirty"` SharedDirty uint64 `json:"shared_dirty"`
Private_clean uint64 `json:"private_clean"` PrivateClean uint64 `json:"private_clean"`
Private_dirty uint64 `json:"private_dirty"` PrivateDirty uint64 `json:"private_dirty"`
Referenced uint64 `json:"referenced"` Referenced uint64 `json:"referenced"`
Anonymous uint64 `json:"anonymous"` Anonymous uint64 `json:"anonymous"`
Swap uint64 `json:"swap"` Swap uint64 `json:"swap"`
@ -74,7 +74,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, errors.New("Not implemented yet") return nil, errors.New("not implemented yet")
} }
func (p *Process) Status() (string, error) { func (p *Process) Status() (string, error) {
_, status, _, _, _, err := p.fillFromStatus() _, status, _, _, _, err := p.fillFromStatus()
@ -115,82 +115,82 @@ 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, errors.New("Not implemented yet") return 0, errors.New("not implemented yet")
} }
func (p *Process) Rlimit() ([]RlimitStat, error) { func (p *Process) Rlimit() ([]RlimitStat, error) {
return nil, errors.New("Not implemented yet") return nil, errors.New("not implemented yet")
} }
func (p *Process) Io_counters() (*Io_countersStat, error) { func (p *Process) IOCounters() (*IOCountersStat, error) {
return nil, errors.New("Not implemented yet") return nil, errors.New("not implemented yet")
} }
func (p *Process) Num_ctx_switches() (int32, error) { func (p *Process) NumCtxSwitches() (int32, error) {
return 0, errors.New("Not implemented yet") return 0, errors.New("not implemented yet")
} }
func (p *Process) Num_fds() (int32, error) { func (p *Process) NumFDs() (int32, error) {
return 0, errors.New("Not implemented yet") return 0, errors.New("not implemented yet")
} }
func (p *Process) Num_Threads() (int32, error) { func (p *Process) NumThreads() (int32, error) {
_, _, _, _, num_threads, err := p.fillFromStatus() _, _, _, _, numThreads, err := p.fillFromStatus()
if err != nil { if err != nil {
return 0, err return 0, err
} }
return num_threads, nil return numThreads, nil
} }
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, nil return ret, nil
} }
func (p *Process) Cpu_times() (*CPU_TimesStat, error) { func (p *Process) CPUTimes() (*CPUTimesStat, error) {
_, _, cpu_times, _, _, err := p.fillFromStat() _, _, cpuTimes, _, _, err := p.fillFromStat()
if err != nil { if err != nil {
return nil, err return nil, err
} }
return cpu_times, nil return cpuTimes, nil
} }
func (p *Process) Cpu_percent() (int32, error) { func (p *Process) CPUPpercent() (int32, error) {
return 0, errors.New("Not implemented yet") return 0, errors.New("not implemented yet")
} }
func (p *Process) Cpu_affinity() ([]int32, error) { func (p *Process) CPUAffinity() ([]int32, error) {
return nil, errors.New("Not implemented yet") return nil, errors.New("not implemented yet")
} }
func (p *Process) Memory_info() (*Memory_infoStat, error) { func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
mem_info, _, err := p.fillFromStatm() memInfo, _, err := p.fillFromStatm()
if err != nil { if err != nil {
return nil, err return nil, err
} }
return mem_info, nil return memInfo, nil
} }
func (p *Process) Memory_info_ex() (*Memory_info_exStat, error) { func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
_, mem_info_ex, err := p.fillFromStatm() _, memInfoEx, err := p.fillFromStatm()
if err != nil { if err != nil {
return nil, err return nil, err
} }
return mem_info_ex, nil return memInfoEx, nil
} }
func (p *Process) Memory_percent() (float32, error) { func (p *Process) MemoryPercent() (float32, error) {
return 0, errors.New("Not implemented yet") return 0, errors.New("not implemented yet")
} }
func (p *Process) Children() ([]*Process, error) { func (p *Process) Children() ([]*Process, error) {
return nil, errors.New("Not implemented yet") return nil, errors.New("not implemented yet")
} }
func (p *Process) Open_files() ([]Open_filesStat, error) { func (p *Process) OpenFiles() ([]OpenFilesStat, error) {
return nil, errors.New("Not implemented yet") return nil, errors.New("not implemented yet")
} }
func (p *Process) Connections() ([]Net_connectionStat, error) { func (p *Process) Connections() ([]Net_connectionStat, error) {
return nil, errors.New("Not implemented yet") return nil, errors.New("not implemented yet")
} }
func (p *Process) Is_running() (bool, error) { func (p *Process) IsRunning() (bool, error) {
return true, errors.New("Not implemented yet") return true, errors.New("not implemented yet")
} }
// Get memory maps from /proc/(pid)/smaps // MemoryMaps get memory maps from /proc/(pid)/smaps
func (p *Process) Memory_Maps(grouped bool) (*[]Memory_mapsStat, error) { func (p *Process) MemoryMaps(grouped bool) (*[]MemoryMapsStat, error) {
pid := p.Pid pid := p.Pid
ret := make([]Memory_mapsStat, 0) var ret []MemoryMapsStat
smapsPath := filepath.Join("/", "proc", strconv.Itoa(int(pid)), "smaps") smapsPath := filepath.Join("/", "proc", strconv.Itoa(int(pid)), "smaps")
contents, err := ioutil.ReadFile(smapsPath) contents, err := ioutil.ReadFile(smapsPath)
if err != nil { if err != nil {
@ -199,8 +199,8 @@ func (p *Process) Memory_Maps(grouped bool) (*[]Memory_mapsStat, error) {
lines := strings.Split(string(contents), "\n") lines := strings.Split(string(contents), "\n")
// function of parsing a block // function of parsing a block
get_block := func(first_line []string, block []string) Memory_mapsStat { getBlock := func(first_line []string, block []string) MemoryMapsStat {
m := Memory_mapsStat{} m := MemoryMapsStat{}
m.Path = first_line[len(first_line)-1] m.Path = first_line[len(first_line)-1]
for _, line := range block { for _, line := range block {
@ -217,13 +217,13 @@ func (p *Process) Memory_Maps(grouped bool) (*[]Memory_mapsStat, error) {
case "Pss": case "Pss":
m.Pss = parseUint64(v) m.Pss = parseUint64(v)
case "Shared_Clean": case "Shared_Clean":
m.Shared_clean = parseUint64(v) m.SharedClean = parseUint64(v)
case "Shared_Dirty": case "Shared_Dirty":
m.Shared_dirty = parseUint64(v) m.SharedDirty = parseUint64(v)
case "Private_Clean": case "Private_Clean":
m.Private_clean = parseUint64(v) m.PrivateClean = parseUint64(v)
case "Private_Dirty": case "Private_Dirty":
m.Private_dirty = parseUint64(v) m.PrivateDirty = parseUint64(v)
case "Referenced": case "Referenced":
m.Referenced = parseUint64(v) m.Referenced = parseUint64(v)
case "Anonymous": case "Anonymous":
@ -241,7 +241,7 @@ func (p *Process) Memory_Maps(grouped bool) (*[]Memory_mapsStat, error) {
if strings.HasSuffix(field[0], ":") == false { if strings.HasSuffix(field[0], ":") == false {
// new block section // new block section
if len(blocks) > 0 { if len(blocks) > 0 {
ret = append(ret, get_block(field, blocks)) ret = append(ret, getBlock(field, blocks))
} }
// starts new block // starts new block
blocks = make([]string, 16) blocks = make([]string, 16)
@ -267,9 +267,9 @@ func (p *Process) fillFromfd() (int32, []*Open_filesStat, error) {
} }
defer d.Close() defer d.Close()
fnames, err := d.Readdirnames(-1) fnames, err := d.Readdirnames(-1)
num_fds := int32(len(fnames)) numFDs := int32(len(fnames))
openfiles := make([]*Open_filesStat, num_fds) openfiles := make([]*OpenFilesStat, numFDs)
for _, fd := range fnames { for _, fd := range fnames {
fpath := filepath.Join(statPath, fd) fpath := filepath.Join(statPath, fd)
filepath, err := os.Readlink(fpath) filepath, err := os.Readlink(fpath)
@ -283,7 +283,7 @@ func (p *Process) fillFromfd() (int32, []*Open_filesStat, error) {
openfiles = append(openfiles, o) openfiles = append(openfiles, o)
} }
return num_fds, openfiles, nil return numFDs, openfiles, nil
} }
// Get cwd from /proc/(pid)/cwd // Get cwd from /proc/(pid)/cwd
@ -339,11 +339,11 @@ func (p *Process) fillFromStatm() (*Memory_infoStat, *Memory_info_exStat, error)
rss := parseUint64(fields[0]) * PAGESIZE rss := parseUint64(fields[0]) * PAGESIZE
vms := parseUint64(fields[1]) * PAGESIZE vms := parseUint64(fields[1]) * PAGESIZE
mem_info := &Memory_infoStat{ memInfo := &MemoryInfoStat{
RSS: rss, RSS: rss,
VMS: vms, VMS: vms,
} }
mem_info_ex := &Memory_info_exStat{ memInfoEx := &MemoryInfoExStat{
RSS: rss, RSS: rss,
VMS: vms, VMS: vms,
Shared: parseUint64(fields[2]) * PAGESIZE, Shared: parseUint64(fields[2]) * PAGESIZE,
@ -352,7 +352,7 @@ func (p *Process) fillFromStatm() (*Memory_infoStat, *Memory_info_exStat, error)
Dirty: parseUint64(fields[5]) * PAGESIZE, Dirty: parseUint64(fields[5]) * PAGESIZE,
} }
return mem_info, mem_info_ex, nil return memInfo, memInfoEx, nil
} }
// Get various status from /proc/(pid)/status // Get various status from /proc/(pid)/status
@ -367,9 +367,9 @@ func (p *Process) fillFromStatus() (string, string, []int32, []int32, int32, err
name := "" name := ""
status := "" status := ""
var num_threads int32 var numThreads int32
uids := make([]int32, 0) var uids []int32
gids := make([]int32, 0) var gids []int32
for _, line := range lines { for _, line := range lines {
field := strings.Split(line, ":") field := strings.Split(line, ":")
if len(field) < 2 { if len(field) < 2 {
@ -394,14 +394,14 @@ func (p *Process) fillFromStatus() (string, string, []int32, []int32, int32, err
gids = append(gids, parseInt32(i)) gids = append(gids, parseInt32(i))
} }
case "Threads": case "Threads":
num_threads = parseInt32(field[1]) numThreads = parseInt32(field[1])
} }
} }
return name, status, uids, gids, num_threads, nil return name, status, uids, gids, numThreads, nil
} }
func (p *Process) fillFromStat() (string, int32, *CPU_TimesStat, int64, int32, error) { func (p *Process) fillFromStat() (string, int32, *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)
@ -420,26 +420,26 @@ func (p *Process) fillFromStat() (string, int32, *CPU_TimesStat, int64, int32, e
utime, _ := strconv.ParseFloat(fields[13], 64) utime, _ := strconv.ParseFloat(fields[13], 64)
stime, _ := strconv.ParseFloat(fields[14], 64) stime, _ := strconv.ParseFloat(fields[14], 64)
cpu_times := &CPU_TimesStat{ cpuTimes := &CPUTimesStat{
Cpu: "cpu", Cpu: "cpu",
User: float32(utime * (1000 / CLOCK_TICKS)), User: float32(utime * (1000 / CLOCK_TICKS)),
System: float32(stime * (1000 / CLOCK_TICKS)), System: float32(stime * (1000 / CLOCK_TICKS)),
} }
boot_time, _ := Boot_time() bootTime, _ := BootTime()
ctime := ((parseUint64(fields[21]) / uint64(CLOCK_TICKS)) + uint64(boot_time)) * 1000 ctime := ((parseUint64(fields[21]) / uint64(CLOCK_TICKS)) + uint64(bootTime)) * 1000
create_time := int64(ctime) createTime := int64(ctime)
// p.Nice = parseInt32(fields[18]) // p.Nice = parseInt32(fields[18])
// use syscall instead of parse Stat file // use syscall instead of parse Stat file
snice, _ := syscall.Getpriority(PRIO_PROCESS, int(pid)) snice, _ := syscall.Getpriority(PRIO_PROCESS, int(pid))
nice := int32(snice) // FIXME: is this true? nice := int32(snice) // FIXME: is this true?
return terminal, ppid, cpu_times, create_time, nice, nil return terminal, ppid, cpuTimes, createTime, nice, nil
} }
func Pids() ([]int32, error) { func Pids() ([]int32, error) {
ret := make([]int32, 0) var ret []int32
d, err := os.Open("/proc") d, err := os.Open("/proc")
if err != nil { if err != nil {

@ -24,7 +24,7 @@ func Test_Pid_exists(t *testing.T) {
check_pid = 0 check_pid = 0
} }
ret, err := Pid_exists(int32(check_pid)) ret, err := PidExists(int32(check_pid))
if err != nil { if err != nil {
t.Errorf("error %v", err) t.Errorf("error %v", err)
} }
@ -57,7 +57,7 @@ func Test_Process_memory_maps(t *testing.T) {
return return
ret, err := NewProcess(int32(check_pid)) ret, err := NewProcess(int32(check_pid))
mmaps, err := ret.Memory_Maps(false) mmaps, err := ret.MemoryMaps(false)
if err != nil { if err != nil {
t.Errorf("memory map get error %v", err) t.Errorf("memory map get error %v", err)
} }

@ -19,7 +19,7 @@ type SYSTEM_PROCESS_INFORMATION struct {
NumberOfThreads uint64 NumberOfThreads uint64
Reserved1 [48]byte Reserved1 [48]byte
Reserved2 [3]byte Reserved2 [3]byte
UniqueProcessId uintptr UniqueProcessID uintptr
Reserved3 uintptr Reserved3 uintptr
HandleCount uint64 HandleCount uint64
Reserved4 [4]byte Reserved4 [4]byte
@ -30,15 +30,15 @@ type SYSTEM_PROCESS_INFORMATION struct {
} }
// Memory_info_ex is different between OSes // Memory_info_ex is different between OSes
type Memory_info_exStat struct { type MemoryInfoExStat struct {
} }
type Memory_mapsStat struct { type MemoryMapsStat struct {
} }
func Pids() ([]int32, error) { func Pids() ([]int32, error) {
ret := make([]int32, 0) var ret []int32
procs, err := processes() procs, err := processes()
if err != nil { if err != nil {
@ -60,7 +60,7 @@ func (p *Process) Ppid() (int32, error) {
} }
func (p *Process) Name() (string, error) { func (p *Process) Name() (string, error) {
name := "" name := ""
return name, errors.New("Not implemented yet") return name, errors.New("not implemented yet")
} }
func (p *Process) Exe() (string, error) { func (p *Process) Exe() (string, error) {
_, _, ret, err := p.getFromSnapProcess(p.Pid) _, _, ret, err := p.getFromSnapProcess(p.Pid)
@ -70,51 +70,53 @@ 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 "", errors.New("Not implemented yet") return "", errors.New("not implemented yet")
} }
func (p *Process) Cwd() (string, error) { func (p *Process) Cwd() (string, error) {
return "", errors.New("Not implemented yet") return "", errors.New("not implemented yet")
} }
func (p *Process) Parent() (*Process, error) { func (p *Process) Parent() (*Process, error) {
return p, errors.New("Not implemented yet") return p, errors.New("not implemented yet")
} }
func (p *Process) Status() (string, error) { func (p *Process) Status() (string, error) {
return "", errors.New("Not implemented yet") return "", errors.New("not implemented yet")
} }
func (p *Process) Username() (string, error) { func (p *Process) Username() (string, error) {
return "", errors.New("Not implemented yet") return "", errors.New("not implemented yet")
} }
func (p *Process) Uids() ([]int32, error) { func (p *Process) Uids() ([]int32, error) {
uids := make([]int32, 0) var uids []int32
return uids, errors.New("Not implemented yet")
return uids, errors.New("not implemented yet")
} }
func (p *Process) Gids() ([]int32, error) { func (p *Process) Gids() ([]int32, error) {
gids := make([]int32, 0) var gids []int32
return gids, errors.New("Not implemented yet") return gids, errors.New("not implemented yet")
} }
func (p *Process) Terminal() (string, error) { func (p *Process) Terminal() (string, error) {
return "", errors.New("Not implemented yet") return "", errors.New("not implemented yet")
} }
func (p *Process) Nice() (int32, error) { func (p *Process) Nice() (int32, error) {
return 0, errors.New("Not implemented yet") return 0, errors.New("not implemented yet")
} }
func (p *Process) Ionice() (int32, error) { func (p *Process) Ionice() (int32, error) {
return 0, errors.New("Not implemented yet") return 0, errors.New("not implemented yet")
} }
func (p *Process) Rlimit() ([]RlimitStat, error) { func (p *Process) Rlimit() ([]RlimitStat, error) {
rlimit := make([]RlimitStat, 0) var rlimit []RlimitStat
return rlimit, errors.New("Not implemented yet")
return rlimit, errors.New("not implemented yet")
} }
func (p *Process) Io_counters() (*Io_countersStat, error) { func (p *Process) IoCounters() (*IoCountersStat, error) {
return nil, errors.New("Not implemented yet") return nil, errors.New("not implemented yet")
} }
func (p *Process) Num_ctx_switches() (int32, error) { func (p *Process) NumCtxSwitches() (int32, error) {
return 0, errors.New("Not implemented yet") return 0, errors.New("not implemented yet")
} }
func (p *Process) Num_fds() (int32, error) { func (p *Process) NumFDs() (int32, error) {
return 0, errors.New("Not implemented yet") return 0, errors.New("not implemented yet")
} }
func (p *Process) Num_Threads() (int32, error) { func (p *Process) NumThreads() (int32, error) {
_, ret, _, err := p.getFromSnapProcess(p.Pid) _, ret, _, err := p.getFromSnapProcess(p.Pid)
if err != nil { if err != nil {
return 0, err return 0, err
@ -123,45 +125,45 @@ func (p *Process) Num_Threads() (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, errors.New("Not implemented yet") return ret, errors.New("not implemented yet")
} }
func (p *Process) Cpu_times() (*CPU_TimesStat, error) { func (p *Process) CPUTimes() (*CPUTimesStat, error) {
return nil, errors.New("Not implemented yet") return nil, errors.New("not implemented yet")
} }
func (p *Process) Cpu_percent() (int32, error) { func (p *Process) CPUPercent() (int32, error) {
return 0, errors.New("Not implemented yet") return 0, errors.New("not implemented yet")
} }
func (p *Process) Cpu_affinity() ([]int32, error) { func (p *Process) CPUAffinity() ([]int32, error) {
return nil, errors.New("Not implemented yet") return nil, errors.New("not implemented yet")
} }
func (p *Process) Memory_info() (*Memory_infoStat, error) { func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
return nil, errors.New("Not implemented yet") return nil, errors.New("not implemented yet")
} }
func (p *Process) Memory_info_ex() (*Memory_info_exStat, error) { func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
return nil, errors.New("Not implemented yet") return nil, errors.New("not implemented yet")
} }
func (p *Process) Memory_percent() (float32, error) { func (p *Process) MemoryPercent() (float32, error) {
return 0, errors.New("Not implemented yet") return 0, errors.New("not implemented yet")
} }
func (p *Process) Children() ([]*Process, error) { func (p *Process) Children() ([]*Process, error) {
return nil, errors.New("Not implemented yet") return nil, errors.New("not implemented yet")
} }
func (p *Process) Open_files() ([]Open_filesStat, error) { func (p *Process) OpenFiles() ([]OpenFilesStat, error) {
return nil, errors.New("Not implemented yet") return nil, errors.New("not implemented yet")
} }
func (p *Process) Connections() ([]Net_connectionStat, error) { func (p *Process) Connections() ([]NetConnectionStat, error) {
return nil, errors.New("Not implemented yet") return nil, errors.New("not implemented yet")
} }
func (p *Process) Is_running() (bool, error) { func (p *Process) IsRunning() (bool, error) {
return true, errors.New("Not implemented yet") return true, errors.New("not implemented yet")
} }
func (p *Process) Memory_Maps(grouped bool) (*[]Memory_mapsStat, error) { func (p *Process) MemoryMaps(grouped bool) (*[]MemoryMapsStat, error) {
return nil, errors.New("Not implemented yet") return nil, errors.New("not implemented yet")
} }
func NewProcess(pid int32) (*Process, error) { func NewProcess(pid int32) (*Process, error) {
@ -170,21 +172,21 @@ func NewProcess(pid int32) (*Process, error) {
return p, nil return p, nil
} }
func (p *Process) Send_signal(sig syscall.Signal) error { func (p *Process) SendSignal(sig syscall.Signal) error {
return errors.New("Not implemented yet") return errors.New("not implemented yet")
} }
func (p *Process) Suspend() error { func (p *Process) Suspend() error {
return errors.New("Not implemented yet") return errors.New("not implemented yet")
} }
func (p *Process) Resume() error { func (p *Process) Resume() error {
return errors.New("Not implemented yet") return errors.New("not implemented yet")
} }
func (p *Process) Terminate() error { func (p *Process) Terminate() error {
return errors.New("Not implemented yet") return errors.New("not implemented yet")
} }
func (p *Process) Kill() error { func (p *Process) Kill() error {
return errors.New("Not implemented yet") return errors.New("not implemented yet")
} }
func (p *Process) getFromSnapProcess(pid int32) (int32, int32, string, error) { func (p *Process) getFromSnapProcess(pid int32) (int32, int32, string, error) {
@ -216,14 +218,14 @@ func (p *Process) getFromSnapProcess(pid int32) (int32, int32, string, error) {
// Get processes // Get processes
func processes() ([]*Process, error) { func processes() ([]*Process, error) {
ps := make([]uint32, 255) ps := make([]uint32, 255)
var read uint32 = 0 var read uint32
if w32.EnumProcesses(ps, uint32(len(ps)), &read) == false { if w32.EnumProcesses(ps, uint32(len(ps)), &read) == false {
return nil, syscall.GetLastError() return nil, syscall.GetLastError()
} }
results := make([]*Process, 0) var results []*Process
dward_size := uint32(4) dwardSize := uint32(4)
for _, pid := range ps[:read/dward_size] { for _, pid := range ps[:read/dwardSize] {
if pid == 0 { if pid == 0 {
continue continue
} }
@ -237,14 +239,14 @@ func processes() ([]*Process, error) {
return results, nil return results, nil
} }
func get_proc_info(pid int32) (*SYSTEM_PROCESS_INFORMATION, error) { func getProcInfo(pid int32) (*SYSTEM_PROCESS_INFORMATION, error) {
initialBufferSize := uint64(0x4000) initialBufferSize := uint64(0x4000)
bufferSize := initialBufferSize bufferSize := initialBufferSize
buffer := make([]byte, bufferSize) buffer := make([]byte, bufferSize)
var sys_proc_info SYSTEM_PROCESS_INFORMATION var sysProcInfo SYSTEM_PROCESS_INFORMATION
ret, _, _ := procNtQuerySystemInformation.Call( ret, _, _ := procNtQuerySystemInformation.Call(
uintptr(unsafe.Pointer(&sys_proc_info)), uintptr(unsafe.Pointer(&sysProcInfo)),
uintptr(unsafe.Pointer(&buffer[0])), uintptr(unsafe.Pointer(&buffer[0])),
uintptr(unsafe.Pointer(&bufferSize)), uintptr(unsafe.Pointer(&bufferSize)),
uintptr(unsafe.Pointer(&bufferSize))) uintptr(unsafe.Pointer(&bufferSize)))
@ -252,5 +254,5 @@ func get_proc_info(pid int32) (*SYSTEM_PROCESS_INFORMATION, error) {
return nil, syscall.GetLastError() return nil, syscall.GetLastError()
} }
return &sys_proc_info, nil return &sysProcInfo, nil
} }

Loading…
Cancel
Save