lib/heap_profiler/results.rb in heap-profiler-0.1.0 vs lib/heap_profiler/results.rb in heap-profiler-0.2.0
- old
+ new
@@ -76,12 +76,12 @@
@colorize = color_output ? Polychrome : Monochrome
analyzer = Analyzer.new(heap, index)
dimensions = analyzer.run(@metrics, @groupings)
- io.puts "Total: #{scale_bytes(dimensions['total_memory'].stats)} " \
- "(#{dimensions['total_objects'].stats} objects)"
+ io.puts "Total: #{scale_bytes(dimensions['total'].memory)} " \
+ "(#{dimensions['total'].objects} objects)"
@metrics.each do |metric|
next if metric == "strings"
@groupings.each do |grouping|
dump_data(io, dimensions, metric, grouping, options)
@@ -93,11 +93,11 @@
end
end
def dump_data(io, dimensions, metric, grouping, options)
print_title io, "#{metric} by #{grouping}"
- data = dimensions["#{metric}_by_#{grouping}"].top_n(options.fetch(:top, 50))
+ data = dimensions[grouping].top_n(metric, options.fetch(:top, 50))
scale_data = metric == "memory" && options[:scale_bytes]
normalize_paths = options[:normalize_paths]
if data && !data.empty?
@@ -139,11 +139,11 @@
@groupings = groupings
end
def pretty_print(io = $stdout, **options)
diff = Diff.new(@directory)
- heaps = @types.to_h { |t| [t, diff.public_send("#{t}_diff")] }
+ heaps = @types.each_with_object({}) { |t, h| h[t] = diff.public_send("#{t}_diff") }
index = Index.new(diff.allocated)
color_output = options.fetch(:color_output) { io.respond_to?(:isatty) && io.isatty }
@colorize = color_output ? Polychrome : Monochrome
@@ -152,12 +152,12 @@
analyzer = Analyzer.new(heap, index)
dimensions[type] = analyzer.run(@metrics, @groupings)
end
dimensions.each do |type, metrics|
- io.puts "Total #{type}: #{scale_bytes(metrics['total_memory'].stats)} " \
- "(#{metrics['total_objects'].stats} objects)"
+ io.puts "Total #{type}: #{scale_bytes(metrics['total'].memory)} " \
+ "(#{metrics['total'].objects} objects)"
end
@types.each do |type|
@metrics.each do |metric|
next if metric == "strings"
@@ -174,10 +174,10 @@
end
end
def dump_data(io, dimensions, type, metric, grouping, options)
print_title io, "#{type} #{metric} by #{grouping}"
- data = dimensions[type]["#{metric}_by_#{grouping}"].top_n(options.fetch(:top, 50))
+ data = dimensions[type][grouping].top_n(metric, options.fetch(:top, 50))
scale_data = metric == "memory" && options[:scale_bytes]
normalize_paths = options[:normalize_paths]
if data && !data.empty?