[lttng-dev] decoding tracef msg string via babeltrace API

Jérémie Galarneau jeremie.galarneau at efficios.com
Thu Apr 4 14:25:51 EDT 2019


Hi Milian,

I have pushed a fix [1] in the stable-1.5 branch that addresses the
issue you have encountered with using bt_ctf_get_field_list().
This makes it possible to consume a character sequence's content.

The commit message contains an example to show how to essentially
perform what the 'ctf-text' format plug-in achieves by accessing the
internal string field.

Let me know if that works for you and I'll release an updated version
of the 1.5 branch.

Thanks,
Jérémie

[1] https://github.com/efficios/babeltrace/commit/e7f1ad36b82bb8651c91c6c6faf8b92f145f32bc

On Tue, 2 Apr 2019 at 15:09, Milian Wolff via lttng-dev
<lttng-dev at lists.lttng.org> wrote:
>
> Hey all
>
> I added a tracef tracepoint and want to decode it's `msg` field in the
> BT_EVENT_FIELDS scope. Babeltrace on the command line seems to handle this
> nicely, but whatever I try, it doesn't work with the API.
>
> I'm using babeltrace from the stable-1.5 branch.
>
> First, the output from babeltrace on the command line:
>
> ```
> event {
>         name = "lttng_ust_tracef:event";
>         id = 9;
>         stream_id = 0;
>         loglevel = 14;
>         fields := struct {
>                 integer { size = 32; align = 8; signed = 0; encoding = none;
> base = 10; } __msg_length;
>                 integer { size = 8; align = 8; signed = 1; encoding = UTF8;
> base = 10; } _msg[ __msg_length ];
>         };
> };
> ...
> timestamp = 15:56:15.404973865, delta = +0.000023594, trace = 1000/64-bit,
> trace:hostname = agathebauer, trace:domain = ust, loglevel = TRACE_DEBUG (14),
> name = lttng_ust_tracef:event, stream.packet.context = { timestamp_begin =
> 4382372875047, timestamp_end = 4462741641629, content_size = 47177888,
> packet_size = 47185920, packet_seq_num = 0, events_discarded = 0, cpu_id = 3
> }, stream.event.header = { id = ( "compact" : container = 9 ), v = { compact =
> { timestamp = 70385656 } } }, event.fields = { _msg_length = 33, msg =
> "run_event_entry: ImageCache, 1000" }
> ...
> ```
>
> Now, in my code I find the event and then I've tried:
>
> ```
>             auto definition = bt_ctf_get_field(event, scope, "msg");
>             auto declaration = bt_ctf_get_decl_from_def(definition);
>             auto type = bt_ctf_field_type(declaration);
>             auto encoding = bt_ctf_get_encoding(declaration);
>             auto string = bt_ctf_get_string(definition);
>             auto char_array = bt_ctf_get_char_array(definition);
>             const bt_definition* const* list = nullptr;
>             unsigned num_list = 0;
>             auto field_list_ret = bt_ctf_get_field_list(ctf_event, definition,
> &list, &num_list);
>             fprintf(stderr, "tracef dbg: %p %p | %d %d | %s | %s | %p %u
> %d\n", definition, declaration, type, encoding, string, char_array, list,
> num_list, field_list_ret);
> ```
>
> the output is:
>
> ```
> tracef dbg: 0x55e4c5b084f0 0x55e4c5b3f220 | 9 1 | (null) | (null) | (nil) 0 -1
>
> ```
>
> So, it's a sequence (type 9), but I can't get the sequence... Actually, when I
> tried this the firs ttime without patching babeltrace, then it crashed in
> events.c:256 [1]. The def_sequence is non-null, but def_sequence->elems is
> null and that's not checked...
>
> [1]: https://github.com/efficios/babeltrace/blob/stable-1.5/formats/ctf/
> events.c#L256
>
> I'm quite stumped - what am I doing wrong? How does babeltrace handle the
> string-decoding of tracef's msg arg?
>
> Thanks
> --
> Milian Wolff | milian.wolff at kdab.com | Senior Software Engineer
> KDAB (Deutschland) GmbH, a KDAB Group company
> Tel: +49-30-521325470
> IKDAB - The Qt, C++ and OpenGL Experts_______________________________________________
> lttng-dev mailing list
> lttng-dev at lists.lttng.org
> https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev



-- 
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com


More information about the lttng-dev mailing list