Skip to content

Commit 78032ba

Browse files
committed
chore: bump instrument-hooks
1 parent 475be0c commit 78032ba

4 files changed

Lines changed: 62 additions & 5 deletions

File tree

src/pytest_codspeed/instruments/hooks/__init__.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
if TYPE_CHECKING:
1111
from .dist_instrument_hooks import InstrumentHooksPointer, LibType
1212

13+
MARKER_TYPE_SAMPLE_START = 0
14+
MARKER_TYPE_SAMPLE_END = 1
15+
MARKER_TYPE_BENCHMARK_START = 2
16+
MARKER_TYPE_BENCHMARK_END = 3
17+
1318

1419
class InstrumentHooks:
1520
"""Zig library wrapper class providing benchmark measurement functionality."""
@@ -80,3 +85,24 @@ def set_integration(self, name: str, version: str) -> None:
8085
def is_instrumented(self) -> bool:
8186
"""Check if instrumentation is active."""
8287
return self.lib.instrument_hooks_is_instrumented(self.instance)
88+
89+
def add_marker(self, pid: int, marker_type: int, timestamp: int) -> int:
90+
"""Add a marker with the specified type and timestamp.
91+
92+
Args:
93+
pid: Process ID
94+
marker_type: Type of marker (use MARKER_TYPE_* constants)
95+
timestamp: Timestamp value
96+
97+
Returns:
98+
0 on success, non-zero on error
99+
"""
100+
return self.lib.instrument_hooks_add_marker(self.instance, pid, marker_type, timestamp)
101+
102+
def current_timestamp(self) -> int:
103+
"""Get the current timestamp.
104+
105+
Returns:
106+
Current timestamp value
107+
"""
108+
return self.lib.instrument_hooks_current_timestamp()

src/pytest_codspeed/instruments/hooks/build.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,35 @@
66

77
includes_dir = Path(__file__).parent.joinpath("instrument-hooks/includes")
88
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)
9+
10+
11+
# Manually copied from `instrument-hooks/includes/core.h` to avoid parsing issues
12+
ffibuilder.cdef("""
13+
typedef uint64_t *InstrumentHooks;
14+
15+
InstrumentHooks *instrument_hooks_init(void);
16+
void instrument_hooks_deinit(InstrumentHooks *);
17+
18+
bool instrument_hooks_is_instrumented(InstrumentHooks *);
19+
int8_t instrument_hooks_start_benchmark(InstrumentHooks *);
20+
int8_t instrument_hooks_stop_benchmark(InstrumentHooks *);
21+
int8_t instrument_hooks_set_executed_benchmark(InstrumentHooks *, int32_t pid,
22+
const char *uri);
23+
int8_t instrument_hooks_set_integration(InstrumentHooks *, const char *name,
24+
const char *version);
25+
26+
#define MARKER_TYPE_SAMPLE_START 0
27+
#define MARKER_TYPE_SAMPLE_END 1
28+
#define MARKER_TYPE_BENCHMARK_START 2
29+
#define MARKER_TYPE_BENCHMARK_END 3
30+
31+
int8_t instrument_hooks_add_marker(InstrumentHooks *, uint32_t pid,
32+
uint8_t marker_type, uint64_t timestamp);
33+
uint64_t instrument_hooks_current_timestamp(void);
34+
35+
int8_t callgrind_start_instrumentation();
36+
int8_t callgrind_stop_instrumentation();
37+
""")
1338

1439
ffibuilder.set_source(
1540
"pytest_codspeed.instruments.hooks.dist_instrument_hooks",

src/pytest_codspeed/instruments/hooks/dist_instrument_hooks.pyi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ class lib:
2020
hooks: InstrumentHooksPointer, name: bytes, version: bytes
2121
) -> int: ...
2222
@staticmethod
23+
def instrument_hooks_add_marker(
24+
hooks: InstrumentHooksPointer, pid: int, marker_type: int, timestamp: int
25+
) -> int: ...
26+
@staticmethod
27+
def instrument_hooks_current_timestamp() -> int: ...
28+
@staticmethod
2329
def callgrind_start_instrumentation() -> int: ...
2430
@staticmethod
2531
def callgrind_stop_instrumentation() -> int: ...

0 commit comments

Comments
 (0)