Python pprofile

From wikinotes

This is the sexiest python profiler that I've seen to date. It performs line-by-line profiling, both from the SHELL, and it is easily restricted to areas of interest within the script. The output is all-terminal, and gives some additional specifics that were lacking in profile/cProfile.

pprofile is best used after first identifying a function with cprofile rather than filtering the results with grep, save output to a file. the strength of pprofile is getting per-line statistics. That is where you will find answers


python2 -m pprofile lute.py --out tmp
cat tmp | grep -e "[1-9]\+\.[0-9].%"		## only include results 1% and above
       OR 
cat tmp | grep -v "0.00%"						## exclude all results with negligible percentages

while profile Method

import pprofile

profiler = pprofile.Profile()
def someHotSpotCallable():
    with profiler:
        # Some hot-spot code

start-stop method

import pprofile
profiler = pprofile.Profile()

profiler.enable()
profiler.disable()
profiler.print_stats()