Skip to main content

A debugging and profiling tool that can trace and visualize python code execution

Project description

VizTracer

build readthedocs pypi support-version license commit

VizTracer is a low-overhead deterministic debugging/profiling/logging tool that can trace and visualize your python code to help you intuitively understand your code better and figure out the time consuming part of your code.

You can take a look at the demo result of multiple example programs(sort algorithms, mcts, modulo algorithms, multithread tracing, etc.)

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

  • Lower overhead than cProfile, more accurate on actual time consumed
  • 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 data through time
  • 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

You can also download the source code and build it yourself.

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

python3 -m viztracer my_script.py arg1 arg2
# OR
viztracer my_script 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

python3 -m viztracer -o result.json my_script.py arg1 arg2
python3 -m viztracer -o result.json.gz my_script.py arg1 arg2

By default, VizTracer only generates trace file, either in HTML format or json. You can have VizTracer to generate a flamegraph as well by

python3 -m viztracer --save_flamegraph my_script.py

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

Display Result

By default, VizTracer will generate a stand alone HTML file which you can simply open with Chrome(maybe Firefox?). 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, which will replace the deprecated trace viewer in the future. Or you can use chrome://tracing to load the file.

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 and load it via chrome://tracing/ or perfetto

Trace Filter

Sometimes your code is really complicated or you need to run you program for a long time, which means the parsing time would be too long and the HTML/JSON file would be too large. There are ways in VizTracer to filter out the data you don't need.

The filter works at tracing time, not parsing time. That means, using filters will introduce some extra overhead while your tracing, but will save significant memory, parsing time and disk space.

VizTracer support:

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.

VizTracer has:

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 does 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.

Performance

Overhead is a big consideration when people choose profilers. VizTracer has a better overhead performance than native cProfiler. In the worst case(Pure FEE) VizTracer is about the same as cProfile and in more practical cases VizTracer performs much better.

This is because VizTracer collects less information than cProfile, and optimized the hook function with a lot of efforts.

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

Uploaded Source

Built Distributions

viztracer-0.5.1-cp38-cp38-win_amd64.whl (672.8 kB view details)

Uploaded CPython 3.8 Windows x86-64

