YJIT: handle when all counters are zero in printout code

Also filter with not equal to zero instead of greater than zero, in case
there is memory corruption and counters are negative.

Fixes Shopify/ruby#70
This commit is contained in:
Alan Wu 2021-03-06 11:05:55 -05:00
parent eaab6605b7
commit 7f7e79d802

View File

@ -67,9 +67,14 @@ module UJIT
def print_counters(counters, prefix:, prompt:)
$stderr.puts(prompt)
counters = counters.filter { |key, _| key.start_with?(prefix) }
counters.filter! { |_, value| value > 0 }
counters.filter! { |_, value| value != 0 }
counters.transform_keys! { |key| key.to_s.delete_prefix(prefix) }
if counters.empty?
$stderr.puts(" (all relevant counters are zero)")
return
end
counters = counters.to_a
counters.sort_by! { |(_, counter_value)| counter_value }
longest_name_length = counters.max_by { |(name, _)| name.length }.first.length