MCPcopy
hub / github.com/docker/compose / Top

Method Top

pkg/compose/top.go:29–68  ·  view source on GitHub ↗
(ctx context.Context, projectName string, services []string)

Source from the content-addressed store, hash-verified

27)
28
29func (s *composeService) Top(ctx context.Context, projectName string, services []string) ([]api.ContainerProcSummary, error) {
30 projectName = strings.ToLower(projectName)
31 var containers Containers
32 containers, err := s.getContainers(ctx, projectName, oneOffInclude, false)
33 if err != nil {
34 return nil, err
35 }
36 if len(services) > 0 {
37 containers = containers.filter(isService(services...))
38 }
39 summary := make([]api.ContainerProcSummary, len(containers))
40 eg, ctx := errgroup.WithContext(ctx)
41 for i, ctr := range containers {
42 eg.Go(func() error {
43 topContent, err := s.apiClient().ContainerTop(ctx, ctr.ID, client.ContainerTopOptions{
44 Arguments: []string{},
45 })
46 if err != nil {
47 return err
48 }
49 name := getCanonicalContainerName(ctr)
50 s := api.ContainerProcSummary{
51 ID: ctr.ID,
52 Name: name,
53 Processes: topContent.Processes,
54 Titles: topContent.Titles,
55 Service: name,
56 }
57 if service, exists := ctr.Labels[api.ServiceLabel]; exists {
58 s.Service = service
59 }
60 if replica, exists := ctr.Labels[api.ContainerNumberLabel]; exists {
61 s.Replica = replica
62 }
63 summary[i] = s
64 return nil
65 })
66 }
67 return summary, eg.Wait()
68}

Callers

nothing calls this directly

Calls 7

getContainersMethod · 0.95
filterMethod · 0.95
apiClientMethod · 0.95
isServiceFunction · 0.85
WaitMethod · 0.65
ContainerTopMethod · 0.45

Tested by

no test coverage detected