diff --git a/cli/command/container/stats_helpers.go b/cli/command/container/stats_helpers.go index 262ce5fc45..c5c25e5d16 100644 --- a/cli/command/container/stats_helpers.go +++ b/cli/command/container/stats_helpers.go @@ -182,13 +182,11 @@ func calculateCPUPercentWindows(v *container.StatsResponse) float64 { // Max number of 100ns intervals between the previous time read and now possIntervals := uint64(v.Read.Sub(v.PreRead).Nanoseconds()) // Start with number of ns intervals possIntervals /= 100 // Convert to number of 100ns intervals - possIntervals *= uint64(v.NumProcs) // Multiple by the number of processors - - // Intervals used - intervalsUsed := v.CPUStats.CPUUsage.TotalUsage - v.PreCPUStats.CPUUsage.TotalUsage + possIntervals *= uint64(v.NumProcs) // Multiply by the number of processors // Percentage avoiding divide-by-zero if possIntervals > 0 { + intervalsUsed := v.CPUStats.CPUUsage.TotalUsage - v.PreCPUStats.CPUUsage.TotalUsage return float64(intervalsUsed) / float64(possIntervals) * 100.0 } return 0.00