Skip to content

Commit

Permalink
vendor: Add support for CYTHON_TRACE environment variable [MAGMA-4116]
Browse files Browse the repository at this point in the history
This commit introduces the ability to enable line tracing in Cython for
profiling purposes. This is controlled by the CYTHON_TRACE environment variable.
When set, the 'linetrace' and 'binding' Cython directives are enabled,
and the CYTHON_TRACE macro is defined.
  • Loading branch information
mtreglia-gpsw committed May 14, 2024
1 parent df2d505 commit 6aade2b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cython_setuptools/vendor.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ def setup(original_setup_file: str, cythonize: bool = True, **kwargs):
PROFILE_CYTHON=1 python setup.py build_ext --inplace
In addition it's possible to add also the CYTHON_TRACE environment variable
to enable line tracing in Cython for profiling::
``CYTHON_TRACE`` environment variable::
CYTHON_TRACE=1 PROFILE_CYTHON=1 python setup.py build_ext --inplace``
Debugging symbols can be added with::
DEBUG=1 python setup.py build_ext --inplace
Expand Down Expand Up @@ -198,6 +204,15 @@ def create_cython_ext_modules(cython_modules, profile_cython=False, debug=False)
if profile_cython:
cython_directives = kwargs.setdefault("cython_directives", {})
cython_directives["profile"] = True
cython_trace = _str_to_bool(os.environ.get("CYTHON_TRACE", False))
if cython_trace:
# Enable line tracing in Cython for profiling
cython_directives["linetrace"] = True
# Enable binding mode in Cython for C API access
cython_directives['binding'] = True
# Define the CYTHON_TRACE macro to enable tracing
define_macros = kwargs.setdefault("define_macros", [])
define_macros.append(('CYTHON_TRACE', '1'))
if debug:
for args_name in ("extra_compile_args", "extra_link_args"):
args = kwargs.setdefault(args_name, [])
Expand Down

0 comments on commit 6aade2b

Please sign in to comment.