summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorGiuseppe Scrivano <gscrivan@redhat.com>2019-07-02 14:14:16 +0200
committerGiuseppe Scrivano <gscrivan@redhat.com>2019-07-02 14:14:18 +0200
commit856780f55288ec9e9bfae6c6a7459ca12fb61c5d (patch)
tree8640d876ffd64511030cf51b6710a990d5ff31b0 /libpod
parent7423426f73f367cd4e9246eb1fb1b6ac1ed33644 (diff)
downloadpodman-856780f55288ec9e9bfae6c6a7459ca12fb61c5d.tar.gz
podman-856780f55288ec9e9bfae6c6a7459ca12fb61c5d.tar.bz2
podman-856780f55288ec9e9bfae6c6a7459ca12fb61c5d.zip
stats: use runtime.NumCPU when percpu counters are not available
in the cgroup v2 implementation we don't have yet percpu times. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Diffstat (limited to 'libpod')
-rw-r--r--libpod/stats.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/libpod/stats.go b/libpod/stats.go
index da383e9d9..eb5ed95c4 100644
--- a/libpod/stats.go
+++ b/libpod/stats.go
@@ -3,6 +3,7 @@
package libpod
import (
+ "runtime"
"strings"
"syscall"
"time"
@@ -105,7 +106,11 @@ func calculateCPUPercent(stats *cgroups.Metrics, previousCPU, previousSystem uin
if systemDelta > 0.0 && cpuDelta > 0.0 {
// gets a ratio of container cpu usage total, multiplies it by the number of cores (4 cores running
// at 100% utilization should be 400% utilization), and multiplies that by 100 to get a percentage
- cpuPercent = (cpuDelta / systemDelta) * float64(len(stats.CPU.Usage.PerCPU)) * 100
+ nCPUS := len(stats.CPU.Usage.PerCPU)
+ if nCPUS == 0 {
+ nCPUS = runtime.NumCPU()
+ }
+ cpuPercent = (cpuDelta / systemDelta) * float64(nCPUS) * 100
}
return cpuPercent
}