Skip to content

Commit

Permalink
Fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonievonMann committed Feb 3, 2024
1 parent 756ee48 commit 272e394
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 35 deletions.
52 changes: 22 additions & 30 deletions varats/varats/data/reports/blame_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ def create_blame_instruction(
section."""
dbghash = str(raw_entry['dbghash'])
varahash = str(raw_entry['varahash'])
return BlameInstruction(dbghash, varahash) #TODO name

@property
def name(self) -> str:
"""Name of the instruction."""
return self.__name
return BlameInstruction(dbghash, varahash)

@property
def dbghash(self) -> str:
Expand Down Expand Up @@ -80,6 +75,7 @@ def __init__(self, path: Path) -> None:
self.__eq_line_ast = 0

def print_yaml(self) -> None:
"""Writes the result of the comparison to a yaml file."""
data = {
'dbg vs ast': {
'diff': self.__diff_dbg_ast,
Expand All @@ -93,60 +89,56 @@ def print_yaml(self) -> None:
with open(self.path, 'w') as yaml_file:
yaml.dump(data, yaml_file, default_flow_style=False)

def update_dbg_ast(self, diff: bool) -> None:
"""Updates the metrics of the comparison between debug and AST based
information."""
if diff:
self.__diff_dbg_ast += 1
else:
self.__eq_dbg_ast += 1

def update_line_ast(self, diff: bool) -> None:
"""Updates the metrics of the comparison between line based and AST
based information."""
if diff:
self.__diff_line_ast += 1
else:
self.__eq_line_ast += 1

@property
def diff_dbg_ast(self) -> int:
"""Count of different instructions between debug and ast blame."""
return self.__diff_dbg_ast

@diff_dbg_ast.setter
def diff_dbg_ast(self, value) -> None:
self.__diff_dbg_ast = value

@property
def eq_dbg_ast(self) -> int:
"""Count of equal instructions between debug and ast blame."""
return self.__eq_dbg_ast

@eq_dbg_ast.setter
def eq_dbg_ast(self, value) -> None:
self.__eq_dbg_ast = value

@property
def diff_line_ast(self) -> int:
"""Count of different instructions between line and ast blame."""
return self.__diff_line_ast

@diff_line_ast.setter
def diff_line_ast(self, value) -> None:
self.__diff_line_ast = value

@property
def eq_line_ast(self) -> int:
"""Count of equal instructions between line and ast blame."""
return self.__eq_line_ast

@eq_line_ast.setter
def eq_line_ast(self, value) -> None:
self.__eq_line_ast = value


def compare_blame_annotations(
line_ba: BlameAnnotations, ast_ba: BlameAnnotations, path: Path
) -> ASTBlameReport:
"""Compares the debug based to the AST based annotations as well as the line
based to the AST based blame."""
ast_report = ASTBlameReport(path)

for entry in ast_ba.blame_annotations:
if entry.dbghash == entry.varahash:
ast_report.eq_dbg_ast += 1
else:
ast_report.diff_dbg_ast += 1
ast_report.update_dbg_ast(entry.dbghash != entry.varahash)

for line_entry, ast_entry in zip(
line_ba.blame_annotations, ast_ba.blame_annotations
):
if line_entry.varahash == ast_entry.varahash:
ast_report.eq_line_ast += 1
else:
ast_report.diff_line_ast += 1
ast_report.update_line_ast(line_entry.varahash != ast_entry.varahash)

return ast_report
14 changes: 9 additions & 5 deletions varats/varats/experiments/vara/blame_ast_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import fnmatch
import os
import typing as tp
from pathlib import Path

from benchbuild import Project
from benchbuild.utils import actions
Expand All @@ -16,7 +17,6 @@
from varats.data.reports.blame_annotations import ASTBlameReport as BAST
from varats.data.reports.blame_annotations import BlameAnnotations as BA
from varats.data.reports.blame_annotations import compare_blame_annotations
from varats.data.reports.blame_report import BlameReport as BR
from varats.experiment.experiment_util import (
ExperimentHandle,
VersionExperiment,
Expand Down Expand Up @@ -47,7 +47,8 @@ class BlameAnnotationGeneration(actions.ProjectStep): #type: ignore
"""Generate blame annotation report."""

NAME = "BlameAnnotationGeneration"
DESCRIPTION = "Generates report with debug and IInfo blame with -vara-BA of VaRA."
DESCRIPTION = "Generates report with debug and IInfo blame "\
"with -vara-BA of VaRA."

project: VProject

Expand Down Expand Up @@ -129,7 +130,8 @@ class BlameASTComparison(actions.ProjectStep): #type: ignore
ones."""

NAME = "BlameASTComparison"
DESCRIPTION = "Compares BlameAnnotation reports of AST based annotations to line based ones."
DESCRIPTION = "Compares BlameAnnotation reports of AST based "\
"annotations to line based ones."

project: VProject

Expand All @@ -145,14 +147,16 @@ def __call__(self) -> actions.StepResult:
return self.analyze()

def analyze(self) -> actions.StepResult:
"""This step retrieves the two previously generated reports (with line
based and AST based blame annotations) and compares them."""
for binary in self.project.binaries:
varats_result_folder = get_varats_result_folder(self.project)

for file in os.listdir(varats_result_folder):
if fnmatch.fnmatch(file, "linereport" + '*'):
line_filepath = os.path.join(varats_result_folder, file)
line_filepath = Path(varats_result_folder / file)
if fnmatch.fnmatch(file, "astreport" + '*'):
ast_filepath = os.path.join(varats_result_folder, file)
ast_filepath = Path(varats_result_folder / file)

line_annotations = BA(line_filepath)
ast_annotations = BA(ast_filepath)
Expand Down

0 comments on commit 272e394

Please sign in to comment.