[lttng-dev] Sequence of strings

Francis Giraldeau francis.giraldeau at gmail.com
Tue Jan 20 09:52:15 EST 2015


Thanks Philippe, I confirm that it works as you suggested.

metadata:

event {
name = "foo";
id = 0;
stream_id = 0;
fields := struct {
uint32_t _len; /* byte len */
uint8_t _num; /* number of strings */
string _mgs[_num]; /* concatenated strings (byte array) */
};
};

code:
        char *msg = "a\0bb\0ccc\0";
        int len = 9;
        int num = 3;
        barectf_trace_foo(pctx, len, num, msg);

And the output of babeltrace:

[18:32:19.663305604] (+?.?????????) foo: { }, { len = 9, num = 3, mgs = [
[0] = "a", [1] = "bb", [2] = "ccc" ] }

I also tried the same trick with a struct, and it seems to work:

metadata:

struct blob {
string _one;
string _two;
};

event {
name = "bar";
id = 1;
stream_id = 0;
fields := struct {
uint32_t _len; /* byte len */
uint8_t _num; /* number of structs */
struct blob _data[_num]; /* byte array */
};
};

code:
msg = "aa\0bb\0cc\0dd\0";
len = 12;
num = 2;
barectf_trace_bar(pctx, len, num, msg);

babeltrace output:

[18:40:37.695057872] (+0.000002364) bar: { }, { len = 12, num = 2, data = [
[0] = { one = "aa", two = "bb" }, [1] = { one = "cc", two = "dd" } ] }


Cheers!

Francis

2015-01-19 19:16 GMT-05:00 Philippe Proulx <eeppeliteloop at gmail.com>:

> On Mon, Jan 19, 2015 at 5:50 PM, Francis Giraldeau
> <francis.giraldeau at gmail.com> wrote:
> >
> > Hi,
> >
> > I would like to record a sequence of strings. Here is an example:
> >
> > struct foo {
> >   string _my_string;
> > };
> >
> > event {
> >   ...
> >   fields := struct {
> >     uint8_t _num;
> >     struct foo _items[_num];
> >   };
> > };
> >
> > The program barectf does not allow it, and I wanted to know whether it's
> an implementation limitation or if CTF supports it at all.
>
> Hi Francis,
>
> CTF and Babeltrace certainly allow this.
>
> It's a current barectf limitation: inner structures, as well as
> array/sequence
> elements must have a fixed size. This is because they are currently copied
> to the packet buffer as is using memcpy() with this precomputed fixed size.
>
> Your best approach today is to precompute the total length of all the
> concatenated strings (including terminating null characters) in your
> application
> code, and use a sequence of bytes instead, also keeping the original number
> of strings:
>
>     event {
>       ...
>       fields := struct {
>         uint32_t _len; /* length of all strings */
>         uint8_t _num; /* number of concatenated strings */
>         uint8_t _strings[_len];
>       };
>     };
>
> Then, after running barectf, change this for:
>
>     event {
>       ...
>       fields := struct {
>         uint32_t _len;
>         uint8_t _num;
>         string _strings[_num];
>       };
>     };
>
> and you should be able to see a sequence of strings in Babeltrace once
> your streams are produced by barectf C code.
>
> Ugly, but should work!
>
> Supporting variable-length inner structures and array/sequence elements
> is definitely on the TODO list for a future barectf release.
>
> Thanks for the input,
> Phil
>
> >
> > Thanks,
> >
> > Francis
> >
> > _______________________________________________
> > lttng-dev mailing list
> > lttng-dev at lists.lttng.org
> > http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lttng.org/pipermail/lttng-dev/attachments/20150120/d236854a/attachment-0001.html>


More information about the lttng-dev mailing list