Fix total_render_time if a Profiler gets used for multiple renders

This commit is contained in:
Dylan Thacker-Smith
2020-12-09 10:04:34 -05:00
parent 60214b957c
commit b3f132efd1
3 changed files with 42 additions and 18 deletions
+12 -6
View File
@@ -90,14 +90,20 @@ module Liquid
def initialize
@root_timing = Timing.new("", nil)
@timing_stack = [@root_timing]
@render_start_at = nil
@total_render_time = 0.0
end
def start
@render_start_at = monotonic_time
end
def stop
@total_render_time = monotonic_time - @render_start_at
def profile
return yield if @render_start_at
started_at = monotonic_time
begin
@started_at = started_at
yield
ensure
@started_at = nil
@total_render_time += monotonic_time - started_at
end
end
def each(&block)