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

Uploaded Source

Built Distributions

viztracer-0.4.2-cp38-cp38-win_amd64.whl (672.6 kB view details)

Uploaded CPython 3.8 Windows x86-64

viztracer-0.4.2-cp38-cp38-manylinux2010_x86_64.whl (701.4 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

viztracer-0.4.2-cp38-cp38-manylinux1_x86_64.whl (701.4 kB view details)

Uploaded CPython 3.8

viztracer-0.4.2-cp38-cp38-macosx_10_14_x86_64.whl (669.3 kB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

viztracer-0.4.2-cp37-cp37m-win_amd64.whl (672.5 kB view details)

Uploaded CPython 3.7m Windows x86-64

viztracer-0.4.2-cp37-cp37m-manylinux2010_x86_64.whl (697.5 kB view details)

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

viztracer-0.4.2-cp37-cp37m-manylinux1_x86_64.whl (697.5 kB view details)

Uploaded CPython 3.7m

viztracer-0.4.2-cp37-cp37m-macosx_10_14_x86_64.whl (669.2 kB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

viztracer-0.4.2-cp36-cp36m-win_amd64.whl (672.6 kB view details)

Uploaded CPython 3.6m Windows x86-64

viztracer-0.4.2-cp36-cp36m-manylinux2010_x86_64.whl (696.6 kB view details)

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

viztracer-0.4.2-cp36-cp36m-manylinux1_x86_64.whl (696.6 kB view details)

Uploaded CPython 3.6m

viztracer-0.4.2-cp36-cp36m-macosx_10_14_x86_64.whl (669.2 kB view details)

Uploaded CPython 3.6m macOS 10.14+ x86-64

File details

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

File metadata

  • Download URL: viztracer-0.4.2.tar.gz
  • Upload date:
  • Size: 664.5 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.4.2.tar.gz
Algorithm Hash digest
SHA256 4421bbe5bb8ae151427709133e2393a58018021faca7c5511e37ee082ec24153
MD5 9fa46ab959c667e359371eb431413d6d
BLAKE2b-256 a830abf0522088d11bc86478d6f39455b754f1ccda39efe1ac88236fb3a97075

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.4.2-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 672.6 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.4.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 4d19c829549f7f722cb398707c274226ba4cd622bc36456dd36f2a3cfe4faecb
MD5 838a1de1dea5d0e0bcd687764e31b1d4
BLAKE2b-256 443ad2485cb931af4c3096bad011d03c11dc605f343364c7223fe902d371f0cf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.4.2-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 701.4 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.4.2-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 4fae74ae7e7dbcfc9fd7544b57f8c9ba924ac2ec1a8fb8355a1eea645a3dbbeb
MD5 2582f2df4da751532c0fc47a8174b2cf
BLAKE2b-256 f039de3d9420121e60f13351c4bede51522c4440f13fd599d8bab9d04a437309

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for viztracer-0.4.2-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 651cf2062872e20206fea1a11a0d0640cd07c8caf29fa004a3308c279f0ceb4e
MD5 a17189d3b680af0588c4b301110ebc82
BLAKE2b-256 500badb913b316c69ec209cd13dd39fb6b799b5765e710e9e66d0acdf10556bc

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for viztracer-0.4.2-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 68af2205cf6ec82c708f727cafc2de43e4198749cf4bc9d5e3c5910bf84f660b
MD5 28cb6d60613a63c3d5c569e15326073d
BLAKE2b-256 b8280ee127e071f2f179a5410d3ea765ca4917a3eef3ee2730ee007b7b749a8d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.4.2-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 672.5 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.4.2-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 5c2a91fe5d50355e29587536d82a20d5c6a6ea3107b453a275165f5dd946733c
MD5 a5b2062f83a58f4432df652b07a4da94
BLAKE2b-256 e73f34cb3f5daad04ec8782026b08fd900ea2ea8e7cd5e9b02956654ca8483ff

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.4.2-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 697.5 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.4.2-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 628886e4445487eabedda3524574bbeb40c157af30a595b8e2d8ad7c1c8ca7a1
MD5 f60f54b01b7c8e14615de0df84003443
BLAKE2b-256 b27a0dbba8a77fb1c911d8474050bc3781cb3486943f4820d17fa6224929af74

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.4.2-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 697.5 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.4.2-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 a312ed124b0cf23b7d92eac5cb5f6c1bddaee526f53811dcac9d2accb6ff1d89
MD5 e35ccb9d488322dc4723e48e6186dec0
BLAKE2b-256 f993f9a39a8f4da8d3d8205410e288f9d788884665b591f5e5e4f88ea4960fd4

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for viztracer-0.4.2-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 8b25b1a62cfbdbca4abd6bccf37f4aae77b3f48edc1652de0138b7e2925b86a2
MD5 b63e904c9d06136c6feb74d24cb7a19a
BLAKE2b-256 76d194d791f95b628faea3c8c9ce025e02395df2135abb0d6b7f78312103029f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.4.2-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 672.6 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.4.2-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 a30fa4c16e1e1304db5044b1e0ee9bd4679a58db4abeccaa1ed1e06bdde54ca5
MD5 f64e499446d25c4a9659939c8c9f8586
BLAKE2b-256 2aa85e7f21c34b4e66db48bad44feeb29282da1ab646081324caff6e83c55554

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.4.2-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 696.6 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.4.2-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 126240d6c67d6b15b26e5aeda9bdf6f64182c763708b27ff0262ff4c42f7af6b
MD5 9992f54f8b01b80fb7d01a01d3688474
BLAKE2b-256 3e43610b306b5be192cc3844f565f58ae27606b2112dcde3220b528b6c903f41

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.4.2-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 696.6 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.4.2-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 ec28c8343a91c9e3c5fb3ec33e9a89683aed6c9627f36343e2f17d6576c527fa
MD5 64896ad1f943ceec1e75a1f2a23922e2
BLAKE2b-256 f7bcc85f5b97bc2ce2c8bff9df4135a98b568b8de01203f44c111cb0c5ae5816

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for viztracer-0.4.2-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 d1da3f771184c08fcfb5357caffa186384f3188873499ef8442a985e54b7f5c6
MD5 40eba405c70f58632de9c86f931f3ac6
BLAKE2b-256 b36fcc51272089d7faefddf411f67707b5df0db9b376ae654e7b56f386a7915b

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