Skip to content

Instantly share code, notes, and snippets.

@maurodoglio
Created September 13, 2013 10:07
Show Gist options
  • Save maurodoglio/6548820 to your computer and use it in GitHub Desktop.
Save maurodoglio/6548820 to your computer and use it in GitHub Desktop.
This is the list of commands I used to read a list of files containing profiling data. It was run inside a ipython shell
import pstats
# in the ipython shell this returns a list
# containing the output of the shell command ls
# I generated many profile files, one per log parsed.
# all the file names were prefixed with parse_log
profiles = !ls parse_log*
# read the first file in the list
stats = pstats.Stats(profiles.pop())
# you can add more than one profile to the stats
# this is totally optional
for i in profiles:
stats.add(i)
# this strips the directory information from the function name
stats.strip_dirs()
# sort by time
# available sort fields can be found here http://hg.python.org/cpython/file/2.7/Lib/pstats.py#l173
stats.sort_stats('time')
stats.print_stats()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment