Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add BenchmarkTools integration #1

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/ValgrindBenchmarkTools/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name = "ValgrindBenchmarkTools"
uuid = "cddf0403-163e-426d-bfc7-5afd20e79fa3"
authors = ["Valentin Churavy <[email protected]>"]
version = "0.1.0"

[deps]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
Valgrind = "a52a33a2-b08a-4c46-b084-8041b090a67d"
15 changes: 15 additions & 0 deletions lib/ValgrindBenchmarkTools/examples/callgrind.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using BenchmarkTools
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Been a while since I touched this code, but don't think you need this.

using ValgrindBenchmarkTools

@noinline function g(a)
c = 0
for x in a
if x > 0
c += 1
end
end
c
end
const data = zeros(10000)

@show @benchmark g($data)
30 changes: 30 additions & 0 deletions lib/ValgrindBenchmarkTools/src/ValgrindBenchmarkTools.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module ValgrindBenchmarkTools

using Valgrind, Reexport
@reexport using BenchmarkTools

@inline function prehook()
Valgrind.Callgrind.zero_stats()
Copy link

@Zentrik Zentrik Aug 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could move zero_stats into the setup_prehook just so it's more isolated from the code being benchmarked, i.e. its not part of the function at https://github.com/Zentrik/BenchmarkTools.jl/blob/a77bfca26390681d889460366cb9980ba36103c9/src/execution.jl#L656-L666

Valgrind.Callgrind.start_instrumentation()
end

@inline function posthook(id)
Valgrind.Callgrind.stop_instrumentation()
Valgrind.Callgrind.dump_stats_at(id)
Copy link

@Zentrik Zentrik Aug 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing you want dump_stats_at in the sample_result hook instead if you're trying to store the result of dump_stats_at as part of your benchmark results.

end

function __init__()
BenchmarkTools.DEFAULT_PARAMETERS = BenchmarkTools.Parameters(;
prehook = prehook,
posthook = posthook,
enable_customizable_func = :ALL,
)
Copy link

@Zentrik Zentrik Aug 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't want to run the normal benchmarking BenchmarkTools does you can set run_customizable_func_only to true.


# Serialization
BenchmarkTools.VERSIONS["Valgrind"] = pkgversion(Valgrind)
BenchmarkTools.VERSIONS["ValgrindBenchmarkTools.jl"] =
pkgversion(ValgrindBenchmarkTools)
end


end # module ValgrindBenchmarkTools