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 twitter

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. Use "AWSD" to zoom/navigate. More help can be found by clicking "?" on the top right corner.

example_img

trace viewer is used to display the stand alone html data.

Highlights

  • Detailed function entry/exit information on timeline with source code
  • Super easy to use, no source code change for most features, no package dependency
  • Optional function filter to ignore functions you are not interested
  • Custom events to log and track arbitrary data through time
  • Log arbitrary function/variable using RegEx without code change
  • 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.py 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(use AWSD to navigate/zoom).

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 supports subprocess with --log_subprocess and multiprocessing or os.fork() with --log_multiprocess. For more general multi-process cases, VizTracer can support with some extra steps.

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

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

viztracer-0.10.0-cp39-cp39-win_amd64.whl (688.4 kB view details)

Uploaded CPython 3.9Windows x86-64

viztracer-0.10.0-cp39-cp39-manylinux2014_x86_64.whl (725.7 kB view details)

Uploaded CPython 3.9

viztracer-0.10.0-cp39-cp39-macosx_10_14_x86_64.whl (684.7 kB view details)

Uploaded CPython 3.9macOS 10.14+ x86-64

viztracer-0.10.0-cp38-cp38-win_amd64.whl (688.4 kB view details)

Uploaded CPython 3.8Windows x86-64

viztracer-0.10.0-cp38-cp38-manylinux2014_x86_64.whl (732.2 kB view details)

Uploaded CPython 3.8

viztracer-0.10.0-cp38-cp38-macosx_10_14_x86_64.whl (684.7 kB view details)

Uploaded CPython 3.8macOS 10.14+ x86-64

viztracer-0.10.0-cp37-cp37m-win_amd64.whl (688.3 kB view details)

Uploaded CPython 3.7mWindows x86-64

viztracer-0.10.0-cp37-cp37m-manylinux2014_x86_64.whl (722.0 kB view details)

Uploaded CPython 3.7m

viztracer-0.10.0-cp37-cp37m-macosx_10_14_x86_64.whl (684.6 kB view details)

Uploaded CPython 3.7mmacOS 10.14+ x86-64

viztracer-0.10.0-cp36-cp36m-win_amd64.whl (688.3 kB view details)

Uploaded CPython 3.6mWindows x86-64

viztracer-0.10.0-cp36-cp36m-manylinux2014_x86_64.whl (721.1 kB view details)

Uploaded CPython 3.6m

viztracer-0.10.0-cp36-cp36m-macosx_10_14_x86_64.whl (684.6 kB view details)

Uploaded CPython 3.6mmacOS 10.14+ x86-64

File details

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

File metadata

  • Download URL: viztracer-0.10.0.tar.gz
  • Upload date:
  • Size: 678.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for viztracer-0.10.0.tar.gz
Algorithm Hash digest
SHA256 a75a836430bf4c4e39890650a5ad855b3dc695ba855006c02633cc9b4f8645f4
MD5 9a9a6c45f19c848f43d6c5ac4b6b88f2
BLAKE2b-256 f85dceeed8a0b3602f18cd3e7195a51dc5afcf9fc370433c3a18eacbecf72616

See more details on using hashes here.

File details

Details for the file viztracer-0.10.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: viztracer-0.10.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 688.4 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

File hashes

Hashes for viztracer-0.10.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 782ba0472f0170398f9d1e5cc9f0edf432aa88f1065b2a8b1f45fd5f890ef3ae
MD5 f4d38f2cad1b5979444bf8f2558a5886
BLAKE2b-256 09a299afd5d2926d3ad147fd6e383d16129e80e54e8d9dfec26feeaaf95a703f

See more details on using hashes here.

File details

Details for the file viztracer-0.10.0-cp39-cp39-manylinux2014_x86_64.whl.

File metadata

  • Download URL: viztracer-0.10.0-cp39-cp39-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 725.7 kB
  • Tags: CPython 3.9
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for viztracer-0.10.0-cp39-cp39-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 92695d13ba9968796daeb275902902854c03f2a874741fc769a42bb6a974f0cb
MD5 565ce085851a45b82ccdd7a72acd8f09
BLAKE2b-256 e15a9c7b16d877c11322c48a0a93843093aa1c7f3675568c268674e0f7098830

See more details on using hashes here.

File details

Details for the file viztracer-0.10.0-cp39-cp39-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: viztracer-0.10.0-cp39-cp39-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 684.7 kB
  • Tags: CPython 3.9, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

File hashes

