0
안녕하세요, 아래 주어진대로 python 스크립트를 프로파일 링하는 명령 줄 방법의 사용법을 알고 있습니다. cProfile.Profile()의 출력을 Python 스크립트의 * .prof 파일에 저장하는 방법
python -m cProfile -o program.prof my_program.py
import cProfile, pstats, io
pr = cProfile.Profile()
pr.enable()
# ... do something ...
pr.disable()
s = io.StringIO()
sortby = 'cumulative'
ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
ps.print_stats()
print(s.getvalue())
나는 pr
대신 분석 및 프로파일 링 결과를 인쇄 할 pstats.Stats()
를 사용하는 *.profile
파일 cProfile.Profile()
의 출력을 저장합니다.
그래서 SnakeViz 또는 유사한 유틸리티를 사용하여 통계를 시각적으로 분석하는 데 사용할 수 있습니다.