golint on Linux

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

@ -13,7 +13,7 @@ import (
"strings" "strings"
) )
// Read contents from file and split by new line. // ReadLines read contents from file and split by new line.
func ReadLines(filename string) ([]string, error) { func ReadLines(filename string) ([]string, error) {
f, err := os.Open(filename) f, err := os.Open(filename)
if err != nil { if err != nil {
@ -21,7 +21,7 @@ func ReadLines(filename string) ([]string, error) {
} }
defer f.Close() defer f.Close()
ret := make([]string, 0) var ret []string
r := bufio.NewReader(f) r := bufio.NewReader(f)
line, err := r.ReadString('\n') line, err := r.ReadString('\n')
@ -52,9 +52,8 @@ func byteToString(orig []byte) string {
} }
if n == -1 { if n == -1 {
return string(orig) return string(orig)
} else {
return string(orig[l:n])
} }
return string(orig[l:n])
} }
// Parse to int32 without error // Parse to int32 without error

@ -7,7 +7,7 @@ import (
"strings" "strings"
) )
func do_sysctrl(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

@ -5,20 +5,20 @@ import (
) )
type CPUTimesStat 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"`
Idle float32 `json:"idle"` Idle float32 `json:"idle"`
Nice float32 `json:"nice"` Nice float32 `json:"nice"`
Iowait float32 `json:"iowait"` Iowait float32 `json:"iowait"`
Irq float32 `json:"irq"` Irq float32 `json:"irq"`
Softirq float32 `json:"softirq"` Softirq float32 `json:"softirq"`
Steal float32 `json:"steal"` Steal float32 `json:"steal"`
Guest float32 `json:"guest"` Guest float32 `json:"guest"`
Guest_nice float32 `json:"guest_nice"` GuestNice float32 `json:"guest_nice"`
Stolen float32 `json:"stolen"` Stolen float32 `json:"stolen"`
} }
func CpuCounts(logical bool) (int, error) { func CPUCounts(logical bool) (int, error) {
return runtime.NumCPU(), nil return runtime.NumCPU(), nil
} }

