Open 6nc0r6-1mp6r0 opened 1 month ago
you have 2 options that require you to modify the code, and 1 that doesnt:
you can do what you were doing before, just create new wrapped function called_func_wrapped = lp(called_func)
and use that insead z = called_func_wrapped (x)
you can use decorators instead of returning a wrapped function
from line_profiler import LineProfiler
import numpy as np
lp = LineProfiler()
m = 2
@lp
def main():
n = 3
@lp
def called_func(x):
y = x**m
z = x + y + n
return z
for i in range(10):
x = np.random.rand()
z = called_func(x)
print(z)
main()
lp.print_stats()
In my code, I have numerous inner functions which, for various reasons, I would like to leave as inner functions if at all possible. However,
line_profiler
does not appear to profile these functions by default. For example, the following codereturns
Is it possible to modify the code above so that
called_func
is also profiled in a second block of output (while leaving it as an inner function)? A command-line approach would be fine if that would be better in some respect than the above in-code approach.Several notes. I am working on Windows 10. So far, I have made several attempts to include a line like
lp.add_function(main.called_func)
and have tried to incorporate ideas from this Medium article and this Stack Overflow post without success. I also saw the comment below on the main GitHub page, but could not figure out how to implement it.Any help would be appreciated.