Skip to contentSkip to conversation

how do I print a value from an array of structs in a userspace tracepoint?

DISCUSSION Jérémie Galarneau 2 participants 3 messages Aug 18, 2015 3 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 12 lines · Jeff Layton

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;
        ...
}
Quoted 9 lines

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

Any help is appreciated!

Quoted 8 lines

--
Jeff Layton <[email protected]>

_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

Signature · 3 lines
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com

_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

A message that is not in the archive (sent off-list or not yet received): CA+jJMxtF10b0g=dy2hJmW3ie=MbHSiAZw5SydGL-u02Uz=zWnw@mail.gmail.com

#3 lore raw
Quoted 24 lines · On Tue, 18 Aug 2015 13:01:23 -0400 Jérémie Galarneau…
Quoted 12 lines · Jeff Layton

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;
        ...
}
Quoted 9 lines

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.

Quoted 9 lines

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
                tracepoint(...);
	}

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

Signature · 6 lines
Jeff Layton <[email protected]>

_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

A message that is not in the archive (sent off-list or not yet received): [email protected]

#5 lore raw
Quoted 44 lines · Jeff Layton
Quoted 24 lines · On Tue, 18 Aug 2015 13:01:23 -0400 Jérémie Galarneau…
Quoted 12 lines · Jeff Layton

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;
        ...
}
Quoted 9 lines

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.

Quoted 9 lines

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):

Quoted 7 lines
        if (caa_unlikely(__tracepoint_##provider##___##name.state)) {
                // marshal on stack array here
                tracepoint(...);
        }

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

Yes, starting from 2.7 (currently in RC), you can use the "tracepoint_enabled"[1] macro to conditionally perform your marshaling.

Regards,
Jérémie

[1] https://github.com/lttng/lttng-ust/blob/master/include/lttng/tracepoint.h#L48

Quoted 3 lines

--
Jeff Layton <[email protected]>

Signature · 8 lines
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com

_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev