Skip to main content

A debugging and profiling tool that can trace and visualize python code execution

Project description

VizTracer

build flake8 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.

The front-end UI is powered by Perfetto. Use "AWSD" to zoom/navigate. More help can be found in "Support - Controls".

example_img

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
  • Supports threading, multiprocessing, subprocess and async
  • Logs arbitrary function/variable using RegEx without code change
  • Powerful front-end, able to render GB-level trace smoothly
  • 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
A result.json file will be generated, which you can open with vizviewer

vizviewer will host an HTTP server on http://localhost:9001. You can also open your browser and use that address.

If you do not want vizviewer to open the webbrowser automatically, you can use

vizviewer --server_only result.json

If you just need to bring up the trace report once, and do not want the persistent server, use

vizviewer --once result.json
vizviewer result.json
You can also generate standalone html file
viztracer -o result.html my_script.py arg1 arg2

The standalone HTML file is powered by catapult trace viewer which is an old tool Google made and is being replaced by Perfetto gradually.

Catapult trace viewer is sluggish with larger traces and is not actively maintained. It is recommended to use Perfetto instead.

However, if you really need a standalone HTML file, this is the only option. Perfetto does not support standalone files.

You can use vizviewer to open the html file as well, just to make the interface consistent

vizviewer result.html
Or add --open to open the reports right after tracing
viztracer --open my_scripy.py arg1 arg2
viztracer -o result.html --open my_script.py arg1 arg2
modules and console scripts(like flask) are supported as well
viztracer -m your_module
viztracer flask run

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.json") as tracer:
    # Something happens here

Jupyter

If you are using Jupyter, you can use viztracer cell magics.

# You need to load the extension first
%load_ext viztracer
%%viztracer
# Your code after

A VizTracer Report button will appear after the cell and you can click it to view the results

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.

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.

example_img

Refer to multi process docs for details

Async Support

VizTracer supports asyncio natively, but could enhance the report by using --log_async.

example_img

Refer to async docs for details

Remote attach

VizTracer supports remote attach to a process as long as you installed VizTracer on that process.

Refer to remote attach docs

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.13.2.tar.gz (7.2 MB view details)

Uploaded Source

Built Distributions

viztracer-0.13.2-cp39-cp39-win_amd64.whl (7.3 MB view details)

Uploaded CPython 3.9 Windows x86-64

viztracer-0.13.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.3 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

