Skip to content

Commit af77b18

Browse files
authored
Ruby: Improve --arena-stats output in analyze (#1324)
**Before** <img width="2944" height="1254" alt="CleanShot 2026-03-07 at 14 30 28@2x" src="https://github.com/user-attachments/assets/3813a794-a2e3-4eae-92bc-631b2aa600b0" /> **After** <img width="2944" height="1254" alt="CleanShot 2026-03-07 at 14 30 42@2x" src="https://github.com/user-attachments/assets/951cc7c9-4723-48bf-a173-68a2f0e3424d" />
1 parent 38d4fd9 commit af77b18

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

lib/herb/project.rb

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,12 +1039,26 @@ def print_arena_summary(file_results)
10391039
puts " #{label("Total")} #{cyan(format_bytes(total_bytes))} across #{cyan("#{stats.size} #{pluralize(stats.size, "file")}")}"
10401040
puts " #{label("Largest")} #{cyan(relative_path(max[:file]))} (#{cyan(format_bytes(max[:bytes]))}, #{cyan("#{max[:pages]} #{pluralize(max[:pages], "page")}")})"
10411041

1042-
thresholds = { "16 KB" => 16 * 1024, "64 KB" => 64 * 1024, "128 KB" => 128 * 1024, "256 KB" => 256 * 1024, "512 KB" => 512 * 1024 }
1042+
boundaries = [0, 16 * 1024, 64 * 1024, 128 * 1024, 256 * 1024, 512 * 1024]
10431043

1044+
total = stats.size
10441045
puts ""
1045-
thresholds.each do |label_text, threshold|
1046-
count = stats.count { |stat| stat[:bytes] > threshold }
1047-
puts " #{label(" > #{label_text}")} #{count} #{pluralize(count, "file")}"
1046+
bucket_counts = []
1047+
boundaries.each_cons(2) do |low, high|
1048+
count = stats.count { |stat| stat[:bytes] > low && stat[:bytes] <= high }
1049+
low_label = format_bytes(low).rjust(6)
1050+
high_label = format_bytes(high).rjust(6)
1051+
bucket_counts << { label: " #{low_label} - #{high_label}", count: count }
1052+
end
1053+
last = boundaries.last
1054+
count = stats.count { |stat| stat[:bytes] > last }
1055+
bucket_counts << { label: " > #{format_bytes(last)}", count: count }
1056+
1057+
count_width = bucket_counts.max_by { |b| b[:count] }[:count].to_s.length
1058+
pct_width = bucket_counts.map { |b| "#{percentage(b[:count], total)}%".length }.max
1059+
bucket_counts.each do |bucket|
1060+
pct = "#{percentage(bucket[:count], total)}%"
1061+
puts " #{label(bucket[:label], 19)} #{bucket[:count].to_s.rjust(count_width)} #{pluralize(bucket[:count], "file").ljust(5)} #{pct.rjust(pct_width)}"
10481062
end
10491063
end
10501064

0 commit comments

Comments
 (0)