mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
libct/cg/fs: add GetStats benchmark
On my CentOS 8 VM it shows: > BenchmarkGetStats-8 8376 625135 ns/op Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user