diff --git a/lib/ValgrindBenchmarkTools/Project.toml b/lib/ValgrindBenchmarkTools/Project.toml new file mode 100644 index 0000000..fad45a5 --- /dev/null +++ b/lib/ValgrindBenchmarkTools/Project.toml @@ -0,0 +1,9 @@ +name = "ValgrindBenchmarkTools" +uuid = "cddf0403-163e-426d-bfc7-5afd20e79fa3" +authors = ["Valentin Churavy "] +version = "0.1.0" + +[deps] +BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" +Reexport = "189a3867-3050-52da-a836-e630ba90ab69" +Valgrind = "a52a33a2-b08a-4c46-b084-8041b090a67d" diff --git a/lib/ValgrindBenchmarkTools/examples/callgrind.jl b/lib/ValgrindBenchmarkTools/examples/callgrind.jl new file mode 100644 index 0000000..b5f81b4 --- /dev/null +++ b/lib/ValgrindBenchmarkTools/examples/callgrind.jl @@ -0,0 +1,15 @@ +using BenchmarkTools +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) \ No newline at end of file diff --git a/lib/ValgrindBenchmarkTools/src/ValgrindBenchmarkTools.jl b/lib/ValgrindBenchmarkTools/src/ValgrindBenchmarkTools.jl new file mode 100644 index 0000000..fc4d6a0 --- /dev/null +++ b/lib/ValgrindBenchmarkTools/src/ValgrindBenchmarkTools.jl @@ -0,0 +1,30 @@ +module ValgrindBenchmarkTools + +using Valgrind, Reexport +@reexport using BenchmarkTools + +@inline function prehook() + Valgrind.Callgrind.zero_stats() + Valgrind.Callgrind.start_instrumentation() +end + +@inline function posthook(id) + Valgrind.Callgrind.stop_instrumentation() + Valgrind.Callgrind.dump_stats_at(id) +end + +function __init__() + BenchmarkTools.DEFAULT_PARAMETERS = BenchmarkTools.Parameters(; + prehook = prehook, + posthook = posthook, + enable_customizable_func = :ALL, + ) + + # Serialization + BenchmarkTools.VERSIONS["Valgrind"] = pkgversion(Valgrind) + BenchmarkTools.VERSIONS["ValgrindBenchmarkTools.jl"] = + pkgversion(ValgrindBenchmarkTools) +end + + +end # module ValgrindBenchmarkTools