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 result.json

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

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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.9 Windows x86-64

viztracer-0.13.0-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.0-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.0-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.0-cp38-cp38-win_amd64.whl (7.3 MB view details)

Uploaded CPython 3.8 Windows x86-64

viztracer-0.13.0-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.0-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.0-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.0-cp37-cp37m-win_amd64.whl (7.3 MB view details)

Uploaded CPython 3.7m Windows x86-64

viztracer-0.13.0-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.0-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.0-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.0-cp36-cp36m-win_amd64.whl (7.3 MB view details)

Uploaded CPython 3.6m Windows x86-64

viztracer-0.13.0-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.0-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.0-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.0.tar.gz.

File metadata

  • Download URL: viztracer-0.13.0.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.60.0 CPython/3.8.10

File hashes

Hashes for viztracer-0.13.0.tar.gz
Algorithm Hash digest
SHA256 1eb76bc74e0a11d494666bda3253618cdfeffbd42959d7f730b5e62025ca0c2a
MD5 b505b758afc4dafc0b9832355cf2609c
BLAKE2b-256 507585a8f66e623afbc1cc3e3ba3ff49f3e25fbbc3dedc61986998fbe36def59

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.13.0-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.60.0 CPython/3.9.5

File hashes

Hashes for viztracer-0.13.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 f72e2de2951dfa588e66affef591fce555fa9889589b8ee39e44efa6a6d90373
MD5 4bb55f0cba3597b351fea37f50d11007
BLAKE2b-256 e81425be68e1dbcb2f426a2af922862953c7116b9db790ab5995ed2b7a81a8d8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for viztracer-0.13.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c3334183472d52fa786f42e300c65af8406807b470f76e95f4d86b848d7514aa
MD5 c3c41c0f6454243504cd3b977aea8610
BLAKE2b-256 8424204f4efc0728e3d5d06b2080c3e42474885bc518d92bcd8341ba54a4902e

See more details on using hashes here.

File details

Details for the file viztracer-0.13.0-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.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 955a92197b13b045dfdab7ca0a9680179309db42307c8acfcf43db7c762fe31b
MD5 16b73ddc299303979ccf6b1fed6ce45f
BLAKE2b-256 1927b58760d8d1d72603790f0c3d5e9821089240023351be7998c8267acdfd8e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.13.0-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.60.0 CPython/3.9.5

File hashes

Hashes for viztracer-0.13.0-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 381a786d8ce64c75235e360f90ecf006db4731ccc10eaf3f580cc4cc0b873642
MD5 7394e4842f6529d1df39cc9caae4d7e2
BLAKE2b-256 5fe942e5b0ea37a96a3da84b2c86cc3ef11d826dfbd41f5091120c0bb7a8d277

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.13.0-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.60.0 CPython/3.8.10

File hashes

Hashes for viztracer-0.13.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 728c1655b0b278d335126dd95e71e3d4e6827a0731a75b278fd47ea5dfbe9042
MD5 15a9ea711744ca84f93fbda7ddc55462
BLAKE2b-256 396cf1b602dcb0abce513218120a8c113313d99b63cf4a2a3882551312a25570

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for viztracer-0.13.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6862c2268b898b0daa41d86a123a0e03c1cdb00b7baf477aabd595989fe18ade
MD5 2de5ba06acfa62858e0ce6cf7e9478dc
BLAKE2b-256 c5018ece1a8dff00c7c6a3e03e28f222fc521725937428aa39ad0aacb4f6ee0c

See more details on using hashes here.

File details

Details for the file viztracer-0.13.0-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.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 0e9626dad01662be41593645d50fc0495fbb63a6837a68ab86c5c60009c85e85
MD5 53cfc981d32ff74deac3c5b50e98f589
BLAKE2b-256 5d4a010449da6ac90c928b2d852857ac0bce3058b9ae086e47f6f5bed6f5af65

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.13.0-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.60.0 CPython/3.8.10

File hashes

Hashes for viztracer-0.13.0-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 ce28589405a1522124c9ca76ec57310a421858578d15f51477c9b28ba58f624e
MD5 c8c3370ea0ea4fd99f8fd429c29df107
BLAKE2b-256 81935c24200e8e2f47b2cf222ba4c90d86d5babd80a6f5731aff3a6b086ed4bb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.13.0-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.60.0 CPython/3.7.9

File hashes

Hashes for viztracer-0.13.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 61eadf6349d87e2ff876c23a60c37ed4f580e3a8789f973c0c6f398d31a75028
MD5 064679a24efcfac8d2a2da68b672b448
BLAKE2b-256 9152b579411b54c5ba9dcb82dcaa88412f5d70232dfce4de6cf37d107e803860

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for viztracer-0.13.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bfe28b7a00284d9496b5e226bbf341e0d6ac1c1ef5ece2dec6a51bbff5187ea6
MD5 86cdb0e752ea094c3b4db5670c351ea7
BLAKE2b-256 c38b6ca507a0a2f8bdf8863b2c9c3a11bbfb8166f737da704b7c1f1b081689f1

See more details on using hashes here.

File details

Details for the file viztracer-0.13.0-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.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 6c105b610ddace4c3af0ea980888d82c2b156cc6e5171b84094ad6305b12ac56
MD5 79a2077735505543335fbe5510ac7ab2
BLAKE2b-256 424c5c42907ac2163c0c360284bf318d76a2b910ff6c91d900a3512b6c1c5a05

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.13.0-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.60.0 CPython/3.7.10

File hashes

Hashes for viztracer-0.13.0-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 166d89a8a11e13e5ebc9c7679683c2f3af3539b36d9a39fe4bd4d3fcabc50aca
MD5 8935530fa1d984458f5bde828e836411
BLAKE2b-256 3f49b47d67125c6efe3964d279efb7fde9ee78afd56413733e9bb393f024862c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.13.0-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.60.0 CPython/3.6.8

File hashes

Hashes for viztracer-0.13.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 b09c2cc16a8978edab89b88ebde2f1f638aaa7a28261c46a7e8269ad734ec7ff
MD5 8b0fc4eddbc9a78d3b73581b3d46167a
BLAKE2b-256 2e8017388731555f14d51c4f870e53de435c5c483200710a5219610ccf7a1427

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for viztracer-0.13.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9bf7f7b7548911b3234cdd406ae7a69747897af982392d29edfe56171567fa8d
MD5 f3074d27d49b0c3e728e3b7b8187766d
BLAKE2b-256 296e17283c25633debb80e119f8b84210f93b0715b8296e78ac67187c6cf3d02

See more details on using hashes here.

File details

Details for the file viztracer-0.13.0-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.0-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 6819e09007e7dd6d2e5ff8260fe1f1f12bba3a0009dbb94bbc78a837d1081fe4
MD5 55ccef813f56d4811b64cb72f3ec58a9
BLAKE2b-256 a700ce71a53a9203b54d178cf4f44dd57c37f312e4a40fdb5d127c686614af1c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.13.0-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.60.0 CPython/3.6.13

File hashes

Hashes for viztracer-0.13.0-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 2c1818307da4898221c38946d583849bf8efde0a43e695ff149a339c3791d57c
MD5 faf8dffb7ccc88953f2dfe0cdcbd864b
BLAKE2b-256 3226fc0a67769215f317fb44e5e2f3b170f57997049cec4ec686117ecff692bc

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