Chase an upstream go fmt that has been long overdue.

This commit is contained in:
Sean Chittenden 2017-02-03 22:31:11 -08:00
parent eab1cd3a2e
commit 4c6c18a709
No known key found for this signature in database
GPG key ID: 4EBC9DC16C2E5E16
15 changed files with 670 additions and 671 deletions

View file

@ -36,6 +36,9 @@ func Times(percpu bool) ([]TimesStat, error) {
var startIdx uint = 1 var startIdx uint = 1
for { for {
linen, _ := common.ReadLinesOffsetN(filename, startIdx, 1) linen, _ := common.ReadLinesOffsetN(filename, startIdx, 1)
if len(linen) == 0 {
break
}
line := linen[0] line := linen[0]
if !strings.HasPrefix(line, "cpu") { if !strings.HasPrefix(line, "cpu") {
break break
@ -97,7 +100,7 @@ func finishCPUInfo(c *InfoStat) error {
return nil return nil
} }
} }
c.Mhz = value/1000.0 // value is in kHz c.Mhz = value / 1000.0 // value is in kHz
return nil return nil
} }
@ -147,7 +150,7 @@ func Info() ([]InfoStat, error) {
case "model name", "cpu": case "model name", "cpu":
c.ModelName = value c.ModelName = value
if strings.Contains(value, "POWER8") || if strings.Contains(value, "POWER8") ||
strings.Contains(value, "POWER7") { strings.Contains(value, "POWER7") {
c.Model = strings.Split(value, " ")[0] c.Model = strings.Split(value, " ")[0]
c.Family = "POWER" c.Family = "POWER"
c.VendorID = "IBM" c.VendorID = "IBM"

View file

@ -26,9 +26,9 @@ const (
// sys/sysctl.h // sys/sysctl.h
const ( const (
CTLKern = 1 // "high kernel": proc, limits CTLKern = 1 // "high kernel": proc, limits
KernCptime = 40 // KERN_CPTIME KernCptime = 40 // KERN_CPTIME
KernCptime2 = 71 // KERN_CPTIME2 KernCptime2 = 71 // KERN_CPTIME2
) )
var ClocksPerSec = float64(128) var ClocksPerSec = float64(128)
@ -79,7 +79,7 @@ func Times(percpu bool) ([]TimesStat, error) {
c := TimesStat{ c := TimesStat{
User: float64(cpuTimes[CPUser]) / ClocksPerSec, User: float64(cpuTimes[CPUser]) / ClocksPerSec,
Nice: float64(cpuTimes[CPNice]) / ClocksPerSec, Nice: float64(cpuTimes[CPNice]) / ClocksPerSec,
System: float64(cpuTimes[CPSys]) / ClocksPerSec, System: float64(cpuTimes[CPSys]) / ClocksPerSec,
Idle: float64(cpuTimes[CPIdle]) / ClocksPerSec, Idle: float64(cpuTimes[CPIdle]) / ClocksPerSec,
Irq: float64(cpuTimes[CPIntr]) / ClocksPerSec, Irq: float64(cpuTimes[CPIntr]) / ClocksPerSec,
} }

View file

@ -4,28 +4,28 @@
package host package host
const ( const (
sizeofPtr = 0x8 sizeofPtr = 0x8
sizeofShort = 0x2 sizeofShort = 0x2
sizeofInt = 0x4 sizeofInt = 0x4
sizeofLong = 0x8 sizeofLong = 0x8
sizeofLongLong = 0x8 sizeofLongLong = 0x8
sizeOfUtmp = 0x130 sizeOfUtmp = 0x130
) )
type ( type (
_C_short int16 _C_short int16
_C_int int32 _C_int int32
_C_long int64 _C_long int64
_C_long_long int64 _C_long_long int64
) )
type Utmp struct { type Utmp struct {
Line [8]int8 Line [8]int8
Name [32]int8 Name [32]int8
Host [256]int8 Host [256]int8
Time int64 Time int64
} }
type Timeval struct { type Timeval struct {
Sec int64 Sec int64
Usec int64 Usec int64
} }

View file

@ -27,7 +27,7 @@ const (
sizeofInt = C.sizeof_int sizeofInt = C.sizeof_int
sizeofLong = C.sizeof_long sizeofLong = C.sizeof_long
sizeofLongLong = C.sizeof_longlong sizeofLongLong = C.sizeof_longlong
sizeOfUtmp = C.sizeof_struct_utmp sizeOfUtmp = C.sizeof_struct_utmp
) )
// Basic types // Basic types

View file

@ -344,43 +344,43 @@ func WaitTimeout(c *exec.Cmd, timeout time.Duration) error {
// https://gist.github.com/kylelemons/1525278 // https://gist.github.com/kylelemons/1525278
func Pipeline(cmds ...*exec.Cmd) ([]byte, []byte, error) { func Pipeline(cmds ...*exec.Cmd) ([]byte, []byte, error) {
// Require at least one command // Require at least one command
if len(cmds) < 1 { if len(cmds) < 1 {
return nil, nil, nil return nil, nil, nil
} }
// Collect the output from the command(s) // Collect the output from the command(s)
var output bytes.Buffer var output bytes.Buffer
var stderr bytes.Buffer var stderr bytes.Buffer
last := len(cmds) - 1 last := len(cmds) - 1
for i, cmd := range cmds[:last] { for i, cmd := range cmds[:last] {
var err error var err error
// Connect each command's stdin to the previous command's stdout // Connect each command's stdin to the previous command's stdout
if cmds[i+1].Stdin, err = cmd.StdoutPipe(); err != nil { if cmds[i+1].Stdin, err = cmd.StdoutPipe(); err != nil {
return nil, nil, err return nil, nil, err
} }
// Connect each command's stderr to a buffer // Connect each command's stderr to a buffer
cmd.Stderr = &stderr cmd.Stderr = &stderr
} }
// Connect the output and error for the last command // Connect the output and error for the last command
cmds[last].Stdout, cmds[last].Stderr = &output, &stderr cmds[last].Stdout, cmds[last].Stderr = &output, &stderr
// Start each command // Start each command
for _, cmd := range cmds { for _, cmd := range cmds {
if err := cmd.Start(); err != nil { if err := cmd.Start(); err != nil {
return output.Bytes(), stderr.Bytes(), err return output.Bytes(), stderr.Bytes(), err
} }
} }
// Wait for each command to complete // Wait for each command to complete
for _, cmd := range cmds { for _, cmd := range cmds {
if err := cmd.Wait(); err != nil { if err := cmd.Wait(); err != nil {
return output.Bytes(), stderr.Bytes(), err return output.Bytes(), stderr.Bytes(), err
} }
} }
// Return the pipeline output and the collected standard error // Return the pipeline output and the collected standard error
return output.Bytes(), stderr.Bytes(), nil return output.Bytes(), stderr.Bytes(), nil
} }

View file

@ -7,8 +7,8 @@ import (
"encoding/binary" "encoding/binary"
"errors" "errors"
"fmt" "fmt"
"os/exec"
"github.com/shirou/gopsutil/internal/common" "github.com/shirou/gopsutil/internal/common"
"os/exec"
) )
func GetPageSize() (uint64, error) { func GetPageSize() (uint64, error) {
@ -47,12 +47,12 @@ func VirtualMemory() (*VirtualMemoryStat, error) {
p := uint64(uvmexp.Pagesize) p := uint64(uvmexp.Pagesize)
ret := &VirtualMemoryStat{ ret := &VirtualMemoryStat{
Total: uint64(uvmexp.Npages) * p, Total: uint64(uvmexp.Npages) * p,
Free: uint64(uvmexp.Free) * p, Free: uint64(uvmexp.Free) * p,
Active: uint64(uvmexp.Active) * p, Active: uint64(uvmexp.Active) * p,
Inactive: uint64(uvmexp.Inactive) * p, Inactive: uint64(uvmexp.Inactive) * p,
Cached: 0, // not available Cached: 0, // not available
Wired: uint64(uvmexp.Wired) * p, Wired: uint64(uvmexp.Wired) * p,
} }
ret.Available = ret.Inactive + ret.Cached + ret.Free ret.Available = ret.Inactive + ret.Cached + ret.Free
@ -94,8 +94,8 @@ func SwapMemory() (*SwapMemoryStat, error) {
var total, used, free uint64 var total, used, free uint64
_, err = fmt.Sscanf(line, _, err = fmt.Sscanf(line,
"total: %d 1K-blocks allocated, %d used, %d available", "total: %d 1K-blocks allocated, %d used, %d available",
&total, &used, &free) &total, &used, &free)
if err != nil { if err != nil {
return nil, errors.New("failed to parse swapctl output") return nil, errors.New("failed to parse swapctl output")
} }

View file

@ -4,119 +4,119 @@
package mem package mem
const ( const (
CTLVm = 2 CTLVm = 2
CTLVfs = 10 CTLVfs = 10
VmUvmexp = 4 VmUvmexp = 4
VfsGeneric = 0 VfsGeneric = 0
VfsBcacheStat = 3 VfsBcacheStat = 3
) )
const ( const (
sizeOfUvmexp = 0x154 sizeOfUvmexp = 0x154
sizeOfBcachestats = 0x78 sizeOfBcachestats = 0x78
) )
type Uvmexp struct { type Uvmexp struct {
Pagesize int32 Pagesize int32
Pagemask int32 Pagemask int32
Pageshift int32 Pageshift int32
Npages int32 Npages int32
Free int32 Free int32
Active int32 Active int32
Inactive int32 Inactive int32
Paging int32 Paging int32
Wired int32 Wired int32
Zeropages int32 Zeropages int32
Reserve_pagedaemon int32 Reserve_pagedaemon int32
Reserve_kernel int32 Reserve_kernel int32
Anonpages int32 Anonpages int32
Vnodepages int32 Vnodepages int32
Vtextpages int32 Vtextpages int32
Freemin int32 Freemin int32
Freetarg int32 Freetarg int32
Inactarg int32 Inactarg int32
Wiredmax int32 Wiredmax int32
Anonmin int32 Anonmin int32
Vtextmin int32 Vtextmin int32
Vnodemin int32 Vnodemin int32
Anonminpct int32 Anonminpct int32
Vtextminpct int32 Vtextminpct int32
Vnodeminpct int32 Vnodeminpct int32
Nswapdev int32 Nswapdev int32
Swpages int32 Swpages int32
Swpginuse int32 Swpginuse int32
Swpgonly int32 Swpgonly int32
Nswget int32 Nswget int32
Nanon int32 Nanon int32
Nanonneeded int32 Nanonneeded int32
Nfreeanon int32 Nfreeanon int32
Faults int32 Faults int32
Traps int32 Traps int32
Intrs int32 Intrs int32
Swtch int32 Swtch int32
Softs int32 Softs int32
Syscalls int32 Syscalls int32
Pageins int32 Pageins int32
Obsolete_swapins int32 Obsolete_swapins int32
Obsolete_swapouts int32 Obsolete_swapouts int32
Pgswapin int32 Pgswapin int32
Pgswapout int32 Pgswapout int32
Forks int32 Forks int32
Forks_ppwait int32 Forks_ppwait int32
Forks_sharevm int32 Forks_sharevm int32
Pga_zerohit int32 Pga_zerohit int32
Pga_zeromiss int32 Pga_zeromiss int32
Zeroaborts int32 Zeroaborts int32
Fltnoram int32 Fltnoram int32
Fltnoanon int32 Fltnoanon int32
Fltpgwait int32 Fltpgwait int32
Fltpgrele int32 Fltpgrele int32
Fltrelck int32 Fltrelck int32
Fltrelckok int32 Fltrelckok int32
Fltanget int32 Fltanget int32
Fltanretry int32 Fltanretry int32
Fltamcopy int32 Fltamcopy int32
Fltnamap int32 Fltnamap int32
Fltnomap int32 Fltnomap int32
Fltlget int32 Fltlget int32
Fltget int32 Fltget int32
Flt_anon int32 Flt_anon int32
Flt_acow int32 Flt_acow int32
Flt_obj int32 Flt_obj int32
Flt_prcopy int32 Flt_prcopy int32
Flt_przero int32 Flt_przero int32
Pdwoke int32 Pdwoke int32
Pdrevs int32 Pdrevs int32
Pdswout int32 Pdswout int32
Pdfreed int32 Pdfreed int32
Pdscans int32 Pdscans int32
Pdanscan int32 Pdanscan int32
Pdobscan int32 Pdobscan int32
Pdreact int32 Pdreact int32
Pdbusy int32 Pdbusy int32
Pdpageouts int32 Pdpageouts int32
Pdpending int32 Pdpending int32
Pddeact int32 Pddeact int32
Pdreanon int32 Pdreanon int32
Pdrevnode int32 Pdrevnode int32
Pdrevtext int32 Pdrevtext int32
Fpswtch int32 Fpswtch int32
Kmapent int32 Kmapent int32
} }
type Bcachestats struct { type Bcachestats struct {
Numbufs int64 Numbufs int64
Numbufpages int64 Numbufpages int64
Numdirtypages int64 Numdirtypages int64
Numcleanpages int64 Numcleanpages int64
Pendingwrites int64 Pendingwrites int64
Pendingreads int64 Pendingreads int64
Numwrites int64 Numwrites int64
Numreads int64 Numreads int64
Cachehits int64 Cachehits int64
Busymapped int64 Busymapped int64
Dmapages int64 Dmapages int64
Highpages int64 Highpages int64
Delwribufs int64 Delwribufs int64
Kvaslots int64 Kvaslots int64
Avail int64 Avail int64
} }

View file

@ -4,7 +4,6 @@
Input to cgo -godefs. Input to cgo -godefs.
*/ */
package mem package mem
/* /*
@ -19,19 +18,17 @@ import "C"
// Machine characteristics; for internal use. // Machine characteristics; for internal use.
const ( const (
CTLVm = 2 CTLVm = 2
CTLVfs = 10 CTLVfs = 10
VmUvmexp = 4 // get uvmexp VmUvmexp = 4 // get uvmexp
VfsGeneric = 0 VfsGeneric = 0
VfsBcacheStat = 3 VfsBcacheStat = 3
) )
const ( const (
sizeOfUvmexp = C.sizeof_struct_uvmexp sizeOfUvmexp = C.sizeof_struct_uvmexp
sizeOfBcachestats = C.sizeof_struct_bcachestats sizeOfBcachestats = C.sizeof_struct_bcachestats
) )
type Uvmexp C.struct_uvmexp type Uvmexp C.struct_uvmexp
type Bcachestats C.struct_bcachestats type Bcachestats C.struct_bcachestats

View file

@ -222,7 +222,7 @@ func IOCounters(pernic bool) ([]IOCountersStat, error) {
} }
if truncated { if truncated {
// run netstat with -I$ifacename // run netstat with -I$ifacename
if out, err = invoke.Command(netstat, "-ibdnWI" + interfaceName);err != nil { if out, err = invoke.Command(netstat, "-ibdnWI"+interfaceName); err != nil {
return nil, err return nil, err
} }
parsedIfaces, err := parseNetstatOutput(string(out)) parsedIfaces, err := parseNetstatOutput(string(out))

View file

@ -12,7 +12,7 @@ import (
) )
func ParseNetstat(output string, mode string, func ParseNetstat(output string, mode string,
iocs map[string]IOCountersStat) (error) { iocs map[string]IOCountersStat) error {
lines := strings.Split(output, "\n") lines := strings.Split(output, "\n")
exists := make([]string, 0, len(lines)-1) exists := make([]string, 0, len(lines)-1)
@ -44,16 +44,16 @@ func ParseNetstat(output string, mode string,
var vv []string var vv []string
if mode == "inb" { if mode == "inb" {
vv = []string{ vv = []string{
values[base+3], // BytesRecv values[base+3], // BytesRecv
values[base+4], // BytesSent values[base+4], // BytesSent
} }
} else { } else {
vv = []string{ vv = []string{
values[base+3], // Ipkts values[base+3], // Ipkts
values[base+4], // Ierrs values[base+4], // Ierrs
values[base+5], // Opkts values[base+5], // Opkts
values[base+6], // Oerrs values[base+6], // Oerrs
values[base+8], // Drops values[base+8], // Drops
} }
} }
for _, target := range vv { for _, target := range vv {
@ -72,18 +72,18 @@ func ParseNetstat(output string, mode string,
n, present := iocs[values[0]] n, present := iocs[values[0]]
if !present { if !present {
n = IOCountersStat{Name : values[0]} n = IOCountersStat{Name: values[0]}
} }
if mode == "inb" { if mode == "inb" {
n.BytesRecv = parsed[0] n.BytesRecv = parsed[0]
n.BytesSent = parsed[1] n.BytesSent = parsed[1]
} else { } else {
n.PacketsRecv = parsed[0] n.PacketsRecv = parsed[0]
n.Errin = parsed[1] n.Errin = parsed[1]
n.PacketsSent = parsed[2] n.PacketsSent = parsed[2]
n.Errout = parsed[3] n.Errout = parsed[3]
n.Dropin = parsed[4] n.Dropin = parsed[4]
n.Dropout = parsed[4] n.Dropout = parsed[4]
} }
iocs[n.Name] = n iocs[n.Name] = n

View file

@ -4,189 +4,189 @@
package process package process
const ( const (
CTLKern = 1 CTLKern = 1
KernProc = 14 KernProc = 14
KernProcPID = 1 KernProcPID = 1
KernProcProc = 8 KernProcProc = 8
KernProcPathname = 12 KernProcPathname = 12
KernProcArgs = 7 KernProcArgs = 7
) )
const ( const (
sizeofPtr = 0x4 sizeofPtr = 0x4
sizeofShort = 0x2 sizeofShort = 0x2
sizeofInt = 0x4 sizeofInt = 0x4
sizeofLong = 0x4 sizeofLong = 0x4
sizeofLongLong = 0x8 sizeofLongLong = 0x8
) )
const ( const (
sizeOfKinfoVmentry = 0x488 sizeOfKinfoVmentry = 0x488
sizeOfKinfoProc = 0x300 sizeOfKinfoProc = 0x300
) )
const ( const (
SIDL = 1 SIDL = 1
SRUN = 2 SRUN = 2
SSLEEP = 3 SSLEEP = 3
SSTOP = 4 SSTOP = 4
SZOMB = 5 SZOMB = 5
SWAIT = 6 SWAIT = 6
SLOCK = 7 SLOCK = 7
) )
type ( type (
_C_short int16 _C_short int16
_C_int int32 _C_int int32
_C_long int32 _C_long int32
_C_long_long int64 _C_long_long int64
) )
type Timespec struct { type Timespec struct {
Sec int32 Sec int32
Nsec int32 Nsec int32
} }
type Timeval struct { type Timeval struct {
Sec int32 Sec int32
Usec int32 Usec int32
} }
type Rusage struct { type Rusage struct {
Utime Timeval Utime Timeval
Stime Timeval Stime Timeval
Maxrss int32 Maxrss int32
Ixrss int32 Ixrss int32
Idrss int32 Idrss int32
Isrss int32 Isrss int32
Minflt int32 Minflt int32
Majflt int32 Majflt int32
Nswap int32 Nswap int32
Inblock int32 Inblock int32
Oublock int32 Oublock int32
Msgsnd int32 Msgsnd int32
Msgrcv int32 Msgrcv int32
Nsignals int32 Nsignals int32
Nvcsw int32 Nvcsw int32
Nivcsw int32 Nivcsw int32
} }
type Rlimit struct { type Rlimit struct {
Cur int64 Cur int64
Max int64 Max int64
} }
type KinfoProc struct { type KinfoProc struct {
Structsize int32 Structsize int32
Layout int32 Layout int32
Args int32 /* pargs */ Args int32 /* pargs */
Paddr int32 /* proc */ Paddr int32 /* proc */
Addr int32 /* user */ Addr int32 /* user */
Tracep int32 /* vnode */ Tracep int32 /* vnode */
Textvp int32 /* vnode */ Textvp int32 /* vnode */
Fd int32 /* filedesc */ Fd int32 /* filedesc */
Vmspace int32 /* vmspace */ Vmspace int32 /* vmspace */
Wchan int32 Wchan int32
Pid int32 Pid int32
Ppid int32 Ppid int32
Pgid int32 Pgid int32
Tpgid int32 Tpgid int32
Sid int32 Sid int32
Tsid int32 Tsid int32
Jobc int16 Jobc int16
Spare_short1 int16 Spare_short1 int16
Tdev uint32 Tdev uint32
Siglist [16]byte /* sigset */ Siglist [16]byte /* sigset */
Sigmask [16]byte /* sigset */ Sigmask [16]byte /* sigset */
Sigignore [16]byte /* sigset */ Sigignore [16]byte /* sigset */
Sigcatch [16]byte /* sigset */ Sigcatch [16]byte /* sigset */
Uid uint32 Uid uint32
Ruid uint32 Ruid uint32
Svuid uint32 Svuid uint32
Rgid uint32 Rgid uint32
Svgid uint32 Svgid uint32
Ngroups int16 Ngroups int16
Spare_short2 int16 Spare_short2 int16
Groups [16]uint32 Groups [16]uint32
Size uint32 Size uint32
Rssize int32 Rssize int32
Swrss int32 Swrss int32
Tsize int32 Tsize int32
Dsize int32 Dsize int32
Ssize int32 Ssize int32
Xstat uint16 Xstat uint16
Acflag uint16 Acflag uint16
Pctcpu uint32 Pctcpu uint32
Estcpu uint32 Estcpu uint32
Slptime uint32 Slptime uint32
Swtime uint32 Swtime uint32
Cow uint32 Cow uint32
Runtime uint64 Runtime uint64
Start Timeval Start Timeval
Childtime Timeval Childtime Timeval
Flag int32 Flag int32
Kiflag int32 Kiflag int32
Traceflag int32 Traceflag int32
Stat int8 Stat int8
Nice int8 Nice int8
Lock int8 Lock int8
Rqindex int8 Rqindex int8
Oncpu uint8 Oncpu uint8
Lastcpu uint8 Lastcpu uint8
Tdname [17]int8 Tdname [17]int8
Wmesg [9]int8 Wmesg [9]int8
Login [18]int8 Login [18]int8
Lockname [9]int8 Lockname [9]int8
Comm [20]int8 Comm [20]int8
Emul [17]int8 Emul [17]int8
Loginclass [18]int8 Loginclass [18]int8
Sparestrings [50]int8 Sparestrings [50]int8
Spareints [7]int32 Spareints [7]int32
Flag2 int32 Flag2 int32
Fibnum int32 Fibnum int32
Cr_flags uint32 Cr_flags uint32
Jid int32 Jid int32
Numthreads int32 Numthreads int32
Tid int32 Tid int32
Pri Priority Pri Priority
Rusage Rusage Rusage Rusage
Rusage_ch Rusage Rusage_ch Rusage
Pcb int32 /* pcb */ Pcb int32 /* pcb */
Kstack int32 Kstack int32
Udata int32 Udata int32
Tdaddr int32 /* thread */ Tdaddr int32 /* thread */
Spareptrs [6]int32 Spareptrs [6]int32
Sparelongs [12]int32 Sparelongs [12]int32
Sflag int32 Sflag int32
Tdflags int32 Tdflags int32
} }
type Priority struct { type Priority struct {
Class uint8 Class uint8
Level uint8 Level uint8
Native uint8 Native uint8
User uint8 User uint8
} }
type KinfoVmentry struct { type KinfoVmentry struct {
Structsize int32 Structsize int32
Type int32 Type int32
Start uint64 Start uint64
End uint64 End uint64
Offset uint64 Offset uint64
Vn_fileid uint64 Vn_fileid uint64
Vn_fsid uint32 Vn_fsid uint32
Flags int32 Flags int32
Resident int32 Resident int32
Private_resident int32 Private_resident int32
Protection int32 Protection int32
Ref_count int32 Ref_count int32
Shadow_count int32 Shadow_count int32
Vn_type int32 Vn_type int32
Vn_size uint64 Vn_size uint64
Vn_rdev uint32 Vn_rdev uint32
Vn_mode uint16 Vn_mode uint16
Status uint16 Status uint16
X_kve_ispare [12]int32 X_kve_ispare [12]int32
Path [1024]int8 Path [1024]int8
} }

View file

@ -4,189 +4,189 @@
package process package process
const ( const (
CTLKern = 1 CTLKern = 1
KernProc = 14 KernProc = 14
KernProcPID = 1 KernProcPID = 1
KernProcProc = 8 KernProcProc = 8
KernProcPathname = 12 KernProcPathname = 12
KernProcArgs = 7 KernProcArgs = 7
) )
const ( const (
sizeofPtr = 0x8 sizeofPtr = 0x8
sizeofShort = 0x2 sizeofShort = 0x2
sizeofInt = 0x4 sizeofInt = 0x4
sizeofLong = 0x8 sizeofLong = 0x8
sizeofLongLong = 0x8 sizeofLongLong = 0x8
) )
const ( const (
sizeOfKinfoVmentry = 0x488 sizeOfKinfoVmentry = 0x488
sizeOfKinfoProc = 0x440 sizeOfKinfoProc = 0x440
) )
const ( const (
SIDL = 1 SIDL = 1
SRUN = 2 SRUN = 2
SSLEEP = 3 SSLEEP = 3
SSTOP = 4 SSTOP = 4
SZOMB = 5 SZOMB = 5
SWAIT = 6 SWAIT = 6
SLOCK = 7 SLOCK = 7
) )
type ( type (
_C_short int16 _C_short int16
_C_int int32 _C_int int32
_C_long int64 _C_long int64
_C_long_long int64 _C_long_long int64
) )
type Timespec struct { type Timespec struct {
Sec int64 Sec int64
Nsec int64 Nsec int64
} }
type Timeval struct { type Timeval struct {
Sec int64 Sec int64
Usec int64 Usec int64
} }
type Rusage struct { type Rusage struct {
Utime Timeval Utime Timeval
Stime Timeval Stime Timeval
Maxrss int64 Maxrss int64
Ixrss int64 Ixrss int64
Idrss int64 Idrss int64
Isrss int64 Isrss int64
Minflt int64 Minflt int64
Majflt int64 Majflt int64
Nswap int64 Nswap int64
Inblock int64 Inblock int64
Oublock int64 Oublock int64
Msgsnd int64 Msgsnd int64
Msgrcv int64 Msgrcv int64
Nsignals int64 Nsignals int64
Nvcsw int64 Nvcsw int64
Nivcsw int64 Nivcsw int64
} }
type Rlimit struct { type Rlimit struct {
Cur int64 Cur int64
Max int64 Max int64
} }
type KinfoProc struct { type KinfoProc struct {
Structsize int32 Structsize int32
Layout int32 Layout int32
Args int64 /* pargs */ Args int64 /* pargs */
Paddr int64 /* proc */ Paddr int64 /* proc */
Addr int64 /* user */ Addr int64 /* user */
Tracep int64 /* vnode */ Tracep int64 /* vnode */
Textvp int64 /* vnode */ Textvp int64 /* vnode */
Fd int64 /* filedesc */ Fd int64 /* filedesc */
Vmspace int64 /* vmspace */ Vmspace int64 /* vmspace */
Wchan int64 Wchan int64
Pid int32 Pid int32
Ppid int32 Ppid int32
Pgid int32 Pgid int32
Tpgid int32 Tpgid int32
Sid int32 Sid int32
Tsid int32 Tsid int32
Jobc int16 Jobc int16
Spare_short1 int16 Spare_short1 int16
Tdev uint32 Tdev uint32
Siglist [16]byte /* sigset */ Siglist [16]byte /* sigset */
Sigmask [16]byte /* sigset */ Sigmask [16]byte /* sigset */
Sigignore [16]byte /* sigset */ Sigignore [16]byte /* sigset */
Sigcatch [16]byte /* sigset */ Sigcatch [16]byte /* sigset */
Uid uint32 Uid uint32
Ruid uint32 Ruid uint32
Svuid uint32 Svuid uint32
Rgid uint32 Rgid uint32
Svgid uint32 Svgid uint32
Ngroups int16 Ngroups int16
Spare_short2 int16 Spare_short2 int16
Groups [16]uint32 Groups [16]uint32
Size uint64 Size uint64
Rssize int64 Rssize int64
Swrss int64 Swrss int64
Tsize int64 Tsize int64
Dsize int64 Dsize int64
Ssize int64 Ssize int64
Xstat uint16 Xstat uint16
Acflag uint16 Acflag uint16
Pctcpu uint32 Pctcpu uint32
Estcpu uint32 Estcpu uint32
Slptime uint32 Slptime uint32
Swtime uint32 Swtime uint32
Cow uint32 Cow uint32
Runtime uint64 Runtime uint64
Start Timeval Start Timeval
Childtime Timeval Childtime Timeval
Flag int64 Flag int64
Kiflag int64 Kiflag int64
Traceflag int32 Traceflag int32
Stat int8 Stat int8
Nice int8 Nice int8
Lock int8 Lock int8
Rqindex int8 Rqindex int8
Oncpu uint8 Oncpu uint8
Lastcpu uint8 Lastcpu uint8
Tdname [17]int8 Tdname [17]int8
Wmesg [9]int8 Wmesg [9]int8
Login [18]int8 Login [18]int8
Lockname [9]int8 Lockname [9]int8
Comm [20]int8 Comm [20]int8
Emul [17]int8 Emul [17]int8
Loginclass [18]int8 Loginclass [18]int8
Sparestrings [50]int8 Sparestrings [50]int8
Spareints [7]int32 Spareints [7]int32
Flag2 int32 Flag2 int32
Fibnum int32 Fibnum int32
Cr_flags uint32 Cr_flags uint32
Jid int32 Jid int32
Numthreads int32 Numthreads int32
Tid int32 Tid int32
Pri Priority Pri Priority
Rusage Rusage Rusage Rusage
Rusage_ch Rusage Rusage_ch Rusage
Pcb int64 /* pcb */ Pcb int64 /* pcb */
Kstack int64 Kstack int64
Udata int64 Udata int64
Tdaddr int64 /* thread */ Tdaddr int64 /* thread */
Spareptrs [6]int64 Spareptrs [6]int64
Sparelongs [12]int64 Sparelongs [12]int64
Sflag int64 Sflag int64
Tdflags int64 Tdflags int64
} }
type Priority struct { type Priority struct {
Class uint8 Class uint8
Level uint8 Level uint8
Native uint8 Native uint8
User uint8 User uint8
} }
type KinfoVmentry struct { type KinfoVmentry struct {
Structsize int32 Structsize int32
Type int32 Type int32
Start uint64 Start uint64
End uint64 End uint64
Offset uint64 Offset uint64
Vn_fileid uint64 Vn_fileid uint64
Vn_fsid uint32 Vn_fsid uint32
Flags int32 Flags int32
Resident int32 Resident int32
Private_resident int32 Private_resident int32
Protection int32 Protection int32
Ref_count int32 Ref_count int32
Shadow_count int32 Shadow_count int32
Vn_type int32 Vn_type int32
Vn_size uint64 Vn_size uint64
Vn_rdev uint32 Vn_rdev uint32
Vn_mode uint16 Vn_mode uint16
Status uint16 Status uint16
X_kve_ispare [12]int32 X_kve_ispare [12]int32
Path [1024]int8 Path [1024]int8
} }

View file

@ -3,8 +3,8 @@
package process package process
import ( import (
"bytes"
"C" "C"
"bytes"
"encoding/binary" "encoding/binary"
"strings" "strings"
"syscall" "syscall"
@ -12,8 +12,8 @@ import (
cpu "github.com/shirou/gopsutil/cpu" cpu "github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/internal/common" "github.com/shirou/gopsutil/internal/common"
net "github.com/shirou/gopsutil/net"
mem "github.com/shirou/gopsutil/mem" mem "github.com/shirou/gopsutil/mem"
net "github.com/shirou/gopsutil/net"
) )
// MemoryInfoExStat is different between OSes // MemoryInfoExStat is different between OSes
@ -58,7 +58,7 @@ func (p *Process) Exe() (string, error) {
} }
func (p *Process) CmdlineSlice() ([]string, error) { func (p *Process) CmdlineSlice() ([]string, error) {
mib := []int32{CTLKern, KernProcArgs, p.Pid, KernProcArgv } mib := []int32{CTLKern, KernProcArgs, p.Pid, KernProcArgv}
buf, _, err := common.CallSyscall(mib) buf, _, err := common.CallSyscall(mib)
if err != nil { if err != nil {
@ -75,7 +75,7 @@ func (p *Process) CmdlineSlice() ([]string, error) {
strParts = append(strParts, C.GoString(argv)) strParts = append(strParts, C.GoString(argv))
argc++ argc++
argv = *(**C.char)(unsafe.Pointer(uintptr(argvp) + uintptr(argc) * size)) argv = *(**C.char)(unsafe.Pointer(uintptr(argvp) + uintptr(argc)*size))
} }
return strParts, nil return strParts, nil
} }

View file

@ -4,15 +4,15 @@
package process package process
const ( const (
CTLKern = 1 CTLKern = 1
KernProc = 66 KernProc = 66
KernProcAll = 0 KernProcAll = 0
KernProcPID = 1 KernProcPID = 1
KernProcProc = 8 KernProcProc = 8
KernProcPathname = 12 KernProcPathname = 12
KernProcArgs = 55 KernProcArgs = 55
KernProcArgv = 1 KernProcArgv = 1
KernProcEnv = 3 KernProcEnv = 3
) )
const ( const (
@ -20,181 +20,181 @@ const (
) )
const ( const (
sizeofPtr = 0x8 sizeofPtr = 0x8
sizeofShort = 0x2 sizeofShort = 0x2
sizeofInt = 0x4 sizeofInt = 0x4
sizeofLong = 0x8 sizeofLong = 0x8
sizeofLongLong = 0x8 sizeofLongLong = 0x8
) )
const ( const (
sizeOfKinfoVmentry = 0x50 sizeOfKinfoVmentry = 0x50
sizeOfKinfoProc = 0x268 sizeOfKinfoProc = 0x268
) )
const ( const (
SIDL = 1 SIDL = 1
SRUN = 2 SRUN = 2
SSLEEP = 3 SSLEEP = 3
SSTOP = 4 SSTOP = 4
SZOMB = 5 SZOMB = 5
SDEAD = 6 SDEAD = 6
SONPROC = 7 SONPROC = 7
) )
type ( type (
_C_short int16 _C_short int16
_C_int int32 _C_int int32
_C_long int64 _C_long int64
_C_long_long int64 _C_long_long int64
) )
type Timespec struct { type Timespec struct {
Sec int64 Sec int64
Nsec int64 Nsec int64
} }
type Timeval struct { type Timeval struct {
Sec int64 Sec int64
Usec int64 Usec int64
} }
type Rusage struct { type Rusage struct {
Utime Timeval Utime Timeval
Stime Timeval Stime Timeval
Maxrss int64 Maxrss int64
Ixrss int64 Ixrss int64
Idrss int64 Idrss int64
Isrss int64 Isrss int64
Minflt int64 Minflt int64
Majflt int64 Majflt int64
Nswap int64 Nswap int64
Inblock int64 Inblock int64
Oublock int64 Oublock int64
Msgsnd int64 Msgsnd int64
Msgrcv int64 Msgrcv int64
Nsignals int64 Nsignals int64
Nvcsw int64 Nvcsw int64
Nivcsw int64 Nivcsw int64
} }
type Rlimit struct { type Rlimit struct {
Cur uint64 Cur uint64
Max uint64 Max uint64
} }
type KinfoProc struct { type KinfoProc struct {
Forw uint64 Forw uint64
Back uint64 Back uint64
Paddr uint64 Paddr uint64
Addr uint64 Addr uint64
Fd uint64 Fd uint64
Stats uint64 Stats uint64
Limit uint64 Limit uint64
Vmspace uint64 Vmspace uint64
Sigacts uint64 Sigacts uint64
Sess uint64 Sess uint64
Tsess uint64 Tsess uint64
Ru uint64 Ru uint64
Eflag int32 Eflag int32
Exitsig int32 Exitsig int32
Flag int32 Flag int32
Pid int32 Pid int32
Ppid int32 Ppid int32
Sid int32 Sid int32
X_pgid int32 X_pgid int32
Tpgid int32 Tpgid int32
Uid uint32 Uid uint32
Ruid uint32 Ruid uint32
Gid uint32 Gid uint32
Rgid uint32 Rgid uint32
Groups [16]uint32 Groups [16]uint32
Ngroups int16 Ngroups int16
Jobc int16 Jobc int16
Tdev uint32 Tdev uint32
Estcpu uint32 Estcpu uint32
Rtime_sec uint32 Rtime_sec uint32
Rtime_usec uint32 Rtime_usec uint32
Cpticks int32 Cpticks int32
Pctcpu uint32 Pctcpu uint32
Swtime uint32 Swtime uint32
Slptime uint32 Slptime uint32
Schedflags int32 Schedflags int32
Uticks uint64 Uticks uint64
Sticks uint64 Sticks uint64
Iticks uint64 Iticks uint64
Tracep uint64 Tracep uint64
Traceflag int32 Traceflag int32
Holdcnt int32 Holdcnt int32
Siglist int32 Siglist int32
Sigmask uint32 Sigmask uint32
Sigignore uint32 Sigignore uint32
Sigcatch uint32 Sigcatch uint32
Stat int8 Stat int8
Priority uint8 Priority uint8
Usrpri uint8 Usrpri uint8
Nice uint8 Nice uint8
Xstat uint16 Xstat uint16
Acflag uint16 Acflag uint16
Comm [24]int8 Comm [24]int8
Wmesg [8]int8 Wmesg [8]int8
Wchan uint64 Wchan uint64
Login [32]int8 Login [32]int8
Vm_rssize int32 Vm_rssize int32
Vm_tsize int32 Vm_tsize int32
Vm_dsize int32 Vm_dsize int32
Vm_ssize int32 Vm_ssize int32
Uvalid int64 Uvalid int64
Ustart_sec uint64 Ustart_sec uint64
Ustart_usec uint32 Ustart_usec uint32
Uutime_sec uint32 Uutime_sec uint32
Uutime_usec uint32 Uutime_usec uint32
Ustime_sec uint32 Ustime_sec uint32
Ustime_usec uint32 Ustime_usec uint32
Pad_cgo_0 [4]byte Pad_cgo_0 [4]byte
Uru_maxrss uint64 Uru_maxrss uint64
Uru_ixrss uint64 Uru_ixrss uint64
Uru_idrss uint64 Uru_idrss uint64
Uru_isrss uint64 Uru_isrss uint64
Uru_minflt uint64 Uru_minflt uint64
Uru_majflt uint64 Uru_majflt uint64
Uru_nswap uint64 Uru_nswap uint64
Uru_inblock uint64 Uru_inblock uint64
Uru_oublock uint64 Uru_oublock uint64
Uru_msgsnd uint64 Uru_msgsnd uint64
Uru_msgrcv uint64 Uru_msgrcv uint64
Uru_nsignals uint64 Uru_nsignals uint64
Uru_nvcsw uint64 Uru_nvcsw uint64
Uru_nivcsw uint64 Uru_nivcsw uint64
Uctime_sec uint32 Uctime_sec uint32
Uctime_usec uint32 Uctime_usec uint32
Psflags int32 Psflags int32
Spare int32 Spare int32
Svuid uint32 Svuid uint32
Svgid uint32 Svgid uint32
Emul [8]int8 Emul [8]int8
Rlim_rss_cur uint64 Rlim_rss_cur uint64
Cpuid uint64 Cpuid uint64
Vm_map_size uint64 Vm_map_size uint64
Tid int32 Tid int32
Rtableid uint32 Rtableid uint32
} }
type Priority struct{} type Priority struct{}
type KinfoVmentry struct { type KinfoVmentry struct {
Start uint64 Start uint64
End uint64 End uint64
Guard uint64 Guard uint64
Fspace uint64 Fspace uint64
Fspace_augment uint64 Fspace_augment uint64
Offset uint64 Offset uint64
Wired_count int32 Wired_count int32
Etype int32 Etype int32
Protection int32 Protection int32
Max_protection int32 Max_protection int32
Advice int32 Advice int32
Inheritance int32 Inheritance int32
Flags uint8 Flags uint8
Pad_cgo_0 [7]byte Pad_cgo_0 [7]byte
} }

View file

@ -42,16 +42,15 @@ const (
KernProcPID = 1 // by process id KernProcPID = 1 // by process id
KernProcProc = 8 // only return procs KernProcProc = 8 // only return procs
KernProcPathname = 12 // path to executable KernProcPathname = 12 // path to executable
KernProcArgs = 55 // get/set arguments/proctitle KernProcArgs = 55 // get/set arguments/proctitle
KernProcArgv = 1 KernProcArgv = 1
KernProcEnv = 3 KernProcEnv = 3
) )
const ( const (
ArgMax = 256 * 1024 // sys/syslimits.h:#define ARG_MAX ArgMax = 256 * 1024 // sys/syslimits.h:#define ARG_MAX
) )
const ( const (
sizeofPtr = C.sizeofPtr sizeofPtr = C.sizeofPtr
sizeofShort = C.sizeof_short sizeofShort = C.sizeof_short
@ -67,12 +66,12 @@ const (
// from sys/proc.h // from sys/proc.h
const ( const (
SIDL = 1 /* Process being created by fork. */ SIDL = 1 /* Process being created by fork. */
SRUN = 2 /* Currently runnable. */ SRUN = 2 /* Currently runnable. */
SSLEEP = 3 /* Sleeping on an address. */ SSLEEP = 3 /* Sleeping on an address. */
SSTOP = 4 /* Process debugging or suspension. */ SSTOP = 4 /* Process debugging or suspension. */
SZOMB = 5 /* Awaiting collection by parent. */ SZOMB = 5 /* Awaiting collection by parent. */
SDEAD = 6 /* Thread is almost gone */ SDEAD = 6 /* Thread is almost gone */
SONPROC = 7 /* Thread is currently on a CPU. */ SONPROC = 7 /* Thread is currently on a CPU. */
) )