Skip to content

Commit e6271b1

Browse files
committed
Add enabling perf and its options to Parameters struct
This allows users to set these. Also disabled perf when not running on Linux, this won't be enough to pass tests as perf is not always available. I want to default to perf on so work needs to be done. Also docs + tests to do.
1 parent 3d8cf07 commit e6271b1

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

docs/src/manual.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ 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+
- `experimental_enable_linux_perf`:
89+
- `linux_perf_opts`:
8890

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

src/execution.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,6 @@ function generate_benchmark_definition(
540540
end
541541
)
542542
end
543-
experimental_enable_linux_perf = true # TODO: take this as input from the user
544-
# TODO: let the user actually provide these options.
545-
linux_perf_opts = LinuxPerf.parse_pstats_options([])
546543
return Core.eval(
547544
eval_module,
548545
quote
@@ -575,13 +572,13 @@ function generate_benchmark_definition(
575572
__evals,
576573
),
577574
)
578-
if $(experimental_enable_linux_perf)
575+
if $(params.experimental_enable_linux_perf)
579576
# Based on https://github.com/JuliaPerf/LinuxPerf.jl/blob/a7fee0ff261a5b5ce7a903af7b38d1b5c27dd931/src/LinuxPerf.jl#L1043-L1061
580577
__linux_perf_groups = BenchmarkTools.LinuxPerf.set_default_spaces(
581-
$(linux_perf_opts.events), $(linux_perf_opts.spaces)
578+
$(params.linux_perf_options.events), $(params.linux_perf_options.spaces)
582579
)
583580
__linux_perf_bench = BenchmarkTools.LinuxPerf.make_bench_threaded(
584-
__linux_perf_groups; threads=$(linux_perf_opts.threads)
581+
__linux_perf_groups; threads=$(params.linux_perf_options.threads)
585582
)
586583
BenchmarkTools.LinuxPerf.enable!(__linux_perf_bench)
587584
# We'll just run it one time.
@@ -595,6 +592,9 @@ function generate_benchmark_definition(
595592
__linux_perf_bench
596593
)
597594
end
595+
else
596+
__return_val_2 = nothing
597+
__linux_perf_stats = nothing
598598
end
599599
return BenchmarkTools.TrialContents(
600600
__time,

src/parameters.jl

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ mutable struct Parameters
1515
gcsample::Bool
1616
time_tolerance::Float64
1717
memory_tolerance::Float64
18+
experimental_enable_linux_perf::Bool
19+
linux_perf_options::@NamedTuple{events::Expr, spaces::Expr, threads::Bool}
1820
end
1921

20-
const DEFAULT_PARAMETERS = Parameters(5.0, 10000, 1, false, 0, true, false, 0.05, 0.01)
22+
# TODO: determine whether perf is available
23+
const DEFAULT_PARAMETERS = Parameters(5.0, 10000, 1, false, 0, true, false, 0.05, 0.01, Sys.islinux(), LinuxPerf.parse_pstats_options([]))
2124

2225
function Parameters(;
2326
seconds=DEFAULT_PARAMETERS.seconds,
@@ -29,6 +32,8 @@ function Parameters(;
2932
gcsample=DEFAULT_PARAMETERS.gcsample,
3033
time_tolerance=DEFAULT_PARAMETERS.time_tolerance,
3134
memory_tolerance=DEFAULT_PARAMETERS.memory_tolerance,
35+
experimental_enable_linux_perf=DEFAULT_PARAMETERS.experimental_enable_linux_perf,
36+
linux_perf_options=DEFAULT_PARAMETERS.linux_perf_options,
3237
)
3338
return Parameters(
3439
seconds,
@@ -40,6 +45,8 @@ function Parameters(;
4045
gcsample,
4146
time_tolerance,
4247
memory_tolerance,
48+
experimental_enable_linux_perf,
49+
linux_perf_options,
4350
)
4451
end
4552

@@ -53,6 +60,8 @@ function Parameters(
5360
gcsample=nothing,
5461
time_tolerance=nothing,
5562
memory_tolerance=nothing,
63+
experimental_enable_linux_perf=nothing,
64+
linux_perf_options=nothing,
5665
)
5766
params = Parameters()
5867
params.seconds = seconds != nothing ? seconds : default.seconds
@@ -65,6 +74,10 @@ function Parameters(
6574
time_tolerance != nothing ? time_tolerance : default.time_tolerance
6675
params.memory_tolerance =
6776
memory_tolerance != nothing ? memory_tolerance : default.memory_tolerance
77+
params.experimental_enable_linux_perf =
78+
experimental_enable_linux_perf != nothing ? experimental_enable_linux_perf : default.experimental_enable_linux_perf
79+
params.linux_perf_options =
80+
linux_perf_options != nothing ? linux_perf_options : default.linux_perf_options
6881
return params::BenchmarkTools.Parameters
6982
end
7083

@@ -76,7 +89,9 @@ function Base.:(==)(a::Parameters, b::Parameters)
7689
a.gctrial == b.gctrial &&
7790
a.gcsample == b.gcsample &&
7891
a.time_tolerance == b.time_tolerance &&
79-
a.memory_tolerance == b.memory_tolerance
92+
a.memory_tolerance == b.memory_tolerance &&
93+
a.experimental_enable_linux_perf == b.experimental_enable_linux_perf &&
94+
a.linux_perf_options == b.linux_perf_options
8095
end
8196

8297
function Base.copy(p::Parameters)
@@ -90,6 +105,8 @@ function Base.copy(p::Parameters)
90105
p.gcsample,
91106
p.time_tolerance,
92107
p.memory_tolerance,
108+
p.experimental_enable_linux_perf,
109+
p.linux_perf_options, # Is this really a copy, the values contain Expr's which store Vector's.
93110
)
94111
end
95112

0 commit comments

Comments
 (0)