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

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

Uploaded Source

Built Distributions

viztracer-0.9.1-cp39-cp39-win_amd64.whl (685.9 kB view details)

Uploaded CPython 3.9 Windows x86-64

viztracer-0.9.1-cp39-cp39-manylinux2014_x86_64.whl (720.8 kB view details)

Uploaded CPython 3.9

viztracer-0.9.1-cp39-cp39-macosx_10_14_x86_64.whl (682.3 kB view details)

Uploaded CPython 3.9 macOS 10.14+ x86-64

viztracer-0.9.1-cp38-cp38-win_amd64.whl (685.9 kB view details)

Uploaded CPython 3.8 Windows x86-64

viztracer-0.9.1-cp38-cp38-manylinux2014_x86_64.whl (726.4 kB view details)

Uploaded CPython 3.8

viztracer-0.9.1-cp38-cp38-macosx_10_14_x86_64.whl (682.3 kB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

viztracer-0.9.1-cp37-cp37m-win_amd64.whl (685.7 kB view details)

Uploaded CPython 3.7m Windows x86-64

viztracer-0.9.1-cp37-cp37m-manylinux2014_x86_64.whl (718.1 kB view details)

Uploaded CPython 3.7m

viztracer-0.9.1-cp37-cp37m-macosx_10_14_x86_64.whl (682.3 kB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

viztracer-0.9.1-cp36-cp36m-win_amd64.whl (685.7 kB view details)

Uploaded CPython 3.6m Windows x86-64

viztracer-0.9.1-cp36-cp36m-manylinux2014_x86_64.whl (717.1 kB view details)

Uploaded CPython 3.6m

viztracer-0.9.1-cp36-cp36m-macosx_10_14_x86_64.whl (682.3 kB view details)

Uploaded CPython 3.6m macOS 10.14+ x86-64

File details

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

File metadata

  • Download URL: viztracer-0.9.1.tar.gz
  • Upload date:
  • Size: 675.8 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.1.tar.gz
Algorithm Hash digest
SHA256 de1954cd4f662d75468a01aa5a1d6d4fd2a537e94b4a14e8a8f2e2ad9bcb572a
MD5 2b7995f051d55269148698b69d8281c9
BLAKE2b-256 40877ce5e62243e21539fe99956028d91badc8cbb4478450a6d28c88ab123f76

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.9.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 685.9 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.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 1d8a12ef695ca82972d48b850749c6ce5d620253b1dceacfbef806cca17bab14
MD5 b64aff3689636101b924bf609fd2b819
BLAKE2b-256 b6e177a7680ef6264fdc0789a5cbbee4a88be92c096c40ef45ec5d5abf98f25a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.9.1-cp39-cp39-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 720.8 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.1-cp39-cp39-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 37118d1f816c7abe9447301527052e252eb480da65c462a7b2521a140dbd1af9
MD5 e30fc7aa8057aa8391239893a375865e
BLAKE2b-256 dd402c6d58c6ba0863fb5c24d3a5b40464e9900795430f9e485d4b4b7d95b25d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.9.1-cp39-cp39-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 682.3 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.1-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 5bce68c2de63c4b55337aba4c448da79c91a9fd43b4d0073fa41002125dbbbb3
MD5 17cabb2debd879bc38953b3f34d0c82b
BLAKE2b-256 405306704e283160b81e28a5584366d36f63bdf9122db6ac596dfce5b5fd20dc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.9.1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 685.9 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.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 fdc4ccbbb0275d66c4945604ebd9cdd821f183a4e79d7e4c47e93dd64959b49b
MD5 9b4615e6b984edbed01ed41e15cf39cd
BLAKE2b-256 7710feab05e492ceb19ef8156420a555dc6f085ffe308275e03dde3e1846f47e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.9.1-cp38-cp38-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 726.4 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.1-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cab20a9c1efd07238e0e458407fda0b01c6bd407ed6a110d3ae9c561c20b9d37
MD5 1fafbee66cfb26d060760b27ec0404d9
BLAKE2b-256 7e9993675fd9cc819fa4d36dc83537f3fb9413ca7724e8390e554126368b7ba2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.9.1-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 682.3 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.1-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 80c2a745409ef457e742bfa1919b5cc15fa8e2be9c3c9abcebdddc912d8858c4
MD5 08d9d54a16724de5fd4a68d447dab26d
BLAKE2b-256 01583b72467f3887910476a8ce08b7cbfa18cb9ae9be9e77ac8c1c48c0660693

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.9.1-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 685.7 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.1-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 f5bd3ecf33affca5f2b9999ef4f15c4dabe950f2ffe7aeebc56a8a03f3097c55
MD5 af60da9cb38de99cc95832646ea607c6
BLAKE2b-256 8881f9a6e81d474c12aa6c7f4bce67d3ccdc50ebffe344b13110659482b3c97f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.9.1-cp37-cp37m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 718.1 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.1-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 deb7267eaaeb783f1c6de77b77fd2abfcebaebd8a17475ef99c5aa30595d1172
MD5 5469aebf5e9b622cfef1a40d6034a337
BLAKE2b-256 ea5d5ffc486c0f7f0911196b1bed14cc4a63d2efccf24a16644e4a67e6b0338b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.9.1-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 682.3 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.1-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 aaa3b5a3723a363cb99f69372932768ead0efdf3c3a0bc43db8b6f8f713bca74
MD5 470c91bf26f6e295f2a6c30e68b3e5e5
BLAKE2b-256 358a9fd826288cc7cfe12dfbf1767a967bb90fa3972568f6b9d19838c5365d90

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.9.1-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 685.7 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.1-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 947134b3a25c9bafba1fb8460ebba68b4f99835d59614acd590d33d0bee50f6b
MD5 b0efe4c67fcd3d888e1bf67a5843b0fc
BLAKE2b-256 90a609f21b62bbddcc9e3ff23dac07620a2666ba8e76e1af2d24857e2d5203be

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.9.1-cp36-cp36m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 717.1 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.1-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 aaa49285edab8e6cee54eef652b633c34111a3535c7cc0ea0c5e80a46766f8a8
MD5 f6082603fa2af0f87c503f1cd3c9bd51
BLAKE2b-256 a1b5c53fe8789ff788d316238af46adee8d9dfe355abec4bab31053e2d04f688

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.9.1-cp36-cp36m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 682.3 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.1-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 d81d3cf2135ec0f0601436ee4ca9465531056ea4d3570810ca8f8316be265f0e
MD5 a768ebf02fa7000b0f617af9fad982ef
BLAKE2b-256 726f2cc8eb7a7e943b5424346d90b60227dc56cb5a1e58611a12f8fb4207daca

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