:::{note} AI Translation Notice
This document was automatically translated by Qwen/Qwen3-8B
model, for reference only.
Source document: kernel/trace/tracepoint.md
Translation time: 2025-06-14 09:36:42
Translation model: Qwen/Qwen3-8B
Please report issues via Community Channel
:::
Author: Chen Linfeng
Email: chenlinfeng25@outlook.com
Tracepoints are a tracing mechanism provided by the Linux kernel, allowing developers to insert probe points at specific locations in the kernel code to collect runtime information. Unlike kprobes, tracepoints are predefined and are typically used for collecting performance data or debugging information without modifying the kernel code.
define_event_trace
.define_event_trace
, and pass relevant context information. For example, if the defined tracepoint is named my_tracepoint
, it can be triggered using trace_my_tracepoint()
.trace-cmd
or perf
). Currently, DragonOS only supports viewing the data files created by the kernel for these data.
/sys/kernel/debug/tracing/trace
file can view the tracepoint collected data. The buffer content will not be cleared./sys/kernel/debug/tracing/trace_pipe
file can view the tracepoint collected data. The buffer content will be cleared. If there is no content in the buffer, it will block until new data is available./sys/kernel/debug/tracing/events/
directory can view all available tracepoints./sys/kernel/debug/tracing/events/<event_name>/format
file can view the data format of a specific tracepoint./sys/kernel/debug/tracing/events/<event_name>/enable
file can enable a specific tracepoint./sys/kernel/debug/tracing/trace
can clear the current trace data.define_event_trace!() // 定义一个 tracepoint
// example
define_event_trace!(
sys_enter_openat,
TP_system(syscalls),
TP_PROTO(dfd: i32, path:*const u8, o_flags: u32, mode: u32),
TP_STRUCT__entry{
dfd: i32,
path: u64,
o_flags: u32,
mode: u32,
},
TP_fast_assign{
dfd: dfd,
path: path as u64,
o_flags: o_flags,
mode: mode,
},
TP_ident(__entry),
TP_printk({
format!(
"dfd: {}, path: {:#x}, o_flags: {:?}, mode: {:?}",
__entry.dfd,
__entry.path,
__entry.o_flags,
__entry.mode
)
})
);
In DragonOS, tracepoints can also be used in conjunction with eBPF to collect richer data within the kernel. eBPF programs can be attached to tracepoints to execute custom logic when a tracepoint is triggered.