Mirror of the lttng-dev mailing list
 help / color / mirror / Atom feed
* [lttng-dev] Reading CTF trace using Babeltrace API
       [not found]           ` <E537659DE2B2C54EBD9FC9180F059880395D955070@zulu.esk.fraunhofer.de>
@ 2013-11-03 19:39             ` Salman Rafiq
  2013-11-07 21:40             ` Jérémie Galarneau
  1 sibling, 0 replies; 3+ messages in thread
From: Salman Rafiq @ 2013-11-03 19:39 UTC (permalink / raw)


Hi J?r?mie,

Sorry for being a little impatient. 
Please do let me know if you can provide some information regarding my previous email.

Thanks!
Salman

--
Salman Rafiq
Gesch?ftsfeld Industrial Communication
Fraunhofer-Institut  f?r Eingebettete Systeme und Kommunikationstechnik ESK

Hansastra?e 32 | 80686 M?nchen
Telefon, Fax:  +49 89 547088-356 | +49 89 547088-221
E-Mail:   salman.rafiq at esk.fraunhofer.de

Internet:
http://www.esk.fraunhofer.de
http://www.twitter.com/FraunhoferESK

________________________________________
From: Salman Rafiq [salman.rafiq@esk.fraunhofer.de]
Sent: Wednesday, October 23, 2013 4:50 PM
To: J?r?mie Galarneau; Mathieu Desnoyers
Cc: lttng-dev at lists.lttng.org; Julien Desfossez
Subject: Re: [lttng-dev] Reading CTF trace using Babeltrace API

Hello again :)

While reading Kernel trace events (system calls), I came across an issue related to reading the field 'args' inside 'sys_unknown' system call event.

Below is the information I get using public babeltrace API's for the event field type.
Ctf_type_id = 8  (CTF_TYPE_ARRAY)


But when I try to read the value for the field using the following API
char * bt_ctf_get_char_array(const struct bt_definition *field);

I receive null value. Also it gives me warning that I am instead extracting a String.
[warning] Extracting String

Also, I am unable to read the value using the following API.
char *bt_ctf_get_string(const struct bt_definition *field);


below is the sample event recorded:
[00002934900435406801] (+0.000009630) sys_unknown: { cpu_id = 3 }, { id = 277, args = [ [0] = 22, [1] = 0, [2] = 4096, [3] = 2, [4] = 4096, [5] = 5 ] }

AND the event definition:
event {
        name = sys_unknown;
        id = 2;
        stream_id = 0;
        fields := struct {
                integer { size = 32; align = 8; signed = 0; encoding = none; base = 10; } _id
                integer { size = 64; align = 8; signed = 0; encoding = none; base = 10; } _args[6];
        };
};


Any suggestion related to that will be very helpful.
Thanks!

Best Regards,
Salman
--
Salman Rafiq
Gesch?ftsfeld Industrial Communication
Fraunhofer-Institut  f?r Eingebettete Systeme und Kommunikationstechnik ESK

Hansastra?e 32 | 80686 M?nchen
Telefon, Fax:  +49 89 547088-356 | +49 89 547088-221
E-Mail:   salman.rafiq at esk.fraunhofer.de

Internet:
http://www.esk.fraunhofer.de
http://www.twitter.com/FraunhoferESK


-----Original Message-----
From: jeremie.galarneau@gmail.com [mailto:jeremie.galarneau@gmail.com] On Behalf Of J?r?mie Galarneau
Sent: Mittwoch, 9. Oktober 2013 01:50
To: Mathieu Desnoyers
Cc: Salman Rafiq; Julien Desfossez; lttng-dev at lists.lttng.org
Subject: Re: Reading CTF trace using Babeltrace API

On Tue, Oct 8, 2013 at 7:14 PM, Mathieu Desnoyers <mathieu.desnoyers at efficios.com> wrote:
> ----- Original Message -----
>> From: "J?r?mie Galarneau" <jeremie.galarneau@efficios.com>
>> To: "Salman Rafiq" <salman.rafiq at esk.fraunhofer.de>
>> Cc: jdesfossez at efficios.com, lttng-dev at lists.lttng.org, "Mathieu
>> Desnoyers" <mathieu.desnoyers at efficios.com>
>> Sent: Tuesday, October 8, 2013 2:52:38 PM
>> Subject: Re: Reading CTF trace using Babeltrace API
> [...]
>>
>> The problem is that the "id" fields in both struct
>> event_header_compact and event_header_large acts as a variant's tag
>> enumeration.
>>
>> For instance, if we take a look at the event_header_compact
>> structure,
>>
>> struct event_header_compact {
>>         enum : uint5_t { compact = 0 ... 30, extended = 31 } id;
>>         variant <id> {
>>                 struct {
>>                         uint27_clock_monotonic_t timestamp;
>>                 } compact;
>>                 struct {
>>                         uint32_t id;
>>                         uint64_clock_monotonic_t timestamp;
>>                 } extended;
>>         } v;
>> } align(8);
>>
>> The "enum id" field will indicate the event's id if it has a value of
>> [0, 30]. It also indicates that the "compact" structure is selected
>> in the variant that follows. If id == 31, the "extended" structure is
>> selected, which means that you should retrieve the "id" field's value
>> from that structure.
>>
>> Since code is worth a thousand words, here's a more complete code
>> sample to read the id fields.
>>
>> while ((ctf_event = bt_ctf_iter_read_event(iter))) {
>>         uint64_t event_id = 0;
>>         const struct bt_definition *stream_event_header_scope =
>>                 bt_ctf_get_top_level_scope(
>>                         ctf_event, BT_STREAM_EVENT_HEADER);
>>         const struct bt_definition *id_definition =
>>                 bt_ctf_get_field(ctf_event, stream_event_header_scope,
>>                                  "id");
>>         const struct bt_definition *v_definition =
>>                 bt_ctf_get_field(ctf_event, stream_event_header_scope,
>>                                  "v");
>>
>>         /* "id may be an enum, get the underlying integer if it's the case */
>>         if (id_definition &&
>> bt_ctf_field_type(bt_ctf_get_decl_from_def(id_definition)) ==
>> CTF_TYPE_ENUM) {
>>                 id_definition = bt_ctf_get_enum_int(id_definition);
>>         }
>>
>>         /* Check if there is a "v" field and if it contains an "id" field */
>>         if (v_definition &&
>> bt_ctf_field_type(bt_ctf_get_decl_from_def(v_definition)) ==
>> CTF_TYPE_STRUCT) {
>>                 struct bt_definition const * const *list = NULL;
>>                 unsigned int count = 0;
>>                 unsigned int i;
>>
>>                 ret = bt_ctf_get_field_list(ctf_event, v_definition,
>> &list, &count);
>>                 if (ret) {
>>                         goto end;
>>                 }
>>
>>                 for (i = 0; i < count; i++) {
>>                         const char *name =
>> bt_ctf_field_name(list[i]);
>>
>>                         if (strcmp("id", name) == 0) {
>>                                 id_definition = list[i];
>>                                 break;
>>                         }
>>                 }
>
> Instead of doing this bt_ctf_get_field_list() and iteration, can't we simply use bt_ctf_get_field() to try getting the struct bt_definition ?

Right. I was under the impression the bt_ctf_get_field() would only work on scopes, but it's not the case.

Thanks!
J?r?mie

>
> Thanks,
>
> Mathieu
>
>>         }
>>
>>         if (id_definition &&
>> bt_ctf_field_type(bt_ctf_get_decl_from_def(id_definition)) ==
>> CTF_TYPE_INTEGER) {
>>                 event_id = bt_ctf_get_uint64(id_definition);
>>         }
>>
>>         printf("id = %" PRIu64 "\n", event_id); }
>>
>> Regards,
>> J?r?mie
>>
>> > Thanks a lot!
>> >
>> > Regards,
>> > Salman
>> >
>> > --
>> > Salman Rafiq
>> > Gesch?ftsfeld Industrial Communication Fraunhofer-Institut  f?r
>> > Eingebettete Systeme und Kommunikationstechnik ESK
>> >
>> > Hansastra?e 32 | 80686 M?nchen
>> > Telefon, Fax:  +49 89 547088-356 | +49 89 547088-221
>> > E-Mail:   salman.rafiq at esk.fraunhofer.de
>> >
>> > Internet:
>> > http://www.esk.fraunhofer.de
>> > http://www.twitter.com/FraunhoferESK
>> >
>> >
>> > -----Original Message-----
>> > From: jeremie.galarneau@gmail.com
>> > [mailto:jeremie.galarneau at gmail.com] On Behalf Of J?r?mie Galarneau
>> > Sent: Mittwoch, 2. Oktober 2013 20:25
>> > To: Salman Rafiq
>> > Cc: jdesfossez at efficios.com; lttng-dev at lists.lttng.org; Mathieu
>> > Desnoyers
>> > Subject: Re: Reading CTF trace using Babeltrace API
>> >
>> > On Wed, Oct 2, 2013 at 12:55 PM, Salman Rafiq
>> > <salman.rafiq at esk.fraunhofer.de> wrote:
>> >> Dear LTTngers,
>> >>
>> >> I would like to ask few questions related to the API's for reading
>> >> CTF traces.
>> >>
>> >> 1.  Is there any way to read CTF metadata independently, like we
>> >> have certain API's to read the events.
>> >>
>> >
>> > Not from the public API, unfortunately.
>> >
>> >> 2. There are certain scopes defined in ctf/events.h like:
>> >>         BT_TRACE_PACKET_HEADER          = 0,
>> >>         BT_STREAM_PACKET_CONTEXT        = 1,
>> >>         BT_STREAM_EVENT_HEADER          = 2,
>> >>         BT_STREAM_EVENT_CONTEXT         = 3,
>> >>         BT_EVENT_CONTEXT                = 4,
>> >>         BT_EVENT_FIELDS                 = 5,
>> >>
>> >> I could not figure out the way to ready the fields 'id' and
>> >> 'stream_id', for a particular event while iterating through the trace.
>> >> Though I can ready the event name using an API and fields using
>> >> BT_EVENT_FIELDS as a scope.
>> >> For e.g. consider the
>> >>
>> >> event {
>> >>         name = sched_migrate_task;
>> >>         id = 1;
>> >>         stream_id = 0;
>> >>         fields := struct {
>> >>                 integer { size = 8; align = 8; signed = 1; encoding =
>> >>                 UTF8; base = 10; } _comm[16];
>> >>                 integer { size = 32; align = 8; signed = 1; encoding =
>> >>                 none; base = 10; } _tid;
>> >>                 integer { size = 32; align = 8; signed = 1; encoding =
>> >>                 none; base = 10; } _prio;
>> >>                 integer { size = 32; align = 8; signed = 1; encoding =
>> >>                 none; base = 10; } _orig_cpu;
>> >>                 integer { size = 32; align = 8; signed = 1; encoding =
>> >>                 none; base = 10; } _dest_cpu;
>> >>         };
>> >> };
>> >>
>> >
>> > The "id" field is part of the BT_STREAM_EVENT_HEADER scope, while
>> > the "stream_id" field is part of the BT_TRACE_PACKET_HEADER scope.
>> >
>> > The code below is adapted from converter/babeltrace.c's
>> > convert_trace() loop to print both values.
>> >
>> > while ((ctf_event = bt_ctf_iter_read_event(iter))) {
>> >
>> >         const struct bt_definition *stream_event_header_scope =
>> >                 bt_ctf_get_top_level_scope(
>> >                         ctf_event, BT_STREAM_EVENT_HEADER);
>> >         const struct bt_definition *id_field =
>> >                 bt_ctf_get_field(
>> >                         ctf_event, stream_event_header_scope,
>> > "id");
>> >
>> >         printf("id = %" PRIu64 "\n", bt_ctf_get_uint64(id_field));
>> >
>> >         const struct bt_definition *packet_header_scope =
>> >                 bt_ctf_get_top_level_scope(
>> >                         ctf_event, BT_TRACE_PACKET_HEADER);
>> >         const struct bt_definition *stream_id_field =
>> >                 bt_ctf_get_field(
>> >                         ctf_event, packet_header_scope,
>> > "stream_id");
>> >
>> >         printf("stream_id = %" PRIu64 "\n", bt_ctf_get_uint64(
>> >                        stream_id_field)); [...] }
>> >
>> > Regards,
>> > J?r?mie
>> >
>> >>
>> >> Any help or suggestion related to this issue will be really appreciated.
>> >> Thanks!
>> >>
>> >> Regards,
>> >> Salman
>> >>
>> >> --
>> >> Salman Rafiq
>> >> Gesch?ftsfeld Industrial Communication Fraunhofer-Institut  f?r
>> >> Eingebettete Systeme und Kommunikationstechnik ESK
>> >>
>> >> Hansastra?e 32 | 80686 M?nchen
>> >> Telefon, Fax:  +49 89 547088-356 | +49 89 547088-221
>> >> E-Mail:   salman.rafiq at esk.fraunhofer.de
>> >>
>> >> Internet:
>> >> http://www.esk.fraunhofer.de
>> >> http://www.twitter.com/FraunhoferESK
>> >>
>> >
>> >
>> >
>> > --
>> > J?r?mie Galarneau
>> > EfficiOS Inc.
>> > http://www.efficios.com
>>
>>
>>
>> --
>> J?r?mie Galarneau
>> EfficiOS Inc.
>> http://www.efficios.com
>>
>
> --
> Mathieu Desnoyers
> EfficiOS Inc.
> http://www.efficios.com



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

_______________________________________________
lttng-dev mailing list
lttng-dev at lists.lttng.org
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [lttng-dev] Reading CTF trace using Babeltrace API
       [not found]           ` <E537659DE2B2C54EBD9FC9180F059880395D955070@zulu.esk.fraunhofer.de>
  2013-11-03 19:39             ` [lttng-dev] Reading CTF trace using Babeltrace API Salman Rafiq
@ 2013-11-07 21:40             ` Jérémie Galarneau
  2013-11-20 12:45               ` Salman Rafiq
  1 sibling, 1 reply; 3+ messages in thread
From: Jérémie Galarneau @ 2013-11-07 21:40 UTC (permalink / raw)


On Wed, Oct 23, 2013 at 10:50 AM, Salman Rafiq
<salman.rafiq at esk.fraunhofer.de> wrote:
> Hello again :)
>
> While reading Kernel trace events (system calls), I came across an issue related to reading the field 'args' inside 'sys_unknown' system call event.
>
> Below is the information I get using public babeltrace API's for the event field type.
> Ctf_type_id = 8  (CTF_TYPE_ARRAY)
>
>
> But when I try to read the value for the field using the following API
> char * bt_ctf_get_char_array(const struct bt_definition *field);
>
> I receive null value. Also it gives me warning that I am instead extracting a String.
> [warning] Extracting String
>
> Also, I am unable to read the value using the following API.
> char *bt_ctf_get_string(const struct bt_definition *field);
>

You should be using the bt_ctf_get_index() function to access the
individual elements of _args. Let me know how that works out.

As for the "Extracting string" message, it can indeed be misleading...

J?r?mie

>
> below is the sample event recorded:
> [00002934900435406801] (+0.000009630) sys_unknown: { cpu_id = 3 }, { id = 277, args = [ [0] = 22, [1] = 0, [2] = 4096, [3] = 2, [4] = 4096, [5] = 5 ] }
>
> AND the event definition:
> event {
>         name = sys_unknown;
>         id = 2;
>         stream_id = 0;
>         fields := struct {
>                 integer { size = 32; align = 8; signed = 0; encoding = none; base = 10; } _id
>                 integer { size = 64; align = 8; signed = 0; encoding = none; base = 10; } _args[6];
>         };
> };
>
>
> Any suggestion related to that will be very helpful.
> Thanks!
>
> Best Regards,
> Salman
> --
> Salman Rafiq
> Gesch?ftsfeld Industrial Communication
> Fraunhofer-Institut  f?r Eingebettete Systeme und Kommunikationstechnik ESK
>
> Hansastra?e 32 | 80686 M?nchen
> Telefon, Fax:  +49 89 547088-356 | +49 89 547088-221
> E-Mail:   salman.rafiq at esk.fraunhofer.de
>
> Internet:
> http://www.esk.fraunhofer.de
> http://www.twitter.com/FraunhoferESK
>
>
> -----Original Message-----
> From: jeremie.galarneau@gmail.com [mailto:jeremie.galarneau@gmail.com] On Behalf Of J?r?mie Galarneau
> Sent: Mittwoch, 9. Oktober 2013 01:50
> To: Mathieu Desnoyers
> Cc: Salman Rafiq; Julien Desfossez; lttng-dev at lists.lttng.org
> Subject: Re: Reading CTF trace using Babeltrace API
>
> On Tue, Oct 8, 2013 at 7:14 PM, Mathieu Desnoyers <mathieu.desnoyers at efficios.com> wrote:
>> ----- Original Message -----
>>> From: "J?r?mie Galarneau" <jeremie.galarneau@efficios.com>
>>> To: "Salman Rafiq" <salman.rafiq at esk.fraunhofer.de>
>>> Cc: jdesfossez at efficios.com, lttng-dev at lists.lttng.org, "Mathieu
>>> Desnoyers" <mathieu.desnoyers at efficios.com>
>>> Sent: Tuesday, October 8, 2013 2:52:38 PM
>>> Subject: Re: Reading CTF trace using Babeltrace API
>> [...]
>>>
>>> The problem is that the "id" fields in both struct
>>> event_header_compact and event_header_large acts as a variant's tag
>>> enumeration.
>>>
>>> For instance, if we take a look at the event_header_compact
>>> structure,
>>>
>>> struct event_header_compact {
>>>         enum : uint5_t { compact = 0 ... 30, extended = 31 } id;
>>>         variant <id> {
>>>                 struct {
>>>                         uint27_clock_monotonic_t timestamp;
>>>                 } compact;
>>>                 struct {
>>>                         uint32_t id;
>>>                         uint64_clock_monotonic_t timestamp;
>>>                 } extended;
>>>         } v;
>>> } align(8);
>>>
>>> The "enum id" field will indicate the event's id if it has a value of
>>> [0, 30]. It also indicates that the "compact" structure is selected
>>> in the variant that follows. If id == 31, the "extended" structure is
>>> selected, which means that you should retrieve the "id" field's value
>>> from that structure.
>>>
>>> Since code is worth a thousand words, here's a more complete code
>>> sample to read the id fields.
>>>
>>> while ((ctf_event = bt_ctf_iter_read_event(iter))) {
>>>         uint64_t event_id = 0;
>>>         const struct bt_definition *stream_event_header_scope =
>>>                 bt_ctf_get_top_level_scope(
>>>                         ctf_event, BT_STREAM_EVENT_HEADER);
>>>         const struct bt_definition *id_definition =
>>>                 bt_ctf_get_field(ctf_event, stream_event_header_scope,
>>>                                  "id");
>>>         const struct bt_definition *v_definition =
>>>                 bt_ctf_get_field(ctf_event, stream_event_header_scope,
>>>                                  "v");
>>>
>>>         /* "id may be an enum, get the underlying integer if it's the case */
>>>         if (id_definition &&
>>> bt_ctf_field_type(bt_ctf_get_decl_from_def(id_definition)) ==
>>> CTF_TYPE_ENUM) {
>>>                 id_definition = bt_ctf_get_enum_int(id_definition);
>>>         }
>>>
>>>         /* Check if there is a "v" field and if it contains an "id" field */
>>>         if (v_definition &&
>>> bt_ctf_field_type(bt_ctf_get_decl_from_def(v_definition)) ==
>>> CTF_TYPE_STRUCT) {
>>>                 struct bt_definition const * const *list = NULL;
>>>                 unsigned int count = 0;
>>>                 unsigned int i;
>>>
>>>                 ret = bt_ctf_get_field_list(ctf_event, v_definition,
>>> &list, &count);
>>>                 if (ret) {
>>>                         goto end;
>>>                 }
>>>
>>>                 for (i = 0; i < count; i++) {
>>>                         const char *name =
>>> bt_ctf_field_name(list[i]);
>>>
>>>                         if (strcmp("id", name) == 0) {
>>>                                 id_definition = list[i];
>>>                                 break;
>>>                         }
>>>                 }
>>
>> Instead of doing this bt_ctf_get_field_list() and iteration, can't we simply use bt_ctf_get_field() to try getting the struct bt_definition ?
>
> Right. I was under the impression the bt_ctf_get_field() would only work on scopes, but it's not the case.
>
> Thanks!
> J?r?mie
>
>>
>> Thanks,
>>
>> Mathieu
>>
>>>         }
>>>
>>>         if (id_definition &&
>>> bt_ctf_field_type(bt_ctf_get_decl_from_def(id_definition)) ==
>>> CTF_TYPE_INTEGER) {
>>>                 event_id = bt_ctf_get_uint64(id_definition);
>>>         }
>>>
>>>         printf("id = %" PRIu64 "\n", event_id); }
>>>
>>> Regards,
>>> J?r?mie
>>>
>>> > Thanks a lot!
>>> >
>>> > Regards,
>>> > Salman
>>> >
>>> > --
>>> > Salman Rafiq
>>> > Gesch?ftsfeld Industrial Communication Fraunhofer-Institut  f?r
>>> > Eingebettete Systeme und Kommunikationstechnik ESK
>>> >
>>> > Hansastra?e 32 | 80686 M?nchen
>>> > Telefon, Fax:  +49 89 547088-356 | +49 89 547088-221
>>> > E-Mail:   salman.rafiq at esk.fraunhofer.de
>>> >
>>> > Internet:
>>> > http://www.esk.fraunhofer.de
>>> > http://www.twitter.com/FraunhoferESK
>>> >
>>> >
>>> > -----Original Message-----
>>> > From: jeremie.galarneau@gmail.com
>>> > [mailto:jeremie.galarneau at gmail.com] On Behalf Of J?r?mie Galarneau
>>> > Sent: Mittwoch, 2. Oktober 2013 20:25
>>> > To: Salman Rafiq
>>> > Cc: jdesfossez at efficios.com; lttng-dev at lists.lttng.org; Mathieu
>>> > Desnoyers
>>> > Subject: Re: Reading CTF trace using Babeltrace API
>>> >
>>> > On Wed, Oct 2, 2013 at 12:55 PM, Salman Rafiq
>>> > <salman.rafiq at esk.fraunhofer.de> wrote:
>>> >> Dear LTTngers,
>>> >>
>>> >> I would like to ask few questions related to the API's for reading
>>> >> CTF traces.
>>> >>
>>> >> 1.  Is there any way to read CTF metadata independently, like we
>>> >> have certain API's to read the events.
>>> >>
>>> >
>>> > Not from the public API, unfortunately.
>>> >
>>> >> 2. There are certain scopes defined in ctf/events.h like:
>>> >>         BT_TRACE_PACKET_HEADER          = 0,
>>> >>         BT_STREAM_PACKET_CONTEXT        = 1,
>>> >>         BT_STREAM_EVENT_HEADER          = 2,
>>> >>         BT_STREAM_EVENT_CONTEXT         = 3,
>>> >>         BT_EVENT_CONTEXT                = 4,
>>> >>         BT_EVENT_FIELDS                 = 5,
>>> >>
>>> >> I could not figure out the way to ready the fields 'id' and
>>> >> 'stream_id', for a particular event while iterating through the trace.
>>> >> Though I can ready the event name using an API and fields using
>>> >> BT_EVENT_FIELDS as a scope.
>>> >> For e.g. consider the
>>> >>
>>> >> event {
>>> >>         name = sched_migrate_task;
>>> >>         id = 1;
>>> >>         stream_id = 0;
>>> >>         fields := struct {
>>> >>                 integer { size = 8; align = 8; signed = 1; encoding =
>>> >>                 UTF8; base = 10; } _comm[16];
>>> >>                 integer { size = 32; align = 8; signed = 1; encoding =
>>> >>                 none; base = 10; } _tid;
>>> >>                 integer { size = 32; align = 8; signed = 1; encoding =
>>> >>                 none; base = 10; } _prio;
>>> >>                 integer { size = 32; align = 8; signed = 1; encoding =
>>> >>                 none; base = 10; } _orig_cpu;
>>> >>                 integer { size = 32; align = 8; signed = 1; encoding =
>>> >>                 none; base = 10; } _dest_cpu;
>>> >>         };
>>> >> };
>>> >>
>>> >
>>> > The "id" field is part of the BT_STREAM_EVENT_HEADER scope, while
>>> > the "stream_id" field is part of the BT_TRACE_PACKET_HEADER scope.
>>> >
>>> > The code below is adapted from converter/babeltrace.c's
>>> > convert_trace() loop to print both values.
>>> >
>>> > while ((ctf_event = bt_ctf_iter_read_event(iter))) {
>>> >
>>> >         const struct bt_definition *stream_event_header_scope =
>>> >                 bt_ctf_get_top_level_scope(
>>> >                         ctf_event, BT_STREAM_EVENT_HEADER);
>>> >         const struct bt_definition *id_field =
>>> >                 bt_ctf_get_field(
>>> >                         ctf_event, stream_event_header_scope,
>>> > "id");
>>> >
>>> >         printf("id = %" PRIu64 "\n", bt_ctf_get_uint64(id_field));
>>> >
>>> >         const struct bt_definition *packet_header_scope =
>>> >                 bt_ctf_get_top_level_scope(
>>> >                         ctf_event, BT_TRACE_PACKET_HEADER);
>>> >         const struct bt_definition *stream_id_field =
>>> >                 bt_ctf_get_field(
>>> >                         ctf_event, packet_header_scope,
>>> > "stream_id");
>>> >
>>> >         printf("stream_id = %" PRIu64 "\n", bt_ctf_get_uint64(
>>> >                        stream_id_field)); [...] }
>>> >
>>> > Regards,
>>> > J?r?mie
>>> >
>>> >>
>>> >> Any help or suggestion related to this issue will be really appreciated.
>>> >> Thanks!
>>> >>
>>> >> Regards,
>>> >> Salman
>>> >>
>>> >> --
>>> >> Salman Rafiq
>>> >> Gesch?ftsfeld Industrial Communication Fraunhofer-Institut  f?r
>>> >> Eingebettete Systeme und Kommunikationstechnik ESK
>>> >>
>>> >> Hansastra?e 32 | 80686 M?nchen
>>> >> Telefon, Fax:  +49 89 547088-356 | +49 89 547088-221
>>> >> E-Mail:   salman.rafiq at esk.fraunhofer.de
>>> >>
>>> >> Internet:
>>> >> http://www.esk.fraunhofer.de
>>> >> http://www.twitter.com/FraunhoferESK
>>> >>
>>> >
>>> >
>>> >
>>> > --
>>> > J?r?mie Galarneau
>>> > EfficiOS Inc.
>>> > http://www.efficios.com
>>>
>>>
>>>
>>> --
>>> J?r?mie Galarneau
>>> EfficiOS Inc.
>>> http://www.efficios.com
>>>
>>
>> --
>> Mathieu Desnoyers
>> EfficiOS Inc.
>> http://www.efficios.com
>
>
>
> --
> J?r?mie Galarneau
> EfficiOS Inc.
> http://www.efficios.com



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



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [lttng-dev] Reading CTF trace using Babeltrace API
  2013-11-07 21:40             ` Jérémie Galarneau
