Skip to content

Commit

Permalink
Add blame server experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonievonMann committed Nov 29, 2024
1 parent fc7a59f commit 3dba6c1
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
99 changes: 99 additions & 0 deletions varats/varats/experiments/vara/blame_server_experiment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
"""
Implements blame experiment using a blame cache server.
The experiment starts the blame server, compiles with blame annotations and
kills the server at the end.
"""
import socket
import typing as tp

from benchbuild import Project
from benchbuild.utils import actions
from plumbum import local
from plumbum.cmd import kill

import varats.experiments.vara.blame_experiment as BE
from varats.data.reports.blame_annotations import BlameAnnotations as BA
from varats.experiment.experiment_util import (
VersionExperiment,
create_default_compiler_error_handler,
)
from varats.experiment.wllvm import BCFileExtensions, Extract
from varats.experiments.vara.blame_ast_experiment import (
BlameAnnotationGeneration,
)
from varats.report.report import ReportSpecification


class BlameServerSteps(actions.Compile): # type: ignore

Check failure on line 28 in varats/varats/experiments/vara/blame_server_experiment.py

View workflow job for this annotation

GitHub Actions / pylint

[pylint] varats/varats/experiments/vara/blame_server_experiment.py#L28 <115>

Missing class docstring (missing-class-docstring)
Raw output
varats/varats/experiments/vara/blame_server_experiment.py:28:0: C0115: Missing class docstring (missing-class-docstring)
NAME = "BlameServerSteps"
DESCRIPTION = "Start server before and kill server after compilation."

def __init__(self, project: Project, port: int):
super().__init__(project)
self.__port = port

def __call__(self) -> actions.StepResult:
server_cmd = local["vara-blamed"][
f"--blame-server=0.0.0.0:{self.__port}"]
server_proc = server_cmd.popen()
try:
steps = super().__call__()
finally:
kill[str(server_proc.pid)]()
return steps

Check warning on line 44 in varats/varats/experiments/vara/blame_server_experiment.py

View workflow job for this annotation

GitHub Actions / pylint

[pylint] varats/varats/experiments/vara/blame_server_experiment.py#L44 <134>

'return' shadowed by the 'finally' clause. (return-in-finally)
Raw output
varats/varats/experiments/vara/blame_server_experiment.py:44:12: W0134: 'return' shadowed by the 'finally' clause. (return-in-finally)

Check warning on line 44 in varats/varats/experiments/vara/blame_server_experiment.py

View workflow job for this annotation

GitHub Actions / pylint

[pylint] varats/varats/experiments/vara/blame_server_experiment.py#L44 <150>

return statement in finally block may swallow exception (lost-exception)
Raw output
varats/varats/experiments/vara/blame_server_experiment.py:44:12: W0150: return statement in finally block may swallow exception (lost-exception)

Check failure on line 44 in varats/varats/experiments/vara/blame_server_experiment.py

View workflow job for this annotation

GitHub Actions / pylint

[pylint] varats/varats/experiments/vara/blame_server_experiment.py#L44 <601>

Using variable 'steps' before assignment (used-before-assignment)
Raw output
varats/varats/experiments/vara/blame_server_experiment.py:44:19: E0601: Using variable 'steps' before assignment (used-before-assignment)

@staticmethod
def find_open_port():

Check failure on line 47 in varats/varats/experiments/vara/blame_server_experiment.py

View workflow job for this annotation

GitHub Actions / mypy

[mypy] varats/varats/experiments/vara/blame_server_experiment.py#L47

error: Function is missing a return type annotation [no-untyped-def]
Raw output
varats/varats/experiments/vara/blame_server_experiment.py:47:5: error: Function is missing a return type annotation  [no-untyped-def]
"""Finds and returns an available port on the local machine."""
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind(('', 0)) # Bind to a free port provided by the OS
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
return s.getsockname()[1]


class BlameServerExperiment(VersionExperiment, shorthand="BSE"):
"""Generate a blame annotation report using blame server."""

NAME = "RunBlameServer"

REPORT_SPEC = ReportSpecification(BA)

def actions_for_project(
self, project: Project
) -> tp.MutableSequence[actions.Step]:
"""
Returns the specified steps to run the project(s) specified in the call
in a fixed order.
Args:
project: to analyze
"""
project.cflags += ["-O1", "-Xclang", "-disable-llvm-optzns", "-g"]
bc_file_extensions = [
BCFileExtensions.NO_OPT,
BCFileExtensions.TBAA,
BCFileExtensions.BLAME #TODO: add extension for blame server ?

Check warning on line 76 in varats/varats/experiments/vara/blame_server_experiment.py

View workflow job for this annotation

GitHub Actions / pylint

[pylint] varats/varats/experiments/vara/blame_server_experiment.py#L76 <511>

TODO: add extension for blame server ? (fixme)
Raw output
varats/varats/experiments/vara/blame_server_experiment.py:76:37: W0511: TODO: add extension for blame server ? (fixme)
]

BE.setup_basic_blame_experiment(self, project, BA)
open_port = BlameServerSteps.find_open_port()

Check failure on line 80 in varats/varats/experiments/vara/blame_server_experiment.py

View workflow job for this annotation

GitHub Actions / mypy

[mypy] varats/varats/experiments/vara/blame_server_experiment.py#L80

error: Call to untyped function "find_open_port" of "BlameServerSteps" in typed context [no-untyped-call]
Raw output
varats/varats/experiments/vara/blame_server_experiment.py:80:21: error: Call to untyped function "find_open_port" of "BlameServerSteps" in typed context  [no-untyped-call]
project.cflags += [f"-fvara-blame-server=0.0.0.0:{open_port}"]
analysis_actions = []
analysis_actions.append(BlameServerSteps(project, open_port))
analysis_actions.append(
Extract(
project,
bc_file_extensions,
handler=create_default_compiler_error_handler(
self.get_handle(), project, self.REPORT_SPEC.main_report
)
)
)
analysis_actions.append(
BlameAnnotationGeneration(
project, self.get_handle(), bc_file_extensions
)
)

return analysis_actions
1 change: 1 addition & 0 deletions varats/varats/tools/bb_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def update_experiments(bb_cfg: s.Configuration) -> None:
'varats.experiments.vara.agg_region_interaction_perf_runner',
'varats.experiments.vara.blame_ast_experiment',
'varats.experiments.vara.blame_report_experiment',
'varats.experiments.vara.blame_server_experiment',
'varats.experiments.vara.blame_verifier_experiment',
'varats.experiments.vara.commit_report_experiment',
'varats.experiments.vara.feature_perf_runner',
Expand Down

0 comments on commit 3dba6c1

Please sign in to comment.