pyutils / line_profiler

Line-by-line profiling for Python
Other
2.57k stars 118 forks source link

Customizing line_profiler #188

Open jtlz2 opened 1 year ago

jtlz2 commented 1 year ago

I love the module and have been using it for years, for which many thanks.

A StackOverflow question appeared yesterday asking - wait for it - about type checking (32-bit vs 64-bit) for every function call. Here is the Q:

https://stackoverflow.com/questions/74516195/detecting-unexpected-type-conversion-in-python

I suggested line_profiler (or memory_profiler) might be hackable along the lines of https://stackoverflow.com/a/74517678/1021819

Do you have any advice on whether customizing line_profiler in this way would be feasible, and if so how one might go about it?

Thanks again!

Erotemic commented 1 year ago

Because this repo requires each function is manually registered to be profiled, I think this might not be a fit. However, there were discussions about automatically discovering and profiling all functions automatically, which is more aligned with what you need.

See https://github.com/pyutils/line_profiler/issues/21 and https://github.com/pyutils/line_profiler/pull/24 I thought there was another where I discuss using code in xdoctest / mkinit to automatically enumerate items to profile, but I can't find it.

ta946 commented 1 year ago

i dont recommend following whats in issues #21 & #24. they are very hacky and inefficient. I've updated the code to use AST which is alot more reliable. you can follow the changes i made in my fork under autoprofile branch and use it as a stepping stone to get what you want as I don't plan on maintaining my fork and keeping it up to date.

also @Erotemic you were looking for this discussion where you mentioned using xdoctest. And if you have some free time i've responded in there that my autoprofiler is close to completion :)