From 93b947a8565061036b72ce8ca90182c017d3f8b3 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 7 Apr 2024 21:30:08 +0200 Subject: [PATCH] tests: disable debug output in benchmarks --- testsuite_c_wrappers.go | 12 ++++++++++++ testsuite_unit_test.go | 20 ++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/testsuite_c_wrappers.go b/testsuite_c_wrappers.go index 6047f6d..68c6f9b 100644 --- a/testsuite_c_wrappers.go +++ b/testsuite_c_wrappers.go @@ -17,6 +17,18 @@ func init() { C.enable_debug = 1 } +func enable_debug(state bool) (oldState bool) { + if C.enable_debug == 1 { + oldState = true + } + if state { + C.enable_debug = 1 + } else { + C.enable_debug = 0 + } + return +} + func parse_term_kill_tuple(optarg string, upper_limit int) (error, float64, float64) { cs := C.CString(optarg) tuple := C.parse_term_kill_tuple(cs, C.longlong(upper_limit)) diff --git a/testsuite_unit_test.go b/testsuite_unit_test.go index 9a6a14d..4760e35 100644 --- a/testsuite_unit_test.go +++ b/testsuite_unit_test.go @@ -319,6 +319,7 @@ func Test_is_larger(t *testing.T) { } mockProc(t, procs) + defer procdir_path("/proc") t.Logf("procdir_path=%q", procdir_path("")) permute_is_larger(t, false, procs) @@ -337,30 +338,39 @@ func Test_is_larger_by_rss(t *testing.T) { } mockProc(t, procs) + defer procdir_path("/proc") t.Logf("procdir_path=%q", procdir_path("")) permute_is_larger(t, true, procs) } func Benchmark_parse_meminfo(b *testing.B) { + enable_debug(false) + for n := 0; n < b.N; n++ { parse_meminfo() } } func Benchmark_kill_process(b *testing.B) { + enable_debug(false) + for n := 0; n < b.N; n++ { kill_process() } } func Benchmark_find_largest_process(b *testing.B) { + enable_debug(false) + for n := 0; n < b.N; n++ { find_largest_process() } } func Benchmark_get_oom_score(b *testing.B) { + enable_debug(false) + pid := os.Getpid() for n := 0; n < b.N; n++ { get_oom_score(pid) @@ -368,6 +378,8 @@ func Benchmark_get_oom_score(b *testing.B) { } func Benchmark_get_oom_score_adj(b *testing.B) { + enable_debug(false) + pid := os.Getpid() for n := 0; n < b.N; n++ { var out int @@ -376,6 +388,8 @@ func Benchmark_get_oom_score_adj(b *testing.B) { } func Benchmark_get_vm_rss_kib(b *testing.B) { + enable_debug(false) + pid := os.Getpid() for n := 0; n < b.N; n++ { rss := get_vm_rss_kib(pid) @@ -386,6 +400,8 @@ func Benchmark_get_vm_rss_kib(b *testing.B) { } func Benchmark_get_comm(b *testing.B) { + enable_debug(false) + pid := os.Getpid() for n := 0; n < b.N; n++ { res, comm := get_comm(pid) @@ -399,6 +415,8 @@ func Benchmark_get_comm(b *testing.B) { } func Benchmark_get_cmdline(b *testing.B) { + enable_debug(false) + pid := os.Getpid() for n := 0; n < b.N; n++ { res, comm := get_cmdline(pid) @@ -412,6 +430,8 @@ func Benchmark_get_cmdline(b *testing.B) { } func Benchmark_parse_proc_pid_stat(b *testing.B) { + enable_debug(false) + pid := os.Getpid() for n := 0; n < b.N; n++ { res, out := parse_proc_pid_stat(pid)