fixes bug where priorities where lost when force-rechecking.
[libtorrent.git] / parse_memory_log.py
blob2528bee768d652264d44b360289b8aa7f9a258db
1 import os, sys, time
3 # usage: memory.log memory_index.log
5 lines = open(sys.argv[1], 'rb').readlines()
6 index = open(sys.argv[2], 'rb').readlines()
8 # logfile format:
9 # #<allocation-point> <time(ms)> <key ('A' | 'F')> <address> <size> <total-size> <total-space-time> <peak-total-size>
10 # example:
11 # #12 38 A 0xd902a0 16 16 0 16
13 allocation_points_to_print = 30
15 def print_allocation_point(ap):
16 print 'space_time: %d kBms' % (ap['spacetime'] / 1024)
17 print 'allocations: %d' % ap['allocations']
18 print 'peak: %d kB' % (ap['peak'] / 1024)
19 print 'stack: '
20 counter = 0
21 for e in ap['stack']:
22 print '#%d %s' % (counter, e)
23 counter += 1
25 allocation_points = []
26 for l in index:
27 l = l.split('#')
28 l.pop(0)
29 ap = { 'allocations': 0, 'peak': 0, 'spacetime': 0, 'allocation_point': len(allocation_points), 'stack': l}
30 allocation_points.append(ap);
32 for l in lines:
33 l = l.lstrip('#').rstrip('\n').split(' ')
34 if len(l) != 8:
35 print l
36 continue
37 try:
38 ap = int(l[0])
39 allocation_points[ap]['allocations'] += 1
40 allocation_points[ap]['peak'] = int(l[7])
41 allocation_points[ap]['spacetime'] = int(l[6])
42 except Exception, e:
43 print type(e), e, l
45 print '=== space time ==='
47 hot_ap = []
48 allocation_points.sort(key = lambda x:x['spacetime'], reverse=True);
49 counter = 0
50 for ap in allocation_points[0:allocation_points_to_print]:
51 print '== %d ==' % counter
52 counter += 1
53 print_allocation_point(ap)
54 hot_ap.append(ap['allocation_point']);
56 print '=== allocations ==='
58 allocation_points.sort(key = lambda x:x['allocations'], reverse=True);
59 for ap in allocation_points[0:allocation_points_to_print]:
60 print_allocation_point(ap)
62 print '=== peak ==='
64 allocation_points.sort(key = lambda x:x['peak'], reverse=True);
65 for ap in allocation_points[0:allocation_points_to_print]:
66 print_allocation_point(ap)
68 # generate graph
69 lines = open(sys.argv[1], 'rb').readlines()
71 out = open('memory.dat', 'wb')
72 cur_line = [0] * allocation_points_to_print
73 prev_line = [0] * allocation_points_to_print
74 last_time = 0
76 for l in lines:
77 l = l.lstrip('#').rstrip('\n').split(' ')
78 if len(l) != 8:
79 print l
80 continue
81 try:
82 time = int(l[1])
83 if time != last_time:
84 print >>out, last_time, '\t',
85 for i in range(allocation_points_to_print):
86 if cur_line[i] == -1:
87 print >>out, prev_line[i], '\t',
88 else:
89 print >>out, cur_line[i], '\t',
90 prev_line[i] = cur_line[i]
91 print >>out
92 cur_line = [-1] * allocation_points_to_print
93 last_time = time
95 size = int(l[5])
96 ap = int(l[0])
97 if ap in hot_ap:
98 index = hot_ap.index(ap)
99 cur_line[index] = max(cur_line[index], size)
101 except Exception, e:
102 print type(e), e, l
104 out.close()
106 out = open('memory.gnuplot', 'wb')
107 print >>out, "set term png size 1200,700"
108 print >>out, 'set output "memory.png"'
109 print >>out, 'set xrange [0:*]'
110 print >>out, 'set xlabel "time (ms)"'
111 print >>out, 'set ylabel "bytes (B)"'
112 print >>out, "set style data lines"
113 print >>out, "set key box"
114 print >>out, 'plot',
115 for k in range(allocation_points_to_print):
116 print >>out, ' "memory.dat" using 1:(',
117 for i in range(k, allocation_points_to_print):
118 if i == k: print >>out, '$%d' % (i + 2),
119 else: print >>out, '+$%d' % (i + 2),
120 print >>out, ') title "%d" with filledcurves x1, \\' % k
121 print >>out, 'x=0'
122 out.close()
124 os.system('gnuplot memory.gnuplot');