Skip to content

Commit c6a1bb2

Browse files
committed
Simplify LinuxPerf parameters
`linux_perf_options` is now significantly simpler, serialization doesn't require LinuxPerf to have a JSON extension. Removed experimental from parameter name so that it's not breaking when this feature becomes non experimental and also because it isn't experimental in my view.
1 parent 504eed3 commit c6a1bb2

File tree

5 files changed

+22
-43
lines changed

5 files changed

+22
-43
lines changed

docs/src/manual.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +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`: If `true`, profile using perf once per sample and return result from last sample. Defaults to `BenchmarkTools.DEFAULT_PARAMETERS.experimental_enable_linux_perf`, which is `true` if perf is available and `false` otherwise.
89-
- `linux_perf_opts`: Options for perf profiling. Defaults to `BenchmarkTools.DEFAULT_PARAMETERS.linux_perf_opts = LinuxPerf.parse_pstats_options([])`.
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.
89+
- `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:
9292

src/execution.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ function _run(b::Benchmark, p::Parameters; verbose=false, pad="", kwargs...)
117117
iters += 1
118118
end
119119

120-
if p.experimental_enable_linux_perf
120+
if p.enable_linux_perf
121121
params.gcsample && gcscrub()
122122
trial.linux_perf_stats = b.linux_perf_func(b.quote_vals, params)
123123
end
@@ -586,15 +586,16 @@ function generate_benchmark_definition(
586586
$(Expr(:tuple, quote_vars...)), __params::$BenchmarkTools.Parameters
587587
)
588588
# Based on https://github.com/JuliaPerf/LinuxPerf.jl/blob/a7fee0ff261a5b5ce7a903af7b38d1b5c27dd931/src/LinuxPerf.jl#L1043-L1061
589+
__linux_perf_options = $LinuxPerf.parse_pstats_options(
590+
__params.linux_perf_options
591+
)
589592
__linux_perf_groups = $LinuxPerf.set_default_spaces(
590-
eval(__params.linux_perf_options.events),
591-
eval(__params.linux_perf_options.spaces),
593+
eval(__linux_perf_options.events), eval(__linux_perf_options.spaces)
592594
)
593595
__linux_perf_bench = nothing
594596
try
595597
__linux_perf_bench = $LinuxPerf.make_bench_threaded(
596-
__linux_perf_groups;
597-
threads=eval(__params.linux_perf_options.threads),
598+
__linux_perf_groups; threads=eval(__linux_perf_options.threads)
598599
)
599600
catch e
600601
if e isa ErrorException &&

src/parameters.jl

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ 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}
18+
enable_linux_perf::Bool
19+
linux_perf_options::Vector{String}
2020
end
2121

22-
const DEFAULT_LINUX_PERF_OPTIONS = LinuxPerf.parse_pstats_options([])
22+
const DEFAULT_LINUX_PERF_OPTIONS = String[]
2323

2424
function perf_available()
2525
if !Sys.islinux()
@@ -28,7 +28,7 @@ function perf_available()
2828

