Simple python flame graph generator
Project description
PyInferno
Python package that renders pyinstrument profiles as flamegraphs, using the inferno rust crate.
Installation
Install from PyPi:
pip install pyinferno
Usage
Context manager
To profile a specific piece of code, you can use the pyinstrument Profiler class, then render the result using pyinferno's InfernoRenderer
:
from pyinstrument.profiler import Profiler
from pyinferno import InfernoRenderer
import time
def slow():
time.sleep(0.5)
with Profiler() as profiler:
slow()
output = profiler.output(InfernoRenderer(title="slow"))
with open("flamegraph.svg", "w+") as f:
f.write(output)
For convenience, the same result can be achieved using the InfernoProfiler
context manager:
from pyinferno import InfernoProfiler
import time
def slow():
time.sleep(0.5)
with InfernoProfiler(file="flamegraph.svg", auto_open=True, title="slow"):
slow()
Command-line
To profile a Python script, you can pass pyinferno.Renderer
as the renderer to the pyinstrument
CLI:
pyinstrument -r pyinferno.Renderer -o flamegraph.svg slow.py
For convenience, pyinferno
includes its own script which wraps the pyinstrument
CLI:
pyinferno slow.py
If no output file is specified, the flamegraph will be written to a temporary file and automatically opened using python's webbrowser
module. To save the flamegraph to a file, pass the -o
option:
pyinferno -o flamegraph.svg slow.py
To profile a python module, pass the -m
argument:
pyinferno -m pytest -k slow_test
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for pyinferno-0.2.3-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4059500da4154ca38a6e428a988c4dcfb2fa619c62199f9b68386fed3e9b16a9 |
|
MD5 | a879a99a959295089320ab0c9fb66694 |
|
BLAKE2b-256 | 4a7d4a985ca9c637e01b6a660b64582db5fc096d0257f5830f2751817aa324e4 |
Hashes for pyinferno-0.2.3-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7c5045d98b1325eba990cf4bc57e998de8ba0b0a75937eac1bc726d50994866 |
|
MD5 | 78098b23aab8f2e3a69597929ac4722f |
|
BLAKE2b-256 | a7564500a6e3bd06dab210cd6573f520145a657ff913b707fcf530e15cc3f8f2 |
Hashes for pyinferno-0.2.3-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8534a5fa32768b625bd7844147669440ae26d97907548850c575cc33e620e8e |
|
MD5 | 39e0c5a8da2f84436fae55d5a1b0c0db |
|
BLAKE2b-256 | b7b2dfcd274556611b94361042a7423887a494f8d55764f979416255c7cdb1ec |
Hashes for pyinferno-0.2.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb25f4815569deee37de60047f47cb7420bbbf773ce6fe67683d3f3462464beb |
|
MD5 | b5395fb97dd29f1b32bbbc52f0552c60 |
|
BLAKE2b-256 | 757f6873ac2b752e134396ef39a23720bb4c80225cb12f612b0703c86c27e2f6 |
Hashes for pyinferno-0.2.3-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0184cd2d7b242779e48567ebcf98a5bce7d1c41e7cbd98ca2203e4e6ff9e3426 |
|
MD5 | 7b50ea58097ae8274757af8b6c95bded |
|
BLAKE2b-256 | 20f223dcde83f4f41393fa61b53eea25e779c04befc12fdad20c96872bb316c4 |
Hashes for pyinferno-0.2.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aaaae372e32060548ff35b1ea4aaabe59b990d2229684f6d57777d5768566a5b |
|
MD5 | 937e8834ab64fa1623aec5c1f9cb8dfc |
|
BLAKE2b-256 | 9c06e084985a024e5aec604bb12f8c30b21979ccdd27aafb59292f46ad4fc259 |
Hashes for pyinferno-0.2.3-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d79d127383c67eac550b1f5b819038013f3ffdef81333ba7e29cce7b351919f7 |
|
MD5 | 9cf5f2ea83fea5a7d384b0d0ff52335c |
|
BLAKE2b-256 | 506bdd4cc362b10c5bca6c82c549af278ce4bc256a499f8183c0dc9b225c7f50 |
Hashes for pyinferno-0.2.3-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84a11427f237fffe857910b49405589807d5704203933ae44fa04034dfe0cb7b |
|
MD5 | 94465b3719f28c6938606bcdcb37d71a |
|
BLAKE2b-256 | b8da6874799c8aaafa7e552db28daa8d165f90a6c3a2892e85248cfbea1dabfc |
Hashes for pyinferno-0.2.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8602e724aa93cdb07037cfda8de43163560c513a504f011f8b0539b4df744eae |
|
MD5 | e5a7e256904e2bb84d365cdfb67d789f |
|
BLAKE2b-256 | 236938ebcf4ced4259edcbe619b66a5ae6035da8341d39c6d8fb8f930dadc23c |
Hashes for pyinferno-0.2.3-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ce89b909cb7a8ef7afab90f31dffd45bce15af2e4f306358c1d1d25d628f336 |
|
MD5 | 42f7626eac6026f17c265185068b9313 |
|
BLAKE2b-256 | ec8e55164e8d7681fe3c8b0be2fe3166000353db24c8c15da5c570888ac71bc1 |
Hashes for pyinferno-0.2.3-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0c7c8b788750d377f097d7e78057c0ea689982b3869b9cf230dfdb05e8b624e |
|
MD5 | 7644a98a4e7382b9ed94a87e416c8d7b |
|
BLAKE2b-256 | cbc65b2e6417fcbb29a16979416c367965dc6a7e81932f0eefe0d8662a52be42 |
Hashes for pyinferno-0.2.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a484fb09ccdff163b2763296ef510816715f8e66f545ed1fadd46dc6ddf1e544 |
|
MD5 | 882093c18365aa0e4e9a2588168cca37 |
|
BLAKE2b-256 | 1f4a96e1229096bdbd473e8ddf126e3b06bb11633e512331bd793350569bbdc4 |
Hashes for pyinferno-0.2.3-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8488d43bf2dc46c43eded962e142c0827fc615afaf7276d61919cb0fc1e5db1 |
|
MD5 | 9b1f8113a41b19c82827dc5a58a3911a |
|
BLAKE2b-256 | d9323aeafbba2f9c9a0c1cb0dcba99d6bb63e6ae913b2c1e0c484d9fa6706aeb |
Hashes for pyinferno-0.2.3-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89b451ac990c1b1877118c58874ca6dd39d40ad2895e9e5cc3d92dca8c5dbc3d |
|
MD5 | b5030482c358cafc8f652cc0f2145e02 |
|
BLAKE2b-256 | edef559809b83485ccc45e6778965330b8aa962d48b1ce2c24e105e882b4b061 |
Hashes for pyinferno-0.2.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e71a822af411dc2c6a1bc8e04fd756fbe36afd5ac7ac49015049dd5ed6e2bd76 |
|
MD5 | 2cc94b2f84196fc3a689df034c305dfd |
|
BLAKE2b-256 | 135f62cd18dcf42e1736cc7534573a6dc42bcd5573e11a06b114f38640fd3a29 |
Hashes for pyinferno-0.2.3-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a92d41f1854452041a701067ad92cdcd961fcce7d8907173e943b9ee824baf56 |
|
MD5 | 6e72af34c89e67c35771c36d3b4e6d4b |
|
BLAKE2b-256 | de5ae7710e6e8ae1bfa68de270a5bbe13eee7e91f33abed37ff64204bce4d013 |