statsFormatWrite renders the context for a list of containers statistics
(ctx formatter.Context, stats []StatsEntry, osType string, trunc bool)
| 124 | |
| 125 | // statsFormatWrite renders the context for a list of containers statistics |
| 126 | func statsFormatWrite(ctx formatter.Context, stats []StatsEntry, osType string, trunc bool) error { |
| 127 | // TODO(thaJeztah): this should be taken from the (first) StatsEntry instead. |
| 128 | // also, assuming all stats are for the same platform (and basing the |
| 129 | // column headers on that) won't allow aggregated results, which could |
| 130 | // be mixed platform. |
| 131 | memUsage := memUseHeader |
| 132 | if osType == winOSType { |
| 133 | memUsage = winMemUseHeader |
| 134 | } |
| 135 | statsCtx := statsContext{os: osType} |
| 136 | statsCtx.Header = formatter.SubHeaderContext{ |
| 137 | "Container": containerHeader, |
| 138 | "Name": formatter.NameHeader, |
| 139 | "ID": formatter.ContainerIDHeader, |
| 140 | "CPUPerc": cpuPercHeader, |
| 141 | "MemUsage": memUsage, |
| 142 | "MemPerc": memPercHeader, |
| 143 | "NetIO": netIOHeader, |
| 144 | "BlockIO": blockIOHeader, |
| 145 | "PIDs": pidsHeader, |
| 146 | } |
| 147 | return ctx.Write(&statsCtx, func(format func(subContext formatter.SubContext) error) error { |
| 148 | for _, cstats := range stats { |
| 149 | if err := format(&statsContext{ |
| 150 | s: cstats, |
| 151 | os: osType, |
| 152 | trunc: trunc, |
| 153 | }); err != nil { |
| 154 | return err |
| 155 | } |
| 156 | } |
| 157 | return nil |
| 158 | }) |
| 159 | } |
| 160 | |
| 161 | type statsContext struct { |
| 162 | formatter.HeaderContext |
searching dependent graphs…