Skip to content

Commit 929f1c1

Browse files
committed
Default to not using perf
1 parent 8e6e3a5 commit 929f1c1

File tree

3 files changed

+22
-57
lines changed

3 files changed

+22
-57
lines changed

docs/src/manual.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ You can pass the following keyword arguments to `@benchmark`, `@benchmarkable`,
8585
- `gcsample`: If `true`, run `gc()` before each sample. Defaults to `BenchmarkTools.DEFAULT_PARAMETERS.gcsample = false`.
8686
- `time_tolerance`: The noise tolerance for the benchmark's time estimate, as a percentage. This is utilized after benchmark execution, when analyzing results. Defaults to `BenchmarkTools.DEFAULT_PARAMETERS.time_tolerance = 0.05`.
8787
- `memory_tolerance`: The noise tolerance for the benchmark's memory estimate, as a percentage. This is utilized after benchmark execution, when analyzing results. Defaults to `BenchmarkTools.DEFAULT_PARAMETERS.memory_tolerance = 0.01`.
88-
- `enable_linux_perf`: If `true`, profile using perf once. Defaults to `BenchmarkTools.DEFAULT_PARAMETERS.enable_linux_perf`, which is `true` if perf is available and `false` otherwise.
88+
- `enable_linux_perf`: If `true`, profile using perf once. Defaults to `BenchmarkTools.DEFAULT_PARAMETERS.enable_linux_perf = false`.
8989
- `linux_perf_opts`: Options for perf profiling. Defaults to `BenchmarkTools.DEFAULT_PARAMETERS.linux_perf_opts = String[]`. See LinuxPerf.jl for further details.
9090

9191
To change the default values of the above fields, one can mutate the fields of `BenchmarkTools.DEFAULT_PARAMETERS`, for example:

src/execution.jl

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -599,41 +599,28 @@ function generate_benchmark_definition(
599599
__linux_perf_groups = $LinuxPerf.set_default_spaces(
600600
eval(__linux_perf_options.events), eval(__linux_perf_options.spaces)
601601
)
602-
__linux_perf_bench = nothing
602+
__linux_perf_bench = $LinuxPerf.make_bench_threaded(
603+
__linux_perf_groups; threads=eval(__linux_perf_options.threads)
604+
)
605+
606+
$(setup)
603607
try
604-
__linux_perf_bench = $LinuxPerf.make_bench_threaded(
605-
__linux_perf_groups; threads=eval(__linux_perf_options.threads)
606-
)
607-
catch e
608-
if e isa ErrorException &&
609-
startswith(e.msg, "perf_event_open error : ")
610-
@warn "Perf is disabled" # Really we only want to do this if we defaulted to running with perf, otherwise we should just throw.
611-
# Given we now more accurately determine if perf is available can we do away with this hack?
608+
$LinuxPerf.enable!(__linux_perf_bench)
609+
# We'll just run it one time.
610+
__return_val_2 = $(invocation)
611+
$LinuxPerf.disable!(__linux_perf_bench)
612+
# trick the compiler not to eliminate the code
613+
if rand() < 0
614+
__linux_perf_stats = __return_val_2
612615
else
613-
rethrow()
614-
end
615-
end
616-
617-
if !isnothing(__linux_perf_bench)
618-
$(setup)
619-
try
620-
$LinuxPerf.enable!(__linux_perf_bench)
621-
# We'll just run it one time.
622-
__return_val_2 = $(invocation)
623-
$LinuxPerf.disable!(__linux_perf_bench)
624-
# trick the compiler not to eliminate the code
625-
if rand() < 0
626-
__linux_perf_stats = __return_val_2
627-
else
628-
__linux_perf_stats = $LinuxPerf.Stats(__linux_perf_bench)
629-
end
630-
return __linux_perf_stats
631-
catch
632-
rethrow()
633-
finally
634-
close(__linux_perf_bench)
635-
$(teardown)
616+
__linux_perf_stats = $LinuxPerf.Stats(__linux_perf_bench)
636617
end
618+
return __linux_perf_stats
619+
catch
620+
rethrow()
621+
finally
622+
close(__linux_perf_bench)
623+
$(teardown)
637624
end
638625
end
639626
$BenchmarkTools.Benchmark(

src/parameters.jl

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,6 @@ mutable struct Parameters
1919
linux_perf_options::Vector{String}
2020
end
2121

22-
const DEFAULT_LINUX_PERF_OPTIONS = String[]
23-
24-
function perf_available()
25-
if !Sys.islinux()
26-
return false
27-
end
28-
29-
bench = nothing
30-
try
31-
opts = LinuxPerf.parse_pstats_options(DEFAULT_LINUX_PERF_OPTIONS)
32-
groups = LinuxPerf.set_default_spaces(eval(opts.events), eval(opts.spaces))
33-
bench = LinuxPerf.make_bench_threaded(groups; threads=eval(opts.threads))
34-
return true
35-
catch
36-
return false
37-
finally
38-
if !isnothing(bench)
39-
close(bench)
40-
end
41-
end
42-
end
43-
4422
const DEFAULT_PARAMETERS = Parameters(
4523
5.0,
4624
10000,
@@ -51,8 +29,8 @@ const DEFAULT_PARAMETERS = Parameters(
5129
false,
5230
0.05,
5331
0.01,
54-
perf_available(),
55-
DEFAULT_LINUX_PERF_OPTIONS,
32+
false,
33+
String[],
5634
)
5735

5836
function Parameters(;

0 commit comments

Comments
 (0)