Skip to content

Commit

Permalink
Merge pull request #109 from jbaicoianu/mamebench
Browse files Browse the repository at this point in the history
Added mame benchmarking scripts
  • Loading branch information
textfiles committed May 20, 2015
2 parents df8f38b + 23ba09f commit 3319744
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 0 deletions.
15 changes: 15 additions & 0 deletions utils/mamebench/USAGE
@@ -0,0 +1,15 @@
MAMEBench
=========
This is a set of shell scripts which make it simple to run parallel benchmarks on all roms in a directory.

Usage: ./mamebench.sh <romdir> <benchfile> [-t <benchtime>] [-j <threads>] [-p <pattern>]


Examples:

# Benchmark all roms in /data/roms for 45 seconds each, using 4 threads
$ ./mamebench.sh /data/roms benchmark-20150519.tsv -t 45 -j 4

# Benchmark all sf2 variants in /data/roms for 90 seconds each, using 6 threads
$ ./mamebench.sh /data/roms benchmark-20150519.tsv -t 90 -j 6 -p sf2*

24 changes: 24 additions & 0 deletions utils/mamebench/mamebench-buildqueue.sh
@@ -0,0 +1,24 @@
#!/bin/bash

ROMDIR=$1
LOGFILE=$2
BENCHTIME=30
THREADS=4
PATTERN="*"

shift 2
while getopts "t:p:" opt; do
case "$opt" in
t)
BENCHTIME=$OPTARG
;;
p)
PATTERN=$OPTARG
;;
esac
done

for I in "$ROMDIR"/$PATTERN.zip; do
GAME=$(basename "${I/\.zip/}")
echo "./mamebench-game.sh \"${ROMDIR}\" \"${LOGFILE}\" $GAME -t $BENCHTIME"
done
21 changes: 21 additions & 0 deletions utils/mamebench/mamebench-game.sh
@@ -0,0 +1,21 @@
#!/bin/sh

ROMDIR=$1
LOGFILE=$2
GAME=$3

BENCHTIME=30

shift 3
while getopts "t:j:" opt; do
case "$opt" in
t)
BENCHTIME=$OPTARG
;;
esac
done

MAMEOUT=$(SDLMAME_DESKTOPDIM=800x600 SDL_VIDEODRIVER=dummy SDL_RENDER_DRIVER=software mame -rompath "$ROMDIR" -bench $BENCHTIME $GAME | tr -d '\n' | sed 's/.*Average speed: //' | sed 's/\% .*$/%/' )
FULLNAME=$(mame -listfull $GAME |tail -1 |sed -r 's/^.*"(.*)"$/\1/g')
echo "$GAME\t$FULLNAME\t$MAMEOUT" >> "${LOGFILE}"

38 changes: 38 additions & 0 deletions utils/mamebench/mamebench.sh
@@ -0,0 +1,38 @@
#!/bin/sh

if [ $# -lt 2 ]; then
echo "Usage: $0 <romdir> <logfile> [-t <benchtime>] [-j <threads>]"
exit 1
fi

ROMDIR=$1
LOGFILE=$2
BENCHTIME=30
THREADS=4
PATTERN="*"

shift 2
while getopts "t:j:p:" opt; do
case "$opt" in
t)
BENCHTIME=$OPTARG
;;
j)
THREADS=$OPTARG
;;
p)
PATTERN=$OPTARG
;;
esac
done

if [ ! -d "$ROMDIR" ]; then
echo "Could not find rom directory: $ROMDIR"
exit 1
fi

NUMROMS=$(ls "$ROMDIR" |wc -l)

echo "Benchmarking $NUMROMS roms in $ROMDIR for $BENCHTIME seconds ($THREADS threads)"

./mamebench-buildqueue.sh "$ROMDIR" "$LOGFILE" -t $BENCHTIME -p "$PATTERN" | ./procspawn.sh $THREADS
42 changes: 42 additions & 0 deletions utils/mamebench/procspawn.sh
@@ -0,0 +1,42 @@
#!/bin/bash

if [ "$1" = "" ]; then
echo "Usage: $0 <NUMPROCS>"
exit
fi
NUMPROCS=$1
CURRPROCS=0

ALLPROCS=

trap 'echo -n "Killing processes:"; for I in $ALLPROCS; do echo -n " $I"; kill $I; done; echo " done"; exit 1' SIGINT
trap 'NUMPROCS=$(( $NUMPROCS + 1 )); echo "Increased NUMPROCS to ${NUMPROCS}"' SIGUSR1
trap 'NUMPROCS=$(( $NUMPROCS - 1 )); echo "Decreased NUMPROCS to ${NUMPROCS}"' SIGUSR2

while read -r CMD; do
while [ $CURRPROCS -ge $NUMPROCS ]; do
STILLRUNNING=
STILLRUNNINGCNT=0
for PID in $ALLPROCS; do
if [ -e /proc/$PID ]; then
STILLRUNNING="$STILLRUNNING $PID"
STILLRUNNINGCNT=$(( $STILLRUNNINGCNT + 1 ))
fi
done
if [ "$ALLPROCS" = "$STILLRUNNING" ]; then
sleep 1
else
ALLPROCS=$STILLRUNNING
CURRPROCS=$STILLRUNNINGCNT
fi
done

sh -c "$CMD" &
NEWPID=$!
echo "Spawned '$CMD' ($NEWPID)"
ALLPROCS="$ALLPROCS $NEWPID"
CURRPROCS=$(( $CURRPROCS + 1 ))
done
wait

echo COMPLETE

0 comments on commit 3319744

Please sign in to comment.