mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	linux-kernel@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Peter Zijlstra <peterz@infradead.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Theodore Tso <tytso@mit.edu>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Mathieu Desnoyers <compudj@krystal.dyndns.org>,
	Lai Jiangshan <laijs@cn.fujitsu.com>,
	"Martin J. Bligh" <mbligh@mbligh.org>,
	"Frank Ch. Eigler" <fche@redhat.com>,
	Larry Woodman <lwoodman@redhat.com>,
	Jason Baron <jbaron@redhat.com>, Tom Zanussi <tzanussi@gmail.com>,
	Masami Hiramatsu <mhiramat@redhat.com>,
	Christoph Hellwig <hch@infradead.org>,
	Jiaying Zhang <jiayingz@google.com>,
	Steven Rostedt <srostedt@redhat.com>
Subject: Re: [PATCH 4/7] tracing: new format for specialized trace points
Date: Tue, 10 Mar 2009 09:54:18 +0100	[thread overview]
Message-ID: <20090310085418.GB3097@elte.hu> (raw)
In-Reply-To: <20090310144700.A48E.A69D9226@jp.fujitsu.com>


* KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> wrote:

> Hi Steven,
> 
> >  TRACE_EVENT(sched_switch,
> > 
> > 	TP_PROTO(struct rq *rq, struct task_struct *prev,
> > 		 struct task_struct *next),
> > 
> > 	TP_ARGS(rq, prev, next),
> > 
> > 	TP_STRUCT__entry(
> > 		__array(	char,	prev_comm,	TASK_COMM_LEN	)
> > 		__field(	pid_t,	prev_pid			)
> > 		__field(	int,	prev_prio			)
> > 		__array(	char,	next_comm,	TASK_COMM_LEN	)
> > 		__field(	pid_t,	next_pid			)
> > 		__field(	int,	next_prio			)
> > 	),
> > 
> > 	TP_printk("task %s:%d [%d] ==> %s:%d [%d]",
> > 		__entry->prev_comm, __entry->prev_pid, __entry->prev_prio,
> > 		__entry->next_comm, __entry->next_pid, __entry->next_prio),
> > 
> > 	TP_fast_assign(
> > 		memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN);
> > 		__entry->prev_pid	= prev->pid;
> > 		__entry->prev_prio	= prev->prio;
> > 		memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN);
> > 		__entry->next_pid	= next->pid;
> > 		__entry->next_prio	= next->prio;
> > 	)
> >  );
> 
> Could you please write the documentation how to make new 
> tracepont and use various TP_ macro? Some developer (include 
> me) plan to add new tracepoint. but these macro usage is a bit 
> difficult.

Sure, here's a commented/annotated variant:

  /*
   * We define a tracepoint, its arguments, its printk format
   * and its 'fast binay record' layout.
   *
   * Firstly, name your tracepoint via TRACE_EVENT(name : the 
   * 'subsystem_event' notation is fine.
   *
   * Think about this whole construct as the 
   * 'trace_sched_switch() function' from now on.
   */
 
  TRACE_EVENT(sched_switch,

        /*
         * A function has a regular function arguments 
         * prototype, declare it via TP_PROTO():
         */
 	TP_PROTO(struct rq *rq, struct task_struct *prev,
 		 struct task_struct *next),
 
        /*
         * Define the call signature of the 'function'. 
	 * (Design sidenote: we use this instead of a
	 *  TP_PROTO1/TP_PROTO2/TP_PROTO3 ugliness.)
         */
 	TP_ARGS(rq, prev, next),
 
        /*
         * Fast binary tracing: define the trace record via 
         * TP_STRUCT__entry(). You can think about it like a 
         * regular C structure local variable definition.
         *
         * This is how the trace record is structured and will
         * be saved into the ring buffer. These are the fields
         * that will be exposed to user-space in 
         * /debug/tracing/events/*/format.
         *
         * The declared 'local variable' is called '__entry'
         */
 	TP_STRUCT__entry(
 		__array(	char,	prev_comm,	TASK_COMM_LEN	)
 		__field(	pid_t,	prev_pid			)
 		__field(	int,	prev_prio			)
 		__array(	char,	next_comm,	TASK_COMM_LEN	)
 		__field(	pid_t,	next_pid			)
 		__field(	int,	next_prio			)
 	),

        /*
         * Assign the entry into the trace record, by embedding 
         * a full C statement block into TP_fast_assign(). You 
         * can refer to the trace record as '__entry' - 
         * otherwise you can put arbitrary C code in here.
         *
         * Note: this C code will execute every time a trace event 
         * happens, on an active tracepoint.
         */
 	TP_fast_assign(
 		memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN);
 		__entry->prev_pid	= prev->pid;
 		__entry->prev_prio	= prev->prio;
 		memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN);
 		__entry->next_pid	= next->pid;
 		__entry->next_prio	= next->prio;
 	)

        /*
         * Formatted output of a trace record via TP_printk(). 
         * This is how the tracepoint will appear under ftrace 
         * plugins that make use of this tracepoint.
         *
         * (raw-binary tracing wont actually perform this step.)
         */
 	TP_printk("task %s:%d [%d] ==> %s:%d [%d]",
 		__entry->prev_comm, __entry->prev_pid, __entry->prev_prio,
 		__entry->next_comm, __entry->next_pid, __entry->next_prio),

  );

