@@ -586,27 +586,41 @@ function generate_benchmark_definition(
586
586
$ (params. linux_perf_options. events),
587
587
$ (params. linux_perf_options. spaces),
588
588
)
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
592
590
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"
600
597
else
601
- __linux_perf_stats = BenchmarkTools. LinuxPerf. Stats (
602
- __linux_perf_bench
603
- )
598
+ rethrow ()
604
599
end
605
- catch
606
- rethrow ()
607
- finally
608
- close (__linux_perf_bench)
600
+ end
601
+
602
+ if isnothing (__linux_perf_bench)
609
603
$ (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
610
624
end
611
625
else
612
626
__return_val_2 = nothing
0 commit comments