title: Can Decorator + Reflection selectively create object trees representing individual function-call chain?
body: <p>Given:</p>
  
  <pre><code>G = []
  
  @Track
  def f(x):
    a = g(x)
    b = h(x + 2)
    return a + b
  
  def g(x)
    for n in range(2):
      i(x + n)
  
  @Track
  def h(x):
    return j(x) + 9
  
  @Track
  def i(x):
    return x + 10
  
  @Track
  def j(x):
    return 0
  </code></pre>
  
  <p>Is it possible to write &amp; apply a decorator Track to f, h, i, j that will on each invocation of f, h, i, and j:</p>
  
  <ul>
  <li>instantiate a 'Call' object containing the function name 'f','h','i', and the arg- and return-values</li>
  <li>use reflection to search for the nearest similarly decorated function that called it (directly or indirectly) i.e. it would pass over calls to g(), since that is not @Tracked.</li>
  <li>appends the above 'Call' object to a 'children' list on the caller's 'Call' object, or to the global list G if there was no suitable caller found</li>
  </ul>
  
  <p>For the code:</p>
  
  <pre><code>f(3)
  j(3)
  </code></pre>
  
  <p>this should create the following connected object tree:</p>
  
  <pre><code>G
   -- Call(name='f',args=..., return=...)
      -- Call(name='i',args=..., return=...)
      -- Call(name='i',args=..., return=...)
      -- Call(name='i',args=..., return=...)
      -- Call(name='h',args=..., return=...)
        -- Call(name='j', args=..., return=...)
   -- Call(name='j', args=..., return=...)
  </code></pre>
  
  <p>I am stuck on the reflection / traverse the run-time stack frames part.</p>
  
  <p>Thanks!</p>