File tree Expand file tree Collapse file tree 6 files changed +25
-16
lines changed Expand file tree Collapse file tree 6 files changed +25
-16
lines changed Original file line number Diff line number Diff line change 5
5
import warnings
6
6
from typing import TYPE_CHECKING
7
7
8
+ from pytest_codspeed .utils import SUPPORTS_PERF_TRAMPOLINE
9
+
8
10
if TYPE_CHECKING :
9
11
from .dist_instrument_hooks import InstrumentHooksPointer , LibType
10
12
11
- SUPPORTS_PERF_TRAMPOLINE = sys .version_info >= (3 , 12 )
12
-
13
13
14
14
class InstrumentHooks :
15
15
"""Zig library wrapper class providing benchmark measurement functionality."""
Original file line number Diff line number Diff line change 1
1
from __future__ import annotations
2
2
3
- import sys
4
3
import warnings
5
4
from typing import TYPE_CHECKING
6
5
7
6
from pytest_codspeed import __semver_version__
8
7
from pytest_codspeed .instruments import Instrument
9
8
from pytest_codspeed .instruments .hooks import InstrumentHooks
9
+ from pytest_codspeed .utils import SUPPORTS_PERF_TRAMPOLINE
10
10
11
11
if TYPE_CHECKING :
12
12
from typing import Any , Callable
17
17
from pytest_codspeed .instruments import T
18
18
from pytest_codspeed .plugin import BenchmarkMarkerOptions , CodSpeedConfig
19
19
20
- SUPPORTS_PERF_TRAMPOLINE = sys .version_info >= (3 , 12 )
21
-
22
20
23
21
class ValgrindInstrument (Instrument ):
24
22
instrument = "valgrind"
Original file line number Diff line number Diff line change 16
16
from pytest_codspeed import __semver_version__
17
17
from pytest_codspeed .instruments import Instrument
18
18
from pytest_codspeed .instruments .hooks import InstrumentHooks
19
+ from pytest_codspeed .utils import SUPPORTS_PERF_TRAMPOLINE
19
20
20
21
if TYPE_CHECKING :
21
22
from typing import Any , Callable
@@ -173,7 +174,13 @@ def __init__(self, config: CodSpeedConfig) -> None:
173
174
self .benchmarks : list [Benchmark ] = []
174
175
175
176
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 , []
177
184
178
185
def measure (
179
186
self ,
Original file line number Diff line number Diff line change 2
2
3
3
import functools
4
4
import gc
5
- import importlib .util
6
5
import json
7
6
import os
8
7
import random
19
18
CodSpeedConfig ,
20
19
PedanticOptions ,
21
20
)
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
26
22
from pytest_codspeed .utils import (
23
+ BEFORE_PYTEST_8_1_1 ,
24
+ IS_PYTEST_BENCHMARK_INSTALLED ,
25
+ IS_PYTEST_SPEED_INSTALLED ,
27
26
get_environment_metadata ,
28
27
get_git_relative_uri_and_name ,
29
28
)
37
36
38
37
T = TypeVar ("T" )
39
38
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
-
44
39
45
40
@pytest .hookimpl (trylast = True )
46
41
def pytest_addoption (parser : pytest .Parser ):
Original file line number Diff line number Diff line change 1
1
from __future__ import annotations
2
2
3
+ import importlib .util
3
4
import os
4
5
import sys
5
6
import sysconfig
6
7
from pathlib import Path
7
8
9
+ import pytest
10
+
8
11
from pytest_codspeed import __semver_version__
9
12
10
13
if sys .version_info < (3 , 10 ):
13
16
import importlib .metadata as importlib_metadata
14
17
15
18
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
+
16
25
def get_git_relative_path (abs_path : Path ) -> Path :
17
26
"""Get the path relative to the git root directory. If the path is not
18
27
inside a git repository, the original path itself is returned.
Original file line number Diff line number Diff line change 10
10
import pytest
11
11
12
12
from pytest_codspeed .instruments import MeasurementMode
13
+ from pytest_codspeed .utils import IS_PYTEST_BENCHMARK_INSTALLED
13
14
14
15
if TYPE_CHECKING :
15
16
from _pytest .pytester import RunResult
16
17
17
18
pytest_plugins = ["pytester" ]
18
19
19
- IS_PYTEST_BENCHMARK_INSTALLED = importlib .util .find_spec ("pytest_benchmark" ) is not None
20
20
skip_without_pytest_benchmark = pytest .mark .skipif (
21
21
not IS_PYTEST_BENCHMARK_INSTALLED , reason = "pytest_benchmark not installed"
22
22
)
You can’t perform that action at this time.
0 commit comments