Just a quick script to profile any Python module (filename passed in as a command-line arg; has to have a main()
) using hotshot
. Logs to stdout.
Last active
August 4, 2016 08:01
-
-
Save jebeck/c3295ee4abb7c9f27582 to your computer and use it in GitHub Desktop.
profile a Python module with hotshot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html></html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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