Browse Source

partial multiple origins

main
pvincent 2 months ago
parent
commit
bd6405f7e1
  1. 2
      lib/semantic/helper.rb
  2. 21
      lib/semantic/subscribers/action_view.rb

2
lib/semantic/helper.rb

@ -19,7 +19,7 @@ module Semantic
return trace unless match
_, m2, _, m4 = match.captures
"#{symbol} #{m2} #{BOLD}#{m4.chop}#{CLEAR}"
"#{symbol} #{m2} #{colorize(m4.chop, BOLD)}"
end
end
end

21
lib/semantic/subscribers/action_view.rb

@ -14,12 +14,9 @@ module Semantic
def render_partial(event)
identifier = pathname(event.payload[:identifier])
partial_savings = @partials[event.transaction_id] ||= {}
partial_saving = partial_savings[identifier] ||= {
# TODO: might be smarter: origins=[{caller:, count:}]
count: 0,
first_origin: Rails.backtrace_cleaner.clean(caller)[1]
}
partial_saving[:count] += 1
partial_saving = partial_savings[identifier] ||= {}
origin = Rails.backtrace_cleaner.clean(caller)[1] # [0] is related to Instrumentalizer, get rid of it!
partial_saving[origin] = partial_saving.key?(origin) ? partial_saving[origin] + 1 : 1
end
def render_template(event)
@ -61,10 +58,14 @@ module Semantic
def pop_partial_savings(transaction_id)
partial_savings = @partials.delete(transaction_id)
partial_savings.each do |partial, saving|
count_info = " (#{saving[:count]} times)" if saving[:count] > 1
logger.debug("Rendered partial #{partial}#{count_info}")
logger.debug(Semantic::Helper.stackisize(saving[:first_origin], symbol: '⇤'))
partial_savings.each do |partial, origins|
sum_count = origins.values.reduce(:+)
sum_count_info = " (#{sum_count} times in total)" if sum_count > 1
logger.debug("Rendered partial #{partial}#{sum_count_info}")
origins.each do |origin, count|
count_info = colorize("(#{count} times)", TEXT_GRAY_400) if count > 1
logger.debug("#{Semantic::Helper.stackisize(origin, symbol: '⇤')}#{count_info}")
end
end
end

Loading…
Cancel
Save