lib/heap_profiler/results.rb in heap-profiler-0.5.0 vs lib/heap_profiler/results.rb in heap-profiler-0.6.0

- old
+ new

@@ -12,15 +12,21 @@ 18 => 'EB', 21 => 'ZB', 24 => 'YB', }.freeze - METRICS = ["memory", "objects", "strings"].freeze + METRICS = ["memory", "objects", "strings", "shape_edges"].freeze + GROUPED_METRICS = ["memory", "objects"] GROUPINGS = ["gem", "file", "location", "class"].freeze attr_reader :types, :dimensions + @top_entries_count = 50 + class << self + attr_accessor :top_entries_count + end + def initialize(*, **) raise NotImplementedError end def print_title(io, title) @@ -80,24 +86,28 @@ io.puts "Total: #{scale_bytes(dimensions['total'].memory)} " \ "(#{dimensions['total'].objects} objects)" @metrics.each do |metric| - next if metric == "strings" + next unless GROUPED_METRICS.include?(metric) @groupings.each do |grouping| dump_data(io, dimensions, metric, grouping, options) end end if @metrics.include?("strings") dump_strings(io, dimensions, options) end + + if @metrics.include?("shape_edges") + dump_shape_edges(io, dimensions, options) + end end def dump_data(io, dimensions, metric, grouping, options) print_title io, "#{metric} by #{grouping}" - data = dimensions[grouping].top_n(metric, options.fetch(:top, 50)) + data = dimensions[grouping].top_n(metric, AbstractResults.top_entries_count) scale_data = metric == "memory" && options[:scale_bytes] normalize_paths = options[:normalize_paths] if data && !data.empty? @@ -110,11 +120,11 @@ end def dump_strings(io, dimensions, options) normalize_paths = options[:normalize_paths] scale_data = options[:scale_bytes] - top = options.fetch(:top, 50) + top = AbstractResults.top_entries_count print_title(io, "String Report") dimensions["strings"].top_n(top).each do |string| memsize = scale_data ? scale_bytes(string.memsize) : string.memsize @@ -125,10 +135,23 @@ print_output2 io, '', string_location.count, location end io.puts end end + + def dump_shape_edges(io, dimensions, _options) + top = AbstractResults.top_entries_count + + data = dimensions["shape_edges"].top_n(top) + unless data.empty? + print_title(io, "Shape Edges Report") + + data.each do |edge_name, count| + print_output io, count, edge_name + end + end + end end class DiffResults < AbstractResults TYPES = ["allocated", "retained"].freeze @@ -158,11 +181,11 @@ "(#{metrics['total'].objects} objects)" end @types.each do |type| @metrics.each do |metric| - next if metric == "strings" + next unless GROUPED_METRICS.include?(metric) @groupings.each do |grouping| dump_data(io, dimensions, type, metric, grouping, options) end end end @@ -170,15 +193,21 @@ if @metrics.include?("strings") @types.each do |type| dump_strings(io, dimensions[type], type, options) end end + + if @metrics.include?("shape_edges") + @types.each do |type| + dump_shape_edges(io, dimensions[type], type, options) + end + end end def dump_data(io, dimensions, type, metric, grouping, options) print_title io, "#{type} #{metric} by #{grouping}" - data = dimensions[type][grouping].top_n(metric, options.fetch(:top, 50)) + data = dimensions[type][grouping].top_n(metric, AbstractResults.top_entries_count) scale_data = metric == "memory" && options[:scale_bytes] normalize_paths = options[:normalize_paths] if data && !data.empty? @@ -191,11 +220,11 @@ end def dump_strings(io, dimensions, type, options) normalize_paths = options[:normalize_paths] scale_data = options[:scale_bytes] - top = options.fetch(:top, 50) + top = AbstractResults.top_entries_count print_title(io, "#{type.capitalize} String Report") dimensions["strings"].top_n(top).each do |string| memsize = scale_data ? scale_bytes(string.memsize) : string.memsize @@ -204,9 +233,22 @@ location = string_location.location location = normalize_path(location) if normalize_paths print_output2 io, '', string_location.count, location end io.puts + end + end + + def dump_shape_edges(io, dimensions, _type, _options) + top = AbstractResults.top_entries_count + + data = dimensions["shape_edges"].top_n(top) + unless data.empty? + print_title(io, "Shape Edges Report") + + data.each do |edge_name, count| + print_output io, count, edge_name + end end end end end