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

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

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

Uploaded Source

Built Distributions

viztracer-0.6.3-cp38-cp38-win_amd64.whl (679.6 kB view details)

Uploaded CPython 3.8 Windows x86-64

viztracer-0.6.3-cp38-cp38-manylinux2010_x86_64.whl (714.8 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

viztracer-0.6.3-cp38-cp38-manylinux1_x86_64.whl (714.8 kB view details)

Uploaded CPython 3.8

viztracer-0.6.3-cp38-cp38-macosx_10_14_x86_64.whl (676.1 kB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

viztracer-0.6.3-cp37-cp37m-win_amd64.whl (679.4 kB view details)

Uploaded CPython 3.7m Windows x86-64

viztracer-0.6.3-cp37-cp37m-manylinux2010_x86_64.whl (708.5 kB view details)

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

viztracer-0.6.3-cp37-cp37m-manylinux1_x86_64.whl (708.4 kB view details)

Uploaded CPython 3.7m

viztracer-0.6.3-cp37-cp37m-macosx_10_14_x86_64.whl (676.0 kB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

viztracer-0.6.3-cp36-cp36m-win_amd64.whl (679.4 kB view details)

Uploaded CPython 3.6m Windows x86-64

viztracer-0.6.3-cp36-cp36m-manylinux2010_x86_64.whl (707.5 kB view details)

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

viztracer-0.6.3-cp36-cp36m-manylinux1_x86_64.whl (707.5 kB view details)

Uploaded CPython 3.6m

viztracer-0.6.3-cp36-cp36m-macosx_10_14_x86_64.whl (676.0 kB view details)

Uploaded CPython 3.6m macOS 10.14+ x86-64

File details

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

File metadata

  • Download URL: viztracer-0.6.3.tar.gz
  • Upload date:
  • Size: 669.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.3.tar.gz
Algorithm Hash digest
SHA256 a334ad01f42876984440688d5041d5a34096dc370e1a124d4dd4fe009e8bd040
MD5 218f88a0b4c794f1b9f20f1cf5029c67
BLAKE2b-256 1202bb223b5ed18a3bb0e22a2b14f793a6ba35e7caa57deec3917ad3013df4df

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.3-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 679.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.6.3-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 7e4e5b6f43d97d8659e12ec3059dfd72595eaf23a745af7b2415b045aeb0d6b6
MD5 15601f750f1b4ac35ed29d0cbedb4580
BLAKE2b-256 078e67a0ba81cf33745fb4238b1508a44822fbbb4be114287097f728cc5dfd8d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.3-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 714.8 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.3-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 04bf7d5ae95767e7c9a750ca4ab0583d2acb661d2e35db38c52370f024f1436e
MD5 d9ba304bd43ed460f4a63f34fd110cf2
BLAKE2b-256 9a440261b7681ba61a6c9a0fedf78aabbc18ff646835a9321ac53414f8e5078d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.3-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 714.8 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.3-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 e7554b78856d69759aa548f31b64f373df8ab92d5be96e739a612b5f76653186
MD5 224907a586dc3316d8613f777775e7c8
BLAKE2b-256 6fd477f076b39297328b29276a5cdcdf733d65573f68e39b51411cd6cf54f33e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.3-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 676.1 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.3-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 20234544d0b9fbc98fd032cb7b752f1b49a7ed98af2ca268149fb7935d25c985
MD5 f8039efa8a4b68b781d6a71d9d385021
BLAKE2b-256 681b1254d13eee24c88b09314b8768739272990b150acd346942765e72dd65ac

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.3-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 679.4 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.3-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 94e9cf82a430332db29fc224d3d02ce13592fadae7b702c4148114a7697080be
MD5 ee020eed6be2e431b55ca2785dba778a
BLAKE2b-256 941b24729302428e37d18eaee8ee4e9fab7735d04e4e8ee4b44cd1b1b9c65ee0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.3-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 708.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.6.3-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 662270bd0c22d3a79824a9ec0affbd7b2d3d2813ef4f1bcfc10572c2f8f0cbed
MD5 823606727569b11f136cb388bbedfb84
BLAKE2b-256 034aaad39be9013a91d0293d3d719eb098bc80190f502fa151d7927db7fca22c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.3-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 708.4 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.3-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 fe5884b3f4bce0f31e76d11400aeb40a27a27cb79e63f757821928256e622ab1
MD5 3a15b4cf7138ba54f51001f2d54462a3
BLAKE2b-256 c2276169fe71854409ba60cfb171299196969f12e7d9c691734b9aea0cab0d7e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.3-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 676.0 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.3-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 999cb705277a332eca9838c615c0b231804350285b40fe2a2007dd88954b4bc2
MD5 ee15a25372596e6e2695a2c15e3e901c
BLAKE2b-256 f6fb5d1b97d1cfdc52bcad9ba3259c702396ac7331db8441dd4010ccd5a9dfb5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.3-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 679.4 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.3-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 65b5b6928b4c28397e2733e96603ea7b2443b3e2e6314dc23e53f605a9396365
MD5 a26e9f5e1e789cf1bada1ca50f38456a
BLAKE2b-256 5b1769ff52114cedaf4aac9e717ac20637a878251d909749b5687f07876af0e6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.3-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 707.5 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.3-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 6b584f088d8cc582621ba9be948b10b99ec0fc5eaee96a2ac38fc93e35812fdf
MD5 df2b7521c6f20d7dd6889404f87adf05
BLAKE2b-256 5e6d0554c49302232b7c2d2b4ca80206b8c6cc6cb6c378832478675e536bd270

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.3-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 707.5 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.3-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 77ccbfdc4b53ef43bf6d4c6fb8dc142fb409d438ca46cff2c1c9e30ac3090b0e
MD5 aef9bf47b95a66d4cff6ed2fefb9d122
BLAKE2b-256 3b52a774202130c2c80a28fa6420b386b7312d62146f642e33c84855f371ae5e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.3-cp36-cp36m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 676.0 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.3-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 a54370d8d90728c952ddd3c6b353545add287682deada820a7bb82a07d1b4a23
MD5 b8f0e4d82c6463e43a158ab7e95da3ec
BLAKE2b-256 81a8a119a397f3c9683f61320fb001161c5941eff5e065c7562362ce36eb02db

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