How can I analyze a file created with pstats.dump_stats(filename) off line?

北战南征 提交于 2020-01-01 07:59:06
问题 I have essentially done the following: import cProfile, pstats, StringIO pr = cProfile.Profile() pr.enable() # ... my code did something ... pr.disable() s = StringIO.StringIO() sortby = 'cumulative' ps = pstats.Stats(pr, stream=s).sort_stats(sortby) ps.dump_stats('stats.dmp') # dump the stats to a file named stats.dmp So now i have the file named 'stats.dmp' stored offline. How can i use pstats to analyze this file for human consumption? Thanks in advance. 回答1: Here's what i found out and