This macro construct is thus used for the regular printk format 
tracing setup, it is used to construct a function pointer based 
tracepoint callback (this is used by programmatic plugins and 
can also by used by generic instrumentation like SystemTap), and 
it is also used to expose a structured trace record in 
/debug/tracing/events/.

Steve: i flipped around TP_fast_assign() and TP_printk() in the 
example above because it makes more sense that way. (we first 
assign the record, then we print it out) I suspect we should 
flip it around in the code too.

	Ingo

  reply	other threads:[~2009-03-10  8:55 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-10  4:57 [PATCH 0/7] [GIT PULL] enhancements for tracing in tip Steven Rostedt
2009-03-10  4:57 ` [PATCH 1/7] tracing: typecast sizeof and offsetof to unsigned int Steven Rostedt
2009-03-10  5:20   ` Andrew Morton
2009-03-10 13:39     ` Steven Rostedt
2009-03-10  4:57 ` [PATCH 2/7] tracing: replace TP<var> with TP_<var> Steven Rostedt
2009-03-17  7:58   ` Christoph Hellwig
2009-03-17 15:30     ` Steven Rostedt
2009-03-10  4:57 ` [PATCH 3/7] tracing: use generic __stringify Steven Rostedt
2009-03-10 10:56   ` Frederic Weisbecker
2009-03-10 11:18     ` KOSAKI Motohiro
2009-03-10 11:21     ` Peter Zijlstra
2009-03-10 15:48       ` Frédéric Weisbecker
2009-03-10  4:57 ` [PATCH 4/7] tracing: new format for specialized trace points Steven Rostedt
2009-03-10  5:50   ` KOSAKI Motohiro
2009-03-10  8:54     ` Ingo Molnar [this message]
2009-03-10 13:45       ` Steven Rostedt
2009-03-10  9:54   ` KOSAKI Motohiro
2009-03-10 13:55     ` Steven Rostedt
2009-03-17  8:08   ` Christoph Hellwig
2009-03-17 15:41     ` Steven Rostedt
2009-03-10  4:57 ` [PATCH 5/7] tracing: convert the sched trace points to the TRACE_EVENT macros Steven Rostedt
2009-03-10  4:57 ` [PATCH 6/7] tracing: convert irq trace points to new macros Steven Rostedt
2009-03-10  4:57 ` [PATCH 7/7] tracing: remove obsolete TRACE_EVENT_FORMAT macro Steven Rostedt
2009-03-17  8:08   ` Christoph Hellwig
2009-03-10  8:59 ` [PATCH 0/7] [GIT PULL] enhancements for tracing in tip Ingo Molnar

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=20090310085418.GB3097@elte.hu \
    --to=mingo@elte.hu \
    --cc=acme@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=compudj@krystal.dyndns.org \
    --cc=fche@redhat.com \
    --cc=fweisbec@gmail.com \
    --cc=hch@infradead.org \
    --cc=hpa@zytor.com \
    --cc=jbaron@redhat.com \
    --cc=jiayingz@google.com \
    --cc=kosaki.motohiro@jp.fujitsu.com \
    --cc=laijs@cn.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lwoodman@redhat.com \
    --cc=mbligh@mbligh.org \
    --cc=mhiramat@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=srostedt@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=tytso@mit.edu \
    --cc=tzanussi@gmail.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®