mcpField
C
code-profiler

code-profiler

github.com/dkyazzentwatwa开发12456 次安装29 周前更新
代码仓库

关于 code-profiler

code-profiler 是用于分析 Python 性能并定位瓶颈的 skill,可测量运行时间和内存用量,并提供逐行分析、调用统计、火焰图及优化前后对比。

主要功能

  1. 01测量函数执行时间
  2. 02逐行性能分析
  3. 03统计调用次数与累计耗时
  4. 04跟踪内存分配
  5. 05生成火焰图
  6. 06比较优化前后表现

适用场景

  1. 01查找 Python 脚本中的慢函数
  2. 02检查内存用量
  3. 03查看函数调用路径
  4. 04验证优化效果

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/dkyazzentwatwa/chatgpt-skills --skill code-profiler

安装后在 Claude Code 中输入/code-profiler确认已加载。

附带文件scripts/code_profiler.pyscripts/requirements.txt

详细介绍

代码性能分析器

分析 Python 代码性能、识别瓶颈,并通过全面的性能分析工具优化执行效率。

用途

性能分析适用于:

  • 识别瓶颈
  • 测量函数执行时间
  • 分析内存使用情况
  • 可视化调用图
  • 验证优化效果

功能

  • 时间分析:测量函数执行时间
  • 逐行分析:分析每行代码
  • 调用统计:统计函数调用次数和累计耗时
  • 内存分析:跟踪内存分配和使用情况
  • 火焰图可视化:可视化分析调用堆栈
  • 对比:比较优化前后的效果

快速入门

from code_profiler import CodeProfiler

# Profile function
profiler = CodeProfiler()
profiler.profile_function(my_function, args=(arg1, arg2))
profiler.print_stats(top=10)

# Profile script
profiler.profile_script('script.py')
profiler.export_report('profile_report.html')

CLI 用法

# Profile Python script
python code_profiler.py script.py

# Profile with line-by-line analysis
python code_profiler.py script.py --line-by-line

# Export HTML report
python code_profiler.py script.py --output report.html

评论

支持 Markdown