Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable cprofile on Cython code #6

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion 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 All @@ -166,7 +172,7 @@ def setup(original_setup_file: str, cythonize: bool = True, **kwargs):
except ImportError:
pass
else:
cython_ext_modules = Build.cythonize(cython_ext_modules, force=True)
cython_ext_modules = Build.cythonize(cython_ext_modules, force=True, compiler_directives={'profile': profile_cython})

ext_modules = kwargs.setdefault("ext_modules", [])
ext_modules.extend(cython_ext_modules)
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
Loading