<div dir="ltr">Hi Simon,<div>thanks for the reply!</div><div>What I came up with for now is <a href="https://github.com/ImMax/babeltrace/commit/2082a0f4d77d2edeec6fb95c308a79fb313f7a02" target="_blank">this example</a>. It's probably has a lot of design mistakes but it's at least runnable.</div><div>I also see that examples for C API aren't build, but maybe I'm wrong.</div><div>Another thing, if you have lack of resources I would be happy to help, I could make a PR with your guidance and review.</div><div><br></div><div><div dir="ltr"><div>Answers to the questions:</div><div>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.</div><div>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.</div><div>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)</div></div><div class="gmail-yj6qo gmail-ajU" style="outline:none;padding:10px 0px;width:22px;margin:2px 0px 0px"><br class="gmail-Apple-interchange-newline"></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 19 Aug 2022 at 17:00, Simon Marchi <<a href="mailto:simark@simark.ca">simark@simark.ca</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 8/12/22 09:19, Maksim Khmelevskiy via lttng-dev wrote:<br>
> Hi,<br>
><br>
<br>
> there is a nice py message iterator example<br>
> <<a href="https://babeltrace.org/docs/v2.0/python/bt2/examples.html" rel="noreferrer" target="_blank">https://babeltrace.org/docs/v2.0/python/bt2/examples.html</a>> but for C<br>
> API only plugins are covered with examples, do you think it would make<br>
> sense to create an example of a standalone application which simply<br>
> uses `source.ctf.fs` as source and iterates over all messages? It<br>
> would be nice hint for those who want to see an example of graph<br>
> creation with all the code in one file.<br>
<br>
Hi Maksim,<br>
<br>
I'm not sure which example you are referring to exactly. But in Python,<br>
we have the high-level TraceCollectionMessageIterator object, which does<br>
roughly:<br>
<br>
- Instantiate source and filter components according to the provided<br>
specs, including automatic source discovery<br>
- Instantiate a flt.utils.muxer component to merge the streams from all<br>
sources ports<br>
- Instantiate a sink component that presents the events as a Python<br>
iterable<br>
- Connect the ports of all these components<br>
- More things that are irrelevant here<br>
<br>
There is no such high-level object in the C interface, so you have<br>
to do all this by hand, it will necessarily be much more verbose. It<br>
would be nice to have the equivalent of TraceCollectionMessageIterator<br>
in the C API, it is just not done yet due to lack of resources.<br>
<br>
I did search in the documentation for an example program that uses the C<br>
API to create and run a graph, and I haven't found one. I agree that<br>
adding one would be nice. I'll look into writing one.<br>
<br>
Regarding your use case:<br>
<br>
> I'm interested in that example because I want to transform CTF file<br>
> into list of C structures representing messages.<br>
<br>
I have some questions:<br>
<br>
- Is the data you want to convert found in the metadata of the traces<br>
(description of event types) of in the payload of events?<br>
- Why do you want to write this in C instead of Python? It sounds like<br>
it would be much faster to write in Python (with<br>
TraceCollectionMessageIterator), and it doesn't sound like something<br>
where the performance is critical (but of course I don't have the<br>
full context).<br>
- Why do you need to write an application where you create and run the<br>
graph yourself? Could you instead just write your sink component<br>
class (which reads the messages and writes your output files),<br>
packaged in a plugin and use it through the babeltrace2 command-line:<br>
<br>
$ babeltrace2 /path/to/ctf/trace -c sink.foo.bar -p 'output="out.h"'<br>
<br>
? This way, you just have to care about writing your component<br>
class, which does the conversion you need.<br>
<br>
Simon<br>
</blockquote></div>