?? killer
字號:
#!/bin/sh## This is a killer test that produces timing results in msql.times# It's run as "killer <dbName>" where dbName is an existing database# in which it does it's thing. It creates, drops and generally# beats up on a table called "test" within the given database so# run it somewhere that you don't have a test table.## You may need to change a couple of the definitions below depending# on how you`re setup (eg "/var/adm/msqld.pid" and "bc -l")## The script tries to determine what sort of /bin/time you have and# works properly with either a SysV or BSD styled time.## BambiCREATE_INDEX="create unique index idx1 on test (num)"CREATE_TABLE="create table test ( name char(40), num int)"DROP="drop table test"DELETE="delete from test"TMP_FILE="/tmp/msql_test.out"RES_FILE="./msql.times"DB=$1NUM_TESTS=1#NUM_INSERTS=500000#NUM_SELECTS=75000#SEQ_SELECTS=1000NUM_INSERTS=100000NUM_SELECTS=25000SEQ_SELECTS=200CALC="bc -l"PID_FILE="/var/adm/msqld.pid"#MSQL_HOST="-h fawn"MSQL="../msql/msql $MSQL_HOST"#MSQL="/usr/local/Hughes/bin/msql $MSQL_HOST"MSQL_ADMIN="../msqladmin/msqladmin $MSQL_HOST"#MSQL_ADMIN="/usr/local/Hughes/bin/msqladmin $MSQL_HOST"PROFILE="N"GRAND_TOTAL=0if test "$DB." = "."then echo echo "Bad usage. Please read the intro to the script." echo exit 1fi## Print the output file header#echo "mSQL Killer Test. Test machine = `uname -a`" > $RES_FILE$MSQL_ADMIN version | grep "server version" >> $RES_FILEecho "------------------------------------------------------------" >> $RES_FILEecho >> $RES_FILEecho >> $RES_FILE## Try to find time. Linux may have it in /usr/bin#if test -f /bin/timethen BIN_TIME="/bin/time"else if test -f /usr/bin/time then BIN_TIME="/usr/bin/time" else if test -f /usr/sbin/time then BIN_TIME="/usr/sbin/time" fi fifiif test "$BIN_TIME." = "."then echo "Can't find /bin/time, /usr/bin/time or /usr/sbin/time" echo "Timing details ar not available" BIN_TIME="" echo "time not found. No timing details available" >> $RES_FILE echo >> $RES_FILE echo >> $RES_FILEelse echo "Using $BIN_TIME for timing calculations" $BIN_TIME --version >/dev/null 2>&1 if test $? -eq 0 then echo "$BIN_TIME is actually GNU time. Using --portability." BIN_TIME="$BIN_TIME --portability" fifi## What sort of /bin/time do we have?#if test `$BIN_TIME /bin/test 2>&1 | wc -l` -gt 1then echo "$BIN_TIME produces System V styled output." TIME_CALC="(grep -i \"^real\" | awk '{ print \$2 }')"else echo "$BIN_TIME produces BSD styled output." TIME_CALC="awk '{ print \$1 }'"fi########################################################################## Insert into a new keyed table#COUNT=0rm -f $TMP_FILETOTAL=0if test "$PROFILE." = "Y."then kill -INT `cat $PID_FILE` sleep 1 ../msql/msqld& sleep 1fiecho "Inserting $NUM_INSERTS rows into new keyed table gave :-" >> $RES_FILEwhile test $COUNT -lt $NUM_TESTSdo echo "Dropping test table" echo "$DROP \p\g" | ($MSQL $DB > /dev/null) echo "Creating keyed table" echo "$CREATE_TABLE \p\g" | ($MSQL $DB > /dev/null) echo "$CREATE_INDEX \p\g" | ($MSQL $DB > /dev/null) echo "Inserting $NUM_INSERTS rows into keyed table" $BIN_TIME ./insert_test $MSQL_HOST $DB $NUM_INSERTS 2> $TMP_FILE 3>/dev/tty if test $? -ne 0 then echo echo "Test failed! Aborting." echo exit 1 fi TIME=`(eval $TIME_CALC) < $TMP_FILE` echo " $TIME seconds real time" >> $RES_FILE TOTAL=`echo "$TOTAL + $TIME" | $CALC` COUNT=`expr $COUNT + 1` echo "Inserts took $TIME seconds"doneecho >> $RES_FILEAVG=`echo "($NUM_INSERTS * $NUM_TESTS) / $TOTAL" | $CALC | sed "s/\..*//"`echo " Total time = $TOTAL" >> $RES_FILEecho " Average operations per second = $AVG" >> $RES_FILEGRAND_TOTAL=`echo "$GRAND_TOTAL + $TOTAL" | $CALC`if test "$PROFILE." = "Y."then kill -INT `cat $PID_FILE` sleep 1 echo >> $RES_FILE echo >> $RES_FILE prof ../msql/msqld | head -10 >> $RES_FILEfiecho >> $RES_FILEecho >> $RES_FILEecho >> $RES_FILEecho >> $RES_FILE########################################################################## Filling a deleted keyed table#COUNT=0rm -f $TMP_FILETOTAL=0if test "$PROFILE." = "Y."then ../msql/msqld& sleep 1fiecho "Filling a deleted keyed table with $NUM_INSERTS rows gave :-" >> $RES_FILEwhile test $COUNT -lt $NUM_TESTSdo echo "Deleting contents of keyed table" echo "$DELETE \p\g" | ($MSQL $DB > /dev/null) echo "Filling data holes with $NUM_INSERTS inserts." $BIN_TIME ./insert_test $MSQL_HOST $DB $NUM_INSERTS 2> $TMP_FILE if test $? -ne 0 then echo echo "Test failed! Aborting." echo exit 1 fi TIME=`(eval $TIME_CALC) < $TMP_FILE` echo " $TIME seconds real time" >> $RES_FILE TOTAL=`echo "$TOTAL + $TIME" | $CALC` COUNT=`expr $COUNT + 1` echo "Inserts took $TIME seconds."doneecho >> $RES_FILEAVG=`echo "($NUM_INSERTS * $NUM_TESTS) / $TOTAL" | $CALC| sed "s/\..*//"`echo " Total time = $TOTAL" >> $RES_FILEecho " Average operations per second = $AVG" >> $RES_FILEGRAND_TOTAL=`echo "$GRAND_TOTAL + $TOTAL" | $CALC`if test "$PROFILE." = "Y."then kill -INT `cat $PID_FILE` sleep 1 echo >> $RES_FILE echo >> $RES_FILE prof ../msql/msqld | head -10 >> $RES_FILEfiecho >> $RES_FILEecho >> $RES_FILEecho >> $RES_FILEecho >> $RES_FILE########################################################################## Selecting from a keyed table#COUNT=0rm -f $TMP_FILETOTAL=0if test "$PROFILE." = "Y."then ../msql/msqld& sleep 1fiecho "Selecting $NUM_SELECTS rows using primary key :-" >> $RES_FILEwhile test $COUNT -lt $NUM_TESTSdo echo "Selecting $NUM_SELECTS rows from a keyed table" $BIN_TIME ./select_test $MSQL_HOST $DB $NUM_SELECTS 2> $TMP_FILE if test $? -ne 0 then echo echo "Test failed! Aborting." echo exit 1 fi TIME=`(eval $TIME_CALC) < $TMP_FILE` echo " $TIME seconds real time" >> $RES_FILE TOTAL=`echo "$TOTAL + $TIME" | $CALC` COUNT=`expr $COUNT + 1` echo "Selects took $TIME seconds"doneecho >> $RES_FILEAVG=`echo "($NUM_SELECTS * $NUM_TESTS) / $TOTAL" | $CALC| sed "s/\..*//"`echo " Total time = $TOTAL" >> $RES_FILEecho " Average operations per second = $AVG" >> $RES_FILEGRAND_TOTAL=`echo "$GRAND_TOTAL + $TOTAL" | $CALC`if test "$PROFILE." = "Y."then kill -INT `cat $PID_FILE` sleep 1 echo >> $RES_FILE echo >> $RES_FILE prof ../msql/msqld | head -10 >> $RES_FILEfiecho >> $RES_FILEecho >> $RES_FILEecho >> $RES_FILEecho >> $RES_FILE########################################################################## Insert into a new flat table#COUNT=0rm -f $TMP_FILETOTAL=0if test "$PROFILE." = "Y."then ../msql/msqld& sleep 1fiecho "Inserting $NUM_INSERTS rows into new flat table gave :-" >> $RES_FILEwhile test $COUNT -lt $NUM_TESTSdo echo "Dropping test table" echo "$DROP \p\g" | ($MSQL $DB > /dev/null) echo "Creating flat table" echo "$CREATE_TABLE \p\g" | ($MSQL $DB > /dev/null) echo "Inserting $NUM_INSERTS rows into flat table" $BIN_TIME ./insert_test $MSQL_HOST $DB $NUM_INSERTS 2> $TMP_FILE if test $? -ne 0 then echo echo "Test failed! Aborting." echo exit 1 fi TIME=`(eval $TIME_CALC) < $TMP_FILE` echo " $TIME seconds real time" >> $RES_FILE TOTAL=`echo "$TOTAL + $TIME" | $CALC` COUNT=`expr $COUNT + 1` echo "Inserts took $TIME seconds."doneecho >> $RES_FILEAVG=`echo "($NUM_INSERTS * $NUM_TESTS) / $TOTAL" | $CALC| sed "s/\..*//"`echo " Total time = $TOTAL" >> $RES_FILEecho " Average operations per second = $AVG" >> $RES_FILEGRAND_TOTAL=`echo "$GRAND_TOTAL + $TOTAL" | $CALC`if test "$PROFILE." = "Y."then kill -INT `cat $PID_FILE` sleep 1 echo >> $RES_FILE echo >> $RES_FILE prof ../msql/msqld | head -10 >> $RES_FILEfiecho >> $RES_FILEecho >> $RES_FILEecho >> $RES_FILEecho >> $RES_FILE########################################################################## Filling a flat table#COUNT=0rm -f $TMP_FILETOTAL=0if test "$PROFILE." = "Y."then ../msql/msqld& sleep 1fiecho "Filling a deleted flat table with $NUM_INSERTS rows gave :-" >> $RES_FILEwhile test $COUNT -lt $NUM_TESTSdo echo "Deleting contents of flat table" echo "$DELETE \p\g" | ($MSQL $DB > /dev/null) echo "Filling data holes with $NUM_INSERTS inserts." $BIN_TIME ./insert_test $MSQL_HOST $DB $NUM_INSERTS 2> $TMP_FILE if test $? -ne 0 then echo echo "Test failed! Aborting." echo exit 1 fi TIME=`(eval $TIME_CALC) < $TMP_FILE` echo " $TIME seconds real time" >> $RES_FILE TOTAL=`echo "$TOTAL + $TIME" | $CALC` COUNT=`expr $COUNT + 1` echo "Inserts took $TIME seconds"doneecho >> $RES_FILEAVG=`echo "($NUM_INSERTS * $NUM_TESTS) / $TOTAL" | $CALC| sed "s/\..*//"`echo " Total time = $TOTAL" >> $RES_FILEecho " Average operations per second = $AVG" >> $RES_FILEGRAND_TOTAL=`echo "$GRAND_TOTAL + $TOTAL" | $CALC`if test "$PROFILE." = "Y."then kill -INT `cat $PID_FILE` sleep 1 echo >> $RES_FILE echo >> $RES_FILE prof ../msql/msqld | head -10 >> $RES_FILEfiecho >> $RES_FILEecho >> $RES_FILEecho >> $RES_FILEecho >> $RES_FILE########################################################################## Selecting from a flat table#COUNT=0rm -f $TMP_FILETOTAL=0if test "$PROFILE." = "Y."then ../msql/msqld& sleep 1fiecho "Selecting $SEQ_SELECTS rows without a key :-" >> $RES_FILEwhile test $COUNT -lt $NUM_TESTSdo echo "Selecting $SEQ_SELECTS rows from a flat table" $BIN_TIME ./select_test $MSQL_HOST $DB $SEQ_SELECTS 2> $TMP_FILE if test $? -ne 0 then echo echo "Test failed! Aborting." echo exit 1 fi TIME=`(eval $TIME_CALC) < $TMP_FILE` echo " $TIME seconds real time" >> $RES_FILE TOTAL=`echo "$TOTAL + $TIME" | $CALC` COUNT=`expr $COUNT + 1` echo "Selects took $TIME seconds"doneecho >> $RES_FILEAVG=`echo "($NUM_SELECTS * $NUM_TESTS) / $TOTAL" | $CALC| sed "s/\..*//"`echo " Total time = $TOTAL" >> $RES_FILEecho " Average operations per second = $AVG" >> $RES_FILEGRAND_TOTAL=`echo "$GRAND_TOTAL + $TOTAL" | $CALC`if test "$PROFILE." = "Y."then kill -INT `cat $PID_FILE` sleep 1 echo >> $RES_FILE echo >> $RES_FILE prof ../msql/msqld | head -10 >> $RES_FILEfiecho >> $RES_FILEecho >> $RES_FILEecho "Total execution time = $GRAND_TOTAL" >> $RES_FILEecho >> $RES_FILEecho >> $RES_FILEechoechoecho "Total execution time = $GRAND_TOTAL" echo
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -