Skip to content

Commit 529d153

Browse files
committed
Default to not using perf
1 parent c6a1bb2 commit 529d153

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
@@ -592,41 +592,28 @@ function generate_benchmark_definition(
592592
__linux_perf_groups = $LinuxPerf.set_default_spaces(
593593
eval(__linux_perf_options.events), eval(__linux_perf_options.spaces)
594594
)
595-
__linux_perf_bench = nothing
595+
__linux_perf_bench = $LinuxPerf.make_bench_threaded(
596+
__linux_perf_groups; threads=eval(__linux_perf_options.threads)
597+
)
598+
599+
$(setup)
596600
try
597-
__linux_perf_bench = $LinuxPerf.make_bench_threaded(
598-
__linux_perf_groups; threads=eval(__linux_perf_options.threads)
599-
)
600-
catch e
601-
if e isa ErrorException &&
602-
startswith(e.msg, "perf_event_open error : ")
603-
@warn "Perf is disabled" # Really we only want to do this if we defaulted to running with perf, otherwise we should just throw.
604-
# Given we now more accurately determine if perf is available can we do away with this hack?
601+
$LinuxPerf.enable!(__linux_perf_bench)
602+
# We'll just run it one time.
603+
__return_val_2 = $(invocation)
604+
$LinuxPerf.disable!(__linux_perf_bench)
605+
# trick the compiler not to eliminate the code
606+
if rand() < 0
607+
__linux_perf_stats = __return_val_2
605608
else
606-
rethrow()
607-
end
608-
end
609-
610-
if !isnothing(__linux_perf_bench)
611-
$(setup)
612-
try
613-
$LinuxPerf.enable!(__linux_perf_bench)
614-
# We'll just run it one time.
615-
__return_val_2 = $(invocation)
616-
$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 = $LinuxPerf.Stats(__linux_perf_bench)
622-
end
623-
return __linux_perf_stats
624-
catch
625-
rethrow()
626-
finally
627-
close(__linux_perf_bench)
628-
$(teardown)
609+
__linux_perf_stats = $LinuxPerf.Stats(__linux_perf_bench)
629610
end
611+
return __linux_perf_stats
612+
catch
613+
rethrow()
614+
finally
615+
close(__linux_perf_bench)
616+
$(teardown)
630617
end
631618
end
632619
$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)