Add cpu throttling stats.

Docker-DCO-1.1-Signed-off-by: Rohit Jnagal <jnagal@google.com> (github: rjnagal)
This commit is contained in:
Rohit Jnagal 2014-04-29 00:18:18 +00:00
parent 5479a8e86f
commit 51d9b2b0a0
2 changed files with 64 additions and 3 deletions

40
cgroups/fs/cpu_test.go Normal file
View file

@ -0,0 +1,40 @@
package fs
import (
"testing"
)
func TestCpuStats(t *testing.T) {
helper := NewCgroupTestUtil("cpu", t)
defer helper.cleanup()
cpuStatContent := `nr_periods 2000
nr_throttled 200
throttled_time 42424242424`
helper.writeFileContents(map[string]string{
"cpu.stat": cpuStatContent,
})
cpu := &cpuGroup{}
stats, err := cpu.Stats(helper.CgroupData)
if err != nil {
t.Fatal(err)
}
expected_stats := map[string]float64{
"nr_periods": 2000.0,
"nr_throttled": 200.0,
"throttled_time": 42424242424.0,
}
expectStats(t, expected_stats, stats)
}
func TestNoCpuStatFile(t *testing.T) {
helper := NewCgroupTestUtil("cpu", t)
defer helper.cleanup()
cpu := &cpuGroup{}
_, err := cpu.Stats(helper.CgroupData)
if err == nil {
t.Fatal("Expected to fail, but did not.")
}
}