<commit_before>#! /bin/bash
cleanup() {
	exit 1
}
trap cleanup SIGTERM SIGINT

sleep_time=1

duration=0
tot_nb_iter=0
nb_events=0

run_baseline() {
	testcase=$1
	cpu_affinity=$2
	nbThreads=$3
	sleepTime=$4
	output=$(./$testcase $cpu_affinity $nbThreads $sleepTime)
	duration=$(echo $output | cut -f1 -d ' ')
	tot_nb_iter=$(echo $output | cut -f2 -d ' ')
	nb_events=-1
}
run_strace() {
	testcase=$1
	cpu_affinity=$2
	nbThreads=$3
	sleepTime=$4
	output=$(strace -f ./$testcase $cpu_affinity $nbThreads $sleepTime 2> /dev/null)
	duration=$(echo $output | cut -f1 -d-)
	tot_nb_iter=$(echo $output | cut -f2 -d-)
	nb_events=-1
}

run_lttng() {
	testcase=$1
	cpu_affinity=$2
	nbThreads=$3
	sleepTime=$4
	lttng-sessiond -d
	lttng create
	lttng enable-channel --num-subbuf 4 --subbuf-size 2M -k my_channel
	lttng enable-event -k sched_process_exit,sched_switch,signal_deliver --channel my_channel
	lttng enable-event -k --syscall --all --channel my_channel
	lttng start
	sleep 2
	output=$(./$testcase $cpu_affinity $nbThreads $sleepTime)
	duration=$(echo $output | cut -f1 -d-)
	tot_nb_iter=$(echo $output | cut -f2 -d-)
	lttng stop
	sleep 1
	nb_events=$(lttng view | wc -l)
	lttng destroy -a
	killall lttng-sessiond
}
run_sysdig() {
	testcase=$1
	cpu_affinity=$2
	nbThreads=$3
	sleepTime=$4
	tmp=$(mktemp)

	sysdig -w $tmp &
	#save sysdig's pid
	p=$!
	sleep 2
	output=$(./$testcase $cpu_affinity $nbThreads $sleepTime)
	duration=$(echo $output | cut -f1 -d-)
	tot_nb_iter=$(echo $output | cut -f2 -d-)
	sleep 1

	# Send sigint to sysdig and wait for it to exit
	kill -2 $p
	wait $p

	#sync to make sure the entire trace is written to disk
	sync

	# extract the number of events from the read verbose output
	sysdig_output=$(sysdig -r $tmp -v 2>&1 >/dev/null)

	nb_events=$(echo $sysdig_output |grep 'Elapsed'|awk '{print $10}'|sed 's/,//g')
	echo $sysdig_output | grep 'Driver'
	rm $tmp
}


file_output=./results/results-$sleep_time-8.csv
echo 'testcase,tracer,run,sleeptime,cpu_affinity,nbthreads,duration,nbiter,nbevents' > $file_output
for nthreads in 1 2 4 8 16; do
	for cpuaffinity in 0 1; do
		for tcase in failing-open-efault failing-open-enoent failing-close; do
			for tracer in baseline lttng sysdig; do
				for i in $(seq 1 10); do
					run_$tracer $tcase $cpuaffinity $nthreads $sleep_time
					echo $tcase,$tracer,$i,$sleep_time,$cpuaffinity,$nthreads,$duration,$tot_nb_iter,$nb_events >> $file_output
					sleep 1
				done
			done
		done
	done
done
<commit_msg>Fix duration and iter parsing<commit_after>#! /bin/bash
cleanup() {
	exit 1
}
trap cleanup SIGTERM SIGINT

sleep_time=1

duration=0
tot_nb_iter=0
nb_events=0

run_baseline() {
	testcase=$1
	cpu_affinity=$2
	nbThreads=$3
	sleepTime=$4
	output=$(./$testcase $cpu_affinity $nbThreads $sleepTime)
	duration=$(echo $output | cut -f1 -d ' ')
	tot_nb_iter=$(echo $output | cut -f2 -d ' ')
	nb_events=-1
}
run_strace() {
	testcase=$1
	cpu_affinity=$2
	nbThreads=$3
	sleepTime=$4
	output=$(strace -f ./$testcase $cpu_affinity $nbThreads $sleepTime 2> /dev/null)
	duration=$(echo $output | cut -f1 -d ' ')
	tot_nb_iter=$(echo $output | cut -f2 -d ' ')
	nb_events=-1
}

run_lttng() {
	testcase=$1
	cpu_affinity=$2
	nbThreads=$3
	sleepTime=$4
	lttng-sessiond -d
	lttng create
	lttng enable-channel --num-subbuf 4 --subbuf-size 2M -k my_channel
	lttng enable-event -k sched_process_exit,sched_switch,signal_deliver --channel my_channel
	lttng enable-event -k --syscall --all --channel my_channel
	lttng start
	sleep 2
	output=$(./$testcase $cpu_affinity $nbThreads $sleepTime)
	duration=$(echo $output | cut -f1 -d ' ')
	tot_nb_iter=$(echo $output | cut -f2 -d ' ')
	lttng stop
	sleep 1
	nb_events=$(lttng view | wc -l)
	lttng destroy -a
	killall lttng-sessiond
}
run_sysdig() {
	testcase=$1
	cpu_affinity=$2
	nbThreads=$3
	sleepTime=$4
	tmp=$(mktemp)

	sysdig -w $tmp &
	#save sysdig's pid
	p=$!
	sleep 2
	output=$(./$testcase $cpu_affinity $nbThreads $sleepTime)
	duration=$(echo $output | cut -f1 -d ' ')
	tot_nb_iter=$(echo $output | cut -f2 -d ' ')
	sleep 1

	# Send sigint to sysdig and wait for it to exit
	kill -2 $p
	wait $p

	#sync to make sure the entire trace is written to disk
	sync

	# extract the number of events from the read verbose output
	sysdig_output=$(sysdig -r $tmp -v 2>&1 >/dev/null)

	nb_events=$(echo $sysdig_output |grep 'Elapsed'|awk '{print $10}'|sed 's/,//g')
	echo $sysdig_output | grep 'Driver'
	rm $tmp
}


file_output=./results/results-$sleep_time-8.csv
echo 'testcase,tracer,run,sleeptime,cpu_affinity,nbthreads,duration,nbiter,nbevents' > $file_output
for nthreads in 1; do
	for cpuaffinity in 0 1; do
		for tcase in failing-open-enoent; do
			for tracer in  lttng sysdig; do
				for i in $(seq 1 3); do
					run_$tracer $tcase $cpuaffinity $nthreads $sleep_time
					echo $tcase,$tracer,$i,$sleep_time,$cpuaffinity,$nthreads,$duration,$tot_nb_iter,$nb_events >> $file_output
					echo $tcase,$tracer,$i,$sleep_time,$cpuaffinity,$nthreads,$duration,$tot_nb_iter,$nb_events
					sleep 1
				done
			done
		done
	done
done

{'fraction_non_alphanumeric': 0.13599202392821536, 'fraction_numerical': 0.021136590229312063, 'mean_word_length': 4.2195629552549425, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '990377', 'n_tokens_mistral': 2091, 'n_tokens_neox': 1944, 'n_words': 519}