| 116 | |
| 117 | |
| 118 | def collect_stats(files, fd, pattern): |
| 119 | # TODO: Handle compressed callgrind files |
| 120 | line_regexs = [ |
| 121 | re.compile(r"(?P<lineno>[0-9]+)(\s[0-9]+)+"), |
| 122 | re.compile(r"((jump)|(jcnd))=([0-9]+)\s(?P<lineno>[0-9]+)") |
| 123 | ] |
| 124 | |
| 125 | current_file = None |
| 126 | current_function = None |
| 127 | for i, line in enumerate(fd): |
| 128 | if re.match("f[lie]=.+", line): |
| 129 | path = line.split('=', 2)[1].strip() |
| 130 | if os.path.exists(path) and re.search(pattern, path): |
| 131 | current_file = files.get_file(path) |
| 132 | else: |
| 133 | current_file = None |
| 134 | elif re.match("fn=.+", line): |
| 135 | current_function = line.split('=', 2)[1].strip() |
| 136 | elif current_file is not None: |
| 137 | for regex in line_regexs: |
| 138 | match = regex.match(line) |
| 139 | if match: |
| 140 | lineno = int(match.group('lineno')) |
| 141 | current_file.mark_line(lineno, current_function) |
| 142 | |
| 143 | |
| 144 | if __name__ == '__main__': |