Merge pull request #1263 from hashicorp/fix-driver-ticks

Fix the calculation of total ticks for docker and exec
This commit is contained in:
Alex Dadgar 2016-06-12 09:31:39 -07:00 committed by GitHub
commit b2d2112578
2 changed files with 4 additions and 2 deletions

View file

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

View file

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