Skip to content

Repository files navigation

Simple Tracer

A simple tracer for Python programs using the sys.monitoring namespace introduced in Python 3.12. The tracer exports to the Chrome Trace event format.

Installation

pip install simple-tracer

Usage

As a context manager:

fromsimple_tracerimporttracerwithtracer("trace.json"):
func()

as a function decorator:

fromsimple_tracerimporttraceable@traceabledefsquare(x: int) ->int:
returnx**2

or as a runnable script:

simple-tracer -o trace.json.gz -m mymodule
# or
simple-tracer -o trace.json.gz myscript.py

Examples

There are some example scripts in the examples directory. Some can be run as a python script, while others are to be launched using the simple-tracer command.

Limitations

Currently the tracer does not trace built-in dunder methods (e.g. __add__()), due to the way monitoring is implemented. This means that code such as

importnumpyasnpx=np.zeros(10)
y=x+x

will not record the addition operation as a call to numpy.ndarray.__add__().

About

A simple tracer for Python 3.12+

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages