masters-thesis/op-summarizer/op-summarizer.py

40 lines
1.3 KiB
Python

from dataclasses import dataclass
from typing import Dict, List
from gcovreader import GCovFile, GCovLine
from opfinderreader import OperationLogReader, UniqueOperation
if __name__ == "__main__":
gcov = GCovFile("./data/gcov.json")
ops = OperationLogReader("./data/opfinder.json")
gcov.read()
ops.read()
for file_name in gcov.files:
op_counter: Dict[UniqueOperation, int] = {}
if file_name not in ops.files:
print(f"Couldn't find {file_name} in op-finder output. Skipping.")
continue
for gcov_line in gcov.files[file_name]:
op_lines = ops.get_lines(file_name, gcov_line.line_number)
for op_log in op_lines:
# TODO: revise this. Need a special case for for-loop clauses
# or branching in general.
if op_log.branch_number != gcov_line.branch_number:
continue
unique_op = op_log.entry
if unique_op in op_counter:
op_counter[unique_op] += gcov_line.count
else:
op_counter[unique_op] = gcov_line.count
print(f"Unique operations for file {file_name}:")
for uop, count in op_counter.items():
print(f"\t{count}: {uop}")