From: "Steven Rostedt (VMware)" <rostedt@xxxxxxxxxxx> Add an interface to libtracefs that makes it easy to create synthetic events. For example: struct tracefs_synth *synth; struct tep_handle *tep; struct trace_seq seq; /* Load all events from the system */ tep = tracefs_local_events(NULL); /* Initialize the synthetic event */ synth = tracefs_synth_init(tep, "wakeup_lat", NULL, start_event, NULL, end_event, match_name, start_field, end_field); /* The tep is no longer needed */ tep_free(tep); /* Save the "prio" field as "prio" from the start event */ tracefs_synth_add_start_field(synth, NULL, "prio"); /* Save the "next_comm" as "comm" from the end event */ tracefs_synth_add_end_field(synth, "comm", "next_comm"); /* Save the "prev_prio" as "prev_prio" from the end event */ tracefs_synth_add_end_field(synth, NULL, "prev_prio"); /* * Take a microsecond time difference between end and start * and record as "delta" */ tracefs_synth_add_compare_field(synth, "delta", TRACEFS_TIMESTAMP_USECS, TRACEFS_TIMESTAMP_USECS, TRACEFS_SYNTH_DELTA_END); /* Only record if start event "prio" is less than 100 */ tracefs_synth_add_start_filter(synth, "prio", TRACEFS_COMPARE_LT, "100", false, false); /* * Only record if end event "next_prio" is less than 50 * or the previous task's prio was less than 100. */ tracefs_synth_add_end_filter(synth, "next_prio", TRACEFS_COMPARE_LT, "50", false, false); tracefs_synth_add_end_filter(synth, "prev_prio", TRACEFS_COMPARE_LT, "100", false, true); trace_seq_init(&seq); tracefs_synth_show(&seq, tracefs_synth_show(&s, NULL, synth); trace_seq_terminate(&s); trace_seq_do_printf(&s); trace_seq_destroy(&s); tracefs_synth_free(synth); Will produce: echo 'wakeup_lat s32 pid; s32 prio; char comm[16]; s32 prev_prio; u64 delta;' > /sys/kernel/tracing/synthetic_events echo 'hist:keys=pid:__arg__1=prio,__arg__2=common_timestamp.usecs if (prio < 100)' > /sys/kernel/tracing/events/sched/sched_waking/trigger echo 'hist:keys=next_pid:pid=next_pid,prio=$__arg__1,comm=next_comm,prev_prio=prev_prio,delta=common_timestamp.usecs-$__arg__2:onmatch(sched.sched_waking).trace(wakeup_lat,$pid,$prio,$comm,$prev_prio,$delta) if (next_prio < 50) || (prev_prio < 100)' > /sys/kernel/tracing/events/sched/sched_switch/trigger There's functionality to also create and destroy the synthetic event, not only produce the above. Once this is in libtracefs, it can then be brought over to trace-cruncher where this can be done in Python. Steven Rostedt (VMware) (4): libtracefs: Add tracefs_list_pop() to remove the last item libtracefs: Create a way to create a synthetic event libtracefs: Add TRACEFS_TIMESTAMP and TRACEFS_TIMESTAMP_USECS to synth libtracefs: Add man pages for creating synthetic events Documentation/libtracefs-synth.txt | 353 +++++++++ include/tracefs.h | 70 ++ src/tracefs-hist.c | 1104 ++++++++++++++++++++++++++++ src/tracefs-utils.c | 26 + 4 files changed, 1553 insertions(+) create mode 100644 Documentation/libtracefs-synth.txt -- 2.30.2