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, multiprocessing and os.fork() out of the box.

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

Uploaded Source

Built Distributions

viztracer-0.14.1-cp310-cp310-win_amd64.whl (8.2 MB view details)

Uploaded CPython 3.10 Windows x86-64

viztracer-0.14.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.2 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

viztracer-0.14.1-cp310-cp310-macosx_10_14_x86_64.whl (8.2 MB view details)

Uploaded CPython 3.10 macOS 10.14+ x86-64

viztracer-0.14.1-cp39-cp39-win_amd64.whl (8.2 MB view details)

Uploaded CPython 3.9 Windows x86-64

viztracer-0.14.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.2 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

viztracer-0.14.1-cp39-cp39-macosx_10_14_x86_64.whl (8.2 MB view details)

Uploaded CPython 3.9 macOS 10.14+ x86-64

viztracer-0.14.1-cp38-cp38-win_amd64.whl (8.2 MB view details)

Uploaded CPython 3.8 Windows x86-64

viztracer-0.14.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.2 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

viztracer-0.14.1-cp38-cp38-macosx_10_14_x86_64.whl (8.2 MB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

viztracer-0.14.1-cp37-cp37m-win_amd64.whl (8.2 MB view details)

Uploaded CPython 3.7m Windows x86-64

viztracer-0.14.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.2 MB view details)

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

viztracer-0.14.1-cp37-cp37m-macosx_10_14_x86_64.whl (8.2 MB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

viztracer-0.14.1-cp36-cp36m-win_amd64.whl (8.2 MB view details)

Uploaded CPython 3.6m Windows x86-64

viztracer-0.14.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.2 MB view details)

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

viztracer-0.14.1-cp36-cp36m-macosx_10_14_x86_64.whl (8.2 MB view details)

Uploaded CPython 3.6m macOS 10.14+ x86-64

File details

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

File metadata

  • Download URL: viztracer-0.14.1.tar.gz
  • Upload date:
  • Size: 8.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for viztracer-0.14.1.tar.gz
Algorithm Hash digest
SHA256 3d5723175b9dceeead8e63f0655231b75a4bc2ef8521bc84a0dd8fe44419087c
MD5 e7856335d4b64cdd21d43237df01bf4d
BLAKE2b-256 87c552e09091002b6300888f95fa4e77c2ee05283659ef0fe17a2edbbada097d

See more details on using hashes here.

File details

Details for the file viztracer-0.14.1-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: viztracer-0.14.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 8.2 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for viztracer-0.14.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b4823c099254cd2b167d1c0629a7e3f498b9a24461875b2c6c8318ea79caa48a
MD5 9626099fe0e5f64183ac82455dcd413d
BLAKE2b-256 52042a8582e537d608732a7e44512ef2890c83d1192ad7b7c619356e9f94c378

See more details on using hashes here.

File details

Details for the file viztracer-0.14.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for viztracer-0.14.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 38c7786f81e8843340eab99e9159930fb0cc60d29bd70ecef401bf33572177f4
MD5 f5bdf20b9e2a78d6d37e6e8d8a8d4174
BLAKE2b-256 d4e420d231416ed7bcb594c0559894d552446a7a2838bafd78fa6ca45774c974

See more details on using hashes here.

File details

Details for the file viztracer-0.14.1-cp310-cp310-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: viztracer-0.14.1-cp310-cp310-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 8.2 MB
  • Tags: CPython 3.10, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for viztracer-0.14.1-cp310-cp310-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 2e1d6b31724f758c8388a564e3c62094bb3fdfeed2c7d1c64516714a19e614c1
MD5 74937acd50d82728c3c8c8ad3d1226b4
BLAKE2b-256 b91af178264544cd41e50996b1e3d68021707f7d6f6de1375b303957b065be2a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.14.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 8.2 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for viztracer-0.14.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 d92ddaa3e824b6273d1d417ef8ec513f62d9b27788a48b0c4fe1948df5255d78
MD5 3662205d91a1d1d51b7b053b630de7c8
BLAKE2b-256 e6c7b193592bf60ead02c8a8780634e02dfb6cf63cf0f8a253317c1be7d13def

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for viztracer-0.14.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d5dc837e128d2a0b7c8b2978cfc82fa788f379f6089895d845af159887f9215e
MD5 9d8a27bef9eae1e607cc45f0961ac810
BLAKE2b-256 abe5ad7fab4151e9bf91d9c1e3a33ccbd88e601405f615267799f742b36acf73

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.14.1-cp39-cp39-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 8.2 MB
  • Tags: CPython 3.9, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for viztracer-0.14.1-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 16018cd0ceeec7c41a94afdf829b469f17835f27e3bf2d0edea33576385eb3a9
