All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-trace-devel@vger.kernel.org
Cc: Tom Zanussi <zanussi@kernel.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	"Steven Rostedt (VMware)" <rostedt@goodmis.org>
Subject: [PATCH 0/4] libtracefs: Creating synthetic events
Date: Wed, 21 Jul 2021 23:39:13 -0400	[thread overview]
Message-ID: <20210722033917.367982-1-rostedt@goodmis.org> (raw)

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

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


             reply	other threads:[~2021-07-22  3:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-22  3:39 Steven Rostedt [this message]
2021-07-22  3:39 ` [PATCH 1/4] libtracefs: Add tracefs_list_pop() to remove the last item Steven Rostedt
2021-07-22  3:39 ` [PATCH 2/4] libtracefs: Create a way to create a synthetic event Steven Rostedt
2021-07-22  3:39 ` [PATCH 3/4] libtracefs: Add TRACEFS_TIMESTAMP and TRACEFS_TIMESTAMP_USECS to synth Steven Rostedt
2021-07-22  3:39 ` [PATCH 4/4] libtracefs: Add man pages for creating synthetic events Steven Rostedt
2021-07-22  3:45 ` [PATCH 0/4] libtracefs: Creating " Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210722033917.367982-1-rostedt@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=zanussi@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.