-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
LinuxPerf
extension for branch + instruction counts
This updates the core BenchmarkTools types to include `instructions` and `branches` fields. These fields support serialization and all of the usual stats / judgements via the Trial / TrialEstimate / TrialRatio interface. If the extension is not available or `perf` is not configured correctly on your system, these are `NaN`. This also keeps the serialization format backwards-compatible, reporting any missing measurements as `NaN`.
- Loading branch information
1 parent
b9f4c5e
commit 21ca9cd
Showing
15 changed files
with
626 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module LinuxPerfExt | ||
|
||
import BenchmarkTools: PerfInterface | ||
import LinuxPerf: LinuxPerf, PerfBench, EventGroup, EventType | ||
import LinuxPerf: enable!, disable!, enable_all!, disable_all!, close, read! | ||
|
||
function interface() | ||
let g = try | ||
EventGroup([EventType(:hw, :instructions), EventType(:hw, :branches)]) | ||
catch | ||
# If perf is not working on the system, the above constructor will throw an | ||
# ioctl or perf_event_open error (after presenting a warning to the user) | ||
return PerfInterface() | ||
end | ||
close(g) | ||
length(g.fds) != 2 && return PerfInterface() | ||
end | ||
|
||
# If we made it here, perf seems to be working on this system | ||
return PerfInterface(; | ||
setup=() -> | ||
let g = EventGroup([EventType(:hw, :instructions), EventType(:hw, :branches)]) | ||
PerfBench(0, EventGroup[g]) | ||
end, | ||
start=(bench) -> enable_all!(), | ||
stop=(bench) -> disable_all!(), | ||
# start=(bench) -> enable!(bench), | ||
# stop=(bench) -> disable!(bench), | ||
teardown=(bench) -> close(bench), | ||
read=(bench) -> let g = only(bench.groups) | ||
(N, time_enabled, time_running, insts, branches) = read!(g.leader_io, Vector{UInt64}(undef, 5)) | ||
if 2 * time_running <= time_enabled | ||
# enabled less than 50% of the time | ||
# (most likely due to PMU contention with other perf events) | ||
return (NaN, NaN) | ||
else | ||
# account for partially-active measurement | ||
k = time_enabled / time_running | ||
estimated_instructions = Float64(insts) * k | ||
estimated_branches = Float64(branches) * k | ||
return (estimated_instructions, estimated_branches) | ||
end | ||
end, | ||
) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.