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

KEYWORD=$1

SOURCE_DIRECTORY="$HOME/perf.snapshot"
LOGROTATE_DIRECTORY="${SOURCE_DIRECTORY}/Log"

if [ "${ENABLE_PERF_MONITOR}" -eq "1" ]; then
	for directory in $(ls ${SOURCE_DIRECTORY}); do
		echo ${directory}
	
		cd ${SOURCE_DIRECTORY}/${directory}
		[ ! -d "${LOGROTATE_DIRECTORY}/${KEYWORD}/${directory}" ] && mkdir -p ${LOGROTATE_DIRECTORY}/${KEYWORD}/${directory}
		find . -type f -name "*${KEYWORD}*" -exec mv {} ${LOGROTATE_DIRECTORY}/${KEYWORD}/${directory} \;
	
		cd ${LOGROTATE_DIRECTORY}/${KEYWORD}/${directory}
		for log_file in $(find . -type f -name "*.perf" | sed 's|./||'); do 
			echo "${LOGROTATE_DIRECTORY}/${KEYWORD}/${directory}/${log_file}"
			ionice -c 3 nice -n 19 $HOME/bin/xz -3 ${log_file}
		done
	done
fi
