Skip to content

Commit

Permalink
Merge branch 'vara-dev' into f-ASTBlameComparison
Browse files Browse the repository at this point in the history
  • Loading branch information
boehmseb authored Apr 25, 2024
2 parents f5a69bb + 62cbd3a commit b65e658
Show file tree
Hide file tree
Showing 8 changed files with 359 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,31 @@ How to set up VaRA/LLVM in CLion
-DBUILD_SHARED_LIBS=ON
-DCMAKE_C_FLAGS_DEBUG="-O2 -g -fno-omit-frame-pointer"
-DCMAKE_CXX_FLAGS_DEBUG="-O2 -g -fno-omit-frame-pointer"
-DCMAKE_SHARED_LINKER_FLAGS="-Wl,--undefined-version"
-DCMAKE_CXX_STANDARD=17
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
-DCMAKE_INSTALL_PREFIX=<varats_root>/tools/VaRA
-DLLVM_ENABLE_ASSERTIONS=ON
-DLLVM_ENABLE_BINDINGS=OFF
-DLLVM_ENABLE_EH=ON
-DLLVM_ENABLE_LDD=ON
-DLLVM_ENABLE_LLD=ON
-DLLVM_ENABLE_PROJECTS="clang;lld;compiler-rt;clang-tools-extra;vara;phasar"
-DLLVM_ENABLE_RTTI=ON
-DLLVM_OPTIMIZED_TABLEGEN=ON
-DLLVM_PARALLEL_LINK_JOBS=4
-DLLVM_PHASAR_BUILD=ON
-DLLVM_TOOL_PHASAR_BUILD=ON
-DPHASAR_ENABLE_DYNAMIC_LOG=OFF
-DPHASAR_BUILD_IR=OFF
-DPHASAR_BUILD_UNITTESTS=OFF
-DLLVM_TARGETS_TO_BUILD=X86
-DLLVM_TOOL_PHASAR_BUILD=ON
-DLLVM_USE_NEWPM=ON
-DUSE_HTTPS=OFF
-DUSE_SSH=OFF
-DVARA_BUILD_LIBGIT=ON
-DVARA_FEATURE_BUILD_PYTHON_BINDINGS=OFF
-DVARA_FEATURE_BUILD_Z3_SOLVER=ON
-DVARA_FEATURE_USE_Z3_SOLVER=ON
Use ``-O0`` for debug builds and ``-O2`` for development builds.

