Skip to content
This repository has been archived by the owner on Aug 29, 2020. It is now read-only.

Commit

Permalink
Show process args when ungrouped on unix
Browse files Browse the repository at this point in the history
  • Loading branch information
cjbassi committed May 16, 2018
1 parent 0647a4b commit 9587edb
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions src/widgets/proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Process struct {
Command string
CPU float64
Mem float64
Args string
}

type Proc struct {
Expand Down Expand Up @@ -100,7 +101,7 @@ func (self *Proc) Sort() {
self.Header[3] += DOWN
}

self.Rows = FieldsToStrings(*processes)
self.Rows = FieldsToStrings(*processes, self.group)
}

// ColResize overrides the default ColResize in the termui table.
Expand Down Expand Up @@ -220,13 +221,15 @@ func Group(P []Process) []Process {
val.Command,
val.CPU + process.CPU,
val.Mem + process.Mem,
"",
}
} else {
groupedP[process.Command] = Process{
1,
process.Command,
process.CPU,
process.Mem,
"",
}
}
}
Expand All @@ -242,14 +245,18 @@ func Group(P []Process) []Process {
}

// FieldsToStrings converts a []Process to a [][]string
func FieldsToStrings(P []Process) [][]string {
func FieldsToStrings(P []Process, grouped bool) [][]string {
strings := make([][]string, len(P))
for i, p := range P {
strings[i] = make([]string, 4)
strings[i][0] = strconv.Itoa(int(p.PID))
strings[i][1] = p.Command
if grouped {
strings[i][1] = p.Command
} else {
strings[i][1] = p.Args
}
strings[i][2] = fmt.Sprintf("%4s", strconv.FormatFloat(p.CPU, 'f', 1, 64))
strings[i][3] = fmt.Sprintf("%4s", strconv.FormatFloat(float64(p.Mem), 'f', 1, 32))
strings[i][3] = fmt.Sprintf("%4s", strconv.FormatFloat(float64(p.Mem), 'f', 1, 64))
}
return strings
}
Expand Down
3 changes: 2 additions & 1 deletion src/widgets/proc_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (self *Proc) update() {
}

func Processes() []Process {
output, _ := exec.Command("ps", "--no-headers", "-acxo", "pid,comm,pcpu,pmem").Output()
output, _ := exec.Command("ps", "--no-headers", "-axo", "pid,comm,pcpu,pmem,args").Output()
strOutput := strings.TrimSpace(string(output))
processes := []Process{}
for _, line := range strings.Split(strOutput, "\n") {
Expand All @@ -35,6 +35,7 @@ func Processes() []Process {
Command: split[1],
CPU: cpu,
Mem: mem,
Args: strings.Join(split[4:], " "),
}
processes = append(processes, process)
}
Expand Down
1 change: 1 addition & 0 deletions src/widgets/proc_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func (self *Proc) update() {
command,
cpu / self.cpuCount,
float64(mem),
command,
}
}

Expand Down
1 change: 1 addition & 0 deletions vendor/github.com/cjbassi/termui/colors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion vendor/github.com/cjbassi/termui/table.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9587edb

Please sign in to comment.