summaryrefslogtreecommitdiff
path: root/cmd/podman/top.go
diff options
context:
space:
mode:
authorValentin Rothberg <vrothberg@suse.com>2018-06-13 08:59:59 +0200
committerAtomic Bot <atomic-devel@projectatomic.io>2018-06-18 12:56:44 +0000
commitb1e709806dd628b542bda4dc823ff8c0ca870110 (patch)
tree0364b6ca7e550f298299949f9bb6a5e379bb3854 /cmd/podman/top.go
parent9e134576e8eb047466706fa71a201def6d5d8159 (diff)
downloadpodman-b1e709806dd628b542bda4dc823ff8c0ca870110.tar.gz
podman-b1e709806dd628b542bda4dc823ff8c0ca870110.tar.bz2
podman-b1e709806dd628b542bda4dc823ff8c0ca870110.zip
top: make output tabular
Make the output of top tabular to be compatible with Docker. Please note, that any user-input for `GetContainerPidInformation(...)` will be ignored until we have found a way to generically and reliably parse ps-1 output or until there is a go-lib to extract all the data from /proc in a ps-1 compatible fashion. Fixes: #458 Signed-off-by: Valentin Rothberg <vrothberg@suse.com> Closes: #939 Approved by: rhatdan
Diffstat (limited to 'cmd/podman/top.go')
-rw-r--r--cmd/podman/top.go19
1 files changed, 9 insertions, 10 deletions
diff --git a/cmd/podman/top.go b/cmd/podman/top.go
index 7ea8a1169..d848723e2 100644
--- a/cmd/podman/top.go
+++ b/cmd/podman/top.go
@@ -2,6 +2,8 @@ package main
import (
"fmt"
+ "os"
+ "text/tabwriter"
"github.com/pkg/errors"
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
@@ -34,8 +36,7 @@ func topCmd(c *cli.Context) error {
var container *libpod.Container
var err error
args := c.Args()
- var psArgs []string
- psOpts := []string{"-o", "uid,pid,ppid,c,stime,tname,time,cmd"}
+
if len(args) < 1 && !c.Bool("latest") {
return errors.Errorf("you must provide the name or id of a running container")
}
@@ -48,9 +49,6 @@ func topCmd(c *cli.Context) error {
return errors.Wrapf(err, "error creating libpod runtime")
}
defer runtime.Shutdown(false)
- if len(args) > 1 {
- psOpts = args[1:]
- }
if c.Bool("latest") {
container, err = runtime.GetLatestContainer()
@@ -69,14 +67,15 @@ func topCmd(c *cli.Context) error {
return errors.Errorf("top can only be used on running containers")
}
- psArgs = append(psArgs, psOpts...)
-
- psOutput, err := container.GetContainerPidInformation(psArgs)
+ psOutput, err := container.GetContainerPidInformation([]string{})
if err != nil {
return err
}
- for _, line := range psOutput {
- fmt.Println(line)
+
+ w := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0)
+ for _, proc := range psOutput {
+ fmt.Fprintln(w, proc)
}
+ w.Flush()
return nil
}