libct/cg/fs: add GetStats benchmark
On my CentOS 8 VM it shows:
>   	    8376	    625135 ns/op
@@ -104,3 +104,35 @@ func TestTryDefaultCgroupRoot(t *testing.T) {
t.Errorf("tryDefaultCgroupRoot: want %q, got %q", exp, res)
}
}
+
+func BenchmarkGetStats(b *testing.B) {
+ if cgroups.IsCgroup2UnifiedMode() {
+ b.Skip("cgroup v2 is not supported")
+ }
+
+ cg := &configs.Cgroup{
+ Path: "/some/kind/of/a/path/here",
+ Resources: &configs.Resources{},
+ }
+ m := NewManager(cg, nil, false)
+ err := m.Apply(-1)
+ if err != nil {
+ b.Fatal(err)
+ }
+ defer func() {
+ _ = m.Destroy()
+ }()
+
+ var st *cgroups.Stats
+
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ st, err = m.GetStats()
+ if err != nil {
+ b.Fatal(err)
+ }
+ }
+ if st.CpuStats.CpuUsage.TotalUsage != 0 {
+ b.Fatalf("stats: %+v", st)
+ }
+}
