3 # usage: memory.log memory_index.log
5 lines
= open(sys
.argv
[1], 'rb').readlines()
6 index
= open(sys
.argv
[2], 'rb').readlines()
9 # #<allocation-point> <time(ms)> <key ('A' | 'F')> <address> <size> <total-size> <total-space-time> <peak-total-size>
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)
22 print '#%d %s' % (counter
, e
)
25 allocation_points
= []
29 ap
= { 'allocations': 0, 'peak': 0, 'spacetime': 0, 'allocation_point': len(allocation_points
), 'stack': l
}
30 allocation_points
.append(ap
);
33 l
= l
.lstrip('#').rstrip('\n').split(' ')
39 allocation_points
[ap
]['allocations'] += 1
40 allocation_points
[ap
]['peak'] = int(l
[7])
41 allocation_points
[ap
]['spacetime'] = int(l
[6])
45 print '=== space time ==='
48 allocation_points
.sort(key
= lambda x
:x
['spacetime'], reverse
=True);
50 for ap
in allocation_points
[0:allocation_points_to_print
]:
51 print '== %d ==' % counter
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
)
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
)
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
77 l
= l
.lstrip('#').rstrip('\n').split(' ')
84 print >>out
, last_time
, '\t',
85 for i
in range(allocation_points_to_print
):
87 print >>out
, prev_line
[i
], '\t',
89 print >>out
, cur_line
[i
], '\t',
90 prev_line
[i
] = cur_line
[i
]
92 cur_line
= [-1] * allocation_points_to_print
98 index
= hot_ap
.index(ap
)
99 cur_line
[index
] = max(cur_line
[index
], size
)
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"
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
124 os
.system('gnuplot memory.gnuplot');