Skip to content

Instantly share code, notes, and snippets.

@ogroleg
Forked from jebeck/README.md
Created August 4, 2016 08:01
Show Gist options
  • Save ogroleg/3d56643d4924fd436f0f798c768bcd2b to your computer and use it in GitHub Desktop.
Save ogroleg/3d56643d4924fd436f0f798c768bcd2b to your computer and use it in GitHub Desktop.
profile a Python module with hotshot
import hotshot, hotshot.stats
import sys
def main():
module = __import__(sys.argv[1].replace('.py', ''))
prof = hotshot.Profile('example.prof')
prof.runcall(module.main)
prof.close()
stats = hotshot.stats.load('example.prof')
stats.strip_dirs()
stats.sort_stats('time', 'calls')
stats.print_stats()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment