diff --git a/src/pytest_codspeed/instruments/hooks/__init__.py b/src/pytest_codspeed/instruments/hooks/__init__.py index be8e665..507aae7 100644 --- a/src/pytest_codspeed/instruments/hooks/__init__.py +++ b/src/pytest_codspeed/instruments/hooks/__init__.py @@ -86,12 +86,9 @@ def set_executed_benchmark(self, uri: str, pid: int | None = None) -> None: if ret != 0: warnings.warn("Failed to set executed benchmark", RuntimeWarning) - @staticmethod - def current_timestamp() -> int: + def current_timestamp(self) -> int: """Return a monotonic timestamp in nanoseconds from the native library.""" - from . import dist_instrument_hooks # type: ignore - - return dist_instrument_hooks.instrument_hooks_current_timestamp() + return self._module.instrument_hooks_current_timestamp() def add_marker( self, marker_type: int, timestamp: int, pid: int | None = None @@ -229,31 +226,13 @@ def collect_and_write_python_environment(self) -> None: self.write_environment() -def callgrind_add_obj_skip(path: str) -> None: - """Tell callgrind to skip the given object file (and its realpath). - - The actual Valgrind client-request trapdoor lives in the C extension; this - just resolves the realpath so callgrind's strcmp matches either form. - """ - if not path or not os.path.exists(path): - return +def callgrind_skip_python_runtime() -> None: + """Skip libpython and the python executable from callgrind measurement.""" try: from . import dist_instrument_hooks # type: ignore except ImportError: return - dist_instrument_hooks.callgrind_add_obj_skip(path.encode()) - - # The dynamic loader maps the realpath (e.g. libpython3.12.so.1.0), and - # callgrind stores that in obj_node->name. Skip both so the exact strcmp - # matches regardless of which path callgrind sees. - real = os.path.realpath(path) - if real != path: - dist_instrument_hooks.callgrind_add_obj_skip(real.encode()) - - -def callgrind_skip_python_runtime() -> None: - """Skip libpython and the python executable from callgrind measurement.""" ldlibrary = sysconfig.get_config_var("LDLIBRARY") libdir = sysconfig.get_config_var("LIBDIR") libpython = next( @@ -268,6 +247,6 @@ def callgrind_skip_python_runtime() -> None: None, ) if libpython: - callgrind_add_obj_skip(libpython) + dist_instrument_hooks.callgrind_add_obj_skip(libpython.encode()) - callgrind_add_obj_skip(sys.executable) + dist_instrument_hooks.callgrind_add_obj_skip(sys.executable.encode()) diff --git a/src/pytest_codspeed/instruments/hooks/instrument-hooks b/src/pytest_codspeed/instruments/hooks/instrument-hooks index 3d13108..65a7afb 160000 --- a/src/pytest_codspeed/instruments/hooks/instrument-hooks +++ b/src/pytest_codspeed/instruments/hooks/instrument-hooks @@ -1 +1 @@ -Subproject commit 3d131089cd93dd2971d35776334c9b6142c43ec1 +Subproject commit 65a7afb18fb3570eed33dc80df4e3428720c9d6d diff --git a/src/pytest_codspeed/instruments/hooks/instrument_hooks_module.c b/src/pytest_codspeed/instruments/hooks/instrument_hooks_module.c index a358d62..0866e7c 100644 --- a/src/pytest_codspeed/instruments/hooks/instrument_hooks_module.c +++ b/src/pytest_codspeed/instruments/hooks/instrument_hooks_module.c @@ -1,12 +1,6 @@ #define PY_SSIZE_T_CLEAN #include #include "core.h" -#include "valgrind.h" - -/* CodSpeed-specific Valgrind client request: tell callgrind to skip an - * object file by path. Not present in upstream callgrind.h. */ -// TODO(COD-2654): Move this to instrument-hooks and just call it here -#define VG_USERREQ__ADD_OBJ_SKIP 0x43540006 /* Capsule destructor for InstrumentHooks pointer */ static void instrument_hooks_capsule_destructor(PyObject *capsule) { @@ -248,15 +242,14 @@ static PyObject *py_instrument_hooks_write_environment(PyObject *self, PyObject return PyLong_FromLong(result); } -/* callgrind_add_obj_skip(path: bytes) -> None - * Outside Valgrind this expands to a nop, so it's safe on bare metal. */ +/* callgrind_add_obj_skip(path: bytes) -> int */ static PyObject *py_callgrind_add_obj_skip(PyObject *self, PyObject *args) { const char *path; if (!PyArg_ParseTuple(args, "y", &path)) { return NULL; } - VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__ADD_OBJ_SKIP, path, 0, 0, 0, 0); - Py_RETURN_NONE; + uint8_t result = instrument_hooks_callgrind_add_obj_skip(path); + return PyLong_FromLong(result); } /* Method definitions */