worldstone benchmark script
. also imports seq(1) to help it . add -C option to time(1) to print tsc difference . increase col width for ministat for tsc numbers
This commit is contained in:
@@ -33,7 +33,7 @@ SUBDIR= aal add_route adduser arp ash at autil awk \
|
||||
unstack update uud uue version vol wc \
|
||||
whereis which who write writeisofs fetch \
|
||||
xargs yacc yes zdump zic zmodem pkgin_cd \
|
||||
mktemp
|
||||
mktemp worldstone
|
||||
|
||||
.if ${COMPILER_TYPE} == "gnu"
|
||||
SUBDIR += elf2aout
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
PROG= time
|
||||
MAN=
|
||||
NEED_NBSDLIBC= yes
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
#include <minix/minlib.h>
|
||||
#include <minix/u64.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* -DNEW prints time to 0.01 sec. */
|
||||
@@ -33,7 +34,7 @@ int main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
|
||||
int cycles = 0;
|
||||
struct tms pre_buf, post_buf;
|
||||
int status, pid;
|
||||
#if _VMD_EXT
|
||||
@@ -42,12 +43,28 @@ char *argv[];
|
||||
struct tms dummy;
|
||||
int start_time, end_time;
|
||||
#endif
|
||||
u64_t start_tsc, end_tsc, spent_tsc;
|
||||
clock_t real_time;
|
||||
int c;
|
||||
|
||||
if (argc == 1) exit(0);
|
||||
|
||||
args = &argv[1];
|
||||
name = argv[1];
|
||||
while((c=getopt(argc, argv, "C")) != EOF) {
|
||||
switch(c) {
|
||||
case 'C':
|
||||
cycles = 1;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "usage: time [-C] <command>\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
argv += optind;
|
||||
argc -= optind;
|
||||
|
||||
args = &argv[0];
|
||||
name = argv[0];
|
||||
|
||||
/* Get real time at start of run. */
|
||||
#if _VMD_EXT
|
||||
@@ -55,6 +72,7 @@ char *argv[];
|
||||
#else
|
||||
start_time = times(&dummy);
|
||||
#endif
|
||||
read_tsc_64(&start_tsc);
|
||||
|
||||
/* Fork off child. */
|
||||
if ((pid = fork()) < 0) {
|
||||
@@ -70,6 +88,8 @@ char *argv[];
|
||||
do {
|
||||
times(&pre_buf);
|
||||
} while (wait(&status) != pid);
|
||||
read_tsc_64(&end_tsc);
|
||||
spent_tsc = sub64(end_tsc, start_tsc);
|
||||
#if _VMD_EXT
|
||||
(void) sysutime(UTIME_TIMEOFDAY, &end_time);
|
||||
real_time = (end_time.tv_sec - start_time.tv_sec) * CLOCKS_PER_SEC
|
||||
@@ -82,6 +102,9 @@ char *argv[];
|
||||
if ((status & 0377) != 0) std_err("Command terminated abnormally.\n");
|
||||
times(&post_buf);
|
||||
|
||||
if(cycles) {
|
||||
fprintf(stderr, "%qd tsc ", spent_tsc);
|
||||
}
|
||||
/* Print results. -DNEW enables time on one line to 0.01 sec */
|
||||
#ifndef NEW
|
||||
std_err("real ");
|
||||
|
||||
4
commands/worldstone/Makefile
Normal file
4
commands/worldstone/Makefile
Normal file
@@ -0,0 +1,4 @@
|
||||
SCRIPTS= worldstone.sh
|
||||
MAN= worldstone.1
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
85
commands/worldstone/worldstone.1
Normal file
85
commands/worldstone/worldstone.1
Normal file
@@ -0,0 +1,85 @@
|
||||
.Dd $Mdocdate: September 22 2011 $
|
||||
.Dt WORLDSTONE 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm worldstone
|
||||
.Nd shell script to consistently execute benchmarks
|
||||
.Sh SYNOPSIS
|
||||
.Nm worldstone
|
||||
.Op Fl n Ar iterations
|
||||
.Op Fl c Ar command
|
||||
.Op Fl p Ar command
|
||||
.Op Fl t Ar tag
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility is a shell script and takes care of some of the
|
||||
grunt work around benchmarking, in order to make it easier
|
||||
to get consistent and comparable benchmark results. Its basic
|
||||
operation is: execute the precommand, then execute and time
|
||||
the command, and do this a set number of iterations, and record
|
||||
the times in a logfile.
|
||||
|
||||
Its features are:
|
||||
.Bl -tag -width Ds
|
||||
.It -
|
||||
It executes the precommand and command once without timing it
|
||||
in order to mitigate cold cache effects.
|
||||
.It -
|
||||
It allows a precommand to run before the command, so that the initial
|
||||
state can be set up by the precommand without it being part of the timing
|
||||
(e.g. make clean).
|
||||
.It -
|
||||
It redirects the stdout and stderr to /dev/null so that lots of output
|
||||
going over a network connection doesn't influence timing.
|
||||
.It -
|
||||
It does a sync before running the timed command, and makes sure a final
|
||||
sync is part of the timed command, to make the i/o more consistent.
|
||||
.It -
|
||||
It logs the times of each iteration in an easy-to-parse logfile.
|
||||
.It -
|
||||
It tries to guess a sensible log file name based on the current git
|
||||
branch in /usr/src.
|
||||
.El
|
||||
|
||||
The options are as follows:
|
||||
.Bl -tag -width Ds
|
||||
.It Fl n Ar iterations
|
||||
Set the number of iterations to perform, after the initial run.
|
||||
The default is 5.
|
||||
.It Fl c Ar command
|
||||
Set the command to run to be timed. This is passed to sh -c, so shell constructs
|
||||
like loops etc. are okay to do. Default: make all.
|
||||
.It Fl p Ar command
|
||||
Set the pre-command to run. This command gets run before the timed command in order
|
||||
to make the timed command get a consistent state before it starts.
|
||||
Default: make clean.
|
||||
.It Fl t Ar tag
|
||||
Use the given tag name to modify the logfile that the utility uses
|
||||
to write its results in. The default is just 'time' plus the git branch you
|
||||
are currently on in /usr/src. In order for this to be useful you have to make sure the
|
||||
git branch you are on reflects the system you wish to benchmark of course.
|
||||
The script checks /usr/src/.git even if you are outside the /usr/src hierarchy
|
||||
(such as in pkgsrc).
|
||||
.El
|
||||
|
||||
The script executes the commands the set number of iterations, redirecting stdout
|
||||
and stderr to /dev/null, and records the timed results in the logfile tagged with
|
||||
the given tag.
|
||||
.Nm
|
||||
executes
|
||||
.Xr time 1
|
||||
with the -C option, resulting in printing the 64-bit cpu cycle counter
|
||||
for both HZ-independent high resolution and an easy way not to have to convert minutes
|
||||
and seconds to seconds when parsing the results.
|
||||
.Pp
|
||||
You can feed the two separate logfiles directly to
|
||||
.Xr ministat 1
|
||||
to have it tell you the statistical properties of the two datasets, and judge whether
|
||||
there is a statistically significant difference.
|
||||
.Sh ENVIRONMENT
|
||||
The default commands, i.e. make all and make clean, can be modified by supplying a MAKE
|
||||
environment variable, so e.g. MAKE=bmake worldstone still does something sensible
|
||||
by default in /usr/pkgsrc directories.
|
||||
.Sh SEE ALSO
|
||||
.Xr ministat 1
|
||||
56
commands/worldstone/worldstone.sh
Normal file
56
commands/worldstone/worldstone.sh
Normal file
@@ -0,0 +1,56 @@
|
||||
|
||||
if [ ! "$MAKE" ]; then MAKE=make; fi
|
||||
ITERATIONS=5
|
||||
PRECMD="$MAKE clean"
|
||||
COMMAND="$MAKE all"
|
||||
TAG=time.$(basename $(git --git-dir=/usr/src/.git describe --all --dirty))
|
||||
|
||||
set -e
|
||||
|
||||
while getopts "n:d:p:c:r:" c
|
||||
do
|
||||
case "$c" in
|
||||
n) ITERATIONS=$OPTARG ;;
|
||||
p) PRECMD="$OPTARG" ;;
|
||||
c) COMMAND="$OPTARG" ;;
|
||||
t) TAG=$OPTARG ;;
|
||||
r) echo "Reading settings from $OPTARG"; cat $OPTARG; . $OPTARG ; echo "Reading done.";;
|
||||
*) exit 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
CONFIGPREFIX=".worldstone"
|
||||
CONFIGVARS="ITERATIONS PRECMD COMMAND MAKE"
|
||||
TMPF=.worldstone.tmpconfig.$$
|
||||
rm -f $TMPF
|
||||
for d in $CONFIGVARS
|
||||
do eval "echo $d=\\\"\$$d\\\"" >>$TMPF
|
||||
done
|
||||
CONFIGTAG=`crc <$TMPF | awk '{ print $1 }'`
|
||||
CONFIGFILE=$CONFIGPREFIX.$CONFIGTAG
|
||||
mv -f $TMPF $CONFIGFILE
|
||||
|
||||
LOGFILE=$TAG.worldstone.log
|
||||
|
||||
while [ -f $LOGFILE ]
|
||||
do echo "$0: WARNING: $LOGFILE already exists, appending."
|
||||
LOGFILE=$LOGFILE.next
|
||||
done
|
||||
|
||||
echo "Logging to $LOGFILE."
|
||||
|
||||
echo "First run."
|
||||
sh -c "$PRECMD"
|
||||
sh -c "$COMMAND"
|
||||
|
||||
for n in `seq 1 $ITERATIONS`
|
||||
do echo -n "$n"
|
||||
sh -c "$PRECMD >/dev/null 2>&1"
|
||||
echo -n "."
|
||||
sync
|
||||
time -C sh -c "$COMMAND >/dev/null 2>&1; sync" 2>>$LOGFILE
|
||||
echo -n " "
|
||||
done
|
||||
echo "Done."
|
||||
echo "Time measurements logfile is $LOGFILE."
|
||||
echo "Config file is $CONFIGFILE."
|
||||
Reference in New Issue
Block a user