@@ -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,46 +228,21 @@ def collect_and_write_python_environment(self) -> None:
228228
229229 self .write_environment ()
230230
231-
232- def callgrind_add_obj_skip (path : str ) -> None :
233- """Tell callgrind to skip the given object file (and its realpath).
234-
235- The actual Valgrind client-request trapdoor lives in the C extension; this
236- just resolves the realpath so callgrind's strcmp matches either form.
237- """
238- if not path or not os .path .exists (path ):
239- return
240- try :
241- from . import dist_instrument_hooks # type: ignore
242- except ImportError :
243- return
244-
245- dist_instrument_hooks .callgrind_add_obj_skip (path .encode ())
246-
247- # The dynamic loader maps the realpath (e.g. libpython3.12.so.1.0), and
248- # callgrind stores that in obj_node->name. Skip both so the exact strcmp
249- # matches regardless of which path callgrind sees.
250- real = os .path .realpath (path )
251- if real != path :
252- dist_instrument_hooks .callgrind_add_obj_skip (real .encode ())
253-
254-
255- def callgrind_skip_python_runtime () -> None :
256- """Skip libpython and the python executable from callgrind measurement."""
257- ldlibrary = sysconfig .get_config_var ("LDLIBRARY" )
258- libdir = sysconfig .get_config_var ("LIBDIR" )
259- libpython = next (
260- (
261- p
262- for p in (
263- os .path .join (libdir , ldlibrary ) if ldlibrary and libdir else None ,
264- os .path .join (sys .prefix , "lib" , ldlibrary ) if ldlibrary else None ,
265- )
266- if p and os .path .exists (p )
267- ),
268- None ,
269- )
270- if libpython :
271- callgrind_add_obj_skip (libpython )
272-
273- callgrind_add_obj_skip (sys .executable )
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