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

Uploaded Source

Built Distributions

viztracer-0.14.0-cp39-cp39-win_amd64.whl (8.0 MB view details)

Uploaded CPython 3.9 Windows x86-64

viztracer-0.14.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.0 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

viztracer-0.14.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (8.1 MB view details)

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

viztracer-0.14.0-cp39-cp39-macosx_10_14_x86_64.whl (8.0 MB view details)

Uploaded CPython 3.9 macOS 10.14+ x86-64

viztracer-0.14.0-cp38-cp38-win_amd64.whl (8.0 MB view details)

Uploaded CPython 3.8 Windows x86-64

viztracer-0.14.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.1 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

viztracer-0.14.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (8.1 MB view details)

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

viztracer-0.14.0-cp38-cp38-macosx_10_14_x86_64.whl (8.0 MB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

viztracer-0.14.0-cp37-cp37m-win_amd64.whl (8.0 MB view details)

Uploaded CPython 3.7m Windows x86-64

viztracer-0.14.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.0 MB view details)

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

viztracer-0.14.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (8.1 MB view details)

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

viztracer-0.14.0-cp37-cp37m-macosx_10_14_x86_64.whl (8.0 MB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

viztracer-0.14.0-cp36-cp36m-win_amd64.whl (8.0 MB view details)

Uploaded CPython 3.6m Windows x86-64

viztracer-0.14.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.0 MB view details)

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

viztracer-0.14.0-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (8.1 MB view details)

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

viztracer-0.14.0-cp36-cp36m-macosx_10_14_x86_64.whl (8.0 MB view details)

Uploaded CPython 3.6m macOS 10.14+ x86-64

File details

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

File metadata

  • Download URL: viztracer-0.14.0.tar.gz
  • Upload date:
  • Size: 7.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.7.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.11

File hashes

Hashes for viztracer-0.14.0.tar.gz
Algorithm Hash digest
SHA256 80a8968e179679e012fdc510b339dcc092074d2a1edd2f8b18db3c8a61dae531
MD5 35c1770ddea1f9ce89d91ac6604b1a23
BLAKE2b-256 cde3b9999344edbc3a0195b27b849220ab15baae4685f511fb78c612f9d8b6df

See more details on using hashes here.

File details

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

File metadata

  • Download URL: viztracer-0.14.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 8.0 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.7.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

File hashes

Hashes for viztracer-0.14.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 4f2bd83486ad0363c72cb5a9b38a8ee58389a0d1d032d6f5b08aa220bff5a8b2
MD5 5f67250613a112bbfb604004f886e31d
BLAKE2b-256 772d01997c3eedd15b2b891c55f40185442ad67aef9a46116f535453aa42add6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for viztracer-0.14.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 07bc365c86ea7670692631196bf4becb5f905e6d48795e74a40afa83e3ea7c12
MD5 0679739f58fbb6dc36fefd89657a12f8
BLAKE2b-256 06acff5b7012c1e5d1025f6c675a4532b4ca6e19bf7419eaa01b27ff630ae15c

See more details on using hashes here.

File details

Details for the file viztracer-0.14.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.14.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 34b371196bf144926587488ba5d3ce7613e72bcbd755975941f289e6185e68be
MD5 af9e3d32f4822f9547d9f767214ebc3a
BLAKE2b-256 b684e1df0ea58dfeed36755c63a4756e16484dc15c872e56960b7d9c430a838a

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for viztracer-0.14.0-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 8fc60182191c74d8158069834d8a07b1353767898de501e10844b28e17962507
MD5 b95be63ae39db40a723ef824c7f1ec9a
BLAKE2b-256 fe2f11a1cdd5133b9ca99ee055e1c4b7fb172712eeeb5b91a65b7163401377f7

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for viztracer-0.14.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 fa3aa9da7cfc7fc69feda692cf0c9f31f9d2c94d2233df6abac9f322612895a4
MD5 176f748e976348bf58d097795d757be1
BLAKE2b-256 932b4279700803318eaff4633be6eacd09a536c6dacac5b72e2fc9d40ce71b9c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for viztracer-0.14.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3fd914d640938d6681e2412169f8240ac5f3955e94a6f77648bcdce1bc0d1c88
MD5 7c268556aec7231b7535c42b6cb1cd19
BLAKE2b-256 9c0369e903cab1e8da16d4966529dac0c08d47514939c8e682e92c5fa2af38a3

