no support for profiling code at top level of script/module
I write lots of exploratory data processing scripts with a lot of code at the top level outside any function, and I desperately want to profile this code with line_profiler. I came up with a sort of a monkey patch solution to allow profiling top-level code which I've put into a gist here:
https://gist.github.com/jmuhlich/b6e349c5d80ec3897a77
I would be willing to work up a pull request if it would be considered.
Oops, just realized this is sort of a duplicate of #3 .
According to this comment it is not a duplicate at all.
Hi, all. I still confused about this situation. I have the main function a in file a.py, and it another function b in b.py. So I add the @profile to b function. But when I run the kernprof -l -v a.py. There is not the detail of b function. Is the same problem with this issue? Is it solved?
Unrelated.
@jmuhlich Nice hack, thanks. Worked for me. I feel like I proposed adding a similar feature to line_profiler ages ago, but never ended up going anywhere with it; I forget what happened there.
Another use case for this is debugging import times of modules in large packages (see: sagemath). Understanding what causes slow import times can be non-trivial in some such packages.