[lttng-dev] Tracing in python application with custom tracepoints

Philippe Proulx eeppeliteloop at gmail.com
Tue Jun 21 14:24:22 UTC 2016


On Tue, Jun 21, 2016 at 4:25 AM, Charles Lesire-Cabaniols
<charles.lesire at gmail.com> wrote:
> Hi,
>
> I have written a C++ code in which I use custom tracepoints (generated from
> a .tp file).
>
> My system now deploys a mix of my C++ app and a python script.
> Is there a way to write traces in my python script using the same
> tracepoints definition (from the .tp file), and then being recorded within
> the same lttng session?
>
> I found this link about using lttng traces within python apps but it is very
> concise:

It is very concise because there's no more to it: import the LTTng-UST Python
agent package and use the `logging` package as usual. Everything related to
standard logging is documented by the Python project itself.

That being said, you won't be able to reuse the same tracepoints when using
the LTTng-UST Python agent. It does not work like the C/C++ liblttng-ust where
you statically define tracepoints and use them to emit LTTng events.

Your best bet currently would be to do like the LTTng-UST Python agent does.
This agent actually sits on a liblttng-ust tracepoint provider with a
single tracepoint
definition [1]. The tracepoint is called in py_tracepoint(), which is
part of a shared
object named `liblttng-ust-python-agent.so`. The LTTng-UST Python agent [2]
(Python code, exclusively) uses Python's ctypes [3] to load
`liblttng-ust-python-agent.so` and call py_tracepoint() when there's a new log
statement [4] (part of a log handler).

You can implement this strategy with multiple tracepoints and it will
work just fine.

Phil

[1] https://github.com/lttng/lttng-ust/tree/stable-2.8/liblttng-ust-python-agent
[2] https://github.com/lttng/lttng-ust/tree/stable-2.8/python-lttngust/lttngust
[3] https://docs.python.org/3/library/ctypes.html
[4] https://github.com/lttng/lttng-ust/blob/stable-2.8/python-lttngust/lttngust/loghandler.py#L35

> https://lttng.org/docs/#doc-python-application
>
> Thanks in advance,
>
> Charles
>
> _______________________________________________
> lttng-dev mailing list
> lttng-dev at lists.lttng.org
> https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
>


More information about the lttng-dev mailing list