@@ -579,27 +579,41 @@ function generate_benchmark_definition(
579
579
$ (params. linux_perf_options. events),
580
580
$ (params. linux_perf_options. spaces),
581
581
)
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
585
583
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"
593
590
else
594
- __linux_perf_stats = BenchmarkTools. LinuxPerf. Stats (
595
- __linux_perf_bench
596
- )
591
+ rethrow ()
597
592
end
598
- catch
599
- rethrow ()
600
- finally
601
- close (__linux_perf_bench)
593
+ end
594
+
595
+ if isnothing (__linux_perf_bench)
602
596
$ (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
603
617
end
604
618
else
605
619
__return_val_2 = nothing
0 commit comments