Created by: QiJune
#279 (closed)
Python provides cProfile module to help us profiling python codes. A common usage can be:
python -m cProfile -o train.prof train.py
Since train.prof is a binary file, we have to transfer it into readable text or graph. The Pstats module’s Stats class has a variety of methods for manipulating and printing the data saved into a profile results file. Following is the usage:
import pstats
p = pstats.Stats('train.prof)
p.strip_dirs().sort_stats("time").print_stats(20)
p.strip_dirs().sort_stats("cumtime").print_stats(20)
And gprof2dot is a Python script to convert the output from profilers into a dot graph. Following is the usage:
gprof2dot -f pstats train.prof | dot -Tpng -o train.prof.png