20 bins = [1 << n for n in range(4, 13)]
33 sep_pos = reversed(range(c-3, 0, -3))
34 return ','.join([sn[:c%3 or 3]] + [str(sn[i:i+3]) for i in sep_pos])
44 def percent(n, total):
45 return rm0(float(n) / total * 100) + '%'
48 for mult in sorted(bytes_suffix.keys(), reverse=True):
50 return '%s bytes [%s%s]' % (num(n),
56 f.readline() # ignore headers
65 no_scan = bool(int(d[NO_SCAN]))
68 size_freq[size] = size_freq.get(size, 0) + 1
71 size_freq_ti[size] = size_freq_ti.get(size, 0) + 1
73 scan_c = len(sizes_ti)
74 no_scan_c = len(sizes)
75 total_c = scan_c + no_scan_c
77 scan_b = sum(sizes_ti)
78 no_scan_b = sum(sizes)
79 total_b = scan_b + no_scan_b
81 p('Total requested: %s objecs, %s', num(total_c), bytes(total_b))
82 p('\tScanned: %s (%s) objecs, %s (%s)', num(scan_c), percent(scan_c, total_c),
83 bytes(scan_b), percent(scan_b, total_b))
84 p('\tNot scanned: %s (%s) objecs, %s (%s)', num(no_scan_c),
85 percent(no_scan_c, total_c), bytes(no_scan_b),
86 percent(no_scan_b, total_b))
88 different_sizes_c = len(set(size_freq.keys()).union(size_freq_ti.keys()))
89 p('Different object sizes: %s', num(different_sizes_c))
91 p('Objects requested with a bin size of:')
93 n = sum((freq for size, freq in size_freq.iteritems() if size <= bins[0]))
94 n += sum((freq for size, freq in size_freq_ti.iteritems() if size <= bins[0]))
95 b = sum((size*freq for size, freq in size_freq.iteritems() if size <= bins[0]))
96 b += sum((size*freq for size, freq in size_freq_ti.iteritems()
100 p('\t%s bytes: %s (%s) objects, %s (%s)', bins[0], num(n),
101 percent(n, total_c), bytes(b), percent(b, total_b))
105 n = sum((freq for size, freq in size_freq.iteritems() if size <= bin))
106 n += sum((freq for size, freq in size_freq_ti.iteritems()
108 b = sum((size*freq for size, freq in size_freq.iteritems()
110 b += sum((size*freq for size, freq in size_freq_ti.iteritems()
116 p('\t%s bytes: %s (%s, %s cumulative) objects, '
117 '%s (%s, %s cumulative)', bin, num(nn),
118 percent(nn, total_c), percent(n, total_c),
119 bytes(bb), percent(bb, total_b),
123 n = sum((freq for size, freq in size_freq.iteritems() if size > 4096))
124 n += sum((freq for size, freq in size_freq_ti.iteritems() if size > 4096))
125 b = sum((size*freq for size, freq in size_freq.iteritems() if size > 4096))
126 b += sum((size*freq for size, freq in size_freq_ti.iteritems() if size > 4096))
129 p('\tmore than a page: %s (%s) objects, %s (%s)', num(n),
130 percent(n, total_c), bytes(b), percent(b, total_b))
132 def wasted_bin(start, end, extra=0):
134 for i in range(start, end+1):
135 w += (end - i) * size_freq.get(i, 0)
136 if i <= (end - extra):
137 w += (end - i) * size_freq_ti.get(i, 0)
139 w += (2*end - i) * size_freq_ti.get(i, 0)
142 def wasted_pageplus(extra=0):
144 for size, freq in size_freq.iteritems():
146 w += (size % 4096) * freq
147 for size, freq in size_freq_ti.iteritems():
150 w += (size % 4096 + extra) * freq
153 def print_wasted(mode, extra=0):
155 wasted[bins[0]] = wasted_bin(1, bins[0], extra)
157 wasted[bin] = wasted_bin(bin/2 + 1, bin, extra)
158 wasted_pplus = wasted_pageplus()
159 wasted_total = sum((w for w in wasted.values())) + wasted_pplus
160 alloc_total = wasted_total + total_b
162 p('\tTotal allocated: %s', bytes(alloc_total))
163 p('\tTotal wasted: %s, %s', bytes(wasted_total), percent(wasted_total,
165 p('\tWasted due to objects that should use a bin of:')
167 p('\t %s bytes: %s (%s)', bins[0], bytes(wasted[bins[0]]),
168 percent(wasted[bins[0]], wasted_total))
169 w_cumulative = wasted[bins[0]]
171 if wasted[bin] == 0 and alloc_c[bin] == 0:
173 w_cumulative += wasted[bin]
174 p('\t %s bytes: %s (%s, %s cumulative)', bin,
175 bytes(wasted[bin]), percent(wasted[bin],
176 wasted_total), percent(w_cumulative,
179 p('\t more than a page: %s (%s)', bytes(wasted_pplus),
180 percent(wasted_pplus, wasted_total))
182 print_wasted('Conservative')
183 print_wasted('Precise', 4)
185 #print size_freq, size_freq_ti