import time
import cProfile as profile


class Foo(object):

    def bar(self):
        profile.runctx('self.baz()', globals(), locals())

def baz(self):
    time.sleep(1)
print('slept')
time.sleep(2)
foo = Foo()
foo.bar()
profiling a method of a class in Python using cProfile?