https://pyinstrument.readthedocs.io/en/latest/guide.html

这是一个 python 性能分析工具.

大致有两种使用方式:

  1. 命令行直接运行脚本
pyinstrument script.py
  1. 嵌入到项目中
  • 简单包裹代码块
from pyinstrument import Profiler
profiler = Profiler()
profiler.start()
# code you want to profile
profiler.stop()
profiler.print()
  • 作为中间件嵌入到 djangoflaskfastapifalcon 中使用