Polished logging and cpu/core detection.

This commit is contained in:
Louwrentius 2009-03-10 21:32:12 +00:00
parent 1d35b51da4
commit c8b1d84122
1 changed files with 20 additions and 18 deletions

View File

@ -38,7 +38,7 @@ trap 'kill_process; ' INT
# Setting some vars. Do not change. # Setting some vars. Do not change.
SCRIPT_NAME="Distributed Parallel Processing Shell Script" SCRIPT_NAME="Distributed Parallel Processing Shell Script"
SCRIPT_VERSION="2.0" SCRIPT_VERSION="2.03"
# The first argument to this script is always the 'mode'. # The first argument to this script is always the 'mode'.
MODE="$1" MODE="$1"
@ -459,6 +459,11 @@ init_vars () {
rm $LOGFILE rm $LOGFILE
fi fi
log DEBUG "---------------------------------------------------------"
log INFO "$SCRIPT_NAME version $SCRIPT_VERSION"
log DEBUG "---------------------------------------------------------"
log INFO "Hostname: $HOSTNAME"
if [ -z "$COMMAND" ] if [ -z "$COMMAND" ]
then then
echo echo
@ -487,6 +492,8 @@ init_vars () {
MAX_NO_OF_RUNNING_JOBS=`get_no_of_cpus $HYPERTHREADING` MAX_NO_OF_RUNNING_JOBS=`get_no_of_cpus $HYPERTHREADING`
fi fi
log DEBUG "---------------------------------------------------------"
does_file_exist "$JOB_LOG_DIR" does_file_exist "$JOB_LOG_DIR"
if [ ! "$?" == "0" ] if [ ! "$?" == "0" ]
then then
@ -564,8 +571,6 @@ log () {
} }
log INFO "$0 $@"
check_status () { check_status () {
ERROR="$1" ERROR="$1"
@ -725,6 +730,7 @@ get_no_of_cpus () {
NUMBER=`grep ^processor $CPUINFO | wc -l` NUMBER=`grep ^processor $CPUINFO | wc -l`
got_cpu_info "$?" got_cpu_info "$?"
fi fi
log DEBUG "Found $NUMBER logic processors."
elif [ "$HPT" == "no" ] elif [ "$HPT" == "no" ]
then then
log DEBUG "Hyperthreading is disabled." log DEBUG "Hyperthreading is disabled."
@ -734,24 +740,23 @@ get_no_of_cpus () {
if [ "$?" == "0" ] if [ "$?" == "0" ]
then then
PHYSICAL=`grep 'physical id' $CPUINFO | sort | uniq | wc -l` PHYSICAL=`grep 'physical id' $CPUINFO | sort | uniq | wc -l`
log DEBUG "Detected $PHYSICAL CPU(s)" log DEBUG "Detected $PHYSICAL physical CPU(s)"
TMP=`grep 'cpu cores' $CPUINFO` TMP=`grep 'core id' $CPUINFO`
if [ "$?" == "0" ] if [ "$?" == "0" ]
then then
MULTICORE=`grep 'cpu cores' $CPUINFO | sort | uniq | cut -d ":" -f 2 | sed s/\ //g` log DEBUG "Starting job only for each physical core on all physical CPU(s)."
log DEBUG "Detected $MULTICORE cores per CPU." NUMBER=`grep 'core id' $CPUINFO | sort | uniq | wc -l`
NUMBER=$(($PHYSICAL*$MULTICORE)) log DEBUG "Found $NUMBER physical cores."
else else
log DEBUG "Starting job only for each physical CPU." log DEBUG "Single core processor(s) detected (or you found a bug)."
log DEBUG "Starting job (only) for each physical CPU."
NUMBER=$PHYSICAL NUMBER=$PHYSICAL
fi fi
else else
log DEBUG "No 'physical id' section found in $CPUINFO." log DEBUG "No 'physical id' section found in $CPUINFO, is this a bug?."
NUMBER=`grep ^processor $CPUINFO | wc -l` NUMBER=`grep ^processor $CPUINFO | wc -l`
got_cpu_info "$?" got_cpu_info "$?"
fi fi
elif [ "$ARCH" == "Darwin" ] elif [ "$ARCH" == "Darwin" ]
then then
NUMBER=`sysctl -a hw | grep -w physicalcpu | awk '{ print $2 }'` NUMBER=`sysctl -a hw | grep -w physicalcpu | awk '{ print $2 }'`
@ -1206,11 +1211,9 @@ main () {
is_running is_running
case $MODE in case $MODE in
node|standalone ) node|standalone )
log DEBUG "---------------- START ---------------------"
log INFO "$SCRIPT_NAME version $SCRIPT_VERSION"
log INFO `hostname`
init_vars init_vars
test_server test_server
get_all_items get_all_items
@ -1220,7 +1223,6 @@ main () {
;; ;;
start ) start )
# This option only starts all nodes. # This option only starts all nodes.
init_vars
if [ ! -e "$NODES_FILE" ] if [ ! -e "$NODES_FILE" ]
then then
@ -1304,7 +1306,7 @@ while true
do do
sleep 5 sleep 5
JOBS=`ps ax | grep -v grep | grep -v -i screen | grep ppss.sh | wc -l` JOBS=`ps ax | grep -v grep | grep -v -i screen | grep ppss.sh | wc -l`
log INFO "There are $JOBS running processes. " log DEBUG "There are $JOBS running processes. "
MIN_JOBS=3 MIN_JOBS=3
@ -1318,7 +1320,7 @@ do
if [ "$JOBS" -gt "$MIN_JOBS" ] if [ "$JOBS" -gt "$MIN_JOBS" ]
then then
log INFO "Sleeping $INTERVAL seconds." log DEBUG "Sleeping $INTERVAL seconds."
sleep $INTERVAL sleep $INTERVAL
else else
echo -en "\033[1B" echo -en "\033[1B"