MCPcopy Index your code
hub / github.com/docker/cli / calculateCPUPercentUnix

Function calculateCPUPercentUnix

cli/command/container/stats_helpers.go:183–200  ·  view source on GitHub ↗
(previousCPU container.CPUStats, curCPUStats container.CPUStats)

Source from the content-addressed store, hash-verified

181}
182
183func calculateCPUPercentUnix(previousCPU container.CPUStats, curCPUStats container.CPUStats) float64 {
184 var (
185 cpuPercent = 0.0
186 // calculate the change for the cpu usage of the container in between readings
187 cpuDelta = float64(curCPUStats.CPUUsage.TotalUsage) - float64(previousCPU.CPUUsage.TotalUsage)
188 // calculate the change for the entire system between readings
189 systemDelta = float64(curCPUStats.SystemUsage) - float64(previousCPU.SystemUsage)
190 onlineCPUs = float64(curCPUStats.OnlineCPUs)
191 )
192
193 if onlineCPUs == 0.0 {
194 onlineCPUs = float64(len(curCPUStats.CPUUsage.PercpuUsage))
195 }
196 if systemDelta > 0.0 && cpuDelta > 0.0 {
197 cpuPercent = (cpuDelta / systemDelta) * onlineCPUs * 100.0
198 }
199 return cpuPercent
200}
201
202func calculateCPUPercentWindows(v *container.StatsResponse) float64 {
203 // Max number of 100ns intervals between the previous time read and now

Callers 1

collectFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…