# Tester and Profiler for guider
#
# Copyright (c) 2016 Peace Lee <iipeace5@gmail.com>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.

if [ $# -le 0 ]
    then
        echo "[Usage] guiderTest [cpu|mem|test] OPTIONS"
        exit
elif [ $1 = "cpu" ]
    then
        echo "[Info] CPU profile mode"
        PYTHON_OPT="-m cProfile -s cumtime"
elif [ $1 == "mem" ]
    then
        echo "[Info] Memory profile mode, add @profile line on target function"
        PYTHON_OPT="-m memory_profiler"
elif [ $1 == "test" ]
    then
        echo "[Info] test mode (TBD)"
else
    echo "[Usage] guiderTest [cpu|mem|test] OPTIONS"
    exit
fi



PYTHON_EXEC=$(which python)

if [ ! $PYTHON_EXEC ]
    then
        echo "[Error] Fail to find python"
        exit
fi



PYFILE=guider.py
TESTER_DIR=$(dirname "$0")

if [ -f $TESTER_DIR/$PYFILE ]
    then
        TARGET=$TESTER_DIR/$PYFILE
else
    echo "[Error] Fail to find $TESTER_DIR/$PYFILE"
    exit
fi

echo "[Info] Target file is $TARGET"

$PYTHON_EXEC $PYTHON_OPT $TARGET ${@: 2}
