From b12ec089708f9f9a982e73d83d2a7e19b2fff2d6 Mon Sep 17 00:00:00 2001 From: WAKAYAMA Shirou Date: Thu, 24 Apr 2014 17:20:12 +0900 Subject: [PATCH] gm fmt --- cpu.go | 2 +- process.go | 21 ++++++++++----------- process_linux.go | 5 +++-- process_linux_amd64.go | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/cpu.go b/cpu.go index 033d948..83d2a97 100644 --- a/cpu.go +++ b/cpu.go @@ -5,7 +5,7 @@ import ( ) type CPU_TimesStat struct { - Cpu string `json:"cpu"` + Cpu string `json:"cpu"` User float32 `json:"user"` System float32 `json:"system"` Idle float32 `json:"idle"` diff --git a/process.go b/process.go index 04e3685..ff9110c 100644 --- a/process.go +++ b/process.go @@ -1,8 +1,8 @@ package gopsutil import ( - "strings" "os" + "strings" "syscall" ) @@ -87,10 +87,9 @@ func Pid_exists(pid int32) (bool, error) { return false, err } - // POSIX -func getTerminalMap() (map[uint64]string, error){ - ret := make(map[uint64]string) +func getTerminalMap() (map[uint64]string, error) { + ret := make(map[uint64]string) termfiles := make([]string, 0) d, err := os.Open("/dev") @@ -100,9 +99,9 @@ func getTerminalMap() (map[uint64]string, error){ defer d.Close() devnames, err := d.Readdirnames(-1) - for _, devname := range devnames{ - if strings.HasPrefix(devname, "/dev/tty"){ - termfiles = append(termfiles, "/dev/tty/" + devname) + for _, devname := range devnames { + if strings.HasPrefix(devname, "/dev/tty") { + termfiles = append(termfiles, "/dev/tty/"+devname) } } @@ -113,15 +112,15 @@ func getTerminalMap() (map[uint64]string, error){ defer ptsd.Close() ptsnames, err := ptsd.Readdirnames(-1) - for _, ptsname := range ptsnames{ - termfiles = append(termfiles, "/dev/pts/" + ptsname) + for _, ptsname := range ptsnames { + termfiles = append(termfiles, "/dev/pts/"+ptsname) } - for _, name := range termfiles{ + for _, name := range termfiles { stat := syscall.Stat_t{} syscall.Stat(name, &stat) rdev := stat.Rdev ret[rdev] = strings.Replace(name, "/dev", "", -1) } - return ret, nil + return ret, nil } diff --git a/process_linux.go b/process_linux.go index dc839be..48a4e4c 100644 --- a/process_linux.go +++ b/process_linux.go @@ -63,6 +63,7 @@ func parseInt32(val string) int32 { vv, _ := strconv.ParseInt(val, 10, 32) return int32(vv) } + // Parse to uint64 without error func parseUint64(val string) uint64 { vv, _ := strconv.ParseInt(val, 10, 64) @@ -115,7 +116,7 @@ func fillFromStatus(pid int32, p *Process) error { if len(field) < 2 { continue } -// fmt.Printf("%s ->__%s__\n", field[0], strings.Trim(field[1], " \t")) + // fmt.Printf("%s ->__%s__\n", field[0], strings.Trim(field[1], " \t")) switch field[0] { case "Name": p.Name = strings.Trim(field[1], " \t") @@ -150,7 +151,7 @@ func fillFromStat(pid int32, p *Process) error { fields := strings.Fields(string(contents)) termmap, err := getTerminalMap() - if err == nil{ + if err == nil { p.Terminal = termmap[parseUint64(fields[6])] } diff --git a/process_linux_amd64.go b/process_linux_amd64.go index 82e542d..d68fb95 100644 --- a/process_linux_amd64.go +++ b/process_linux_amd64.go @@ -3,6 +3,6 @@ package gopsutil -const( +const ( CLOCK_TICKS = 2 // FIXME: /usr/include/x86_64-linux-gnu/bits/time.h )