summaryrefslogtreecommitdiff
path: root/cmd/podman/top.go
diff options
context:
space:
mode:
authorBrent Baude <bbaude@redhat.com>2020-04-16 12:25:26 -0500
committerBrent Baude <bbaude@redhat.com>2020-04-16 15:53:58 -0500
commit241326a9a8c20ad7f2bcf651416b836e7778e090 (patch)
tree4001e8e47a022bb1b9bfbf2332c42e1aeb802f9e /cmd/podman/top.go
parent88c6fd06cd54fb9a8826306dfdf1a77e400de5de (diff)
downloadpodman-241326a9a8c20ad7f2bcf651416b836e7778e090.tar.gz
podman-241326a9a8c20ad7f2bcf651416b836e7778e090.tar.bz2
podman-241326a9a8c20ad7f2bcf651416b836e7778e090.zip
Podman V2 birth
remote podman v1 and replace with podman v2. Signed-off-by: Brent Baude <bbaude@redhat.com>
Diffstat (limited to 'cmd/podman/top.go')
-rw-r--r--cmd/podman/top.go99
1 files changed, 0 insertions, 99 deletions
diff --git a/cmd/podman/top.go b/cmd/podman/top.go
deleted file mode 100644
index bfba90fc0..000000000
--- a/cmd/podman/top.go
+++ /dev/null
@@ -1,99 +0,0 @@
-package main
-
-import (
- "fmt"
- "os"
- "strings"
- "text/tabwriter"
-
- "github.com/containers/libpod/cmd/podman/cliconfig"
- "github.com/containers/libpod/pkg/adapter"
- "github.com/containers/libpod/pkg/util"
- "github.com/pkg/errors"
- "github.com/spf13/cobra"
-)
-
-func getDescriptorString() string {
- descriptors, err := util.GetContainerPidInformationDescriptors()
- if err == nil {
- return fmt.Sprintf(`
- Format Descriptors:
- %s`, strings.Join(descriptors, ","))
- }
- return ""
-}
-
-var (
- topCommand cliconfig.TopValues
- topDescription = fmt.Sprintf(`Similar to system "top" command.
-
- Specify format descriptors to alter the output.
-
- Running "podman top -l pid pcpu seccomp" will print the process ID, the CPU percentage and the seccomp mode of each process of the latest container.
-%s`, getDescriptorString())
-
- _topCommand = &cobra.Command{
- Use: "top [flags] CONTAINER [FORMAT-DESCRIPTORS|ARGS]",
- Short: "Display the running processes of a container",
- Long: topDescription,
- RunE: func(cmd *cobra.Command, args []string) error {
- topCommand.InputArgs = args
- topCommand.GlobalFlags = MainGlobalOpts
- topCommand.Remote = remoteclient
- return topCmd(&topCommand)
- },
- Args: cobra.ArbitraryArgs,
- Example: `podman top ctrID
-podman top --latest
-podman top ctrID pid seccomp args %C
-podman top ctrID -eo user,pid,comm`,
- }
-)
-
-func init() {
- topCommand.Command = _topCommand
- topCommand.SetHelpTemplate(HelpTemplate())
- topCommand.SetUsageTemplate(UsageTemplate())
- flags := topCommand.Flags()
- flags.SetInterspersed(false)
- flags.BoolVar(&topCommand.ListDescriptors, "list-descriptors", false, "")
- markFlagHidden(flags, "list-descriptors")
- flags.BoolVarP(&topCommand.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
- markFlagHiddenForRemoteClient("latest", flags)
-}
-
-func topCmd(c *cliconfig.TopValues) error {
- var err error
- args := c.InputArgs
-
- if c.ListDescriptors {
- descriptors, err := util.GetContainerPidInformationDescriptors()
- if err != nil {
- return err
- }
- fmt.Println(strings.Join(descriptors, "\n"))
- return nil
- }
-
- if len(args) < 1 && !c.Latest {
- return errors.Errorf("you must provide the name or id of a running container")
- }
-
- runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
- if err != nil {
- return errors.Wrapf(err, "error creating libpod runtime")
- }
- defer runtime.DeferredShutdown(false)
-
- psOutput, err := runtime.Top(c)
- if err != nil {
- return err
- }
- w := tabwriter.NewWriter(os.Stdout, 5, 1, 3, ' ', 0)
- for _, proc := range psOutput {
- if _, err := fmt.Fprintln(w, proc); err != nil {
- return err
- }
- }
- return w.Flush()
-}