summaryrefslogtreecommitdiff
path: root/libpod
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 /libpod
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 'libpod')
-rw-r--r--libpod/container_top.go24
1 files changed, 21 insertions, 3 deletions
diff --git a/libpod/container_top.go b/libpod/container_top.go
index a83303036..f5d314d49 100644
--- a/libpod/container_top.go
+++ b/libpod/container_top.go
@@ -44,8 +44,20 @@ func (c *Container) getContainerPids() ([]string, error) {
}
// GetContainerPidInformation calls ps with the appropriate options and returns
-// the results as a string and the container's PIDs as a []string
+// the results as a string and the container's PIDs as a []string. Note that
+// the ps output columns of each string are separated by a '\t\'. Currently,
+// the args argument is overwriten with []string{"-ef"} until there is a
+// portable library for ps-1 or to parse the procFS to extract all data.
func (c *Container) GetContainerPidInformation(args []string) ([]string, error) {
+ // XXX(ps-issue): args is overwriten with []{"-ef"} as the ps-1 tool
+ // doesn't support a generic way of splitting columns, rendering its
+ // output hard to parse. Docker first deterimes the number of columns
+ // and merges all exceeding ones into the last one. We believe that
+ // writing a go library which parses procFS in a ps-compatible way may
+ // be more beneficial in the long run. Until then, args will be
+ // ignored.
+ args = []string{"-ef"}
+
if !c.batched {
c.lock.Lock()
defer c.lock.Unlock()
@@ -80,7 +92,7 @@ func filterPids(psOutput string, pids []string) ([]string, error) {
// Pids that don't belong.
// append the headers back in
- output = append(output, results[0])
+ output = append(output, strings.Join(headers, "\t"))
pidIndex := -1
for i, header := range headers {
@@ -98,7 +110,13 @@ func filterPids(psOutput string, pids []string) ([]string, error) {
cols := fieldsASCII(l)
pid := cols[pidIndex]
if util.StringInSlice(pid, pids) {
- output = append(output, l)
+ // XXX(ps-issue): Strip cols down to the header's size
+ // and merge exceeding fields. This is required to
+ // "merge" the overhanging CMD entries which can
+ // contain white spaces.
+ out := cols[:len(headers)-1]
+ out = append(out, strings.Join(cols[len(headers)-1:], " "))
+ output = append(output, strings.Join(out, "\t"))
}
}
return output, nil