Skip to main content

A debugging and profiling tool that can trace and visualize python code execution

Project description

VizTracer

build readthedocs coverage pypi support-version license commit twitter

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.

example_img

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.

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

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.

example_img

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

viztracer-0.8.1.tar.gz (674.1 kB view details)

Uploaded Source

Built Distributions

viztracer-0.8.1-cp39-cp39-win_amd64.whl (684.4 kB view details)

Uploaded CPython 3.9 Windows x86-64

viztracer-0.8.1-cp39-cp39-manylinux2014_x86_64.whl (718.7 kB view details)

Uploaded CPython 3.9

viztracer-0.8.1-cp39-cp39-macosx_10_14_x86_64.whl (680.7 kB view details)

Uploaded CPython 3.9 macOS 10.14+ x86-64

viztracer-0.8.1-cp38-cp38-win_amd64.whl (684.4 kB view details)

Uploaded CPython 3.8 Windows x86-64

viztracer-0.8.1-cp38-cp38-manylinux2014_x86_64.whl (724.3 kB view details)

Uploaded CPython 3.8

viztracer-0.8.1-cp38-cp38-macosx_10_14_x86_64.whl (680.7 kB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

viztracer-0.8.1-cp37-cp37m-win_amd64.whl (684.2 kB view details)

Uploaded CPython 3.7m Windows x86-64

viztracer-0.8.1-cp37-cp37m-manylinux2014_x86_64.whl (716.1 kB view details)

Uploaded CPython 3.7m

viztracer-0.8.1-cp37-cp37m-macosx_10_14_x86_64.whl (680.7 kB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

viztracer-0.8.1-cp36-cp36m-win_amd64.whl (684.2 kB view details)

Uploaded CPython 3.6m Windows x86-64

viztracer-0.8.1-cp36-cp36m-manylinux2014_x86_64.whl (715.2 kB view details)

Uploaded CPython 3.6m

viztracer-0.8.1-cp36-cp36m-macosx_10_14_x86_64.whl (680.7 kB view details)

Uploaded CPython 3.6m macOS 10.14+ x86-64

File details

Details for the file viztracer-0.8.1.tar.gz.

File metadata

  • Download URL: viztracer-0.8.1.tar.gz
  • Upload date:
  • Size: 674.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

File hashes

Hashes for viztracer-0.8.1.tar.gz
Algorithm Hash digest
SHA256 871e52874d353df5dcad674c29ba04128c5d54ec2d3f47fd675fb5519ac69ddd
MD5 bf9cb4031e318dcc335ced0720918fe4
BLAKE2b-256 a053f412ee9e85e8a3ce5b44c6b24fa71c0b465ec7711ba46a70aa04bccb1972

See more details on using hashes here.

File details

Details for the file viztracer-0.8.1-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: viztracer-0.8.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 684.4 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.9.0

File hashes

Hashes for viztracer-0.8.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 39d1c80723c097ae1cd84b1bb530a1c9960f7c3612e3bd006882cabb4d8f800a
MD5 a293f7041dfe610d11026f3338794336
BLAKE2b-256 809876995d4d2bd47f6493c4825e0e85ca8a672c72e40d7916588e19b81f69d9

See more details on using hashes here.

File details

Details for the file viztracer-0.8.1-cp39-cp39-manylinux2014_x86_64.whl.

File metadata

  • Download URL: viztracer-0.8.1-cp39-cp39-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 718.7 kB
  • Tags: CPython 3.9
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

File hashes

Hashes for viztracer-0.8.1-cp39-cp39-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 94cb1632deb2424dcb47d13a18c3eebc962bafc1ffabd11f6936ad7c89210cc3
MD5 f1537b383219b3a9fff09b0ffe80a170
BLAKE2b-256 85d32ce62a9f79bbfb0ff81a56f47fcc9c92ea3650fd242eaf6666bd6db66aad

See more details on using hashes here.

File details

Details for the file viztracer-0.8.1-cp39-cp39-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: viztracer-0.8.1-cp39-cp39-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 680.7 kB
  • Tags: CPython 3.9, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.9.0

File hashes

Hashes for viztracer-0.8.1-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 d131224bf2f2bb22be02749860a3bd0bd79fc05b5ff23be400f700d61cdb4447
MD5 1beaba50344b310672bf506f685c6198
BLAKE2b-256 6523a46e257a687eb17bb37549f335983a36e922658a1f9342d0b480fba7801e

See more details on using hashes here.

File details

Details for the file viztracer-0.8.1-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: viztracer-0.8.1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 684.4 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

File hashes

Hashes for viztracer-0.8.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 36786027807b13fb75183f2d8ef5ca6fca963d5649030aac97697fdee1061a87
MD5 99b1ad97869c49a7832add726ec075ff
BLAKE2b-256 55fe2e2063e25995f82e1eac00877b42f36e5509e7a61e2712ac0050e3e82aac

See more details on using hashes here.

File details

Details for the file viztracer-0.8.1-cp38-cp38-manylinux2014_x86_64.whl.

File metadata

  • Download URL: viztracer-0.8.1-cp38-cp38-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 724.3 kB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

File hashes

Hashes for viztracer-0.8.1-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d53b33863b2c126b4d5c5a2df1dc6eeb1df9e837e2d3921506dea95cb4f46173
MD5 669fab73c8e622ce5c5b09fea6148f0d
BLAKE2b-256 29de7263941d1dced4a9951570bf96e6631ce45ad56b10f75ef8ca029d0d8f7b

See more details on using hashes here.

File details

Details for the file viztracer-0.8.1-cp38-cp38-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: viztracer-0.8.1-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 680.7 kB
  • Tags: CPython 3.8, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

File hashes

Hashes for viztracer-0.8.1-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 3577b5d03e6f1b137225fe75a7a483fe4a13df5bfb28e22994eb2f3529f408a8
MD5 f59eb32116bf4979b896fb10be308466
BLAKE2b-256 b3502cae80616d6f2b5596d88984dd5ff3c923f01baede74bd2fc6ebc52a0a44

See more details on using hashes here.

File details

Details for the file viztracer-0.8.1-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: viztracer-0.8.1-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 684.2 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.9

File hashes

Hashes for viztracer-0.8.1-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 c97c97c7fa0384a953dbfff00d5be723310ede0643bc784115fda3c292e2490f
MD5 d54d9bea72cfe7a5fa381222ed17d49e
BLAKE2b-256 a7172b3f36d3779880d3d2b3a9088fbda85bb60081eceb62555edfad4ec58bff

See more details on using hashes here.

File details

Details for the file viztracer-0.8.1-cp37-cp37m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: viztracer-0.8.1-cp37-cp37m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 716.1 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

File hashes

Hashes for viztracer-0.8.1-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f5b36d255cffda8bfd611d98d796681e3da995f0b265d3db44c05891cb650cfc
MD5 9fb0b8671a1de463fb1c78c1aaae3764
BLAKE2b-256 d8a643e2c7ece096b72567038c97e8837e8f1349e9209f3c556b9e8f5d663e6e

See more details on using hashes here.

File details

Details for the file viztracer-0.8.1-cp37-cp37m-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: viztracer-0.8.1-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 680.7 kB
  • Tags: CPython 3.7m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.9

File hashes

Hashes for viztracer-0.8.1-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 e7b81b8416549977b001fe8fdea0b11018a4d20d2ec30329d6c5706dcaa54ce1
MD5 7a029239a41ebe2c1c20db5f514d2a5d
BLAKE2b-256 fe0400f631cbebcb4df186391a7c38bfc6efc825ebcfdf35b7505868299c77a6

See more details on using hashes here.

File details

Details for the file viztracer-0.8.1-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: viztracer-0.8.1-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 684.2 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.6.8

File hashes

Hashes for viztracer-0.8.1-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 b7398bdbb5512791c093dd91bdb96d5118f8a32950817158b06d70ca288b2701
MD5 97ce3e45e6634786cd1815fa5dc00ac2
BLAKE2b-256 89c17188a61509f4aff582aad7952ff0a34a53b09980d021626a3a5252ac628e

See more details on using hashes here.

File details

Details for the file viztracer-0.8.1-cp36-cp36m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: viztracer-0.8.1-cp36-cp36m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 715.2 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

File hashes

Hashes for viztracer-0.8.1-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dca6409c80f92f0157d40c7e22124e602465f1a42a8042407daa70a1ef5dce39
MD5 52b02f2a1aa6d104a146122bd86c29a9
BLAKE2b-256 19a8c759221d52d26fc39aa3b6e7d5fa555704e51ebe44e039184096873d67fc

See more details on using hashes here.

File details

Details for the file viztracer-0.8.1-cp36-cp36m-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: viztracer-0.8.1-cp36-cp36m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 680.7 kB
  • Tags: CPython 3.6m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.6.12

File hashes

Hashes for viztracer-0.8.1-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 71274652b48ca4e1c54f369faaebc71564591de4f5124f0a34b2a91f56389fa7
MD5 c6ea0640e44014406afb25dd3d8412ff
BLAKE2b-256 16784836c7352ac30aecf4966540cc322678c5804e58be49340c3683c715bfba

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page