MD5 6f1539476ac9ff1a1414eac6424a37f5
BLAKE2b-256 1507858258083486a0bdff370a8690df69efd30aae92e5c9f000bb9c989bea7c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.14.1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 8.2 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for viztracer-0.14.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 12408f93cf042a1d6bf45f612ed7d8fc5c3db4140afd52431d2cabe7dc28ec37
MD5 bed70b92cf938d3cc717bf2febf0eb3a
BLAKE2b-256 c0813c0f8b01a764ec72923e70981b52e1aef6ce627ebff13f445807e65a0fdb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for viztracer-0.14.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c237a97cd4f2da6e8086858212b9dbc3bdf5513b84e2c795b13a5bf521906e04
MD5 25da9f73c7f3bd6b548e2cce6277f60f
BLAKE2b-256 1339f651b9742d0015cf143e160a516801105f24d2a6b5dee30d2cfa65b5503f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.14.1-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 8.2 MB
  • Tags: CPython 3.8, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for viztracer-0.14.1-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 c9cba0e0ec25bb8b9aed40fc844cb95830bc9556e3504bc24fc43a7b3434e5a4
MD5 02d27ca826eb220fa971e172f65b39a8
BLAKE2b-256 bd42e896d09633ee40ecc3868176b8d71a1642e1a8a84654e60f657ff279bd6d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.14.1-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 8.2 MB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.9

File hashes

Hashes for viztracer-0.14.1-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 9e3ea2061ea65ec97c2313d467a5afd61bf91ef23dc56687adc823767508dc57
MD5 49662dd07cfb594989ac09c68c9c8628
BLAKE2b-256 184a96994fb6ee7c98705fdeddfc9873660aedfaada7d4b5bf55687bdd69dcc1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for viztracer-0.14.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dd54b4ec9081e179fa71d7011cc43b50ac92a48dc3b90aced64cdc002a759292
MD5 f3b85e91e59f63abdd65cc6db0f3f79b
BLAKE2b-256 3069a1c7e4d4020276f15d6f1ae59bfc7d6a7d808293cb8c62ab849d0c6bd13e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.14.1-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 8.2 MB
  • Tags: CPython 3.7m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.12

File hashes

Hashes for viztracer-0.14.1-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 0fa6bda23da7f0840a2390d8c364dbf928ec1bcaca604c45c286af1ee4297409
MD5 042b413fb6737231387280b88612839c
BLAKE2b-256 970aae14c789bd47f756a9c14936f48a2eb1c9f6214dda538d77d6742e99c5b1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.14.1-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 8.2 MB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.8

File hashes

Hashes for viztracer-0.14.1-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 511338e7d67c7f975400d014b11d1a8f9353beab163a6c33d8b97db921e3fa8e
MD5 f98bd8daed66ae54ee064d8f680916e2
BLAKE2b-256 2d74c0c48fdb5b430d65d231c876118b9dedcd60ec9ee1c4ea8225b3d2efb31f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for viztracer-0.14.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 30b37684d0027f52f1a60a480c7f04daeef027dd786e1bf73f8db27cb5ab128d
MD5 e49d3bc95b5b72f7f1714875b55ed05d
BLAKE2b-256 b59ae3fb7105918e37dfbd89f0da8775d421e56b0948672fe6217e15d4250d86

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.14.1-cp36-cp36m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 8.2 MB
  • Tags: CPython 3.6m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.15

File hashes

Hashes for viztracer-0.14.1-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 77f9dabf63a2ce27062aab8d63f784a1feaac22ce41ab2927241eb154177e858
MD5 abbb07ce3820b68c5393707e4c2f44c4
BLAKE2b-256 76085c58d7a7c9bf6436e895ab72cc6d759431c8735f9070786b4898943627c6

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