Skip to content

Commit 7bcb410

Browse files
committed
chore: wip [skip ci]
1 parent adee8a1 commit 7bcb410

5 files changed

Lines changed: 29 additions & 23 deletions

File tree

src/pytest_codspeed/instruments/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def get_result_dict(
5757

5858
class MeasurementMode(str, Enum):
5959
Simulation = "simulation"
60+
Memory = "memory"
6061
WallTime = "walltime"
6162

6263
@classmethod
@@ -68,12 +69,12 @@ def _missing_(cls, value: object):
6869

6970

7071
def get_instrument_from_mode(mode: MeasurementMode) -> type[Instrument]:
71-
from pytest_codspeed.instruments.valgrind import (
72-
ValgrindInstrument,
72+
from pytest_codspeed.instruments.analysis import (
73+
AnalysisInstrument,
7374
)
7475
from pytest_codspeed.instruments.walltime import WallTimeInstrument
7576

76-
if mode == MeasurementMode.Simulation:
77-
return ValgrindInstrument
77+
if mode in (MeasurementMode.Simulation, MeasurementMode.Memory):
78+
return AnalysisInstrument
7879
else:
7980
return WallTimeInstrument

src/pytest_codspeed/instruments/valgrind.py renamed to src/pytest_codspeed/instruments/analysis.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
from pytest_codspeed.plugin import BenchmarkMarkerOptions, CodSpeedConfig
2020

2121

22-
class ValgrindInstrument(Instrument):
23-
instrument = "valgrind"
22+
class AnalysisInstrument(Instrument):
23+
instrument = "analysis"
2424
instrument_hooks: InstrumentHooks | None
2525

2626
def __init__(self, config: CodSpeedConfig) -> None:
@@ -30,27 +30,29 @@ def __init__(self, config: CodSpeedConfig) -> None:
3030
self.instrument_hooks.set_integration("pytest-codspeed", __semver_version__)
3131
except RuntimeError as e:
3232
if os.environ.get("CODSPEED_ENV") is not None:
33+
# FIXME: use the actual mode str here
3334
raise Exception(
34-
"Failed to initialize CPU simulation instrument hooks"
35+
"Failed to initialize analysis instrument hooks"
3536
) from e
3637
self.instrument_hooks = None
3738

3839
self.should_measure = self.instrument_hooks is not None
3940

4041
def get_instrument_config_str_and_warns(self) -> tuple[str, list[str]]:
42+
# FIXME: use the actual mode str here
4143
config = (
42-
f"mode: simulation, "
44+
f"instrument: analysis, "
4345
f"callgraph: {'enabled' if SUPPORTS_PERF_TRAMPOLINE else 'not supported'}"
4446
)
45-
warnings = []
47+
warns = []
4648
if not self.should_measure:
47-
warnings.append(
49+
warns.append(
4850
"\033[1m"
4951
"NOTICE: codspeed is enabled, but no performance measurement"
5052
" will be made since it's running in an unknown environment."
5153
"\033[0m"
5254
)
53-
return config, warnings
55+
return config, warns
5456

5557
def measure(
5658
self,
@@ -73,14 +75,12 @@ def __codspeed_root_frame__() -> T:
7375
# Warmup CPython performance map cache
7476
__codspeed_root_frame__()
7577

76-
# Manually call the library function to avoid an extra stack frame. Also
77-
# call the callgrind markers directly to avoid extra overhead.
78-
self.instrument_hooks.lib.callgrind_start_instrumentation()
78+
self.instrument_hooks.start_benchmark()
7979
try:
8080
return __codspeed_root_frame__()
8181
finally:
8282
# Ensure instrumentation is stopped even if the test failed
83-
self.instrument_hooks.lib.callgrind_stop_instrumentation()
83+
self.instrument_hooks.stop_benchmark()
8484
self.instrument_hooks.set_executed_benchmark(uri)
8585

8686
def measure_pedantic(
@@ -91,8 +91,9 @@ def measure_pedantic(
9191
uri: str,
9292
) -> T:
9393
if pedantic_options.rounds != 1 or pedantic_options.iterations != 1:
94+
# FIXME: Use the real instrument here
9495
warnings.warn(
95-
"Valgrind instrument ignores rounds and iterations settings "
96+
"Analysis instrument ignores rounds and iterations settings "
9697
"in pedantic mode"
9798
)
9899
if not self.instrument_hooks:
@@ -117,11 +118,12 @@ def __codspeed_root_frame__(*args, **kwargs) -> T:
117118

118119
# Compute the actual result of the function
119120
args, kwargs = pedantic_options.setup_and_get_args_kwargs()
120-
self.instrument_hooks.lib.callgrind_start_instrumentation()
121+
122+
self.instrument_hooks.start_benchmark()
121123
try:
122124
out = __codspeed_root_frame__(*args, **kwargs)
123125
finally:
124-
self.instrument_hooks.lib.callgrind_stop_instrumentation()
126+
self.instrument_hooks.stop_benchmark()
125127
self.instrument_hooks.set_executed_benchmark(uri)
126128
if pedantic_options.teardown is not None:
127129
pedantic_options.teardown(*args, **kwargs)
@@ -140,5 +142,5 @@ def report(self, session: Session) -> None:
140142
def get_result_dict(self) -> dict[str, Any]:
141143
return {
142144
"instrument": {"type": self.instrument},
143-
# bench results will be dumped by valgrind
145+
# bench results will be dumped by the runner
144146
}

src/pytest_codspeed/plugin.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,11 @@ def pytest_configure(config: pytest.Config):
112112
)
113113

114114
if os.environ.get("CODSPEED_ENV") is not None:
115-
if os.environ.get("CODSPEED_RUNNER_MODE") == "walltime":
115+
runner_mode = os.environ.get("CODSPEED_RUNNER_MODE")
116+
if runner_mode == "walltime":
116117
default_mode = MeasurementMode.WallTime.value
118+
elif runner_mode == "memory":
119+
default_mode = MeasurementMode.Memory.value
117120
else:
118121
default_mode = MeasurementMode.Simulation.value
119122
else:

tests/test_pytest_plugin_cpu_instrumentation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def fixtured_child():
7676
with open(perf_filepath) as perf_file:
7777
lines = perf_file.readlines()
7878
assert any(
79-
"py::ValgrindInstrument.measure.<locals>.__codspeed_root_frame__" in line
79+
"py::AnalysisInstrument.measure.<locals>.__codspeed_root_frame__" in line
8080
for line in lines
8181
), "No root frame found in perf map"
8282
assert any("py::test_some_addition_marked" in line for line in lines), (
@@ -135,7 +135,7 @@ def foo():
135135
result = run_pytest_codspeed_with_mode(pytester, MeasurementMode.Simulation)
136136
result.stdout.fnmatch_lines(
137137
[
138-
"*UserWarning: Valgrind instrument ignores rounds and iterations settings "
138+
"*UserWarning: Analysis instrument ignores rounds and iterations settings "
139139
"in pedantic mode*"
140140
]
141141
)

0 commit comments

Comments
 (0)