Kernel tracing
Writing to the kernel trace
An application may write messages to the trace of the kernel tracer, so that they appear among the kernel events, in the order of their occurrence. It may also freeze the trace when it detects an issue, such as a missed deadline, so that the events leading to it can be studied later. Both operations work from either stage, so an out-of-band thread does not switch stage for this.
A message is logged by the evl/evl_trace tracepoint, which must be
enabled for the message to appear, for instance with the evl trace command.
Tracing services
evl_open_ktracer() | Open a channel to the kernel tracer. | in-band |
evl_close_ktracer() | Close a channel to the kernel tracer. | in-band |
evl_write_ktrace() | Write a message to the kernel trace. | no stage switch |
evl_print_ktrace() | Format and write a message to the kernel trace. | no stage switch |
evl_freeze_ktrace() | Take a snapshot of the kernel trace. | no stage switch |
Open a channel to the kernel tracer, through the /dev/evl/trace
device.
flagsReserved, pass zero.
evl_open_ktracer() returns a
file descriptor on success, which the other calls take as argument.
Otherwise, it returns a negated error code from the open() call.
Close a channel opened by evl_open_ktracer().
fdThe file descriptor of the channel.
evl_close_ktracer() returns
zero on success, or a negated error code from the close() call.
int evl_write_ktrace(int fd, const char *buf, size_t len)
#include <evl/tracing.h>
no stage switch
non-EVL threads: yes
Write a message to the kernel trace. A message longer than 127 bytes is truncated.
fdThe file descriptor of the channel.
bufThe text of the message.
lenThe length of the text in bytes.
evl_write_ktrace() returns the number of bytes written on success. Otherwise, a negated error code is returned:
| Error | Meaning |
|---|---|
-EBADF |
fd is not a valid file descriptor. |
-EFAULT |
buf points to an invalid address. |
int evl_print_ktrace(int fd, const char *fmt, ...)
#include <evl/tracing.h>
no stage switch
non-EVL threads: yes
Format a message like printf(), then write it to the kernel trace
like evl_write_ktrace(). The
message is formatted in a buffer of the calling thread, so the call
neither allocates memory nor takes a lock.
fdThe file descriptor of the channel.
fmtA printf-like format string.
...The optional variable argument list completing the format.
evl_print_ktrace() returns the same values as evl_write_ktrace().
Take a snapshot of the kernel trace, which can be read later from the
snapshot file of the tracer. The kernel must be built with
CONFIG_TRACER_SNAPSHOT, otherwise this call has no effect, and the
snapshot buffer must be allocated beforehand, as described in the
kernel
documentation.
Tip
It is recommended to enable CONFIG_TRACER_SNAPSHOT_PER_CPU_SWAP as
well, which enables per-CPU
snapshots.
fdThe file descriptor of the channel.
evl_freeze_ktrace() returns
zero on success, or -EBADF if fd is not a valid file descriptor.
Last modified: Wed, 25 Nov 2026 16:53:53 +0100