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

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

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

This version

0.6.0

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

Uploaded Source

Built Distributions

viztracer-0.6.0-cp38-cp38-win_amd64.whl (677.7 kB view details)

Uploaded CPython 3.8 Windows x86-64

viztracer-0.6.0-cp38-cp38-manylinux2010_x86_64.whl (713.0 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

viztracer-0.6.0-cp38-cp38-manylinux1_x86_64.whl (713.0 kB view details)

Uploaded CPython 3.8

viztracer-0.6.0-cp38-cp38-macosx_10_14_x86_64.whl (674.2 kB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

viztracer-0.6.0-cp37-cp37m-win_amd64.whl (677.6 kB view details)

Uploaded CPython 3.7m Windows x86-64

viztracer-0.6.0-cp37-cp37m-manylinux2010_x86_64.whl (706.6 kB view details)

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

viztracer-0.6.0-cp37-cp37m-manylinux1_x86_64.whl (706.6 kB view details)

Uploaded CPython 3.7m

viztracer-0.6.0-cp37-cp37m-macosx_10_14_x86_64.whl (674.1 kB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

viztracer-0.6.0-cp36-cp36m-win_amd64.whl (677.6 kB view details)

Uploaded CPython 3.6m Windows x86-64

viztracer-0.6.0-cp36-cp36m-manylinux2010_x86_64.whl (705.7 kB view details)

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

viztracer-0.6.0-cp36-cp36m-manylinux1_x86_64.whl (705.7 kB view details)

Uploaded CPython 3.6m

viztracer-0.6.0-cp36-cp36m-macosx_10_14_x86_64.whl (674.1 kB view details)

Uploaded CPython 3.6m macOS 10.14+ x86-64

File details

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

File metadata

  • Download URL: viztracer-0.6.0.tar.gz
  • Upload date:
  • Size: 668.7 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.6.0.tar.gz
Algorithm Hash digest
SHA256 17d6d4e4fde19f03440135eac35bd97f38f94a02c92889664828eef49d956520
MD5 8d2e249121d5d1c3d94c7151559821b6
BLAKE2b-256 09b0d0c182d4637b4634b65c9110036723c42efc934779c1ad3b5e4c28dfa774

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 677.7 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.6.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 3c905667fdc0d94a810b8248c249a0d60901324670bd130feb635a1fe089c5df
MD5 5b4c8428436cb03a5cf61170cee53cff
BLAKE2b-256 ac7929803b0fd8a1ebbfab7fb003e50fa3d084d7e444eefd134733b777a517c9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.0-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 713.0 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.6.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 ab5d965bd8de2058b79a39fa565d12e94d68c19e94024db0960b20b8fe45100e
MD5 fe53360cc4bc81f7637b0353fa5ab469
BLAKE2b-256 e5e93c0b433e324f43c5205141a0c95580b22c63f636341a4be0cb3e7935b925

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.0-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 713.0 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.6.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 f2ef946b7cea647cea11db715d283dd8aa154e76eb2c6f80772db91e622cc54b
MD5 8677f8fa8b17645fe4ba3d77ca512da8
BLAKE2b-256 a1e69fe6a27b43db6ff5c52e75370d6d51edaca576e9353768aa2180edf86ade

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.0-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 674.2 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.6.0-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 f120483ab5c36d512da6c28c4e7a18de0338d2630f296c65e9ee4505e5b6f9be
MD5 f530ed1580ced2d6c40fc85c8ea21a53
BLAKE2b-256 1368f4598ab2c1ef34d7fc1b74ae0cf8fbbdbb0f61d181db197b644a7d4981e5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 677.6 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.6.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 329b1c0d95c5f7a2fe5cc62962d4b74cd3882c238b1ad8820baa8eb7b59b0aeb
MD5 3fe19701ebdd1c83f9e52e741975c6b6
BLAKE2b-256 7b56f2095a92a5479a0ad9c11b5897da34496da8679ee14c8210f2b11c3dfdf8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.0-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 706.6 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.6.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 3aded22ce16c0cf1fb181e26894687162596e8a8ed5f54e06517c5449e5b6c56
MD5 c1eb2799c4f2ea07d5705a03fccb1f09
BLAKE2b-256 1c2e47b9c3482f64b6cfd405f06c1e728237067641b406ac1d659f59ae1abdf7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.0-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 706.6 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.6.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 eeff43825b7d42c1538ec83fdada818ce8017185cf9c19a8c8a5f455248c94db
MD5 00c7481bca0e7145b487bc945b79419d
BLAKE2b-256 47424e601e7bf2420bce06898b3d75bf1de33d853d22eb903064811d64d1b026

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.0-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 674.1 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.6.0-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 dc0ee4be1bbe994cfd7fc85d875fbcc5a7f6a9cced3ff39b22f749b8a3f2eeb4
MD5 f2301d9015fb024ee6ad0d7e7c588a90
BLAKE2b-256 4342f70d00e71c1136174bd5df97a8dcafb7cb0bd3e8ed92f67e34c6331542e1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.0-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 677.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.6.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 b91ab09e3066d47680deee0b2e1d5aae02c200e7cd1c8ebaeb8ddb6e01b6632b
MD5 b1dc260be336fa9b55354e0b5d5a2164
BLAKE2b-256 bb6e7f46061b04bddae819840dd2525db9cdd0c8f0fbf213c7dc709c337e85a8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.0-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 705.7 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.6.0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 a78b1490970ec1c2d7af57d3c0fb71752a27b6c7bfcd9c83e85e461b0ad49e55
MD5 38cda80170532532fe008028152219e8
BLAKE2b-256 6f43d332655a320ad8991b10bae3b2d56e06b3ce1faaa886e737a9ad00260881

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.0-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 705.7 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.6.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 e1ad52d73224e1d5c21e1b0dc8924940293837291a528c3b87ee35879148d5ae
MD5 ad6f1d654f7eeb92968f9ca6e3ffe0a3
BLAKE2b-256 34d7f7616f4688b277afb72edb7868de099c3ebf0bc78f69a64b336b0a669e92

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.0-cp36-cp36m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 674.1 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.6.0-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 d6f05639ae56b38492d2e2b8af0d3a54c7079648f83d896bc864da24bc7bbafb
MD5 91ac024fde4b0a2bee0a29bc0870bb5b
BLAKE2b-256 b587763239d46cda96480c589242efd4431c3769b9894f5fef4e7fac98f273c3

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