PyMOTW: profile, cProfile, pstats

The profile and cProfile modules provide APIs for collecting and analyzing statistics about how Python source consumes processor resources.

Read more at pymotw.com: profile