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.

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

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

Uploaded Source

Built Distributions

viztracer-0.5.4-cp38-cp38-win_amd64.whl (673.5 kB view details)

Uploaded CPython 3.8 Windows x86-64

viztracer-0.5.4-cp38-cp38-manylinux2010_x86_64.whl (708.3 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

viztracer-0.5.4-cp38-cp38-manylinux1_x86_64.whl (708.3 kB view details)

Uploaded CPython 3.8

viztracer-0.5.4-cp38-cp38-macosx_10_14_x86_64.whl (669.9 kB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

viztracer-0.5.4-cp37-cp37m-win_amd64.whl (673.3 kB view details)

Uploaded CPython 3.7m Windows x86-64

viztracer-0.5.4-cp37-cp37m-manylinux2010_x86_64.whl (702.0 kB view details)

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

viztracer-0.5.4-cp37-cp37m-manylinux1_x86_64.whl (702.0 kB view details)

Uploaded CPython 3.7m

viztracer-0.5.4-cp37-cp37m-macosx_10_14_x86_64.whl (669.9 kB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

viztracer-0.5.4-cp36-cp36m-win_amd64.whl (673.3 kB view details)

Uploaded CPython 3.6m Windows x86-64

viztracer-0.5.4-cp36-cp36m-manylinux2010_x86_64.whl (701.0 kB view details)

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

viztracer-0.5.4-cp36-cp36m-manylinux1_x86_64.whl (701.0 kB view details)

Uploaded CPython 3.6m

viztracer-0.5.4-cp36-cp36m-macosx_10_14_x86_64.whl (669.9 kB view details)

Uploaded CPython 3.6m macOS 10.14+ x86-64

File details

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

File metadata

  • Download URL: viztracer-0.5.4.tar.gz
  • Upload date:
  • Size: 664.8 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.4.tar.gz
Algorithm Hash digest
SHA256 132e8862badec5c9895d095506ffc212938a2e11036a979315533cf51f9d407a
MD5 c49eb07a936c5e1f335e50fda6e4b262
BLAKE2b-256 01ca18eb09696a19be333d3de4e9638a003918e7d2a8e0d12875e3b2114df4f4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.5.4-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 673.5 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.4-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 214d59d9d41f458bb0d5cb037d726356210e22a19e68af58f2915e20f20d0e54
MD5 dbf2e69083c6a26c236edd426ac72bf5
BLAKE2b-256 9fd8c431ffc5fd3bc7b2dbd8d5588caa67529dd437796f6182ad26626d6a6319

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.5.4-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 708.3 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.4-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 1697f5070768034052cd25fd7022c46ae0c5f44915def783f21760c50efbed59
MD5 393afb6e6353264ad49ce7a9ca5dfac9
BLAKE2b-256 51ff972683ee717336d85ffa560125a0233e82616bd752faeaba49f186a2ae2d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.5.4-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 708.3 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.4-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 8b47da2546af8f14412ace8a0cfcb2ca5b9aad6aaaffb196fb57997df72030b2
MD5 307da1566131e3a5240177f5dc8b20df
BLAKE2b-256 44fcd519deda81afbd4e453deec9fb5138dd7fa64cf505ac597fa6b77ba1ccd0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.5.4-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 669.9 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.4-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 a2039691a23557dd0414d83d96e288344a25dc25ac152be0d74c2959b9f2b40c
MD5 855b550a3e46b708d48be7c366f957b3
BLAKE2b-256 0f06914d8c80b76261538151a042f35e459022c95d6da9b826acf8b7a149debd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.5.4-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 673.3 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.4-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 7d1fdb6e63bd92a3b2126b73ed6730ca74698482b2d5532670f20ca969dfe027
MD5 018778ee33c492bee02ba9b7dd2601f0
BLAKE2b-256 2c70917ec1f7b2c5e3fe6fe14251ca4247407145cee99e196bbccafe709d4659

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.5.4-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 702.0 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.4-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 20ea6b5eceb8323019d7de5785e0fe3ecbc1c41af5f50c245bbb557bfba4cfe7
MD5 62ab9f73a97195ca9a76fef1cd1f6f82
BLAKE2b-256 2598c7d14d291c240051d9dd0ab3bc66602bbad12db41cfc7fa805a032ff141e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.5.4-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 702.0 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.4-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 70d5b8d4c0affc655b6eac0578d84206e75a99131195348bc96b936ab17420c6
MD5 0f6418b1a780505893270e73cf1a3859
BLAKE2b-256 3ddb98c234bf5aa18b62d9f947d72a3b5d8d1716885aa13959ce4526b27f6902

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.5.4-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 669.9 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.4-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 6cfcd80cc84fec40662a6876aee954dff0e79eb0f359e01d503cc57f705fef9c
MD5 0b13cb655570968375579af83b6f6c3b
BLAKE2b-256 9f4ee695b43bf50050bd1493cd76d71506012829149dcd60cd9c3b24c66b4b2d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.5.4-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 673.3 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.4-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 5f3bebfb5dc4ce87865c68aafbd56f4a91d4fdb3b722f863b108f3e587bf0ec9
MD5 a401cd91f928b956eabd9f37ec4c6d3c
BLAKE2b-256 97eea7ca84804819268fe9f93d575c09a78f5ed56366b44c0dd66a75f4c75884

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.5.4-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 701.0 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.4-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 1e62c83a6129c0beea47990b578e25e7f9e125f8331c3a6dd3128ede8805eff3
MD5 146590cb730b5c5cd1a777532e0210fc
BLAKE2b-256 70f96a761b5e589e19af63eab815cf0558eb41e06a6d8518c00845e76d77d511

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.5.4-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 701.0 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.4-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 6d6fccf6418a03c0b2c854309ed1789be6d3c1d5407f53cdffec86d4dd170151
MD5 5c8e76c548adc943d1215e9ec76b7a6d
BLAKE2b-256 6d3ac152feb3b895f83c249ee027f517187b1afd15dbbb3dacc605af2e3b2226

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.5.4-cp36-cp36m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 669.9 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.4-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 b2023f647ddaaf4a02c9e0ff985374f49d142595b4f3bf4d2bd536ccf67a3d46
MD5 fda24b3d6283aceaaf0626445185c6eb
BLAKE2b-256 7e18645c87abfef959016e8059a4ec45c3870a8bca1838f9dce1d6a94fc756a7

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