[lttng-dev] how do I print a value from an array of structs in a userspace tracepoint?

Jeff Layton jlayton at poochiereds.net
Tue Aug 18 13:31:26 EDT 2015

On Tue, 18 Aug 2015 13:01:23 -0400
Jérémie Galarneau <jeremie.galarneau at efficios.com> wrote:

> On Tue, Aug 18, 2015 at 8:00 AM, Jeff Layton <jlayton at poochiereds.net>
> wrote:
> > I'd like to add a tracepoint to my code that can walk a
> > dynamically-sized array of structs and print one of the fields from
> > each struct. For instance, suppose I have an array of structs that
> > looks like this:
> >
> > struct foo
> > {
> >         int bar;
> >         int baz;
> >         ...
> > }
> >
> > At the time of the tracepoint, I know the number of elements in the
> > array and can pass that in. Is there any way to have lttng walk the
> > array of structs and print out only the "bar" field from each?
> >
> > I've tried using ctf_sequence, but it doesn't seem to do the right
> > thing. You can't tell it that you want to print out an "int" while
> > walking an array of differently-sized objects.
> >
> >
> Indeed, sequences assume elements are of the same type/size. That would,
> presumably, be possible using variants, but they remain unsupported by the
> current tracer implementations.
> For now, you could serialize your fields to a dynamically-sized array and
> extract this array using a ctf_sequence.
> Jérémie

I was afraid you were going to say that...Is there a way to do that
serialization only when the tracepoint is enabled or would I have to do
that unconditionally?

I guess we could do something like this (filling in the appropriate
name and provider of course):

	if (caa_unlikely(__tracepoint_##provider##___##name.state)) {
		// marshal on stack array here

Though we'd need to know that __tracepoint_##provider##___##name.state
is properly set at that point. Is it?

Jeff Layton <jlayton at poochiereds.net>

More information about the lttng-dev mailing list