memray python 内存profiler 工具简单试用

memray python 内存profiler 工具,功能还是很强大的,以下是一个简单使用

参考使用

  • 安装
pip install memray
  • 支持的cli
usage: memray [-h] [-v] [-V] {run,flamegraph,table,live,tree,parse,summary,stats,transform,attach,detach} ...
 
Memory profiler for Python applications
 
Run `memray run` to generate a memory profile report, then use a reporter command
such as `memray flamegraph` or `memray table` to convert the results into HTML.
 
Example:
 
    $ python3 -m memray run -o output.bin my_script.py
    $ python3 -m memray flamegraph output.bin
 
positional arguments:
  {run,flamegraph,table,live,tree,parse,summary,stats,transform,attach,detach}
                        Mode of operation
    run                 Run the specified application and track memory usage
    flamegraph          Generate an HTML flame graph for peak memory usage
    table               Generate an HTML table with all records in the peak memory usage
    live                Remotely monitor allocations in a text-based interface
    tree                Generate a tree view in the terminal for peak memory usage
    parse               Debug a results file by parsing and printing each record in it
    summary             Generate a terminal-based summary report of the functions that allocate most memory
    stats               Generate high level stats of the memory usage in the terminal
    transform           Generate reports files in different formats
    attach              Begin tracking allocations in an already-started process
    detach              End the tracking started by a previous ``memray attach`` call
 
options:
  -h, --help            show this help message and exit
  -v, --verbose         Increase verbosity. Option is additive and can be specified up to 3 times
  -V, --version         Displays the current version of Memray
 
Please submit feedback, ideas, and bug reports by filing a new issue at
https://github.com/bloomberg/memray/issues
  • 参考使用
// 生成结果数据
python -m memray run -o output.bin app.py
// 通过火焰图查看数据
python -m memray flamegraph output.bin
  • 效果

说明

memray 与以前介绍的scalene 都是很不错的工具,对于性能分析场景,都值得试用下

参考资料

https://github.com/bloomberg/memray

posted on   荣锋亮  阅读(348)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2023-03-07 snowflake 元数据存储一些参考资料
2023-03-07 dremio 替换kv 服务的一些思路
2022-03-07 dremio 反射加速服务简单说明一

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示