Last active
August 29, 2015 14:15
-
-
Save ryansturmer/83e0ee670a776cbe4cb1 to your computer and use it in GitHub Desktop.
Analyzer for output of mb.gdb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import sys | |
STATES = { | |
0 : 'EMPTY', | |
1 : 'PLANNING', | |
2 : 'QUEUED', | |
3 : 'PENDING', | |
4 : 'RUNNING' | |
} | |
def load_pool(filename): | |
current_buffer = 0 | |
with open(filename) as mb: | |
lines = mb.readlines() | |
pool = {} | |
for line in lines: | |
buf = re.search('\(mpBuffer\s\*\)\s(0x[0-9a-fA-F]+)', line) | |
if buf: | |
current_buffer = int(buf.groups()[0], 16) | |
pool[current_buffer] = {} | |
else: | |
match = re.search('([a-zA-Z_]+)\s=\s((?:0x[0-9a-fA-F]+)|(?:[0-9]+))', line) | |
if match: | |
key, val = match.groups() | |
if key == 'pv': | |
pv = int(val, 16) | |
pool[current_buffer]['pv'] = pv | |
elif key == 'nx': | |
nv = int(val, 16) | |
pool[current_buffer]['nx'] = nv | |
elif key == 'buffer_state': | |
pool[current_buffer]['buffer_state'] = STATES[int(val)] | |
return pool | |
def check_integrity(pool): | |
key = pool.keys()[0] | |
buffers = set() | |
count = 0; | |
while True: | |
if key in buffers: | |
break | |
buffers.add(key) | |
key = pool[key]['nx'] | |
count += 1 | |
if count != 28: | |
raise "Buffer pool integrity is bad." | |
def check_pool(filename): | |
pool = load_pool(filename) | |
check_integrity(pool) | |
return pool | |
if __name__ == "__main__": | |
pool = check_pool(sys.argv[1]) | |
for key in sorted(pool.keys()): | |
print '%s:%s' % (key, pool[key]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment