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

Usage

There are a couple ways to use VizTracer

Command Line

The easiest way to use VizTracer is through command line. Assume you have a python script to profile and the normal way to run it is:

python3 my_script.py arg1 arg2

You can simply use VizTracer as

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. Open it in browser and there's your result.

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

Sometimes the command line may not work as you expected, or you do not want to profile the whole script. You can manually start/stop the profiling 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

There are a lot of advanced usage available as well.

Display Result

By default, VizTracer will generate a stand alone HTML file which you can simply open with Chrome. The front-end uses trace-viewer to show all the data.

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

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.

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.

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

Uploaded Source

Built Distributions

viztracer-0.7.1-cp38-cp38-win_amd64.whl (680.9 kB view details)

Uploaded CPython 3.8 Windows x86-64

viztracer-0.7.1-cp38-cp38-manylinux2010_x86_64.whl (717.7 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

viztracer-0.7.1-cp38-cp38-manylinux1_x86_64.whl (717.7 kB view details)

Uploaded CPython 3.8

viztracer-0.7.1-cp38-cp38-macosx_10_14_x86_64.whl (677.3 kB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

viztracer-0.7.1-cp37-cp37m-win_amd64.whl (680.8 kB view details)

Uploaded CPython 3.7m Windows x86-64

viztracer-0.7.1-cp37-cp37m-manylinux2010_x86_64.whl (711.3 kB view details)

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

viztracer-0.7.1-cp37-cp37m-manylinux1_x86_64.whl (711.3 kB view details)

Uploaded CPython 3.7m

viztracer-0.7.1-cp37-cp37m-macosx_10_14_x86_64.whl (677.2 kB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

viztracer-0.7.1-cp36-cp36m-win_amd64.whl (680.8 kB view details)

Uploaded CPython 3.6m Windows x86-64

viztracer-0.7.1-cp36-cp36m-manylinux2010_x86_64.whl (710.4 kB view details)

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

viztracer-0.7.1-cp36-cp36m-manylinux1_x86_64.whl (710.4 kB view details)

Uploaded CPython 3.6m

viztracer-0.7.1-cp36-cp36m-macosx_10_14_x86_64.whl (677.2 kB view details)

Uploaded CPython 3.6m macOS 10.14+ x86-64

File details

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

File metadata

  • Download URL: viztracer-0.7.1.tar.gz
  • Upload date:
  • Size: 670.9 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.1.tar.gz
Algorithm Hash digest
SHA256 6513f86532a87aa25bcb56ad52f90aa4dfb57cb540dbbf3e05127e331cd6c5b1
MD5 e0c69999eeed453ecf450b6bf847ce14
BLAKE2b-256 90be0e7ae6fff64bb5e506b621b6fd4c28322a5b532755a105375e8abd1d9803

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for viztracer-0.7.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 eac28ed19dcef9b1271cdcf76f55cdff97e804c21aef0062e52ce0a392eff48f
MD5 4da76ec0648038a880f91e3c508ce780
BLAKE2b-256 bb09f4422a45367cb920d882bfeb4afba57d55b49e67db7ba8a42f8e5bd0a579

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.7.1-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 717.7 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.1-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 cfcacd6348866a1db7bd9ae0c48dc53c0d91129544f28e189bff436704d2d65d
MD5 03947b7c8f307cd2c0de606746a10d81
BLAKE2b-256 dc15cf321fabdd60be623d755ab2d926d625063da5f59a37e5c0b1392a378aff

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.7.1-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 717.7 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.1-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 bf7e09d9b68d9fa2f15385c734d94c12f0012b5b33bff86caccc51975969d0ac
MD5 23ac1493fc271e99b71a107ab9058803
BLAKE2b-256 81851b7d10b6f5a87885ad8f8f1fe3cf726f90da6c9b63f4b135269f08f8f562

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for viztracer-0.7.1-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 8991a60f5440951f12a37860ea72208291f425c4086231d801689f1c5ea512fd
MD5 dd71ad07783384456a52c8631767e0c9
BLAKE2b-256 5f85d74edb7208b8c750242909548dae59f58de09de398f4cb46f15d4083caa5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.7.1-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 680.8 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.1-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 c1635329eee1a888bf0018bc64ac03f23e082b2701d3cc8f5d31d6e1aa86101c
MD5 a32ad6ce6aa4568dcf61f9bd4e6f0af3
BLAKE2b-256 58b6e868b6bb36e9146efd7d491523b934283379877b33fac210b450bd900d50

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.7.1-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 711.3 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.1-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 cef4aba49d4fadf17197b532df7fff2c86336b7b9987009da0722961a46bd554
MD5 47df92f103000afce37d09b7b52a423d
BLAKE2b-256 36c846f59b527dd8f892646c7eeee755d4f56252622d85bf198ca12d8e371dd3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.7.1-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 711.3 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.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 983d15452298311970924612f1e68eda0f7a9a0e0d8a049039ccde63273ed0ea
MD5 1bc763d7ce4b31e84e43c6df9b692d4f
BLAKE2b-256 551bab2115ea26d7c92405c1ca7a9501cf0925933301461971c2e4bb6dbcfaab

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for viztracer-0.7.1-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 e124f7a4da9df7d7aca8a1467d1e0327301c929e990ecef18d145e2afdab679b
MD5 28255ce1c39a72bfdf223a798c9934ca
BLAKE2b-256 ff6afe511477f27ba11092ba070952a0c7c2e9b7d5c0cee884e06e4bc35ec9ef

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.7.1-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 680.8 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.1-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 081bbe6378d540d2faddd6e3e7bf7551631b68ea8a621257f9a6b5e75d8eae87
MD5 e10743f541a765b8885bf0f84d20bd5c
BLAKE2b-256 f95641134963db989eb0faf443f5d57a6a94ace077035203fa9ad86e41dcb916

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.7.1-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 710.4 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.1-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 cb4f290a3ba3e2168dbc0874e6c928844cf8261ca4115480130e458227ca8796
MD5 86988238e3f7cd18e9a9d531496facaa
BLAKE2b-256 66d842099c533dd067a60c9f2a985c0214983dbb4b56f0ee3d875c415d1d4e49

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.7.1-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 710.4 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.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 884a599f8839561cc268b31c5f7e713716e3f0c1c94a43da85fdeafc3a8e4720
MD5 0421900c50d92fdf9b00a1df7bf56a5f
BLAKE2b-256 75797d40f8813eaf87b27dcf55488be922efb9afc19754e886943048136effc2

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for viztracer-0.7.1-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 1efe1ca95158e9e56786e576f3d613c59dedb55787c28acf81d0c221958d9f68
MD5 8ac14e73959f0e09be5efdebc0c0aed0
BLAKE2b-256 377b462e96e1402951671731f4889a61b1558079a1cb677e70f4171a0915f655

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