Created
August 10, 2014 13:03
-
-
Save rampage644/178f1ab3fbcc917b0970 to your computer and use it in GitHub Desktop.
Python strace log analysis script
This file contains 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
#!/usr/bin/env python | |
import sys | |
import re | |
def main(): | |
regexp = re.compile(r'^(\S+)\((.*)\)\s+=\s+(\d+)$') | |
whitelist = ['read', 'write', 'fstat', 'lseek', 'fcntl'] | |
opened_fd = {} | |
output = {} | |
with open(sys.argv[1]) as f: | |
for line in f: | |
try: | |
(func, args, res) = regexp.findall(line)[0] | |
except IndexError: | |
continue | |
arg0 = args.split(',')[0] | |
# check for open/close | |
if func == 'open': | |
opened_fd[int(res)] = arg0 | |
output[int(res)] = [] | |
if func in whitelist: | |
try: | |
output[int(arg0)].append(func) | |
except KeyError as e: | |
print("Error with {}({}), skipping".format(func, arg0)) | |
if func == 'close': | |
print(opened_fd[int(arg0)], end=': ') | |
print(", ".join(set(output[int(arg0)]))) | |
del opened_fd[int(arg0)] | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment