diff --git a/src/pytest_codspeed/instruments/__init__.py b/src/pytest_codspeed/instruments/__init__.py index 163bcc4..edd2849 100644 --- a/src/pytest_codspeed/instruments/__init__.py +++ b/src/pytest_codspeed/instruments/__init__.py @@ -16,7 +16,7 @@ class Instrument(metaclass=ABCMeta): - instrument: ClassVar[MeasurementMode] + instrument: ClassVar[str] @abstractmethod def __init__(self, config: CodSpeedConfig): ... @@ -44,17 +44,17 @@ def get_result_dict( class MeasurementMode(str, Enum): - CPUInstrumentation = "cpu_instrumentation" + Instrumentation = "instrumentation" WallTime = "walltime" def get_instrument_from_mode(mode: MeasurementMode) -> type[Instrument]: - from pytest_codspeed.instruments.cpu_instrumentation import ( - CPUInstrumentationInstrument, + from pytest_codspeed.instruments.valgrind import ( + ValgrindInstrument, ) from pytest_codspeed.instruments.walltime import WallTimeInstrument - if mode == MeasurementMode.CPUInstrumentation: - return CPUInstrumentationInstrument + if mode == MeasurementMode.Instrumentation: + return ValgrindInstrument else: return WallTimeInstrument diff --git a/src/pytest_codspeed/instruments/cpu_instrumentation/__init__.py b/src/pytest_codspeed/instruments/valgrind/__init__.py similarity index 87% rename from src/pytest_codspeed/instruments/cpu_instrumentation/__init__.py rename to src/pytest_codspeed/instruments/valgrind/__init__.py index 3f8f49d..b8d1974 100644 --- a/src/pytest_codspeed/instruments/cpu_instrumentation/__init__.py +++ b/src/pytest_codspeed/instruments/valgrind/__init__.py @@ -5,8 +5,8 @@ from typing import TYPE_CHECKING from pytest_codspeed import __version__ -from pytest_codspeed.instruments import Instrument, MeasurementMode -from pytest_codspeed.instruments.cpu_instrumentation._wrapper import get_lib +from pytest_codspeed.instruments import Instrument +from pytest_codspeed.instruments.valgrind._wrapper import get_lib if TYPE_CHECKING: from typing import Any, Callable @@ -14,14 +14,14 @@ from pytest import Session from pytest_codspeed.instruments import P, T - from pytest_codspeed.instruments.cpu_instrumentation._wrapper import LibType + from pytest_codspeed.instruments.valgrind._wrapper import LibType from pytest_codspeed.plugin import CodSpeedConfig SUPPORTS_PERF_TRAMPOLINE = sys.version_info >= (3, 12) -class CPUInstrumentationInstrument(Instrument): - instrument = MeasurementMode.CPUInstrumentation +class ValgrindInstrument(Instrument): + instrument = "valgrind" lib: LibType | None def __init__(self, config: CodSpeedConfig) -> None: @@ -90,6 +90,6 @@ def report(self, session: Session) -> None: def get_result_dict(self) -> dict[str, Any]: return { - "instrument": {"type": self.instrument.value}, + "instrument": {"type": self.instrument}, # bench results will be dumped by valgrind } diff --git a/src/pytest_codspeed/instruments/cpu_instrumentation/_wrapper/.gitignore b/src/pytest_codspeed/instruments/valgrind/_wrapper/.gitignore similarity index 100% rename from src/pytest_codspeed/instruments/cpu_instrumentation/_wrapper/.gitignore rename to src/pytest_codspeed/instruments/valgrind/_wrapper/.gitignore diff --git a/src/pytest_codspeed/instruments/cpu_instrumentation/_wrapper/__init__.py b/src/pytest_codspeed/instruments/valgrind/_wrapper/__init__.py similarity index 100% rename from src/pytest_codspeed/instruments/cpu_instrumentation/_wrapper/__init__.py rename to src/pytest_codspeed/instruments/valgrind/_wrapper/__init__.py diff --git a/src/pytest_codspeed/instruments/cpu_instrumentation/_wrapper/wrapper.c b/src/pytest_codspeed/instruments/valgrind/_wrapper/wrapper.c similarity index 100% rename from src/pytest_codspeed/instruments/cpu_instrumentation/_wrapper/wrapper.c rename to src/pytest_codspeed/instruments/valgrind/_wrapper/wrapper.c diff --git a/src/pytest_codspeed/instruments/cpu_instrumentation/_wrapper/wrapper.h b/src/pytest_codspeed/instruments/valgrind/_wrapper/wrapper.h similarity index 100% rename from src/pytest_codspeed/instruments/cpu_instrumentation/_wrapper/wrapper.h rename to src/pytest_codspeed/instruments/valgrind/_wrapper/wrapper.h diff --git a/src/pytest_codspeed/instruments/cpu_instrumentation/_wrapper/wrapper.pyi b/src/pytest_codspeed/instruments/valgrind/_wrapper/wrapper.pyi similarity index 100% rename from src/pytest_codspeed/instruments/cpu_instrumentation/_wrapper/wrapper.pyi rename to src/pytest_codspeed/instruments/valgrind/_wrapper/wrapper.pyi diff --git a/src/pytest_codspeed/instruments/walltime.py b/src/pytest_codspeed/instruments/walltime.py index eaa799c..d81cc74 100644 --- a/src/pytest_codspeed/instruments/walltime.py +++ b/src/pytest_codspeed/instruments/walltime.py @@ -9,7 +9,7 @@ from rich.console import Console from rich.table import Table -from pytest_codspeed.instruments import Instrument, MeasurementMode +from pytest_codspeed.instruments import Instrument if TYPE_CHECKING: from typing import Any, Callable @@ -153,7 +153,7 @@ def run_benchmark( class WallTimeInstrument(Instrument): - instrument = MeasurementMode.WallTime + instrument = "walltime" def __init__(self, config: CodSpeedConfig) -> None: self.config = config @@ -224,7 +224,7 @@ def _print_benchmark_table(self) -> None: def get_result_dict(self) -> dict[str, Any]: return { "instrument": { - "type": self.instrument.value, + "type": self.instrument, "clock_info": get_clock_info("perf_counter").__dict__, }, "benchmarks": [asdict(bench) for bench in self.benchmarks], diff --git a/src/pytest_codspeed/plugin.py b/src/pytest_codspeed/plugin.py index 42dae38..c3bd886 100644 --- a/src/pytest_codspeed/plugin.py +++ b/src/pytest_codspeed/plugin.py @@ -123,7 +123,7 @@ def pytest_configure(config: pytest.Config): if os.environ.get("CODSPEED_RUNNER_MODE") == "walltime": default_mode = MeasurementMode.WallTime.value else: - default_mode = MeasurementMode.CPUInstrumentation.value + default_mode = MeasurementMode.Instrumentation.value else: default_mode = MeasurementMode.WallTime.value @@ -144,7 +144,7 @@ def pytest_configure(config: pytest.Config): profile_folder = os.environ.get("CODSPEED_PROFILE_FOLDER") if profile_folder: - result_path = Path(profile_folder) / "walltime" / f"{os.getpid()}.json" + result_path = Path(profile_folder) / "results" / f"{os.getpid()}.json" else: result_path = config.rootpath / f".codspeed/results_{time() * 1000:.0f}.json" diff --git a/tests/test_pytest_plugin_cpu_instrumentation.py b/tests/test_pytest_plugin_cpu_instrumentation.py index bb3b133..e911c52 100644 --- a/tests/test_pytest_plugin_cpu_instrumentation.py +++ b/tests/test_pytest_plugin_cpu_instrumentation.py @@ -36,7 +36,7 @@ def _(): return 1 + 1 """ ) - result = run_pytest_codspeed_with_mode(pytester, MeasurementMode.CPUInstrumentation) + result = run_pytest_codspeed_with_mode(pytester, MeasurementMode.Instrumentation) result.stdout.fnmatch_lines( [ ( @@ -76,8 +76,7 @@ def fixtured_child(): with open(perf_filepath) as perf_file: lines = perf_file.readlines() assert any( - "py::CPUInstrumentationInstrument.measure..__codspeed_root_frame__" - in line + "py::ValgrindInstrument.measure..__codspeed_root_frame__" in line for line in lines ), "No root frame found in perf map" assert any(