[lttng-dev] C API message iterator example for libbabeltrace2

Simon Marchi simark at simark.ca
Wed Aug 24 11:56:09 EDT 2022


On 8/20/22 12:14, Maksim Khmelevskiy via lttng-dev wrote:
> Hi Simon,
> thanks for the reply!

> What I came up with for now is this example
> <https://github.com/ImMax/babeltrace/commit/2082a0f4d77d2edeec6fb95c308a79fb313f7a02>.
> It's probably has a lot of design mistakes but it's at least runnable.

Looks like a good prototype, it seems right.  Some hopefully
constructive comments:

 - You can probably use bt_plugin_find to find a plugin by name instead
   of your code that does it by hand
 - When you instantiate a src.ctf.fs component, it may have more than
   one port (there is one port per data stream), in which case you want
   to connect them all to a flt.utils.muxer component (which is what the
   CLI and the Python TraceCollectionMessageIterator class do) to funnel
   all the messages to a single output port.  Of course, if you know
   the CTF traces you deal with have a single data stream, that is not
   necessary.

> I also see that examples for C API aren't build, but maybe I'm wrong.

C API examples in the documentation indeed aren't built.

> Another thing, if you have lack of resources I would be happy to help, I could make a PR with your guidance and review.
>

> Answers to the questions:
> 1) Not sure that I completely understand the question, I wanted to parse events(name, fields), not the metadata file aligned with the CTF trace file.
> 2) Because I wanted to get C-structs directly from the CTF traces. I'm sure that it's very niche requirement, sane people would not need it.
> 3) I would do something like that, but I have a requirement of providing C structs. I guess to apply filters or do something else with traces (I'm not sure, not my idea, but I also find it weird)

Ok, I understand.  When you said you need to write "C structs", I
thought you meant that you needed to output some generated C code, for
instance convert event types to structures, for use in a program later.
But that's not the case, you want to take event payload and fill out
some structures at runtime, from what I can see.  That explains why you
want to use the C API and why you want to create and run a graph in your
own application.

Following your questions, I have written an example of creating and
running a graph, which I just submitted for review here:

  https://review.lttng.org/c/babeltrace/+/8741

It is roughly equivalent to this Python example:

  https://babeltrace.org/docs/v2.0/python/bt2/examples.html#build-and-run-a-trace-processing-graph

Simon


More information about the lttng-dev mailing list