
SAMPLING=100000 # 100 milli seconds 

filestr=/mnt/sdcard/seestats/$(date +%m)_$(date +%d)_$(date +%Y)"/"

echo "mkdir" $filestr 
mkdir -p $filestr 

suffixstr="shortterm_"$(date +%H)_$(date +%M)_$(date +%S)"/"
filestr=$filestr$suffixstr

echo "mkdir" $filestr 
mkdir -p $filestr

stopfile=/data/seestats/stop_st
runfile=/data/seestats/run_st

if [ -f "$stopfile" ]
then
	echo Error!!!
	echo "$stopfile found." "Make sure you have called stop_st.sh" 
	exit 1
fi

if [ -f "$runfile" ]
then
	echo Error!!!
	echo "$runfile found." "Make sure you have called stop_st.sh" 
	exit 1
fi

echo "## Output of master (short term) utility" $(date +%s)  $(date) 

echo "ON" > $runfile

for program in cpufreq cpuusage cpuonoff gpubusy gpufreq temperature battery  
do

	echo starting /data/seestats/$program.out $SAMPLING $stopfile to $filestr$program.$(date +%s).txt
	/data/seestats/$program.out $SAMPLING $stopfile > $filestr$program.$(date +%s).txt  2>&1 &  

done

# calling only shorterm1
for script in shortterm1 
do

	echo starting /data/seestats/$script.sh to $filestr$script.$(date +%s).txt
	/data/seestats/$script.sh > $filestr$script.$(date +%s).txt  2>&1 &  

done

# echo /data/seestats/shortterm1.sh to $filestr"shortterm1".$(date +%s).txt
# /data/data/com.qualcomm.qview/qview/busybox nohup sh /data/seestats/shortterm1.sh > $filestr"shortterm1".$(date +%s).txt  2>&1 &  


while [ 1 ]
do

        if [ -f "$stopfile" ]
        then
                echo "$stopfile found."
                break
        else
                echo "$stopfile not found."
        fi

        echo "## Off period starts" $(date +%s) $(date) 
        sleep 10
        (( c++ ))

done
echo "## Done master utility" $(date +%s) $(date) 


echo "## Done master (short term) utility" $(date +%s) $(date)  



