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