Skip to content

Commit

Permalink
track number of changes in patch stage (resolve #138)
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippvK committed Oct 30, 2024
1 parent f0d4830 commit d1e29b4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
13 changes: 13 additions & 0 deletions seal5/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@ def patch(self, verbose: bool = False, stages: List[PatchStage] = None, force: b
stages = list(map(PatchStage, range(PatchStage.PHASE_5 + 1)))
assert len(stages) > 0
patches_per_stage = self.collect_patches()
stages_metrics = {}
for stage in stages:
logger.info("Current stage: %s", stage)
patches = patches_per_stage.get(stage, [])
Expand All @@ -779,11 +780,23 @@ def patch(self, verbose: bool = False, stages: List[PatchStage] = None, force: b
# author = git_.get_author(self.settings.git)
# self.repo.create_tag(tag_name, message=tag_msg, force=True, author=author)
self.repo.create_tag(tag_name, message=tag_msg, force=True)
base_tag = f"seal5-{self.name}-base"
if int(stage) > 0:
prev_tag = f"seal5-{self.name}-stage{int(stage)-1}"
else:
prev_tag = base_tag
n_files_changed, n_insertions, n_deletions = inject_patches.analyze_diff(self.repo, cur=tag_name, base=prev_tag)
stage_metrics = {}
stage_metrics["n_files_changed"] = n_files_changed
stage_metrics["n_insertions"] = n_insertions
stage_metrics["n_deletions"] = n_deletions
stages_metrics[PatchStage(stage).name] = stage_metrics
end = time.time()
diff = end - start
metrics["start"] = start
metrics["end"] = end
metrics["time_s"] = diff
metrics["stages"] = stages_metrics
self.settings.metrics.append({"patch": metrics})
self.settings.save()
logger.info("Completed application of Seal5 patches")
Expand Down
31 changes: 31 additions & 0 deletions seal5/tools/inject_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
import os
import argparse
from pathlib import Path
from typing import Optional

from email.utils import formatdate
import yaml

from seal5 import utils
from seal5.logging import get_logger

logger = get_logger()
Expand Down Expand Up @@ -230,6 +232,35 @@ def process_arguments():
return args


def analyze_diff(repo, base: str, cur: Optional[str] = None):
args = ["git", "diff", "--shortstat"]
args += [base]
if cur is not None:
args += [cur]
out = utils.exec_getout(
*args,
cwd=repo.working_tree_dir,
print_func=lambda *args, **kwargs: None,
live=False,
)
n_files_changed = 0
n_insertions = 0
n_deletions = 0
for x in out.split(","):
x = x.strip()
if len(x) == 0:
continue
val, key = x.split(" ", 1)
val = int(val)
if "files changed" in key:
n_files_changed = val
elif "insertions" in key:
n_insertions = val
elif "deletions" in key:
n_deletions = val
return n_files_changed, n_insertions, n_deletions


def main():
"""Main entry point."""
args = process_arguments()
Expand Down

0 comments on commit d1e29b4

Please sign in to comment.