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

Uploaded Source

Built Distributions

viztracer-0.13.4-cp39-cp39-win_amd64.whl (7.7 MB view details)

Uploaded CPython 3.9 Windows x86-64

viztracer-0.13.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.7 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

viztracer-0.13.4-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (7.7 MB view details)

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

viztracer-0.13.4-cp39-cp39-macosx_10_14_x86_64.whl (7.6 MB view details)

Uploaded CPython 3.9 macOS 10.14+ x86-64

viztracer-0.13.4-cp38-cp38-win_amd64.whl (7.7 MB view details)

Uploaded CPython 3.8 Windows x86-64

viztracer-0.13.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.7 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

viztracer-0.13.4-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (7.7 MB view details)

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

viztracer-0.13.4-cp38-cp38-macosx_10_14_x86_64.whl (7.6 MB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

viztracer-0.13.4-cp37-cp37m-win_amd64.whl (7.7 MB view details)

Uploaded CPython 3.7m Windows x86-64

viztracer-0.13.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.7 MB view details)

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

viztracer-0.13.4-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (7.7 MB view details)

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

viztracer-0.13.4-cp37-cp37m-macosx_10_14_x86_64.whl (7.6 MB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

viztracer-0.13.4-cp36-cp36m-win_amd64.whl (7.7 MB view details)

Uploaded CPython 3.6m Windows x86-64

viztracer-0.13.4-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.7 MB view details)

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

viztracer-0.13.4-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (7.7 MB view details)

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

viztracer-0.13.4-cp36-cp36m-macosx_10_14_x86_64.whl (7.6 MB view details)

Uploaded CPython 3.6m macOS 10.14+ x86-64

File details

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

File metadata

  • Download URL: viztracer-0.13.4.tar.gz
  • Upload date:
  • Size: 7.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 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.4.tar.gz
Algorithm Hash digest
SHA256 5703be90b7dab22bde2e9e2ee4cee140b866c6182c899544f8f28b7f970e224d
MD5 98cb24b9e8ac3e2ca1d057f7ac9128c5
BLAKE2b-256 b3959e3207115455ea6b63718e596ec4316cc2808b051045f2981c29af98928e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.13.4-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 7.7 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 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.4-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 679ffca71f32281e6a6c24662e5bb3ffe377c8237d915958ef04e9cbdbcfca6a
MD5 00e36150a6b4427c3870fe8ee3dfbe0d
BLAKE2b-256 1bd6e1ba67d3344bb53d876141b454fd084d8a12aa242bb2d6502dff2700720b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for viztracer-0.13.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1930954e7a4e071612db92a60fd560f24108625c22639fd7a92817be4221cd6b
MD5 140bca2ebf6ef9617b8469282f21e903
BLAKE2b-256 502ed3cf1aee28acd8f9cda64f84b93789ba17bf640ce478552872e577dd7fe0

See more details on using hashes here.

File details

Details for the file viztracer-0.13.4-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.4-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 f349062b45eb74617ef7cdab03f2b7f8e96d44c4734be850c9da89eabf04d36a
MD5 f7cc2b97432000a94f80da167718dab1
BLAKE2b-256 45f4428100504f86e1dc3857eb73c157fac7cf04335febbfddcd242df6163a9b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.13.4-cp39-cp39-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 7.6 MB
  • Tags: CPython 3.9, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 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.4-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 d2774b40ecf457363bc54e875eaf209051e4a4840336f487f8bd7079dbba614b
MD5 a5b8e8cd09b1b2c90a1552e8b7518fba
BLAKE2b-256 797365083acbcb1e67379fc9420dac053f5e55508c18e0c829e04ad263f48972

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.13.4-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 7.7 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 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.4-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 9e49bf1b9ba056281448c09f23bbf21c65b1210480a542a5d257e0d0620c4dc8
MD5 cf38542354ea0925d85b2973f45c3191
BLAKE2b-256 08701993b8adf4afeaaca158bd4f5353f78a1921885a974cf1b0a4925e2b0272

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for viztracer-0.13.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 de4a650b4ed8edf52eeba58abb881abdf7ca7710ed290a7c6de9c75916a652eb
MD5 5fd37abc162faa643b404e62e1f6ed8a
BLAKE2b-256 8b52c851263cf8dbf2f84b33e59a5899d45d8ed02df99c0909cb97ae2801637c

