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

Flamegraph

VizTracer can show flamegraph of traced data.

vizviewer --flamegraph result.json

example_img

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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.9 Windows x86-64

viztracer-0.13.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.4 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

viztracer-0.13.3-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (7.4 MB view details)

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

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

Uploaded CPython 3.8 Windows x86-64

viztracer-0.13.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.4 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

viztracer-0.13.3-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (7.4 MB view details)

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

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

Uploaded CPython 3.7m Windows x86-64

viztracer-0.13.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.4 MB view details)

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

viztracer-0.13.3-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (7.4 MB view details)

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

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

Uploaded CPython 3.6m Windows x86-64

viztracer-0.13.3-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.3-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.3-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.3.tar.gz.

File metadata

  • Download URL: viztracer-0.13.3.tar.gz
  • Upload date:
  • Size: 7.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.3.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.3.tar.gz
Algorithm Hash digest
SHA256 9253dbafc9fc1ef7dfe75b73072178d562de33529848f637eb33c3480a90ee82
MD5 b5c1d2ef4efe127ea9041bb8bb98a7c4
BLAKE2b-256 30e453ee236ab932cc4c022bd1149981237c0be78d464f62f5da717f75fca0b9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.13.3-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.3.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.3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 b9680f3a2c9a8a0a509d0074ce73499145abe582edf4906d1c00a130fdff021c
MD5 8da066db3ef4d40620fc1a38e165e778
BLAKE2b-256 c8219d419a35b6c2943f1748874b0070979d29f2dfee1ffc861eabab85aaee88

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for viztracer-0.13.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fcb7aa345ea3acbaa5d7bcdd44ad0bb8fa7d696882917ca2460737ea7768ba3c
MD5 c5aa4a332a84557921297561a147dc43
BLAKE2b-256 56283743e4ba47992904008962e20500ad6b7a39b04220bc07e80d9d69702f31

See more details on using hashes here.

File details

Details for the file viztracer-0.13.3-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.3-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 03487f5a4e4aee1eb49acf51bebbac74592fda04e963dd5cea378b14e20677cd
MD5 0f4ca714082f3fd68da195ce931904cb
BLAKE2b-256 6231cbedfeb1a038a3a04652f1ac7b1b4d8358ca0613ad9148ef5837f7164c77

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.13.3-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.3.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.3-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 450f4e08e737e5b91d5fab58cbc824361ff878187ac69e81a8acea515d728246
MD5 29cffe875ac307489570b345b9f84007
BLAKE2b-256 fb6f79b5a728c397d2f8ec7d0d9d99c7d04c86e20a05eb3c61d5750d4e8e7699

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.13.3-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.3.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.3-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 ef9378eee88d30355fdce49245e99c396be249d792d911c591247761c91a78bf
MD5 594ace936cd7c896753d050c30baec40
BLAKE2b-256 48c6b729f98226f7686533c790467ebb8d7c7f60e8bf917f5c45b25395697b7d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for viztracer-0.13.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 09fea1c9c317da2651a1facf0052a13240d355bf611e1b72e90672fd9ddc479f
MD5 e8d422b86d13566a5af882f08dd080ba
BLAKE2b-256 cfdd46ab0d56b6c2cdc08716bc63f7c352b62ff0b882cc1121515d43480f852f

See more details on using hashes here.

File details

Details for the file viztracer-0.13.3-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.3-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 ca548dddb382561623bca9cf83d324801fef38d289000ddad333d74f2b4dbc35
MD5 dbe5e9760d76d17f6d33896de103fd3b
BLAKE2b-256 558b5dc57351388a2770b570e8f056f1f55994d910d35566cb223b787f375023

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.13.3-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.3.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.3-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 d369e84f57161a99bb1b8e1e9af61fbf85a768e781e03dc28ea6b306e06e4413
MD5 6e2a29770869f09b6f813093b1a1b5a1
BLAKE2b-256 962ff27f5b0360f3bdc5791937612855cc5d00b850aadf98fe567d3d62888c76

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.13.3-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.3-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 e2034e24925ad7be50ce39d0864fa2bedca1a96bc2631cd3c6366289f775b9a1
MD5 a821c0fa2130dc90fc4982d44a6fc9dd
BLAKE2b-256 49171927da360aa08f2cfd4db5a25d2818de46693c734939374969661d4bf270

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for viztracer-0.13.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8c3c7d096fbab6afa228f438bce2b0e612b22d3f3d68adb79a76704d963001d9
MD5 4a1f17237c49684a518700302facab8c
BLAKE2b-256 de6cbc38e16932470688a5c02a96f6cc8e55b8306c7907c71f29c697f18f5ae1

See more details on using hashes here.

File details

Details for the file viztracer-0.13.3-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.3-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 ebd2f0047df6e612ddb69bace6e21072762a326a1d2fd4c092620def8c413682
MD5 28fc280d85f25548c4ff606c424e3882
BLAKE2b-256 6861b0b0cd2c696c0d33f785e0c0a1500a37fabe35afd42c2ddbc60e4db2ef5b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.13.3-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.3.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.3-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 6cbd4d2327dbea8dd37b1108d057204a5bd0b47544dfc006e60d8ab14edcc670
MD5 7b23f1bd3ec8f30165948834b3dac7c5
BLAKE2b-256 dbb8334d67ff47abab4b6e01872c5a0174964d16adb4f0130fabbad05a0677a7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.13.3-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.3.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.3-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 d0361e07d788b3c3d9d699c91c6e2efb175732bbb0f1a9f954da2aaebf3dee27
MD5 6caab4f04ca83f32940268f30db94d19
BLAKE2b-256 849fd06ef89bec86c5142634ca389dc32272b0eed1141031d4ee58950d0f3379

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for viztracer-0.13.3-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 16b0feccda42e235b7bf9383ab182de099f94c4423c18cdd01ed2fc62eb96736
MD5 708feef8ae9c5c28c708f04d910d9ed0
BLAKE2b-256 6c6073eb1431ced15e578b192c21c4262b4e88f6912e43b0e7662cf216d998f1

See more details on using hashes here.

File details

Details for the file viztracer-0.13.3-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.3-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 9af8661eb144bc4af767e3761949248893bacfdd07c6f803772ac94801be90d2
MD5 22abc0063df2f3b8571a31ed0433879c
BLAKE2b-256 d285b4bb9a522caeb8e6bf6533e22e8e3d170fdca360a88aa714a73dfd4409ec

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.13.3-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.3.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.3-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 10263986e44ed42136f241cecd4aa7d572b59080f2629fd73b8d21db4a035efe
MD5 fa36cc92871e7ebb38cbd6ee425e1b83
BLAKE2b-256 94d725ddb6532465af41392d9a2cb042cc50fd7dd46ce03164c971e7b1b6cd17

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