Skip to content

Commit 01f1b7b

Browse files
committed
feat: add instrument-hook library
1 parent c92304c commit 01f1b7b

11 files changed

Lines changed: 71 additions & 79 deletions

File tree

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
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"]
5+
path = src/pytest_codspeed/instruments/hooks
6+
url = https://github.com/CodSpeedHQ/instrument-hooks

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from setuptools import setup
77

88
build_path = (
9-
Path(__file__).parent / "src/pytest_codspeed/instruments/valgrind/_wrapper/build.py"
9+
Path(__file__).parent / "src/pytest_codspeed/instruments/hooks/build.py"
1010
)
1111

1212
spec = importlib.util.spec_from_file_location("build", build_path)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import os
2+
from typing import Optional
3+
4+
from pytest_codspeed.core import lib
5+
6+
class InstrumentHooks:
7+
"""Core library wrapper class providing benchmark measurement functionality."""
8+
9+
@staticmethod
10+
def start_benchmark() -> None:
11+
"""Start a new benchmark measurement."""
12+
lib.start_benchmark()
13+
14+
@staticmethod
15+
def stop_benchmark() -> None:
16+
"""Stop the current benchmark measurement."""
17+
lib.stop_benchmark()
18+
19+
@staticmethod
20+
def set_current_benchmark(uri: str, pid: Optional[int] = None) -> None:
21+
"""Set the current benchmark URI and process ID.
22+
23+
Args:
24+
uri: The benchmark URI string identifier
25+
pid: Optional process ID (defaults to current process)
26+
"""
27+
if pid is None:
28+
pid = os.getpid()
29+
lib.current_benchmark(pid, uri.encode('ascii'))
30+
31+
@staticmethod
32+
def set_integration(name: str, version: str) -> None:
33+
"""Set the integration name and version."""
34+
lib.set_integration(name.encode('ascii'), version.encode('ascii'))
35+
36+
@staticmethod
37+
def is_instrumented() -> bool:
38+
"""Check if instrumentation is active."""
39+
return lib.is_instrumented()
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from pathlib import Path
2+
from cffi import FFI # type: ignore
3+
4+
ffibuilder = FFI()
5+
6+
dist_dir = Path(__file__).parent.joinpath("instrument-hooks/dist")
7+
header_text = (dist_dir / "core.h").read_text()
8+
filtered_header = "\n".join(
9+
line for line in header_text.splitlines()
10+
if not line.strip().startswith("#")
11+
)
12+
ffibuilder.cdef(filtered_header)
13+
14+
ffibuilder.set_source(
15+
"pytest_codspeed.core",
16+
"",
17+
libraries=["m", "quadmath"],
18+
sources=[
19+
"src/pytest_codspeed/instruments/core/instrument-hooks/dist/core.c",
20+
"src/pytest_codspeed/instruments/core/instrument-hooks/dist/wrapper.c",
21+
],
22+
include_dirs=[str(dist_dir)],
23+
extra_compile_args=["-lm", "-lcs50"],
24+
)
25+
26+
if __name__ == "__main__":
27+
ffibuilder.compile(verbose=True)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 3363c83d15532a981c4a4c9985871ceebb546ed4
File renamed without changes.

src/pytest_codspeed/instruments/valgrind/_wrapper/__init__.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/pytest_codspeed/instruments/valgrind/_wrapper/build.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/pytest_codspeed/instruments/valgrind/_wrapper/wrapper.c

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/pytest_codspeed/instruments/valgrind/_wrapper/wrapper.h

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)