mirror of https://github.com/cjbassi/gotop.git
Show process args when ungrouped on unix
This commit is contained in:
parent
0647a4b433
commit
ee1c57c6fe
|
@ -17,7 +17,7 @@
|
||||||
branch = "master"
|
branch = "master"
|
||||||
name = "github.com/cjbassi/termui"
|
name = "github.com/cjbassi/termui"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
revision = "75525ee19c41f52324024b7a2bf31edcd1428494"
|
revision = "50e37fc8a80ca08ddca62be4537c7d49261994a3"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
|
|
|
@ -22,6 +22,7 @@ type Process struct {
|
||||||
Command string
|
Command string
|
||||||
CPU float64
|
CPU float64
|
||||||
Mem float64
|
Mem float64
|
||||||
|
Args string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Proc struct {
|
type Proc struct {
|
||||||
|
@ -100,7 +101,7 @@ func (self *Proc) Sort() {
|
||||||
self.Header[3] += DOWN
|
self.Header[3] += DOWN
|
||||||
}
|
}
|
||||||
|
|
||||||
self.Rows = FieldsToStrings(*processes)
|
self.Rows = FieldsToStrings(*processes, self.group)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ColResize overrides the default ColResize in the termui table.
|
// ColResize overrides the default ColResize in the termui table.
|
||||||
|
@ -220,6 +221,7 @@ func Group(P []Process) []Process {
|
||||||
val.Command,
|
val.Command,
|
||||||
val.CPU + process.CPU,
|
val.CPU + process.CPU,
|
||||||
val.Mem + process.Mem,
|
val.Mem + process.Mem,
|
||||||
|
"",
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
groupedP[process.Command] = Process{
|
groupedP[process.Command] = Process{
|
||||||
|
@ -227,6 +229,7 @@ func Group(P []Process) []Process {
|
||||||
process.Command,
|
process.Command,
|
||||||
process.CPU,
|
process.CPU,
|
||||||
process.Mem,
|
process.Mem,
|
||||||
|
"",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -242,14 +245,18 @@ func Group(P []Process) []Process {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FieldsToStrings converts a []Process to a [][]string
|
// FieldsToStrings converts a []Process to a [][]string
|
||||||
func FieldsToStrings(P []Process) [][]string {
|
func FieldsToStrings(P []Process, grouped bool) [][]string {
|
||||||
strings := make([][]string, len(P))
|
strings := make([][]string, len(P))
|
||||||
for i, p := range P {
|
for i, p := range P {
|
||||||
strings[i] = make([]string, 4)
|
strings[i] = make([]string, 4)
|
||||||
strings[i][0] = strconv.Itoa(int(p.PID))
|
strings[i][0] = strconv.Itoa(int(p.PID))
|
||||||
|
if grouped {
|
||||||
strings[i][1] = p.Command
|
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][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
|
return strings
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ func (self *Proc) update() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Processes() []Process {
|
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))
|
strOutput := strings.TrimSpace(string(output))
|
||||||
processes := []Process{}
|
processes := []Process{}
|
||||||
for _, line := range strings.Split(strOutput, "\n") {
|
for _, line := range strings.Split(strOutput, "\n") {
|
||||||
|
@ -35,6 +35,7 @@ func Processes() []Process {
|
||||||
Command: split[1],
|
Command: split[1],
|
||||||
CPU: cpu,
|
CPU: cpu,
|
||||||
Mem: mem,
|
Mem: mem,
|
||||||
|
Args: strings.Join(split[4:], " "),
|
||||||
}
|
}
|
||||||
processes = append(processes, process)
|
processes = append(processes, process)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,9 @@ func (self *Proc) update() {
|
||||||
command,
|
command,
|
||||||
cpu / self.cpuCount,
|
cpu / self.cpuCount,
|
||||||
float64(mem),
|
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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package termui
|
package termui
|
||||||
|
|
||||||
// Color is an integer in the range -1 to 255.
|
// Color is an integer in the range -1 to 255.
|
||||||
|
// -1 is clear, while 0-255 are xterm 256 colors.
|
||||||
type Color int
|
type Color int
|
||||||
|
|
||||||
// ColorDefault = clear
|
// ColorDefault = clear
|
||||||
|
|
|
@ -106,7 +106,11 @@ func (self *Table) Buffer() *Buffer {
|
||||||
if width == 0 {
|
if width == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
r := MaxString(row[i], self.X-self.CellXPos[i])
|
width = self.X - self.CellXPos[i]
|
||||||
|
if len(self.CellXPos) > i+1 {
|
||||||
|
width -= self.X - self.CellXPos[i+1]
|
||||||
|
}
|
||||||
|
r := MaxString(row[i], width)
|
||||||
buf.SetString(self.CellXPos[i], y, r, self.Fg, bg)
|
buf.SetString(self.CellXPos[i], y, r, self.Fg, bg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue