Skip to content
This repository has been archived by the owner on Jun 9, 2020. It is now read-only.

kernprof.py -m package #3

Closed
anntzer opened this issue Sep 22, 2014 · 9 comments
Closed

kernprof.py -m package #3

anntzer opened this issue Sep 22, 2014 · 9 comments
Assignees

Comments

@anntzer
Copy link

anntzer commented Sep 22, 2014

Support for running package.__main__ via kernprof.py -m package would be appreciated, thanks.

@embray
Copy link

embray commented Nov 30, 2015

I think this would be really useful to have, but of course it's not entirely trivial. My main question would be how to handle profiling imports within the module. Should each imported module be profiled as well--or should a module only be profiled if it's also been tagged for profiling (a la LineProfiler.add_function, but for a module)?

@anntzer
Copy link
Author

anntzer commented Nov 30, 2015

My optimal command-line experience would be something like

$ kernprof --profile-funcs=qualified.function.name,... --profile-imports=qualified.module.name,... \
    [script.py | -c "commands" | -m module]

Then there's no need to edit the file for profiling, you can just save a tiny script for that.

@rkern
Copy link
Owner

rkern commented Nov 30, 2015

I interpret the request as simply enabling -m package for locating the entrypoint of the script and properly initializing it, not as actually profiling everything in package/__main__.py. One would still use @profile or whatever to mark the methods that are to be profiled.

@embray
Copy link

embray commented Nov 30, 2015

Ah, I interpreted this maybe as something more like #26, that is, profiling module-level code that is not in a function. I have some ideas for making that work if you'd be interested in a patch.

@anntzer
Copy link
Author

anntzer commented Nov 30, 2015

(I was also initially talking about @rkern's interpretation -- my next comment is further down on my wishlist.)

@Lan1991Xu
Copy link

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?

@rkern
Copy link
Owner

rkern commented Jan 13, 2017

@Lan1991Xu This issue is unrelated to your problem. Please open a new issue with more information. Please create a complete, minimal example that we can run that demonstrates the problem. Thanks.

@Lan1991Xu
Copy link

OK,thanks for your reply

@mattkatz
Copy link

Really like line_profiler - it's helped me immensely.
I also really like anntzer's idea of a --profile-funcs option. I'm profiling repeatedly as I develop when I have to optimize a call. I set up entr to automatically rerun line_profile one every save.

However, if i also want other windows to run the same code, but not under profile, I have to put in a fake profile decorator that everything else uses.

A very helpful workflow would be to pass the profiling functions on the command line so they can be wrapped then before being run - but leave the pure code alone so that other timing and unit testing scripts can continue to work.

@caethan caethan closed this as completed Feb 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants