mirror of https://github.com/containers/podman.git
ps: get network data in batch mode
The network functions popped up in the CPU profiles when listing 2042 containers. Not a very realistic or common use case but a nice way to get something on the CPU profiles. Listing 2042 containers now runs 1.54 times faster. [NO NEW TESTS NEEDED] Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
This commit is contained in:
parent
ce504bbfe3
commit
6f519c9bde
23
pkg/ps/ps.go
23
pkg/ps/ps.go
|
@ -11,6 +11,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
libnetworkTypes "github.com/containers/common/libnetwork/types"
|
||||||
"github.com/containers/podman/v4/libpod"
|
"github.com/containers/podman/v4/libpod"
|
||||||
"github.com/containers/podman/v4/libpod/define"
|
"github.com/containers/podman/v4/libpod/define"
|
||||||
"github.com/containers/podman/v4/pkg/domain/entities"
|
"github.com/containers/podman/v4/pkg/domain/entities"
|
||||||
|
@ -134,6 +135,8 @@ func ListContainerBatch(rt *libpod.Runtime, ctr *libpod.Container, opts entities
|
||||||
startedTime time.Time
|
startedTime time.Time
|
||||||
exitedTime time.Time
|
exitedTime time.Time
|
||||||
cgroup, ipc, mnt, net, pidns, user, uts string
|
cgroup, ipc, mnt, net, pidns, user, uts string
|
||||||
|
portMappings []libnetworkTypes.PortMapping
|
||||||
|
networks []string
|
||||||
)
|
)
|
||||||
|
|
||||||
batchErr := ctr.Batch(func(c *libpod.Container) error {
|
batchErr := ctr.Batch(func(c *libpod.Container) error {
|
||||||
|
@ -167,6 +170,16 @@ func ListContainerBatch(rt *libpod.Runtime, ctr *libpod.Container, opts entities
|
||||||
return fmt.Errorf("unable to obtain container pid: %w", err)
|
return fmt.Errorf("unable to obtain container pid: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
portMappings, err = c.PortMappings()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
networks, err = c.Networks()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if !opts.Size && !opts.Namespace {
|
if !opts.Size && !opts.Namespace {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -203,16 +216,6 @@ func ListContainerBatch(rt *libpod.Runtime, ctr *libpod.Container, opts entities
|
||||||
return entities.ListContainer{}, batchErr
|
return entities.ListContainer{}, batchErr
|
||||||
}
|
}
|
||||||
|
|
||||||
portMappings, err := ctr.PortMappings()
|
|
||||||
if err != nil {
|
|
||||||
return entities.ListContainer{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
networks, err := ctr.Networks()
|
|
||||||
if err != nil {
|
|
||||||
return entities.ListContainer{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
ps := entities.ListContainer{
|
ps := entities.ListContainer{
|
||||||
AutoRemove: ctr.AutoRemove(),
|
AutoRemove: ctr.AutoRemove(),
|
||||||
Command: conConfig.Command,
|
Command: conConfig.Command,
|
||||||
|
|
Loading…
Reference in New Issue