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