@ 2013-11-20 12:45               ` Salman Rafiq
  0 siblings, 0 replies; 3+ messages in thread
From: Salman Rafiq @ 2013-11-20 12:45 UTC (permalink / raw)


Thanks J?r?mie. It worked out fine by using the bt_ctf_get_index() function.
As for now, I ignored the warning " [warning] Extracting String".


Regards,
Salman
--
Salman Rafiq
Gesch?ftsfeld Industrial Communication
Fraunhofer-Institut  f?r Eingebettete Systeme und Kommunikationstechnik ESK

Hansastra?e 32 | 80686 M?nchen
Telefon, Fax:? +49 89 547088-356 | +49 89 547088-221
E-Mail:?? salman.rafiq at esk.fraunhofer.de
? 
Internet: 
http://www.esk.fraunhofer.de
http://www.twitter.com/FraunhoferESK

-----Original Message-----
From: jeremie.galarneau@gmail.com [mailto:jeremie.galarneau@gmail.com] On Behalf Of J?r?mie Galarneau
Sent: Donnerstag, 7. November 2013 22:41
To: Salman Rafiq
Cc: Mathieu Desnoyers; Julien Desfossez; lttng-dev at lists.lttng.org
Subject: Re: Reading CTF trace using Babeltrace API

On Wed, Oct 23, 2013 at 10:50 AM, Salman Rafiq <salman.rafiq at esk.fraunhofer.de> wrote:
> Hello again :)
>
> While reading Kernel trace events (system calls), I came across an issue related to reading the field 'args' inside 'sys_unknown' system call event.
>
> Below is the information I get using public babeltrace API's for the event field type.
> Ctf_type_id = 8  (CTF_TYPE_ARRAY)
>
>
> But when I try to read the value for the field using the following API 
> char * bt_ctf_get_char_array(const struct bt_definition *field);
>
> I receive null value. Also it gives me warning that I am instead extracting a String.
> [warning] Extracting String
>
> Also, I am unable to read the value using the following API.
> char *bt_ctf_get_string(const struct bt_definition *field);
>

You should be using the bt_ctf_get_index() function to access the individual elements of _args. Let me know how that works out.

As for the "Extracting string" message, it can indeed be misleading...

J?r?mie

>
> below is the sample event recorded:
> [00002934900435406801] (+0.000009630) sys_unknown: { cpu_id = 3 }, { 
> id = 277, args = [ [0] = 22, [1] = 0, [2] = 4096, [3] = 2, [4] = 4096, 
> [5] = 5 ] }
>
> AND the event definition:
> event {
>         name = sys_unknown;
>         id = 2;
>         stream_id = 0;
>         fields := struct {
>                 integer { size = 32; align = 8; signed = 0; encoding = none; base = 10; } _id
>                 integer { size = 64; align = 8; signed = 0; encoding = none; base = 10; } _args[6];
>         };
> };
>
>
> Any suggestion related to that will be very helpful.
> Thanks!
>
> Best Regards,
> Salman
> --
> Salman Rafiq
> Gesch?ftsfeld Industrial Communication Fraunhofer-Institut  f?r 
> Eingebettete Systeme und Kommunikationstechnik ESK
>
> Hansastra?e 32 | 80686 M?nchen
> Telefon, Fax:  +49 89 547088-356 | +49 89 547088-221
> E-Mail:   salman.rafiq at esk.fraunhofer.de
>
> Internet:
> http://www.esk.fraunhofer.de
> http://www.twitter.com/FraunhoferESK
>
>
> -----Original Message-----
> From: jeremie.galarneau@gmail.com [mailto:jeremie.galarneau@gmail.com] 
> On Behalf Of J?r?mie Galarneau
> Sent: Mittwoch, 9. Oktober 2013 01:50
> To: Mathieu Desnoyers
> Cc: Salman Rafiq; Julien Desfossez; lttng-dev at lists.lttng.org
> Subject: Re: Reading CTF trace using Babeltrace API
>
> On Tue, Oct 8, 2013 at 7:14 PM, Mathieu Desnoyers <mathieu.desnoyers at efficios.com> wrote:
>> ----- Original Message -----
>>> From: "J?r?mie Galarneau" <jeremie.galarneau@efficios.com>
>>> To: "Salman Rafiq" <salman.rafiq at esk.fraunhofer.de>
>>> Cc: jdesfossez at efficios.com, lttng-dev at lists.lttng.org, "Mathieu 
>>> Desnoyers" <mathieu.desnoyers at efficios.com>
>>> Sent: Tuesday, October 8, 2013 2:52:38 PM
>>> Subject: Re: Reading CTF trace using Babeltrace API
>> [...]
>>>
>>> The problem is that the "id" fields in both struct 
>>> event_header_compact and event_header_large acts as a variant's tag 
>>> enumeration.
>>>
>>> For instance, if we take a look at the event_header_compact 
>>> structure,
>>>
>>> struct event_header_compact {
>>>         enum : uint5_t { compact = 0 ... 30, extended = 31 } id;
>>>         variant <id> {
>>>                 struct {
>>>                         uint27_clock_monotonic_t timestamp;
>>>                 } compact;
>>>                 struct {
>>>                         uint32_t id;
>>>                         uint64_clock_monotonic_t timestamp;
>>>                 } extended;
>>>         } v;
>>> } align(8);
>>>
>>> The "enum id" field will indicate the event's id if it has a value 
>>> of [0, 30]. It also indicates that the "compact" structure is 
>>> selected in the variant that follows. If id == 31, the "extended" 
>>> structure is selected, which means that you should retrieve the "id" 
>>> field's value from that structure.
>>>
>>> Since code is worth a thousand words, here's a more complete code 
>>> sample to read the id fields.
>>>
>>> while ((ctf_event = bt_ctf_iter_read_event(iter))) {
>>>         uint64_t event_id = 0;
>>>         const struct bt_definition *stream_event_header_scope =
>>>                 bt_ctf_get_top_level_scope(
>>>                         ctf_event, BT_STREAM_EVENT_HEADER);
>>>         const struct bt_definition *id_definition =
>>>                 bt_ctf_get_field(ctf_event, stream_event_header_scope,
>>>                                  "id");
>>>         const struct bt_definition *v_definition =
>>>                 bt_ctf_get_field(ctf_event, stream_event_header_scope,
>>>                                  "v");
>>>
>>>         /* "id may be an enum, get the underlying integer if it's the case */
>>>         if (id_definition &&
>>> bt_ctf_field_type(bt_ctf_get_decl_from_def(id_definition)) ==
>>> CTF_TYPE_ENUM) {
>>>                 id_definition = bt_ctf_get_enum_int(id_definition);
>>>         }
>>>
>>>         /* Check if there is a "v" field and if it contains an "id" field */
>>>         if (v_definition &&
>>> bt_ctf_field_type(bt_ctf_get_decl_from_def(v_definition)) ==
>>> CTF_TYPE_STRUCT) {
>>>                 struct bt_definition const * const *list = NULL;
>>>                 unsigned int count = 0;
>>>                 unsigned int i;
>>>
>>>                 ret = bt_ctf_get_field_list(ctf_event, v_definition, 
>>> &list, &count);
>>>                 if (ret) {
>>>                         goto end;
>>>                 }
>>>
>>>                 for (i = 0; i < count; i++) {
>>>                         const char *name = 
>>> bt_ctf_field_name(list[i]);
>>>
>>>                         if (strcmp("id", name) == 0) {
>>>                                 id_definition = list[i];
>>>                                 break;
>>>                         }
>>>                 }
>>
>> Instead of doing this bt_ctf_get_field_list() and iteration, can't we simply use bt_ctf_get_field() to try getting the struct bt_definition ?
>
> Right. I was under the impression the bt_ctf_get_field() would only work on scopes, but it's not the case.
>
> Thanks!
> J?r?mie
>
>>
>> Thanks,
>>
>> Mathieu
>>
>>>         }
>>>
>>>         if (id_definition &&
>>> bt_ctf_field_type(bt_ctf_get_decl_from_def(id_definition)) ==
>>> CTF_TYPE_INTEGER) {
>>>                 event_id = bt_ctf_get_uint64(id_definition);
>>>         }
>>>
>>>         printf("id = %" PRIu64 "\n", event_id); }
>>>
>>> Regards,
>>> J?r?mie
>>>
>>> > Thanks a lot!
>>> >
>>> > Regards,
>>> > Salman
>>> >
>>> > --
>>> > Salman Rafiq
>>> > Gesch?ftsfeld Industrial Communication Fraunhofer-Institut  f?r 
>>> > Eingebettete Systeme und Kommunikationstechnik ESK
>>> >
>>> > Hansastra?e 32 | 80686 M?nchen
>>> > Telefon, Fax:  +49 89 547088-356 | +49 89 547088-221
>>> > E-Mail:   salman.rafiq at esk.fraunhofer.de
>>> >
>>> > Internet:
>>> > http://www.esk.fraunhofer.de
>>> > http://www.twitter.com/FraunhoferESK
>>> >
>>> >
>>> > -----Original Message-----
>>> > From: jeremie.galarneau@gmail.com
>>> > [mailto:jeremie.galarneau at gmail.com] On Behalf Of J?r?mie 
>>> > Galarneau
>>> > Sent: Mittwoch, 2. Oktober 2013 20:25
>>> > To: Salman Rafiq
>>> > Cc: jdesfossez at efficios.com; lttng-dev at lists.lttng.org; Mathieu 
>>> > Desnoyers
>>> > Subject: Re: Reading CTF trace using Babeltrace API
>>> >
>>> > On Wed, Oct 2, 2013 at 12:55 PM, Salman Rafiq 
>>> > <salman.rafiq at esk.fraunhofer.de> wrote:
>>> >> Dear LTTngers,
>>> >>
>>> >> I would like to ask few questions related to the API's for 
>>> >> reading CTF traces.
>>> >>
>>> >> 1.  Is there any way to read CTF metadata independently, like we 
>>> >> have certain API's to read the events.
>>> >>
>>> >
>>> > Not from the public API, unfortunately.
>>> >
>>> >> 2. There are certain scopes defined in ctf/events.h like:
>>> >>         BT_TRACE_PACKET_HEADER          = 0,
>>> >>         BT_STREAM_PACKET_CONTEXT        = 1,
>>> >>         BT_STREAM_EVENT_HEADER          = 2,
>>> >>         BT_STREAM_EVENT_CONTEXT         = 3,
>>> >>         BT_EVENT_CONTEXT                = 4,
>>> >>         BT_EVENT_FIELDS                 = 5,
>>> >>
>>> >> I could not figure out the way to ready the fields 'id' and 
>>> >> 'stream_id', for a particular event while iterating through the trace.
>>> >> Though I can ready the event name using an API and fields using 
>>> >> BT_EVENT_FIELDS as a scope.
>>> >> For e.g. consider the
>>> >>
>>> >> event {
>>> >>         name = sched_migrate_task;
>>> >>         id = 1;
>>> >>         stream_id = 0;
>>> >>         fields := struct {
>>> >>                 integer { size = 8; align = 8; signed = 1; encoding =
>>> >>                 UTF8; base = 10; } _comm[16];
>>> >>                 integer { size = 32; align = 8; signed = 1; encoding =
>>> >>                 none; base = 10; } _tid;
>>> >>                 integer { size = 32; align = 8; signed = 1; encoding =
>>> >>                 none; base = 10; } _prio;
>>> >>                 integer { size = 32; align = 8; signed = 1; encoding =
>>> >>                 none; base = 10; } _orig_cpu;
>>> >>                 integer { size = 32; align = 8; signed = 1; encoding =
>>> >>                 none; base = 10; } _dest_cpu;
>>> >>         };
>>> >> };
>>> >>
>>> >
>>> > The "id" field is part of the BT_STREAM_EVENT_HEADER scope, while 
>>> > the "stream_id" field is part of the BT_TRACE_PACKET_HEADER scope.
>>> >
>>> > The code below is adapted from converter/babeltrace.c's
>>> > convert_trace() loop to print both values.
>>> >
>>> > while ((ctf_event = bt_ctf_iter_read_event(iter))) {
>>> >
>>> >         const struct bt_definition *stream_event_header_scope =
>>> >                 bt_ctf_get_top_level_scope(
>>> >                         ctf_event, BT_STREAM_EVENT_HEADER);
>>> >         const struct bt_definition *id_field =
>>> >                 bt_ctf_get_field(
>>> >                         ctf_event, stream_event_header_scope, 
>>> > "id");
>>> >
>>> >         printf("id = %" PRIu64 "\n", bt_ctf_get_uint64(id_field));
>>> >
>>> >         const struct bt_definition *packet_header_scope =
>>> >                 bt_ctf_get_top_level_scope(
>>> >                         ctf_event, BT_TRACE_PACKET_HEADER);
>>> >         const struct bt_definition *stream_id_field =
>>> >                 bt_ctf_get_field(
>>> >                         ctf_event, packet_header_scope, 
>>> > "stream_id");
>>> >
>>> >         printf("stream_id = %" PRIu64 "\n", bt_ctf_get_uint64(
>>> >                        stream_id_field)); [...] }
>>> >
>>> > Regards,
>>> > J?r?mie
>>> >
>>> >>
>>> >> Any help or suggestion related to this issue will be really appreciated.
>>> >> Thanks!
>>> >>
>>> >> Regards,
>>> >> Salman
>>> >>
>>> >> --
>>> >> Salman Rafiq
>>> >> Gesch?ftsfeld Industrial Communication Fraunhofer-Institut  f?r 
>>> >> Eingebettete Systeme und Kommunikationstechnik ESK
>>> >>
>>> >> Hansastra?e 32 | 80686 M?nchen
>>> >> Telefon, Fax:  +49 89 547088-356 | +49 89 547088-221
>>> >> E-Mail:   salman.rafiq at esk.fraunhofer.de
>>> >>
>>> >> Internet:
>>> >> http://www.esk.fraunhofer.de
>>> >> http://www.twitter.com/FraunhoferESK
>>> >>
>>> >
>>> >
>>> >
>>> > --
>>> > J?r?mie Galarneau
>>> > EfficiOS Inc.
>>> > http://www.efficios.com
>>>
>>>
>>>
>>> --
>>> J?r?mie Galarneau
>>> EfficiOS Inc.
>>> http://www.efficios.com
>>>
>>
>> --
>> Mathieu Desnoyers
>> EfficiOS Inc.
>> http://www.efficios.com
>
>
>
> --
> J?r?mie Galarneau
> EfficiOS Inc.
> http://www.efficios.com



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



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-11-20 12:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <E537659DE2B2C54EBD9FC9180F059880395D85FEA2@zulu.esk.fraunhofer.de>
     [not found] ` <CA+jJMxtmqSLA9wpyCMxCo5i7k2=ndL_GZNi8Dbw8YsSbQ15qeQ@mail.gmail.com>
     [not found]   ` <E537659DE2B2C54EBD9FC9180F059880395D860010@zulu.esk.fraunhofer.de>
     [not found]     ` <CA+jJMxsMU5u_4m3pUPJ6EBQVKTL_4+PNSj8iHvRcn6CJ=bt6Ag@mail.gmail.com>
     [not found]       ` <439534666.36114.1381274066505.JavaMail.zimbra@efficios.com>
     [not found]         ` <CA+jJMxtK8ZHvXKw3Ea6wxF_6f8_LwmkDahbxCg=rBu3SXjBMWg@mail.gmail.com>
     [not found]           ` <E537659DE2B2C54EBD9FC9180F059880395D955070@zulu.esk.fraunhofer.de>
2013-11-03 19:39             ` [lttng-dev] Reading CTF trace using Babeltrace API Salman Rafiq
2013-11-07 21:40             ` Jérémie Galarneau
2013-11-20 12:45               ` Salman Rafiq

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox