Skip to content

Commit

Permalink
vendor: Add support for CYTHON_TRACE environment variable
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 15, 2024
1 parent 2b6e52c commit 42e46b4
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 42e46b4

Please sign in to comment.