Skip to content

Instantly share code, notes, and snippets.

@czue
Created February 13, 2013 19:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save czue/4947238 to your computer and use it in GitHub Desktop.
Save czue/4947238 to your computer and use it in GitHub Desktop.
profile analysis utilitiy
import hotshot.stats
import sys
DEFAULT_LIMIT = 200
def profile(filename, limit=DEFAULT_LIMIT):
print "loading profile stats for %s" % filename
stats = hotshot.stats.load(filename)
# normal stats
stats.sort_stats('cumulative', 'calls').print_stats(limit)
# stats.strip_dirs() # this fails! bug in python http://bugs.python.org/issue7372
# callers
stats.print_callers(limit)
#stats.strip_dirs().sort_stats('cumulative', 'calls').print_callers(limit)
if __name__ == "__main__":
if len(sys.argv) < 2:
print "please pass in a filename."
sys.exit()
filename = sys.argv[1] if len(sys.argv) > 1 else "myview-20110922T212250.prof"
limit = sys.argv[2] if len(sys.argv) > 2 else DEFAULT_LIMIT
profile(filename, limit)
@snopoke
Copy link

snopoke commented Sep 11, 2014

Modified version to allow analysing aggregated prof files:

#!/usr/bin/python

import hotshot.stats
import pstats
import sys

DEFAULT_LIMIT = 200

def profile(filename, limit=DEFAULT_LIMIT):
    print "loading profile stats for %s" % filename
    if filename.endswith('.agg.prof'):
        stats = pstats.Stats(filename)
    else:
        stats = hotshot.stats.load(filename)
....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment