利用python提取vc output中的内存泄漏统计信息

import re

logfile = open("memoryleak.log","r")
allln = logfile.readlines()
sumary = {"filename":[0,0]}
for singleln in allln:
    #reobj = re.compile(r".*\.cpp(\(d+\)): \{d+\}\s*normal block at .*(d+)\s bytes long\.")
    reobj = re.compile(r"(.*\.cpp\((\d+)\))\s:\s\{\d+\}\s*normal block at 0x.*,\s(\d+)\sbytes long\.")
    matchobj = reobj.match(singleln)
    if matchobj:
        if matchobj.group(1) in sumary:
            sumary[matchobj.group(1)][0] += 1
            sumary[matchobj.group(1)][1] += int(matchobj.group(3))
        else:
            sumary[matchobj.group(1)] = [0,int(matchobj.group(3))]
        print(sumary , '\n ')

你可能感兴趣的:(python,内存泄漏)