#!/bin/bash
help="usage: ${0##*/} <cpu id(s)>"
[[ $# -lt 1 ]] && echo $help && exit 1

debug=/sys/kernel/debug
trace_dir=/var/log/netcontrold/traces
trace_file="$trace_dir/ftrace.out$$"
mkdir -p $trace_dir
echo > $trace_file

for pmd in "$@"
do
  echo "running ftrace on cpu $pmd"
  x=$pmd
  x=$(( 1 << $x ))
  xcpu=$(printf %0.2x $x)
  echo $xcpu >$debug/tracing/tracing_cpumask
  echo '*' >$debug/tracing/set_ftrace_filter
  echo function_graph >$debug/tracing/current_tracer
  echo >$debug/tracing/trace
  echo 1 >$debug/tracing/tracing_on
  sleep 10
  echo 0 >$debug/tracing/tracing_on
  cat $debug/tracing/trace >> $trace_file
done

echo "$trace_file has ftrace on $@"
exit 0
