I'm trying to start and stop the line profiling of a Python function multiple times during runtime. Therefore I'd like to reset the already collected stats when starting a new profiling. Is there a way to do that?
In lack of an obvious solution I also tried replacing the line profiler lp
with a fresh instance:
#!/usr/bin/env python3
from line_profiler import LineProfiler
lp = LineProfiler()
@lp
def count():
return sum(range(1_000_000))
count()
lp.print_stats()
# reset line profiler
new_lp = LineProfiler()
for f in lp.functions:
new_lp(f)
lp = new_lp
count()
lp.print_stats()
But somehow the new stats are empty, possibly because the function count()
can't be wrapped twice?