github.com/opencontainers/runc@v1.2.0-rc.1.0.20240520010911-492dc558cdd6/libcontainer/cgroups/fs/fs_test.go (about) 1 package fs 2 3 import ( 4 "testing" 5 6 "github.com/opencontainers/runc/libcontainer/cgroups" 7 "github.com/opencontainers/runc/libcontainer/configs" 8 ) 9 10 func BenchmarkGetStats(b *testing.B) { 11 if cgroups.IsCgroup2UnifiedMode() { 12 b.Skip("cgroup v2 is not supported") 13 } 14 15 // Unset TestMode as we work with real cgroupfs here, 16 // and we want OpenFile to perform the fstype check. 17 cgroups.TestMode = false 18 defer func() { 19 cgroups.TestMode = true 20 }() 21 22 cg := &configs.Cgroup{ 23 Path: "/some/kind/of/a/path/here", 24 Resources: &configs.Resources{}, 25 } 26 m, err := NewManager(cg, nil) 27 if err != nil { 28 b.Fatal(err) 29 } 30 err = m.Apply(-1) 31 if err != nil { 32 b.Fatal(err) 33 } 34 defer func() { 35 _ = m.Destroy() 36 }() 37 38 var st *cgroups.Stats 39 40 b.ResetTimer() 41 for i := 0; i < b.N; i++ { 42 st, err = m.GetStats() 43 if err != nil { 44 b.Fatal(err) 45 } 46 } 47 if st.CpuStats.CpuUsage.TotalUsage != 0 { 48 b.Fatalf("stats: %+v", st) 49 } 50 }