efficios / barectf

Generator of ANSI C tracers which output CTF data streams
https://barectf.org
MIT License
65 stars 17 forks source link

How we can make barectf to output logs into lttng-session? #25

Open demvy opened 2 years ago

demvy commented 2 years ago

Hello,

I'm pretty new in CTF tracing, but interested in LTTng and barectf. Want to trace events from my Arduino and capture them in live mode on host by LTTng (with other LTTng events). I've wrote barectf platform files to send data to one of host's devices. So, data is on host and if I collect it to file, I can read it with babeltrace. Problem: I want to have live data from my sensors. After searching for a while, found LTTng with live mode. Seems, it is using TCP sockets, but there is no mention about how to interract.

Can I somehow connect barectf on my device and lttng on host? How to do this? Without porting lttng-ust on FreeRTOS, of course :) Can you please help?

christophebedard commented 2 years ago

Without porting lttng-ust on FreeRTOS, of course :)

I'm sure many people would be interested in getting LTTng(-UST) on FreeRTOS :grinning:

eepp commented 2 years ago

@demvy, I'm afraid there's no way to do what you want with barectf out of the box.

You could indeed mimic what LTTng does with its live protocol so that you can see your data in "real time" in Babeltrace 2 (and Trace Compass I think).

That being said, there's no up-to-date documentation for the LTTng live protocol. There's this, but it might be missing parts or might be hard to follow, just like the corresponding Babeltrace 2 code (most of which was moved as is from the Babeltrace 1 project).

If you want to go that way, what I suggest is starting with the faux LTTng live server we're using in Babeltrace 2 to test the src.ctf.lttng-live component class. This script is pretty clean and shows you the LTTng live server-side perspective, which is what you need.

Another way to achieve what you want, if you just care about reading the data as your tracer produces it, is to write each CTF packet (or small group of packets) to its own file, then move it to some directory D containing them, then, periodically:

  1. Create a CTF trace (directory) T containing:
    1. A copy or symbolic link of your barectf-generated metadata file.
    2. The oldest data stream file (one or more packets), moved from D so that you don't read it twice.
  2. Read T with Babeltrace 2.
  3. Delete or archive T.

Here's an example using Bash:

metadata_file_path=$1
dsf_dir=$2

while true; do
    # Get oldest data stream file path
    oldest_dsf_path=$dsf_dir/$(ls "$dsf_dir" -rt | head -1)

    if [[ -f "$oldest_dsf_path" ]]; then
        # Create trace
        trace_dir=$(mktemp -d)
        cp "$metadata_file_path" $trace_dir
        mv "$oldest_dsf_path" $trace_dir

        # Read trace
        echo babeltrace2 $trace_dir

        # Delete trace
        rm -rf $trace_dir
    else
        # Nothing for the moment
        sleep .5
    fi
done

Use:

bash barectf-live.bash /path/to/generated/metadata /path/to/data/stream/files

This approach is similar to the recording session rotation feature of LTTng.

Hope it helps.

demvy commented 2 years ago

@eepp, thank you for good points, I'll check them. As I've understood, events from barectf and lttng cannot be mixed or captured with one lttng session? Doesn't matter live or no. Found that we can read several CTF traces with babeltrace2 source plugin, but what about doing this before end of capture?

Also, about live capture of barectf log: I've thought creation of tool that will redirect data from barectf to lttng-relayd through TCP sockets. There are 2 ports: control and data. Seems, they can be emulated on barectf side. What do you think about this way?

eepp commented 2 years ago

Sorry for the late reply.

As I've understood, events from barectf and lttng cannot be mixed or captured with one lttng session?

No.

Found that we can read several CTF traces with babeltrace2 source plugin, but what about doing this before end of capture?

You can add two src.ctf.lttng-live components to a single Babeltrace 2 graph, as long as all the clocks are correlatable.

Seems, they can be emulated on barectf side. What do you think about this way?

Yes you can to that way, although I'm not sure it will be much more simple than emulating the relay daemon itself.