Skip to content

Commit 6f873a0

Browse files
committed
Fix error when perf is not available
1 parent 8061006 commit 6f873a0

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

src/execution.jl

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -593,27 +593,41 @@ function generate_benchmark_definition(
593593
$(params.linux_perf_options.events),
594594
$(params.linux_perf_options.spaces),
595595
)
596-
__linux_perf_bench = BenchmarkTools.LinuxPerf.make_bench_threaded(
597-
__linux_perf_groups; threads=$(params.linux_perf_options.threads)
598-
)
596+
__linux_perf_bench = nothing
599597
try
600-
BenchmarkTools.LinuxPerf.enable!(__linux_perf_bench)
601-
# We'll just run it one time.
602-
__return_val_2 = $(invocation)
603-
BenchmarkTools.LinuxPerf.disable!(__linux_perf_bench)
604-
# trick the compiler not to eliminate the code
605-
if rand() < 0
606-
__linux_perf_stats = __return_val_2
598+
__linux_perf_bench = BenchmarkTools.LinuxPerf.make_bench_threaded(
599+
__linux_perf_groups; threads=$(params.linux_perf_options.threads)
600+
)
601+
catch e
602+
if e isa ErrorException && startswith(e.msg, "perf_event_open error : ")
603+
@warn "Perf is disabled"
607604
else
608-
__linux_perf_stats = BenchmarkTools.LinuxPerf.Stats(
609-
__linux_perf_bench
610-
)
605+
rethrow()
611606
end
612-
catch
613-
rethrow()
614-
finally
615-
close(__linux_perf_bench)
607+
end
608+
609+
if isnothing(__linux_perf_bench)
616610
$(teardown)
611+
else
612+
try
613+
BenchmarkTools.LinuxPerf.enable!(__linux_perf_bench)
614+
# We'll just run it one time.
615+
__return_val_2 = $(invocation)
616+
BenchmarkTools.LinuxPerf.disable!(__linux_perf_bench)
617+
# trick the compiler not to eliminate the code
618+
if rand() < 0
619+
__linux_perf_stats = __return_val_2
620+
else
621+
__linux_perf_stats = BenchmarkTools.LinuxPerf.Stats(
622+
__linux_perf_bench
623+
)
624+
end
625+
catch
626+
rethrow()
627+
finally
628+
close(__linux_perf_bench)
629+
$(teardown)
630+
end
617631
end
618632
else
619633
__return_val_2 = nothing

0 commit comments

Comments
 (0)