Skip to content

Commit

Permalink
Merge pull request #143 from fearful-symmetry/aix-cleanup
Browse files Browse the repository at this point in the history
Clean up AIX code
  • Loading branch information
fearful-symmetry authored Jul 17, 2020
2 parents b915fb1 + 2ab2bc2 commit 3b8ff34
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 40 deletions.
72 changes: 37 additions & 35 deletions sigar_aix.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,20 @@ func init() {
// utmp can't be used by "encoding/binary" if generated by cgo,
// some pads will be explicitly missing.
type utmp struct {
User [256]uint8
Id [14]uint8
Line [64]uint8
XPad1 int16
Pid int32
Type int16
XPad2 int16
Time int64
Termination int16
Exit int16
Host [256]uint8
Xdbl_word_pad int32
XreservedA [2]int32
XreservedV [6]int32
User [256]uint8
ID [14]uint8
Line [64]uint8
XPad1 int16
Pid int32
Type int16
XPad2 int16
Time int64
Termination int16
Exit int16
Host [256]uint8
XdblWordPad int32
XreservedA [2]int32
XreservedV [6]int32
}

func bootTime() (uint64, error) {
Expand Down Expand Up @@ -93,7 +93,7 @@ func tick2msec(val uint64) uint64 {
return val * 1000 / system.ticks
}

// Return the list of file systems
// Get returns the list of file systems
func (self *FileSystemList) Get() error {
var size C.int
_, err := C.mntctl(C.MCTL_QUERY, C.sizeof_int, (*C.char)(unsafe.Pointer(&size)))
Expand Down Expand Up @@ -187,7 +187,7 @@ func (self *FileSystemList) Get() error {
return nil
}

// Return the CPU load average
// Get returns the CPU load average
func (self *LoadAverage) Get() error {
cpudata := C.perfstat_cpu_total_t{}

Expand All @@ -208,7 +208,7 @@ func (self *LoadAverage) Get() error {
return nil
}

// Return the system uptime
// Get returns the system uptime
func (self *Uptime) Get() error {
btime, err := bootTime()
if err != nil {
Expand All @@ -219,7 +219,7 @@ func (self *Uptime) Get() error {
return nil
}

// Return the current system memory
// Get returns the current system memory
func (self *Mem) Get() error {
meminfo := C.perfstat_memory_total_t{}
_, err := C.perfstat_memory_total(nil, &meminfo, C.sizeof_perfstat_memory_total_t, 1)
Expand All @@ -239,7 +239,7 @@ func (self *Mem) Get() error {
return nil
}

// Return the current system swap memory
// Get returns the current system swap memory
func (self *Swap) Get() error {
ps := C.perfstat_pagingspace_t{}
id := C.perfstat_id_t{}
Expand Down Expand Up @@ -271,7 +271,7 @@ func (self *Swap) Get() error {
return nil
}

// Return information about a CPU
// Get returns information about a CPU
func (self *Cpu) Get() error {
cpudata := C.perfstat_cpu_total_t{}

Expand All @@ -287,7 +287,7 @@ func (self *Cpu) Get() error {
return nil
}

// Return the list of CPU used by the system
// Get returns the list of CPU used by the system
func (self *CpuList) Get() error {
cpudata := C.perfstat_cpu_t{}
id := C.perfstat_id_t{}
Expand Down Expand Up @@ -321,10 +321,9 @@ func (self *CpuList) Get() error {
self.List = list

return nil

}

// Return the list of all active processes
// Get returns the list of all active processes
func (self *ProcList) Get() error {
info := C.struct_procsinfo64{}
pid := C.pid_t(0)
Expand All @@ -350,7 +349,7 @@ func (self *ProcList) Get() error {
return nil
}

// Return information about a process
// Get returns information about a process
func (self *ProcState) Get(pid int) error {
info := C.struct_procsinfo64{}
cpid := C.pid_t(pid)
Expand Down Expand Up @@ -387,9 +386,9 @@ func (self *ProcState) Get(pid int) error {

// Get process username. Fallback to UID if username is not available.
uid := strconv.Itoa(int(info.pi_uid))
user, err := user.LookupId(uid)
if err == nil && user.Username != "" {
self.Username = user.Username
userID, err := user.LookupId(uid)
if err == nil && userID.Username != "" {
self.Username = userID.Username
} else {
self.Username = uid
}
Expand All @@ -404,7 +403,7 @@ func (self *ProcState) Get(pid int) error {
return nil
}

// Return the current memory usage of a process
//Get returns the current memory usage of a process
func (self *ProcMem) Get(pid int) error {
info := C.struct_procsinfo64{}
cpid := C.pid_t(pid)
Expand All @@ -428,7 +427,7 @@ func (self *ProcMem) Get(pid int) error {
return nil
}

// Return a process uptime
// Get returns a process uptime
func (self *ProcTime) Get(pid int) error {
info := C.struct_procsinfo64{}
cpid := C.pid_t(pid)
Expand All @@ -449,7 +448,7 @@ func (self *ProcTime) Get(pid int) error {
return nil
}

// Return arguments of a process
// Get returns arguments of a process
func (self *ProcArgs) Get(pid int) error {
/* If buffer is not large enough, args are truncated */
buf := make([]byte, 8192)
Expand Down Expand Up @@ -480,7 +479,7 @@ func (self *ProcArgs) Get(pid int) error {
return nil
}

// Return the environment of a process
// Get returns the environment of a process
func (self *ProcEnv) Get(pid int) error {
if self.Vars == nil {
self.Vars = map[string]string{}
Expand Down Expand Up @@ -518,7 +517,7 @@ func (self *ProcEnv) Get(pid int) error {
return nil
}

// Return the path of the process executable
// Get returns the path of the process executable
func (self *ProcExe) Get(pid int) error {
/* If buffer is not large enough, args are truncated */
buf := make([]byte, 8192)
Expand Down Expand Up @@ -549,14 +548,17 @@ func (self *ProcExe) Get(pid int) error {
return nil
}

func (self *ProcFDUsage) Get(pid int) error {
// Get returns process filesystem usage. Not implimented on AIX.
func (*ProcFDUsage) Get(_ int) error {
return ErrNotImplemented{runtime.GOOS}
}

func (self *FDUsage) Get() error {
// Get returns filesytem usage. Not implimented on AIX.
func (*FDUsage) Get() error {
return ErrNotImplemented{runtime.GOOS}
}

func (self *HugeTLBPages) Get() error {
// Get returns huge pages info. Not implimented on AIX.
func (*HugeTLBPages) Get() error {
return ErrNotImplemented{runtime.GOOS}
}
7 changes: 2 additions & 5 deletions sigar_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ func chop(buf []byte) []byte {
return buf[0 : len(buf)-1]
}

// convertBytesToString trims null bytes and returns a string
func convertBytesToString(arr []byte) string {
n := bytes.IndexByte(arr, 0)
if n == -1 {
return string(arr[:])
}
return string(arr[:n])
return string(bytes.Trim(arr, "\x00"))
}

0 comments on commit 3b8ff34

Please sign in to comment.