We wanted to show the sum of multiple ActiveSupport notifications during a long process, so here is a tiny snipped to do that, an advanced version is used in Samson
# sum activesupport notification duration for given metrics
def time_sum(metrics, &block)
sum = Hash.new(0.0)
add = ->(m, s, f, *) { sum[m] += 1000 * (f - s) }
metrics.inject(block) do |inner, m|
-> { ActiveSupport::Notifications.subscribed(add, m, &inner) }
end.call
sum
end
time_sum(["sql.active_record"]) { 10.times { User.first } }
# {"sql.active_record" => 10.3}