@@ -591,27 +591,41 @@ function generate_benchmark_definition(
591
591
$ (params. linux_perf_options. events),
592
592
$ (params. linux_perf_options. spaces),
593
593
)
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
597
595
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"
605
602
else
606
- __linux_perf_stats = BenchmarkTools. LinuxPerf. Stats (
607
- __linux_perf_bench
608
- )
603
+ rethrow ()
609
604
end
610
- catch
611
- rethrow ()
612
- finally
613
- close (__linux_perf_bench)
605
+ end
606
+
607
+ if isnothing (__linux_perf_bench)
614
608
$ (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
615
629
end
616
630
else
617
631
__return_val_2 = nothing
0 commit comments