From 34f85baab0394f0719aac96b3e4e2d28b4881012 Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Sun, 12 Jun 2016 18:08:35 +0200 Subject: [PATCH] Fix the calculation of total ticks for docker and exec --- client/driver/docker.go | 4 +++- client/stats/cpu.go | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/client/driver/docker.go b/client/driver/docker.go index 972cb6000..6cbf33b62 100644 --- a/client/driver/docker.go +++ b/client/driver/docker.go @@ -9,6 +9,7 @@ import ( "os/exec" "path/filepath" "regexp" + "runtime" "strconv" "strings" "sync" @@ -1008,6 +1009,7 @@ func (h *DockerHandle) collectStats() { h.logger.Printf("[DEBUG] driver.docker: error collecting stats from container %s: %v", h.containerID, err) } }() + numCores := runtime.NumCPU() for { select { case s := <-statsCh: @@ -1037,7 +1039,7 @@ func (h *DockerHandle) collectStats() { cs.UserMode = calculatePercent( s.CPUStats.CPUUsage.UsageInUsermode, s.PreCPUStats.CPUUsage.UsageInUsermode, s.CPUStats.CPUUsage.TotalUsage, s.PreCPUStats.CPUUsage.TotalUsage, cores) - cs.TotalTicks = (cs.Percent / 100) * shelpers.TotalTicksAvailable() + cs.TotalTicks = (cs.Percent / 100) * shelpers.TotalTicksAvailable() / float64(numCores) h.resourceUsageLock.Lock() h.resourceUsage = &cstructs.TaskResourceUsage{ diff --git a/client/stats/cpu.go b/client/stats/cpu.go index 05ae1d92d..3e98048e9 100644 --- a/client/stats/cpu.go +++ b/client/stats/cpu.go @@ -48,7 +48,7 @@ func (c *CpuStats) Percent(cpuTime float64) float64 { // TicksConsumed calculates the total ticks consumes by the process across all // cpu cores func (c *CpuStats) TicksConsumed(percent float64) float64 { - return (percent / 100) * shelpers.TotalTicksAvailable() + return (percent / 100) * shelpers.TotalTicksAvailable() / float64(c.totalCpus) } func (c *CpuStats) calculatePercent(t1, t2 float64, timeDelta int64) float64 {