Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

The pymontrace expression language

The pymontrace language is heavily inspired by the D language of DTrace and by bpftrace.

In general it follows the form

program ::= ( probe-spec probe-action )*

probe-spec = probe-name ":" probe-arg1 ":" probe-arg2

probe-action = "{{" python-program-text "}}"

probe-name = "line" | ...

Here is an example pymontrace program:

line:*/some-file.py:123 {{
    print("a =", ctx.a)
    if b is not None:
        vars.b = agg.count()
}}

pymontrace::END {{
    print("b =", vars.b)
}}

The python blocks are run in the context of the probe site. The local and global variables are available on ctx and ctx.globals respectively.