Python Hotshot Profiler
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.
| <!DOCTYPE html> | |
| <html></html> |
| 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() |