I am trying to use the python line_profiler by Robert Kern for some object oriented code and I am having trouble getting the desired output. My object is of the following form:
class myObj:
def __init__(self,inputs):
#process inputs
@profile
def run(self):
for t in range(self.timesteps):
self.update()
@profile
def update(self):
self.A += self.dA()
self.B += self.dB()
@profile
def dA(self):
#process data
@profile
def dB(self):
#process data
I want to do line profiling for each of the methods with the @profile
decorator, but when I run the profiler in an iPython environment using the command:
test = myObj()
%lprun -f test.run test.run()
I get the following:
Timer unit: 1e-06 s
Total time: 0 s
File: /Users/-----/anaconda3/lib/python3.7/site-packages/line_profiler.py
Function: wrapper at line 111
Line # Hits Time Per Hit % Time Line Contents
==============================================================
111 @functools.wraps(func)
112 def wrapper(*args, **kwds):
113 self.enable_by_count()
114 try:
115 result = func(*args, **kwds)
116 finally:
117 self.disable_by_count()
118 return result
I have tried it without the @profile
decorators and it just tells me that all of the time is spent in the update
method, which is pretty clear.