See more details on using hashes here.

File details

Details for the file viztracer-0.14.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.14.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 1ec8db8c2dba3ffa4cc726b7307c73223dbdf5d02cc18f5e6dddad801e222dc9
MD5 2acdcceaa6c7b33c0d532c79908278ed
BLAKE2b-256 d4e3388c23c39bfb3a9d03a1e02fe74c63c0509dae74b6e7c68f4ccfd3bc273a

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for viztracer-0.14.0-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 44f3ef805f2e34400400c0d38a4759399a5e5a11f3ed513895e4db225247c731
MD5 ebc6e73ff453d10af1011cc6d316b6d7
BLAKE2b-256 35bb8cf4a3f72f3efbcb1fac0f6ff92012e33440fdae7b144414b3e957c72e8b

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for viztracer-0.14.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 27e2b9071d30d5bb02e905c6e11e7488230d879e3c7061dca9194290fedcdf46
MD5 30c76989b2aa9626fbe3652f1114fca9
BLAKE2b-256 e8b693123c427893a88cc448adf8eed9e0cc268527256ec6ac35139e168e1754

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for viztracer-0.14.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 30f349e91d21a52c0e9b37de9298d61dfe8f3b9fb429be912df69e491762334c
MD5 31db0572d3b0816e9aa8df535d3cbae6
BLAKE2b-256 83fe538cd81e5bdc8bed0be63f2b97ec42e000089398e365ee18cc1c543cf63d

See more details on using hashes here.

File details

Details for the file viztracer-0.14.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.14.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 3b114140fe9944972bd7d1a4dd38759774084592edb9435d1800e0a833a3b98e
MD5 23965e391ecc6b7040f7c04463163be2
BLAKE2b-256 ef418c7aae289dd00b33802d9928cbf8c08431937bf448bcc1b8b8a74162fdbb

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for viztracer-0.14.0-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 73ba94ad3462e552a00a5b9e620d38fc6dcfba45a261f4987576fa49b77b0d0b
MD5 ad238a0ceac944af07aebe17c6845c3d
BLAKE2b-256 c217512c11732896944a6cdde1272ac9f494e84ee98bda9be39b54987738a772

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for viztracer-0.14.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 ca6c926ab395748542695f0891f7c600aeaaf3a7b19f147bfa2f5be2e9766943
MD5 54f0e66c35676d32560edb9549c8d493
BLAKE2b-256 6566ab7e903c0eae8ffc0bee1eb284fb5f6592fcef76da4b8419ed878eee647c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for viztracer-0.14.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 571fd540a92f346663403cadf763e4ccf62e51a1d6bf8680d2327a77866296f9
MD5 68b24b7bd7157ce217fcb9ec76ce00d4
BLAKE2b-256 82e900cf43de7c6436ec76f7419ae7ec566c3ccb32d3a41f45aa7a8fdd7fdaff

See more details on using hashes here.

File details

Details for the file viztracer-0.14.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.14.0-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 c06a7e5f7b23d28b34164d8828f9fa6cde0820cde1cbf576a28efe20f10c3980
MD5 14ad4f60c13b5485af6dd3f9ff558451
BLAKE2b-256 368caeb97e26c8ae6d96fba591fdd40abef21dbf9145df7670446bbc3429ee5d

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for viztracer-0.14.0-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 7a54a6886043825586bfdc0a879758e44e5ab5fc8a743b23427dc162b7b4173e
MD5 bd8dc1a653d6385b0863edb2548468e0
BLAKE2b-256 f23541dab56d0e01e89b4e26e2210a7f698ea47b2e2a593a37f86091f49cc354

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