mirror of
https://github.com/kemko/liquid.git
synced 2026-01-01 15:55:40 +03:00
Fix total_render_time if a Profiler gets used for multiple renders
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -193,6 +193,10 @@ module Liquid
|
||||
# Retrying a render resets resource usage
|
||||
context.resource_limits.reset
|
||||
|
||||
if @profiling && context.profiler.nil?
|
||||
@profiler = context.profiler = Liquid::Profiler.new
|
||||
end
|
||||
|
||||
begin
|
||||
# render the nodelist.
|
||||
with_profiling(context) do
|
||||
@@ -221,18 +225,8 @@ module Liquid
|
||||
end
|
||||
|
||||
def with_profiling(context)
|
||||
if @profiling && context.profiler.nil?
|
||||
@profiler = context.profiler = Profiler.new
|
||||
@profiler.start
|
||||
|
||||
begin
|
||||
yield
|
||||
ensure
|
||||
@profiler.stop
|
||||
end
|
||||
else
|
||||
yield
|
||||
end
|
||||
return yield unless context.profiler
|
||||
context.profiler.profile { yield }
|
||||
end
|
||||
|
||||
def apply_options_to_context(context, options)
|
||||
|
||||
Reference in New Issue
Block a user