diff --git a/src/TrixiBase.jl b/src/TrixiBase.jl index c4829fa..daac03c 100644 --- a/src/TrixiBase.jl +++ b/src/TrixiBase.jl @@ -6,7 +6,8 @@ include("trixi_include.jl") include("trixi_timeit.jl") export trixi_include -export @trixi_timeit, timer, timeit_debug_enabled, disable_debug_timings +export @trixi_timeit, timer, timeit_debug_enabled, + disable_debug_timings, enable_debug_timings function _precompile_manual_() @assert Base.precompile(Tuple{typeof(trixi_include), String}) diff --git a/test/test_timers.jl b/test/test_timers.jl index 9438c72..38bef8e 100644 --- a/test/test_timers.jl +++ b/test/test_timers.jl @@ -56,4 +56,47 @@ # Compare against empty timer output @test actual == expected end + + @testset verbose=true "disable and enable timings" begin + # Start with empty timer output + TrixiBase.TimerOutputs.reset_timer!(timer()) + + # Disable timings + disable_debug_timings() + + # These two timings should be disabled + @trixi_timeit timer() "test timer" sin(0.0) + @trixi_timeit timer() "test timer" sin(0.0) + + # Disable timings + enable_debug_timings() + + # This timing should be counted + @trixi_timeit timer() "test timer 2" sin(0.0) + + println(timer()) + + timer_output = """ + ───────────────────────────────────────────────────────────────────────── + Time Allocations + ─────────────────────── ──────────────────────── + Tot / % measured: 23.7ms / 0.0% 1.00MiB / 0.0% + + Section ncalls time %tot avg alloc %tot avg + ───────────────────────────────────────────────────────────────────────── + test timer 2 1 875ns 100.0% 875ns 48.0B 100.0% 48.0B + ───────────────────────────────────────────────────────────────────────── + """ + # Remove "Tot / % measured" line and trailing white spaces and replace + # the "test timer" line (but don't remove it, we want to check that it's there). + expected = replace(timer_output, r"Tot / % measured: .*" => "", + r"\s+\n" => "\n", + r"test timer 2 1 .*B\n" => "test timer 2 1") + actual = replace(repr(timer()) * "\n", r"Tot / % measured: .*" => "", + r"\s+\n" => "\n", + r"test timer 2 1 .*B\n" => "test timer 2 1") + + # Compare against empty timer output + @test actual == expected + end end;