@@ -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