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. Use "AWSD" to zoom/navigate. More help can be found by clicking "?" on the top right corner.

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(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

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 supports subprocess with --log_subprocess and multiprocessing or os.fork() with --log_multiprocess. For more general multi-process cases, VizTracer can support with some extra steps.

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

This version

0.9.3

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.9.3.tar.gz (676.9 kB view details)

Uploaded Source

Built Distributions

viztracer-0.9.3-cp39-cp39-win_amd64.whl (687.0 kB view details)

Uploaded CPython 3.9 Windows x86-64

viztracer-0.9.3-cp39-cp39-manylinux2014_x86_64.whl (724.3 kB view details)

Uploaded CPython 3.9

viztracer-0.9.3-cp39-cp39-macosx_10_14_x86_64.whl (683.2 kB view details)

Uploaded CPython 3.9 macOS 10.14+ x86-64

viztracer-0.9.3-cp38-cp38-win_amd64.whl (687.0 kB view details)

Uploaded CPython 3.8 Windows x86-64

viztracer-0.9.3-cp38-cp38-manylinux2014_x86_64.whl (730.8 kB view details)

Uploaded CPython 3.8

viztracer-0.9.3-cp38-cp38-macosx_10_14_x86_64.whl (683.2 kB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

viztracer-0.9.3-cp37-cp37m-win_amd64.whl (686.8 kB view details)

Uploaded CPython 3.7m Windows x86-64

viztracer-0.9.3-cp37-cp37m-manylinux2014_x86_64.whl (720.6 kB view details)

Uploaded CPython 3.7m

viztracer-0.9.3-cp37-cp37m-macosx_10_14_x86_64.whl (683.2 kB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

viztracer-0.9.3-cp36-cp36m-win_amd64.whl (686.8 kB view details)

Uploaded CPython 3.6m Windows x86-64

viztracer-0.9.3-cp36-cp36m-manylinux2014_x86_64.whl (719.7 kB view details)

Uploaded CPython 3.6m

viztracer-0.9.3-cp36-cp36m-macosx_10_14_x86_64.whl (683.2 kB view details)

Uploaded CPython 3.6m macOS 10.14+ x86-64

File details

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

File metadata

  • Download URL: viztracer-0.9.3.tar.gz
  • Upload date:
  • Size: 676.9 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

Hashes for viztracer-0.9.3.tar.gz
Algorithm Hash digest
SHA256 4bd34630a304907cfc83f3ff8f9e9c16773f5a5e1dbd13e5392442835c164b49
MD5 4c91033b03da5391a0c041ceeb333198
BLAKE2b-256 43f9fc1fcb24d247ce8c44c032aa5761a585390504a2e8380ff86f32e58326a1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.9.3-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 687.0 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

Hashes for viztracer-0.9.3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 54ec49ed70e05a25c3c5325d896829f5145883e09d9c43d2c1e5238dc9470c16
MD5 4bad875c28c36676d8b08b30ede4af53
BLAKE2b-256 09f30a102bb15dc84114238e743b070f6f095d96200f9195b34a2a152b6488a7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.9.3-cp39-cp39-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 724.3 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

Hashes for viztracer-0.9.3-cp39-cp39-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0e4c3723114bdeebdb1bafa079c0794ce01a69532be25293fa07b6e458cd7efe
MD5 5192dc0ac8460644d00d70b9e75b674a
BLAKE2b-256 5c85412f7f6f6667bf98c96d3a965f341f34a4ae7d5f0016bd8db25f38503c66

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.9.3-cp39-cp39-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 683.2 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

Hashes for viztracer-0.9.3-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 f3f3a473bc6fb125bc2a3e7db1f789a36cfa5db2e3cc9b4850850f07929a4139
MD5 72e2c6e016393eb8114e8763d62907d4
BLAKE2b-256 8d9c099b3cc9941608bff8165fe0121020b0a79b91d2a9adf8ad8892e4551de9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.9.3-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 687.0 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

Hashes for viztracer-0.9.3-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 5ad604c3a699c3c2025c03b41aaa7a5e0477d26da0a206af8710697ba54e0144
MD5 cd8af5804478a16f79b0b7f033317bdd
BLAKE2b-256 8fbfc8da4dafc43a5bfe8029c0c70b2c9f850aca69e1c7c71ca7346bb20e4b0c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.9.3-cp38-cp38-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 730.8 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

Hashes for viztracer-0.9.3-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 31bfd477706756d62044aee7bbe759afc7e6da5f9e37db2b42e52e3098e7c06b
MD5 b804ab05155b7ab2cf5e96bc077cd5bf
BLAKE2b-256 de325982cf8880b4ad9ff1da161bdfd82e78562558d2dc8270e2e8e839e75872

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.9.3-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 683.2 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

Hashes for viztracer-0.9.3-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 97aa22f3ab0b4a423f809e53dbe7003b87a26e0fd294f6554170cac60df8fede
MD5 6368a207104612a8cdce577ecd3d3e08
BLAKE2b-256 8f1cea4766fba29b97c4fc2f61008421d218424e2240b84a01fe5fb6d1b180f6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.9.3-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 686.8 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

Hashes for viztracer-0.9.3-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 bd4562e79429ba592dc50774696eb08daf6efb95ea623211e85176a776987a3c
MD5 57f7b5e90039204cb1321bd9a0cfb592
BLAKE2b-256 5c7a8499a8f5802ea3981871ec023ba63b1680bd7fb2f311309d0e14dc844d69

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.9.3-cp37-cp37m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 720.6 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

Hashes for viztracer-0.9.3-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7314028bb750ff67974d36d395bdd580b4c382c47e98c072200a8615fcc77724
MD5 cafe1c9deb37658cfd39f3a29a282cc0
BLAKE2b-256 3838bd4e50223d50149ea8b7e27d9ffecbccd19196250eb75baf4a350195cd83

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.9.3-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 683.2 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

Hashes for viztracer-0.9.3-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 32708345b19ca11f83228f57ed22a7f01307ca79554ea5f36a46312ac7eba503
MD5 9ddced6c6fed5a4cb7f014c641d3c5de
BLAKE2b-256 b347cf3bd9bd4e3441a590d3d58cde28cfc9978cd724ee5229c42af80c4748d4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.9.3-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 686.8 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

Hashes for viztracer-0.9.3-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 9732ddab95bd9f2e8b97a95ffa003a482bed22fd5af94d948db887e858c85bc5
MD5 20f2b95ac2f6a8b542eedf016e74895a
BLAKE2b-256 912fc46580332b977e8a4816584de77165e833fd606b1c113646c3264b83b950

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.9.3-cp36-cp36m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 719.7 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

Hashes for viztracer-0.9.3-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 86d58d5aaeedf088a7686cabde30345071cf7eaebe5177d53e2f4f39c23b25ff
MD5 fc4e62b8b8863afeab7d08e1a853560f
BLAKE2b-256 54fc8bc0fbb6639fd00e989d6e039fdffc2bb6f9c918ea95cfcb42150685ab39

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.9.3-cp36-cp36m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 683.2 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

Hashes for viztracer-0.9.3-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 3394a258b253c23d4d37a03a68d678da5ee5c95557b4d4b92e8683ab437b8d78
MD5 ea508c80e772384c16df1b13e6d97faf
BLAKE2b-256 cf6c67bf932527a514348ac610352941bbfa951c8709044d38280b71faa61fa3

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