Update op-summarizer to match branch counts properly
This commit is contained in:
parent
6ed38077c6
commit
cdf6b850f9
@ -8,7 +8,7 @@ from typing import Dict, List
|
|||||||
class GCovLine:
|
class GCovLine:
|
||||||
line_number: int
|
line_number: int
|
||||||
count: int
|
count: int
|
||||||
is_fallthrough: bool = False
|
branch_number: int = 0
|
||||||
|
|
||||||
|
|
||||||
class GCovFile:
|
class GCovFile:
|
||||||
@ -28,8 +28,11 @@ class GCovFile:
|
|||||||
|
|
||||||
for line in file["lines"]:
|
for line in file["lines"]:
|
||||||
if len(line["branches"]):
|
if len(line["branches"]):
|
||||||
|
# GCov reports branches in reverse order to our parser.
|
||||||
|
branch_number = len(line["branches"])
|
||||||
for branch in line["branches"]:
|
for branch in line["branches"]:
|
||||||
lines.append(GCovLine(line["line_number"], branch["count"], branch["fallthrough"]))
|
lines.append(GCovLine(line["line_number"], branch["count"], branch_number))
|
||||||
|
branch_number -= 1
|
||||||
else:
|
else:
|
||||||
lines.append(GCovLine(line["line_number"], line["count"]))
|
lines.append(GCovLine(line["line_number"], line["count"]))
|
||||||
|
|
||||||
|
|||||||
@ -1,25 +1,8 @@
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Dict, List, Optional
|
from typing import Dict, List
|
||||||
|
|
||||||
from gcovreader import GCovFile, GCovLine
|
from gcovreader import GCovFile, GCovLine
|
||||||
from opfinderreader import OperationLogReader, OperationLog
|
from opfinderreader import OperationLogReader, UniqueOperation
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
|
||||||
class UniqueOperation:
|
|
||||||
name: str
|
|
||||||
type_lhs: Optional[str]
|
|
||||||
type_rhs: Optional[str]
|
|
||||||
type_expr: Optional[str]
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def from_operation_log(op_log: OperationLog) -> "UniqueOperation":
|
|
||||||
return UniqueOperation(
|
|
||||||
op_log.operation,
|
|
||||||
op_log.operand_lhs,
|
|
||||||
op_log.operand_rhs,
|
|
||||||
op_log.operand_result
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
@ -36,17 +19,15 @@ if __name__ == "__main__":
|
|||||||
print(f"Couldn't find {file_name} in op-finder output. Skipping.")
|
print(f"Couldn't find {file_name} in op-finder output. Skipping.")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
loop_stack: List[int] = []
|
|
||||||
|
|
||||||
for gcov_line in gcov.files[file_name]:
|
for gcov_line in gcov.files[file_name]:
|
||||||
op_lines = ops.get_lines(file_name, gcov_line.line_number)
|
op_lines = ops.get_lines(file_name, gcov_line.line_number)
|
||||||
for opfinder_line in op_lines:
|
for op_log in op_lines:
|
||||||
# TODO: revise this. Need a special case for for-loop clauses
|
# TODO: revise this. Need a special case for for-loop clauses
|
||||||
# or branching in general.
|
# or branching in general.
|
||||||
if opfinder_line.is_fallthrough != gcov_line.is_fallthrough:
|
if op_log.branch_number != gcov_line.branch_number:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
unique_op = UniqueOperation.from_operation_log(opfinder_line)
|
unique_op = op_log.entry
|
||||||
|
|
||||||
if unique_op in op_counter:
|
if unique_op in op_counter:
|
||||||
op_counter[unique_op] += gcov_line.count
|
op_counter[unique_op] += gcov_line.count
|
||||||
|
|||||||
@ -1,18 +1,48 @@
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from dataclasses import dataclass, field
|
from enum import Enum
|
||||||
from typing import Dict, List
|
from dataclasses import dataclass
|
||||||
|
from typing import Any, Dict, List, Union
|
||||||
|
|
||||||
|
|
||||||
|
class OperationType(Enum):
|
||||||
|
BASIC = "basic_operation"
|
||||||
|
FUNCTION_CALL = "function_call"
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True)
|
||||||
|
class BasicOperation:
|
||||||
|
operation_name: str
|
||||||
|
type_lhs: str
|
||||||
|
type_rhs: str
|
||||||
|
type_result: str
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True)
|
||||||
|
class FunctionCall:
|
||||||
|
function_name: str
|
||||||
|
call_result_type: str
|
||||||
|
|
||||||
|
|
||||||
|
UniqueOperation = Union[BasicOperation, FunctionCall]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class OperationLog:
|
class OperationLog:
|
||||||
operation: str
|
|
||||||
line: int
|
line: int
|
||||||
operand_lhs: str
|
branch_number: int
|
||||||
operand_rhs: str
|
entry_type: OperationType
|
||||||
operand_result: str
|
entry: UniqueOperation
|
||||||
is_fallthrough: bool
|
|
||||||
current_for_loops: list[int] = field(default_factory=list)
|
def __post_init__(self) -> None:
|
||||||
|
self.entry_type = OperationType(self.entry_type)
|
||||||
|
|
||||||
|
if self.entry_type == OperationType.BASIC:
|
||||||
|
self.entry = BasicOperation(**self.entry)
|
||||||
|
elif self.entry_type == OperationType.FUNCTION_CALL:
|
||||||
|
self.entry = FunctionCall(**self.entry)
|
||||||
|
else:
|
||||||
|
assert False, "Unaccounted for operation type."
|
||||||
|
|
||||||
|
|
||||||
class OperationLogReader:
|
class OperationLogReader:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user