Skip to content
Permalink
Browse files

Show process args when ungrouped on unix

  • Loading branch information...
cjbassi committed May 16, 2018
1 parent 0647a4b commit ee1c57c6fe364457c2461c8f18848480779712bb

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -22,6 +22,7 @@ type Process struct {
Command string
CPU float64
Mem float64
Args string
}

type Proc struct {
@@ -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.
@@ -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,
"",
}
}
}
@@ -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
}
@@ -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") {
@@ -35,6 +35,7 @@ func Processes() []Process {
Command: split[1],
CPU: cpu,
Mem: mem,
Args: strings.Join(split[4:], " "),
}
processes = append(processes, process)
}
@@ -18,6 +18,9 @@ func (self *Proc) update() {
command,
cpu / self.cpuCount,
float64(mem),
// getting command args using gopsutil's Cmdline and CmdlineSlice wasn't
// working the last time I tried it, so we're just reusing 'command'
command,
}
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit ee1c57c

Please sign in to comment.
You can’t perform that action at this time.