@ -23,20 +23,20 @@ const (
// TODO: get per cpus // TODO: get per cpus
func CPUTimes(percpu bool) ([]CPUTimesStat, error) { func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
ret := make([]CPU_TimesStat, 0) var ret []CPU_TimesStat
cpu_time, err := do_sysctrl("kern.cp_time") cpuTime, err := doSysctrl("kern.cp_time")
if err != nil { if err != nil {
return ret, err return ret, err
} }
user, _ := strconv.ParseFloat(cpu_time[CP_USER], 32) user, _ := strconv.ParseFloat(cpuTime[CP_USER], 32)
nice, _ := strconv.ParseFloat(cpu_time[CP_NICE], 32) nice, _ := strconv.ParseFloat(cpuTime[CP_NICE], 32)
sys, _ := strconv.ParseFloat(cpu_time[CP_SYS], 32) sys, _ := strconv.ParseFloat(cpuTime[CP_SYS], 32)
idle, _ := strconv.ParseFloat(cpu_time[CP_IDLE], 32) idle, _ := strconv.ParseFloat(cpuTime[CP_IDLE], 32)
intr, _ := strconv.ParseFloat(cpu_time[CP_INTR], 32) intr, _ := strconv.ParseFloat(cpuTime[CP_INTR], 32)
c := CPU_TimesStat{ c := CPUTimesStat{
User: float32(user / CLOCKS_PER_SEC), User: float32(user / CLOCKS_PER_SEC),
Nice: float32(nice / CLOCKS_PER_SEC), Nice: float32(nice / CLOCKS_PER_SEC),
System: float32(sys / CLOCKS_PER_SEC), System: float32(sys / CLOCKS_PER_SEC),

@ -8,8 +8,8 @@ import (
"strings" "strings"
) )
func Cpu_times(percpu bool) ([]CPU_TimesStat, error) { func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
ret := make([]CPU_TimesStat, 0) var ret []CPUTimesStat
filename := "/proc/stat" filename := "/proc/stat"
lines, _ := ReadLines(filename) lines, _ := ReadLines(filename)
@ -24,12 +24,12 @@ func Cpu_times(percpu bool) ([]CPU_TimesStat, error) {
return ret, nil return ret, nil
} }
func parseStatLine(line string) (CPU_TimesStat, error) { func parseStatLine(line string) (CPUTimesStat, error) {
fields := strings.Fields(line) fields := strings.Fields(line)
if strings.HasPrefix(fields[0], "cpu") == false { if strings.HasPrefix(fields[0], "cpu") == false {
// return CPU_TimesStat{}, e // return CPUTimesStat{}, e
return CPU_TimesStat{}, errors.New("not contain cpu") return CPUTimesStat{}, errors.New("not contain cpu")
} }
cpu := fields[0] cpu := fields[0]
@ -44,8 +44,8 @@ func parseStatLine(line string) (CPU_TimesStat, error) {
irq, _ := strconv.ParseFloat(fields[6], 32) irq, _ := strconv.ParseFloat(fields[6], 32)
softirq, _ := strconv.ParseFloat(fields[7], 32) softirq, _ := strconv.ParseFloat(fields[7], 32)
stolen, _ := strconv.ParseFloat(fields[8], 32) stolen, _ := strconv.ParseFloat(fields[8], 32)
ct := CPU_TimesStat{ ct := CPUTimesStat{
Cpu: cpu, CPU: cpu,
User: float32(user), User: float32(user),
Nice: float32(nice), Nice: float32(nice),
System: float32(system), System: float32(system),
@ -64,8 +64,8 @@ func parseStatLine(line string) (CPU_TimesStat, error) {
ct.Guest = float32(guest) ct.Guest = float32(guest)
} }
if len(fields) > 11 { // Linux >= 3.2.0 if len(fields) > 11 { // Linux >= 3.2.0
guest_nice, _ := strconv.ParseFloat(fields[11], 32) guestNice, _ := strconv.ParseFloat(fields[11], 32)
ct.Guest_nice = float32(guest_nice) ct.GuestNice = float32(guestNice)
} }
return ct, nil return ct, nil

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

@ -9,7 +9,7 @@ import (
) )
func DiskPartitions(all bool) ([]DiskPartitionStat, error) { func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
ret := make([]Disk_partitionStat, 0) var ret []Disk_partitionStat
// get length // get length
count, err := syscall.Getfsstat(nil, MNT_WAIT) count, err := syscall.Getfsstat(nil, MNT_WAIT)
@ -72,8 +72,8 @@ func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
} }
d := Disk_partitionStat{ d := Disk_partitionStat{
Mountpoint: byteToString(stat.F_mntonname[:]), Mountpoint: byteToString(stat.FMntonname[:]),
Fstype: byteToString(stat.F_fstypename[:]), Fstype: byteToString(stat.FFstypename[:]),
Opts: opts, Opts: opts,
} }
ret = append(ret, d) ret = append(ret, d)
@ -83,7 +83,7 @@ func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
} }
func DiskIOCounters() (map[string]DiskIOCountersStat, 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")
} }

@ -30,26 +30,26 @@ const (
) )
type Statfs struct { type Statfs struct {
F_version uint32 /* structure version number */ FVersion uint32 /* structure version number */
F_type uint32 /* type of filesystem */ FType uint32 /* type of filesystem */
F_flags uint64 /* copy of mount exported flags */ FFlags uint64 /* copy of mount exported flags */
F_bsize uint64 /* filesystem fragment size */ FBsize uint64 /* filesystem fragment size */
F_iosize uint64 /* optimal transfer block size */ FIosize uint64 /* optimal transfer block size */
F_blocks uint64 /* total data blocks in filesystem */ FBlocks uint64 /* total data blocks in filesystem */
F_bfree uint64 /* free blocks in filesystem */ FBfree uint64 /* free blocks in filesystem */
F_bavail int64 /* free blocks avail to non-superuser */ FBavail int64 /* free blocks avail to non-superuser */
F_files uint64 /* total file nodes in filesystem */ FFiles uint64 /* total file nodes in filesystem */
F_ffree int64 /* free nodes avail to non-superuser */ FFfree int64 /* free nodes avail to non-superuser */
F_syncwrites uint64 /* count of sync writes since mount */ FSyncwrites uint64 /* count of sync writes since mount */
F_asyncwrites uint64 /* count of async writes since mount */ FAsyncwrites uint64 /* count of async writes since mount */
F_syncreads uint64 /* count of sync reads since mount */ FSyncreads uint64 /* count of sync reads since mount */
F_asyncreads uint64 /* count of async reads since mount */ FAsyncreads uint64 /* count of async reads since mount */
F_spare [10]uint64 /* unused spare */ FSpare [10]uint64 /* unused spare */
F_namemax uint32 /* maximum filename length */ FNamemax uint32 /* maximum filename length */
F_owner uint32 /* user that mounted the filesystem */ FOwner uint32 /* user that mounted the filesystem */
F_fsid int32 /* filesystem id */ FFsid int32 /* filesystem id */
F_charspare [80]byte /* spare string space */ FCharspare [80]byte /* spare string space */
F_fstypename [MFSNAMELEN]byte /* filesystem type name */ FFstypename [MFSNAMELEN]byte /* filesystem type name */
F_mntfromname [MNAMELEN]byte /* mounted filesystem */ FMntfromname [MNAMELEN]byte /* mounted filesystem */
F_mntonname [MNAMELEN]byte /* directory on which mounted */ FMntonname [MNAMELEN]byte /* directory on which mounted */
} }