viztracer-0.5.1-cp38-cp38-manylinux2010_x86_64.whl (701.7 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

viztracer-0.5.1-cp38-cp38-manylinux1_x86_64.whl (701.7 kB view details)

Uploaded CPython 3.8

viztracer-0.5.1-cp38-cp38-macosx_10_14_x86_64.whl (669.7 kB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

viztracer-0.5.1-cp37-cp37m-win_amd64.whl (672.8 kB view details)

Uploaded CPython 3.7m Windows x86-64

viztracer-0.5.1-cp37-cp37m-manylinux2010_x86_64.whl (697.8 kB view details)

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

viztracer-0.5.1-cp37-cp37m-manylinux1_x86_64.whl (697.9 kB view details)

Uploaded CPython 3.7m

viztracer-0.5.1-cp37-cp37m-macosx_10_14_x86_64.whl (669.6 kB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

viztracer-0.5.1-cp36-cp36m-win_amd64.whl (672.8 kB view details)

Uploaded CPython 3.6m Windows x86-64

viztracer-0.5.1-cp36-cp36m-manylinux2010_x86_64.whl (696.9 kB view details)

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

viztracer-0.5.1-cp36-cp36m-manylinux1_x86_64.whl (696.9 kB view details)

Uploaded CPython 3.6m

viztracer-0.5.1-cp36-cp36m-macosx_10_14_x86_64.whl (669.6 kB view details)

Uploaded CPython 3.6m macOS 10.14+ x86-64

File details

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

File metadata

  • Download URL: viztracer-0.5.1.tar.gz
  • Upload date:
  • Size: 665.0 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.48.2 CPython/3.8.5

File hashes

Hashes for viztracer-0.5.1.tar.gz
Algorithm Hash digest
SHA256 40b22dddec9a4a06aed5ba132e9638239cc70adbd6e41eac7b3a4e0d31480d20
MD5 972bae3c4967fd9762a5e64bee873c88
BLAKE2b-256 b4a74fba5f49ce58d5294d96b55eb7546fe0fb05c39d8357332d4db907c60dc0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.5.1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 672.8 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.48.2 CPython/3.8.5

File hashes

Hashes for viztracer-0.5.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 d1fd6982688249246c5838bd7da19a9a758aff279910f898d8682e572aafbebc
MD5 dfbb3fd53f9d8633ff6bf2e4a4be3c76
BLAKE2b-256 a89d5d8c490cc4338601c49e920c0e693b45d29f403c216559cc5a9ecffe2a06

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.5.1-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 701.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.48.2 CPython/3.8.5

File hashes

Hashes for viztracer-0.5.1-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 63de6cd8c273d36411ebd51004f89d41870108d6557399e8c4e52fcef2c17212
MD5 ff95e804452b8723cc3ff048e78b754b
BLAKE2b-256 f956d1e50a5a022b2918598bb4f52953e3566dec480e9caa66022c56d4125d2f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.5.1-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 701.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.48.2 CPython/3.8.5

File hashes

Hashes for viztracer-0.5.1-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 4102bcc8ed51efa665c0420e01e618b6c194d76615537f8b38304ddc80aea029
MD5 b4495e49d9db149cf8f2ed90b836767a
BLAKE2b-256 2d7d881c87c2aa18b63053869978f84f82e0f61a22717573cc6a18f9d91cd743

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.5.1-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 669.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.48.2 CPython/3.8.5

File hashes

Hashes for viztracer-0.5.1-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 afef7f3fa17444ba4b464a4655551507d58ada7b00fcd9991f3759aa4383ec24
MD5 e91e99dafff74c7f3893c5e144e4cb39
BLAKE2b-256 0ebff33af3a4057c2e3f82a47a28d940ae57d7fdbc0b6fb513dcdbae64af2bc1

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for viztracer-0.5.1-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 df5d56cad44a2339f7b359fb921a03f109eadaac7195f5e6a721a766650dd2db
MD5 36af0fd4910a8e573565b63b636948cf
BLAKE2b-256 90c0d49d9e9d45d84673060939d6c72574b4c39660b7e267339f8a3d8e9369d4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.5.1-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 697.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.48.2 CPython/3.8.5

File hashes

Hashes for viztracer-0.5.1-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 0c463ff067728dbb72a1780102257ab2f69d3fe2b682f9e1ed87db4949d3006d
MD5 1d9ab2f4feefaeda113f63936adbe688
BLAKE2b-256 5c70db1d1eb32004c9607d34a3d5c2e28f67b33fad18b03bee6e73724a5524ef

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.5.1-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 697.9 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.48.2 CPython/3.8.5

File hashes

Hashes for viztracer-0.5.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 5299ab4425a1389d2c3c6bb93cca8da22e531e18486a312cec9b80f7bb643369
MD5 8843f3b9b679bec99f2adb9b30381227
BLAKE2b-256 89474614c9c33d2aa188e926862667c4cbdb1511ecc4887c91d19c6c5a28e221

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for viztracer-0.5.1-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 61fbcf29db804eb82d97cc68d73ea6ccfc55a6e1e5d6e9f5f00c6972cbc32cf0
MD5 caf3b37629d6f7e48136a1ea4938f130
BLAKE2b-256 30eef7496006f4080d89cf02622c98edc9c12ee3e35368b83be3ed764a75074c

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for viztracer-0.5.1-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 36b06ccc7542abf98bfed711b3f360954ce1e71ec224d63867b28cc63c063db1
MD5 cfe85d38ee1b5ab44b9ed6a8f9b8e11f
BLAKE2b-256 6ab79dbd0bc90f17d96146d9fdbd42cafaa77ac67b9d8e70969006fa05b7a79e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.5.1-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 696.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.48.2 CPython/3.8.5

File hashes

Hashes for viztracer-0.5.1-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 4a1ed5fac737ccb1c575242cbaa86612402293ea18465c08ca52710928c2f194
MD5 e4203eccf7d304684686e50badabdb2a
BLAKE2b-256 5c8738cf2857ac7ca5098f1919dbf4527418f5456291a19e65416837314e1f30

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.5.1-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 696.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.48.2 CPython/3.8.5

File hashes

Hashes for viztracer-0.5.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 e1cb1799b03a9855c1ca87ec6eae69251f79045805b2ca386f52aecc2c2523e6
MD5 6ba3789c6d88807978e71689a6a1726d
BLAKE2b-256 70fb57f1345c7c71b129248e5ef7925b7e8d2f1aa138017120ac13dd1c10d68a

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for viztracer-0.5.1-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 3375dbf261410110e9d1970eefde42f216398c9a1b4bb6c241a011a858df84d3
MD5 0e0e01f8cfb0a83c2a0944e114c05cd4
BLAKE2b-256 3caecb5451761f4a4c5d8467a36bdd2275913a368b0bef210448bc13c53e407b

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