bootlin / training-materials

Bootlin embedded Linux and kernel training materials
https://bootlin.com/training/
Other
621 stars 182 forks source link

Add user event as a new static userspace tracepoint tool ? #251

Open Tropicao opened 4 months ago

Tropicao commented 4 months ago

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:

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:

cpus=20
         example-258900 [002] 20092.119852: test:                 count=0
         example-258900 [002] 20094.045727: test:                 count=1
         example-258900 [002] 20095.453523: test:                 count=2
         example-258900 [002] 20095.648020: test:                 count=3
         example-258900 [002] 20095.971038: test:                 count=4
         example-258900 [002] 20096.188430: test:                 count=5
         example-258900 [002] 20096.352141: test:                 count=6
         example-258900 [002] 20096.535957: test:                 count=7

EDIT: since the corresponding events are captured in ftrace buffer, those can be displayed in kernel shark when captured with trace-cmd

tpetazzoni commented 4 months ago

Definitely seems worth covering in the training course!