Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
demvy opened this issue Nov 3, 2022 · 4 comments
Open

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

demvy opened this issue Nov 3, 2022 · 4 comments
Labels

Comments

@demvy
Copy link

demvy commented Nov 3, 2022

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
Copy link

christophebedard commented Nov 3, 2022

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

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

@eepp eepp added the question label Nov 3, 2022
@eepp
Copy link
Member

eepp commented Nov 3, 2022

@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
Copy link
Author

demvy commented Nov 4, 2022

@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
Copy link
Member

eepp commented Nov 14, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants