Skip to content

Commit 3947b3c

Browse files
committed
Fix error when perf is not available
1 parent c40873e commit 3947b3c

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
@@ -586,27 +586,41 @@ function generate_benchmark_definition(
586586
$(params.linux_perf_options.events),
587587
$(params.linux_perf_options.spaces),
588588
)
589-
__linux_perf_bench = BenchmarkTools.LinuxPerf.make_bench_threaded(
590-
__linux_perf_groups; threads=$(params.linux_perf_options.threads)
591-
)
589+
__linux_perf_bench = nothing
592590
try
593-
BenchmarkTools.LinuxPerf.enable!(__linux_perf_bench)
594-
# We'll just run it one time.
595-
__return_val_2 = $(invocation)
596-
BenchmarkTools.LinuxPerf.disable!(__linux_perf_bench)
597-
# trick the compiler not to eliminate the code
598-
if rand() < 0
599-
__linux_perf_stats = __return_val_2
591+
__linux_perf_bench = BenchmarkTools.LinuxPerf.make_bench_threaded(
592+
__linux_perf_groups; threads=$(params.linux_perf_options.threads)
593+
)
594+
catch e
595+
if e isa ErrorException && startswith(e.msg, "perf_event_open error : ")
596+
@warn "Perf is disabled"
600597
else
601-
__linux_perf_stats = BenchmarkTools.LinuxPerf.Stats(
602-
__linux_perf_bench
603-
)
598+
rethrow()
604599
end
605-
catch
606-
rethrow()
607-
finally
608-
close(__linux_perf_bench)
600+
end
601+
602+
if isnothing(__linux_perf_bench)
609603
$(teardown)
604+
else
605+
try
606+
BenchmarkTools.LinuxPerf.enable!(__linux_perf_bench)
607+
# We'll just run it one time.
608+
__return_val_2 = $(invocation)
609+
BenchmarkTools.LinuxPerf.disable!(__linux_perf_bench)
610+
# trick the compiler not to eliminate the code
611+
if rand() < 0
612+
__linux_perf_stats = __return_val_2
613+
else
614+
__linux_perf_stats = BenchmarkTools.LinuxPerf.Stats(
615+
__linux_perf_bench
616+
)
617+
end
618+
catch
619+
rethrow()
620+
finally
621+
close(__linux_perf_bench)
622+
$(teardown)
623+
end
610624
end
611625
else
612626
__return_val_2 = nothing

0 commit comments

Comments
 (0)