File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55import warnings
66from typing import TYPE_CHECKING
77
8+ from pytest_codspeed .utils import SUPPORTS_PERF_TRAMPOLINE
9+
810if TYPE_CHECKING :
911 from .dist_instrument_hooks import InstrumentHooksPointer , LibType
1012
11- SUPPORTS_PERF_TRAMPOLINE = sys .version_info >= (3 , 12 )
12-
1313
1414class InstrumentHooks :
1515 """Zig library wrapper class providing benchmark measurement functionality."""
Original file line number Diff line number Diff line change 11from __future__ import annotations
22
3- import sys
43import warnings
54from typing import TYPE_CHECKING
65
76from pytest_codspeed import __semver_version__
87from pytest_codspeed .instruments import Instrument
98from pytest_codspeed .instruments .hooks import InstrumentHooks
9+ from pytest_codspeed .utils import SUPPORTS_PERF_TRAMPOLINE
1010
1111if TYPE_CHECKING :
1212 from typing import Any , Callable
1717 from pytest_codspeed .instruments import T
1818 from pytest_codspeed .plugin import BenchmarkMarkerOptions , CodSpeedConfig
1919
20- SUPPORTS_PERF_TRAMPOLINE = sys .version_info >= (3 , 12 )
21-
2220
2321class ValgrindInstrument (Instrument ):
2422 instrument = "valgrind"
Original file line number Diff line number Diff line change 1616from pytest_codspeed import __semver_version__
1717from pytest_codspeed .instruments import Instrument
1818from pytest_codspeed .instruments .hooks import InstrumentHooks
19+ from pytest_codspeed .utils import SUPPORTS_PERF_TRAMPOLINE
1920
2021if TYPE_CHECKING :
2122 from typing import Any , Callable
@@ -173,7 +174,13 @@ def __init__(self, config: CodSpeedConfig) -> None:
173174 self .benchmarks : list [Benchmark ] = []
174175
175176 def get_instrument_config_str_and_warns (self ) -> tuple [str , list [str ]]:
176- return f"mode: walltime, timer_resolution: { TIMER_RESOLUTION_NS :.1f} ns" , []
177+ config_str = (
178+ f"mode: walltime, "
179+ f"callgraph: "
180+ f"{ 'enabled' if SUPPORTS_PERF_TRAMPOLINE else 'not supported' } , "
181+ f"timer_resolution: { TIMER_RESOLUTION_NS :.1f} ns"
182+ )
183+ return config_str , []
177184
178185 def measure (
179186 self ,
Original file line number Diff line number Diff line change 22
33import functools
44import gc
5- import importlib .util
65import json
76import os
87import random
1918 CodSpeedConfig ,
2019 PedanticOptions ,
2120)
22- from pytest_codspeed .instruments import (
23- MeasurementMode ,
24- get_instrument_from_mode ,
25- )
21+ from pytest_codspeed .instruments import MeasurementMode , get_instrument_from_mode
2622from pytest_codspeed .utils import (
23+ BEFORE_PYTEST_8_1_1 ,
24+ IS_PYTEST_BENCHMARK_INSTALLED ,
25+ IS_PYTEST_SPEED_INSTALLED ,
2726 get_environment_metadata ,
2827 get_git_relative_uri_and_name ,
2928)
3736
3837 T = TypeVar ("T" )
3938
40- IS_PYTEST_BENCHMARK_INSTALLED = importlib .util .find_spec ("pytest_benchmark" ) is not None
41- IS_PYTEST_SPEED_INSTALLED = importlib .util .find_spec ("pytest_speed" ) is not None
42- BEFORE_PYTEST_8_1_1 = pytest .version_tuple < (8 , 1 , 1 )
43-
4439
4540@pytest .hookimpl (trylast = True )
4641def pytest_addoption (parser : pytest .Parser ):
Original file line number Diff line number Diff line change 11from __future__ import annotations
22
3+ import importlib .util
34import os
45import sys
56import sysconfig
67from pathlib import Path
78
9+ import pytest
10+
811from pytest_codspeed import __semver_version__
912
1013if sys .version_info < (3 , 10 ):
1316 import importlib .metadata as importlib_metadata
1417
1518
19+ IS_PYTEST_BENCHMARK_INSTALLED = importlib .util .find_spec ("pytest_benchmark" ) is not None
20+ IS_PYTEST_SPEED_INSTALLED = importlib .util .find_spec ("pytest_speed" ) is not None
21+ BEFORE_PYTEST_8_1_1 = pytest .version_tuple < (8 , 1 , 1 )
22+ SUPPORTS_PERF_TRAMPOLINE = sysconfig .get_config_var ("PY_HAVE_PERF_TRAMPOLINE" ) == 1
23+
24+
1625def get_git_relative_path (abs_path : Path ) -> Path :
1726 """Get the path relative to the git root directory. If the path is not
1827 inside a git repository, the original path itself is returned.
Original file line number Diff line number Diff line change 1010import pytest
1111
1212from pytest_codspeed .instruments import MeasurementMode
13+ from pytest_codspeed .utils import IS_PYTEST_BENCHMARK_INSTALLED
1314
1415if TYPE_CHECKING :
1516 from _pytest .pytester import RunResult
1617
1718pytest_plugins = ["pytester" ]
1819
19- IS_PYTEST_BENCHMARK_INSTALLED = importlib .util .find_spec ("pytest_benchmark" ) is not None
2020skip_without_pytest_benchmark = pytest .mark .skipif (
2121 not IS_PYTEST_BENCHMARK_INSTALLED , reason = "pytest_benchmark not installed"
2222)
You can’t perform that action at this time.
0 commit comments