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

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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.8 Windows x86-64

viztracer-0.6.2-cp38-cp38-manylinux2010_x86_64.whl (714.9 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

viztracer-0.6.2-cp38-cp38-manylinux1_x86_64.whl (714.9 kB view details)

Uploaded CPython 3.8

viztracer-0.6.2-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.2-cp37-cp37m-win_amd64.whl (679.5 kB view details)

Uploaded CPython 3.7m Windows x86-64

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

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

viztracer-0.6.2-cp37-cp37m-manylinux1_x86_64.whl (708.5 kB view details)

Uploaded CPython 3.7m

viztracer-0.6.2-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.2-cp36-cp36m-win_amd64.whl (679.5 kB view details)

Uploaded CPython 3.6m Windows x86-64

viztracer-0.6.2-cp36-cp36m-manylinux2010_x86_64.whl (707.6 kB view details)

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

viztracer-0.6.2-cp36-cp36m-manylinux1_x86_64.whl (707.6 kB view details)

Uploaded CPython 3.6m

viztracer-0.6.2-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.2.tar.gz.

File metadata

  • Download URL: viztracer-0.6.2.tar.gz
  • Upload date:
  • Size: 670.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.6.2.tar.gz
Algorithm Hash digest
SHA256 9dad50947aada9d5f1a7067a846e3471a8f66a6105107ef49adb6238ae52534f
MD5 e361f36f866a0b767778f83b0013c4d6
BLAKE2b-256 051cde4ac5f359bc26e0afb7ee44270e748f6b243566b1d1b2b3bc09b42d270d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.2-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.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 6007c54adfa21276f8e5e43058e35ad6b96d23d8a0103f2d1f7b08724c8bb676
MD5 971ca93f3176abb04aa1bd7574296cba
BLAKE2b-256 88a5c57d467b1542125bfd415cb2a6d20221f5255cfba41237aaaa9ed5adc831

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.2-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 714.9 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.2-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 964ebb4042b2314a8e3b8f32bfb0693d02e674ae60f6969b028457457a7496bd
MD5 9de7398b912d819733dae48ae23da055
BLAKE2b-256 ff8edc594864dd7dd9410a374a1f1d4b1eea01baa48d82e636e59fe09d0657a5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.2-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 714.9 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.2-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 9f342b7cd00903257820864157f6587186f8cd560cef691742374e30c92edaf2
MD5 ee26ce0e7bddd064d85efddd624c4085
BLAKE2b-256 9afacc4b4849a36b24ab22ca00027a07d402b189457d6f51beee15d79bdcb31c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.2-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.2-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 76bc289048035f79c95515b6ae92abbfd7ce95899768471d32f35d497fc5b896
MD5 9540163b9826f94e6f0a5b4a9fb94f65
BLAKE2b-256 c7bfdd417f4a03de22990111f0f8d9c3bca4c2a34f5c5df612e9267830177f71

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.2-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 679.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.6.2-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 4d0f21c6830f63cb01c5e2456b27fd110a67165535c9f1e1e82ca7dad4c3edd8
MD5 c393da3de31b8bc48ed47828414f8857
BLAKE2b-256 496a2265f24bc1976f6d0feb936b630f0336c3d9fa035f94fcb6f275d0e5cb6b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.2-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.2-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 2bfa6d18595c782ea0c337290ae7152c5d26b8ef26ae79a1068783405f2aa9b6
MD5 14b4c03529817200f68e019e9f6f44b4
BLAKE2b-256 adb9a718debafd663a9512a3586b427fdd48e58467e43850c22a8f39e98cfdc3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.2-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 708.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.6.2-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 9d04905533719116669901e9fd532a32afec204ae39545854a97b5bc4dbddbe3
MD5 05a3bc0bade735c4161cff7438c3ff25
BLAKE2b-256 13bf8b274c9e2a950b730f8230aac6838d5efea0a776273dfb9377523b0afefd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.2-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.2-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 1aac0370a370e9f2d085e6088fd6df8bc1f25486e55463f3a7fbea37a5d8e351
MD5 63c847ede0cfb51abc2f2be72364754a
BLAKE2b-256 2f0610c436dd06eaff1a42eb59862f1258519076daf9cd8a728786c0c9ac7355

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.2-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 679.5 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.2-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 03684413c8570cc9ad326ca6f91d35d3a1babc55a84a83350d278deda49b5701
MD5 dd9b48a1744605e4d5c98fc1c80bc55d
BLAKE2b-256 40edd703c9bd9877c5af1ec1ae44529a22ff4688a4b273552e0c29249f76c969

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.2-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 707.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.6.2-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 455718aab9ef66d50d2d5e92bcb58884ec192cce81b56409106f5c9492ab4c01
MD5 f6e041899f2f920a2c8f2c52bddd72db
BLAKE2b-256 af31d92878eb27d981fb441bd0f16591741b23ff01f6313d1e3d4cb2d4fafbee

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.2-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 707.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.6.2-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 8df3a6f8169beed0c8e7b0f57e545c03e95332a5549f2b463bc365f39cf651f5
MD5 b5d5cc47bf361cda95eeca84d8666c32
BLAKE2b-256 02085743a40dae2fd2da8a29891a1f75284dc9376b0c033f77ee567b40a52ba4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.6.2-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.2-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 4ec5911e530a5bbec9923a007f142d59a7ac2dbca11b3da0436ff94d8a059253
MD5 cf8c6e55ab0e3a31e2b5e9ac6c22b868
BLAKE2b-256 739c00dd4e48d179f0b68efd222f68fc30f5e8dca8b31a3da0e027e6542be9b6

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