20 bins = [1 << n for n in range(4, 13)]
31 def percent(n, total):
32 return '%f' % (float(n) / total * 100)
38 f.readline() # ignore headers
47 no_scan = bool(int(d[NO_SCAN]))
50 size_freq[size] = size_freq.get(size, 0) + 1
53 size_freq_ti[size] = size_freq_ti.get(size, 0) + 1
55 scan_c = len(sizes_ti)
56 no_scan_c = len(sizes)
57 total_c = scan_c + no_scan_c
59 scan_b = sum(sizes_ti)
60 no_scan_b = sum(sizes)
61 total_b = scan_b + no_scan_b
63 p('Number of objects')
64 p('Scanned\tNot scanned\tTotal')
65 p('%s\t%s\t%s', num(scan_c), num(no_scan_c), num(total_c))
69 p('Scanned\tNot scanned\tTotal')
70 p('%s\t%s\t%s', bytes(scan_b), bytes(no_scan_b), bytes(total_b))
73 different_sizes_c = len(set(size_freq.keys()).union(size_freq_ti.keys()))
74 p('Different object sizes')
75 p(num(different_sizes_c))
78 p('Objects requested')
79 p('Bin Size\tNumber\tBytes')
81 n = sum((freq for size, freq in size_freq.iteritems() if size <= bins[0]))
82 n += sum((freq for size, freq in size_freq_ti.iteritems() if size <= bins[0]))
83 b = sum((size*freq for size, freq in size_freq.iteritems() if size <= bins[0]))
84 b += sum((size*freq for size, freq in size_freq_ti.iteritems()
87 p('%s\t%s\t%s', bins[0], num(n), bytes(b))
91 n = sum((freq for size, freq in size_freq.iteritems() if size <= bin))
92 n += sum((freq for size, freq in size_freq_ti.iteritems()
94 b = sum((size*freq for size, freq in size_freq.iteritems()
96 b += sum((size*freq for size, freq in size_freq_ti.iteritems()
101 p('%s\t%s\t%s', bin, num(nn), bytes(bb))
104 n = sum((freq for size, freq in size_freq.iteritems() if size > 4096))
105 n += sum((freq for size, freq in size_freq_ti.iteritems() if size > 4096))
106 b = sum((size*freq for size, freq in size_freq.iteritems() if size > 4096))
107 b += sum((size*freq for size, freq in size_freq_ti.iteritems() if size > 4096))
109 p('>4096\t%s\t%s', num(n), bytes(b))
112 def wasted_bin(start, end, extra=0):
114 for i in range(start, end+1):
115 w += (end - i) * size_freq.get(i, 0)
116 if i <= (end - extra):
117 w += (end - i) * size_freq_ti.get(i, 0)
119 w += (2*end - i) * size_freq_ti.get(i, 0)
122 def wasted_pageplus(extra=0):
124 for size, freq in size_freq.iteritems():
126 w += (size % 4096) * freq
127 for size, freq in size_freq_ti.iteritems():
130 w += (size % 4096 + extra) * freq
133 def print_wasted(mode, extra=0):
135 wasted[bins[0]] = wasted_bin(1, bins[0], extra)
137 wasted[bin] = wasted_bin(bin/2 + 1, bin, extra)
138 wasted_pplus = wasted_pageplus()
139 wasted_total = sum((w for w in wasted.values())) + wasted_pplus
140 alloc_total = total_b + wasted_total
141 p('Real allocated bytes for mode %s', mode)
143 p('Requested\tWasted\tTotal')
144 p('%s\t%s\t%s', bytes(total_b), bytes(wasted_total), bytes(alloc_total))
146 p('%s\t%s', bins[0], bytes(wasted[bins[0]]))
148 p('%s\t%s', bin, bytes(wasted[bin]))
149 p('>4096\t%s', bytes(wasted_pplus))
152 print_wasted('Conservative')
153 print_wasted('Precise', 4)
155 #print size_freq, size_freq_ti