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