From c467ebafd8031285c02775fbae6b02b40bbf2fef Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 28 Oct 2025 12:49:10 +0100 Subject: [PATCH] cli/command/container: calculateCPUPercentWindows minor cleanup Signed-off-by: Sebastiaan van Stijn --- cli/command/container/stats_helpers.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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