title: tracemalloc in python 3.4
body: <p>I am trying to use Python's <code>tracemalloc</code> module and copied the <code>display_top</code> function from the <a href="https://docs.python.org/3/library/tracemalloc.html#tracemalloc.Statistic.traceback" rel="nofollow noreferrer">API documentation</a>. The output can be seen below, which is not super helpful:</p>
  
  <pre><code> #1: collections/__init__.py:366: 85.6 KiB
    exec(class_definition, namespace)
  
   #2: python3.4/ast.py:55: 83.9 KiB
     return tuple(map(_convert,
  </code></pre>
  
  <p>What I really want to see is where in my application these functions are invoked from. So, I'd really like to see the oldest frame as opposed to the most recent frame. Is this even the correct approach though?</p>
  
  <p>I have tried <code>tracemalloc.start(25)</code> so that it stores up to 25 frames. 
  But if I check <code>len(stat.traceback)</code>, it is 1! So, I can only print the most recent frame, which is not so useful.</p>
  
  <pre><code>def display_top(self, snapshot, group_by="lineno",  limit=_NUM_MEMORY_BLOCKS):
      snapshot = snapshot.filter_traces((
          tracemalloc.Filter(False, "&lt;frozen importlib._bootstrap&gt;"),
          tracemalloc.Filter(False, "&lt;unknown&gt;"),
      ))
      top_stats = snapshot.statistics(group_by)
  
      for index, stat in enumerate(top_stats[:limit], 1):
          # Ideally, I want to print all frames in traceback. 
          # But length of the traceback is somehow always 1 !!
          frame = stat.traceback[0] 
          # replace "/path/to/module/file.py" with "module/file.py"
          filename = os.sep.join(frame.filename.split(os.sep)[-2:])
          log.debug("#%s: %s:%s: %.1f KiB", index, filename, frame.lineno, stat.size / 1024)
          line = linecache.getline(frame.filename, frame.lineno).strip()
          if line:
              log.debug("    %s", line)
  
      other = top_stats[limit:]
      if other:
          size = sum(stat.size for stat in other)
          log.debug("%s other: %.1f KiB", len(other), size / 1024)
      total = sum(stat.size for stat in top_stats)
      log.debug("Total allocated size: %.1f KiB", total / 1024)
  </code></pre>