Files
Python-Profiler-Visualizer/README.md
2026-09-12 14:19:56 +08:00

67 lines
2.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Python Profiler Visualizer
粘贴一段 Python 代码,一键运行,立刻看到每个函数各花多少时间。桌面应用,不联网,不传你的代码,不配环境。
## 下载
到 [Releases](../../releases) 下载 `Python Profiler Visualizer Setup x.y.z.exe`,双击安装。首次启动会扫描 Python找不到可点应用里的「打开终端」按钮按系统预填命令装即可。
## 从源码运行
需 Node 20+ 和 Python 3.9+`npm install``npm run dev`
## 用法
1. 左侧编辑器贴代码(或点工具栏「加载示例」)
2. `Ctrl/Cmd + Enter` 运行
3. 右侧看摘要、热点表、6 种耗时可视化
4. 点热点表任意函数跳到对应行;标准库/第三方包会新开标签页展示源文件
5. 工具栏切换「剖析范围」:仅用户代码 / 含库函数(切换后旧结果会标为陈旧)
`← / →` 在柱状图、火焰图、矩形树图、旭日图、累计柱状图、模块热力图之间切换。
### 快捷键
| 按键 | 作用 |
| --- | --- |
| `Ctrl/Cmd + Enter` | 运行 / 取消 |
| `Esc` | 取消运行 / 关设置面板 |
| `← / →` | 切标签页或图表视图 |
| `Home` / `End` | 跳到首/尾 |
| `Delete` / `Ctrl/Cmd + W` | 关闭当前标签页 |
## 耗时数字说明
cProfile 会拖慢代码 1.5~3 倍。引擎启动时跑同一段 tight-loop 测出裸跑与仪器化倍率,把你的 instrumented 时间除回去,摘要数字接近真实耗时,并标「已校准」。
提醒:
- 单次数字有抖动,比较时建议跑多次
-`plt.show()` / `input()` / `cv2.waitKey()` 等阻塞事件循环的等待时UI 会提示「含交互等待」
## 限制
- 仅单文件自包含脚本,不支持命令行参数或多文件项目
- 无自动超时(取消靠按钮或 `Esc`),长时间任务跑到自然结束
- 不替代 `py-spy` / `scalene`
## 给开发者
Electron 31 + React 18 + Vite 5 + TypeScript 5Python 引擎用 cProfile + 标准库。
```bash
npm run dev # 开发
npm run build # 打包
npm run release # 出 Windows 安装包
npm test # 单元测试
npm run test:e2e # E2E
python -m pytest engine/tests -v # Python 引擎测试
```
架构:`src/main/` 主进程、`src/renderer/` React 前端、`engine/` Python 引擎。跨语言契约 `AnalysisResult`Python 侧 `engine/schema.py` 是事实源TypeScript 侧 `src/shared/analysis.ts` 对齐,契约测试 `engine/tests/test_contract.py` 锁版本。
`npm run release` 产物在 `release/Python Profiler Visualizer Setup x.y.z.exe`。未签名Windows SmartScreen 点「更多信息 → 仍要运行」即可。
## License
MIT