mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
commit
d097d4254d
@ -1,42 +0,0 @@
|
||||
[#]: subject: "Bloomberg Open Sources Memray, A Python Memory Profiler"
|
||||
[#]: via: "https://www.opensourceforu.com/2022/04/bloomberg-open-sources-memray-a-python-memory-profiler/"
|
||||
[#]: author: "Laveesh Kocher https://www.opensourceforu.com/author/laveesh-kocher/"
|
||||
[#]: collector: "lkxed"
|
||||
[#]: translator: "geekpi"
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
Bloomberg Open Sources Memray, A Python Memory Profiler
|
||||
======
|
||||
![soft][1]
|
||||
|
||||
Memray is a memory profiler that was developed at Bloomberg and is now open source. It can track memory allocations in Python code, including native extensions and the Python interpreter itself. Memory profiling is a strong tool for understanding how a program utilises memory and, as a result, detecting memory leaks or determining which areas of the program consume the most memory.
|
||||
|
||||
In contrast to sampling memory profilers like py-spy, Memray can track every function call, including calls into C/C++ libraries, and display the call stack in detail. Bloomberg claims that this does not come at the sacrifice of performance, with profiling only slowing down interpreted code by a little amount. However, native code profiling is slower and must be enabled directly.
|
||||
|
||||
Memray may generate a variety of reports based on the acquired memory consumption data, including flame graphs, which are valuable for rapidly and precisely identifying the most common code-paths.
|
||||
|
||||
According to Yury Selivanov, co-founder and CEO of EgdeDB, the tool gives previously unavailable insights into Python applications. Memray can be used to execute and profile a Python application from the command line:
|
||||
|
||||
```python
|
||||
$ python3 -m memray run -o output.bin my_script.py
|
||||
$ python3 -m memray flamegraph output.bin
|
||||
```
|
||||
|
||||
Alternatively, you can use pytest-memray to integrate Memray into your test suite. You can also profile all C/C++ calls with the —native command line option, or analyse memory allocation in real time while a programme is executing with the —live command line option. Memray can be installed with python3 -m pip install memray on a Linux x86/64 system.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.opensourceforu.com/2022/04/bloomberg-open-sources-memray-a-python-memory-profiler/
|
||||
|
||||
作者:[Laveesh Kocher][a]
|
||||
选题:[lkxed][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.opensourceforu.com/author/laveesh-kocher/
|
||||
[b]: https://github.com/lkxed
|
||||
[1]: https://www.opensourceforu.com/wp-content/uploads/2022/04/soft-1-696x363.jpg
|
@ -0,0 +1,42 @@
|
||||
[#]: subject: "Bloomberg Open Sources Memray, A Python Memory Profiler"
|
||||
[#]: via: "https://www.opensourceforu.com/2022/04/bloomberg-open-sources-memray-a-python-memory-profiler/"
|
||||
[#]: author: "Laveesh Kocher https://www.opensourceforu.com/author/laveesh-kocher/"
|
||||
[#]: collector: "lkxed"
|
||||
[#]: translator: "geekpi"
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
彭博社开源 Memray,一个 Python 内存分析器
|
||||
======
|
||||
![soft][1]
|
||||
|
||||
Memray 是一个内存分析器,由彭博社发,现在已经开源。它可以跟踪 Python 代码中的内存分配,包括本地扩展和 Python 解释器本身。内存剖析是了解程序如何利用内存的有力工具,因此可以检测内存泄漏或确定程序中哪些区域消耗的内存最多。
|
||||
|
||||
与 py-spy 等抽样内存剖析器相比,Memray 可以跟踪每个函数调用,包括对 C/C++ 库的调用,并详细显示调用栈。彭博社称,这并不以牺牲性能为代价,剖析只使解释代码的速度变慢一点。然而,原生代码剖析的速度较慢,因此需要直接启用。
|
||||
|
||||
Memray 可以根据获得的内存消耗数据生成各种报告,包括火焰图,这对快速、准确地识别最常见的代码路径很有价值。
|
||||
|
||||
据 EgdeDB 的联合创始人兼 CEO Yury Selivanov 称,该工具提供了以前无法获得的对 Python 应用的洞察力。Memray 可以用来从命令行中执行和分析 Python 应用。
|
||||
|
||||
```python
|
||||
$ python3 -m memray run -o output.bin my_script.py
|
||||
$ python3 -m memray flamegraph output.bin
|
||||
```
|
||||
|
||||
另外,你可以使用 pytest-memray 将 Memray 集成到你的测试套件中。你也可以用 -native 命令行选项对所有的 C/C++ 调用进行剖析,或者用 -live 命令行选项在程序执行过程中实时分析内存分配。Memray 可以在 Linux x86/64 系统上用 python3 -m pip install memray 来安装。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.opensourceforu.com/2022/04/bloomberg-open-sources-memray-a-python-memory-profiler/
|
||||
|
||||
作者:[Laveesh Kocher][a]
|
||||
选题:[lkxed][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.opensourceforu.com/author/laveesh-kocher/
|
||||
[b]: https://github.com/lkxed
|
||||
[1]: https://www.opensourceforu.com/wp-content/uploads/2022/04/soft-1-696x363.jpg
|
Loading…
Reference in New Issue
Block a user