#!/bin/bash
set -e
export LTTNG_UST_DEBUG=1

lttng --version

# clear old data first
rm -rf ~/lttng-traces/
rm *.log

lttng-sessiond -vvv --verbose-consumer -b &>> session_daemon.log
lttng create test_session --snapshot
lttng enable-event --userspace hello_world:my_first_tracepoint
lttng start test_session

# this is similar to the hello world example from the documentation - it will just create 10 tracepoints and exit
../hello &> hello.log

for i in {1..10}
do
    echo FINDME______ now creating snapshot $i &>> session_daemon.log
    lttng -vvv snapshot record &> snapshot_record_$i.log
done

# clean up everything
lttng stop test_session
lttng destroy test_session
pkill lttng-sessiond

for i in ~/lttng-traces/test_session-*/*
do
    # just count the lines, should be exactly 10 per snapshot
    babeltrace2 $i | wc -l
done
