Skip to content

Commit 2fd61d3

Browse files
committed
fixup! feat: skip Python runtime objects in callgrind
1 parent fc558b1 commit 2fd61d3

1 file changed

Lines changed: 19 additions & 26 deletions

File tree

src/pytest_codspeed/instruments/hooks/__init__.py

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def __init__(self) -> None:
5252

5353
# Ignore libpython and python executable frames in callgrind so they
5454
# don't obfuscate the flamegraph.
55-
callgrind_skip_python_runtime()
55+
self._callgrind_skip_python_runtime()
5656

5757
def __del__(self):
5858
# Don't manually deinit - let the capsule destructor handle it
@@ -228,28 +228,21 @@ def collect_and_write_python_environment(self) -> None:
228228

229229
self.write_environment()
230230

231-
232-
def callgrind_skip_python_runtime() -> None:
233-
"""Skip libpython and the python executable from callgrind measurement."""
234-
try:
235-
from . import dist_instrument_hooks # type: ignore
236-
except ImportError:
237-
return
238-
239-
ldlibrary = sysconfig.get_config_var("LDLIBRARY")
240-
libdir = sysconfig.get_config_var("LIBDIR")
241-
libpython = next(
242-
(
243-
p
244-
for p in (
245-
os.path.join(libdir, ldlibrary) if ldlibrary and libdir else None,
246-
os.path.join(sys.prefix, "lib", ldlibrary) if ldlibrary else None,
247-
)
248-
if p and os.path.exists(p)
249-
),
250-
None,
251-
)
252-
if libpython:
253-
dist_instrument_hooks.callgrind_add_obj_skip(libpython.encode())
254-
255-
dist_instrument_hooks.callgrind_add_obj_skip(sys.executable.encode())
231+
def _callgrind_skip_python_runtime(self) -> None:
232+
"""Skip libpython and the python executable from callgrind measurement."""
233+
ldlibrary = sysconfig.get_config_var("LDLIBRARY")
234+
libdir = sysconfig.get_config_var("LIBDIR")
235+
libpython = next(
236+
(
237+
p
238+
for p in (
239+
os.path.join(libdir, ldlibrary) if ldlibrary and libdir else None,
240+
os.path.join(sys.prefix, "lib", ldlibrary) if ldlibrary else None,
241+
)
242+
if p and os.path.exists(p)
243+
),
244+
None,
245+
)
246+
if libpython:
247+
self._module.callgrind_add_obj_skip(libpython.encode())
248+
self._module.callgrind_add_obj_skip(sys.executable.encode())

0 commit comments

Comments
 (0)