Line Profiler
python script를 한줄 단위로 profiling해줌
아래의 code snippets으로 쉽게 decorator로 구현 가능
cProfile
import cProfile, pstats, io
from pstats import SortKey
pr = cProfile.Profile()
pr.enable()
self.train_run()
pr.disable()
s = io.StringIO()
sortby = SortKey.CUMULATIVE
ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
ps.print_stats() with open('profile.txt', 'w+') as f: f.write(s.getvalue())
print(s.getvalue())
python -m cProfile ../run_service.py > profile_result.txt
https://stackoverflow.com/questions/582336/how-can-you-profile-a-python-script
https://stackoverflow.com/questions/51536411/saving-cprofile-results-to-readable-external-file
'Development > Python' 카테고리의 다른 글
Python Traceback 에러 로그에 표시되는 line이 부정확할 때 (0) | 2023.07.28 |
---|---|
Python Module 실행 (0) | 2022.06.27 |
Python Callback (0) | 2020.08.13 |
Python Subprocess (0) | 2020.08.13 |
Python Audio Processing (0) | 2020.05.02 |
댓글