summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2018-01-22 12:08:22 -0600
committerbaude <bbaude@redhat.com>2018-01-22 14:31:50 -0600
commitc04fb6c5643795d30208ae041be6adf747c2ecdc (patch)
tree822431a0b614f191305038b615f9eaea1049f4e6
parent5c3e4cfa62452b9cd5c2c08bf081ab524ded1cb4 (diff)
downloadpodman-c04fb6c5643795d30208ae041be6adf747c2ecdc.tar.gz
podman-c04fb6c5643795d30208ae041be6adf747c2ecdc.tar.bz2
podman-c04fb6c5643795d30208ae041be6adf747c2ecdc.zip
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 <bbaude@redhat.com>
-rw-r--r--cmd/podman/ps.go45
1 files changed, 30 insertions, 15 deletions
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