#!/bin/bash
source $HOME/.gamerc

if [ "${ENABLE_PERF_MONITOR}" -eq "1" ]; then
	$HOME/bin/create_perf
	
	SCREEN_DIRECTORY="/var/run/screen/S-${USER}"
	SNAPSHOT_SOURCE_DIRECTORY="$HOME/perf.snapshot"
	
	[ ! -d "${SNAPSHOT_SOURCE_DIRECTORY}" ] && mkdir -p ${SNAPSHOT_SOURCE_DIRECTORY}
	
	for ss in $(ls ${SCREEN_DIRECTORY});
	do
	        PROCESS_SHORT_NAME=$(echo ${ss}|awk -F"." '{print $2}')
		SNAPSHOT_DIRECTORY="${SNAPSHOT_SOURCE_DIRECTORY}/${PROCESS_SHORT_NAME}"
	        FILENAME=$(echo ${ss}|awk -F"." '{print $2"."$3}')
	        echo "${ss} => ${PROCESS_SHORT_NAME}"
	
	        nohup $HOME/bin/create_screen_snapshot ${PROCESS_SHORT_NAME} ${SNAPSHOT_DIRECTORY} > /tmp/${FILENAME}.out 2> /tmp/${FILENAME}.err &
	done
fi
