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

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

Uploaded Source

Built Distributions

viztracer-0.7.2-cp38-cp38-win_amd64.whl (681.4 kB view details)

Uploaded CPython 3.8 Windows x86-64

viztracer-0.7.2-cp38-cp38-manylinux2010_x86_64.whl (721.0 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

viztracer-0.7.2-cp38-cp38-manylinux1_x86_64.whl (721.0 kB view details)

Uploaded CPython 3.8

viztracer-0.7.2-cp38-cp38-macosx_10_14_x86_64.whl (677.7 kB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

viztracer-0.7.2-cp37-cp37m-win_amd64.whl (681.2 kB view details)

Uploaded CPython 3.7m Windows x86-64

viztracer-0.7.2-cp37-cp37m-manylinux2010_x86_64.whl (712.8 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

viztracer-0.7.2-cp37-cp37m-manylinux1_x86_64.whl (712.8 kB view details)

Uploaded CPython 3.7m

viztracer-0.7.2-cp37-cp37m-macosx_10_14_x86_64.whl (677.7 kB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

viztracer-0.7.2-cp36-cp36m-win_amd64.whl (681.2 kB view details)

Uploaded CPython 3.6m Windows x86-64

viztracer-0.7.2-cp36-cp36m-manylinux2010_x86_64.whl (711.9 kB view details)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64

viztracer-0.7.2-cp36-cp36m-manylinux1_x86_64.whl (711.9 kB view details)

Uploaded CPython 3.6m

viztracer-0.7.2-cp36-cp36m-macosx_10_14_x86_64.whl (677.7 kB view details)

Uploaded CPython 3.6m macOS 10.14+ x86-64

File details

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

File metadata

  • Download URL: viztracer-0.7.2.tar.gz
  • Upload date:
  • Size: 671.3 kB
  • Tags: Source
  • 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.49.0 CPython/3.8.5

File hashes

Hashes for viztracer-0.7.2.tar.gz
Algorithm Hash digest
SHA256 a797a17d1ead5fd715ad9fa609998f378f8855cf98a6c8dfb377a9bdf6f07a43
MD5 6dc8814b3d3a3ee6298c7b0a98ba7367
BLAKE2b-256 a230866459ba67d4a1fe2e7507a5a3523977dca5b96d6d9465a09c6ca4fadb52

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.7.2-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 681.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/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for viztracer-0.7.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 8e461a2bce54550557baa0d08801050c09b06fcac16479d65a3f365fcff94854
MD5 04d88a3cec18c129e9480647c4c97bd6
BLAKE2b-256 15be3cfb97727ace7af529ede4aa76782ba6b9dce4e71ae06690e1c0ef00c110

See more details on using hashes here.

File details

Details for the file viztracer-0.7.2-cp38-cp38-manylinux2010_x86_64.whl.

File metadata

  • Download URL: viztracer-0.7.2-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 721.0 kB
  • Tags: CPython 3.8, manylinux: glibc 2.12+ 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.49.0 CPython/3.8.5

File hashes

Hashes for viztracer-0.7.2-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 5ae382f0dc043ab3f07aac88dc3f9a50956654fe926d969567d7d113a5003263
MD5 69c546133a5d11eae25d53a6703dd20a
BLAKE2b-256 344dbfdb800b7db1f858324911ff04a6a587fe39d0e9b808683c047c8f68aa54

See more details on using hashes here.

File details

Details for the file viztracer-0.7.2-cp38-cp38-manylinux1_x86_64.whl.

File metadata

  • Download URL: viztracer-0.7.2-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 721.0 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/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for viztracer-0.7.2-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 fde459e0d72d2e6092e04e697be33b936d064b0307d95cfe72569e3b468a2f09
MD5 e94938d7bfa346e030631bc5d928e30c
BLAKE2b-256 29812879e95cd5afa14d95b059eec9f1861b3cf37b6b941f7ebb9911ad41d00e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.7.2-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 677.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/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for viztracer-0.7.2-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 fa28cb36c37a6fbff1fb06b98b20fefdd0b70f948648f9af8b4fa64fe1a0b3ab
MD5 9522481c2fed5ca8c93f87b7ab2b90ff
BLAKE2b-256 94e54d70c7672d6b14837cee8736b435e09c8aa06f02c95449b4516eb30c5e98

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.7.2-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 681.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.49.0 CPython/3.7.9

File hashes

Hashes for viztracer-0.7.2-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 cfe76b403c00249f20575ac1980eb324084022a29fc5d27c0370844a8c68c682
MD5 247c9dee39aa4a5612618142fb0fcd36
BLAKE2b-256 95ea75da1248021f3d073dfc8ad24942d0006808b9edd859903a181cc959c74e

See more details on using hashes here.

File details

Details for the file viztracer-0.7.2-cp37-cp37m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: viztracer-0.7.2-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 712.8 kB
  • Tags: CPython 3.7m, manylinux: glibc 2.12+ 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.49.0 CPython/3.8.5

File hashes

Hashes for viztracer-0.7.2-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 5c54afe599a106284dfe29caeeae1274dc44171916da0f47ba45a7489993f2a9
MD5 2ee73cfcea8441b3c4fbee466b3e9110
BLAKE2b-256 eba892a8635efb6adfda3c8a7cb0d4c2e0b344d777ea2452f938891a9b7e3504

See more details on using hashes here.

File details

Details for the file viztracer-0.7.2-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: viztracer-0.7.2-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 712.8 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/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for viztracer-0.7.2-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 e3030063c686ecb46f9761b9796b0c61a802ff2090eed73744b4cca8cac0babb
MD5 2cb7efca2f1e577150d60a75c179cff7
BLAKE2b-256 a183a3f4863c150d6151f5c9f247788e5b45155e07a27bf9cac440309fe910a9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.7.2-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 677.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.49.0 CPython/3.7.9

File hashes

Hashes for viztracer-0.7.2-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 d67af9e459145dfa478b724234d351dc6841f0ecabaf3f08034efccbf0bec471
MD5 56033cb5c20c2622833a19edd9164119
BLAKE2b-256 a61a7cc8722c0d69b26e1548fd4b77f779f48d30e4c99c02bd761b375a10b493

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.7.2-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 681.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.49.0 CPython/3.6.8

File hashes

Hashes for viztracer-0.7.2-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 a8a787b1ecaacbfa01ffc7e935c5ad7607c8e613b6a5c979338f68445b2d4c93
MD5 e4ab1402a64f7378f7c82b6b343d5933
BLAKE2b-256 65846253eb418e47526705c6a4ee5df2ea565f67450e5536be6e16c1d30c7d5e

See more details on using hashes here.

File details

Details for the file viztracer-0.7.2-cp36-cp36m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: viztracer-0.7.2-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 711.9 kB
  • Tags: CPython 3.6m, manylinux: glibc 2.12+ 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.49.0 CPython/3.8.5

File hashes

Hashes for viztracer-0.7.2-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 8bb7253618f10fd253674a356996f0c4aeec36f1984b991e6b4001dcb188887f
MD5 73393bb5f84dbfabc9525d83b6c16c65
BLAKE2b-256 05b245fa8d6a20fd8f665e3434f0f18483b9ee6b513dd80fb57000bb26a05e06

See more details on using hashes here.

File details

Details for the file viztracer-0.7.2-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: viztracer-0.7.2-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 711.9 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/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for viztracer-0.7.2-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 236771fa498daea0c4119d40b212077facacc48d14b436d6a36b0681512f3ae6
MD5 c8c59a865a6d05a129a2e5730baabe21
BLAKE2b-256 dbd0985fad7c4a7a8f490f0360d21f2dcc55864b9d58354fbb60995c12cf175c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.7.2-cp36-cp36m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 677.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.49.0 CPython/3.6.12

File hashes

Hashes for viztracer-0.7.2-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 163afb0bd5cf78b4e15c7a8a619b157cd461e1646d2e903ab76b1d1c9a9df2d2
MD5 d29d4009c1f08229a2ab1e56b734fda7
BLAKE2b-256 9707db71b69d409eda965e09247f1e00a6009b63e9c048c8b0973fe75b81b8b3

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