Skip to content

Instantly share code, notes, and snippets.

@mirekfranc
Last active August 29, 2015 14:20
Show Gist options
  • Save mirekfranc/69f167936790882217e5 to your computer and use it in GitHub Desktop.
Save mirekfranc/69f167936790882217e5 to your computer and use it in GitHub Desktop.
How to profile and debug python script
##################################################
# profiler:
# https://docs.python.org/2/library/profile.html
# python -mcProfile -o profiler.out ./something.py
### profile.py ###
import pstats
p = pstats.Stats('profiler.out')
p.sort_stats('cumtime').print_stats(20)
p.sort_stats('time').print_stats(20)
p.print_stats ('lambda|filter')
# python profile.py
##################################################
# debugger:
# https://docs.python.org/2/library/pdb.html
# python -mpdb ./something.py
# help
# b main
# n
# pp options
# bt
# c
##################################################
# code coverage:
# python -mtrace --count ./something.py
# coverage in something.cover
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment