Skip to content

Commit

Permalink
tests: disable debug output in benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
rfjakob committed Apr 7, 2024
1 parent 2948234 commit 5a51abf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
12 changes: 12 additions & 0 deletions testsuite_c_wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
20 changes: 20 additions & 0 deletions testsuite_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -337,37 +338,48 @@ 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)
}
}

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
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 5a51abf

Please sign in to comment.