#!/bin/bash
/usr/bin/devkit_tools/echo_binary "${HOME}" > /usr/bin/devkit_tools/debug_path
params="$@"
miss_event_flag=0
etc_config="/etc/centos-release"
for args in "$@"
do
    if [[ -f "${args}" && -x "${args}" ]];then
        if [[ "${args}" != "/usr/bin/devkit_tools/launch_app.sh" ]] && [[ "${args}" != "/usr/bin/devkit_tools/launch_app_uarch.sh" ]]; then
            echo "The app mode must be called by the launch_app.sh script"
            exit 1
        else
            break
        fi
    fi
done
 
for args in "${params}"
do
    if [[ "${args}" =~ arm_spe_0.* ]]; then
        miss_event_flag=1
    fi
done
perf_path=$(which perf)
if [[ -f "${etc_config}" ]] && [[ "${miss_event_flag}" == 1 ]]; then
    grep "CentOS Linux release 7.6.1810" "${etc_config}" >/dev/null 2>&1
    if [[ "$?" -eq 0 ]]; then
        perf_path="/usr/bin/devkit/spe/4.14.0-115.el7a.0.1/perf"
    fi
fi
 
if [[ "${params}" =~ "list sched" ]];then
    ${perf_path} list sched|awk '{print $0}' ${param/list sched/}
    exit
fi
if [[ "${params}" =~ "list" ]];then
    ${perf_path} list |awk '{print $0}' ${param/list/}
    exit
fi

if [[ "${params}" == "--help" ]] || [[ "${params}" == "-h" ]];then
    exit 1
fi

${perf_path} ${params}