@ -14,7 +14,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 DiskPartitions(all bool) ([]DiskPartitionStat, error) { func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
ret := make([]Disk_partitionStat, 0) var ret []DiskPartitionStat
filename := "/etc/mtab" filename := "/etc/mtab"
lines, err := ReadLines(filename) lines, err := ReadLines(filename)
@ -24,7 +24,7 @@ func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
for _, line := range lines { for _, line := range lines {
fields := strings.Fields(line) fields := strings.Fields(line)
d := Disk_partitionStat{ d := DiskPartitionStat{
Mountpoint: fields[1], Mountpoint: fields[1],
Fstype: fields[2], Fstype: fields[2],
Opts: fields[3], Opts: fields[3],
@ -36,7 +36,7 @@ func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
} }
func DiskIOCounters() (map[string]DiskIOCountersStat, error) { func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
ret := make(map[string]Disk_IO_CountersStat, 0) ret := make(map[string]DiskIOCountersStat, 0)
// determine partitions we want to look for // determine partitions we want to look for
filename := "/proc/partitions" filename := "/proc/partitions"
@ -44,7 +44,7 @@ func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
if err != nil { if err != nil {
return ret, err return ret, err
} }
partitions := make([]string, 0) var partitions []string
for _, line := range lines[2:] { for _, line := range lines[2:] {
fields := strings.Fields(line) fields := strings.Fields(line)
@ -76,7 +76,7 @@ func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
wbytes := parseUint64(fields[9]) wbytes := parseUint64(fields[9])
wtime := parseUint64(fields[10]) wtime := parseUint64(fields[10])
if stringContains(partitions, name) { if stringContains(partitions, name) {
d := Disk_IO_CountersStat{ d := DiskIOCountersStat{
Name: name, Name: name,
ReadBytes: rbytes * SECTOR_SIZE, ReadBytes: rbytes * SECTOR_SIZE,
WriteBytes: wbytes * SECTOR_SIZE, WriteBytes: wbytes * SECTOR_SIZE,

@ -8,12 +8,12 @@ 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 {
return Disk_usageStat{Path: path}, err return DiskUsageStat{Path: path}, err
} }
bsize := stat.Bsize / 512 bsize := stat.Bsize / 512
ret := Disk_usageStat{ ret := DiskUsageStat{
Path: path, Path: path,
Total: (uint64(stat.Blocks) * uint64(bsize)) >> 1, Total: (uint64(stat.Blocks) * uint64(bsize)) >> 1,
Free: (uint64(stat.Bfree) * uint64(bsize)) >> 1, Free: (uint64(stat.Bfree) * uint64(bsize)) >> 1,

@ -46,7 +46,7 @@ func DiskUsage(path string) (DiskUsageStat, error) {
} }
func DiskPartitions(all bool) ([]DiskPartitionStat, error) { func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
ret := make([]DiskPartitionStat, 0) var ret []DiskPartitionStat
lpBuffer := make([]byte, 254) lpBuffer := make([]byte, 254)
diskret, _, err := procGetLogicalDriveStringsW.Call( diskret, _, err := procGetLogicalDriveStringsW.Call(
uintptr(len(lpBuffer)), uintptr(len(lpBuffer)),

@ -25,7 +25,7 @@ func HostInfo() (HostInfoStat, error) {
} }
func BootTime() (int64, error) { func BootTime() (int64, error) {
values, err := do_sysctrl("kern.boottime") values, err := doSysctrl("kern.boottime")
if err != nil { if err != nil {
return 0, err return 0, err
} }
@ -42,7 +42,7 @@ func BootTime() (int64, error) {
func Users() ([]UserStat, error) { func Users() ([]UserStat, error) {
utmpfile := "/var/run/utmp" utmpfile := "/var/run/utmp"
ret := make([]UserStat, 0) var ret []UserStat
file, err := os.Open(utmpfile) file, err := os.Open(utmpfile)
if err != nil { if err != nil {

@ -10,8 +10,8 @@ const (
) )
type utmp struct { type utmp struct {
Ut_line [UT_LINESIZE]byte UtLine [UT_LINESIZE]byte
Ut_name [UT_NAMESIZE]byte UtName [UT_NAMESIZE]byte
Ut_host [UT_HOSTSIZE]byte UtHost [UT_HOSTSIZE]byte
Ut_time int32 UtTime int32
} }

@ -23,7 +23,7 @@ func HostInfo() (HostInfoStat, error) {
return ret, nil return ret, nil
} }
func Boot_time() (int64, error) { func BootTime() (int64, error) {
sysinfo := &syscall.Sysinfo_t{} sysinfo := &syscall.Sysinfo_t{}
if err := syscall.Sysinfo(sysinfo); err != nil { if err := syscall.Sysinfo(sysinfo); err != nil {
return 0, err return 0, err
@ -33,7 +33,7 @@ func Boot_time() (int64, error) {
func Users() ([]UserStat, error) { func Users() ([]UserStat, error) {
utmpfile := "/var/run/utmp" utmpfile := "/var/run/utmp"
ret := make([]UserStat, 0) var ret []UserStat
file, err := os.Open(utmpfile) file, err := os.Open(utmpfile)
if err != nil { if err != nil {
@ -59,10 +59,10 @@ func Users() ([]UserStat, error) {
continue continue
} }
user := UserStat{ user := UserStat{
User: byteToString(u.Ut_user[:]), User: byteToString(u.UtUser[:]),
Terminal: byteToString(u.Ut_line[:]), Terminal: byteToString(u.UtLine[:]),
Host: byteToString(u.Ut_host[:]), Host: byteToString(u.UtHost[:]),
Started: int(u.Ut_tv.Tv_sec), Started: int(u.UtTv.TvSec),
} }
ret = append(ret, user) ret = append(ret, user)
} }

@ -3,25 +3,25 @@
package gopsutil package gopsutil
type exit_status struct { type exitStatus struct {
E_termination int16 // Process termination status. Etermination int16 // Process termination status.
E_exit int16 // Process exit status. Eexit int16 // Process exit status.
} }
type timeval struct { type timeval struct {
Tv_sec uint32 // Seconds. TvSec uint32 // Seconds.
Tv_usec uint32 // Microseconds. TvUsec uint32 // Microseconds.
} }
type utmp struct { type utmp struct {
Ut_type int16 // Type of login. UtType int16 // Type of login.
Ut_pid int32 // Process ID of login process. UtPid int32 // Process ID of login process.
Ut_line [32]byte // Devicename. UtLine [32]byte // Devicename.
Ut_id [4]byte // Inittab ID. UtID [4]byte // Inittab ID.
Ut_user [32]byte // Username. UtUser [32]byte // Username.
Ut_host [256]byte // Hostname for remote login. UtHost [256]byte // Hostname for remote login.
Ut_exit exit_status // Exit status of a process marked UtExit exitStatus // Exit status of a process marked
Ut_session int32 // Session ID, used for windowing. UtSession int32 // Session ID, used for windowing.
Ut_tv timeval // Time entry was made. UtTv timeval // Time entry was made.
Ut_addr_v6 [16]byte // Internet address of remote host. UtAddrV6 [16]byte // Internet address of remote host.
Unused [20]byte // Reserved for future use. // original is 20 Unused [20]byte // Reserved for future use. // original is 20
} }

@ -7,7 +7,7 @@ import (
) )
func LoadAvg() (LoadAvgStat, error) { func LoadAvg() (LoadAvgStat, error) {
values, err := do_sysctrl("vm.loadavg") values, err := doSysctrl("vm.loadavg")
if err != nil { if err != nil {
return LoadAvgStat{}, err return LoadAvgStat{}, err
} }

@ -7,7 +7,7 @@ import (
) )
func VirtualMemory() (VirtualMemoryStat, error) { func VirtualMemory() (VirtualMemoryStat, error) {
ret := Virtual_memoryStat{} ret := VirtualMemoryStat{}
sysinfo := &syscall.Sysinfo_t{} sysinfo := &syscall.Sysinfo_t{}
if err := syscall.Sysinfo(sysinfo); err != nil { if err := syscall.Sysinfo(sysinfo); err != nil {
@ -36,7 +36,7 @@ func VirtualMemory() (VirtualMemoryStat, error) {
} }
func SwapMemory() (SwapMemoryStat, error) { func SwapMemory() (SwapMemoryStat, error) {
ret := Swap_memoryStat{} ret := SwapMemoryStat{}
sysinfo := &syscall.Sysinfo_t{} sysinfo := &syscall.Sysinfo_t{}
if err := syscall.Sysinfo(sysinfo); err != nil { if err := syscall.Sysinfo(sysinfo); err != nil {

@ -13,7 +13,7 @@ type NetIOCountersStat struct {
} }
type Addr struct { type Addr struct {
Ip string `json:"ip""` IP string `json:"ip""`
Port uint32 `json:"port""` Port uint32 `json:"port""`
} }

@ -10,27 +10,27 @@ 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 {
return make([]Net_io_countersStat, 0), err return make([]NetIOCountersStat, 0), err
} }
statlen := len(lines) - 1 statlen := len(lines) - 1
ret := make([]Net_io_countersStat, 0, statlen) ret := make([]NetIOCountersStat, 0, statlen)
for _, line := range lines[2:] { for _, line := range lines[2:] {
fields := strings.Fields(line) fields := strings.Fields(line)
if fields[0] == "" { if fields[0] == "" {
continue continue
} }
nic := Net_io_countersStat{ nic := NetIOCountersStat{
Name: strings.Trim(fields[0], ":"), Name: strings.Trim(fields[0], ":"),
Bytes_recv: parseUint64(fields[1]), BytesRecv: parseUint64(fields[1]),
Errin: parseUint64(fields[2]), Errin: parseUint64(fields[2]),
Dropin: parseUint64(fields[3]), Dropin: parseUint64(fields[3]),
Bytes_sent: parseUint64(fields[9]), BytesSent: parseUint64(fields[9]),
Packets_sent: parseUint64(fields[10]), PacketsSent: parseUint64(fields[10]),
Errout: parseUint64(fields[11]), Errout: parseUint64(fields[11]),
Dropout: parseUint64(fields[12]), Dropout: parseUint64(fields[12]),
} }
ret = append(ret, nic) ret = append(ret, nic)
} }

@ -20,7 +20,7 @@ type RlimitStat struct {
Hard int32 `json:"hard"` Hard int32 `json:"hard"`
} }
type IoCountersStat struct { type IOCountersStat struct {
ReadCount int32 `json:"read_count"` ReadCount int32 `json:"read_count"`
WriteCount int32 `json:"write_count"` WriteCount int32 `json:"write_count"`
ReadBytes int32 `json:"read_bytes"` ReadBytes int32 `json:"read_bytes"`

@ -70,7 +70,7 @@ func (p *Process) Terminal() (string, error) {
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) {

@ -13,84 +13,84 @@ const (
) )
// copied from sys/user.h // copied from sys/user.h
type Kinfo_proc struct { type KinfoProc struct {
Ki_structsize int32 KiStructsize int32
Ki_layout int32 KiLayout int32
Ki_args int64 KiArgs int64
Ki_paddr int64 KiPaddr int64
Ki_addr int64 KiAddr int64
Ki_tracep int64 KiTracep int64
Ki_textvp int64 KiTextvp int64
Ki_fd int64 KiFd int64
Ki_vmspace int64 KiVmspace int64
Ki_wchan int64 KiWchan int64
Ki_pid int32 KiPid int32
Ki_ppid int32 KiPpid int32
Ki_pgid int32 KiPgid int32
Ki_tpgid int32 KiTpgid int32
Ki_sid int32 KiSid int32
Ki_tsid int32 KiTsid int32
Ki_jobc [2]byte KiJobc [2]byte
Ki_spare_short1 [2]byte KiSpareShort1 [2]byte
Ki_tdev int32 KiTdev int32
Ki_siglist [16]byte KiSiglist [16]byte
Ki_sigmask [16]byte KiSigmask [16]byte
Ki_sigignore [16]byte KiSigignore [16]byte
Ki_sigcatch [16]byte KiSigcatch [16]byte
Ki_uid int32 KiUID int32
Ki_ruid int32 KiRuid int32
Ki_svuid int32 KiSvuid int32
Ki_rgid int32 KiRgid int32
Ki_svgid int32 KiSvgid int32
Ki_ngroups [2]byte KiNgroups [2]byte
Ki_spare_short2 [2]byte KiSpareShort2 [2]byte
Ki_groups [64]byte KiGroups [64]byte
Ki_size int64 KiSize int64
Ki_rssize int64 KiRssize int64
Ki_swrss int64 KiSwrss int64
Ki_tsize int64 KiTsize int64
Ki_dsize int64 KiDsize int64
Ki_ssize int64 KiSsize int64
Ki_xstat [2]byte KiXstat [2]byte
Ki_acflag [2]byte KiAcflag [2]byte
Ki_pctcpu int32 KiPctcpu int32
Ki_estcpu int32 KiEstcpu int32
Ki_slptime int32 KiSlptime int32
Ki_swtime int32 KiSwtime int32
Ki_cow int32 KiCow int32
Ki_runtime int64 KiRuntime int64
Ki_start [16]byte KiStart [16]byte
Ki_childtime [16]byte KiChildtime [16]byte
Ki_flag int64 KiFlag int64
Ki_kiflag int64 KiKflag int64
Ki_traceflag int32 KiTraceflag int32
Ki_stat [1]byte KiStat [1]byte
Ki_nice [1]byte KiNice [1]byte
Ki_lock [1]byte KiLock [1]byte
Ki_rqindex [1]byte KiRqindex [1]byte
Ki_oncpu [1]byte KiOncpu [1]byte
Ki_lastcpu [1]byte KiLastcpu [1]byte
Ki_ocomm [17]byte KiOcomm [17]byte
Ki_wmesg [9]byte KiWmesg [9]byte
Ki_login [18]byte KiLogin [18]byte
Ki_lockname [9]byte KiLockname [9]byte
Ki_comm [20]byte KiComm [20]byte
Ki_emul [17]byte KiEmul [17]byte
Ki_sparestrings [68]byte KiSparestrings [68]byte
Ki_spareints [36]byte KiSpareints [36]byte
Ki_cr_flags int32 KiCrFlags int32
Ki_jid int32 KiJid int32
Ki_numthreads int32 KiNumthreads int32
Ki_tid int32 KiTid int32
Ki_pri int32 KiPri int32
Ki_rusage [144]byte KiRusage [144]byte
Ki_rusage_ch [144]byte KiRusageCh [144]byte
Ki_pcb int64 KiPcb int64
Ki_kstack int64 KiKstack int64
Ki_udata int64 KiUdata int64
Ki_tdaddr int64 KiTdaddr int64
Ki_spareptrs [48]byte KiSpareptrs [48]byte
Ki_spareint64s [96]byte KiSpareint64s [96]byte
Ki_sflag int64 KiSflag int64
Ki_tdflags int64 KiTdflags int64
} }

@ -114,7 +114,7 @@ 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) {
@ -179,7 +179,7 @@ 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")
} }
@ -258,7 +258,7 @@ func (p *Process) MemoryMaps(grouped bool) (*[]MemoryMapsStat, error) {
**/ **/
// Get num_fds from /proc/(pid)/fd // Get num_fds from /proc/(pid)/fd
func (p *Process) fillFromfd() (int32, []*Open_filesStat, error) { func (p *Process) fillFromfd() (int32, []*OpenFilesStat, error) {
pid := p.Pid pid := p.Pid
statPath := filepath.Join("/", "proc", strconv.Itoa(int(pid)), "fd") statPath := filepath.Join("/", "proc", strconv.Itoa(int(pid)), "fd")
d, err := os.Open(statPath) d, err := os.Open(statPath)
@ -276,7 +276,7 @@ func (p *Process) fillFromfd() (int32, []*Open_filesStat, error) {
if err != nil { if err != nil {
continue continue
} }
o := &Open_filesStat{ o := &OpenFilesStat{
Path: filepath, Path: filepath,
Fd: parseUint64(fd), Fd: parseUint64(fd),
} }
@ -328,7 +328,7 @@ func (p *Process) fillFromCmdline() (string, error) {
} }
// Get memory info from /proc/(pid)/statm // Get memory info from /proc/(pid)/statm
func (p *Process) fillFromStatm() (*Memory_infoStat, *Memory_info_exStat, error) { func (p *Process) fillFromStatm() (*MemoryInfoStat, *MemoryInfoExStat, error) {
pid := p.Pid pid := p.Pid
memPath := filepath.Join("/", "proc", strconv.Itoa(int(pid)), "statm") memPath := filepath.Join("/", "proc", strconv.Itoa(int(pid)), "statm")
contents, err := ioutil.ReadFile(memPath) contents, err := ioutil.ReadFile(memPath)
@ -421,7 +421,7 @@ func (p *Process) fillFromStat() (string, int32, *CPUTimesStat, int64, int32, er
stime, _ := strconv.ParseFloat(fields[14], 64) stime, _ := strconv.ParseFloat(fields[14], 64)
cpuTimes := &CPUTimesStat{ 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)),
} }

@ -13,7 +13,7 @@ import (
// POSIX // POSIX
func getTerminalMap() (map[uint64]string, error) { func getTerminalMap() (map[uint64]string, error) {
ret := make(map[uint64]string) ret := make(map[uint64]string)
termfiles := make([]string, 0) var termfiles []string
d, err := os.Open("/dev") d, err := os.Open("/dev")
if err != nil { if err != nil {
@ -48,20 +48,20 @@ func getTerminalMap() (map[uint64]string, error) {
return ret, nil return ret, nil
} }
func (p *Process) Send_signal(sig syscall.Signal) error { func (p *Process) SendSignal(sig syscall.Signal) error {
sig_as_str := "INT" sigAsStr := "INT"
switch sig { switch sig {
case syscall.SIGSTOP: case syscall.SIGSTOP:
sig_as_str = "STOP" sigAsStr = "STOP"
case syscall.SIGCONT: case syscall.SIGCONT:
sig_as_str = "CONT" sigAsStr = "CONT"
case syscall.SIGTERM: case syscall.SIGTERM:
sig_as_str = "TERM" sigAsStr = "TERM"
case syscall.SIGKILL: case syscall.SIGKILL:
sig_as_str = "KILL" sigAsStr = "KILL"
} }
cmd := exec.Command("kill", "-s", sig_as_str, strconv.Itoa(int(p.Pid))) cmd := exec.Command("kill", "-s", sigAsStr, strconv.Itoa(int(p.Pid)))
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
err := cmd.Run() err := cmd.Run()
if err != nil { if err != nil {
@ -72,14 +72,14 @@ func (p *Process) Send_signal(sig syscall.Signal) error {
} }
func (p *Process) Suspend() error { func (p *Process) Suspend() error {
return p.Send_signal(syscall.SIGSTOP) return p.SendSignal(syscall.SIGSTOP)
} }
func (p *Process) Resume() error { func (p *Process) Resume() error {
return p.Send_signal(syscall.SIGCONT) return p.SendSignal(syscall.SIGCONT)
} }
func (p *Process) Terminate() error { func (p *Process) Terminate() error {
return p.Send_signal(syscall.SIGTERM) return p.SendSignal(syscall.SIGTERM)
} }
func (p *Process) Kill() error { func (p *Process) Kill() error {
return p.Send_signal(syscall.SIGKILL) return p.SendSignal(syscall.SIGKILL)
} }

@ -19,12 +19,12 @@ func Test_Pids(t *testing.T) {
} }
func Test_Pid_exists(t *testing.T) { func Test_Pid_exists(t *testing.T) {
check_pid := 1 checkPid := 1
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
check_pid = 0 checkPid = 0
} }
ret, err := PidExists(int32(check_pid)) ret, err := PidExists(int32(checkPid))
if err != nil { if err != nil {
t.Errorf("error %v", err) t.Errorf("error %v", err)
} }
@ -35,12 +35,12 @@ func Test_Pid_exists(t *testing.T) {
} }
func Test_NewProcess(t *testing.T) { func Test_NewProcess(t *testing.T) {
check_pid := 1 checkPid := 1
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
check_pid = 0 checkPid = 0
} }
ret, err := NewProcess(int32(check_pid)) ret, err := NewProcess(int32(checkPid))
if err != nil { if err != nil {
t.Errorf("error %v", err) t.Errorf("error %v", err)
} }
@ -50,12 +50,12 @@ func Test_NewProcess(t *testing.T) {
} }
func Test_Process_memory_maps(t *testing.T) { func Test_Process_memory_maps(t *testing.T) {
check_pid := os.Getpid() checkPid := os.Getpid()
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
check_pid = 0 checkPid = 0
} }
return return
ret, err := NewProcess(int32(check_pid)) ret, err := NewProcess(int32(checkPid))
mmaps, err := ret.MemoryMaps(false) mmaps, err := ret.MemoryMaps(false)
if err != nil { if err != nil {
@ -68,11 +68,11 @@ func Test_Process_memory_maps(t *testing.T) {
} }
func Test_Process_Ppid(t *testing.T) { func Test_Process_Ppid(t *testing.T) {
check_pid := os.Getpid() checkPid := os.Getpid()
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
check_pid = 7960 checkPid = 7960
} }
ret, err := NewProcess(int32(check_pid)) ret, err := NewProcess(int32(checkPid))
v, err := ret.Ppid() v, err := ret.Ppid()
if err != nil { if err != nil {

@ -8,11 +8,11 @@ import (
"testing" "testing"
) )
func Test_SendSignal(t *testing.T) { func TestSendSignal(t *testing.T) {
check_pid := os.Getpid() checkPid := os.Getpid()
p, _ := NewProcess(int32(check_pid)) p, _ := NewProcess(int32(checkPid))
err := p.Send_signal(syscall.SIGCONT) err := p.SendSignal(syscall.SIGCONT)
if err != nil { if err != nil {
t.Errorf("send signal %v", err) t.Errorf("send signal %v", err)
} }

@ -99,7 +99,7 @@ func (p *Process) Terminal() (string, error) {
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) {
@ -107,7 +107,7 @@ func (p *Process) Rlimit() ([]RlimitStat, error) {
return rlimit, errors.New("not implemented yet") return rlimit, errors.New("not implemented yet")
} }
func (p *Process) IoCounters() (*IoCountersStat, error) { func (p *Process) IOCounters() (*IOCountersStat, error) {
return nil, errors.New("not implemented yet") return nil, errors.New("not implemented yet")
} }
func (p *Process) NumCtxSwitches() (int32, error) { func (p *Process) NumCtxSwitches() (int32, error) {

Loading…
Cancel
Save