This is the mail archive of the
libstdc++@sourceware.cygnus.com
mailing list for the libstdc++ project.
mkcheck timing patch (Bash gurus?)
- To: libstdc++ at sourceware dot cygnus dot com
- Subject: mkcheck timing patch (Bash gurus?)
- From: Phil Edwards <pedwards at jaj dot com>
- Date: Wed, 1 Dec 1999 13:52:23 -0500
Here is a patch to fill in the ctime/etime columns of the mkcheck results.
There is one part I don't like, if the Bash experts would lend a hand.
The rationale for my changes (two different methods) runs like this:
Timing the etime is relatively simple with the 'time' builtin. But
since 'time' writes to stderr and cannot be redirected outside of a
$(...) expression, the only method I found of grabbing the output was to
sink the stderr of the tests as they run. (No big deal, I think, since
they write their output to files.)
That won't work with the ctime; we need the stderr of the compiler to
go to the logfile. Separating the stderr of the compiler and the 'time'
output could be done with a little awk I would think, but never got that
to work. So -- and this is the ugly part -- I'm /still/ having to build
a little "emit the time_t" utility, run it before and after compiling,
and subtract the results. This is the same amount of exec'ing as calling
'date +%s' twice and subtracting those results, but this works on systems
without GNU date(1).
If some Bash expert is willing to play with the compilation timing, maybe
you can find a way to use the 'time' builtin and still grab the compiler's
stderr; then the utility can be discarded. This patch calls the utility
"printnow" and its source is tacked on to the end.
The check for command-line arguments just makes it easier to run the
testsuite after the ${objdir} has been deleted and "make check" is no
longer available.
1999-12-01 Phil Edwards <pedwards@jaj.com>
* mkcheck: Support for compilation/execution timing.
Index: mkcheck
===================================================================
RCS file: /cvs/libstdc++/libstdc++/mkcheck,v
retrieving revision 1.11
diff -u -3 -r1.11 mkcheck
--- mkcheck 1999/11/16 07:14:55 1.11
+++ mkcheck 1999/12/01 18:02:47
@@ -9,6 +9,11 @@
# invocation == mkcheck [01] (path to build) (path to src) (path to install)
+if [ $# != 3 ] && [ $# != 4 ]; then
+ echo 'Usage: mkcheck 0 (path to build) (path to src)'
+ echo ' mkcheck 1 (path to build) (path to src) (path to install)'
+ exit 1
+fi
echo "running mkcheck"
@@ -109,6 +114,13 @@
done
fi
+# Nasty solution to replace GNU date(1)'s %s time_t output function.
+if [ ! -x "$TEST_DIR/printnow" ]; then
+ echo "making utility $TEST_DIR/printnow"
+ gcc -o "$TEST_DIR/printnow" "$SRC_DIR/testsuite/printnow.c"
+ strip "$TEST_DIR/printnow"
+fi
+
# Remove old executables.
rm -rf "$TEST_DIR/*exe"
rm -rf "$TEST_DIR/core" "$TEST_DIR/*core"
@@ -126,7 +138,7 @@
echo "p == pass/fail execution test" >> $RESULTS_FILE
echo "ctime == time to compile and link" >> $RESULTS_FILE
-echo "ctime == time for executable to run" >> $RESULTS_FILE
+echo "etime == time for executable to run (take with salt)" >> $RESULTS_FILE
echo "text == size of the executable text section" >> $RESULTS_FILE
echo "data == size of the executable data section" >> $RESULTS_FILE
echo "total == size of the executable" >> $RESULTS_FILE
@@ -156,9 +168,16 @@
SH_NAME="`echo $PRE_NAME | sed 's/cc$/sh-exe/'`"
CNAME="$SRC_DIR/testsuite/$NAME"
- COMP_TIME_START="$(date +%s)"
+ # This would be deliciously easy if GNU date's %s were always around.
+ # There are three ways to do this: 1) use the builtin 'time' like we
+ # do later; then getting compiler errors into LOG_FILE is a nightmare.
+ # 2) Grab the output of a formatted date(1) and do the math; harder
+ # and harder as we try compiling at, say, top of the hour; we would
+ # eventually have to calculate time_t anyhow. Or 3) just grab two
+ # time_t's (no more overhead than grabbing two date(1)'s).
+ COMP_TIME_START=$($TEST_DIR/printnow)
g++ $CXX_FLAG $ST_FLAG $INC_PATH $LIB_PATH $CNAME -o $ST_NAME 2>> $LOG_FILE
- COMP_TIME_END="$(date +%s)"
+ COMP_TIME_END=$($TEST_DIR/printnow)
if [ $COMP_TIME_START -lt $COMP_TIME_END ]; then
C_TIME=$[ $COMP_TIME_END - $COMP_TIME_START ]
@@ -171,14 +190,14 @@
ST_DATA="$(size -A $ST_NAME | grep data | awk '{print $2}')"
ST_SIZE="$(size -A $ST_NAME | grep otal | awk '{print $2}')"
- # Actually run the excecutable and time it . . . need to
- # actually use some kind of gettimeofday functionality, with
- # the microseconds timer in place. Suggestions on how to
- # implement this are welcome, as the example below does not
- # work. I suppose I could wrap the exe call into a bash
- # function an call time. ..hmm.
- E_TIME=""
- $ST_NAME
+ # Actually run the executable and time it . . .
+ TIMEFORMAT='timemark %R'
+ E_TIME_TEXT="$(exec 2>&1; time $ST_NAME)"
+ E_TIME="$(echo $E_TIME_TEXT | awk '{print $2}')"
+ # joining those two commands does not work due to quoting problems:
+ #E_TIME="$(exec 2>&1; time $ST_NAME | awk '{print $2}')"
+ # this will work as a fallback on certain systems...?
+ #E_TIME=$(exec 2>&1; time $ST_NAME | cut -d ' ' -f 2)
if [ -f core ]; then
ST_EXEC='-'
@@ -246,7 +265,7 @@
fi
echo $ST_EXEC | awk '{printf ("%.1s ", $1)}'>>$RESULTS_FILE
- echo $C_TIME $E_TIME |awk '{printf("%.2d\t%.2d\t", $1, $2)}'>>$RESULTS_FILE
+ echo $C_TIME $E_TIME |awk '{printf("%d\t%.3f\t", $1, $2)}'>>$RESULTS_FILE
echo $ST_TEXT $ST_DATA | awk '{printf("%s\t%s\t", $1, $2)}'>>$RESULTS_FILE
echo $ST_SIZE | awk '{printf("%s\t", $1)}'>>$RESULTS_FILE
echo $NAME | awk '{printf("%s\n", $1)}'>>$RESULTS_FILE
========= libstdc++/testsuite/printnow.c
/* Prints the current time_t to stdout. Equivalent to the
* nonstandard %s format option to GNU date(1).
*/
#include <sys/types.h>
#include <stdio.h>
#include <time.h>
int main ()
{
printf ("%lu\n", time(NULL));
exit(0);
}