Skip to content
Snippets Groups Projects
Commit 78950796 authored by Pawel Dziepak's avatar Pawel Dziepak Committed by Pekka Enberg
Browse files

post-processing/memory: make the script work with python3

parent 7d122f7d
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,7 @@ import re
print("-=[ Mem0ry Allocations Analyz3r ]=-")
trace_records = file("trace.txt", "rt").readlines()
trace_records = open("trace.txt", "rt").readlines()
def is_malloc(x):
return x.find("malloc ") > 0
......@@ -46,9 +46,9 @@ def process_records():
if (is_malloc(l)):
buf = get_buf(l)
t = [get_len(l), False]
if (mallocs.has_key(buf)):
if buf in mallocs:
if (mallocs[buf][-1][1] == False):
print "Buffer %s was already allocated." % buf
print("Buffer %s was already allocated." % buf)
mallocs[buf] += [t]
else:
mallocs[buf] = [t]
......@@ -56,13 +56,13 @@ def process_records():
elif (is_free(l)):
buf = get_buf(l)
# check if buffer had been allocated
if (not mallocs.has_key(buf)):
if not buf in mallocs:
# print "Buffer %s never been allocated." % buf
pass
else:
# check if buffer already freed
if (mallocs[buf][-1][1] == True):
print "Buffer %s buf already been freed." % buf
print("Buffer %s buf already been freed." % buf)
else:
mallocs[buf][-1][1] = True
......@@ -73,9 +73,9 @@ def process_records():
elif (is_page_alloc(l)):
page = get_page(l)
t = [4096, False]
if (page_allocs.has_key(page)):
if page in page_allocs:
if (page_allocs[page][-1][1] == False):
print "Page %s was already allocated." % page
print("Page %s was already allocated." % page)
page_allocs[page] += [t]
else:
page_allocs[page] = [t]
......@@ -83,18 +83,18 @@ def process_records():
elif (is_page_free(l)):
page = get_page(l)
# check if page had been allocated
if (not page_allocs.has_key(page)):
if not page in page_allocs:
# print "Page %s never been allocated." % page
pass
else:
# check if page already freed
if (page_allocs[page][-1][1] == True):
print "Page %s buf already been freed." % page
print("Page %s buf already been freed." % page)
else:
page_allocs[page][-1][1] = True
except:
print "Problem parsing line: '%s'" % l
print("Problem parsing line: '%s'" % l)
raise
......@@ -105,28 +105,28 @@ def process_counts():
sizes = {}
total = 0
print "Calculating size histograms..."
print("Calculating size histograms...")
for buf in mallocs:
for desc in mallocs[buf]:
size = desc[0]
freed = desc[1]
if (not sizes.has_key(size)):
if (not size in sizes):
sizes[size] = {'allocs':0, 'frees':0}
sizes[size]['allocs'] += 1
if (freed):
sizes[size]['frees'] += 1
sizes = sorted(sizes.iteritems(), key=lambda k: (k[1]['allocs']-k[1]['frees']) * int(k[0]))
sizes = sorted(sizes.items(), key=lambda k: (k[1]['allocs']-k[1]['frees']) * int(k[0]))
# print buffers
for sz in sizes:
unfreed = (sz[1]['allocs'] - sz[1]['frees']) * int(sz[0])
print sz[0], sz[1], "Unallocated: %d bytes" % unfreed
print(sz[0], sz[1], "Unallocated: %d bytes" % unfreed)
total += unfreed
print "Total unfreed: %d bytes" % total
print("Total unfreed: %d bytes" % total)
if __name__ == "__main__":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment