#!/bin/sh
if [ `whoami` != root ]
then
    echo you need to run this script as root
    exit 1
fi

mount -t debugfs none /sys/kernel/debug  2>/dev/null
cd /sys/kernel/debug/tracing
start()
{
   echo 50000 > buffer_size_kb
   echo nop > current_tracer
#  exemple for also tracing all function starting with hsi:
#  echo function > current_tracer
#  echo hsi* >> set_ftrace_filter

   echo  > set_event
   (
   while read i
   do
     echo $i >> set_event
   done
   ) <<EOF
sched:sched_wakeup
sched:sched_switch
timer:timer_init
timer:timer_start
timer:timer_expire_entry
timer:timer_expire_exit
timer:hrtimer_start
timer:hrtimer_expire_entry
timer:hrtimer_expire_exit
timer:itimer_expire
workqueue:workqueue_execution
workqueue:workqueue_execution_end
workqueue:workqueue_execute
workqueue:workqueue_execute_end
power:*
irq:*
EOF
   echo >trace
   echo 1 >tracing_enabled
}
stop()
{
   echo >set_event
   echo 0 >tracing_enabled
   output=~/trace`date +%y-%m-%d-%H-%M-%S`.txt.lzma
   cat trace | lzma > $output
   echo trace written to $output
}
COMMAND="$1"
case $COMMAND in
start|stop)
	$COMMAND
	;;
*)
	echo "usage: $0 [start|stop]"
;;
esac
