#!/bin/sh
# initramfs init-bottom script for starting ftrace function tracer

PREREQ=""
MOUNTPOINT="/sys/kernel/debug"
SUBDIR="$MOUNTPOINT/tracing"

# Output pre-requisites
prereqs()
{
    echo "$PREREQ"
}

case "$1" in
    prereqs)
        prereqs
        exit 0
        ;;
esac

echo "Starting with undertaker tracing enabled"
touch /run/ftrace.boot.start
[ -d "$MOUNTPOINT" ] || mkdir "$MOUNTPOINT"
grep -q debugfs /proc/mounts || mount -t debugfs nodev "$MOUNTPOINT"
touch /run/ftrace.boot.mounted
if [ "$(cat /sys/kernel/debug/tracing/current_tracer)" == "function" ]; then
    touch /run/ftrace.kernelparam
else
    sleep 1
    echo 0 > "$SUBDIR/tracing_on"
    echo "sym-addr" > "$SUBDIR/trace_options"
    echo "sym-offset" > "$SUBDIR/trace_options"
    echo "function" > "$SUBDIR/current_tracer"
    echo > "$SUBDIR/set_ftrace_notrace"
    echo 1 > "$SUBDIR/tracing_on"
    touch /run/ftrace.boot.tracing
    sleep 1
fi
cat "$SUBDIR/trace_options" > /run/ftrace.boot.options
