Add basic tracing scripts

This commit is contained in:
Christophe Bedard 2019-05-16 12:55:49 +02:00
parent ad8894d12b
commit 9f771a1812
2 changed files with 127 additions and 0 deletions

View file

@ -0,0 +1,37 @@
#!/bin/bash
# set up ust ros2 events
for event in \
ros2:rcl_init
do
lttng enable-event -c ros2 -u $event
done
# process context
lttng add-context -c ros2 -u \
-t vpid -t procname \
-t vtid -t perf:thread:instructions \
-t perf:thread:cycles -t perf:thread:cpu-cycles
#kernel
lttng enable-channel --kernel kchan --subbuf-size=8M
# # network
# for event in net_dev_queue netif_receive_skb net_if_receive_skb
# do
# lttng enable-event --kernel --channel=kchan $event
# done
# other kernel stuff
for event in sched_switch sched_waking sched_pi_setprio sched_process_fork sched_process_exit sched_process_free sched_wakeup\
irq_softirq_entry irq_softirq_raise irq_softirq_exit irq_handler_entry irq_handler_exit\
lttng_statedump_process_state lttng_statedump_start lttng_statedump_end lttng_statedump_network_interface lttng_statedump_block_device\
block_rq_complete block_rq_insert block_rq_issue\
block_bio_frontmerge sched_migrate sched_migrate_task power_cpu_frequency\
net_dev_queue netif_receive_skb net_if_receive_skb\
timer_hrtimer_start timer_hrtimer_cancel timer_hrtimer_expire_entry timer_hrtimer_expire_exit
do
lttng enable-event --kernel --channel=kchan $event
done
# lttng enable-event -k --syscall --all

90
tracetools/scripts/trace.sh Executable file
View file

@ -0,0 +1,90 @@
#!/bin/bash
## Helper script for ROS tracing
## Christophe Bedard
## see: https://github.com/bosch-robotics-cr/tracetools/blob/devel/scripts/example-run-script.sh
## Call this by providing these arguments:
## 1. a session name [optional; 'ros2' will be used]
## 2. a wait time before killing and stopping (in seconds)
## 3. a roslaunch/rosrun command
## ex: ./trace.sh 3 roslaunch tracecompass_ros_testcases pub_sub.launch
source ./${BASH_SOURCE%/*}/../../../../install/local_setup.bash
## Parameters
# if no parameters were given, exit with error
if [ -z "$1" ] ; then
echo "Error: no parameters were given!"
exit 1
elif [ "$1" == "-h" ] ; then
echo -e "ROS tracing helper script.\n" \
"Provide 3 arguments:\n" \
"1. the lttng session name [optional; 'ros2' will be used]\n" \
"2. the wait time before killing and stopping (in seconds)\n" \
"3. the ros2 run command\n" \
"Example: ./trace.sh ros-trace 3 ros2 run tracetools tracetools_status"
exit 0
fi
# session name
session_name="$1"
case "$session_name" in
''|*[!0-9]*) # not a number: good
shift
;;
*) # number: so use a default session name
session_name="ros2"
;;
esac
# wait time (seconds) before killing and stopping
sleep_time="$1"
case "$sleep_time" in
''|*[!0-9]*) # not a number: error!
echo "Error: not a valid sleep time!"
exit 1
;;
*) # number: good
shift
;;
esac
# command from remaining arguments
if [ -z "$1" ] ; then
echo "Error: no command was given!"
exit 1
fi
launch_cmd="$@"
launch_cmd+=" &"
## Trace
# create lttng session (and set output to traces/ directory)
lttng create $session_name --output=./${BASH_SOURCE%/*}/../traces/$session_name/
# enable events
./${BASH_SOURCE%/*}/setup-lttng.sh
# start
lttng start
# preload UST library
export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/liblttng-ust-cyg-profile.so
# launch
eval "$launch_cmd"
# wait a bit and kill
echo "waiting $sleep_time..."
sleep $sleep_time
echo "killing"
kill $!
# wait again for everything to shutdown
echo "waiting for shutdown..."
sleep 2
echo "stopping"
# stop & destroy
lttng stop
lttng destroy