vprof is a Python package providing rich and interactive visualizations for various Python program characteristics such as running time and memory usage. It supports Python 3.10+ and distributed under BSD license.
All contributions are highly encouraged. Feel free to open an issue or send a pull request.
Dependencies to build vprof from source code:
- Python 3.10+
uvnpm
npm is required to build vprof from sources only.
All Python and npm module dependencies are listed in pyproject.toml and
package.json.
vprof can be installed from PyPI
uv tool install vprof
# or
pip install vprofTo build vprof from sources, clone this repository and execute
uv sync && npm install && npm run build && uv buildTo install just vprof dependencies, run
uv sync && npm installvprof -c <config> <src><config> is a combination of supported modes:
c- CPU flame graph⚠️ Not available for Windows #62
Shows CPU flame graph for <src>.
p- profiler
Runs built-in Python profiler on <src> and displays results.
m- memory graph
Shows objects that are tracked by CPython GC and left in memory after code
execution. Also shows process memory usage after execution of each line of <src>.
h- code heatmap
Displays all executed code of <src> with line run times and execution counts.
<src> can be Python source file (e.g. testscript.py) or path to package
(e.g. myproject/test_package).
To run scripts with arguments use double quotes
vprof -c cmh "testscript.py --foo --bar"Modes can be combined
vprof -c cm testscript.pyvprof can also profile functions. In order to do this,
launch vprof in remote mode:
vprof -rvprof will open new tab in default web browser and then wait for stats.
To profile a function run
from vprof import runner
def foo(arg1, arg2):
...
runner.run(foo, 'cmhp', args=(arg1, arg2), host='localhost', port=8000)where cmhp is profiling mode, host and port are hostname and port of
vprof server launched in remote mode. Obtained stats will be rendered in new
tab of default web browser, opened by vprof -r command.
vprof can save profile stats to file and render visualizations from
previously saved file.
vprof -c cmh src.py --output-file profile.jsonwrites profile to file and
vprof --input-file profile.jsonrenders visualizations from previously saved file.
Check vprof -h for full list of supported parameters.
To show UI help, click the ? button in the top-right corner when visualizations are displayed.
Also you can check examples directory for more profiling examples.
uv run python -m vprof.tests unit && npm test && uv run python -m vprof.tests e2euv run pylint vprof && uv run mypy vprof && npm run lint && npm run typecheckBSD
