From c04fb6c5643795d30208ae041be6adf747c2ecdc Mon Sep 17 00:00:00 2001 From: baude Date: Mon, 22 Jan 2018 12:08:22 -0600 Subject: Use batched operations in ps Because the podman ps command has to collection a lot of information from various places, many of which are controlled by locks, it is a good candidate for doing batch operations under a single lock. Signed-off-by: baude --- cmd/podman/ps.go | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) (limited to 'cmd') diff --git a/cmd/podman/ps.go b/cmd/podman/ps.go index 944664c68..9ac64f0c8 100644 --- a/cmd/podman/ps.go +++ b/cmd/podman/ps.go @@ -373,23 +373,38 @@ func (p *psTemplateParams) headerMap() map[string]string { // getTemplateOutput returns the modified container information func getTemplateOutput(containers []*libpod.Container, opts psOptions) ([]psTemplateParams, error) { - var psOutput []psTemplateParams - var status string + var ( + psOutput []psTemplateParams + status, ctrID string + conConfig *libpod.ContainerConfig + conState libpod.ContainerStatus + err error + exitCode int32 + pid int + ) + for _, ctr := range containers { - ctrID := ctr.ID() - conConfig := ctr.Config() - conState, err := ctr.State() - if err != nil { - return psOutput, errors.Wrapf(err, "unable to obtain container state") - } - exitCode, err := ctr.ExitCode() - if err != nil { - return psOutput, errors.Wrapf(err, "unable to obtain container exit code") - } - pid, err := ctr.PID() - if err != nil { - return psOutput, errors.Wrapf(err, "unable to obtain container pid") + batchErr := ctr.Batch(func(c *libpod.Container) error { + ctrID = c.ID() + conConfig = c.Config() + conState, err = c.State() + if err != nil { + return errors.Wrapf(err, "unable to obtain container state") + } + exitCode, err = c.ExitCode() + if err != nil { + return errors.Wrapf(err, "unable to obtain container exit code") + } + pid, err = c.PID() + if err != nil { + return errors.Wrapf(err, "unable to obtain container pid") + } + return nil + }) + if batchErr != nil { + return nil, err } + runningFor := units.HumanDuration(time.Since(conConfig.CreatedTime)) createdAt := runningFor + " ago" imageName := conConfig.RootfsImageName -- cgit v1.2.3-54-g00ecf