[lttng-dev] Writing from a trace to a new one with Babeltrace 2.0.0-pre1 C API

Julien Desfossez jdesfossez at efficios.com
Fri Jun 30 19:11:53 UTC 2017


Hi,

On 2017-06-29 01:37 PM, Marie Martin wrote:
> Hi everyone!
> 
> I'm trying to use Babeltrace 2.0.0-pre1 C API to copy some events of an
> existing CTF trace (generated with LTTng) into a new one. So I was
> wondering how I should open the existing trace and iterate over its
> events, as there is no method bt_ctf_iter_create, bt_ctf_iter_read_event
> and such, anymore.
> 
> Before, with the 1.5 API, I was reading the trace like this :
>     struct bt_context *ctx = bt_context_create();
>     int trace_id = bt_context_add_trace(ctx, read_trace_path, "ctf",
> NULL, NULL, NULL);
>     struct bt_ctf_iter *iter = bt_ctf_iter_create(ctx, NULL, NULL);
>     while ((ctf_event = bt_ctf_iter_read_event(iter))) { ... }
> 
> I'm not sure about the proper way to do it now. I tried to replicate
> some of the code from babeltrace.c (especially the cmd_run function) and
> I'm able to print metadata from the trace (using
> bt_component_class_query(src_component_class, "metadata-info", params)
> after gettting the ctf plugin and the source component). Can I use
> queries in a similar way to access trace events data ?
> 
> I also tried to instantiate a new graph, add the ctf plugin components
> to the graph and run it, but I don't know how to collect events.
> 
> Also, should I define my own custom plugin for that purpose ?
Yes, plugins is probably the simplest way to do it right now, let the
main Babeltrace executable handle the trace opening and handling, and
connect a filter (or a sink if your plugin needs a custom output) to
manipulate the traces and events from there. From the plugin point of
view, you receive and handle notifications (new stream, new packet, new
event, etc). If you need to embed this into your own executable, you
have to connect the graph yourself, but I'm not sure exactly how to do
it, others on this list can answer.

So I think, the easiest way to start, would be to look at the already
existing plugins. When simply running babeltrace on a trace, it
automatically connects the following chain of plugins :
- ctf/fs-src input
- utils/muxer filter
- lttng-utils/debug-info filter
- text/pretty sink

The ctf/fs-sink sink plugin takes traces as input, performs some
manipulations if needed on the trace structure and writes CTF as output.
In there you should see how to create a new trace, new streams,
manipulate stream classes, event classes, etc.

The API documentation is very well explained, but I don't think there is
a higher level documentation that details how to manipulate traces and
events, so the existing plugins should help.

You can also look at the debug-info filter plugin which takes traces as
input, creates new traces with additional fields and forwards the result
to the rest of the chain (which can be the ctf.fs-sink to output the
result in a CTF trace).

The plugin/libctfcopytrace internal library has some helper functions to
copy the main parts of a CTF trace. It is not currently a public library
installed on the system, but it only uses public API functions from the
Babeltrace library, so if you need to build your plugin out-of-tree, you
can just copy it. It might become part of the public API if it becomes
more used.

Connecting your plugins to the graph can then be done on the command
line with the --component parameter.

I hopes this helps you start,

Julien


More information about the lttng-dev mailing list