The training currently shows only one way to add static tracepoints in a userspace process with LTTNG, especially with UST library.
It may be interesting to provide an alternative, which additionally does not rely on an external, possibly heavy to setup, framework (it may become even more true if we reduce the LTTNG part)
User-space events is a kernel assisted mechanism which provides another way to instrument an application. Those events rely on specific tracefs entries to register a data source and input data to it. The process to generate user events in an application is roughly the following:
register our new event, providing an "enable" variable address, an event name, a write index variable, etc
on successful registration, the kernel will update the write index variable, which must then be used each time we want to write some data
the program can now monitor the enable variable, which will be updated by the kernel everytime someone (perf, trace-cmd, raw tracefs access) enables or disables the corresponding event
when the event is enabled, the application can use the returned write index to write some data when relevant.
The kernel source tree also provides a simple-to-use sample to experiment with it:
cd ~linux/samples/user_events
make
sudo ./example
In another terminal, while the example program is running:
sudo trace-cmd list -e |grep test # We should see the registered user-event named test
sudo trace-cmd -e test
# Wait a few seconds, then Ctrl+c
trace-cmd report
We should see the following data generated by the example program:
The training currently shows only one way to add static tracepoints in a userspace process with LTTNG, especially with UST library.
It may be interesting to provide an alternative, which additionally does not rely on an external, possibly heavy to setup, framework (it may become even more true if we reduce the LTTNG part) User-space events is a kernel assisted mechanism which provides another way to instrument an application. Those events rely on specific tracefs entries to register a data source and input data to it. The process to generate user events in an application is roughly the following:
The kernel source tree also provides a simple-to-use sample to experiment with it:
In another terminal, while the
example
program is running:We should see the following data generated by the example program:
EDIT: since the corresponding events are captured in ftrace buffer, those can be displayed in kernel shark when captured with trace-cmd