File tree 5 files changed +81
-5
lines changed
src/pytest_codspeed/instruments/hooks
5 files changed +81
-5
lines changed Original file line number Diff line number Diff line change 15
15
runs-on : ubuntu-latest
16
16
steps :
17
17
- uses : actions/checkout@v4
18
+ with :
19
+ submodules : true
18
20
- name : Set up Python 3.11
19
21
uses : actions/setup-python@v5
20
22
with :
44
46
45
47
steps :
46
48
- uses : actions/checkout@v4
49
+ with :
50
+ submodules : true
47
51
- uses : astral-sh/setup-uv@v4
48
52
with :
49
53
version : " 0.5.20"
Original file line number Diff line number Diff line change 1
1
[submodule "tests/benchmarks/TheAlgorithms "]
2
2
path = tests/benchmarks/TheAlgorithms
3
3
url = [email protected] :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 5
5
6
6
from setuptools import setup
7
7
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"
11
9
12
10
spec = importlib .util .spec_from_file_location ("build" , build_path )
13
11
assert spec is not None , "The spec should be initialized"
52
50
setup (
53
51
package_data = {
54
52
"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" ,
57
55
]
58
56
},
59
57
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