py-perf-analyzer
Installation
SKILL.md
Perf Profiler
Python 性能分析工具,集成 cProfile、line_profiler 和 tracemalloc,一键定位 CPU 和内存瓶颈。
功能
- CPU 分析 (cProfile):统计每个函数的调用次数、累计耗时、自身耗时,定位热点函数
- 内存分析 (tracemalloc):追踪内存分配热点、峰值内存、内存增长来源
- 逐行分析 (line_profiler):精确到每一行代码的耗时和命中次数,适合深入优化
- 组合分析:
all模式一次执行同时收集 CPU + 内存数据,减少重复运行开销
依赖
| 依赖 | 类型 | 用途 |
|---|---|---|
| Python 3.7+ | 必须 | 运行环境 |
| cProfile / pstats | 内置 | CPU 性能分析 |
| tracemalloc | 内置 | 内存追踪 |
| line_profiler | 可选 | 逐行分析(pip install line_profiler) |