Skip to content

Commit

Permalink
Show details for top large allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Mar 19, 2016
1 parent 7493345 commit e7cb7b0
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion tools/groonga-memory-usage-analyzer.rb
Expand Up @@ -97,7 +97,8 @@ def format_size(size)
"Location",
"N allocations",
])
statistics.sort_by_size.reverse[0, 10].each do |group|
top_allocated_groups = statistics.sort_by_size.reverse_each.take(10)
top_allocated_groups.each do |group|
puts("%10s(%10s:%10s:%10s): %s(%d)" % [
format_size(group.total_size),
format_size(group.average_size),
Expand All @@ -107,3 +108,20 @@ def format_size(size)
group.memories.size,
])
end

puts
puts("Top allocated location's details")
top_allocated_group = top_allocated_groups.first
target_memories = top_allocated_group.memories
size_width = Math.log10(target_memories.size).floor + 1
target_memories.group_by(&:size).sort_by do |size, memories|
size * memories.size
end.reverse_each do |size, memories|
total_size = memories.inject(0) {|sum, memory| sum + memory.size}
puts("%10s(%10s * %#{size_width}d): %s" % [
format_size(total_size),
format_size(size),
memories.size,
memories.first.location,
])
end

0 comments on commit e7cb7b0

Please sign in to comment.