book icon indicating copy to clipboard operation
book copied to clipboard

add profiling scripts

Open QiJune opened this issue 8 years ago • 1 comments

#279 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

QiJune avatar Apr 17 '17 12:04 QiJune

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar Mar 23 '20 12:03 CLAassistant