Hashes for viztracer-0.10.0-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 8ac79cb1db3b3e5335dfee1bfd16ab378283dcd94578f0364da87a405c88cebe
MD5 cbbe295dec2264f5585b82c4e7f97a35
BLAKE2b-256 7a4c7220bdb0aeef36bb4090cdf539eb39623fc233439d894c02333ad04db23e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.10.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 688.4 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for viztracer-0.10.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 7ac42610a33461fb6f4df932059667042d0a7786e9976957b206dda307afdfd2
MD5 c77e46ceb4567f3c618a69332fa45dfc
BLAKE2b-256 2693f8362937794f05185b7540208fc0b148a481544224884e0c0fb7aa0e5d28

See more details on using hashes here.

File details

Details for the file viztracer-0.10.0-cp38-cp38-manylinux2014_x86_64.whl.

File metadata

  • Download URL: viztracer-0.10.0-cp38-cp38-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 732.2 kB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for viztracer-0.10.0-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ec4cf268f1f242b1eb914c1d5eddb1202a2e2eb6353d7edd3edb44ff04ce699f
MD5 6be831c788404bc504310b8d335f132b
BLAKE2b-256 7f5683489286a13c62385170e3c5c2af61dd434a1224a7e02fda32bcf07eda4f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.10.0-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 684.7 kB
  • Tags: CPython 3.8, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for viztracer-0.10.0-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 e62b0274036ebd0a8ac3e45e06f23bd2b23e25541b3a5b1e0af4b71ca03f2bf3
MD5 e6e9e46804989b2f8c7665062af6dc80
BLAKE2b-256 f6501a42d9b449491628b454dcce7b3f7056cd54001ac5ddc1417da44674e1b5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.10.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 688.3 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.9

File hashes

Hashes for viztracer-0.10.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 95782f5db8b1cd7bc11bde5f401d4d5e373c90cf83770118e9ebf5640fe69c30
MD5 b218150b49802716f41df5f94653197c
BLAKE2b-256 476246a1b9b2d3765f913ae2f7676177f48984c270dab853f4d66a9d449cbdb8

See more details on using hashes here.

File details

Details for the file viztracer-0.10.0-cp37-cp37m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: viztracer-0.10.0-cp37-cp37m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 722.0 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for viztracer-0.10.0-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9f5073ad85510c3d7bcc6e7c82062e55288afab0aa3dc1500a67935d6cc48757
MD5 c88ff644d25b04e84c32bb146f044658
BLAKE2b-256 e2b7a5bac45d394a2d1a1f5dffa8a31819bdd7176c31945c73cb51c50d4eb6b6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.10.0-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 684.6 kB
  • Tags: CPython 3.7m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.9

File hashes

Hashes for viztracer-0.10.0-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 f86a66d9113e38944c3c5d06b2c8ff3332ef88a5e356693ac53ac3a97b7c8073
MD5 1f262f5a67e970028ddbe0e34755450a
BLAKE2b-256 d92d73df306800d69dd609d9cccb9be09fccf3b68f5e3d47f988cfe23b895945

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.10.0-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 688.3 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.6.8

File hashes

Hashes for viztracer-0.10.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 89e167a0642177d3602b37d6a6a631b4a28be9c80828ace5c5b8b3e846629828
MD5 bde1c167f2a4cf55269d98f2250a48b5
BLAKE2b-256 ff8dc2ace18b00cee91c8a5ebd12e2569e2c10f8e74f59ffecac2a9c9b888e40

See more details on using hashes here.

File details

Details for the file viztracer-0.10.0-cp36-cp36m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: viztracer-0.10.0-cp36-cp36m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 721.1 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for viztracer-0.10.0-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 73e1da9e8a52c6a265afb4cf65c1f02e8682a7e28f9948b71dd3b8bc1f5971b3
MD5 4e45a9c187f62d083996088f29d65386
BLAKE2b-256 72a928c9d34845e00a499ac62c7dd3f061b4b984980d597de0db697c93f0807e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.10.0-cp36-cp36m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 684.6 kB
  • Tags: CPython 3.6m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.6.12

File hashes

Hashes for viztracer-0.10.0-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 9a5a8e3d98783aad09d56e95d84aeb7bbb5a0e7dd6b7938ac4967cedb5fd4b93
MD5 dbd02c6bb2f9bccaa1aa78337d9b5d86
BLAKE2b-256 a3f6d97fa4490156b99da1e6c64558b4efda2aaa13a11e5aa7bd80d77c118fcb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page