Skip to content

Commit f0dbd7d

Browse files
committed
Fix error when perf is not available
1 parent 93d42dc commit f0dbd7d

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
@@ -591,27 +591,41 @@ function generate_benchmark_definition(
591591
$(params.linux_perf_options.events),
592592
$(params.linux_perf_options.spaces),
593593
)
594-
__linux_perf_bench = BenchmarkTools.LinuxPerf.make_bench_threaded(
595-
__linux_perf_groups; threads=$(params.linux_perf_options.threads)
596-
)
594+
__linux_perf_bench = nothing
597595
try
598-
BenchmarkTools.LinuxPerf.enable!(__linux_perf_bench)
599-
# We'll just run it one time.
600-
__return_val_2 = $(invocation)
601-
BenchmarkTools.LinuxPerf.disable!(__linux_perf_bench)
602-
# trick the compiler not to eliminate the code
603-
if rand() < 0
604-
__linux_perf_stats = __return_val_2
596+
__linux_perf_bench = BenchmarkTools.LinuxPerf.make_bench_threaded(
597+
__linux_perf_groups; threads=$(params.linux_perf_options.threads)
598+
)
599+
catch e
600+
if e isa ErrorException && startswith(e.msg, "perf_event_open error : ")
601+
@warn "Perf is disabled"
605602
else
606-
__linux_perf_stats = BenchmarkTools.LinuxPerf.Stats(
607-
__linux_perf_bench
608-
)
603+
rethrow()
609604
end
610-
catch
611-
rethrow()
612-
finally
613-
close(__linux_perf_bench)
605+
end
606+
607+
if isnothing(__linux_perf_bench)
614608
$(teardown)
609+
else
610+
try
611+
BenchmarkTools.LinuxPerf.enable!(__linux_perf_bench)
612+
# We'll just run it one time.
613+
__return_val_2 = $(invocation)
614+
BenchmarkTools.LinuxPerf.disable!(__linux_perf_bench)
615+
# trick the compiler not to eliminate the code
616+
if rand() < 0
617+
__linux_perf_stats = __return_val_2
618+
else
619+
__linux_perf_stats = BenchmarkTools.LinuxPerf.Stats(
620+
__linux_perf_bench
621+
)
622+
end
623+
catch
624+
rethrow()
625+
finally
626+
close(__linux_perf_bench)
627+
$(teardown)
628+
end
615629
end
616630
else
617631
__return_val_2 = nothing

0 commit comments

Comments
 (0)