title: Line profiling class instantiation in python
body: <p>I have some existing code that I'm trying to profile. I can successfully line profile class methods by adding a <code>@profile</code> decorator using <a href="https://github.com/rkern/line_profiler" rel="nofollow noreferrer">kernprof</a>.</p>
  
  <p>Is there a general way to profile class instantiation? I have a few classes that have a quite complex inheritance structure. When I try to profile their init functions I get something like this:</p>
  
  <pre><code>Line #      Hits         Time  Per Hit   % Time  Line Contents
  ==============================================================
     179                                               def __init__(self, data):
     180         1    8910739.0 8910739.0    100.0          super().__init__(data)
     181         1         10.0      10.0      0.0          self.mortgage_rate = 5.2  # rate in percentage
  </code></pre>
  
  <p>Which is a bit useless, because I don't know what actual parent <code>__init__</code> function (this class has 2 parents, each of which have one or more parents) is being called.</p>
  
  <p>Is there any way to do this better? For example, is there a way to automatically dive into each line, and profile the lines that get called by it (with limited depth)?</p>