Skip to content

Commit bbe262e

Browse files
committed
Fix error when perf is not available
1 parent 5e75d8c commit bbe262e

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
@@ -579,27 +579,41 @@ function generate_benchmark_definition(
579579
$(params.linux_perf_options.events),
580580
$(params.linux_perf_options.spaces),
581581
)
582-
__linux_perf_bench = BenchmarkTools.LinuxPerf.make_bench_threaded(
583-
__linux_perf_groups; threads=$(params.linux_perf_options.threads)
584-
)
582+
__linux_perf_bench = nothing
585583
try
586-
BenchmarkTools.LinuxPerf.enable!(__linux_perf_bench)
587-
# We'll just run it one time.
588-
__return_val_2 = $(invocation)
589-
BenchmarkTools.LinuxPerf.disable!(__linux_perf_bench)
590-
# trick the compiler not to eliminate the code
591-
if rand() < 0
592-
__linux_perf_stats = __return_val_2
584+
__linux_perf_bench = BenchmarkTools.LinuxPerf.make_bench_threaded(
585+
__linux_perf_groups; threads=$(params.linux_perf_options.threads)
586+
)
587+
catch e
588+
if e isa ErrorException && startswith(e.msg, "perf_event_open error : ")
589+
@warn "Perf is disabled"
593590
else
594-
__linux_perf_stats = BenchmarkTools.LinuxPerf.Stats(
595-
__linux_perf_bench
596-
)
591+
rethrow()
597592
end
598-
catch
599-
rethrow()
600-
finally
601-
close(__linux_perf_bench)
593+
end
594+
595+
if isnothing(__linux_perf_bench)
602596
$(teardown)
597+
else
598+
try
599+
BenchmarkTools.LinuxPerf.enable!(__linux_perf_bench)
600+
# We'll just run it one time.
601+
__return_val_2 = $(invocation)
602+
BenchmarkTools.LinuxPerf.disable!(__linux_perf_bench)
603+
# trick the compiler not to eliminate the code
604+
if rand() < 0
605+
__linux_perf_stats = __return_val_2
606+
else
607+
__linux_perf_stats = BenchmarkTools.LinuxPerf.Stats(
608+
__linux_perf_bench
609+
)
610+
end
611+
catch
612+
rethrow()
613+
finally
614+
close(__linux_perf_bench)
615+
$(teardown)
616+
end
603617
end
604618
else
605619
__return_val_2 = nothing

0 commit comments

Comments
 (0)