Expand All @@ -57,22 +64,31 @@ How to set up VaRA/LLVM in CLion
-DBUILD_SHARED_LIBS=ON
-DCMAKE_C_FLAGS_RELEASE="-O3 -DNDEBUG -march=native -fno-omit-frame-pointer -gmlt"
-DCMAKE_CXX_FLAGS_RELEASE="-O3 -DNDEBUG -march=native -fno-omit-frame-pointer -gmlt"
-DCMAKE_SHARED_LINKER_FLAGS="-Wl,--undefined-version"
-DCMAKE_CXX_STANDARD=17
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
-DCMAKE_INSTALL_PREFIX=<varats_root>/tools/VaRA
-DLLVM_ENABLE_ASSERTIONS=OFF
-DLLVM_ENABLE_BINDINGS=OFF
-DLLVM_ENABLE_EH=ON
-DLLVM_ENABLE_LDD=ON
-DLLVM_ENABLE_LLD=ON
-DLLVM_ENABLE_PROJECTS="clang;lld;compiler-rt;clang-tools-extra;vara;phasar"
-DLLVM_ENABLE_RTTI=ON
-DLLVM_OPTIMIZED_TABLEGEN=ON
-DLLVM_PARALLEL_LINK_JOBS=4
-DLLVM_PHASAR_BUILD=ON
-DLLVM_TOOL_PHASAR_BUILD=ON
-DPHASAR_ENABLE_DYNAMIC_LOG=OFF
-DPHASAR_BUILD_IR=OFF
-DPHASAR_BUILD_UNITTESTS=OFF
-DLLVM_TARGETS_TO_BUILD=X86
-DLLVM_TOOL_PHASAR_BUILD=ON
-DLLVM_USE_NEWPM=ON
-DUSE_HTTPS=OFF
-DUSE_SSH=OFF
-DVARA_BUILD_LIBGIT=ON
-DVARA_FEATURE_BUILD_PYTHON_BINDINGS=OFF
-DVARA_FEATURE_BUILD_Z3_SOLVER=ON
-DVARA_FEATURE_USE_Z3_SOLVER=ON
- **Build directory:** ``<varats_root>/tools_src/vara-llvm-project/build/dev-clion``
- **Build options:** leave empty
Expand Down
48 changes: 48 additions & 0 deletions tests/utils/test_filesystem_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""Test the filesystem utils of VaRA-TS."""
import errno
import os
import unittest
import uuid
from fcntl import flock, LOCK_EX, LOCK_NB, LOCK_UN

from varats.utils.filesystem_util import lock_file


class TestFileLock(unittest.TestCase):
"""Tests whether the lock context manager works correctly."""

def test_file_locking(self):
"""Test that the file is locked when in a context manager."""
tmp_lock_file = "/tmp/lock-test.lock"

with lock_file(tmp_lock_file):
# File should automatically be created
self.assertTrue(os.path.exists(tmp_lock_file))

f = os.open(tmp_lock_file, os.O_RDONLY)

with self.assertRaises(OSError) as context:
# A non-blocking attempt to lock the file again should fail immediately
flock(f, LOCK_EX | LOCK_NB)
os.close(f)
self.assertEqual(context.exception.errno, errno.EWOULDBLOCK)

# Attempting to lock the file and immediately unlocking should now work
f = os.open(tmp_lock_file, os.O_RDONLY)
flock(f, LOCK_EX | LOCK_NB)
flock(f, LOCK_UN)
os.close(f)

def test_lock_file_new_folder(self):
"""Test that the lock context manager works correctly when the lock file
is in a new folder."""
tmp_lock_file = f"/tmp/{uuid.uuid4()}"

while os.path.isdir(tmp_lock_file):
tmp_lock_file = f"/tmp/{uuid.uuid4()}"

tmp_lock_file += "/lock-test.lock"

with lock_file(tmp_lock_file):
# File should automatically be created
self.assertTrue(os.path.exists(tmp_lock_file))
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from benchbuild.source.base import target_prefix

from varats.provider.provider import Provider
from varats.utils.filesystem_util import lock_file


class FeatureModelNotFound(FileNotFoundError):
Expand Down Expand Up @@ -90,6 +91,9 @@ def _get_feature_model_repository_path() -> Path:
refspec="origin/HEAD",
limit=1,
)
fm_source.fetch()

lock_path = Path(target_prefix()) / "fm_provider.lock"
with lock_file(lock_path):
fm_source.fetch()

return Path(Path(target_prefix()) / fm_source.local)
3 changes: 3 additions & 0 deletions varats-core/varats/utils/filesystem_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ def __init__(self, folder: tp.Union[Path, str]) -> None:
@contextmanager
def lock_file(lock_path: Path,
lock_mode: int = fcntl.LOCK_EX) -> tp.Generator[None, None, None]:
# Create directories until lock file if required
os.makedirs(os.path.dirname(lock_path), exist_ok=True)

open_mode = os.O_RDWR | os.O_CREAT | os.O_TRUNC
lock_fd = os.open(lock_path, open_mode)
try:
Expand Down
31 changes: 23 additions & 8 deletions varats/varats/experiments/vara/feature_perf_precision.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from plumbum import local, BG
from plumbum.commands.modifiers import Future

from varats.base.configuration import PatchConfiguration
from varats.data.reports.performance_influence_trace_report import (
PerfInfluenceTraceReportAggregate,
)
Expand Down Expand Up @@ -44,7 +45,7 @@
from varats.report.report import ReportSpecification
from varats.report.tef_report import TEFReportAggregate
from varats.tools.research_tools.vara import VaRA
from varats.utils.config import get_current_config_id
from varats.utils.config import get_current_config_id, get_config
from varats.utils.git_util import ShortCommitHash

REPS = 3
Expand Down Expand Up @@ -77,10 +78,24 @@ def perf_prec_workload_commands(
def select_project_binaries(project: VProject) -> tp.List[ProjectBinaryWrapper]:
"""Uniformly select the binaries that should be analyzed."""
if project.name == "DunePerfRegression":
return [
binary for binary in project.binaries
if binary.name == "poisson_yasp_q2_3d"
]
config = get_config(project, PatchConfiguration)
if not config:
return []

f_tags = {opt.value for opt in config.options()}

grid_binary_map = {
"YaspGrid": "poisson_yasp_q2_3d",
"UGGrid": "poisson_ug_pk_2d",
"ALUGrid": "poisson_alugrid"
}

for grid, binary_name in grid_binary_map.items():
if grid in f_tags:
return [
binary for binary in project.binaries
if binary.name == binary_name
]

return [project.binaries[0]]

Expand All @@ -101,12 +116,12 @@ def get_threshold(project: VProject) -> int:
"SynthSAFieldSensitivity", "SynthIPRuntime", "SynthIPTemplate",
"SynthIPTemplate2", "SynthIPCombined"
]:
# Don't instrument everything for these synthtic projects
# Don't instrument everything for these synthetic projects
return 10

return 0

if project.name in ["HyTeg"]:
if project.name in ["HyTeg", "PicoSATLoadTime"]:
return 0

return 100
Expand Down Expand Up @@ -343,7 +358,7 @@ def run_traced_code(self, tmp_dir: Path) -> StepResult:
f"Running example {prj_command.command.label}"
)

bpf_runner = bpf_runner = self.attach_usdt_bcc(
bpf_runner = self.attach_usdt_bcc(
local_tracefile_path,
self.project.source_of_primary /
self._binary.path
Expand Down
37 changes: 33 additions & 4 deletions varats/varats/plots/feature_perf_precision.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from varats.plot.plot import Plot
from varats.plot.plots import PlotGenerator
from varats.plots.scatter_plot_utils import multivariate_grid
from varats.ts_utils.click_param_types import REQUIRE_MULTI_CASE_STUDY
from varats.utils.exceptions import UnsupportedOperation
from varats.utils.git_util import FullCommitHash

Expand Down Expand Up @@ -79,7 +80,7 @@ class PerfPrecisionDistPlot(Plot, plot_name='fperf_precision_dist'):
different profilers."""

