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

Basic Usage

Command Line

Assume you have a python script to run:

python3 my_script.py arg1 arg2

You can simply use VizTracer by

viztracer my_script arg1 arg2
# OR
python3 -m viztracer my_script.py arg1 arg2

which will generate a result.html file in the directory you run this command, which you can open with Chrome.

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

viztracer -o result.json my_script.py arg1 arg2
viztracer -o result.json.gz my_script.py arg1 arg2

Inline

You can also manually start/stop VizTracer 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.

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

Advanced Usage

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.

Extra Logs without Code Change

VizTracer can log extra information without changing your source code

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.

Check more advanced usage for more features

Misc

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

Uploaded Source

Built Distributions

viztracer-0.7.4-cp38-cp38-win_amd64.whl (681.4 kB view details)

Uploaded CPython 3.8 Windows x86-64

viztracer-0.7.4-cp38-cp38-manylinux2010_x86_64.whl (720.8 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

viztracer-0.7.4-cp38-cp38-manylinux1_x86_64.whl (720.8 kB view details)

Uploaded CPython 3.8

viztracer-0.7.4-cp38-cp38-macosx_10_14_x86_64.whl (677.8 kB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

viztracer-0.7.4-cp37-cp37m-win_amd64.whl (681.2 kB view details)

Uploaded CPython 3.7m Windows x86-64

viztracer-0.7.4-cp37-cp37m-manylinux2010_x86_64.whl (712.5 kB view details)

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

viztracer-0.7.4-cp37-cp37m-manylinux1_x86_64.whl (712.5 kB view details)

Uploaded CPython 3.7m

viztracer-0.7.4-cp37-cp37m-macosx_10_14_x86_64.whl (677.7 kB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

viztracer-0.7.4-cp36-cp36m-win_amd64.whl (681.2 kB view details)

Uploaded CPython 3.6m Windows x86-64

viztracer-0.7.4-cp36-cp36m-manylinux2010_x86_64.whl (711.6 kB view details)

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

viztracer-0.7.4-cp36-cp36m-manylinux1_x86_64.whl (711.6 kB view details)

Uploaded CPython 3.6m

viztracer-0.7.4-cp36-cp36m-macosx_10_14_x86_64.whl (677.7 kB view details)

Uploaded CPython 3.6m macOS 10.14+ x86-64

File details

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

File metadata

  • Download URL: viztracer-0.7.4.tar.gz
  • Upload date:
  • Size: 671.3 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.50.0 CPython/3.8.5

File hashes

Hashes for viztracer-0.7.4.tar.gz
Algorithm Hash digest
SHA256 65b5c56ce3afa8e23852981528565adf469f79049c67f551aa3e1bfecca6f881
MD5 57f84ae6278cc718256142fe71472fff
BLAKE2b-256 35154bbcff1b75cf4e3d25349da4c18361077d321ffdb16c31145e20aec10294

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.7.4-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 681.4 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.50.0 CPython/3.8.5

File hashes

Hashes for viztracer-0.7.4-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 e57e290f8c3135073e39674a49b5547bb68ca7c59a708167fc78b90ff8bdd900
MD5 054ad8458636126ef1f06a8c83b12060
BLAKE2b-256 05a9fa2c61fbf36f233a16d9a0dbbd951d6706f6bef3722b16bfa255bbf675b7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.7.4-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 720.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.50.0 CPython/3.8.5

File hashes

Hashes for viztracer-0.7.4-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 b223b71bb09f167a3bfb2e3304bd2c6f1e632e70868a2dbcd0a6295d9fd4ac07
MD5 4724ff6d8dc9a16e75c0e873e760b51f
BLAKE2b-256 e3917ca467f2ac9218c7d1cde2f2820dd08b435e851e88c5b90c18a2a1db8870

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.7.4-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 720.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.50.0 CPython/3.8.5

File hashes

Hashes for viztracer-0.7.4-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 d0affb4a21afb64be55e50f35ac843e499e4a353232bd402f9aa09641887f8f8
MD5 c04c6d2a60d07e5e8609bc29276d8a3b
BLAKE2b-256 46d9c63be345635ec35757b836d4849cd1ed03c524ea27a886de03e3e58e386a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.7.4-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 677.8 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.50.0 CPython/3.8.5

File hashes

Hashes for viztracer-0.7.4-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 af579c29236bbfabf652d49c526908ac7a6bfb8609e46afdddf94f0a6dedcdc5
MD5 b600864d82728721499a4ca5a88e61c7
BLAKE2b-256 74b5e2a463905da15061932921251e5fdc8b27f7be303066a72cba8e78bf356e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.7.4-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 681.2 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.50.0 CPython/3.7.9

File hashes

Hashes for viztracer-0.7.4-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 89be1d0494a8e9f0ffa263c52a0789650f0f7683c2021fddc3390ebe3b45c6f9
MD5 9be200cf721d3527e8f857c4a77fa71e
BLAKE2b-256 5a842707274dc5cd57d80e8bba8bc591899da4e34a8cf2de65b39eab880cf707

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.7.4-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 712.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.50.0 CPython/3.8.5

File hashes

Hashes for viztracer-0.7.4-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 a1540abd3f972d9406d0dfc1a0f199ea5d97aa5649b171e1732b94a9cf6885b5
MD5 94752f6b676a6be44a2a1368a49b7ab6
BLAKE2b-256 43b3e6b85f3b83b8e85c02d705e81ca343d275cd567a9773bbd50907d5e10a0d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.7.4-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 712.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.50.0 CPython/3.8.5

File hashes

Hashes for viztracer-0.7.4-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 dd78cb2bdc5ffefbc281e5f022bf2a2dc6f92920c6209af7341cf0d4dc2a733b
MD5 85d7af57671ac07b6ddda4de28d02e42
BLAKE2b-256 0576a84ad7e84fef73a413f49d1b92bbf30d0867a5d6e80cba7d716232550402

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for viztracer-0.7.4-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 750d748e7673cec5bd40e6ab0139a3c98ecb8bf4f3fe0ac830f1d1dbbf388900
MD5 5b479c5a825056bd22f591739e818911
BLAKE2b-256 c086c009ff00542c42316008a49d2480238b35ac266d42338e4a1b6de97bc73e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.7.4-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 681.2 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.50.0 CPython/3.6.8

File hashes

Hashes for viztracer-0.7.4-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 c6c2bf89311e9c17e6c6db5aa7a36b652c2c8b111f8310f552e4f32578a43b4f
MD5 fcdf86d66daac494e512d49424360254
BLAKE2b-256 dfe1fa428fa507fc37c11416d29bea6bff950e09478ddaba53a4daaae76027c7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.7.4-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 711.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.50.0 CPython/3.8.5

File hashes

Hashes for viztracer-0.7.4-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 7d9cdc6aace529829bcac39a92225811be7d44d8e97035a199006cb470e7a161
MD5 20007b6b4add451bc90827553d796c81
BLAKE2b-256 6b7b71c18dae32cc989b3640f177d077949e2a9dac1d9378f49d829f56fe664d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.7.4-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 711.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.50.0 CPython/3.8.5

File hashes

Hashes for viztracer-0.7.4-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 35c1581eb87f81e7811c6351891625d7b9ea1bb2530eaf25fd8b22fe0edea480
MD5 17619cb439015800450e2d32759e44fe
BLAKE2b-256 05ea485f44dd904ef6c856410cda74b7aeb022f5afbb55934a646dcb58b9d08d

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for viztracer-0.7.4-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 25aafebef9276a690a102e4ef04c37234afbccf0fbb4c55eeda62c1a67851919
MD5 7276dd9b36cbc2e8d01cabd70f1fb5f5
BLAKE2b-256 4f2f13eae64500e11f9a0e8f0638ad991f0fd7c5b155a599c1581541ef21ffa9

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