Increasing the depth of cProfiler in Python to report more functions?
Question: I'm trying to profile a function that calls other functions. I call the
profiler as follows:

    
    
    from mymodule import foo
    def start():
       # ...
       foo()
    
    import cProfile as profile
    profile.run('start()', output_file)
    p = pstats.Stats(output_file)
    print "name: "
    print p.sort_stats('name')
    print "all stats: "
    p.print_stats()
    print "cumulative (top 10): "
    p.sort_stats('cumulative').print_stats(10)
    

I find that the profiler says all the time was spend in function "foo()" of
mymodule, instead of brekaing it down into the subfunctions foo() calls, which
is what I want to see. How can I make the profiler report the performance of
these functions?

thanks.


Answer: You need `p.print_callees()` to get hierarchical breakdown of method calls.
The output is quite self explanatory: On the left column you can find your
function of interest e.g.`foo()`, then going to the right side column shows
all called sub-functions and their scoped total and cumulative times.
Breakdowns for these sub-calls are also included etc.