def plot(self, view_mode: bool) -> None:
case_studies = get_loaded_paper_config().get_all_case_studies()
case_studies = self.plot_kwargs["case_studies"]
profilers: tp.List[Profiler] = [VXray(), PIMTracer(), EbpfTraceTEF()]

# Data aggregation
Expand Down Expand Up @@ -153,12 +154,40 @@ def calc_missing_revisions(


class PerfProfDistPlotGenerator(
PlotGenerator, generator_name="fperf-precision-dist", options=[]
PlotGenerator,
generator_name="fperf-precision-dist",
options=[REQUIRE_MULTI_CASE_STUDY]
):
"""Generates performance distribution plot."""
"""Generates performance distribution plot for a given list of case
studies."""

def generate(self) -> tp.List[Plot]:
return [PerfPrecisionDistPlot(self.plot_config, **self.plot_kwargs)]
case_studies = self.plot_kwargs.pop("case_study")
return [
PerfPrecisionDistPlot(
self.plot_config, case_studies=case_studies, **self.plot_kwargs
)
]


class PerfProfDistPlotGeneratorForEachCS(
PlotGenerator,
generator_name="fperf-precision-dist-cs",
options=[REQUIRE_MULTI_CASE_STUDY]
):
"""Generates performance distribution plot for each of the given case
studies."""

def generate(self) -> tp.List[Plot]:
case_studies = self.plot_kwargs.pop("case_study")
return [
PerfPrecisionDistPlot(
self.plot_config,
case_study=case_study,
case_studies=[case_study],
**self.plot_kwargs
) for case_study in case_studies
]


class PerfOverheadPlot(Plot, plot_name='fperf_overhead'):
Expand Down
Loading

0 comments on commit b65e658

Please sign in to comment.