(containers []api.ContainerProcSummary)
| 79 | } |
| 80 | |
| 81 | func collectTop(containers []api.ContainerProcSummary) (topHeader, []topEntries) { |
| 82 | // map column name to its header (should keep working if backend.Top returns |
| 83 | // varying columns for different containers) |
| 84 | header := topHeader{"SERVICE": 0, "#": 1} |
| 85 | |
| 86 | // assume one process per container and grow if needed |
| 87 | entries := make([]topEntries, 0, len(containers)) |
| 88 | |
| 89 | for _, container := range containers { |
| 90 | for _, proc := range container.Processes { |
| 91 | entry := topEntries{ |
| 92 | "SERVICE": container.Service, |
| 93 | "#": container.Replica, |
| 94 | } |
| 95 | for i, title := range container.Titles { |
| 96 | if _, exists := header[title]; !exists { |
| 97 | header[title] = len(header) |
| 98 | } |
| 99 | entry[title] = proc[i] |
| 100 | } |
| 101 | entries = append(entries, entry) |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | // ensure CMD is the right-most column |
| 106 | if pos, ok := header["CMD"]; ok { |
| 107 | maxPos := pos |
| 108 | for h, i := range header { |
| 109 | if i > maxPos { |
| 110 | maxPos = i |
| 111 | } |
| 112 | if i > pos { |
| 113 | header[h] = i - 1 |
| 114 | } |
| 115 | } |
| 116 | header["CMD"] = maxPos |
| 117 | } |
| 118 | |
| 119 | return header, entries |
| 120 | } |
| 121 | |
| 122 | func topPrint(out io.Writer, headers topHeader, rows []topEntries) error { |
| 123 | if len(rows) == 0 { |
no outgoing calls