Re: [PATCH 07/10] tracing: add raw trace point recording infrastructure

Steven Rostedt
2009-03-02T13:23:36Z

On Mon, 2 Mar 2009, Tom Zanussi wrote:
> > An example of this would be:
> >
> > TRACE_EVENT_FORMAT(sched_wakeup,
> > TPPROTO(struct rq *rq, struct task_struct *p, int success),
> > TPARGS(rq, p, success),
> > TPFMT("task %s:%d %s",
> > p->comm, p->pid, success?"succeeded":"failed"),
> > TRACE_STRUCT(
> > TRACE_FIELD(pid_t, pid, p->pid)
> > TRACE_FIELD(int, success, success)
> > ),
> > TPRAWFMT("task %d success=%d")
> > );
> >
> > This creates us a unique struct of:
> >
> > struct {
> > pid_t pid;
> > int success;
> > };
> >
> > And the way the call back would assign these values would be:
> >
> > entry->pid = p->pid;
> > entry->success = success;
> >
> > The nice part about this is that the creation of the assignent is done
> > via macro magic in the event tracer. Once the TRACE_EVENT_FORMAT is
> > created, the developer will then have a faster method to record
> > into the ring buffer. They do not need to worry about the tracer itself.
> >
>
> Nice improvements - I definitely was unhappy about having things spread
> around in different files unnecessarily. And I like the fact that your
> macros generate assignments too but am curious about what to do if you
> need to do something more complicated than an assignment e.g. in the
> block tracepoints I had to assign fields differently based on the value
> of blk_pc_request():
>
> if (blk_pc_request(rq)) {
> zed_event->sector = 0;
> zed_event->bytes = rq->data_len;
> zed_event->pdu_len = pdu_len;
> memcpy(zed_event->pdu, rq->cmd, pdu_len);
> } else {
> zed_event->sector = rq->hard_sector;
> zed_event->bytes = rq->hard_nr_sectors << 9;
> zed_event->pdu_len = 0;
> }
>
> Is there a way to define some fields but without the assignments, and do
> them manually somewhere else? I guess it would be nice to be able to
> define all events using TRACE_EVENT_FORMAT but have a way to special
> case certain events/fields.
>
> Anyway, sorry if it's already handled in the code - haven't had a chance
> to really peruse it.

Nope, you are right, it is not handled... yet ;-)

I was thinking about adding TRACE_FIELD_SPECIAL() that would allow for a
different means to copy the field.

TRACE_FIELD_SPECIAL(char*, pdu, rec,
TPCMD(memcpy((rec)->pdu, rq->cmd, pdu_len));

Where, rec would have your "zed_event", and the fourth argument would have
the way to handle that field.

I have not tried that yet, but I think this, or something similar, could
work.

Thanks,

-- Steve