A debugging and profiling tool that can trace and visualize python code execution
Project description
VizTracer
VizTracer is a low-overhead logging/debugging/profiling tool that can trace and visualize your python code execution.
You can take a look at the demo result of multiple example programs.
trace viewer is used to display the stand alone html data.
VizTracer also supports json output that complies with Chrome trace event format, which can be loaded using perfetto
VizTracer generates HTML report for flamegraph using d3-flamegraph
Highlights
- Detailed function entry/exit information on timeline, not just summary of time used
- Super easy to use, no source code change for basic usage, no package dependency
- Optional function filter to ignore functions you are not interested
- Custom events to log and track arbitrary data through time
- Keep latest entries, dump anytime or auto save at exit
- Stand alone HTML report with powerful front-end, or chrome-compatible json
- Works on Linux/MacOS/Windows
Install
The prefered way to install VizTracer is via pip
pip install viztracer
Basic Usage
Command Line
Assume you have a python script to run:
python3 my_script.py arg1 arg2
You can simply use VizTracer by
viztracer my_script arg1 arg2
# OR
python3 -m viztracer my_script.py arg1 arg2
which will generate a result.html
file in the directory you run this command, which you can open with Chrome(use AWSD to navigate/zoom).
You can also generate json
file or gz
file and load it with chrome://tracing/ or perfetto. gz
file is especially helpful when your trace file is large
viztracer -o result.json my_script.py arg1 arg2
viztracer -o result.json.gz my_script.py arg1 arg2
Inline
You can also manually start/stop VizTracer in your script as well.
from viztracer import VizTracer
tracer = VizTracer()
tracer.start()
# Something happens here
tracer.stop()
tracer.save() # also takes output_file as an optional argument
Or, you can do it with with
statement
with VizTracer(output_file="optional.html") as tracer:
# Something happens here
Display Result
By default, VizTracer will generate a stand alone HTML file which you can simply open with Chrome.
However, you can generate json file as well, which complies to the chrome trace event format. You can load the json file on perfetto or chrome://tracing.
When you are dealing with big traces, a stand alone HTML file might be very large and hard to load. You should try to dump a compressed filename.json.gz
file
Advanced Usage
Trace Filter
VizTracer can filter out the data you don't want to reduce overhead and keep info of a longer time period before you dump the log.
Extra Logs without Code Change
VizTracer can log extra information without changing your source code
print()
function- Function Input Arguments
- Garbage Collector Operation
- Function Return Value
- Any Variable/Attribute with RegEx
- Variables in Specified Function
- Raised Exceptions
Add Custom Event
VizTracer supports inserting custom events while the program is running. This works like a print debug, but you can know when this print happens while looking at trace data.
Check more advanced usage for more features
Misc
Multi Thread Support
VizTracer supports python native threading
module without the need to do any modification to your code. Just start VizTracer
before you create threads and it will just work.
Multi Process Support
VizTracer can support multi process with some extra steps. The current structure of VizTracer keeps one single buffer for one process, which means the user will have to produce multiple results from multiple processes and combine them together.
Refer to multi process docs for details
JSON alternative
VizTracer needs to dump the internal data to json format. It is recommended for the users to install orjson
, which is much faster than the builtin json
library. VizTracer will try to import orjson
and fall back to the builtin json
library if orjson
does not exist.
Virtual Debug
You can virtually debug your program with you saved json report. The interface is very similar to pdb
. Even better, you can go back in time
because VizTracer has all the info recorded for you.
vdb <your_json_report>
Refer to the docs for detailed commands
Performance
VizTracer will introduce 2x to 3x overhead in the worst case. The overhead is much better if there are less function calls or if filters are applied correctly.
An example run for test_performance with Python 3.8 / Ubuntu 18.04.4 on Github VM
fib:
0.000678067(1.00)[origin]
0.019880272(29.32)[py] 0.011103901(16.38)[parse] 0.021165599(31.21)[json]
0.001344933(1.98)[c] 0.008181911(12.07)[parse] 0.015789866(23.29)[json]
0.001472846(2.17)[cProfile]
hanoi (6148, 4100):
0.000550255(1.00)[origin]
0.016343521(29.70)[py] 0.007299123(13.26)[parse] 0.016779364(30.49)[json]
0.001062505(1.93)[c] 0.006416136(11.66)[parse] 0.011463236(20.83)[json]
0.001144914(2.08)[cProfile]
qsort (8289, 5377):
0.002817679(1.00)[origin]
0.052747431(18.72)[py] 0.011339725(4.02)[parse] 0.023644345(8.39)[json]
0.004767673(1.69)[c] 0.008735166(3.10)[parse] 0.017173703(6.09)[json]
0.007248019(2.57)[cProfile]
slow_fib (1135, 758):
0.028759652(1.00)[origin]
0.033994071(1.18)[py] 0.001630461(0.06)[parse] 0.003386635(0.12)[json]
0.029481623(1.03)[c] 0.001152415(0.04)[parse] 0.002191417(0.08)[json]
0.028289305(0.98)[cProfile]
Documentation
For full documentation, please see https://viztracer.readthedocs.io/en/stable
Bugs/Requests
Please send bug reports and feature requests through github issue tracker. VizTracer is currently under development now and it's open to any constructive suggestions.
License
Copyright Tian Gao, 2020.
Distributed under the terms of the Apache 2.0 license.
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file viztracer-0.8.3.tar.gz
.
File metadata
- Download URL: viztracer-0.8.3.tar.gz
- Upload date:
- Size: 675.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc0e54a2d87bec18d894eea319e039d1c0d05163ba0701679f6bc022c7059aaa |
|
MD5 | 777b60623aae5a6a9eeae547d482bcd2 |
|
BLAKE2b-256 | b63dda8f28e384597e55d7240785283bf4a1367a6a0612ca66b98ecc693a978d |
File details
Details for the file viztracer-0.8.3-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: viztracer-0.8.3-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 685.1 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9a65155a7250221dfeea317ea5e3cda62509e4d90b99916fecf01e28239dd2b |
|
MD5 | 0f808ca6506b9768d97f51e056165df1 |
|
BLAKE2b-256 | dd1745ff4f37524e77c2f691ea162ca332463dd7072530a286a9c7a768040c4e |
File details
Details for the file viztracer-0.8.3-cp39-cp39-manylinux2014_x86_64.whl
.
File metadata
- Download URL: viztracer-0.8.3-cp39-cp39-manylinux2014_x86_64.whl
- Upload date:
- Size: 719.9 kB
- Tags: CPython 3.9
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92511ee83a8171ec0f988cdea1a69d39c27b0859205eab5941c82ba9fae7ad83 |
|
MD5 | ad8336ddb0fca47c34dc80c15f11b1e4 |
|
BLAKE2b-256 | 28fb592d57b1f6965ce41f7991cd3d7fc31b734cec7df33725a54d8172a6daea |
File details
Details for the file viztracer-0.8.3-cp39-cp39-macosx_10_14_x86_64.whl
.
File metadata
- Download URL: viztracer-0.8.3-cp39-cp39-macosx_10_14_x86_64.whl
- Upload date:
- Size: 681.4 kB
- Tags: CPython 3.9, macOS 10.14+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6444b37041fb274e889198fc98394b758b1d1bd0077a4153ec45e53a7bc77e33 |
|
MD5 | edea92eb2ba9b258424e8a35c792c024 |
|
BLAKE2b-256 | 834477ad4819d5273c24e7f7f5658987f0fba46c454cd4163f05b28578b320ef |
File details
Details for the file viztracer-0.8.3-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: viztracer-0.8.3-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 685.1 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6eadb9f09da5895d9ef97c985106d069871f3329dc399defdedd572f856401d6 |
|
MD5 | 359c9e22a2c64ae3154222c6946d23bf |
|
BLAKE2b-256 | b4173be856cd22a468dbc7b2ae13c5dc39f7a59f8a9b1d0077434eb5f763a9f6 |
File details
Details for the file viztracer-0.8.3-cp38-cp38-manylinux2014_x86_64.whl
.
File metadata
- Download URL: viztracer-0.8.3-cp38-cp38-manylinux2014_x86_64.whl
- Upload date:
- Size: 725.5 kB
- Tags: CPython 3.8
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d13c9a20c990cb3aef88258e43442273a24b923b43426c2c6774c5556009b219 |
|
MD5 | abe0212e01aa5fb698eb0af0ffc5acb2 |
|
BLAKE2b-256 | 312d9134d981e1723530e5474b5b31dda16a339be9b576489c0b8185edd28236 |
File details
Details for the file viztracer-0.8.3-cp38-cp38-macosx_10_14_x86_64.whl
.
File metadata
- Download URL: viztracer-0.8.3-cp38-cp38-macosx_10_14_x86_64.whl
- Upload date:
- Size: 681.4 kB
- Tags: CPython 3.8, macOS 10.14+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41240f31946a39dea5701c337e9d22bc1fd464fde60e2cf0827684df48e9b828 |
|
MD5 | 222e471bd1074affd07e996c77544654 |
|
BLAKE2b-256 | 90542c2cafc6e81b58af516706800c31ac29fb41e4e586ce454c422e10370844 |
File details
Details for the file viztracer-0.8.3-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: viztracer-0.8.3-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 684.9 kB
- Tags: CPython 3.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff50fd6415c5019bfddc5a93cf0d57e94fea03afbbdbc85e4debc412677d3ed9 |
|
MD5 | 8fef59ae608b18c845bea170c542e704 |
|
BLAKE2b-256 | 9fe167ac6449035ec0b2c62d3f677a89a99384db4097e4b4bfc43ba519ad72d8 |
File details
Details for the file viztracer-0.8.3-cp37-cp37m-manylinux2014_x86_64.whl
.
File metadata
- Download URL: viztracer-0.8.3-cp37-cp37m-manylinux2014_x86_64.whl
- Upload date:
- Size: 717.2 kB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9439154a5d4f1f18aac2e2c1c6acd4321fd966248ebdf4016bfe9b84b9c95097 |
|
MD5 | 2aedac71a921fffb6511e4be70c34c63 |
|
BLAKE2b-256 | 050f57a1fb98ff1ed4c6001018648b085f3b6b95a6235fef8eb3755d908d717a |
File details
Details for the file viztracer-0.8.3-cp37-cp37m-macosx_10_14_x86_64.whl
.
File metadata
- Download URL: viztracer-0.8.3-cp37-cp37m-macosx_10_14_x86_64.whl
- Upload date:
- Size: 681.4 kB
- Tags: CPython 3.7m, macOS 10.14+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e892739f2970548380e8442a8309d71bdc548523048e7c18cac9ad9ee6bb1c8b |
|
MD5 | 557aa09cae90daa6997c7e6dff58ec8e |
|
BLAKE2b-256 | f33d4e0d532c49568d57f50283629bd9fc530b9356728dc95997c5aede1bc75a |
File details
Details for the file viztracer-0.8.3-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: viztracer-0.8.3-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 684.9 kB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92c471d39eccdc580479bf76796c33a63e62b42f7a51c4ff2a9aa99c36bec5eb |
|
MD5 | 852831a67dda74565918e09c018d5757 |
|
BLAKE2b-256 | 75d9273424ad46cf036be7a6239074211ccf601325b43b481a86f9f061cbd0e2 |
File details
Details for the file viztracer-0.8.3-cp36-cp36m-manylinux2014_x86_64.whl
.
File metadata
- Download URL: viztracer-0.8.3-cp36-cp36m-manylinux2014_x86_64.whl
- Upload date:
- Size: 716.3 kB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22180a2796857dd8d632d2094372b0f6906ed15b6bef2462a45ba0ec038fb5e6 |
|
MD5 | 3145764f1a4d5a5dcbd364c7116824f3 |
|
BLAKE2b-256 | d94a2e608dc8816016d900ac5bc2b7d8888807ba16bbe03990663a740e91f00b |
File details
Details for the file viztracer-0.8.3-cp36-cp36m-macosx_10_14_x86_64.whl
.
File metadata
- Download URL: viztracer-0.8.3-cp36-cp36m-macosx_10_14_x86_64.whl
- Upload date:
- Size: 681.4 kB
- Tags: CPython 3.6m, macOS 10.14+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.6.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e519756d728600b10078a33e5f97db8a7e72e56d788bf390b08405382e5d619 |
|
MD5 | e31e81fecd9b5365795897accd8611df |
|
BLAKE2b-256 | 030020f2d1049a930a5be477f3bf269f712a696150c5f3d8538146eb43212293 |