viztracer-0.13.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (7.3 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

viztracer-0.13.2-cp39-cp39-macosx_10_14_x86_64.whl (7.3 MB view details)

Uploaded CPython 3.9 macOS 10.14+ x86-64

viztracer-0.13.2-cp38-cp38-win_amd64.whl (7.3 MB view details)

Uploaded CPython 3.8 Windows x86-64

viztracer-0.13.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.3 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

viztracer-0.13.2-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (7.3 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

viztracer-0.13.2-cp38-cp38-macosx_10_14_x86_64.whl (7.3 MB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

viztracer-0.13.2-cp37-cp37m-win_amd64.whl (7.3 MB view details)

Uploaded CPython 3.7m Windows x86-64

viztracer-0.13.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.3 MB view details)

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

viztracer-0.13.2-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (7.3 MB view details)

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

viztracer-0.13.2-cp37-cp37m-macosx_10_14_x86_64.whl (7.3 MB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

viztracer-0.13.2-cp36-cp36m-win_amd64.whl (7.3 MB view details)

Uploaded CPython 3.6m Windows x86-64

viztracer-0.13.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.3 MB view details)

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

viztracer-0.13.2-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (7.3 MB view details)

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

viztracer-0.13.2-cp36-cp36m-macosx_10_14_x86_64.whl (7.3 MB view details)

Uploaded CPython 3.6m macOS 10.14+ x86-64

File details

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

File metadata

  • Download URL: viztracer-0.13.2.tar.gz
  • Upload date:
  • Size: 7.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.10

File hashes

Hashes for viztracer-0.13.2.tar.gz
Algorithm Hash digest
SHA256 297f704101b92bea7264585822d5040b365b65db528ec948ffee2b4ac2835193
MD5 111cadbd607dca499a3d45c26a53dfb5
BLAKE2b-256 c4445594f571e0795b202c929d4482eabdef9553e18d58d9f62bef3fcde7b225

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.13.2-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 7.3 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for viztracer-0.13.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 91ff87447ae0cdb3cefec899199d31fddb6d539c88f0619488ce1cd0f323305a
MD5 4fde443aa84460e5090f5a87630c234f
BLAKE2b-256 48f1660c0ce958a53e013952e6caaee6bd1d585a46364055660ae99e144fe59b

See more details on using hashes here.

File details

Details for the file viztracer-0.13.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for viztracer-0.13.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4735ce2cc118b54c65cf13ddbf5aa045d93f472e57de193fd1238a6ca0aca86b
MD5 d6df4f39d9d9dee622fc748986a95b11
BLAKE2b-256 770770978e5209eb7d617111a3a673e8193b764a4f21503b0e73053652b1d9e9

See more details on using hashes here.

File details

Details for the file viztracer-0.13.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for viztracer-0.13.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 d400d335928b0e695f459d819b788e32b65b750a60f9abf9edae2e3c1efdd550
MD5 939b6160d3c5c49367d1e17edaf2ced7
BLAKE2b-256 1de5887e4161720f60be878cc08a54316e9f384f6d2bcc3508c942385cc9e48b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.13.2-cp39-cp39-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 7.3 MB
  • Tags: CPython 3.9, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for viztracer-0.13.2-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 37ff2b09ebc296e1e79b18e6679059e722f0e99181c7f1f750b48bbcf4216de0
MD5 b9c31b117fb65226460ad9db98be5cf6
BLAKE2b-256 ce08e36cdcb681695e4f7efafb6b1b278e2c364a8539480acfe7d42c1e49cc81

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.13.2-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 7.3 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.10

File hashes

Hashes for viztracer-0.13.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 ebc57e1a83789169c6c418305befd3da65f60002311bf331094544b228778744
MD5 b49704b4f98691c99d62fc4bf3917bad
BLAKE2b-256 b4e5eb6e6ad76fadf696e772bfa201bbba5177c416d0fffb7e55a8f4ac5fdd80

See more details on using hashes here.

File details

Details for the file viztracer-0.13.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for viztracer-0.13.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3a707f4e019ee0c66763c15452d2d4ec9f86b53069dba38c2c7e035653c02644
MD5 4e961ed4413d52d055d9b865866585fd
BLAKE2b-256 78103338eed7afba910a2fb641e2ccde6c5a5af5cd7a4d245b0de685382b5818

See more details on using hashes here.

File details

Details for the file viztracer-0.13.2-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for viztracer-0.13.2-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 5aeea59261cd2c7af3d40bcd70c85c2f2167dcdb6e0eb6ce4b78302730f09785
MD5 c8b07309d38529033e2d5c3f9dd54d67
BLAKE2b-256 8b8d1b079ac9135c21616157b1dc2b9adb51b3ef1201eaa891d13954168fe1b5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.13.2-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 7.3 MB
  • Tags: CPython 3.8, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.10

File hashes

Hashes for viztracer-0.13.2-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 fdfa0377af6f8ae4b95d1a5ed579e11c768ab69adafd7defd81dc02aba2b3f3a
MD5 b30d02158a951990b2a40baed37857a2
BLAKE2b-256 af857c1445c9b3f0d888399758039c100612815670f0362522e47f4d4e30438d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.13.2-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 7.3 MB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.7.9

File hashes

Hashes for viztracer-0.13.2-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 71aa20216b3011797a22b44adc6a955153991fb5e7d1d10601a0f1590849e0a4
MD5 dfb4bec6e44aa3019229bce54b51f023
BLAKE2b-256 3d3abbbbc4ae61d344f0d2de4ded57688541d40917f353628aaf0d1a5f0ed101

See more details on using hashes here.

File details

Details for the file viztracer-0.13.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for viztracer-0.13.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c0c77e78628f430ed3bc9f8013b71040f0e4cb9b31e0c16434788858c8abbbdd
MD5 188bb863750c0242993ef270a0417731
BLAKE2b-256 d3f09dfbee7e637cc92617bf986db8022eaac34cf8f16841688de5e9d345ae3b

See more details on using hashes here.

File details

Details for the file viztracer-0.13.2-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for viztracer-0.13.2-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 3f344f835ec797ee2f3dc671fe2f6f8be1986bba5cba160460ea316259f49a5e
MD5 526d2b022d6310b8a27d3b77aea91e64
BLAKE2b-256 a8b9b48829282bc7ddc495d0a91053079dcbb3557963e0991eca101d02defbf9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.13.2-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 7.3 MB
  • Tags: CPython 3.7m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.7.10

File hashes

Hashes for viztracer-0.13.2-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 f539131ceaa75bf95e26bead1b60023217de4ab79fca3839b8db201aafb49de0
MD5 71b42d28eb11543576eb004850417b69
BLAKE2b-256 62858c8bbd1a18d5c2b9f403dc83e1a093ba959c215a908101e04b14f69daad5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.13.2-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 7.3 MB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.6.8

File hashes

Hashes for viztracer-0.13.2-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 68fe90dbef3325f76d02e72dde3cf81db708cbf8588ac2a6b74f9a7371d18c10
MD5 53880681eb64d59d5cba32125b53f077
BLAKE2b-256 24a8f3c63643544da5aab193171e57a84153b3b62408bd45d9b19e03acdd422d

See more details on using hashes here.

File details

Details for the file viztracer-0.13.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for viztracer-0.13.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5ee628d8f06fce3a4bac04fffcd6c30e3dd85202f5a4625c5efb6839bd234c09
MD5 1fe6195e3fe0f20ef9de05acd94cac10
BLAKE2b-256 fa5bb9d6464b62758b7d584995edd1a4202294ebd4233d42ed8df7449eabba22

See more details on using hashes here.

File details

Details for the file viztracer-0.13.2-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for viztracer-0.13.2-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 b68f3b236788cb4f45f6974f2ad2d8930f82e9c9b016d22b76c795cac0cf18d2
MD5 40186636624100778ceab19de71d11dd
BLAKE2b-256 261c0c6a06faef5772a07d3031dc87dcbd9947ef7750a16c150688ec8e38b367

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.13.2-cp36-cp36m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 7.3 MB
  • Tags: CPython 3.6m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.6.13

File hashes

Hashes for viztracer-0.13.2-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 b1ede07f4a113fc2993c044d46f8f04f0bf51a53b1163b226df37c3e0299fea9
MD5 01b524d70782e2b6aee3b92ef9993020
BLAKE2b-256 76645f0e642cf9d013b205f7eb00f2ee37355c858a9cbdb48be216c775e684da

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