MCPcopy Create free account
hub / github.com/containerd/nerdctl / Top

Function Top

pkg/cmd/container/top.go:55–73  ·  view source on GitHub ↗

Top performs the equivalent of running `top` inside of container(s)

(ctx context.Context, client *containerd.Client, containers []string, opt types.ContainerTopOptions)

Source from the content-addressed store, hash-verified

53
54// Top performs the equivalent of running `top` inside of container(s)
55func Top(ctx context.Context, client *containerd.Client, containers []string, opt types.ContainerTopOptions) error {
56 walker := &containerwalker.ContainerWalker{
57 Client: client,
58 OnFound: func(ctx context.Context, found containerwalker.Found) error {
59 if found.MatchCount > 1 {
60 return fmt.Errorf("multiple IDs found with provided prefix: %s", found.Req)
61 }
62 return containerTop(ctx, opt.Stdout, client, found.Container.ID(), opt.PsArgs)
63 },
64 }
65
66 n, err := walker.Walk(ctx, containers[0])
67 if err != nil {
68 return err
69 } else if n == 0 {
70 return fmt.Errorf("no such container %s", containers[0])
71 }
72 return nil
73}

Callers 2

topActionFunction · 0.92
topActionFunction · 0.92

Calls 2

WalkMethod · 0.95
containerTopFunction · 0.70

Tested by

no test coverage detected