File tree Expand file tree Collapse file tree
src/pytest_codspeed/instruments/hooks Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1515 runs-on : ubuntu-latest
1616 steps :
1717 - uses : actions/checkout@v4
18+ with :
19+ submodules : true
1820 - name : Set up Python 3.11
1921 uses : actions/setup-python@v5
2022 with :
4446
4547 steps :
4648 - uses : actions/checkout@v4
49+ with :
50+ submodules : true
4751 - uses : astral-sh/setup-uv@v4
4852 with :
4953 version : " 0.5.20"
Original file line number Diff line number Diff line change 11[submodule "tests/benchmarks/TheAlgorithms "]
22 path = tests/benchmarks/TheAlgorithms
33 url = git@github.com:TheAlgorithms/Python.git
4+ [submodule "src/pytest_codspeed/instruments/hooks/instrument-hooks "]
5+ path = src/pytest_codspeed/instruments/hooks/instrument-hooks
6+ url = https://github.com/CodSpeedHQ/instrument-hooks
7+ branch = cod-731-ipc-implementation-for-perf-and-other-tools
Original file line number Diff line number Diff line change 55
66from setuptools import setup
77
8- build_path = (
9- Path (__file__ ).parent / "src/pytest_codspeed/instruments/valgrind/_wrapper/build.py"
10- )
8+ build_path = Path (__file__ ).parent / "src/pytest_codspeed/instruments/hooks/build.py"
119
1210spec = importlib .util .spec_from_file_location ("build" , build_path )
1311assert spec is not None , "The spec should be initialized"
5250setup (
5351 package_data = {
5452 "pytest_codspeed" : [
55- "instruments/valgrind/_wrapper /*.h" ,
56- "instruments/valgrind/_wrapper /*.c" ,
53+ "instruments/hooks/instrument-hooks/includes /*.h" ,
54+ "instruments/hooks/instrument-hooks/dist /*.c" ,
5755 ]
5856 },
5957 ext_modules = (
Original file line number Diff line number Diff line change 1+ from __future__ import annotations
2+
3+ import os
4+
5+ from pytest_codspeed .core import lib
6+
7+
8+ class InstrumentHooks :
9+ """Core library wrapper class providing benchmark measurement functionality."""
10+
11+ @staticmethod
12+ def start_benchmark () -> None :
13+ """Start a new benchmark measurement."""
14+ lib .start_benchmark ()
15+
16+ @staticmethod
17+ def stop_benchmark () -> None :
18+ """Stop the current benchmark measurement."""
19+ lib .stop_benchmark ()
20+
21+ @staticmethod
22+ def set_current_benchmark (uri : str , pid : int | None = None ) -> None :
23+ """Set the current benchmark URI and process ID.
24+
25+ Args:
26+ uri: The benchmark URI string identifier
27+ pid: Optional process ID (defaults to current process)
28+ """
29+ if pid is None :
30+ pid = os .getpid ()
31+ lib .current_benchmark (pid , uri .encode ("ascii" ))
32+
33+ @staticmethod
34+ def set_integration (name : str , version : str ) -> None :
35+ """Set the integration name and version."""
36+ lib .set_integration (name .encode ("ascii" ), version .encode ("ascii" ))
37+
38+ @staticmethod
39+ def is_instrumented () -> bool :
40+ """Check if instrumentation is active."""
41+ return lib .is_instrumented ()
Original file line number Diff line number Diff line change 1+ from pathlib import Path
2+
3+ from cffi import FFI # type: ignore
4+
5+ ffibuilder = FFI ()
6+
7+ includes_dir = Path (__file__ ).parent .joinpath ("instrument-hooks/includes" )
8+ header_text = (includes_dir / "core.h" ).read_text ()
9+ filtered_header = "\n " .join (
10+ line for line in header_text .splitlines () if not line .strip ().startswith ("#" )
11+ )
12+ ffibuilder .cdef (filtered_header )
13+
14+ ffibuilder .set_source (
15+ "pytest_codspeed.core" ,
16+ """
17+ #include "core.h"
18+ #include <quadmath.h>
19+ """ ,
20+ libraries = ["m" , "quadmath" ],
21+ sources = [
22+ "src/pytest_codspeed/instruments/hooks/instrument-hooks/dist/core.c" ,
23+ ],
24+ include_dirs = [str (includes_dir )],
25+ extra_compile_args = ["-lm" , "-lcs50" ],
26+ )
27+
28+ if __name__ == "__main__" :
29+ ffibuilder .compile (verbose = True )
You can’t perform that action at this time.
0 commit comments