[lttng-dev] Read CTF events

Julien Desfossez julien.desfossez at polymtl.ca
Thu Feb 23 13:58:56 EST 2012


Hello Salman,

As a generic rule, to access a field in an event, you need to know in
which scope this field is located (scopes are defined in CTF). In your
example you want to access to the event field scope (the complete list
of scopes is available in the enum bt_ctf_scope).

Once you know which scope you are intested in, you can get access to a
field by using the bt_ctf_get_field or list all fields functions with
bt_ctf_get_field_list.
These two functions return you definition pointers which you can use to
get the name and value of the field.

I am currently in the process of writing a small documentation to
explain all of that :-)

If you want, I just posted an example on how to use the API :
git://git.dorsal.polymtl.ca/~jdesfossez/babeltrace-api-test

It covers, opening, using the callbacks, iterating, reading the event
name, timestamp and a field in sched_switch.
Please note that the strcmp is here as an example only and if you can,
you should use callbacks instead for performance reason.

Please also note that the libctf just changed name in babeltrace (as in
commit 76863fd6cdec274450a6fd640fc70ea7398c4510), so before trying this
example do the following in your babeltrace tree :
make uninstall
make distclean
git pull
./configure
make
sudo make install
sudo ldconfig

Hope this help you use the API,

Julien


On 23/02/12 12:43 PM, Salman Rafiq wrote:
> Dear Mathieu,
> 
>  
> 
> I am trying to read the events generated by LTTng kernel tracer in my
> Application. I can successfully read the event name and timestamp with
> the help of babeltrace API/library. But the problem comes with reading
> remaining fields.
> 
> e.g. my metadata file generated via LTTng kernel trace has:
> 
>  
> 
> event {
> 
>         name = sched_switch;
> 
>         id = 0;
> 
>         stream_id = 0;
> 
>         fields := struct {
> 
>                 integer { size = 8; align = 8; signed = 1; encoding =
> UTF8; base = 10; } *_prev_comm[16];*
> 
>                 integer { size = 32; align = 8; signed = 1; encoding =
> none; base = 10; } _prev_tid;
> 
>                 integer { size = 32; align = 8; signed = 1; encoding =
> none; base = 10; } _prev_prio;
> 
>                 integer { size = 64; align = 8; signed = 1; encoding =
> none; base = 10; } _prev_state;
> 
>                 integer { size = 8; align = 8; signed = 1; encoding =
> UTF8; base = 10; } *_next_comm[16];*
> 
>                 integer { size = 32; align = 8; signed = 1; encoding =
> none; base = 10; } _next_tid;
> 
>                 integer { size = 32; align = 8; signed = 1; encoding =
> none; base = 10; } _next_prio;
> 
>         };
> 
> };
> 
>  
> 
> I wanted to read event fields like _/prev/_command and _/next/_command.
> The pseudocode of my application is:
> 
>  
> 
> 1)    Create context
> 
> 2)    Add trace to context with given context, input_path and defaults
> (NULL) for packet seek, mmap_stream_list, and FILE*
> 
> 3)    Allocate a CTF trace collection iterator using context above and
> NULL (default for begin_pos and end_pos)
> 
> 4)    Using iterator read event in bt_ctf_event struct , until iterator
> move to next event in trace collection
> 
> 5)    Read event name and timestamp
> 
>  
> 
> But I could not figure out the way to read event fields in general,
> since with different types of events they will change. Kindly suggest me
> which files to look into? Or suggest some way through which I can
> achieve this.
> 
>  
> 
> I shall be really thankful to you.
> 
>  
> 
> Best Regards,
> 
> Salman
> 
>  
> 
> --
> 
> Salman Rafiq
> 
> Industrial Communication
> 
> Fraunhofer-Einrichtung für Systeme der Kommunikationstechnik ESK
> 
>  
> 
> Hansastraße 32 | 80686 München
> 
> Telefon, Fax:  +49 89 547088-356 | +49 89 547088-66-356
> 
> E-Mail:   salman.rafiq at esk.fraunhofer.de <http://www.esk.fraunhofer.de/>
> 
>  
> 
> Internet:
> 
> http://www.esk.fraunhofer.de <http://www.esk.fraunhofer.de/>
> 
> http://www.facebook.com/FraunhoferESK
> http://www.twitter.com/FraunhoferESK
> 
>  
> 
> 
> 
> _______________________________________________
> lttng-dev mailing list
> lttng-dev at lists.lttng.org
> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev



More information about the lttng-dev mailing list