calculate how many times of the functions or variables be invoked
<p>I want to get the invoked times of each function or variable from existing codes which is writing in python.</p>

<p>What i thought is override the object's <strong>getattribute</strong> function, such as below:</p>

<pre><code>acc = {}

class object(object):
    def __getattribute__(self, p):
        acc.update({str(self) + p: acc.get(str(self) + p, 0) + 1})
        return supe(object, self).__getattribute__(p)

class A(object):
    def a(self):
        pass

class B(A):
    def b(self):
        pass

def main():
    a = A()
    a.a()
    b = B()
    b.b()
    b.a = 'a'
    b.a

    print acc
if __name__ == '__main__':
    main()
</code></pre>

<p>But, it only can calculate functions and variable in object, how can i calculate the normal functions or variable, such as:</p>

<pre><code>def fun1():
    pass
fun1()
fun1()
</code></pre>

<p>I want to get the result as 2, is there any tool or method to do it?</p>

<p>I am sorry my pool english, What i really need is the invoked times not the run time.
such as above, we said, fun1() is invoked two times.</p>
