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

Uploaded Source

Built Distributions

viztracer-0.8.2-cp39-cp39-win_amd64.whl (684.9 kB view details)

Uploaded CPython 3.9 Windows x86-64

viztracer-0.8.2-cp39-cp39-manylinux2014_x86_64.whl (719.8 kB view details)

Uploaded CPython 3.9

viztracer-0.8.2-cp39-cp39-macosx_10_14_x86_64.whl (681.3 kB view details)

Uploaded CPython 3.9 macOS 10.14+ x86-64

viztracer-0.8.2-cp38-cp38-win_amd64.whl (684.9 kB view details)

Uploaded CPython 3.8 Windows x86-64

viztracer-0.8.2-cp38-cp38-manylinux2014_x86_64.whl (725.4 kB view details)

Uploaded CPython 3.8

viztracer-0.8.2-cp38-cp38-macosx_10_14_x86_64.whl (681.3 kB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

viztracer-0.8.2-cp37-cp37m-win_amd64.whl (684.7 kB view details)

Uploaded CPython 3.7m Windows x86-64

viztracer-0.8.2-cp37-cp37m-manylinux2014_x86_64.whl (717.1 kB view details)

Uploaded CPython 3.7m

viztracer-0.8.2-cp37-cp37m-macosx_10_14_x86_64.whl (681.2 kB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

viztracer-0.8.2-cp36-cp36m-win_amd64.whl (684.7 kB view details)

Uploaded CPython 3.6m Windows x86-64

viztracer-0.8.2-cp36-cp36m-manylinux2014_x86_64.whl (716.1 kB view details)

Uploaded CPython 3.6m

viztracer-0.8.2-cp36-cp36m-macosx_10_14_x86_64.whl (681.2 kB view details)

Uploaded CPython 3.6m macOS 10.14+ x86-64

File details

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

File metadata

  • Download URL: viztracer-0.8.2.tar.gz
  • Upload date:
  • Size: 674.8 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.2.tar.gz
Algorithm Hash digest
SHA256 404cc30d68117f6edcc64f6ce324bafffad5107922c7deab835def88bd0ba71d
MD5 3dab935194d73f8242e29021c3d595ef
BLAKE2b-256 3c743444e42e0a832ef4349f7d0257769188bba5bdff43b1c6b48c03b81a4110

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.8.2-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 684.9 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.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 28c500c7e41347998c307d6dbe8563640aa3b731def1e693e7387fdc2d19cbf5
MD5 bf7f3c768230c5d35700ce5ff4fc852f
BLAKE2b-256 c2ced1ce84bf31a103e80de6c9982505d7317926e3babcc2c28c5afdc6da5bdf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.8.2-cp39-cp39-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 719.8 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.2-cp39-cp39-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8b597bb994d4d39bd5edd49c0363c5c18b9b9b4936e367bf61e5f67a9f1a9e13
MD5 34b23d993b3555072d9ef2efc4f6931c
BLAKE2b-256 d9c4b474845fa322cd77c6624590e564a054162f74d52e0d450db5555061a5cf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.8.2-cp39-cp39-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 681.3 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.2-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 bd8c936c87706bf333d2ca3867431115f110f99dec5b2ee250c2550a4d747c70
MD5 cce3991a552ece749037d75d8ca16476
BLAKE2b-256 9bed4e403485adf26668004d949acd4247db69c3b89bffd01374fc930232beb1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.8.2-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 684.9 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.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 da5a385067d25fa5df4900d84673147f8e918e82e724894cc14f5c266a8b8660
MD5 12e88425d7a10b017456ce30c673e5b7
BLAKE2b-256 dcd161bb4877d61d8cbf60c68f40320e3fe18bacac8a077d5e4f3e26975d6cca

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.8.2-cp38-cp38-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 725.4 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.2-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1ce1ea6e4849124b4c2825bcd4eca7543173b34e7764c287ed48341fe0d0f693
MD5 58cea2190bc2ca4b9d1f344ce00641af
BLAKE2b-256 c91088f85c3237eefb885e043bb1ced410a45349c24ce260c45dfe8a64f7f4fa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.8.2-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 681.3 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.2-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 6c3a63c41ca4384301b668371ba4751bdf2e64fea8c67b612fa0d101c3c2bd91
MD5 12ab6382ff412a33af76e16f8e3fe92e
BLAKE2b-256 bd8c0f5824fad6e68c44103c3c152d8d7e9578e267852873785a3b974e797f76

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.8.2-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 684.7 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.2-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 5de40e169586abd0ea672922a863500d1050719d06911a7dd46a30eb30c01e22
MD5 7064d57918dc421c87f62222b0853097
BLAKE2b-256 2e04d919f28d69b7e09c0020ffe1244b47034cd99e5b40592958d265b679480f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.8.2-cp37-cp37m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 717.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.2-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 28cb18f0bfcc7351827916749bb32591f6cc67c7b59159a1e6f977b56a55cb92
MD5 0d9444618fa9f963fdd7ae840d269aee
BLAKE2b-256 1b7265b3bb19e8cf18fdf629e1789ba066a8f437b5bc90e180a7a51b72d139a7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.8.2-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 681.2 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.2-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 af3a53e515d3248587a6930a50c113d813465545ac5078462262e57e6896d0d3
MD5 5b9511213174f6228233dee7c3da6f49
BLAKE2b-256 d312e9903b075e45feda8d99ad64e2a44603df275724fff4d2ff49ce8974deb8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.8.2-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 684.7 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.2-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 a70327b1f913d96ee31d540aa703a059528bdf49329b7dbe6c8dedbc585ba5ca
MD5 f857a32750a6f27e932b3848e22b7c91
BLAKE2b-256 264d8370e30f8b4cb5ce2ce420d43001b2d98843247a5c9dd32c3d315d014543

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.8.2-cp36-cp36m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 716.1 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.2-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 067beb05f74f7fe9269a1188329e4ee8922ecdfc569801771bfcfd9144ddb1e0
MD5 9d5565a4e230c704a907b39d6b057194
BLAKE2b-256 788451b4870b15e8b0cdd21aeb495870674e98a04de3dbf5e64d407977d4b990

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.8.2-cp36-cp36m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 681.2 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.2-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 14869ff92f1a3c0a25789e522f0f2faa91b49b6f38572226f8d7add68a589376
MD5 968856a739828bea93dd06ab0ba06375
BLAKE2b-256 bc3271a5bbfa81c075c1027224e37d0acd8322b33a14a563092d821b38cd659d

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