2929
bench = nothing
3030
try
31-
opts = DEFAULT_LINUX_PERF_OPTIONS
31+
opts = LinuxPerf.parse_pstats_options(DEFAULT_LINUX_PERF_OPTIONS)
3232
groups = LinuxPerf.set_default_spaces(eval(opts.events), eval(opts.spaces))
3333
bench = LinuxPerf.make_bench_threaded(groups; threads=eval(opts.threads))
3434
return true
@@ -65,7 +65,7 @@ function Parameters(;
6565
gcsample=DEFAULT_PARAMETERS.gcsample,
6666
time_tolerance=DEFAULT_PARAMETERS.time_tolerance,
6767
memory_tolerance=DEFAULT_PARAMETERS.memory_tolerance,
68-
experimental_enable_linux_perf=DEFAULT_PARAMETERS.experimental_enable_linux_perf,
68+
enable_linux_perf=DEFAULT_PARAMETERS.enable_linux_perf,
6969
linux_perf_options=DEFAULT_PARAMETERS.linux_perf_options,
7070
)
7171
return Parameters(
@@ -78,7 +78,7 @@ function Parameters(;
7878
gcsample,
7979
time_tolerance,
8080
memory_tolerance,
81-
experimental_enable_linux_perf,
81+
enable_linux_perf,
8282
linux_perf_options,
8383
)
8484
end
@@ -93,7 +93,7 @@ function Parameters(
9393
gcsample=nothing,
9494
time_tolerance=nothing,
9595
memory_tolerance=nothing,
96-
experimental_enable_linux_perf=nothing,
96+
enable_linux_perf=nothing,
9797
linux_perf_options=nothing,
9898
)
9999
params = Parameters()
@@ -107,10 +107,10 @@ function Parameters(
107107
time_tolerance != nothing ? time_tolerance : default.time_tolerance
108108
params.memory_tolerance =
109109
memory_tolerance != nothing ? memory_tolerance : default.memory_tolerance
110-
params.experimental_enable_linux_perf = if experimental_enable_linux_perf != nothing
111-
experimental_enable_linux_perf
110+
params.enable_linux_perf = if enable_linux_perf != nothing
111+
enable_linux_perf
112112
else
113-
default.experimental_enable_linux_perf
113+
default.enable_linux_perf
114114
end
115115
params.linux_perf_options =
116116
linux_perf_options != nothing ? linux_perf_options : default.linux_perf_options
@@ -126,7 +126,7 @@ function Base.:(==)(a::Parameters, b::Parameters)
126126
a.gcsample == b.gcsample &&
127127
a.time_tolerance == b.time_tolerance &&
128128
a.memory_tolerance == b.memory_tolerance &&
129-
a.experimental_enable_linux_perf == b.experimental_enable_linux_perf &&
129+
a.enable_linux_perf == b.enable_linux_perf &&
130130
a.linux_perf_options == b.linux_perf_options
131131
end
132132

@@ -141,12 +141,8 @@ function Base.copy(p::Parameters)
141141
p.gcsample,
142142
p.time_tolerance,
143143
p.memory_tolerance,
144-
p.experimental_enable_linux_perf,
145-
(
146-
events=copy(p.linux_perf_options.events),
147-
spaces=copy(p.linux_perf_options.spaces),
148-
threads=copy(p.linux_perf_options.threads),
149-
),
144+
p.enable_linux_perf,
145+
copy(p.linux_perf_options),
150146
)
151147
end
152148

src/serialization.jl

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,6 @@ function recover(x::Vector)
6060
end
6161
elseif ft <: get(SUPPORTED_TYPES, nameof(ft), Union{})
6262
xsi = recover(fields[fn])
63-
elseif fn == "linux_perf_options"
64-
field_val = fields[fn]
65-
xsi = (
66-
events=Expr(
67-
Symbol(field_val["events"]["head"]),
68-
LinuxPerf.parse_groups,
69-
field_val["events"]["args"][2],
70-
),
71-
spaces=Expr(
72-
Symbol(field_val["spaces"]["head"]), field_val["spaces"]["args"]...
73-
),
74-
threads=field_val["threads"],
75-
)
7663
else
7764
xsi = convert(ft, fields[fn])
7865
end

test/SerializationTests.jl

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@ using Test
66
function eq(x::T, y::T) where {T<:Union{values(BenchmarkTools.SUPPORTED_TYPES)...}}
77
return all(i -> eq(getfield(x, i), getfield(y, i)), 1:fieldcount(T))
88
end
9-
function eq(
10-
x::@NamedTuple{events::Expr, spaces::Expr, threads::Bool},
11-
y::@NamedTuple{events::Expr, spaces::Expr, threads::Bool},
12-
)
13-
return x == y
14-
end
9+
eq(x::Vector{String}, y::Vector{String}) = x == y
1510
function eq(x::LinuxPerf.Stats, y::LinuxPerf.Stats)
1611
return all(a -> eq(a[1], a[2]), zip(x.threads, y.threads))
1712
end

0 commit comments

Comments
 (0)