summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-07-02 19:48:20 +0200
committerGitHub <noreply@github.com>2019-07-02 19:48:20 +0200
commit26d02e97395b2fb5ab5abdc0a35ab6019dccbe18 (patch)
treec201ff82479441d5aacff262275c74b2d28c34f1 /libpod
parent4d45d8020e58841862791796ea4c0797a62540e9 (diff)
parent856780f55288ec9e9bfae6c6a7459ca12fb61c5d (diff)
downloadpodman-26d02e97395b2fb5ab5abdc0a35ab6019dccbe18.tar.gz
podman-26d02e97395b2fb5ab5abdc0a35ab6019dccbe18.tar.bz2
podman-26d02e97395b2fb5ab5abdc0a35ab6019dccbe18.zip
Merge pull request #3471 from giuseppe/small-fixes-cgroups
cgroups v2: fix cpu time
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
}