debuggingtestingand profiling function calls ( primitive callsin cpu secs ncalls tottime percall cumtime percall filename:lineno(function : ( : ( : (function_a : (function_b : ( : (function_c : (in cprofile terminologya primitive call is nonrecursive function call using the cprofile module in this way can be useful for identifying areas that are worth investigating further herefor examplewe can clearly see that function_b(takes long time but how do we drill down into the detailswe could instrument the program by replacing calls to function_b(with cprofile run("function_b()"or we could save the complete profile data and analyze it using the pstats module to save the profile we must modify our command line slightlypython - cprofile - profiledatafile programormodule py we can then analyze the profile datafor exampleby starting idleimporting the pstats moduleand giving it the saved profiledatafileor by using pstats interactively at the console here' very short example console session that has been tidied up slightly to fit on the pageand with our input shown in boldpython - cprofile - profile dat mymodule py python - pstats welcome to the profile statistics browser read profile dat profile datcallers function_b random listing order was used list reduced from to due to restriction function was called by ncalls tottime cumtime : (function_b< : (profile datcallees function_b random listing order was used list reduced from to due to restriction function called ncalls tottime cumtime : (function_b- built-in method bisect_left built-in method len built-in method sorted profile datquit