1
0
mirror of https://github.com/docker/cli.git synced 2026-01-06 05:41:44 +03:00

cli/command/container: calculateCPUPercentWindows minor cleanup

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-10-28 12:49:10 +01:00
parent 689152a804
commit c467ebafd8

View File

@@ -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