From 9152b1c9b87a469d4f27e2c6db18859109590dfc Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Sun, 28 Oct 2018 15:34:27 +0530 Subject: [PATCH] Measure the no. of times a template gets rendered (#7316) Merge pull request 7316 --- lib/jekyll/liquid_renderer.rb | 5 ++++- lib/jekyll/liquid_renderer/file.rb | 13 +++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/jekyll/liquid_renderer.rb b/lib/jekyll/liquid_renderer.rb index f895a800..986b7c5e 100644 --- a/lib/jekyll/liquid_renderer.rb +++ b/lib/jekyll/liquid_renderer.rb @@ -31,7 +31,6 @@ module Jekyll end LiquidRenderer::File.new(self, filename).tap do @stats[filename] ||= new_profile_hash - @stats[filename][:count] += 1 end end @@ -43,6 +42,10 @@ module Jekyll @stats[filename][:time] += time end + def increment_count(filename) + @stats[filename][:count] += 1 + end + def stats_table(num_of_rows = 50) LiquidRenderer::Table.new(@stats).to_s(num_of_rows) end diff --git a/lib/jekyll/liquid_renderer/file.rb b/lib/jekyll/liquid_renderer/file.rb index 8d38ffbf..a113e851 100644 --- a/lib/jekyll/liquid_renderer/file.rb +++ b/lib/jekyll/liquid_renderer/file.rb @@ -20,7 +20,9 @@ module Jekyll def render(*args) measure_time do measure_bytes do - @template.render(*args) + measure_counts do + @template.render(*args) + end end end end @@ -29,7 +31,9 @@ module Jekyll def render!(*args) measure_time do measure_bytes do - @template.render!(*args) + measure_counts do + @template.render!(*args) + end end end end @@ -40,6 +44,11 @@ module Jekyll private + def measure_counts + @renderer.increment_count(@filename) + yield + end + def measure_bytes yield.tap do |str| @renderer.increment_bytes(@filename, str.bytesize)