Skip to content

Commit 7d4377c

Browse files
Fix issues found by JET.jl (#57)
* put accumulated_data in second if block * use Hendriks suggestion * define dummy accumulated_data in disabled case * fix comments * use default TimeData
1 parent 45d85d5 commit 7d4377c

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

src/trixi_timeit.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ macro trixi_timeit(timer_output, label, expr)
5757
local enabled = to.enabled
5858
if enabled
5959
local accumulated_data = $(TimerOutputs.push!)(to, $(esc(label)))
60+
else
61+
# dummy to avoid issues with JET.jl complaining about potentially undefined variables
62+
local accumulated_data = TimerOutputs.TimeData()
6063
end
6164
local b0 = $(TimerOutputs.gc_bytes)()
6265
local t0 = $(TimerOutputs.time_ns)()

test/test_timers.jl

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
@test actual == expected
5858
end
5959

60-
@testset verbose=true "disable and enable timings" begin
60+
@testset verbose=true "disable and enable timings using disable_debug_timings and enable_debug_timings" begin
6161
# Start with empty timer output
6262
TrixiBase.TimerOutputs.reset_timer!(timer())
6363

@@ -68,13 +68,52 @@
6868
@trixi_timeit timer() "test timer" sin(0.0)
6969
@trixi_timeit timer() "test timer" sin(0.0)
7070

71-
# Disable timings
71+
# Enable timings
7272
enable_debug_timings()
7373

7474
# This timing should be counted
7575
@trixi_timeit timer() "test timer 2" sin(0.0)
7676

77-
println(timer())
77+
timer_output = """
78+
─────────────────────────────────────────────────────────────────────────
79+
Time Allocations
80+
─────────────────────── ────────────────────────
81+
Tot / % measured: 23.7ms / 0.0% 1.00MiB / 0.0%
82+
83+
Section ncalls time %tot avg alloc %tot avg
84+
─────────────────────────────────────────────────────────────────────────
85+
test timer 2 1 875ns 100.0% 875ns 48.0B 100.0% 48.0B
86+
─────────────────────────────────────────────────────────────────────────
87+
"""
88+
# Remove "Tot / % measured" line and trailing white spaces and replace
89+
# the "test timer" line (but don't remove it, we want to check that it's there).
90+
expected = replace(timer_output, r"Tot / % measured: .*" => "",
91+
r"\s+\n" => "\n",
92+
r"test timer 2 1 .*B\n" => "test timer 2 1")
93+
actual = replace(repr(timer()) * "\n", r"Tot / % measured: .*" => "",
94+
r"\s+\n" => "\n",
95+
r"test timer 2 1 .*B\n" => "test timer 2 1")
96+
97+
# Compare against empty timer output
98+
@test actual == expected
99+
end
100+
101+
@testset verbose=true "disable and enable timings using disable_timer! and enable_timer!" begin
102+
# Start with empty timer output
103+
TrixiBase.TimerOutputs.reset_timer!(timer())
104+
105+
# Disable timer
106+
TrixiBase.TimerOutputs.disable_timer!(timer())
107+
108+
# These two timings should be disabled
109+
@trixi_timeit timer() "test timer" sin(0.0)
110+
@trixi_timeit timer() "test timer" sin(0.0)
111+
112+
# Enable timer
113+
TrixiBase.TimerOutputs.enable_timer!(timer())
114+
115+
# This timing should be counted
116+
@trixi_timeit timer() "test timer 2" sin(0.0)
78117

79118
timer_output = """
80119
─────────────────────────────────────────────────────────────────────────

0 commit comments

Comments
 (0)