From 8a9deccd3cbd91ab90524b9554fc66c7a1b937ac Mon Sep 17 00:00:00 2001 From: XiaoFan <1066580119@qq.com> Date: Tue, 21 Nov 2023 22:42:25 +0800 Subject: [PATCH] fix:update --- .../pyinstrument.md" | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 "source/_posts/\346\265\213\350\257\225\345\274\200\345\217\221/pyinstrument.md" diff --git "a/source/_posts/\346\265\213\350\257\225\345\274\200\345\217\221/pyinstrument.md" "b/source/_posts/\346\265\213\350\257\225\345\274\200\345\217\221/pyinstrument.md" new file mode 100644 index 0000000..2c349c6 --- /dev/null +++ "b/source/_posts/\346\265\213\350\257\225\345\274\200\345\217\221/pyinstrument.md" @@ -0,0 +1,34 @@ +--- +title: pyinstrument +date: 2023-11-21 22:41:31 +tags: + - DEBUG + - python + - 工具 +categories: 测试开发 +--- +>https://pyinstrument.readthedocs.io/en/latest/guide.html + +这是一个python性能分析工具. + +大致有两种使用方式: +1. 命令行直接运行脚本 +``` +pyinstrument script.py +``` +2. 嵌入到项目中 +- 简单包裹代码块 +```python +from pyinstrument import Profiler + +profiler = Profiler() +profiler.start() + +# code you want to profile + +profiler.stop() + +profiler.print() + +``` +- 作为中间件嵌入到`django`、`flask`、`fastapi`、`falcon`中使用