See more details on using hashes here.

File details

Details for the file viztracer-0.13.4-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.4-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 08f66b002d6af072a4550d6d8b56ff5ae36b21f3054c27a5ce8fc4f0e73c88cf
MD5 7a17eefac1ea5316515d3ace7527ba12
BLAKE2b-256 75cb2c502d39ba2d843b94c80bae8fb8364a66199e9d1687202b4484efdd43bb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.13.4-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 7.6 MB
  • Tags: CPython 3.8, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 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.4-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 03c6e43570dc3c3ba33375ecec9500daeb30c6aee240090e6bb098e9be545e69
MD5 7979dc373761bb6e9d84b4dac6723bb1
BLAKE2b-256 838470f6238309765674fe1c49cf2a4c1d5a6f71996b3fa5f6393e9000f405f7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.13.4-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 7.7 MB
  • Tags: CPython 3.7m, 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.7.9

File hashes

Hashes for viztracer-0.13.4-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 57f2b6dc41f588406a1e9ee44eaf866347c5c859421cb63912fc7d1935cc2931
MD5 cf06805487490868c5850c2f37155385
BLAKE2b-256 3080bfce3cb6e6a514f6ad5ec64906d8ab1353c9932913adb59e77f50d5a8fd1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for viztracer-0.13.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0602f53a4de26e3877079cee9a69b6519419e8450174cb83c82754f264613851
MD5 84129e957d4c25ec63b79b98bacdf3f7
BLAKE2b-256 f53f2b653cf2a74f16c1023b6ee60b5894d63eb0caaee1cd7de0b8a1b0d7ec0d

See more details on using hashes here.

File details

Details for the file viztracer-0.13.4-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.4-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 f7e995e9aeaf54e39405c8c5cee471f7bd2b70f4a97d8d8328f9b1afeef83cf8
MD5 c9fc7b92bbb153665ad72e9a4a3f5e33
BLAKE2b-256 206d5f793c4f8f2b432dc98a61fb24ec424125afed140b0d901c37b151679cc6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.13.4-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 7.6 MB
  • Tags: CPython 3.7m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 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.4-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 ea5b2a7e0eb9b019b02e34581b5c38d3871c62ca5641c42dbea08b590960811b
MD5 42590f32693a05c830490e912cca6680
BLAKE2b-256 4ba149c47d73ba19df0dc490570375dd35a61b677297d364da53c64b50f2110e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.13.4-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 7.7 MB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 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.4-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 13a8e51a5dcb172e563f191d80e4816352f571e66a4b5436d9c7104d25bae772
MD5 9b22e855ea5f7cf3cb945a92a173dae1
BLAKE2b-256 6194870a8a8bbedecb91a7f2d12b4e90a3bb6a3b25aea6a6fe6ac8f235c8610e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for viztracer-0.13.4-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2c1e5786de9cb9ed7160b62027bb0d2f1199830bb5aa4a8ec7b8ecfe872c7252
MD5 229873edad9a521cd4359e9a2934a313
BLAKE2b-256 ffa2df31852a0327b1564f53d7413dab6156bdbdd21b630a78578ceb9c312a6c

See more details on using hashes here.

File details

Details for the file viztracer-0.13.4-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.4-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 b75f18378bc7593daf26d08b4db32aa341f742d9abe13dd16f4142537a715471
MD5 6bf075591148f52d4ed76149873b5750
BLAKE2b-256 23898cb4fd94667c50f1a7ffdb7a2256644cac9d05d40407335fdf30dbe8cc3c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.13.4-cp36-cp36m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 7.6 MB
  • Tags: CPython 3.6m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 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.4-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 25ed1638db08c0c663ec7a3ce6a857ce268f6db19b8c3629766fceab9a52cc8e
MD5 a0d182e84dcad3e3ddb79a883d449e72
BLAKE2b-256 f5e662b21115a7d5d70a5db08c8c0c5c36adb5e0ad91dc2634ac03f0486b6cc7

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