class Liquid::Profiler


All render times are in seconds. There is a small performance hit when profiling is enabled.
Profiler also exposes the total time of the template’s render in Liquid::Profiler#total_render_time.
end
end
# …
node.children.each do |child2|
# If the template used {% include %}, this node will also have children.
node.render_time
# Render time in seconds of this node
node.line_number
node.partial
# The top-level template name is ‘nil` by default, but can be set in the Liquid::Context before rendering.
# Which template and line number of this node.
node.code
# Access to the node itself
profile.each do |node|
inside of {% include %} tags.
This is a tree structure that is Enumerable all the way down, and keeps track of tags and rendering times
where in the templates these tags live, and how long each tag took to render.
This object contains all profiling information, containing information on what tags were rendered,
profile = template.profiler
output = template.render
template = Liquid::Template.parse(template_content, profile: true)
class via the Liquid::Template#profiler method.
After Liquid::Template#render is called, the template object makes available an instance of this
Then, to profile a parse/render cycle, pass the profile: true option to Liquid::Template.parse.
To enable profiling, first require ’liquid/profiler’.
Profiler enables support for profiling template rendering to help track down performance issues.

def [](idx)

def [](idx)
  children[idx]
end

def children

def children
  children = @root_children
  if children.length == 1
    children.first.children
  else
    children
  end
end

def each(&block)

def each(&block)
  children.each(&block)
end

def initialize

def initialize
  @root_children = []
  @current_children = nil
  @total_time = 0.0
end

def length

def length
  children.length
end

def monotonic_time

def monotonic_time
  Process.clock_gettime(Process::CLOCK_MONOTONIC)
end

def profile(template_name, &block)

def profile(template_name, &block)
  # nested renders are done from a tag that already has a timing node
  return yield if @current_children
  root_children = @root_children
  render_idx = root_children.length
  begin
    @current_children = root_children
    profile_node(template_name, &block)
  ensure
    @current_children = nil
    if (timing = root_children[render_idx])
      @total_time += timing.total_time
    end
  end
end

def profile_node(template_name, code: nil, line_number: nil)

def profile_node(template_name, code: nil, line_number: nil)
  timing = Timing.new(code: code, template_name: template_name, line_number: line_number)
  parent_children = @current_children
  start_time = monotonic_time
  begin
    @current_children = timing.children
    yield
  ensure
    @current_children = parent_children
    timing.total_time = monotonic_time - start_time
    parent_children << timing
  end
end