一:tracing 目录文件以及创建的代码
root@memory-153:/sys/kernel/debug/tracing# ls
available_events options stack_trace_filter
available_filter_functions per_cpu trace
available_tracers printk_formats trace_clock
buffer_size_kb README trace_marker
buffer_total_size_kb saved_cmdlines trace_options
current_tracer saved_cmdlines_size trace_pipe
dyn_ftrace_total_info set_event trace_stat
enabled_functions set_ftrace_filter tracing_cpumask
events set_ftrace_notrace tracing_max_latency
free_buffer set_ftrace_pid tracing_on
function_profile_enabled set_graph_function tracing_thresh
instances set_graph_notrace uprobe_events
kprobe_events snapshot uprobe_profile
kprobe_profile stack_max_size
max_graph_depth stack_trace
root@memory-153:/sys/kernel/debug/tracing# cat /boot/System.map-3.12.1 | grep trace | grep *initcall
ffffffff81e482d0 t *initcall_trace_init_flags_sys_exitearly
ffffffff81e482d8 t *initcall_trace_init_flags_sys_enterearly
ffffffff81e482e8 t *initcall_register_trigger_all_cpu_backtraceearly
ffffffff81e48348 t *initcall_tracer_alloc_buffersearly
ffffffff81e48358 t *initcall_init_trace_printkearly
ffffffff81e48360 t *initcall_event_trace_memsetupearly
ffffffff81e48368 t *initcall_init_ftrace_syscallsearly
ffffffff81e48410 t *initcall_ftrace_mod_cmd_init1
ffffffff81e48418 t *initcall_init_function_trace1
ffffffff81e48420 t *initcall_init_wakeup_tracer1
ffffffff81e48428 t *initcall_init_graph_trace1
ffffffff81e48430 t *initcall_event_trace_enable1
ffffffff81e48978 t *initcall_ftrace_init_debugfs5
ffffffff81e48980 t *initcall_tracer_init_debugfs5
ffffffff81e48988 t *initcall_init_trace_printk_function_export5
ffffffff81e48998 t *initcall_event_trace_init5
ffffffff81e489a0 t *initcall_init_kprobe_trace5
ffffffff81e489a8 t *initcall_init_uprobe_trace5
ffffffff81e48c10 t *initcall_init_tracepoints6
ffffffff81e48c20 t *initcall_stack_trace_init6
ffffffff81e48c28 t *initcall_init_mmio_trace6
ffffffff81e48c30 t *initcall_init_blk_tracer6
ffffffff81e494a8 t *initcall_clear_boot_tracer7
ffffffff81e494b0 t __initcall_kdb_ftrace_register7
ftrace_init_debugfs 7
available_filter_functions enabled_functions set_ftrace_filter
set_ftrace_notrace set_graph_function set_ftrace_pid trace_stat function_profile_enabled
tracer_init_debugfs 20
tracing_cpumask trace_options trace trace_pipe buffer_size_kb buffer_total_size_kb free_buffer trace_marker trace_clock tracing_on snapshot per_cpu
available_tracers current_tracer tracing_max_latency tracing_thresh README saved_cmdlines dyn_ftrace_total_info instances options
init_trace_printk_function_export 1 printk_formats
event_trace_init 3
available_events set_event events
init_kprobe_trace 2
kprobe_events kprobe_profile
init_uprobe_trace 2
uprobe_events uprobe_profile
stack_trace_init 3
stack_max_size stack_trace stack_trace_filter
not found:
saved_cmdlines_size set_graph_notrace max_graph_depth
二:tracepoint, ftrace event, syscall trace
tracepoint
VMLINUX_SYMBOL(start_tracepoints_ptrs) = .;
(__tracepoints_ptrs) / Tracepoints: pointer array /
VMLINUX_SYMBOL(**stop\**tracepoints_ptrs) = .;
(__tracepoints_strings)/ Tracepoints: strings _/ \
tracepoint.h
#define DEFINETRACE_FN(name, reg, unreg)
static const char __tpstrtab##name[]
attribute((section(“tracepoints_strings”))) = #name;
struct tracepoint *tracepoint##name
**attribute((section(“tracepoints”))) =
{ *tpstrtab##name, STATICKEY_INIT_FALSE, reg, unreg, NULL };
static struct tracepoint \ const __tracepoint_ptr##name *used
**attribute((section(“tracepointsptrs”))) =
&__tracepoint##name;
ftrace event
trace_types 所有 tracer 链表
nop tracer
function_trace
wakeup_tracer
wakeup_rt_tracer
mmio_tracer
blk_tracer
vmlinux.lds.h
#define FTRACE_EVENTS() . = ALIGN(8);
VMLINUX_SYMBOL(start_ftrace_events) = .;
*(_ftrace_events)
VMLINUX_SYMBOL(stop_ftrace_events) = .;
ftrace.h
#undef DEFINEEVENT_PRINT
#define DEFINE_EVENT_PRINT(template, call, proto, args, print)
static const char print_fmt##call[] = print;
static struct ftraceevent_call __used event##call = {
.name = #call,
.class = &eventclass##template,
.event.funcs = &ftraceevent_type_funcs##call,
.printfmt = print_fmt##call,
};
static struct ftraceevent_call used
**attribute((section(“_ftrace_events”))) ***event##call = &event_##call
syscall trace
#define SYSCALLTRACE_ENTER_EVENT(sname)
static struct syscall_metadata __syscall_meta##sname;
static struct ftraceevent_call __used
event_enter##sname = {
.name = “sysenter”#sname,
.class = &event_class_syscall_enter,
.event.funcs = &enter_syscall_print_funcs,
.data = (void \)&__syscall_meta##sname,
.flags = TRACEEVENT_FL_CAP_ANY,
};
static struct ftrace_event_call *used
attribute((section(“_ftrace_events”)))
***event_enter##sname = &evententer##sname;
#define SYSCALLTRACE_EXIT_EVENT(sname)
static struct syscall_metadata __syscall_meta##sname;
static struct ftraceevent_call __used
event_exit##sname = {
.name = “sysexit”#sname,
.class = &event_class_syscall_exit,
.event.funcs = &exit_syscall_print_funcs,
.data = (void \)&__syscall_meta##sname,
.flags = TRACEEVENT_FL_CAP_ANY,
};
static struct ftrace_event_call *used
attribute((section(“_ftrace_events”)))
***event_exit##sname = &eventexit##sname;
#define SYSCALLMETADATA(sname, nb, …)
static const char *types##sname[] = {
MAP(nb,SCSTR_TDECL,VA_ARGS)
};
static const char *args##sname[] = {
MAP(nb,SCSTR_ADECL,VA_ARGS)
};
SYSCALL_TRACE_ENTER_EVENT(sname);
SYSCALL_TRACE_EXIT_EVENT(sname);
static struct syscall_metadata *used
*syscall_meta##sname = {
.name = “sys”#sname,
.syscallnr = -1, / Filled in at boot /
.nb_args = nb,
.types = nb ? types##sname : NULL,
.args = nb ? args##sname : NULL,
.enter_event = &event_enter##sname,
.exitevent = &event_exit##sname,
.enterfields = LIST_HEAD_INIT(__syscall_meta##sname.enterfields),
};
static struct syscall_metadata used
**attribute((section(“*syscalls_metadata”)))
\__p_syscall_meta##sname = &_syscall_meta##sname;
#else
#define SYSCALL_METADATA(sname, nb, …)
#endif
#define SYSCALLDEFINE0(sname)
SYSCALL_METADATA(##sname, 0);
asmlinkage long sys_##sname(void)
#define SYSCALLDEFINE1(name, …) SYSCALL_DEFINEx(1, *##name, *VA_ARGS)
#define SYSCALLDEFINE2(name, …) SYSCALL_DEFINEx(2, *##name, *VA_ARGS)
#define SYSCALLDEFINE3(name, …) SYSCALL_DEFINEx(3, *##name, *VA_ARGS)
#define SYSCALLDEFINE4(name, …) SYSCALL_DEFINEx(4, *##name, *VA_ARGS)
#define SYSCALLDEFINE5(name, …) SYSCALL_DEFINEx(5, *##name, *VA_ARGS)
#define SYSCALLDEFINE6(name, …) SYSCALL_DEFINEx(6, *##name, *VA_ARGS)
#define SYSCALL_DEFINEx(x, sname, …)
SYSCALL_METADATA(sname, x, VA_ARGS)
*SYSCALL_DEFINEx(x, sname, *VA_ARGS__)