Skip to content

Instantly share code, notes, and snippets.

@taoliu
Created April 12, 2012 16:14
Show Gist options
  • Save taoliu/2368738 to your computer and use it in GitHub Desktop.
Save taoliu/2368738 to your computer and use it in GitHub Desktop.
print stats of Python profile
#!/usr/bin/env python
# Time-stamp: <2012-04-12 12:12:53 Tao Liu>
import sys
import pstats
# ------------------------------------
# Main function
# ------------------------------------
def main():
if len(sys.argv) < 3:
sys.stderr.write("need 2 paras: %s <prof file> <time|calls|cumulative|...>\n" % sys.argv[0])
sys.exit(1)
p = pstats.Stats(sys.argv[1])
sort_term = sys.argv[2]
p.strip_dirs().sort_stats(sort_term).print_stats(20)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment