As of 2023, is there any way to line profile Cython at all?

Question:

Something has substantially changed with the way that line profiling Cython works, such that previous answers no longer work. I am not sure if something subtle has changed, or if it is simply totally broken.

For instance, here is a very highly upvoted question about this from about 8 years ago.

The notebook in there no longer seems to work, even with the updates referenced in the post. For instance, here is a new version of the notebook incorporating the updates suggested in the original post: https://nbviewer.org/gist/battaglia01/f138f6b85235a530f7f62f5af5a002f0?flush_cache=true

The output of line_profiler to profiling that Cython function is simply

Timer unit: 1e-09 s

with no line-by-line infomration at all.

I’m making a new question about this because other comments I’ve seen on the site all seem to reference these older answers, and they all seem to be broken. If anyone even has the beginnings of a starting point it would be much appreciated – either for the Jupyter notebook, or with something built using cythonize. My notes on what I’ve tried at least on the Jupyter side are in that notebook.

Is there any way to get this to work?

Asked By: Mike Battaglia

||

Answers:

The current status is: line_profiler v4 and Cython don’t get on (for reasons that haven’t yet been diagnosed but could be on either end). The line_profiler tests run as part of Cython’s CI test-suite have line_profiler pinned to <4. It obviously isn’t the long-term plan to leave this version pin, but if you need to it work now then do the same!

The most recent run on the master branch as today used line_profiler v3.5.1 and this passed.

Relevant issue: https://github.com/cython/cython/issues/5141

Answered By: DavidW