From 13052e3fbac5cd2224dd2f6baea4b668d8c2a3ef Mon Sep 17 00:00:00 2001 From: Alexey Kopytov Date: Fri, 9 Jun 2006 15:42:45 +0000 Subject: [PATCH] Added preliminary scripting support --- ChangeLog | 4 + Makefile.in | 5 + acinclude.m4 | 63 ++ config/config.h.in | 3 + configure | 674 +++++++++++++++++-- configure.ac | 8 +- doc/Makefile.in | 5 + scripts/Makefile.in | 5 + sysbench/Makefile.am | 12 +- sysbench/Makefile.in | 20 +- sysbench/db_driver.c | 129 +++- sysbench/db_driver.h | 22 +- sysbench/drivers/Makefile.in | 5 + sysbench/drivers/mysql/Makefile.in | 5 + sysbench/drivers/mysql/drv_mysql.c | 4 +- sysbench/drivers/oracle/Makefile.in | 5 + sysbench/drivers/pgsql/Makefile.in | 5 + sysbench/sb_list.h | 8 +- sysbench/sb_options.c | 147 +++- sysbench/sb_options.h | 18 +- sysbench/scripting/Makefile.am | 26 + sysbench/scripting/Makefile.in | 511 ++++++++++++++ sysbench/scripting/sb_script.c | 42 ++ sysbench/scripting/sb_script.h | 31 + sysbench/scripting/script_lua.c | 886 +++++++++++++++++++++++++ sysbench/scripting/script_lua.h | 26 + sysbench/sysbench.c | 193 +++++- sysbench/sysbench.h | 12 +- sysbench/tests/Makefile.in | 5 + sysbench/tests/cpu/Makefile.in | 5 + sysbench/tests/db/delete.lua | 108 +++ sysbench/tests/db/insert.lua | 99 +++ sysbench/tests/db/oltp_complex_ro.lua | 163 +++++ sysbench/tests/db/oltp_complex_rw.lua | 200 ++++++ sysbench/tests/db/oltp_simple.lua | 109 +++ sysbench/tests/db/select.lua | 110 +++ sysbench/tests/db/update_index.lua | 108 +++ sysbench/tests/db/update_non_index.lua | 110 +++ sysbench/tests/fileio/Makefile.in | 5 + sysbench/tests/fileio/sb_fileio.c | 3 +- sysbench/tests/memory/Makefile.in | 5 + sysbench/tests/mutex/Makefile.in | 5 + sysbench/tests/oltp/Makefile.in | 5 + sysbench/tests/oltp/sb_oltp.c | 140 +--- sysbench/tests/threads/Makefile.in | 5 + 45 files changed, 3830 insertions(+), 229 deletions(-) create mode 100644 sysbench/scripting/Makefile.am create mode 100644 sysbench/scripting/Makefile.in create mode 100644 sysbench/scripting/sb_script.c create mode 100644 sysbench/scripting/sb_script.h create mode 100644 sysbench/scripting/script_lua.c create mode 100644 sysbench/scripting/script_lua.h create mode 100644 sysbench/tests/db/delete.lua create mode 100644 sysbench/tests/db/insert.lua create mode 100644 sysbench/tests/db/oltp_complex_ro.lua create mode 100644 sysbench/tests/db/oltp_complex_rw.lua create mode 100644 sysbench/tests/db/oltp_simple.lua create mode 100644 sysbench/tests/db/select.lua create mode 100644 sysbench/tests/db/update_index.lua create mode 100644 sysbench/tests/db/update_non_index.lua diff --git a/ChangeLog b/ChangeLog index 7903dcf..4882e35 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2006-05-28 Alexey Kopytov + + * count fsync() time as request execution time in file-fsync-all mode + 2006-05-24 Alexey Kopytov * Added --oltp-reconnect option diff --git a/Makefile.in b/Makefile.in index 3114f60..709a54e 100644 --- a/Makefile.in +++ b/Makefile.in @@ -137,6 +137,8 @@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ +LUA_CPPFLAGS = @LUA_CPPFLAGS@ +LUA_LDFLAGS = @LUA_LDFLAGS@ MAKEINFO = @MAKEINFO@ MYSQL_CFLAGS = @MYSQL_CFLAGS@ MYSQL_LIBS = @MYSQL_LIBS@ @@ -161,6 +163,8 @@ SHELL = @SHELL@ STRIP = @STRIP@ USE_AIO_FALSE = @USE_AIO_FALSE@ USE_AIO_TRUE = @USE_AIO_TRUE@ +USE_LUA_FALSE = @USE_LUA_FALSE@ +USE_LUA_TRUE = @USE_LUA_TRUE@ USE_MYSQL_FALSE = @USE_MYSQL_FALSE@ USE_MYSQL_TRUE = @USE_MYSQL_TRUE@ USE_ORACLE_FALSE = @USE_ORACLE_FALSE@ @@ -208,6 +212,7 @@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localstatedir = @localstatedir@ +luaconfig = @luaconfig@ mandir = @mandir@ mkdir_p = @mkdir_p@ mysqlconfig = @mysqlconfig@ diff --git a/acinclude.m4 b/acinclude.m4 index dce5349..4c7688b 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -454,3 +454,66 @@ else fi AC_LANG_RESTORE ]) + + +dnl --------------------------------------------------------------------------- +dnl Macro: AC_LUA_DEVEL +dnl Checks for Lua and provides the $(LUA_CPPFLAGS) and $(LUA_LDFLAGS) output variables. +dnl --------------------------------------------------------------------------- +AC_DEFUN([AC_LUA_DEVEL],[ + +AC_ARG_WITH(lua, + AC_HELP_STRING([--with-lua],[Compile with Lua scripting support (default is enabled)]), + [ac_cv_use_lua="$with_lua"], [ac_cv_use_lua="yes"]) +AC_CACHE_CHECK([whether to compile with Lua support], [ac_cv_use_lua], [ac_cv_use_lua=no]) + +if test "xac_cv_use_lua" != "xno"; then + +if test "x$ac_cv_use_lua" != "xyes"; then + LUA_CPPFLAGS="-I$ac_cv_use_lua/include" + LUA_LDFLAGS="-L$ac_cv_use_lua/lib" +fi + +AC_CHECK_PROGS(luaconfig, [lua-config lua-config51 luaconfig5.1], "") +if test "x$luaconfig" != "x"; then + LUA_CPPFLAGS="$LUA_CPPFLAGS `[$luaconfig --include]`" + LUA_LDFLAGS="$LUA_LDFLAGS `[$luaconfig --libs]`" +else + if test "$ARCH" = "linux"; then + LUA_LDFLAGS="$LUA_LDFLAGS -ldl" + fi + + AC_CHECK_LIB(lua, lua_getfenv, tmp="-llua", , [$LUA_LDFLAGS -lm]) + if test "x$tmp" = "x"; then + AC_CHECK_LIB(lua50, lua_setfenv, tmp="-llua50", , [$LUA_LDFLAGS -lm]) + fi + if test "x$tmp" = "x"; then + AC_CHECK_LIB(lua5.0, lua_setfenv, tmp=="-llua5.0", , [$LUA_LDFLAGS -lm]) + fi + if test "x$tmp" = "x"; then + AC_MSG_ERROR([Cannot find Lua libraries]) + fi + LUA_LDFLAGS="$LUA_LDFLAGS $tmp" + + tmp="" + AC_CHECK_LIB(lualib, luaopen_base, tmp="-llualib", , [$LUA_LDFLAGS -lm]) + if test "x$tmp" = "x"; then + AC_CHECK_LIB(lualib50, luaopen_base, tmp="-llualib50", , [$LUA_LDFLAGS -lm]) + fi + if test "x$tmp" = "x"; then + AC_CHECK_LIB(lualib5.0, luaopen_base, tmp="-llualib5.0", , [$LUA_LDFLAGS -lm]) + fi + if test "x$tmp" = "x"; then + AC_MSG_ERROR([Cannot find Lua libraries]) + fi + LUA_LDFLAGS="$LUA_LDFLAGS $tmp" +fi + +LUA_LDFLAGS="$LUA_LDFLAGS -lm" +AC_SUBST(LUA_CPPFLAGS) +AC_SUBST(LUA_LDFLAGS) +AC_DEFINE(HAVE_LUA, 1, [Define to 1 if you have Lua headers and libraries]) +AM_CONDITIONAL(USE_LUA, test "x$ac_cv_use_lua" != "x") + +fi +]) diff --git a/config/config.h.in b/config/config.h.in index 87027dc..ef11ee6 100644 --- a/config/config.h.in +++ b/config/config.h.in @@ -48,6 +48,9 @@ /* Define to 1 if you have the `m' library (-lm). */ #undef HAVE_LIBM +/* Define to 1 if you have Lua headers and libraries */ +#undef HAVE_LUA + /* Define to 1 if your system has a GNU libc compatible `malloc' function, and to 0 otherwise. */ #undef HAVE_MALLOC diff --git a/configure b/configure index 7628df2..775c102 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.59 for sysbench 0.4.8. +# Generated by GNU Autoconf 2.59 for sysbench 0.5. # # Report bugs to . # @@ -423,8 +423,8 @@ SHELL=${CONFIG_SHELL-/bin/sh} # Identity of this package. PACKAGE_NAME='sysbench' PACKAGE_TARNAME='sysbench' -PACKAGE_VERSION='0.4.8' -PACKAGE_STRING='sysbench 0.4.8' +PACKAGE_VERSION='0.5' +PACKAGE_STRING='sysbench 0.5' PACKAGE_BUGREPORT='alexeyk@mysql.com' ac_unique_file="sysbench/sysbench.c" @@ -465,7 +465,7 @@ ac_includes_default="\ # include #endif" -ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS build build_cpu build_vendor build_os host host_cpu host_vendor host_os target target_cpu target_vendor target_os INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA CYGPATH_W PACKAGE VERSION ACLOCAL AUTOCONF AUTOMAKE AUTOHEADER MAKEINFO install_sh STRIP ac_ct_STRIP INSTALL_STRIP_PROGRAM mkdir_p AWK SET_MAKE am__leading_dot AMTAR am__tar am__untar CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT DEPDIR am__include am__quote AMDEP_TRUE AMDEP_FALSE AMDEPBACKSLASH CCDEPMODE am__fastdepCC_TRUE am__fastdepCC_FALSE EGREP LN_S ECHO AR ac_ct_AR RANLIB ac_ct_RANLIB CPP CXX CXXFLAGS ac_ct_CXX CXXDEPMODE am__fastdepCXX_TRUE am__fastdepCXX_FALSE CXXCPP F77 FFLAGS ac_ct_F77 LIBTOOL XSLTPROC have_xsltproc_TRUE have_xsltproc_FALSE XML_CATALOG XSLTPROC_FLAGS DOCBOOK_ROOT CAT_ENTRY_START CAT_ENTRY_END acx_pthread_config PTHREAD_CC PTHREAD_LIBS PTHREAD_CFLAGS mysqlconfig MYSQL_LIBS MYSQL_CFLAGS USE_MYSQL_TRUE USE_MYSQL_FALSE USE_ORACLE_TRUE USE_ORACLE_FALSE ORA_LIBS ORA_CFLAGS pgconfig PGSQL_LIBS PGSQL_CFLAGS USE_PGSQL_TRUE USE_PGSQL_FALSE USE_AIO_TRUE USE_AIO_FALSE LIBOBJS AM_CFLAGS AM_CPPFLAGS AM_LDFLAGS LTLIBOBJS' +ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS build build_cpu build_vendor build_os host host_cpu host_vendor host_os target target_cpu target_vendor target_os INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA CYGPATH_W PACKAGE VERSION ACLOCAL AUTOCONF AUTOMAKE AUTOHEADER MAKEINFO install_sh STRIP ac_ct_STRIP INSTALL_STRIP_PROGRAM mkdir_p AWK SET_MAKE am__leading_dot AMTAR am__tar am__untar luaconfig CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT DEPDIR am__include am__quote AMDEP_TRUE AMDEP_FALSE AMDEPBACKSLASH CCDEPMODE am__fastdepCC_TRUE am__fastdepCC_FALSE LUA_CPPFLAGS LUA_LDFLAGS USE_LUA_TRUE USE_LUA_FALSE EGREP LN_S ECHO AR ac_ct_AR RANLIB ac_ct_RANLIB CPP CXX CXXFLAGS ac_ct_CXX CXXDEPMODE am__fastdepCXX_TRUE am__fastdepCXX_FALSE CXXCPP F77 FFLAGS ac_ct_F77 LIBTOOL XSLTPROC have_xsltproc_TRUE have_xsltproc_FALSE XML_CATALOG XSLTPROC_FLAGS DOCBOOK_ROOT CAT_ENTRY_START CAT_ENTRY_END acx_pthread_config PTHREAD_CC PTHREAD_LIBS PTHREAD_CFLAGS mysqlconfig MYSQL_LIBS MYSQL_CFLAGS USE_MYSQL_TRUE USE_MYSQL_FALSE USE_ORACLE_TRUE USE_ORACLE_FALSE ORA_LIBS ORA_CFLAGS pgconfig PGSQL_LIBS PGSQL_CFLAGS USE_PGSQL_TRUE USE_PGSQL_FALSE USE_AIO_TRUE USE_AIO_FALSE LIBOBJS AM_CFLAGS AM_CPPFLAGS AM_LDFLAGS LTLIBOBJS' ac_subst_files='' # Initialize some variables set by options. @@ -954,7 +954,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures sysbench 0.4.8 to adapt to many kinds of systems. +\`configure' configures sysbench 0.5 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1021,16 +1021,16 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of sysbench 0.4.8:";; + short | recursive ) echo "Configuration of sysbench 0.5:";; esac cat <<\_ACEOF Optional Features: --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] - --enable-largefile enable large files support (default is enabled) --disable-dependency-tracking speeds up one-time build --enable-dependency-tracking do not reject slow dependency extractors + --enable-largefile enable large files support (default is enabled) --enable-aio enable Linux asynchronous I/O support (default is enabled) --enable-shared[=PKGS] @@ -1049,6 +1049,8 @@ Optional Packages: --with-oracle compile with Oracle support (default is disabled) --with-pgsql compile with PostgreSQL support (default is disabled) + --with-lua Compile with Lua scripting support (default is + enabled) --with-gnu-ld assume the C compiler uses GNU ld [default=no] --with-pic try to use only PIC/non-PIC objects [default=use both] @@ -1172,7 +1174,7 @@ fi test -n "$ac_init_help" && exit 0 if $ac_init_version; then cat <<\_ACEOF -sysbench configure 0.4.8 +sysbench configure 0.5 generated by GNU Autoconf 2.59 Copyright (C) 2003 Free Software Foundation, Inc. @@ -1186,7 +1188,7 @@ cat >&5 <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by sysbench $as_me 0.4.8, which was +It was created by sysbench $as_me 0.5, which was generated by GNU Autoconf 2.59. Invocation command line was $ $0 $@ @@ -1911,7 +1913,7 @@ fi # Define the identity of the package. PACKAGE='sysbench' - VERSION='0.4.8' + VERSION='0.5' cat >>confdefs.h <<_ACEOF @@ -2107,17 +2109,7 @@ fi echo "$as_me:$LINENO: result: $ac_cv_use_pgsql" >&5 echo "${ECHO_T}$ac_cv_use_pgsql" >&6 -# Check if we should enable large files support -# Check whether --enable-largefile or --disable-largefile was given. -if test "${enable_largefile+set}" = set; then - enableval="$enable_largefile" - -else - enable_largefile=yes - -fi; - -# For SHM_HUGETLB on Linux +# Check if we should compile with Lua interpreter support DEPDIR="${am__leading_dot}deps" ac_config_commands="$ac_config_commands depfiles" @@ -3223,6 +3215,547 @@ fi + + + +# Check whether --with-lua or --without-lua was given. +if test "${with_lua+set}" = set; then + withval="$with_lua" + ac_cv_use_lua="$with_lua" +else + ac_cv_use_lua="yes" +fi; +echo "$as_me:$LINENO: checking whether to compile with Lua support" >&5 +echo $ECHO_N "checking whether to compile with Lua support... $ECHO_C" >&6 +if test "${ac_cv_use_lua+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_cv_use_lua=no +fi +echo "$as_me:$LINENO: result: $ac_cv_use_lua" >&5 +echo "${ECHO_T}$ac_cv_use_lua" >&6 + +if test "xac_cv_use_lua" != "xno"; then + +if test "x$ac_cv_use_lua" != "xyes"; then + LUA_CPPFLAGS="-I$ac_cv_use_lua/include" + LUA_LDFLAGS="-L$ac_cv_use_lua/lib" +fi + +for ac_prog in lua-config lua-config51 luaconfig5.1 +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 +if test "${ac_cv_prog_luaconfig+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$luaconfig"; then + ac_cv_prog_luaconfig="$luaconfig" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_luaconfig="$ac_prog" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done + +fi +fi +luaconfig=$ac_cv_prog_luaconfig +if test -n "$luaconfig"; then + echo "$as_me:$LINENO: result: $luaconfig" >&5 +echo "${ECHO_T}$luaconfig" >&6 +else + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 +fi + + test -n "$luaconfig" && break +done +test -n "$luaconfig" || luaconfig="""" + +if test "x$luaconfig" != "x"; then + LUA_CPPFLAGS="$LUA_CPPFLAGS `$luaconfig --include`" + LUA_LDFLAGS="$LUA_LDFLAGS `$luaconfig --libs`" +else + if test "$ARCH" = "linux"; then + LUA_LDFLAGS="$LUA_LDFLAGS -ldl" + fi + + echo "$as_me:$LINENO: checking for lua_getfenv in -llua" >&5 +echo $ECHO_N "checking for lua_getfenv in -llua... $ECHO_C" >&6 +if test "${ac_cv_lib_lua_lua_getfenv+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-llua $LUA_LDFLAGS -lm $LIBS" +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char lua_getfenv (); +int +main () +{ +lua_getfenv (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lib_lua_lua_getfenv=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lib_lua_lua_getfenv=no +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_lib_lua_lua_getfenv" >&5 +echo "${ECHO_T}$ac_cv_lib_lua_lua_getfenv" >&6 +if test $ac_cv_lib_lua_lua_getfenv = yes; then + tmp="-llua" +fi + + if test "x$tmp" = "x"; then + echo "$as_me:$LINENO: checking for lua_setfenv in -llua50" >&5 +echo $ECHO_N "checking for lua_setfenv in -llua50... $ECHO_C" >&6 +if test "${ac_cv_lib_lua50_lua_setfenv+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-llua50 $LUA_LDFLAGS -lm $LIBS" +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char lua_setfenv (); +int +main () +{ +lua_setfenv (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lib_lua50_lua_setfenv=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lib_lua50_lua_setfenv=no +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_lib_lua50_lua_setfenv" >&5 +echo "${ECHO_T}$ac_cv_lib_lua50_lua_setfenv" >&6 +if test $ac_cv_lib_lua50_lua_setfenv = yes; then + tmp="-llua50" +fi + + fi + if test "x$tmp" = "x"; then + echo "$as_me:$LINENO: checking for lua_setfenv in -llua5.0" >&5 +echo $ECHO_N "checking for lua_setfenv in -llua5.0... $ECHO_C" >&6 +if test "${ac_cv_lib_lua5_0_lua_setfenv+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-llua5.0 $LUA_LDFLAGS -lm $LIBS" +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char lua_setfenv (); +int +main () +{ +lua_setfenv (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lib_lua5_0_lua_setfenv=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lib_lua5_0_lua_setfenv=no +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_lib_lua5_0_lua_setfenv" >&5 +echo "${ECHO_T}$ac_cv_lib_lua5_0_lua_setfenv" >&6 +if test $ac_cv_lib_lua5_0_lua_setfenv = yes; then + tmp=="-llua5.0" +fi + + fi + if test "x$tmp" = "x"; then + { { echo "$as_me:$LINENO: error: Cannot find Lua libraries" >&5 +echo "$as_me: error: Cannot find Lua libraries" >&2;} + { (exit 1); exit 1; }; } + fi + LUA_LDFLAGS="$LUA_LDFLAGS $tmp" + + tmp="" + echo "$as_me:$LINENO: checking for luaopen_base in -llualib" >&5 +echo $ECHO_N "checking for luaopen_base in -llualib... $ECHO_C" >&6 +if test "${ac_cv_lib_lualib_luaopen_base+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-llualib $LUA_LDFLAGS -lm $LIBS" +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char luaopen_base (); +int +main () +{ +luaopen_base (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lib_lualib_luaopen_base=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lib_lualib_luaopen_base=no +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_lib_lualib_luaopen_base" >&5 +echo "${ECHO_T}$ac_cv_lib_lualib_luaopen_base" >&6 +if test $ac_cv_lib_lualib_luaopen_base = yes; then + tmp="-llualib" +fi + + if test "x$tmp" = "x"; then + echo "$as_me:$LINENO: checking for luaopen_base in -llualib50" >&5 +echo $ECHO_N "checking for luaopen_base in -llualib50... $ECHO_C" >&6 +if test "${ac_cv_lib_lualib50_luaopen_base+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-llualib50 $LUA_LDFLAGS -lm $LIBS" +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char luaopen_base (); +int +main () +{ +luaopen_base (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lib_lualib50_luaopen_base=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lib_lualib50_luaopen_base=no +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_lib_lualib50_luaopen_base" >&5 +echo "${ECHO_T}$ac_cv_lib_lualib50_luaopen_base" >&6 +if test $ac_cv_lib_lualib50_luaopen_base = yes; then + tmp="-llualib50" +fi + + fi + if test "x$tmp" = "x"; then + echo "$as_me:$LINENO: checking for luaopen_base in -llualib5.0" >&5 +echo $ECHO_N "checking for luaopen_base in -llualib5.0... $ECHO_C" >&6 +if test "${ac_cv_lib_lualib5_0_luaopen_base+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-llualib5.0 $LUA_LDFLAGS -lm $LIBS" +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char luaopen_base (); +int +main () +{ +luaopen_base (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lib_lualib5_0_luaopen_base=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lib_lualib5_0_luaopen_base=no +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_lib_lualib5_0_luaopen_base" >&5 +echo "${ECHO_T}$ac_cv_lib_lualib5_0_luaopen_base" >&6 +if test $ac_cv_lib_lualib5_0_luaopen_base = yes; then + tmp="-llualib5.0" +fi + + fi + if test "x$tmp" = "x"; then + { { echo "$as_me:$LINENO: error: Cannot find Lua libraries" >&5 +echo "$as_me: error: Cannot find Lua libraries" >&2;} + { (exit 1); exit 1; }; } + fi + LUA_LDFLAGS="$LUA_LDFLAGS $tmp" +fi + +LUA_LDFLAGS="$LUA_LDFLAGS -lm" + + + +cat >>confdefs.h <<\_ACEOF +#define HAVE_LUA 1 +_ACEOF + + + +if test "x$ac_cv_use_lua" != "x"; then + USE_LUA_TRUE= + USE_LUA_FALSE='#' +else + USE_LUA_TRUE='#' + USE_LUA_FALSE= +fi + + +fi + + +# Check if we should enable large files support +# Check whether --enable-largefile or --disable-largefile was given. +if test "${enable_largefile+set}" = set; then + enableval="$enable_largefile" + +else + enable_largefile=yes + +fi; + +# For SHM_HUGETLB on Linux echo "$as_me:$LINENO: checking whether SHM_HUGETLB is declared" >&5 echo $ECHO_N "checking whether SHM_HUGETLB is declared... $ECHO_C" >&6 if test "${ac_cv_have_decl_SHM_HUGETLB+set}" = set; then @@ -4793,7 +5326,7 @@ ia64-*-hpux*) ;; *-*-irix6*) # Find out which ABI we are using. - echo '#line 4796 "configure"' > conftest.$ac_ext + echo '#line 5329 "configure"' > conftest.$ac_ext if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 (eval $ac_compile) 2>&5 ac_status=$? @@ -6631,7 +7164,7 @@ fi # Provide some information about the compiler. -echo "$as_me:6634:" \ +echo "$as_me:7167:" \ "checking for Fortran 77 compiler version" >&5 ac_compiler=`set X $ac_compile; echo $2` { (eval echo "$as_me:$LINENO: \"$ac_compiler --version &5\"") >&5 @@ -7688,11 +8221,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:7691: $lt_compile\"" >&5) + (eval echo "\"\$as_me:8224: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:7695: \$? = $ac_status" >&5 + echo "$as_me:8228: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings @@ -7931,11 +8464,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:7934: $lt_compile\"" >&5) + (eval echo "\"\$as_me:8467: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:7938: \$? = $ac_status" >&5 + echo "$as_me:8471: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings @@ -7991,11 +8524,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:7994: $lt_compile\"" >&5) + (eval echo "\"\$as_me:8527: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:7998: \$? = $ac_status" >&5 + echo "$as_me:8531: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -9327,7 +9860,7 @@ linux*) libsuff= case "$host_cpu" in x86_64*|s390x*|powerpc64*) - echo '#line 9330 "configure"' > conftest.$ac_ext + echo '#line 9863 "configure"' > conftest.$ac_ext if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 (eval $ac_compile) 2>&5 ac_status=$? @@ -10311,7 +10844,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext < conftest.$ac_ext <&5) + (eval echo "\"\$as_me:13141: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:12612: \$? = $ac_status" >&5 + echo "$as_me:13145: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings @@ -12665,11 +13198,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:12668: $lt_compile\"" >&5) + (eval echo "\"\$as_me:13201: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:12672: \$? = $ac_status" >&5 + echo "$as_me:13205: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -13179,7 +13712,7 @@ linux*) libsuff= case "$host_cpu" in x86_64*|s390x*|powerpc64*) - echo '#line 13182 "configure"' > conftest.$ac_ext + echo '#line 13715 "configure"' > conftest.$ac_ext if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 (eval $ac_compile) 2>&5 ac_status=$? @@ -14163,7 +14696,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext < conftest.$ac_ext <&5) + (eval echo "\"\$as_me:16838: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:16309: \$? = $ac_status" >&5 + echo "$as_me:16842: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings @@ -16362,11 +16895,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:16365: $lt_compile\"" >&5) + (eval echo "\"\$as_me:16898: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:16369: \$? = $ac_status" >&5 + echo "$as_me:16902: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -16876,7 +17409,7 @@ linux*) libsuff= case "$host_cpu" in x86_64*|s390x*|powerpc64*) - echo '#line 16879 "configure"' > conftest.$ac_ext + echo '#line 17412 "configure"' > conftest.$ac_ext if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 (eval $ac_compile) 2>&5 ac_status=$? @@ -17860,7 +18393,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext < conftest.$ac_ext <&5) + (eval echo "\"\$as_me:19330: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:18801: \$? = $ac_status" >&5 + echo "$as_me:19334: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings @@ -18854,11 +19387,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:18857: $lt_compile\"" >&5) + (eval echo "\"\$as_me:19390: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:18861: \$? = $ac_status" >&5 + echo "$as_me:19394: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -20170,7 +20703,7 @@ linux*) libsuff= case "$host_cpu" in x86_64*|s390x*|powerpc64*) - echo '#line 20173 "configure"' > conftest.$ac_ext + echo '#line 20706 "configure"' > conftest.$ac_ext if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 (eval $ac_compile) 2>&5 ac_status=$? @@ -20914,11 +21447,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:20917: $lt_compile\"" >&5) + (eval echo "\"\$as_me:21450: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:20921: \$? = $ac_status" >&5 + echo "$as_me:21454: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings @@ -21157,11 +21690,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:21160: $lt_compile\"" >&5) + (eval echo "\"\$as_me:21693: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:21164: \$? = $ac_status" >&5 + echo "$as_me:21697: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings @@ -21217,11 +21750,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:21220: $lt_compile\"" >&5) + (eval echo "\"\$as_me:21753: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:21224: \$? = $ac_status" >&5 + echo "$as_me:21757: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -22553,7 +23086,7 @@ linux*) libsuff= case "$host_cpu" in x86_64*|s390x*|powerpc64*) - echo '#line 22556 "configure"' > conftest.$ac_ext + echo '#line 23089 "configure"' > conftest.$ac_ext if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 (eval $ac_compile) 2>&5 ac_status=$? @@ -23537,7 +24070,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext < conftest.$ac_ext <confcache <<\_ACEOF # This file is a shell script that caches the results of configure # tests run on this system so they can be shared between configure @@ -28865,6 +29398,13 @@ echo "$as_me: error: conditional \"am__fastdepCC\" was never defined. Usually this means the macro was only invoked conditionally." >&2;} { (exit 1); exit 1; }; } fi +if test -z "${USE_LUA_TRUE}" && test -z "${USE_LUA_FALSE}"; then + { { echo "$as_me:$LINENO: error: conditional \"USE_LUA\" was never defined. +Usually this means the macro was only invoked conditionally." >&5 +echo "$as_me: error: conditional \"USE_LUA\" was never defined. +Usually this means the macro was only invoked conditionally." >&2;} + { (exit 1); exit 1; }; } +fi if test -z "${am__fastdepCC_TRUE}" && test -z "${am__fastdepCC_FALSE}"; then { { echo "$as_me:$LINENO: error: conditional \"am__fastdepCC\" was never defined. Usually this means the macro was only invoked conditionally." >&5 @@ -29185,7 +29725,7 @@ _ASBOX } >&5 cat >&5 <<_CSEOF -This file was extended by sysbench $as_me 0.4.8, which was +This file was extended by sysbench $as_me 0.5, which was generated by GNU Autoconf 2.59. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -29248,7 +29788,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF ac_cs_version="\\ -sysbench config.status 0.4.8 +sysbench config.status 0.5 configured by $0, generated by GNU Autoconf 2.59, with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\" @@ -29374,6 +29914,7 @@ do "sysbench/tests/threads/Makefile" ) CONFIG_FILES="$CONFIG_FILES sysbench/tests/threads/Makefile" ;; "sysbench/tests/mutex/Makefile" ) CONFIG_FILES="$CONFIG_FILES sysbench/tests/mutex/Makefile" ;; "sysbench/tests/oltp/Makefile" ) CONFIG_FILES="$CONFIG_FILES sysbench/tests/oltp/Makefile" ;; + "sysbench/scripting/Makefile" ) CONFIG_FILES="$CONFIG_FILES sysbench/scripting/Makefile" ;; "depfiles" ) CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;; "config/config.h" ) CONFIG_HEADERS="$CONFIG_HEADERS config/config.h" ;; *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5 @@ -29495,6 +30036,7 @@ s,@am__leading_dot@,$am__leading_dot,;t t s,@AMTAR@,$AMTAR,;t t s,@am__tar@,$am__tar,;t t s,@am__untar@,$am__untar,;t t +s,@luaconfig@,$luaconfig,;t t s,@CC@,$CC,;t t s,@CFLAGS@,$CFLAGS,;t t s,@LDFLAGS@,$LDFLAGS,;t t @@ -29511,6 +30053,10 @@ s,@AMDEPBACKSLASH@,$AMDEPBACKSLASH,;t t s,@CCDEPMODE@,$CCDEPMODE,;t t s,@am__fastdepCC_TRUE@,$am__fastdepCC_TRUE,;t t s,@am__fastdepCC_FALSE@,$am__fastdepCC_FALSE,;t t +s,@LUA_CPPFLAGS@,$LUA_CPPFLAGS,;t t +s,@LUA_LDFLAGS@,$LUA_LDFLAGS,;t t +s,@USE_LUA_TRUE@,$USE_LUA_TRUE,;t t +s,@USE_LUA_FALSE@,$USE_LUA_FALSE,;t t s,@EGREP@,$EGREP,;t t s,@LN_S@,$LN_S,;t t s,@ECHO@,$ECHO,;t t diff --git a/configure.ac b/configure.ac index fec66b7..a53b21f 100644 --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.57) -AC_INIT(sysbench, 0.4.8, alexeyk@mysql.com) +AC_INIT(sysbench, 0.5, alexeyk@mysql.com) AC_CONFIG_AUX_DIR([config]) AC_CANONICAL_TARGET AM_INIT_AUTOMAKE() @@ -31,6 +31,9 @@ AC_ARG_WITH([pgsql], ) AC_CACHE_CHECK([whether to compile with PostgreSQL support], [ac_cv_use_pgsql], [ac_cv_use_pgsql=yes]) +# Check if we should compile with Lua interpreter support +AC_LUA_DEVEL + # Check if we should enable large files support AC_ARG_ENABLE(largefile, AC_HELP_STRING([--enable-largefile],[enable large files support (default is enabled)]), , @@ -165,7 +168,7 @@ thr_setconcurrency \ valloc \ ]) -if test "$GCC" = "xyes"; then +if test "x$GCC" = "xyes"; then AM_CFLAGS="-W -Wall -Wpointer-arith -Wbad-function-cast \ -Wstrict-prototypes -Wnested-externs -Winline \ -funroll-loops" @@ -197,4 +200,5 @@ sysbench/tests/memory/Makefile sysbench/tests/threads/Makefile sysbench/tests/mutex/Makefile sysbench/tests/oltp/Makefile +sysbench/scripting/Makefile ]) diff --git a/doc/Makefile.in b/doc/Makefile.in index 4de194d..cf2f951 100644 --- a/doc/Makefile.in +++ b/doc/Makefile.in @@ -105,6 +105,8 @@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ +LUA_CPPFLAGS = @LUA_CPPFLAGS@ +LUA_LDFLAGS = @LUA_LDFLAGS@ MAKEINFO = @MAKEINFO@ MYSQL_CFLAGS = @MYSQL_CFLAGS@ MYSQL_LIBS = @MYSQL_LIBS@ @@ -129,6 +131,8 @@ SHELL = @SHELL@ STRIP = @STRIP@ USE_AIO_FALSE = @USE_AIO_FALSE@ USE_AIO_TRUE = @USE_AIO_TRUE@ +USE_LUA_FALSE = @USE_LUA_FALSE@ +USE_LUA_TRUE = @USE_LUA_TRUE@ USE_MYSQL_FALSE = @USE_MYSQL_FALSE@ USE_MYSQL_TRUE = @USE_MYSQL_TRUE@ USE_ORACLE_FALSE = @USE_ORACLE_FALSE@ @@ -176,6 +180,7 @@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localstatedir = @localstatedir@ +luaconfig = @luaconfig@ mandir = @mandir@ mkdir_p = @mkdir_p@ mysqlconfig = @mysqlconfig@ diff --git a/scripts/Makefile.in b/scripts/Makefile.in index 4c9be7f..4c04dd9 100644 --- a/scripts/Makefile.in +++ b/scripts/Makefile.in @@ -114,6 +114,8 @@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ +LUA_CPPFLAGS = @LUA_CPPFLAGS@ +LUA_LDFLAGS = @LUA_LDFLAGS@ MAKEINFO = @MAKEINFO@ MYSQL_CFLAGS = @MYSQL_CFLAGS@ MYSQL_LIBS = @MYSQL_LIBS@ @@ -138,6 +140,8 @@ SHELL = @SHELL@ STRIP = @STRIP@ USE_AIO_FALSE = @USE_AIO_FALSE@ USE_AIO_TRUE = @USE_AIO_TRUE@ +USE_LUA_FALSE = @USE_LUA_FALSE@ +USE_LUA_TRUE = @USE_LUA_TRUE@ USE_MYSQL_FALSE = @USE_MYSQL_FALSE@ USE_MYSQL_TRUE = @USE_MYSQL_TRUE@ USE_ORACLE_FALSE = @USE_ORACLE_FALSE@ @@ -185,6 +189,7 @@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localstatedir = @localstatedir@ +luaconfig = @luaconfig@ mandir = @mandir@ mkdir_p = @mkdir_p@ mysqlconfig = @mysqlconfig@ diff --git a/sysbench/Makefile.am b/sysbench/Makefile.am index 2b939c2..83b8c9d 100644 --- a/sysbench/Makefile.am +++ b/sysbench/Makefile.am @@ -14,7 +14,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -SUBDIRS = drivers tests . +SUBDIRS = drivers tests scripting . bin_PROGRAMS = sysbench @@ -32,11 +32,17 @@ if USE_PGSQL pgsql_ldadd = drivers/pgsql/libsbpgsql.a $(PGSQL_LIBS) endif +if USE_LUA +lua_ldflags = $(LUA_LDFLAGS) +endif + sysbench_SOURCES = sysbench.c sysbench.h sb_timer.c sb_timer.h \ sb_options.c sb_options.h sb_logger.c sb_logger.h sb_list.h db_driver.h \ db_driver.c sysbench_LDADD = tests/fileio/libsbfileio.a tests/threads/libsbthreads.a \ tests/memory/libsbmemory.a tests/cpu/libsbcpu.a tests/oltp/libsboltp.a \ - tests/mutex/libsbmutex.a $(mysql_ldadd) $(pgsql_ldadd) $(ora_ldadd) -sysbench_LDFLAGS = $(mysql_ldflags) $(pgsql_ldflags) $(ora_ldflags) + tests/mutex/libsbmutex.a scripting/libsbscript.a \ + $(mysql_ldadd) $(pgsql_ldadd) $(ora_ldadd) +sysbench_LDFLAGS = $(mysql_ldflags) $(pgsql_ldflags) $(ora_ldflags) \ + $(lua_ldflags) diff --git a/sysbench/Makefile.in b/sysbench/Makefile.in index fe4ba0a..d2f8b5e 100644 --- a/sysbench/Makefile.in +++ b/sysbench/Makefile.in @@ -82,8 +82,9 @@ am__DEPENDENCIES_1 = sysbench_DEPENDENCIES = tests/fileio/libsbfileio.a \ tests/threads/libsbthreads.a tests/memory/libsbmemory.a \ tests/cpu/libsbcpu.a tests/oltp/libsboltp.a \ - tests/mutex/libsbmutex.a $(am__DEPENDENCIES_2) \ - $(am__DEPENDENCIES_3) $(am__DEPENDENCIES_4) + tests/mutex/libsbmutex.a scripting/libsbscript.a \ + $(am__DEPENDENCIES_2) $(am__DEPENDENCIES_3) \ + $(am__DEPENDENCIES_4) DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/config depcomp = $(SHELL) $(top_srcdir)/config/depcomp am__depfiles_maybe = depfiles @@ -152,6 +153,8 @@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ +LUA_CPPFLAGS = @LUA_CPPFLAGS@ +LUA_LDFLAGS = @LUA_LDFLAGS@ MAKEINFO = @MAKEINFO@ MYSQL_CFLAGS = @MYSQL_CFLAGS@ MYSQL_LIBS = @MYSQL_LIBS@ @@ -176,6 +179,8 @@ SHELL = @SHELL@ STRIP = @STRIP@ USE_AIO_FALSE = @USE_AIO_FALSE@ USE_AIO_TRUE = @USE_AIO_TRUE@ +USE_LUA_FALSE = @USE_LUA_FALSE@ +USE_LUA_TRUE = @USE_LUA_TRUE@ USE_MYSQL_FALSE = @USE_MYSQL_FALSE@ USE_MYSQL_TRUE = @USE_MYSQL_TRUE@ USE_ORACLE_FALSE = @USE_ORACLE_FALSE@ @@ -223,6 +228,7 @@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localstatedir = @localstatedir@ +luaconfig = @luaconfig@ mandir = @mandir@ mkdir_p = @mkdir_p@ mysqlconfig = @mysqlconfig@ @@ -238,22 +244,26 @@ target_alias = @target_alias@ target_cpu = @target_cpu@ target_os = @target_os@ target_vendor = @target_vendor@ -SUBDIRS = drivers tests . +SUBDIRS = drivers tests scripting . # The following check will be extended as new database drivers will be added @USE_MYSQL_TRUE@mysql_ldadd = drivers/mysql/libsbmysql.a $(MYSQL_LIBS) @USE_MYSQL_TRUE@mysql_ldflags = -static @USE_ORACLE_TRUE@ora_ldadd = drivers/oracle/libsboracle.a $(ORA_LIBS) @USE_PGSQL_TRUE@pgsql_ldadd = drivers/pgsql/libsbpgsql.a $(PGSQL_LIBS) +@USE_LUA_TRUE@lua_ldflags = $(LUA_LDFLAGS) sysbench_SOURCES = sysbench.c sysbench.h sb_timer.c sb_timer.h \ sb_options.c sb_options.h sb_logger.c sb_logger.h sb_list.h db_driver.h \ db_driver.c sysbench_LDADD = tests/fileio/libsbfileio.a tests/threads/libsbthreads.a \ tests/memory/libsbmemory.a tests/cpu/libsbcpu.a tests/oltp/libsboltp.a \ - tests/mutex/libsbmutex.a $(mysql_ldadd) $(pgsql_ldadd) $(ora_ldadd) + tests/mutex/libsbmutex.a scripting/libsbscript.a \ + $(mysql_ldadd) $(pgsql_ldadd) $(ora_ldadd) + +sysbench_LDFLAGS = $(mysql_ldflags) $(pgsql_ldflags) $(ora_ldflags) \ + $(lua_ldflags) -sysbench_LDFLAGS = $(mysql_ldflags) $(pgsql_ldflags) $(ora_ldflags) all: all-recursive .SUFFIXES: diff --git a/sysbench/db_driver.c b/sysbench/db_driver.c index e450b14..5a4ce66 100644 --- a/sysbench/db_driver.c +++ b/sysbench/db_driver.c @@ -22,6 +22,11 @@ #include "db_driver.h" #include "sb_list.h" +/* How many rows to insert in a single query (used in bulk insert operations) */ +#define INSERT_ROWS 10000 + +/* How many rows to insert before COMMITs (used in bulk insert) */ +#define ROWS_BEFORE_COMMIT 1000 /* Global variables */ @@ -49,8 +54,8 @@ int register_driver_pgsql(sb_list_t *); /* Static functions */ static int db_parse_arguments(void); -db_error_t db_do_query(db_conn_t *, const char *, db_result_set_t *); static void db_free_row(db_row_t *); +static int db_bulk_do_insert(db_conn_t *, int); /* DB layer arguments */ @@ -534,6 +539,12 @@ int db_print_value(db_bind_t *var, char *buf, int buflen) { int n; db_time_t *tm; + + if (var->is_null != NULL && *var->is_null) + { + n = snprintf(buf, buflen, "NULL"); + return (n < buflen) ? n : -1; + } switch (var->type) { case DB_TYPE_TINYINT: @@ -589,3 +600,119 @@ void db_free_row(db_row_t *row) { free(row); } + + +/* Initialize multi-row insert operation */ + + +int db_bulk_insert_init(db_conn_t *con, const char *query) +{ + drv_caps_t driver_caps; + unsigned int query_len; + + if (con->driver == NULL) + return 1; + + /* Get database capabilites */ + if (db_describe(con->driver, &driver_caps, NULL)) + { + log_text(LOG_FATAL, "failed to get database capabilities!"); + return 1; + } + + /* Allocate initial query buffer (will be expanded later if needed) */ + query_len = strlen(query); + con->bulk_max_rows = driver_caps.multi_rows_insert ? INSERT_ROWS : 1; + con->bulk_commit_max = driver_caps.needs_commit ? ROWS_BEFORE_COMMIT : 0; + con->bulk_commit_cnt = 0; + con->bulk_buflen = query_len + con->bulk_max_rows * 80 + 1; + con->bulk_buffer = (char *)malloc(con->bulk_buflen); + if (con->bulk_buffer == NULL) + return 1; + strcpy(con->bulk_buffer, query); + con->bulk_ptr = query_len; + con->bulk_ptr_orig = query_len; + con->bulk_cnt = 0; + con->bulk_not_first = 0; + + return 0; +} + +/* Add row to multi-row insert operation */ + +int db_bulk_insert_next(db_conn_t *con, const char *query) +{ + unsigned int query_len = strlen(query); + + /* + Reserve space for '\0' and ',' (if not the first chunk in + a bulk insert + */ + while (con->bulk_ptr + query_len + 1 + con->bulk_not_first > con->bulk_buflen) + { + con->bulk_buffer = (char *)realloc(con->bulk_buffer, con->bulk_buflen * 2); + if (con->bulk_buffer == NULL) + return 1; + con->bulk_buflen *= 2; + } + + if (con->bulk_not_first) + { + con->bulk_buffer[con->bulk_ptr] = ','; + strcpy(con->bulk_buffer + con->bulk_ptr + 1, query); + } + else + strcpy(con->bulk_buffer + con->bulk_ptr, query); + con->bulk_ptr += query_len + con->bulk_not_first; + + con->bulk_not_first = 1; + + con->bulk_cnt++; + if (con->bulk_cnt == con->bulk_max_rows && db_bulk_do_insert(con, 0)) + return 1; + + return 0; +} + +/* Do the actual INSERT (and COMMIT, if necessary) */ + +int db_bulk_do_insert(db_conn_t *con, int is_last) +{ + if (con->bulk_not_first == 0) + return 0; + + if (db_query(con, con->bulk_buffer) == NULL) + return 1; + + con->bulk_not_first = 0; + con->bulk_ptr = con->bulk_ptr_orig; + con->bulk_cnt = 0; + + if (con->bulk_commit_max != 0) + { + con->bulk_commit_cnt += con->bulk_max_rows; + + if (is_last || con->bulk_commit_cnt >= con->bulk_commit_max) + { + if (db_query(con, "COMMIT") == NULL) + return 1; + con->bulk_commit_cnt = 0; + } + } + + return 0; +} + +/* Finish multi-row insert operation */ + +void db_bulk_insert_done(db_conn_t *con) +{ + /* Flush remaining data in buffer, if any */ + db_bulk_do_insert(con, 1); + + if (con->bulk_buffer != NULL) + { + free(con->bulk_buffer); + con->bulk_buffer = NULL; + } +} diff --git a/sysbench/db_driver.h b/sysbench/db_driver.h index aba433d..d9e6934 100644 --- a/sysbench/db_driver.h +++ b/sysbench/db_driver.h @@ -184,10 +184,21 @@ typedef enum { typedef struct db_conn { - db_driver_t *driver; /* DB driver for this connection */ + db_driver_t *driver; /* DB driver for this connection */ db_conn_type_t type; void *ptr; db_error_t db_errno; + + /* Internal fields */ + unsigned int bulk_cnt; /* Current number of rows in bulk insert buffer */ + unsigned int bulk_max_rows; /* Maximum number of rows in bulk insert buffer */ + char * bulk_buffer; /* Bulk insert query buffer */ + unsigned int bulk_buflen; /* Current length of bulk_buffer */ + unsigned int bulk_ptr; /* Current position in bulk_buffer */ + unsigned int bulk_ptr_orig; /* Save value of bulk_ptr */ + unsigned int bulk_not_first; /* Indicates if bulk insert buffer has some rows */ + unsigned int bulk_commit_cnt; /* Current value of uncommitted rows */ + unsigned int bulk_commit_max; /* Maximum value of uncommitted rows */ } db_conn_t; /* Prepared statement definition */ @@ -262,4 +273,13 @@ db_error_t db_errno(db_conn_t *); int db_print_value(db_bind_t *, char *, int); +/* Initialize multi-row insert operation */ +int db_bulk_insert_init(db_conn_t *, const char *); + +/* Add row to multi-row insert operation */ +int db_bulk_insert_next(db_conn_t *, const char *); + +/* Finish multi-row insert operation */ +void db_bulk_insert_done(db_conn_t *); + #endif /* DB_DRIVER_H */ diff --git a/sysbench/drivers/Makefile.in b/sysbench/drivers/Makefile.in index 359c3c3..82ac1c0 100644 --- a/sysbench/drivers/Makefile.in +++ b/sysbench/drivers/Makefile.in @@ -119,6 +119,8 @@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ +LUA_CPPFLAGS = @LUA_CPPFLAGS@ +LUA_LDFLAGS = @LUA_LDFLAGS@ MAKEINFO = @MAKEINFO@ MYSQL_CFLAGS = @MYSQL_CFLAGS@ MYSQL_LIBS = @MYSQL_LIBS@ @@ -143,6 +145,8 @@ SHELL = @SHELL@ STRIP = @STRIP@ USE_AIO_FALSE = @USE_AIO_FALSE@ USE_AIO_TRUE = @USE_AIO_TRUE@ +USE_LUA_FALSE = @USE_LUA_FALSE@ +USE_LUA_TRUE = @USE_LUA_TRUE@ USE_MYSQL_FALSE = @USE_MYSQL_FALSE@ USE_MYSQL_TRUE = @USE_MYSQL_TRUE@ USE_ORACLE_FALSE = @USE_ORACLE_FALSE@ @@ -190,6 +194,7 @@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localstatedir = @localstatedir@ +luaconfig = @luaconfig@ mandir = @mandir@ mkdir_p = @mkdir_p@ mysqlconfig = @mysqlconfig@ diff --git a/sysbench/drivers/mysql/Makefile.in b/sysbench/drivers/mysql/Makefile.in index 8e82c31..0382a92 100644 --- a/sysbench/drivers/mysql/Makefile.in +++ b/sysbench/drivers/mysql/Makefile.in @@ -132,6 +132,8 @@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ +LUA_CPPFLAGS = @LUA_CPPFLAGS@ +LUA_LDFLAGS = @LUA_LDFLAGS@ MAKEINFO = @MAKEINFO@ MYSQL_CFLAGS = @MYSQL_CFLAGS@ MYSQL_LIBS = @MYSQL_LIBS@ @@ -156,6 +158,8 @@ SHELL = @SHELL@ STRIP = @STRIP@ USE_AIO_FALSE = @USE_AIO_FALSE@ USE_AIO_TRUE = @USE_AIO_TRUE@ +USE_LUA_FALSE = @USE_LUA_FALSE@ +USE_LUA_TRUE = @USE_LUA_TRUE@ USE_MYSQL_FALSE = @USE_MYSQL_FALSE@ USE_MYSQL_TRUE = @USE_MYSQL_TRUE@ USE_ORACLE_FALSE = @USE_ORACLE_FALSE@ @@ -203,6 +207,7 @@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localstatedir = @localstatedir@ +luaconfig = @luaconfig@ mandir = @mandir@ mkdir_p = @mkdir_p@ mysqlconfig = @mysqlconfig@ diff --git a/sysbench/drivers/mysql/drv_mysql.c b/sysbench/drivers/mysql/drv_mysql.c index 6ac07ac..1480310 100644 --- a/sysbench/drivers/mysql/drv_mysql.c +++ b/sysbench/drivers/mysql/drv_mysql.c @@ -515,8 +515,10 @@ int mysql_drv_bind_param(db_stmt_t *stmt, db_bind_t *params, unsigned int len) rc = mysql_stmt_param_count(stmt->ptr); DEBUG("mysql_stmt_param_count(%p) = %u", stmt->ptr, rc); if (rc != len) + { + log_text(LOG_FATAL, "Wrong number of parameters to mysql_stmt_bind_param"); return 1; - + } /* Convert SysBench bind structures to MySQL ones */ bind = (MYSQL_BIND *)calloc(len, sizeof(MYSQL_BIND)); if (bind == NULL) diff --git a/sysbench/drivers/oracle/Makefile.in b/sysbench/drivers/oracle/Makefile.in index d776f81..71ff62e 100644 --- a/sysbench/drivers/oracle/Makefile.in +++ b/sysbench/drivers/oracle/Makefile.in @@ -132,6 +132,8 @@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ +LUA_CPPFLAGS = @LUA_CPPFLAGS@ +LUA_LDFLAGS = @LUA_LDFLAGS@ MAKEINFO = @MAKEINFO@ MYSQL_CFLAGS = @MYSQL_CFLAGS@ MYSQL_LIBS = @MYSQL_LIBS@ @@ -156,6 +158,8 @@ SHELL = @SHELL@ STRIP = @STRIP@ USE_AIO_FALSE = @USE_AIO_FALSE@ USE_AIO_TRUE = @USE_AIO_TRUE@ +USE_LUA_FALSE = @USE_LUA_FALSE@ +USE_LUA_TRUE = @USE_LUA_TRUE@ USE_MYSQL_FALSE = @USE_MYSQL_FALSE@ USE_MYSQL_TRUE = @USE_MYSQL_TRUE@ USE_ORACLE_FALSE = @USE_ORACLE_FALSE@ @@ -203,6 +207,7 @@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localstatedir = @localstatedir@ +luaconfig = @luaconfig@ mandir = @mandir@ mkdir_p = @mkdir_p@ mysqlconfig = @mysqlconfig@ diff --git a/sysbench/drivers/pgsql/Makefile.in b/sysbench/drivers/pgsql/Makefile.in index 21c91ab..f10820b 100644 --- a/sysbench/drivers/pgsql/Makefile.in +++ b/sysbench/drivers/pgsql/Makefile.in @@ -132,6 +132,8 @@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ +LUA_CPPFLAGS = @LUA_CPPFLAGS@ +LUA_LDFLAGS = @LUA_LDFLAGS@ MAKEINFO = @MAKEINFO@ MYSQL_CFLAGS = @MYSQL_CFLAGS@ MYSQL_LIBS = @MYSQL_LIBS@ @@ -156,6 +158,8 @@ SHELL = @SHELL@ STRIP = @STRIP@ USE_AIO_FALSE = @USE_AIO_FALSE@ USE_AIO_TRUE = @USE_AIO_TRUE@ +USE_LUA_FALSE = @USE_LUA_FALSE@ +USE_LUA_TRUE = @USE_LUA_TRUE@ USE_MYSQL_FALSE = @USE_MYSQL_FALSE@ USE_MYSQL_TRUE = @USE_MYSQL_TRUE@ USE_ORACLE_FALSE = @USE_ORACLE_FALSE@ @@ -203,6 +207,7 @@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localstatedir = @localstatedir@ +luaconfig = @luaconfig@ mandir = @mandir@ mkdir_p = @mkdir_p@ mysqlconfig = @mysqlconfig@ diff --git a/sysbench/sb_list.h b/sysbench/sb_list.h index 02a8210..00d0926 100644 --- a/sysbench/sb_list.h +++ b/sysbench/sb_list.h @@ -96,7 +96,13 @@ struct sb_list_item ((type *)((char *)(ptr) - offsetof(type, member))) #define SB_LIST_FOR_EACH(pos_p, head_p) \ - for (pos_p = (head_p)->next_p; pos_p != (head_p); pos_p = pos_p->next_p) + for (pos_p = (head_p)->next_p; pos_p != (head_p); pos_p = pos_p->next_p) + +#define SB_LIST_ENUM_START(head_p) \ + (head_p) + +#define SB_LIST_ENUM_NEXT(pos_p, head_p) \ + ((pos_p->next_p != (head_p)) ? (pos_p->next_p) : NULL) #define SB_LIST_FOR_EACH_SAFE(pos_p, temp_p, head_p) \ for (pos_p = (head_p)->next_p, temp_p = (pos_p)->next_p; pos_p != (head_p); \ diff --git a/sysbench/sb_options.c b/sysbench/sb_options.c index f06a679..bcdaa49 100644 --- a/sysbench/sb_options.c +++ b/sysbench/sb_options.c @@ -40,6 +40,15 @@ static sb_list_t options; /* List of size modifiers (kilo, mega, giga, tera) */ static const char sizemods[] = "KMGT"; +/* Convert dashes to underscores in option names */ + +static void convert_dashes(char *); + +/* Compare option names */ + +static int opt_name_cmp(const char *, const char *); + + /* Initialize options library */ @@ -157,6 +166,12 @@ void sb_print_options(sb_arg_t *opts) } +int sb_opt_to_flag(option_t *opt) +{ + return !SB_LIST_IS_EMPTY(&opt->values); +} + + int sb_get_value_flag(char *name) { option_t *opt; @@ -165,20 +180,15 @@ int sb_get_value_flag(char *name) if (opt == NULL) return 0; - return !SB_LIST_IS_EMPTY(&opt->values); + return sb_opt_to_flag(opt); } -int sb_get_value_int(char *name) +int sb_opt_to_int(option_t *opt) { - option_t *opt; value_t *val; sb_list_item_t *pos; - opt = find_option(&options, name); - if (opt == NULL) - return 0; - SB_LIST_FOR_EACH(pos, &opt->values) { val = SB_LIST_ENTRY(pos, value_t, listitem); @@ -186,12 +196,22 @@ int sb_get_value_int(char *name) } return 0; +} + +int sb_get_value_int(char *name) +{ + option_t *opt; + + opt = find_option(&options, name); + if (opt == NULL) + return 0; + + return sb_opt_to_int(opt); } -unsigned long long sb_get_value_size(char *name) +unsigned long long sb_opt_to_size(option_t *opt) { - option_t *opt; value_t *val; sb_list_item_t *pos; unsigned long long res = 0; @@ -200,16 +220,12 @@ unsigned long long sb_get_value_size(char *name) unsigned int i, n; char *c; - opt = find_option(&options, name); - if (opt == NULL) - return 0; - SB_LIST_FOR_EACH(pos, &opt->values) { val = SB_LIST_ENTRY(pos, value_t, listitem); /* * Reimplentation of sscanf(val->data, "%llu%c", &res, &mult), since - * there is little standartization about how to specify long long values + * there is no standard on how to specify long long values */ res = 0; for (rc = 0, c = val->data; *c != '\0'; c++) @@ -227,7 +243,8 @@ unsigned long long sb_get_value_size(char *name) res = res * 10 + *c - '0'; } - if (rc == 2) { + if (rc == 2) + { for (n = 0; sizemods[n] != '\0'; n++) if (mult == sizemods[n]) break; @@ -246,17 +263,24 @@ unsigned long long sb_get_value_size(char *name) } -float sb_get_value_float(char *name) +unsigned long long sb_get_value_size(char *name) { - option_t *opt; - value_t *val; - sb_list_item_t *pos; - float res; - + option_t *opt; + opt = find_option(&options, name); if (opt == NULL) return 0; + return sb_opt_to_size(opt); +} + + +float sb_opt_to_float(option_t *opt) +{ + value_t *val; + sb_list_item_t *pos; + float res; + SB_LIST_FOR_EACH(pos, &opt->values) { val = SB_LIST_ENTRY(pos, value_t, listitem); @@ -268,15 +292,22 @@ float sb_get_value_float(char *name) } -char *sb_get_value_string(char *name) +float sb_get_value_float(char *name) { option_t *opt; - value_t *val; - sb_list_item_t *pos; opt = find_option(&options, name); if (opt == NULL) - return NULL; + return 0; + + return sb_opt_to_float(opt); +} + + +char *sb_opt_to_string(option_t *opt) +{ + value_t *val; + sb_list_item_t *pos; SB_LIST_FOR_EACH(pos, &opt->values) { @@ -288,6 +319,24 @@ char *sb_get_value_string(char *name) } +char *sb_get_value_string(char *name) +{ + option_t *opt; + + opt = find_option(&options, name); + if (opt == NULL) + return NULL; + + return sb_opt_to_string(opt); +} + + +sb_list_t *sb_opt_to_list(option_t *opt) +{ + return &opt->values; +} + + sb_list_t *sb_get_value_list(char *name) { option_t *opt; @@ -296,7 +345,7 @@ sb_list_t *sb_get_value_list(char *name) if (opt == NULL) return NULL; - return &opt->values; + return sb_opt_to_list(opt); } @@ -476,6 +525,7 @@ option_t *add_option(sb_list_t *options, char *name) return NULL; option->name = strdup(name); + convert_dashes(option->name); SB_LIST_ADD_TAIL(&option->listitem, options); @@ -483,6 +533,32 @@ option_t *add_option(sb_list_t *options, char *name) } +void convert_dashes(char *s) +{ + while (*s != '\0') + { + if (*s == '-') + *s = '_'; + s++; + } +} + + +int opt_name_cmp(const char *s1, const char *s2) +{ + for (/* empty */; *s1 != '\0'; s1++, s2++) + { + if (*s1 == *s2) + continue; + + if ((*s1 != '-' && *s1 != '_') || (*s2 != '-' && *s2 != '_')) + break; + } + + return *s1 - *s2; +} + + option_t *find_option(sb_list_t *options, char *name) { sb_list_item_t *pos; @@ -494,7 +570,7 @@ option_t *find_option(sb_list_t *options, char *name) SB_LIST_FOR_EACH(pos, options) { opt = SB_LIST_ENTRY(pos, option_t, listitem); - if (!strcmp(opt->name, name)) + if (!opt_name_cmp(opt->name, name)) return opt; } @@ -502,6 +578,23 @@ option_t *find_option(sb_list_t *options, char *name) } +sb_list_item_t *sb_options_enum_start(void) +{ + return SB_LIST_ENUM_START(&options); +} + +sb_list_item_t *sb_options_enum_next(sb_list_item_t *pos, option_t **opt) +{ + pos = SB_LIST_ENUM_NEXT(pos, &options); + if (pos == NULL) + return NULL; + + *opt = SB_LIST_ENTRY(pos, option_t, listitem); + + return pos; +} + + sb_list_t *read_config(FILE *fp, sb_list_t *options) { char buf[MAXSTRLEN]; diff --git a/sysbench/sb_options.h b/sysbench/sb_options.h index bd794c4..0ca6f7f 100644 --- a/sysbench/sb_options.h +++ b/sysbench/sb_options.h @@ -94,9 +94,25 @@ float sb_get_value_float(char *name); char *sb_get_value_string(char *name); +sb_list_t *sb_get_value_list(char *name); + char *sb_print_value_size(char *buf, unsigned int buflen, double value); -sb_list_t *sb_get_value_list(char *name); +int sb_opt_to_flag(option_t *); + +int sb_opt_to_int(option_t *); + +unsigned long long sb_opt_to_size(option_t *); + +float sb_opt_to_float(option_t *); + +char *sb_opt_to_string(option_t *); + +sb_list_t *sb_opt_to_list(option_t *); + +sb_list_item_t *sb_options_enum_start(void); + +sb_list_item_t *sb_options_enum_next(sb_list_item_t *, option_t **); value_t *new_value(void); diff --git a/sysbench/scripting/Makefile.am b/sysbench/scripting/Makefile.am new file mode 100644 index 0000000..fd5f870 --- /dev/null +++ b/sysbench/scripting/Makefile.am @@ -0,0 +1,26 @@ +# Copyright (C) 2006 MySQL AB +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +if USE_LUA +lua_sources = script_lua.c script_lua.h +endif + +noinst_LIBRARIES = libsbscript.a + +libsbscript_a_SOURCES = sb_script.c ../sb_script.h $(lua_sources) + +libsbscript_a_CPPFLAGS = -I.. $(AM_CPPFLAGS) $(LUA_CPPFLAGS) + diff --git a/sysbench/scripting/Makefile.in b/sysbench/scripting/Makefile.in new file mode 100644 index 0000000..7e2fa4f --- /dev/null +++ b/sysbench/scripting/Makefile.in @@ -0,0 +1,511 @@ +# Makefile.in generated by automake 1.9.5 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +# Copyright (C) 2006 MySQL AB +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +SOURCES = $(libsbscript_a_SOURCES) + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = ../.. +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +subdir = sysbench/scripting +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/config/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/config/config.h +CONFIG_CLEAN_FILES = +LIBRARIES = $(noinst_LIBRARIES) +ARFLAGS = cru +libsbscript_a_AR = $(AR) $(ARFLAGS) +libsbscript_a_LIBADD = +am__libsbscript_a_SOURCES_DIST = sb_script.c ../sb_script.h \ + script_lua.c script_lua.h +@USE_LUA_TRUE@am__objects_1 = libsbscript_a-script_lua.$(OBJEXT) +am_libsbscript_a_OBJECTS = libsbscript_a-sb_script.$(OBJEXT) \ + $(am__objects_1) +libsbscript_a_OBJECTS = $(am_libsbscript_a_OBJECTS) +DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/config +depcomp = $(SHELL) $(top_srcdir)/config/depcomp +am__depfiles_maybe = depfiles +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +SOURCES = $(libsbscript_a_SOURCES) +DIST_SOURCES = $(am__libsbscript_a_SOURCES_DIST) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMDEP_FALSE = @AMDEP_FALSE@ +AMDEP_TRUE = @AMDEP_TRUE@ +AMTAR = @AMTAR@ +AM_CFLAGS = @AM_CFLAGS@ +AM_CPPFLAGS = @AM_CPPFLAGS@ +AM_LDFLAGS = @AM_LDFLAGS@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CAT_ENTRY_END = @CAT_ENTRY_END@ +CAT_ENTRY_START = @CAT_ENTRY_START@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DOCBOOK_ROOT = @DOCBOOK_ROOT@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +LUA_CPPFLAGS = @LUA_CPPFLAGS@ +LUA_LDFLAGS = @LUA_LDFLAGS@ +MAKEINFO = @MAKEINFO@ +MYSQL_CFLAGS = @MYSQL_CFLAGS@ +MYSQL_LIBS = @MYSQL_LIBS@ +OBJEXT = @OBJEXT@ +ORA_CFLAGS = @ORA_CFLAGS@ +ORA_LIBS = @ORA_LIBS@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PGSQL_CFLAGS = @PGSQL_CFLAGS@ +PGSQL_LIBS = @PGSQL_LIBS@ +PTHREAD_CC = @PTHREAD_CC@ +PTHREAD_CFLAGS = @PTHREAD_CFLAGS@ +PTHREAD_LIBS = @PTHREAD_LIBS@ +RANLIB = @RANLIB@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +USE_AIO_FALSE = @USE_AIO_FALSE@ +USE_AIO_TRUE = @USE_AIO_TRUE@ +USE_LUA_FALSE = @USE_LUA_FALSE@ +USE_LUA_TRUE = @USE_LUA_TRUE@ +USE_MYSQL_FALSE = @USE_MYSQL_FALSE@ +USE_MYSQL_TRUE = @USE_MYSQL_TRUE@ +USE_ORACLE_FALSE = @USE_ORACLE_FALSE@ +USE_ORACLE_TRUE = @USE_ORACLE_TRUE@ +USE_PGSQL_FALSE = @USE_PGSQL_FALSE@ +USE_PGSQL_TRUE = @USE_PGSQL_TRUE@ +VERSION = @VERSION@ +XML_CATALOG = @XML_CATALOG@ +XSLTPROC = @XSLTPROC@ +XSLTPROC_FLAGS = @XSLTPROC_FLAGS@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_F77 = @ac_ct_F77@ +ac_ct_RANLIB = @ac_ct_RANLIB@ +ac_ct_STRIP = @ac_ct_STRIP@ +acx_pthread_config = @acx_pthread_config@ +am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ +am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ +am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@ +am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +datadir = @datadir@ +exec_prefix = @exec_prefix@ +have_xsltproc_FALSE = @have_xsltproc_FALSE@ +have_xsltproc_TRUE = @have_xsltproc_TRUE@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localstatedir = @localstatedir@ +luaconfig = @luaconfig@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +mysqlconfig = @mysqlconfig@ +oldincludedir = @oldincludedir@ +pgconfig = @pgconfig@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +@USE_LUA_TRUE@lua_sources = script_lua.c script_lua.h +noinst_LIBRARIES = libsbscript.a +libsbscript_a_SOURCES = sb_script.c ../sb_script.h $(lua_sources) +libsbscript_a_CPPFLAGS = -I.. $(AM_CPPFLAGS) $(LUA_CPPFLAGS) +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign sysbench/scripting/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --foreign sysbench/scripting/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +clean-noinstLIBRARIES: + -test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES) +libsbscript.a: $(libsbscript_a_OBJECTS) $(libsbscript_a_DEPENDENCIES) + -rm -f libsbscript.a + $(libsbscript_a_AR) libsbscript.a $(libsbscript_a_OBJECTS) $(libsbscript_a_LIBADD) + $(RANLIB) libsbscript.a + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsbscript_a-sb_script.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsbscript_a-script_lua.Po@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ if $(LTCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +libsbscript_a-sb_script.o: sb_script.c +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsbscript_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libsbscript_a-sb_script.o -MD -MP -MF "$(DEPDIR)/libsbscript_a-sb_script.Tpo" -c -o libsbscript_a-sb_script.o `test -f 'sb_script.c' || echo '$(srcdir)/'`sb_script.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libsbscript_a-sb_script.Tpo" "$(DEPDIR)/libsbscript_a-sb_script.Po"; else rm -f "$(DEPDIR)/libsbscript_a-sb_script.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='sb_script.c' object='libsbscript_a-sb_script.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsbscript_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libsbscript_a-sb_script.o `test -f 'sb_script.c' || echo '$(srcdir)/'`sb_script.c + +libsbscript_a-sb_script.obj: sb_script.c +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsbscript_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libsbscript_a-sb_script.obj -MD -MP -MF "$(DEPDIR)/libsbscript_a-sb_script.Tpo" -c -o libsbscript_a-sb_script.obj `if test -f 'sb_script.c'; then $(CYGPATH_W) 'sb_script.c'; else $(CYGPATH_W) '$(srcdir)/sb_script.c'; fi`; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libsbscript_a-sb_script.Tpo" "$(DEPDIR)/libsbscript_a-sb_script.Po"; else rm -f "$(DEPDIR)/libsbscript_a-sb_script.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='sb_script.c' object='libsbscript_a-sb_script.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsbscript_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libsbscript_a-sb_script.obj `if test -f 'sb_script.c'; then $(CYGPATH_W) 'sb_script.c'; else $(CYGPATH_W) '$(srcdir)/sb_script.c'; fi` + +libsbscript_a-script_lua.o: script_lua.c +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsbscript_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libsbscript_a-script_lua.o -MD -MP -MF "$(DEPDIR)/libsbscript_a-script_lua.Tpo" -c -o libsbscript_a-script_lua.o `test -f 'script_lua.c' || echo '$(srcdir)/'`script_lua.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libsbscript_a-script_lua.Tpo" "$(DEPDIR)/libsbscript_a-script_lua.Po"; else rm -f "$(DEPDIR)/libsbscript_a-script_lua.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='script_lua.c' object='libsbscript_a-script_lua.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsbscript_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libsbscript_a-script_lua.o `test -f 'script_lua.c' || echo '$(srcdir)/'`script_lua.c + +libsbscript_a-script_lua.obj: script_lua.c +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsbscript_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libsbscript_a-script_lua.obj -MD -MP -MF "$(DEPDIR)/libsbscript_a-script_lua.Tpo" -c -o libsbscript_a-script_lua.obj `if test -f 'script_lua.c'; then $(CYGPATH_W) 'script_lua.c'; else $(CYGPATH_W) '$(srcdir)/script_lua.c'; fi`; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libsbscript_a-script_lua.Tpo" "$(DEPDIR)/libsbscript_a-script_lua.Po"; else rm -f "$(DEPDIR)/libsbscript_a-script_lua.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='script_lua.c' object='libsbscript_a-script_lua.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsbscript_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libsbscript_a-script_lua.obj `if test -f 'script_lua.c'; then $(CYGPATH_W) 'script_lua.c'; else $(CYGPATH_W) '$(srcdir)/script_lua.c'; fi` + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + -rm -f libtool +uninstall-info-am: + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ + list='$(DISTFILES)'; for file in $$list; do \ + case $$file in \ + $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ + $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ + esac; \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + dir="/$$dir"; \ + $(mkdir_p) "$(distdir)$$dir"; \ + else \ + dir=''; \ + fi; \ + if test -d $$d/$$file; then \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LIBRARIES) +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-noinstLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-libtool distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: + +install-exec-am: + +install-info: install-info-am + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-info-am + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-noinstLIBRARIES ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-data install-data-am install-exec \ + install-exec-am install-info install-info-am install-man \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ + pdf pdf-am ps ps-am tags uninstall uninstall-am \ + uninstall-info-am + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/sysbench/scripting/sb_script.c b/sysbench/scripting/sb_script.c new file mode 100644 index 0000000..8dd8fb7 --- /dev/null +++ b/sysbench/scripting/sb_script.c @@ -0,0 +1,42 @@ +/* Copyright (C) 2006 MySQL AB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "sb_script.h" + +#ifdef HAVE_LUA +# include "script_lua.h" +#endif + +static sb_test_t test; + +/* Initialize interpreter with a given script name */ + +sb_test_t *script_load(const char *testname) +{ + test.sname = strdup(testname); + +#ifdef HAVE_LUA + if (!script_load_lua(testname, &test)) + return &test; +#endif + + return NULL; +} diff --git a/sysbench/scripting/sb_script.h b/sysbench/scripting/sb_script.h new file mode 100644 index 0000000..73c6597 --- /dev/null +++ b/sysbench/scripting/sb_script.h @@ -0,0 +1,31 @@ +/* Copyright (C) 2006 MySQL AB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef SB_SCRIPT_H +#define SB_SCRIPT_H + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "sysbench.h" + +/* Initialize interpreter with a given script name */ + +sb_test_t *script_load(const char *testname); + +#endif /* SB_SCRIPT_H */ diff --git a/sysbench/scripting/script_lua.c b/sysbench/scripting/script_lua.c new file mode 100644 index 0000000..3371c53 --- /dev/null +++ b/sysbench/scripting/script_lua.c @@ -0,0 +1,886 @@ +/* Copyright (C) 2006 MySQL AB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "lua.h" +#include "lualib.h" +#include "lauxlib.h" + +#include "sb_script.h" + +#include "db_driver.h" + +#define EVENT_FUNC "event" +#define PREPARE_FUNC "prepare" +#define CLEANUP_FUNC "cleanup" +#define THREAD_INIT_FUNC "thread_init" +#define THREAD_DONE_FUNC "thread_done" + +/* Macros to call Lua functions */ +#define CALL_ERROR(L, name) \ + do { \ + log_text(LOG_FATAL, "failed to execute function `%s': %s", \ + name, lua_tostring(L, -1)); \ + } while (0) + +/* Interpreter context */ + +typedef struct { + db_conn_t *con; /* Database connection */ +} sb_lua_ctxt_t; + +typedef struct { + int id; + db_bind_type_t type; + void *buf; + unsigned long *buflen; + char is_null; +} sb_lua_bind_t; + +typedef struct { + db_stmt_t *ptr; + sb_lua_bind_t *params; + unsigned int nparams; + int ref; +} sb_lua_db_stmt_t; + +typedef struct { + db_result_set_t *ptr; +} sb_lua_db_rs_t; + +/* Lua interpreter states */ + +static lua_State **states; + +/* Event counter */ +static unsigned int nevents; + +/* Lua test operations */ + +static int sb_lua_init(void); +static int sb_lua_done(void); +static sb_request_t sb_lua_get_request(void); +static int sb_lua_op_execute_request(sb_request_t *, int); +static int sb_lua_op_thread_init(int); +static int sb_lua_op_thread_done(int); + + +static sb_operations_t lua_ops = { + .init = &sb_lua_init, + .get_request = &sb_lua_get_request, + .execute_request = &sb_lua_op_execute_request, + .done = &sb_lua_done +}; + +/* Main (global) interpreter state */ +lua_State *gstate; + +/* Database driver */ +db_driver_t *db_driver; +const char *db_driver_name; + +/* Variable with unique address to store per-state data */ +static const char sb_lua_ctxt_key; + +/* Lua test commands */ +static int sb_lua_cmd_prepare(void); +static int sb_lua_cmd_cleanup(void); + +/* Initialize interpreter state */ +static lua_State *sb_lua_new_state(const char *); + +/* Close interpretet state */ +static int sb_lua_close_state(lua_State *); + +/* Exported C functions */ +static int sb_lua_db_connect(lua_State *); +static int sb_lua_db_disconnect(lua_State *); +static int sb_lua_db_query(lua_State *); +static int sb_lua_db_bulk_insert_init(lua_State *); +static int sb_lua_db_bulk_insert_next(lua_State *); +static int sb_lua_db_bulk_insert_done(lua_State *); +static int sb_lua_db_prepare(lua_State *); +static int sb_lua_db_bind_param(lua_State *); +static int sb_lua_db_execute(lua_State *); +static int sb_lua_db_close(lua_State *); +static int sb_lua_db_store_results(lua_State *); +static int sb_lua_db_free_results(lua_State *); +static int sb_lua_rand(lua_State *); +static int sb_lua_rand_uniq(lua_State *); +static int sb_lua_rnd(lua_State *); + +/* Get a per-state interpreter context */ +static sb_lua_ctxt_t *sb_lua_get_context(lua_State *); + +/* Set a per-state interpreter context */ +void sb_lua_set_context(lua_State *, sb_lua_ctxt_t *); + +unsigned int sb_lua_table_size(lua_State *, int); + +/* Load a specified Lua script */ + +int script_load_lua(const char *testname, sb_test_t *test) +{ + unsigned int i; + + /* Initialize global interpreter state */ + gstate = sb_lua_new_state(testname); + if (gstate == NULL) + goto error; + + /* Test commands */ + lua_getglobal(gstate, PREPARE_FUNC); + if (!lua_isnil(gstate, -1)) + test->cmds.prepare = &sb_lua_cmd_prepare; + lua_pop(gstate, 1); + + lua_getglobal(gstate, CLEANUP_FUNC); + if (!lua_isnil(gstate, -1)) + test->cmds.cleanup = &sb_lua_cmd_cleanup; + + /* Test operations */ + test->ops = lua_ops; + + lua_getglobal(gstate, THREAD_INIT_FUNC); + if (!lua_isnil(gstate, -1)) + test->ops.thread_init = &sb_lua_op_thread_init; + + lua_getglobal(gstate, THREAD_DONE_FUNC); + if (!lua_isnil(gstate, -1)) + test->ops.thread_done = &sb_lua_op_thread_done; + + /* Initialize per-thread interpreters */ + states = (lua_State **)calloc(sb_globals.num_threads, sizeof(lua_State *)); + if (states == NULL) + goto error; + for (i = 0; i < sb_globals.num_threads; i++) + { + states[i] = sb_lua_new_state(testname); + if (states[i] == NULL) + goto error; + } + + return 0; + + error: + + sb_lua_close_state(gstate); + if (states != NULL) + { + for (i = 0; i < sb_globals.num_threads; i++) + sb_lua_close_state(states[i]); + free(states); + } + + return 1; +} + +/* Initialize Lua script */ + +int sb_lua_init(void) +{ + return 0; +} + +sb_request_t sb_lua_get_request(void) +{ + sb_request_t req; + + if (nevents >= sb_globals.max_requests) + { + req.type = SB_REQ_TYPE_NULL; + return req; + } + + req.type = SB_REQ_TYPE_SCRIPT; + nevents++; + + return req; +} + +int sb_lua_op_execute_request(sb_request_t *sb_req, int thread_id) +{ + double rc; + log_msg_t msg; + log_msg_oper_t op_msg; + + (void)sb_req; /* unused */ + + /* Prepare log message */ + msg.type = LOG_MSG_TYPE_OPER; + msg.data = &op_msg; + + lua_getglobal(states[thread_id], EVENT_FUNC); + + lua_pushnumber(states[thread_id], (double)thread_id); + + LOG_EVENT_START(msg, thread_id); + + if (lua_pcall(states[thread_id], 1, 1, 0)) + { + CALL_ERROR(states[thread_id], EVENT_FUNC); + sb_globals.error = 1; + return 1; + } + + LOG_EVENT_STOP(msg, thread_id); + + rc = lua_tonumber(states[thread_id], -1); + lua_pop(states[thread_id], 1); + + return (int)rc; +} + +int sb_lua_op_thread_init(int thread_id) +{ + sb_lua_ctxt_t *ctxt; + + ctxt = sb_lua_get_context(states[thread_id]); + + if (ctxt->con == NULL) + sb_lua_db_connect(states[thread_id]); + + lua_getglobal(states[thread_id], THREAD_INIT_FUNC); + lua_pushnumber(states[thread_id], (double)thread_id); + + if (lua_pcall(states[thread_id], 1, 1, 0)) + { + CALL_ERROR(states[thread_id], THREAD_INIT_FUNC); + return 1; + } + + return 0; +} + +int sb_lua_op_thread_done(int thread_id) +{ + lua_getglobal(states[thread_id], THREAD_DONE_FUNC); + lua_pushnumber(states[thread_id], (double)thread_id); + + if (lua_pcall(states[thread_id], 1, 1, 0)) + { + CALL_ERROR(states[thread_id], THREAD_DONE_FUNC); + return 1; + } + + return 0; +} + +int sb_lua_done(void) +{ + unsigned int i; + + for (i = 0; i < sb_globals.num_threads; i++) + lua_close(states[i]); + + free(states); + + return 0; +} + +/* Allocate and initialize new interpreter state */ + +lua_State *sb_lua_new_state(const char *scriptname) +{ + lua_State *state; + sb_lua_ctxt_t *ctxt; + sb_list_item_t *pos; + option_t *opt; + + state = luaL_newstate(); + + luaL_openlibs(state); + luaopen_math(state); + + /* Export all global options */ + pos = sb_options_enum_start(); + while ((pos = sb_options_enum_next(pos, &opt)) != NULL) + { + switch (opt->type) + { + case SB_ARG_TYPE_FLAG: + lua_pushboolean(state, sb_opt_to_flag(opt)); + break; + case SB_ARG_TYPE_INT: + lua_pushnumber(state, sb_opt_to_int(opt)); + break; + case SB_ARG_TYPE_FLOAT: + lua_pushnumber(state, sb_opt_to_float(opt)); + break; + case SB_ARG_TYPE_SIZE: + lua_pushnumber(state, sb_opt_to_size(opt)); + break; + case SB_ARG_TYPE_STRING: + lua_pushstring(state, sb_opt_to_string(opt)); + break; + case SB_ARG_TYPE_LIST: + /*FIXME: should be exported as tables */ + lua_pushnil(state); + break; + default: + log_text(LOG_WARNING, "Global option '%s' will not be exported, because" + " the type is unknown", opt->name); + break; + } + + lua_setglobal(state, opt->name); + } + + /* Export functions */ + lua_pushcfunction(state, sb_lua_rand); + lua_setglobal(state, "sb_rand"); + + lua_pushcfunction(state, sb_lua_rand_uniq); + lua_setglobal(state, "sb_rand_uniq"); + + lua_pushcfunction(state, sb_lua_rnd); + lua_setglobal(state, "sb_rnd"); + + lua_pushcfunction(state, sb_lua_db_connect); + lua_setglobal(state, "db_connect"); + + lua_pushcfunction(state, sb_lua_db_disconnect); + lua_setglobal(state, "db_disconnect"); + + lua_pushcfunction(state, sb_lua_db_query); + lua_setglobal(state, "db_query"); + + lua_pushcfunction(state, sb_lua_db_bulk_insert_init); + lua_setglobal(state, "db_bulk_insert_init"); + + lua_pushcfunction(state, sb_lua_db_bulk_insert_next); + lua_setglobal(state, "db_bulk_insert_next"); + + lua_pushcfunction(state, sb_lua_db_bulk_insert_done); + lua_setglobal(state, "db_bulk_insert_done"); + + lua_pushcfunction(state, sb_lua_db_prepare); + lua_setglobal(state, "db_prepare"); + + lua_pushcfunction(state, sb_lua_db_bind_param); + lua_setglobal(state, "db_bind_param"); + + lua_pushcfunction(state, sb_lua_db_execute); + lua_setglobal(state, "db_execute"); + + lua_pushcfunction(state, sb_lua_db_close); + lua_setglobal(state, "db_close"); + + lua_pushcfunction(state, sb_lua_db_store_results); + lua_setglobal(state, "db_store_results"); + + lua_pushcfunction(state, sb_lua_db_free_results); + lua_setglobal(state, "db_free_results"); + + luaL_newmetatable(state, "sysbench.stmt"); + luaL_newmetatable(state, "sysbench.rs"); + + if (lua_dofile(state, scriptname)) + { + lua_error(state); + return NULL; + } + + /* Create new state context */ + ctxt = (sb_lua_ctxt_t *)calloc(1, sizeof(sb_lua_ctxt_t)); + if (ctxt == NULL) + return NULL; + sb_lua_set_context(state, ctxt); + + return state; +} + +/* Close interpreter state */ + +int sb_lua_close_state(lua_State *state) +{ + if (state != NULL) + lua_close(state); + + return 0; +} + +/* Prepare command */ + +int sb_lua_cmd_prepare(void) +{ + lua_getglobal(gstate, PREPARE_FUNC); + + if (lua_pcall(gstate, 0, 1, 0) != 0) + { + log_text(LOG_FATAL, "failed to execute function `"PREPARE_FUNC"': %s", + lua_tostring(gstate, -1)); + return 1; + } + + return 0; +} + +/* Cleanup command */ + +int sb_lua_cmd_cleanup(void) +{ + lua_getglobal(gstate, CLEANUP_FUNC); + + if (lua_pcall(gstate, 0, 1, 0) != 0) + { + log_text(LOG_FATAL, "failed to execute function `"CLEANUP_FUNC"': %s", + lua_tostring(gstate, -1)); + return 1; + } + + return 0; +} + +int sb_lua_db_connect(lua_State *L) +{ + sb_lua_ctxt_t *ctxt; + + ctxt = sb_lua_get_context(L); + + if (db_driver == NULL) + { + db_driver = db_init(NULL); + if (db_driver == NULL) + lua_error(L); + lua_pushstring(L, db_driver->sname); + lua_setglobal(L, "db_driver"); + } + + ctxt->con = db_connect(db_driver); + if (ctxt->con == NULL) + lua_error(L); + + return 0; +} + +int sb_lua_db_disconnect(lua_State *L) +{ + sb_lua_ctxt_t *ctxt; + + ctxt = sb_lua_get_context(L); + + db_disconnect(ctxt->con); + + ctxt->con = NULL; + + return 0; +} + +int sb_lua_db_query(lua_State *L) +{ + sb_lua_ctxt_t *ctxt; + const char *query; + + ctxt = sb_lua_get_context(L); + + if (ctxt->con == NULL) + sb_lua_db_connect(L); + + query = luaL_checkstring(L, 1); + if (db_query(ctxt->con, query) == NULL) + lua_error(L); + + return 0; +} + +int sb_lua_db_bulk_insert_init(lua_State *L) +{ + sb_lua_ctxt_t *ctxt; + const char *query; + + ctxt = sb_lua_get_context(L); + + if (ctxt->con == NULL) + sb_lua_db_connect(L); + + query = luaL_checkstring(L, 1); + if (db_bulk_insert_init(ctxt->con, query)) + { + lua_pushstring(L, "db_bulk_insert_init() failed"); + lua_error(L); + } + + return 0; +} + +int sb_lua_db_bulk_insert_next(lua_State *L) +{ + sb_lua_ctxt_t *ctxt; + const char *query; + + ctxt = sb_lua_get_context(L); + + if (ctxt->con == NULL) + lua_error(L); + + query = luaL_checkstring(L, 1); + if (db_bulk_insert_next(ctxt->con, query)) + lua_error(L); + + return 0; +} + +int sb_lua_db_bulk_insert_done(lua_State *L) +{ + sb_lua_ctxt_t *ctxt; + + ctxt = sb_lua_get_context(L); + + if (ctxt->con == NULL) + lua_error(L); + + db_bulk_insert_done(ctxt->con); + + return 0; +} + +int sb_lua_db_prepare(lua_State *L) +{ + sb_lua_ctxt_t *ctxt; + sb_lua_db_stmt_t *stmt; + const char *query; + + ctxt = sb_lua_get_context(L); + + if (ctxt->con == NULL) + sb_lua_db_connect(L); + + query = luaL_checkstring(L, 1); + + stmt = (sb_lua_db_stmt_t *)lua_newuserdata(L, sizeof(sb_lua_db_stmt_t)); + luaL_getmetatable(L, "sysbench.stmt"); + lua_setmetatable(L, -2); + memset(stmt, 0, sizeof(sb_lua_db_stmt_t)); + + stmt->ptr = db_prepare(ctxt->con, query); + if (stmt->ptr == NULL) + lua_error(L); + + return 1; +} + +int sb_lua_db_bind_param(lua_State *L) +{ + sb_lua_ctxt_t *ctxt; + sb_lua_db_stmt_t *stmt; + unsigned int i, n; + db_bind_t *binds; + char needs_rebind = 0; + + ctxt = sb_lua_get_context(L); + + if (ctxt->con == NULL) + lua_error(L); + + stmt = (sb_lua_db_stmt_t *)luaL_checkudata(L, 1, "sysbench.stmt"); + luaL_argcheck(L, stmt != NULL, 1, "prepared statement expected"); + + if (!lua_istable(L, 2)) + { + lua_pushstring(L, "table expected"); + lua_error(L); + } + /* Get table size */ + n = sb_lua_table_size(L, 2); + if (!n) + { + lua_pushstring(L, "table is empty"); + lua_error(L); + } + binds = (db_bind_t *)calloc(n, sizeof(db_bind_t)); + stmt->params = (sb_lua_bind_t *)calloc(n, sizeof(sb_lua_bind_t)); + if (binds == NULL || stmt->params == NULL) + lua_error(L); + + lua_pushnil(L); + for (i = 0; i < n; i++) + { + lua_next(L, 2); + switch(lua_type(L, -1)) + { + case LUA_TNUMBER: + stmt->params[i].buf = malloc(sizeof(int)); + stmt->params[i].id = luaL_checknumber(L, -2); + binds[i].type = DB_TYPE_INT; + binds[i].buffer = stmt->params[i].buf; + break; + case LUA_TSTRING: + stmt->params[i].id = luaL_checknumber(L, -2); + stmt->params[i].buflen = (unsigned long *)malloc(sizeof(unsigned long)); + binds[i].type = DB_TYPE_CHAR; + needs_rebind = 1; + break; + default: + lua_pushfstring(L, "Unsupported variable type: %s", + lua_typename(L, lua_type(L, -1))); + goto error; + } + binds[i].is_null = &stmt->params[i].is_null; + stmt->params[i].type = binds[i].type; + lua_pop(L, 1); + } + + if (!needs_rebind && db_bind_param(stmt->ptr, binds, n)) + goto error; + + stmt->nparams = n; + + /* Create reference for the params table */ + lua_pushvalue(L, 2); + stmt->ref = luaL_ref(L, LUA_REGISTRYINDEX); + + free(binds); + + return 0; + + error: + + free(binds); + lua_error(L); + + return 0; +} + +int sb_lua_db_execute(lua_State *L) +{ + sb_lua_ctxt_t *ctxt; + sb_lua_db_stmt_t *stmt; + sb_lua_db_rs_t *rs; + unsigned int i; + char needs_rebind = 0; + db_bind_t *binds; + + ctxt = sb_lua_get_context(L); + + if (ctxt->con == NULL) + lua_error(L); + + stmt = (sb_lua_db_stmt_t *)luaL_checkudata(L, 1, "sysbench.stmt"); + luaL_argcheck(L, stmt != NULL, 1, "prepared statement expected"); + + /* Get params table */ + lua_rawgeti(L, LUA_REGISTRYINDEX, stmt->ref); + if (!lua_isnil(L, -1) && !lua_istable(L, -1)) + { + lua_pushstring(L, "table expected"); + lua_error(L); + } + + for (i = 0; i < stmt->nparams; lua_pop(L, 1), i++) + { + lua_pushnumber(L, stmt->params[i].id); + lua_gettable(L, -2); + if (lua_isnil(L, -1)) + { + stmt->params[i].is_null = 1; + continue; + } + stmt->params[i].is_null = 0; + switch (stmt->params[i].type) + { + case DB_TYPE_INT: + *((int *)stmt->params[i].buf) = luaL_checknumber(L, -1); + break; + case DB_TYPE_CHAR: + stmt->params[i].buf = strdup(luaL_checkstring(L, -1)); + needs_rebind = 1; + break; + default: + lua_pushfstring(L, "Unsupported variable type: %s", + lua_typename(L, lua_type(L, -1))); + lua_error(L); + } + } + + /* Rebind if needed */ + if (needs_rebind) + { + binds = (db_bind_t *)calloc(stmt->nparams, sizeof(db_bind_t)); + if (binds == NULL) + lua_error(L); + + for (i = 0; i < stmt->nparams; i++) + { + binds[i].type = stmt->params[i].type; + binds[i].is_null = &stmt->params[i].is_null; + if (*binds[i].is_null != 0) + continue; + switch (stmt->params[i].type) + { + case DB_TYPE_INT: + binds[i].buffer = stmt->params[i].buf; + break; + case DB_TYPE_CHAR: + binds[i].buffer = stmt->params[i].buf; + binds[i].data_len = stmt->params[i].buflen; + *stmt->params[i].buflen = strlen(stmt->params[i].buf); + binds[i].max_len = *stmt->params[i].buflen; + binds[i].is_null = 0; + break; + default: + lua_pushstring(L, "Unsupported variable type"); + lua_error(L); + } + } + + if (db_bind_param(stmt->ptr, binds, stmt->nparams)) + lua_error(L); + free(binds); + } + + rs = (sb_lua_db_rs_t *)lua_newuserdata(L, sizeof(sb_lua_db_rs_t)); + luaL_getmetatable(L, "sysbench.rs"); + lua_setmetatable(L, -2); + + rs->ptr = db_execute(stmt->ptr); + if (rs->ptr == NULL) + lua_error(L); + + return 1; +} + +int sb_lua_db_close(lua_State *L) +{ + sb_lua_ctxt_t *ctxt; + sb_lua_db_stmt_t *stmt; + unsigned int i; + + ctxt = sb_lua_get_context(L); + + if (ctxt->con == NULL) + lua_error(L); + + stmt = (sb_lua_db_stmt_t *)luaL_checkudata(L, 1, "sysbench.stmt"); + luaL_argcheck(L, stmt != NULL, 1, "prepared statement expected"); + + for (i = 0; i < stmt->nparams; i++) + { + if (stmt->params[i].buf != NULL) + free(stmt->params[i].buf); + if (stmt->params[i].buflen != NULL) + free(stmt->params[i].buflen); + } + free(stmt->params); + stmt->params = NULL; + + luaL_unref(L, LUA_REGISTRYINDEX, stmt->ref); + + return 0; +} + +int sb_lua_db_store_results(lua_State *L) +{ + sb_lua_ctxt_t *ctxt; + sb_lua_db_rs_t *rs; + + ctxt = sb_lua_get_context(L); + + if (ctxt->con == NULL) + lua_error(L); + + rs = (sb_lua_db_rs_t *)luaL_checkudata(L, 1, "sysbench.rs"); + luaL_argcheck(L, rs != NULL, 1, "result set expected"); + + db_store_results(rs->ptr); + + return 0; +} + +int sb_lua_db_free_results(lua_State *L) +{ + sb_lua_ctxt_t *ctxt; + sb_lua_db_rs_t *rs; + + ctxt = sb_lua_get_context(L); + + if (ctxt->con == NULL) + lua_error(L); + + rs = (sb_lua_db_rs_t *)luaL_checkudata(L, 1, "sysbench.rs"); + luaL_argcheck(L, rs != NULL, 1, "result set expected"); + + db_free_results(rs->ptr); + + return 0; +} + +int sb_lua_rand(lua_State *L) +{ + int a, b; + + a = luaL_checknumber(L, 1); + b = luaL_checknumber(L, 2); + + lua_pushnumber(L, sb_rand(a, b)); + + return 1; +} + +int sb_lua_rand_uniq(lua_State *L) +{ + int a, b; + + a = luaL_checknumber(L, 1); + b = luaL_checknumber(L, 2); + + lua_pushnumber(L, sb_rand_uniq(a, b)); + + return 1; +} + +int sb_lua_rnd(lua_State *L) +{ + lua_pushnumber(L, sb_rnd()); + + return 1; +} + +/* Get a per-state interpreter context */ + +sb_lua_ctxt_t *sb_lua_get_context(lua_State *L) +{ + lua_pushlightuserdata(L, (void *)&sb_lua_ctxt_key); + lua_gettable(L, LUA_REGISTRYINDEX); + + return (sb_lua_ctxt_t *)lua_touserdata(L, -1); +} + +/* Set a per-state interpreter context */ + +void sb_lua_set_context(lua_State *L, sb_lua_ctxt_t *ctxt) +{ + lua_pushlightuserdata(L, (void *)&sb_lua_ctxt_key); + lua_pushlightuserdata(L, (void *)ctxt); + lua_settable(L, LUA_REGISTRYINDEX); +} + +unsigned int sb_lua_table_size(lua_State *L, int index) +{ + unsigned int i; + + lua_pushnil(L); + for (i = 0; lua_next(L, index); i++) + { + lua_pop(L, 1); + } + + return i; +} diff --git a/sysbench/scripting/script_lua.h b/sysbench/scripting/script_lua.h new file mode 100644 index 0000000..7eaefef --- /dev/null +++ b/sysbench/scripting/script_lua.h @@ -0,0 +1,26 @@ +/* Copyright (C) 2006 MySQL AB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "sysbench.h" + +/* Load a specified Lua script */ + +int script_load_lua(const char *testname, sb_test_t *test); diff --git a/sysbench/sysbench.c b/sysbench/sysbench.c index 992adbd..cddb967 100644 --- a/sysbench/sysbench.c +++ b/sysbench/sysbench.c @@ -59,9 +59,32 @@ #include "sysbench.h" #include "sb_options.h" +#include "scripting/sb_script.h" +#include "db_driver.h" + +/* Large prime number to generate unique random IDs */ +#define LARGE_PRIME 2147483647 + +/* Random numbers distributions */ +typedef enum +{ + DIST_TYPE_UNIFORM, + DIST_TYPE_GAUSSIAN, + DIST_TYPE_SPECIAL +} rand_dist_t; /* If we should initialize random numbers generator */ -static int init_rng; +static int rand_init; +static rand_dist_t rand_type; +static int (*rand_func)(int, int); /* pointer to random numbers generator */ +static unsigned int rand_iter; +static unsigned int rand_pct; +static unsigned int rand_res; + +/* Random seed used to generate unique random numbers */ +static unsigned long long rnd_seed; +/* Mutex to protect random seed */ +static pthread_mutex_t rnd_mutex; /* Stack size for each thread */ static int thread_stack_size; @@ -73,15 +96,22 @@ sb_arg_t general_args[] = {"max-requests", "limit for total number of requests", SB_ARG_TYPE_INT, "10000"}, {"max-time", "limit for total execution time in seconds", SB_ARG_TYPE_INT, "0"}, {"thread-stack-size", "size of stack per thread", SB_ARG_TYPE_SIZE, "32K"}, - {"init-rng", "initialize random number generator", SB_ARG_TYPE_FLAG, "off"}, {"test", "test to run", SB_ARG_TYPE_STRING, NULL}, {"debug", "print more debugging info", SB_ARG_TYPE_FLAG, "off"}, {"validate", "perform validation checks where possible", SB_ARG_TYPE_FLAG, "off"}, {"help", "print help and exit", SB_ARG_TYPE_FLAG, NULL}, + {"rand-init", "initialize random number generator", SB_ARG_TYPE_FLAG, "off"}, + {"rand-type", "random numbers distribution {uniform,gaussian,special}", SB_ARG_TYPE_STRING, + "special"}, + {"rand-spec-iter", "number of iterations used for numbers generation", SB_ARG_TYPE_INT, "12"}, + {"rand-spec-pct", "percentage of values to be treated as 'special' (for special distribution)", + SB_ARG_TYPE_INT, "1"}, + {"rand-spec-res", "percentage of 'special' values to use (for special distribution)", + SB_ARG_TYPE_INT, "75"}, {NULL, NULL, SB_ARG_TYPE_NULL, NULL} }; -/* Our main thread descriptors */ +/* Thread descriptors */ sb_thread_ctxt_t *threads; /* List of available tests */ @@ -158,7 +188,7 @@ int register_tests(void) + register_test_memory(&tests) + register_test_threads(&tests) + register_test_mutex(&tests) - + register_test_oltp(&tests) + + db_register() ; } @@ -285,10 +315,10 @@ int parse_arguments(int argc, char *argv[]) opt = sb_find_option(name); if (opt == NULL) { - fprintf(stderr, "Unknown option: %s.\n", argv[i]); - return 1; + if (set_option(name, value, SB_ARG_TYPE_STRING)) + return 1; } - if (set_option(name, value, opt->type)) + else if (set_option(name, value, opt->type)) return 1; } @@ -307,7 +337,7 @@ void print_run_mode(sb_test_t *test) if (sb_globals.validate) log_text(LOG_NOTICE, "Additional request validation enabled.\n"); - if (init_rng) + if (rand_init) { log_text(LOG_NOTICE, "Initializing random number generator from timer.\n"); srandom(time(NULL)); @@ -420,6 +450,10 @@ int run_test(sb_test_t *test) thr_setconcurrency(sb_globals.num_threads); #endif + /* Initialize random seed */ + rnd_seed = LARGE_PRIME; + pthread_mutex_init(&rnd_mutex, NULL); + /* Starting the test threads */ for(i = 0; i < sb_globals.num_threads; i++) { @@ -455,6 +489,8 @@ int run_test(sb_test_t *test) if (test->ops.print_stats != NULL && !sb_globals.error) test->ops.print_stats(); + pthread_mutex_destroy(&rnd_mutex); + pthread_mutex_destroy(&sb_globals.exec_mutex); pthread_mutex_destroy(&thread_start_mutex); @@ -485,8 +521,9 @@ sb_test_t *find_test(char *name) int init(void) { - option_t *opt; - + option_t *opt; + char *s; + sb_globals.num_threads = sb_get_value_int("num-threads"); if (sb_globals.num_threads <= 0) { @@ -525,7 +562,34 @@ int init(void) } sb_globals.validate = sb_get_value_flag("validate"); - init_rng = sb_get_value_flag("init-rng"); + + rand_init = sb_get_value_flag("rand-init"); + s = sb_get_value_string("rand-type"); + if (!strcmp(s, "uniform")) + { + rand_type = DIST_TYPE_UNIFORM; + rand_func = &sb_rand_uniform; + } + else if (!strcmp(s, "gaussian")) + { + rand_type = DIST_TYPE_GAUSSIAN; + rand_func = &sb_rand_gaussian; + } + else if (!strcmp(s, "special")) + { + rand_type = DIST_TYPE_SPECIAL; + rand_func = &sb_rand_special; + } + else + { + log_text(LOG_FATAL, "Invalid random numbers distribution: %s.", s); + return 1; + } + + rand_iter = sb_get_value_int("rand-spec-iter"); + rand_pct = sb_get_value_int("rand-spec-pct"); + rand_res = sb_get_value_int("rand-spec-res"); + return 0; } @@ -572,7 +636,13 @@ int main(int argc, char *argv[]) testname = sb_get_value_string("test"); if (testname != NULL) + { test = find_test(testname); + + /* Check if the testname is a script filename */ + if (test == NULL) + test = script_load(testname); + } /* 'help' command */ if (sb_globals.command == SB_COMMAND_HELP) @@ -595,12 +665,13 @@ int main(int argc, char *argv[]) print_usage(); exit(1); } + if (test == NULL) { - fprintf(stderr, "Invalid test name: %s.\n", testname); - exit(1); + fprintf(stderr, "Invalid test name: %s.\n", testname); + exit(1); } - + /* 'prepare' command */ if (sb_globals.command == SB_COMMAND_PREPARE) { @@ -636,3 +707,97 @@ int main(int argc, char *argv[]) exit(0); } + +/* + Return random number in specified range with distribution specified + with the --rand-type command line option +*/ + +int sb_rand(int a, int b) +{ + return rand_func(a,b); +} + +/* uniform distribution */ + +int sb_rand_uniform(int a, int b) +{ + return a + sb_rnd() % (b - a + 1); +} + +/* gaussian distribution */ + +int sb_rand_gaussian(int a, int b) +{ + int sum; + unsigned int i, t; + + t = b - a + 1; + for(i=0, sum=0; i < rand_iter; i++) + sum += sb_rnd() % t; + + return a + sum / rand_iter; +} + +/* 'special' distribution */ + +int sb_rand_special(int a, int b) +{ + int sum = 0; + unsigned int i; + unsigned int d; + unsigned int t; + unsigned int res; + unsigned int range_size; + + if (a >= b) + return 0; + + t = b - a + 1; + + /* Increase range size for special values. */ + range_size = t * (100 / (100 - rand_res)); + + /* Generate uniformly distributed one at this stage */ + res = sb_rnd() % range_size; + + /* For first part use gaussian distribution */ + if (res < t) + { + for(i = 0; i < rand_iter; i++) + sum += sb_rnd() % t; + return a + sum / rand_iter; + } + + /* + * For second part use even distribution mapped to few items + * We shall distribute other values near by the center + */ + d = t * rand_pct / 100; + if (d < 1) + d = 1; + res %= d; + + /* Now we have res values in SPECIAL_PCT range of the data */ + res += (t / 2 - t * rand_pct / (100 * 2)); + + return a + res; +} + + +/* Generate unique random id */ + + +int sb_rand_uniq(int a, int b) +{ + int res; + + pthread_mutex_lock(&rnd_mutex); + res = (unsigned int) (rnd_seed % (b - a + 1)) ; + rnd_seed += LARGE_PRIME; + pthread_mutex_unlock(&rnd_mutex); + + return res + a; +} + + diff --git a/sysbench/sysbench.h b/sysbench/sysbench.h index 0893a75..1989713 100644 --- a/sysbench/sysbench.h +++ b/sysbench/sysbench.h @@ -52,7 +52,7 @@ #define SB_THREAD_MUTEX_UNLOCK() pthread_mutex_unlock(&sb_globals.exec_mutex) #define SB_MAX_RND 0x3fffffffu -#define sb_rnd() (random() % SB_MAX_RND) +#define sb_rnd() (unsigned int)(random() % SB_MAX_RND) /* Sysbench commands */ @@ -75,7 +75,8 @@ typedef enum SB_REQ_TYPE_FILE, SB_REQ_TYPE_SQL, SB_REQ_TYPE_THREADS, - SB_REQ_TYPE_MUTEX + SB_REQ_TYPE_MUTEX, + SB_REQ_TYPE_SCRIPT } sb_request_type_t; /* Request structure definition */ @@ -197,4 +198,11 @@ unsigned long long sb_get_value_size(char *); float sb_get_value_float(char *); char *sb_get_value_string(char *); +/* Random number generators */ +int sb_rand(int, int); +int sb_rand_uniform(int, int); +int sb_rand_gaussian(int, int); +int sb_rand_special(int, int); +int sb_rand_uniq(int a, int b); + #endif diff --git a/sysbench/tests/Makefile.in b/sysbench/tests/Makefile.in index 2cc49b2..b114a1b 100644 --- a/sysbench/tests/Makefile.in +++ b/sysbench/tests/Makefile.in @@ -119,6 +119,8 @@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ +LUA_CPPFLAGS = @LUA_CPPFLAGS@ +LUA_LDFLAGS = @LUA_LDFLAGS@ MAKEINFO = @MAKEINFO@ MYSQL_CFLAGS = @MYSQL_CFLAGS@ MYSQL_LIBS = @MYSQL_LIBS@ @@ -143,6 +145,8 @@ SHELL = @SHELL@ STRIP = @STRIP@ USE_AIO_FALSE = @USE_AIO_FALSE@ USE_AIO_TRUE = @USE_AIO_TRUE@ +USE_LUA_FALSE = @USE_LUA_FALSE@ +USE_LUA_TRUE = @USE_LUA_TRUE@ USE_MYSQL_FALSE = @USE_MYSQL_FALSE@ USE_MYSQL_TRUE = @USE_MYSQL_TRUE@ USE_ORACLE_FALSE = @USE_ORACLE_FALSE@ @@ -190,6 +194,7 @@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localstatedir = @localstatedir@ +luaconfig = @luaconfig@ mandir = @mandir@ mkdir_p = @mkdir_p@ mysqlconfig = @mysqlconfig@ diff --git a/sysbench/tests/cpu/Makefile.in b/sysbench/tests/cpu/Makefile.in index 7522e93..8b9d605 100644 --- a/sysbench/tests/cpu/Makefile.in +++ b/sysbench/tests/cpu/Makefile.in @@ -132,6 +132,8 @@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ +LUA_CPPFLAGS = @LUA_CPPFLAGS@ +LUA_LDFLAGS = @LUA_LDFLAGS@ MAKEINFO = @MAKEINFO@ MYSQL_CFLAGS = @MYSQL_CFLAGS@ MYSQL_LIBS = @MYSQL_LIBS@ @@ -156,6 +158,8 @@ SHELL = @SHELL@ STRIP = @STRIP@ USE_AIO_FALSE = @USE_AIO_FALSE@ USE_AIO_TRUE = @USE_AIO_TRUE@ +USE_LUA_FALSE = @USE_LUA_FALSE@ +USE_LUA_TRUE = @USE_LUA_TRUE@ USE_MYSQL_FALSE = @USE_MYSQL_FALSE@ USE_MYSQL_TRUE = @USE_MYSQL_TRUE@ USE_ORACLE_FALSE = @USE_ORACLE_FALSE@ @@ -203,6 +207,7 @@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localstatedir = @localstatedir@ +luaconfig = @luaconfig@ mandir = @mandir@ mkdir_p = @mkdir_p@ mysqlconfig = @mysqlconfig@ diff --git a/sysbench/tests/db/delete.lua b/sysbench/tests/db/delete.lua new file mode 100644 index 0000000..6f99b55 --- /dev/null +++ b/sysbench/tests/db/delete.lua @@ -0,0 +1,108 @@ +function prepare() + local query + local i + + set_vars() + + db_connect() + + print("Creating table 'sbtest'...") + + if (db_driver == "mysql") then + query = [[ + CREATE TABLE sbtest ( + id INTEGER UNSIGNED NOT NULL ]] .. ((oltp_auto_inc and "AUTO_INCREMENT") or "") .. [[, + k INTEGER UNSIGNED DEFAULT '0' NOT NULL, + c CHAR(120) DEFAULT '' NOT NULL, + pad CHAR(60) DEFAULT '' NOT NULL, + PRIMARY KEY (id) + ) /*! ENGINE = ]] .. mysql_table_engine .. " MAX_ROWS = " .. myisam_max_rows .. " */" + + elseif (db_driver == "oracle") then + query = [[ + CREATE TABLE sbtest ( + id INTEGER NOT NULL, + k INTEGER, + c CHAR(120) DEFAULT '' NOT NULL, + pad CHAR(60 DEFAULT '' NOT NULL, + PRIMARY KEY (id) + ) ]] + + + elseif (db_driver == "pgsql") then + query = [[ + CREATE TABLE sbtest ( + id ]] .. (sb.oltp_auto_inc and "SERIAL") or "" .. [[, + k INTEGER DEFAULT '0' NOT NULL, + c CHAR(120) DEFAULT '' NOT NULL, + pad CHAR(60) DEFAULT '' NOT NULL, + PRIMARY KEY (id) + ) ]] + else + print("Unknown database driver: " .. db_driver) + return 1 + end + + db_query(query) + + if (db_driver == "oracle") then + db_query("CREATE SEQUENCE sbtest_seq") + db_query([[CREATE TRIGGER sbtest_trig BEFORE INSERT ON sbtest + FOR EACH ROW BEGIN SELECT sbtest_seq.nextval INTO :new.id FROM DUAL; END;]]) + end + + db_query("CREATE INDEX k on sbtest(k)") + + print("Inserting " .. oltp_table_size .. " records into 'sbtest'") + + if (oltp_auto_inc) then + db_bulk_insert_init("INSERT INTO sbtest(k, c, pad) VALUES") + else + db_bulk_insert_init("INSERT INTO sbtest(id, k, c, pad) VALUES") + end + + for i = 1,oltp_table_size do + if (oltp_auto_inc) then + db_bulk_insert_next("(0, ' ', 'qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt')") + else + db_bulk_insert_next("("..i..",0,' ','qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt')") + end + end + + db_bulk_insert_done() + + return 0 +end + +function cleanup() + print("Dropping table 'sbtest'...") + db_query("DROP TABLE sbtest") +end + +function thread_init(thread_id) + local query + + set_vars() + + stmt = db_prepare([[ + DELETE FROM sbtest WHERE id = ? + ]]) + params = {0} + db_bind_param(stmt, params) +end + +function event(thread_id) + local rs + params[1] = sb_rand(1, oltp_table_size) + rs = db_execute(stmt) +end + +function set_vars() + oltp_table_size = oltp_table_size or 10000 + + if (oltp_auto_inc == 'off') then + oltp_auto_inc = false + else + oltp_auto_inc = true + end +end \ No newline at end of file diff --git a/sysbench/tests/db/insert.lua b/sysbench/tests/db/insert.lua new file mode 100644 index 0000000..42d9a96 --- /dev/null +++ b/sysbench/tests/db/insert.lua @@ -0,0 +1,99 @@ +function prepare() + local query + local i + + set_vars() + + db_connect() + + print("Creating table 'sbtest'...") + + if (db_driver == "mysql") then + query = [[ + CREATE TABLE sbtest ( + id INTEGER UNSIGNED NOT NULL ]] .. ((oltp_auto_inc and "AUTO_INCREMENT") or "") .. [[, + k INTEGER UNSIGNED DEFAULT '0' NOT NULL, + c CHAR(120) DEFAULT '' NOT NULL, + pad CHAR(60) DEFAULT '' NOT NULL, + PRIMARY KEY (id) + ) /*! ENGINE = ]] .. mysql_table_engine .. " MAX_ROWS = " .. myisam_max_rows .. " */" + + elseif (db_driver == "oracle") then + query = [[ + CREATE TABLE sbtest ( + id INTEGER NOT NULL, + k INTEGER, + c CHAR(120) DEFAULT '' NOT NULL, + pad CHAR(60 DEFAULT '' NOT NULL, + PRIMARY KEY (id) + ) ]] + + + elseif (db_driver == "pgsql") then + query = [[ + CREATE TABLE sbtest ( + id ]] .. (sb.oltp_auto_inc and "SERIAL") or "" .. [[, + k INTEGER DEFAULT '0' NOT NULL, + c CHAR(120) DEFAULT '' NOT NULL, + pad CHAR(60) DEFAULT '' NOT NULL, + PRIMARY KEY (id) + ) ]] + else + print("Unknown database driver: " .. db_driver) + return 1 + end + + db_query(query) + + if (db_driver == "oracle") then + db_query("CREATE SEQUENCE sbtest_seq") + db_query([[CREATE TRIGGER sbtest_trig BEFORE INSERT ON sbtest + FOR EACH ROW BEGIN SELECT sbtest_seq.nextval INTO :new.id FROM DUAL; END;]]) + end + + db_query("CREATE INDEX k on sbtest(k)") + + return 0 +end + +function cleanup() + print("Dropping table 'sbtest'...") + db_query("DROP TABLE sbtest") +end + +function thread_init(thread_id) + local query + + set_vars() + + stmt = db_prepare([[ + INSERT INTO sbtest VALUES (?,?,?,?) + ]]) + params = {0, 0, "", ""} + db_bind_param(stmt, params) + +end + +function event(thread_id) + local rs + if (oltp_auto_inc) then + params[1] = nil + else + params[1] = sb_rand_uniq(1, oltp_table_size) + end + params[2]= sb_rand(1, oltp_table_size) + params[3] = sb_rnd() .. '-'..sb_rnd()..'-'..sb_rnd()..'-'..sb_rnd() .. '-' .. + sb_rnd()..'-'..sb_rnd()..'-'..sb_rnd()..'-'..sb_rnd()..'-'..sb_rnd()..'-'..sb_rnd() + params[4] = sb_rnd()..'-'.. sb_rnd()..'-'.. sb_rnd()..'-'.. sb_rnd()..'-'.. sb_rnd() + rs = db_execute(stmt) +end + +function set_vars() + oltp_table_size = oltp_table_size or 10000 + + if (oltp_auto_inc == 'off') then + oltp_auto_inc = false + else + oltp_auto_inc = true + end +end \ No newline at end of file diff --git a/sysbench/tests/db/oltp_complex_ro.lua b/sysbench/tests/db/oltp_complex_ro.lua new file mode 100644 index 0000000..90953dc --- /dev/null +++ b/sysbench/tests/db/oltp_complex_ro.lua @@ -0,0 +1,163 @@ +function prepare() + local query + local i + + set_vars() + + db_connect() + + print("Creating table 'sbtest'...") + + if (db_driver == "mysql") then + query = [[ + CREATE TABLE sbtest ( + id INTEGER UNSIGNED NOT NULL ]] .. ((oltp_auto_inc and "AUTO_INCREMENT") or "") .. [[, + k INTEGER UNSIGNED DEFAULT '0' NOT NULL, + c CHAR(120) DEFAULT '' NOT NULL, + pad CHAR(60) DEFAULT '' NOT NULL, + PRIMARY KEY (id) + ) /*! ENGINE = ]] .. mysql_table_engine .. " MAX_ROWS = " .. myisam_max_rows .. " */" + + elseif (db_driver == "oracle") then + query = [[ + CREATE TABLE sbtest ( + id INTEGER NOT NULL, + k INTEGER, + c CHAR(120) DEFAULT '' NOT NULL, + pad CHAR(60 DEFAULT '' NOT NULL, + PRIMARY KEY (id) + ) ]] + + + elseif (db_driver == "pgsql") then + query = [[ + CREATE TABLE sbtest ( + id ]] .. (sb.oltp_auto_inc and "SERIAL") or "" .. [[, + k INTEGER DEFAULT '0' NOT NULL, + c CHAR(120) DEFAULT '' NOT NULL, + pad CHAR(60) DEFAULT '' NOT NULL, + PRIMARY KEY (id) + ) ]] + else + print("Unknown database driver: " .. db_driver) + return 1 + end + + db_query(query) + + if (db_driver == "oracle") then + db_query("CREATE SEQUENCE sbtest_seq") + db_query([[CREATE TRIGGER sbtest_trig BEFORE INSERT ON sbtest + FOR EACH ROW BEGIN SELECT sbtest_seq.nextval INTO :new.id FROM DUAL; END;]]) + end + + db_query("CREATE INDEX k on sbtest(k)") + + print("Inserting " .. oltp_table_size .. " records into 'sbtest'") + + if (oltp_auto_inc) then + db_bulk_insert_init("INSERT INTO sbtest(k, c, pad) VALUES") + else + db_bulk_insert_init("INSERT INTO sbtest(id, k, c, pad) VALUES") + end + + for i = 1,oltp_table_size do + if (oltp_auto_inc) then + db_bulk_insert_next("(0, ' ', 'qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt')") + else + db_bulk_insert_next("("..i..",0,' ','qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt')") + end + end + + db_bulk_insert_done() + + return 0 +end + +function cleanup() + print("Dropping table 'sbtest'...") + db_query("DROP TABLE sbtest") +end + +function thread_init(thread_id) + set_vars() + + if (db_driver == "mysql" and mysql_table_engine == "myisam") then + begin_stmt = db_prepare("LOCK TABLES sbtest READ") + commit_stmt = db_prepare("LOCK TABLES sbtest READ") + else + begin_stmt = db_prepare("BEGIN") + commit_stmt = db_prepare("COMMIT") + end + + point_stmt = db_prepare("SELECT c FROM sbtest WHERE id=?") + point_params = {0} + db_bind_param(point_stmt, point_params) + + range_stmt = db_prepare("SELECT c FROM sbtest WHERE id BETWEEN ? AND ?") + range_params = {0,0} + db_bind_param(range_stmt, range_params) + + sum_stmt = db_prepare("SELECT SUM(K) FROM sbtest WHERE id BETWEEN ? AND ?") + sum_params = {0,0} + db_bind_param(sum_stmt, sum_params) + + order_stmt= db_prepare("SELECT c FROM sbtest WHERE id BETWEEN ? AND ? ORDER BY c") + order_params = {0,0} + db_bind_param(order_stmt, order_params) + + distinct_stmt = db_prepare("SELECT DISTINCT c FROM sbtest WHERE id BETWEEN ? AND ? ORDER BY c") + distinct_params = {0,0} + db_bind_param(distinct_stmt, distinct_params) + +end + +function event(thread_id) + local rs + local i + + db_execute(begin_stmt) + + for i=1,10 do + point_params[1] = sb_rand(1, oltp_table_size) + rs = db_execute(point_stmt) + db_store_results(rs) + db_free_results(rs) + end + + range_params[1] = sb_rand(1, oltp_table_size) + range_params[2] = range_params[1] + oltp_range_size - 1 + rs = db_execute(range_stmt) + db_store_results(rs) + db_free_results(rs) + + sum_params[1] = sb_rand(1, oltp_table_size) + sum_params[2] = sum_params[1] + oltp_range_size - 1 + rs = db_execute(sum_stmt) + db_store_results(rs) + db_free_results(rs) + + order_params[1] = sb_rand(1, oltp_table_size) + order_params[2] = order_params[1] + oltp_range_size - 1 + rs = db_execute(order_stmt) + db_store_results(rs) + db_free_results(rs) + + distinct_params[1] = sb_rand(1, oltp_table_size) + distinct_params[2] = distinct_params[1] + oltp_range_size - 1 + rs = db_execute(distinct_stmt) + db_store_results(rs) + db_free_results(rs) + +end + +function set_vars() + oltp_table_size = oltp_table_size or 10000 + oltp_range_size = oltp_range_size or 10 + + if (oltp_auto_inc == 'off') then + oltp_auto_inc = false + else + oltp_auto_inc = true + end +end diff --git a/sysbench/tests/db/oltp_complex_rw.lua b/sysbench/tests/db/oltp_complex_rw.lua new file mode 100644 index 0000000..9efdfad --- /dev/null +++ b/sysbench/tests/db/oltp_complex_rw.lua @@ -0,0 +1,200 @@ +function prepare() + local query + local i + + set_vars() + + db_connect() + + print("Creating table 'sbtest'...") + + if (db_driver == "mysql") then + query = [[ + CREATE TABLE sbtest ( + id INTEGER UNSIGNED NOT NULL ]] .. ((oltp_auto_inc and "AUTO_INCREMENT") or "") .. [[, + k INTEGER UNSIGNED DEFAULT '0' NOT NULL, + c CHAR(120) DEFAULT '' NOT NULL, + pad CHAR(60) DEFAULT '' NOT NULL, + PRIMARY KEY (id) + ) /*! ENGINE = ]] .. mysql_table_engine .. " MAX_ROWS = " .. myisam_max_rows .. " */" + + elseif (db_driver == "oracle") then + query = [[ + CREATE TABLE sbtest ( + id INTEGER NOT NULL, + k INTEGER, + c CHAR(120) DEFAULT '' NOT NULL, + pad CHAR(60 DEFAULT '' NOT NULL, + PRIMARY KEY (id) + ) ]] + + + elseif (db_driver == "pgsql") then + query = [[ + CREATE TABLE sbtest ( + id ]] .. (sb.oltp_auto_inc and "SERIAL") or "" .. [[, + k INTEGER DEFAULT '0' NOT NULL, + c CHAR(120) DEFAULT '' NOT NULL, + pad CHAR(60) DEFAULT '' NOT NULL, + PRIMARY KEY (id) + ) ]] + else + print("Unknown database driver: " .. db_driver) + return 1 + end + + db_query(query) + + if (db_driver == "oracle") then + db_query("CREATE SEQUENCE sbtest_seq") + db_query([[CREATE TRIGGER sbtest_trig BEFORE INSERT ON sbtest + FOR EACH ROW BEGIN SELECT sbtest_seq.nextval INTO :new.id FROM DUAL; END;]]) + end + + db_query("CREATE INDEX k on sbtest(k)") + + print("Inserting " .. oltp_table_size .. " records into 'sbtest'") + + if (oltp_auto_inc) then + db_bulk_insert_init("INSERT INTO sbtest(k, c, pad) VALUES") + else + db_bulk_insert_init("INSERT INTO sbtest(id, k, c, pad) VALUES") + end + + for i = 1,oltp_table_size do + if (oltp_auto_inc) then + db_bulk_insert_next("(0, ' ', 'qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt')") + else + db_bulk_insert_next("("..i..",0,' ','qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt')") + end + end + + db_bulk_insert_done() + + return 0 +end + +function cleanup() + print("Dropping table 'sbtest'...") + db_query("DROP TABLE sbtest") +end + +function thread_init(thread_id) + set_vars() + + if (db_driver == "mysql" and mysql_table_engine == "myisam") then + begin_stmt = db_prepare("LOCK TABLES sbtest WRITE") + commit_stmt = db_prepare("LOCK TABLES sbtest WRITE") + else + begin_stmt = db_prepare("BEGIN") + commit_stmt = db_prepare("COMMIT") + end + + point_stmt = db_prepare("SELECT c FROM sbtest WHERE id=?") + point_params = {0} + db_bind_param(point_stmt, point_params) + + range_stmt = db_prepare("SELECT c FROM sbtest WHERE id BETWEEN ? AND ?") + range_params = {0,0} + db_bind_param(range_stmt, range_params) + + sum_stmt = db_prepare("SELECT SUM(K) FROM sbtest WHERE id BETWEEN ? AND ?") + sum_params = {0,0} + db_bind_param(sum_stmt, sum_params) + + order_stmt= db_prepare("SELECT c FROM sbtest WHERE id BETWEEN ? AND ? ORDER BY c") + order_params = {0,0} + db_bind_param(order_stmt, order_params) + + distinct_stmt = db_prepare("SELECT DISTINCT c FROM sbtest WHERE id BETWEEN ? AND ? ORDER BY c") + distinct_params = {0,0} + db_bind_param(distinct_stmt, distinct_params) + + update_idx_stmt = db_prepare("UPDATE sbtest SET k=k+1 WHERE id=?") + update_idx_params = {0} + db_bind_param(update_idx_stmt, update_idx_params) + + update_nonidx_stmt = db_prepare("UPDATE sbtest SET c=? WHERE id=?") + update_nonidx_params = {"", 0} + db_bind_param(update_nonidx_stmt, update_nonidx_params) + + delete_stmt = db_prepare("DELETE FROM sbtest WHERE id=?") + delete_params = {0} + db_bind_param(delete_stmt, delete_params) + + insert_stmt = db_prepare([[ + INSERT INTO sbtest VALUES(?,0,' ', + 'aaaaaaaaaaffffffffffrrrrrrrrrreeeeeeeeeeyyyyyyyyyy') + ]]) + insert_params={0} + db_bind_param(insert_stmt, insert_params) +end + +function event(thread_id) + local rs + local i + + db_execute(begin_stmt) + + for i=1,10 do + point_params[1] = sb_rand(1, oltp_table_size) + rs = db_execute(point_stmt) + db_store_results(rs) + db_free_results(rs) + end + + range_params[1] = sb_rand(1, oltp_table_size) + range_params[2] = range_params[1] + oltp_range_size - 1 + rs = db_execute(range_stmt) + db_store_results(rs) + db_free_results(rs) + + sum_params[1] = sb_rand(1, oltp_table_size) + sum_params[2] = sum_params[1] + oltp_range_size - 1 + rs = db_execute(sum_stmt) + db_store_results(rs) + db_free_results(rs) + + order_params[1] = sb_rand(1, oltp_table_size) + order_params[2] = order_params[1] + oltp_range_size - 1 + rs = db_execute(order_stmt) + db_store_results(rs) + db_free_results(rs) + + distinct_params[1] = sb_rand(1, oltp_table_size) + distinct_params[2] = distinct_params[1] + oltp_range_size - 1 + rs = db_execute(distinct_stmt) + db_store_results(rs) + db_free_results(rs) + + update_idx_params[1] = sb_rand(1, oltp_table_size) + rs = db_execute(update_idx_stmt) + + update_nonidx_params[1] = sb_rnd() .. '-'..sb_rnd()..'-'..sb_rnd()..'-'..sb_rnd() .. '-' .. + sb_rnd()..'-'..sb_rnd()..'-'..sb_rnd()..'-'..sb_rnd()..'-'..sb_rnd()..'-'..sb_rnd() + update_nonidx_params[2] = sb_rand(1, oltp_table_size) + rs = db_execute(update_nonidx_stmt) + + -- DELETE and INSERT on the same id + local id = sb_rand(1, oltp_table_size) + + delete_params[1] = id + db_execute(delete_stmt) + + insert_params[1] = id + db_execute(insert_stmt) + + db_execute(commit_stmt) + +end + +function set_vars() + oltp_table_size = oltp_table_size or 10000 + oltp_range_size = oltp_range_size or 10 + + if (oltp_auto_inc == 'off') then + oltp_auto_inc = false + else + oltp_auto_inc = true + end +end diff --git a/sysbench/tests/db/oltp_simple.lua b/sysbench/tests/db/oltp_simple.lua new file mode 100644 index 0000000..f5426fe --- /dev/null +++ b/sysbench/tests/db/oltp_simple.lua @@ -0,0 +1,109 @@ +function prepare() + local query + local i + + set_vars() + + db_connect() + + print("Creating table 'sbtest'...") + + if (db_driver == "mysql") then + query = [[ + CREATE TABLE sbtest ( + id INTEGER UNSIGNED NOT NULL ]] .. ((oltp_auto_inc and "AUTO_INCREMENT") or "") .. [[, + k INTEGER UNSIGNED DEFAULT '0' NOT NULL, + c CHAR(120) DEFAULT '' NOT NULL, + pad CHAR(60) DEFAULT '' NOT NULL, + PRIMARY KEY (id) + ) /*! ENGINE = ]] .. mysql_table_engine .. " MAX_ROWS = " .. myisam_max_rows .. " */" + + elseif (db_driver == "oracle") then + query = [[ + CREATE TABLE sbtest ( + id INTEGER NOT NULL, + k INTEGER, + c CHAR(120) DEFAULT '' NOT NULL, + pad CHAR(60 DEFAULT '' NOT NULL, + PRIMARY KEY (id) + ) ]] + + + elseif (db_driver == "pgsql") then + query = [[ + CREATE TABLE sbtest ( + id ]] .. (sb.oltp_auto_inc and "SERIAL") or "" .. [[, + k INTEGER DEFAULT '0' NOT NULL, + c CHAR(120) DEFAULT '' NOT NULL, + pad CHAR(60) DEFAULT '' NOT NULL, + PRIMARY KEY (id) + ) ]] + else + print("Unknown database driver: " .. db_driver) + return 1 + end + + db_query(query) + + if (db_driver == "oracle") then + db_query("CREATE SEQUENCE sbtest_seq") + db_query([[CREATE TRIGGER sbtest_trig BEFORE INSERT ON sbtest + FOR EACH ROW BEGIN SELECT sbtest_seq.nextval INTO :new.id FROM DUAL; END;]]) + end + + db_query("CREATE INDEX k on sbtest(k)") + + print("Inserting " .. oltp_table_size .. " records into 'sbtest'") + + if (oltp_auto_inc) then + db_bulk_insert_init("INSERT INTO sbtest(k, c, pad) VALUES") + else + db_bulk_insert_init("INSERT INTO sbtest(id, k, c, pad) VALUES") + end + + for i = 1,oltp_table_size do + if (oltp_auto_inc) then + db_bulk_insert_next("(0, ' ', 'qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt')") + else + db_bulk_insert_next("("..i..",0,' ','qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt')") + end + end + + db_bulk_insert_done() + + return 0 +end + +function cleanup() + print("Dropping table 'sbtest'...") + db_query("DROP TABLE sbtest") +end + +function thread_init(thread_id) + set_vars() + + stmt = db_prepare([[ + SELECT c FROM sbtest WHERE id=? + ]]) + params = {1} + db_bind_param(stmt, params) + +end + +function event(thread_id) + local rs + params[1] = sb_rand(1, oltp_table_size) + rs = db_execute(stmt) + db_store_results(rs) + db_free_results(rs) +end + +function set_vars() + oltp_table_size = oltp_table_size or 10000 + + if (oltp_auto_inc == 'off') then + oltp_auto_inc = false + else + oltp_auto_inc = true + end +end diff --git a/sysbench/tests/db/select.lua b/sysbench/tests/db/select.lua new file mode 100644 index 0000000..f99d917 --- /dev/null +++ b/sysbench/tests/db/select.lua @@ -0,0 +1,110 @@ +function prepare() + local query + local i + + set_vars() + + db_connect() + + print("Creating table 'sbtest'...") + + if (db_driver == "mysql") then + query = [[ + CREATE TABLE sbtest ( + id INTEGER UNSIGNED NOT NULL ]] .. ((oltp_auto_inc and "AUTO_INCREMENT") or "") .. [[, + k INTEGER UNSIGNED DEFAULT '0' NOT NULL, + c CHAR(120) DEFAULT '' NOT NULL, + pad CHAR(60) DEFAULT '' NOT NULL, + PRIMARY KEY (id) + ) /*! ENGINE = ]] .. mysql_table_engine .. " MAX_ROWS = " .. myisam_max_rows .. " */" + + elseif (db_driver == "oracle") then + query = [[ + CREATE TABLE sbtest ( + id INTEGER NOT NULL, + k INTEGER, + c CHAR(120) DEFAULT '' NOT NULL, + pad CHAR(60 DEFAULT '' NOT NULL, + PRIMARY KEY (id) + ) ]] + + + elseif (db_driver == "pgsql") then + query = [[ + CREATE TABLE sbtest ( + id ]] .. (sb.oltp_auto_inc and "SERIAL") or "" .. [[, + k INTEGER DEFAULT '0' NOT NULL, + c CHAR(120) DEFAULT '' NOT NULL, + pad CHAR(60) DEFAULT '' NOT NULL, + PRIMARY KEY (id) + ) ]] + else + print("Unknown database driver: " .. db_driver) + return 1 + end + + db_query(query) + + if (db_driver == "oracle") then + db_query("CREATE SEQUENCE sbtest_seq") + db_query([[CREATE TRIGGER sbtest_trig BEFORE INSERT ON sbtest + FOR EACH ROW BEGIN SELECT sbtest_seq.nextval INTO :new.id FROM DUAL; END;]]) + end + + db_query("CREATE INDEX k on sbtest(k)") + + print("Inserting " .. oltp_table_size .. " records into 'sbtest'") + + if (oltp_auto_inc) then + db_bulk_insert_init("INSERT INTO sbtest(k, c, pad) VALUES") + else + db_bulk_insert_init("INSERT INTO sbtest(id, k, c, pad) VALUES") + end + + for i = 1,oltp_table_size do + if (oltp_auto_inc) then + db_bulk_insert_next("(0, ' ', 'qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt')") + else + db_bulk_insert_next("("..i..",0,' ','qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt')") + end + end + + db_bulk_insert_done() + + return 0 +end + +function cleanup() + print("Dropping table 'sbtest'...") + db_query("DROP TABLE sbtest") +end + +function thread_init(thread_id) + local query + + set_vars() + + stmt = db_prepare([[ + SELECT pad FROM sbtest WHERE id = ? + ]]) + params = {0} + db_bind_param(stmt, params) +end + +function event(thread_id) + local rs + params[1] = sb_rand(1, oltp_table_size) + rs = db_execute(stmt) + db_store_results(rs) + db_free_results(rs) +end + +function set_vars() + oltp_table_size = oltp_table_size or 10000 + + if (oltp_auto_inc == 'off') then + oltp_auto_inc = false + else + oltp_auto_inc = true + end +end \ No newline at end of file diff --git a/sysbench/tests/db/update_index.lua b/sysbench/tests/db/update_index.lua new file mode 100644 index 0000000..4e27ab5 --- /dev/null +++ b/sysbench/tests/db/update_index.lua @@ -0,0 +1,108 @@ +function prepare() + local query + local i + + set_vars() + + db_connect() + + print("Creating table 'sbtest'...") + + if (db_driver == "mysql") then + query = [[ + CREATE TABLE sbtest ( + id INTEGER UNSIGNED NOT NULL ]] .. ((oltp_auto_inc and "AUTO_INCREMENT") or "") .. [[, + k INTEGER UNSIGNED DEFAULT '0' NOT NULL, + c CHAR(120) DEFAULT '' NOT NULL, + pad CHAR(60) DEFAULT '' NOT NULL, + PRIMARY KEY (id) + ) /*! ENGINE = ]] .. mysql_table_engine .. " MAX_ROWS = " .. myisam_max_rows .. " */" + + elseif (db_driver == "oracle") then + query = [[ + CREATE TABLE sbtest ( + id INTEGER NOT NULL, + k INTEGER, + c CHAR(120) DEFAULT '' NOT NULL, + pad CHAR(60 DEFAULT '' NOT NULL, + PRIMARY KEY (id) + ) ]] + + + elseif (db_driver == "pgsql") then + query = [[ + CREATE TABLE sbtest ( + id ]] .. (sb.oltp_auto_inc and "SERIAL") or "" .. [[, + k INTEGER DEFAULT '0' NOT NULL, + c CHAR(120) DEFAULT '' NOT NULL, + pad CHAR(60) DEFAULT '' NOT NULL, + PRIMARY KEY (id) + ) ]] + else + print("Unknown database driver: " .. db_driver) + return 1 + end + + db_query(query) + + if (db_driver == "oracle") then + db_query("CREATE SEQUENCE sbtest_seq") + db_query([[CREATE TRIGGER sbtest_trig BEFORE INSERT ON sbtest + FOR EACH ROW BEGIN SELECT sbtest_seq.nextval INTO :new.id FROM DUAL; END;]]) + end + + db_query("CREATE INDEX k on sbtest(k)") + + print("Inserting " .. oltp_table_size .. " records into 'sbtest'") + + if (oltp_auto_inc) then + db_bulk_insert_init("INSERT INTO sbtest(k, c, pad) VALUES") + else + db_bulk_insert_init("INSERT INTO sbtest(id, k, c, pad) VALUES") + end + + for i = 1,oltp_table_size do + if (oltp_auto_inc) then + db_bulk_insert_next("(0, ' ', 'qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt')") + else + db_bulk_insert_next("("..i..",0,' ','qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt')") + end + end + + db_bulk_insert_done() + + return 0 +end + +function cleanup() + print("Dropping table 'sbtest'...") + db_query("DROP TABLE sbtest") +end + +function thread_init(thread_id) + local query + + set_vars() + + stmt = db_prepare([[ + UPDATE sbtest SET k=k+1 WHERE id = ? + ]]) + params = {0} + db_bind_param(stmt, params) +end + +function event(thread_id) + local rs + params[1] = sb_rand(1, oltp_table_size) + rs = db_execute(stmt) +end + +function set_vars() + oltp_table_size = oltp_table_size or 10000 + + if (oltp_auto_inc == 'off') then + oltp_auto_inc = false + else + oltp_auto_inc = true + end +end \ No newline at end of file diff --git a/sysbench/tests/db/update_non_index.lua b/sysbench/tests/db/update_non_index.lua new file mode 100644 index 0000000..a2d6920 --- /dev/null +++ b/sysbench/tests/db/update_non_index.lua @@ -0,0 +1,110 @@ +function prepare() + local query + local i + + set_vars() + + db_connect() + + print("Creating table 'sbtest'...") + + if (db_driver == "mysql") then + query = [[ + CREATE TABLE sbtest ( + id INTEGER UNSIGNED NOT NULL ]] .. ((oltp_auto_inc and "AUTO_INCREMENT") or "") .. [[, + k INTEGER UNSIGNED DEFAULT '0' NOT NULL, + c CHAR(120) DEFAULT '' NOT NULL, + pad CHAR(60) DEFAULT '' NOT NULL, + PRIMARY KEY (id) + ) /*! ENGINE = ]] .. mysql_table_engine .. " MAX_ROWS = " .. myisam_max_rows .. " */" + + elseif (db_driver == "oracle") then + query = [[ + CREATE TABLE sbtest ( + id INTEGER NOT NULL, + k INTEGER, + c CHAR(120) DEFAULT '' NOT NULL, + pad CHAR(60 DEFAULT '' NOT NULL, + PRIMARY KEY (id) + ) ]] + + + elseif (db_driver == "pgsql") then + query = [[ + CREATE TABLE sbtest ( + id ]] .. (sb.oltp_auto_inc and "SERIAL") or "" .. [[, + k INTEGER DEFAULT '0' NOT NULL, + c CHAR(120) DEFAULT '' NOT NULL, + pad CHAR(60) DEFAULT '' NOT NULL, + PRIMARY KEY (id) + ) ]] + else + print("Unknown database driver: " .. db_driver) + return 1 + end + + db_query(query) + + if (db_driver == "oracle") then + db_query("CREATE SEQUENCE sbtest_seq") + db_query([[CREATE TRIGGER sbtest_trig BEFORE INSERT ON sbtest + FOR EACH ROW BEGIN SELECT sbtest_seq.nextval INTO :new.id FROM DUAL; END;]]) + end + + db_query("CREATE INDEX k on sbtest(k)") + + print("Inserting " .. oltp_table_size .. " records into 'sbtest'") + + if (oltp_auto_inc) then + db_bulk_insert_init("INSERT INTO sbtest(k, c, pad) VALUES") + else + db_bulk_insert_init("INSERT INTO sbtest(id, k, c, pad) VALUES") + end + + for i = 1,oltp_table_size do + if (oltp_auto_inc) then + db_bulk_insert_next("(0, ' ', 'qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt')") + else + db_bulk_insert_next("("..i..",0,' ','qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt')") + end + end + + db_bulk_insert_done() + + return 0 +end + +function cleanup() + print("Dropping table 'sbtest'...") + db_query("DROP TABLE sbtest") +end + +function thread_init(thread_id) + local query + + set_vars() + + stmt = db_prepare([[ + UPDATE %s set c=? where id=? + ]]) + params = {"", 0} + db_bind_param(stmt, params) +end + +function event(thread_id) + local rs + params[1] = sb_rnd() .. '-'..sb_rnd()..'-'..sb_rnd()..'-'..sb_rnd() .. '-' .. + sb_rnd()..'-'..sb_rnd()..'-'..sb_rnd()..'-'..sb_rnd()..'-'..sb_rnd()..'-'..sb_rnd() + params[2] = sb_rand(1, oltp_table_size) + rs = db_execute(stmt) +end + +function set_vars() + oltp_table_size = oltp_table_size or 10000 + + if (oltp_auto_inc == 'off') then + oltp_auto_inc = false + else + oltp_auto_inc = true + end +end \ No newline at end of file diff --git a/sysbench/tests/fileio/Makefile.in b/sysbench/tests/fileio/Makefile.in index ae27838..a6d3f89 100644 --- a/sysbench/tests/fileio/Makefile.in +++ b/sysbench/tests/fileio/Makefile.in @@ -133,6 +133,8 @@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ +LUA_CPPFLAGS = @LUA_CPPFLAGS@ +LUA_LDFLAGS = @LUA_LDFLAGS@ MAKEINFO = @MAKEINFO@ MYSQL_CFLAGS = @MYSQL_CFLAGS@ MYSQL_LIBS = @MYSQL_LIBS@ @@ -157,6 +159,8 @@ SHELL = @SHELL@ STRIP = @STRIP@ USE_AIO_FALSE = @USE_AIO_FALSE@ USE_AIO_TRUE = @USE_AIO_TRUE@ +USE_LUA_FALSE = @USE_LUA_FALSE@ +USE_LUA_TRUE = @USE_LUA_TRUE@ USE_MYSQL_FALSE = @USE_MYSQL_FALSE@ USE_MYSQL_TRUE = @USE_MYSQL_TRUE@ USE_ORACLE_FALSE = @USE_ORACLE_FALSE@ @@ -204,6 +208,7 @@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localstatedir = @localstatedir@ +luaconfig = @luaconfig@ mandir = @mandir@ mkdir_p = @mkdir_p@ mysqlconfig = @mysqlconfig@ diff --git a/sysbench/tests/fileio/sb_fileio.c b/sysbench/tests/fileio/sb_fileio.c index abe69ec..cf717a3 100644 --- a/sysbench/tests/fileio/sb_fileio.c +++ b/sysbench/tests/fileio/sb_fileio.c @@ -589,7 +589,6 @@ int file_execute_request(sb_request_t *sb_req, int thread_id) fd, (long long)file_req->pos); return 1; } - LOG_EVENT_STOP(msg, thread_id); /* Check if we have to fsync each write operation */ if (file_fsync_all) @@ -601,6 +600,8 @@ int file_execute_request(sb_request_t *sb_req, int thread_id) } } + LOG_EVENT_STOP(msg, thread_id); + SB_THREAD_MUTEX_LOCK(); write_ops++; real_write_ops++; diff --git a/sysbench/tests/memory/Makefile.in b/sysbench/tests/memory/Makefile.in index 6e66131..4bf6757 100644 --- a/sysbench/tests/memory/Makefile.in +++ b/sysbench/tests/memory/Makefile.in @@ -132,6 +132,8 @@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ +LUA_CPPFLAGS = @LUA_CPPFLAGS@ +LUA_LDFLAGS = @LUA_LDFLAGS@ MAKEINFO = @MAKEINFO@ MYSQL_CFLAGS = @MYSQL_CFLAGS@ MYSQL_LIBS = @MYSQL_LIBS@ @@ -156,6 +158,8 @@ SHELL = @SHELL@ STRIP = @STRIP@ USE_AIO_FALSE = @USE_AIO_FALSE@ USE_AIO_TRUE = @USE_AIO_TRUE@ +USE_LUA_FALSE = @USE_LUA_FALSE@ +USE_LUA_TRUE = @USE_LUA_TRUE@ USE_MYSQL_FALSE = @USE_MYSQL_FALSE@ USE_MYSQL_TRUE = @USE_MYSQL_TRUE@ USE_ORACLE_FALSE = @USE_ORACLE_FALSE@ @@ -203,6 +207,7 @@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localstatedir = @localstatedir@ +luaconfig = @luaconfig@ mandir = @mandir@ mkdir_p = @mkdir_p@ mysqlconfig = @mysqlconfig@ diff --git a/sysbench/tests/mutex/Makefile.in b/sysbench/tests/mutex/Makefile.in index 604aee0..9a4695a 100644 --- a/sysbench/tests/mutex/Makefile.in +++ b/sysbench/tests/mutex/Makefile.in @@ -132,6 +132,8 @@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ +LUA_CPPFLAGS = @LUA_CPPFLAGS@ +LUA_LDFLAGS = @LUA_LDFLAGS@ MAKEINFO = @MAKEINFO@ MYSQL_CFLAGS = @MYSQL_CFLAGS@ MYSQL_LIBS = @MYSQL_LIBS@ @@ -156,6 +158,8 @@ SHELL = @SHELL@ STRIP = @STRIP@ USE_AIO_FALSE = @USE_AIO_FALSE@ USE_AIO_TRUE = @USE_AIO_TRUE@ +USE_LUA_FALSE = @USE_LUA_FALSE@ +USE_LUA_TRUE = @USE_LUA_TRUE@ USE_MYSQL_FALSE = @USE_MYSQL_FALSE@ USE_MYSQL_TRUE = @USE_MYSQL_TRUE@ USE_ORACLE_FALSE = @USE_ORACLE_FALSE@ @@ -203,6 +207,7 @@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localstatedir = @localstatedir@ +luaconfig = @luaconfig@ mandir = @mandir@ mkdir_p = @mkdir_p@ mysqlconfig = @mysqlconfig@ diff --git a/sysbench/tests/oltp/Makefile.in b/sysbench/tests/oltp/Makefile.in index b47c3f1..eeb6e6d 100644 --- a/sysbench/tests/oltp/Makefile.in +++ b/sysbench/tests/oltp/Makefile.in @@ -132,6 +132,8 @@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ +LUA_CPPFLAGS = @LUA_CPPFLAGS@ +LUA_LDFLAGS = @LUA_LDFLAGS@ MAKEINFO = @MAKEINFO@ MYSQL_CFLAGS = @MYSQL_CFLAGS@ MYSQL_LIBS = @MYSQL_LIBS@ @@ -156,6 +158,8 @@ SHELL = @SHELL@ STRIP = @STRIP@ USE_AIO_FALSE = @USE_AIO_FALSE@ USE_AIO_TRUE = @USE_AIO_TRUE@ +USE_LUA_FALSE = @USE_LUA_FALSE@ +USE_LUA_TRUE = @USE_LUA_TRUE@ USE_MYSQL_FALSE = @USE_MYSQL_FALSE@ USE_MYSQL_TRUE = @USE_MYSQL_TRUE@ USE_ORACLE_FALSE = @USE_ORACLE_FALSE@ @@ -203,6 +207,7 @@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localstatedir = @localstatedir@ +luaconfig = @luaconfig@ mandir = @mandir@ mkdir_p = @mkdir_p@ mysqlconfig = @mysqlconfig@ diff --git a/sysbench/tests/oltp/sb_oltp.c b/sysbench/tests/oltp/sb_oltp.c index 5a9ec4d..eae49c6 100644 --- a/sysbench/tests/oltp/sb_oltp.c +++ b/sysbench/tests/oltp/sb_oltp.c @@ -25,9 +25,6 @@ #define GET_RANDOM_ID() ((*rnd_func)()) -/* How many rows to insert in a single query (used for test DB creation) */ -#define INSERT_ROWS 10000 - /* How many rows to insert before COMMITs (used for test DB creation) */ #define ROWS_BEFORE_COMMIT 1000 @@ -272,7 +269,14 @@ static int prepare_stmt_set_nontrx(oltp_stmt_set_t *, oltp_bind_set_t *, db_conn static int prepare_stmt_set_sp(oltp_stmt_set_t *, oltp_bind_set_t *, db_conn_t *); /* Close a set of statements */ -void close_stmt_set(oltp_stmt_set_t *set); +static void close_stmt_set(oltp_stmt_set_t *set); + +/* Initialize connection with a given number */ +static int oltp_connection_init(unsigned int id); + +/* Close connection with a given number */ +int oltp_connection_done(unsigned int id); + int register_test_oltp(sb_list_t *tests) { @@ -298,15 +302,8 @@ int oltp_cmd_help(void) int oltp_cmd_prepare(void) { db_conn_t *con; - char *query = NULL; - unsigned int query_len; + char query[MAX_QUERY_LEN]; unsigned int i; - unsigned int j; - unsigned int n; - unsigned long nrows; - unsigned long commit_cntr = 0; - char insert_str[MAX_QUERY_LEN]; - char *pos; char *table_options_str; if (parse_arguments()) @@ -324,33 +321,10 @@ int oltp_cmd_prepare(void) if (con == NULL) return 1; - /* Determine if database supports multiple row inserts */ - if (driver_caps.multi_rows_insert) - nrows = INSERT_ROWS; - else - nrows = 1; - - /* Prepare statement buffer */ - if (args.auto_inc) - snprintf(insert_str, sizeof(insert_str), - "(0,' ','qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt')"); - else - snprintf(insert_str, sizeof(insert_str), - "(%d,0,' ','qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt')", - args.table_size); - - query_len = MAX_QUERY_LEN + nrows * (strlen(insert_str) + 1); - query = (char *)malloc(query_len); - if (query == NULL) - { - log_text(LOG_FATAL, "memory allocation failure!"); - goto error; - } - /* Create test table */ log_text(LOG_NOTICE, "Creating table '%s'...", args.table_name); table_options_str = driver_caps.table_options_str; - snprintf(query, query_len, + snprintf(query, MAX_QUERY_LEN, "CREATE TABLE %s (" "id %s %s NOT NULL %s, " "k integer %s DEFAULT '0' NOT NULL, " @@ -387,7 +361,7 @@ int oltp_cmd_prepare(void) } /* Create secondary index on 'k' */ - snprintf(query, query_len, + snprintf(query, MAX_QUERY_LEN, "CREATE INDEX k on %s(k)", args.table_name); if (db_query(con, query) == NULL) @@ -395,92 +369,46 @@ int oltp_cmd_prepare(void) log_text(LOG_FATAL, "failed to create secondary index on table!"); goto error; } + /* Fill test table with data */ log_text(LOG_NOTICE, "Creating %d records in table '%s'...", args.table_size, args.table_name); - for (i = 0; i < args.table_size; i += nrows) + if (args.auto_inc) + snprintf(query, MAX_QUERY_LEN, "INSERT INTO %s(k, c, pad) VALUES", + args.table_name); + else + snprintf(query, MAX_QUERY_LEN, "INSERT INTO %s(id, k, c, pad) VALUES ", + args.table_name); + + if (db_bulk_insert_init(con, query)) { - /* Build query */ - if (args.auto_inc) - n = snprintf(query, query_len, "INSERT INTO %s(k, c, pad) VALUES ", - args.table_name); - else - n = snprintf(query, query_len, "INSERT INTO %s(id, k, c, pad) VALUES ", - args.table_name); - if (n >= query_len) - { - log_text(LOG_FATAL, "query is too long!"); - goto error; - } - pos = query + n; - for (j = 0; j < nrows; j++) - { - if ((unsigned)(pos - query) >= query_len) - { - log_text(LOG_FATAL, "query is too long!"); - goto error; - } - - /* Form the values string when if are not using auto_inc */ - if (!args.auto_inc) - snprintf(insert_str, sizeof(insert_str), - "(%d,0,' ','qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt')", - i + j + 1); - - if (j == nrows - 1 || i+j == args.table_size -1) - n = snprintf(pos, query_len - (pos - query), "%s", insert_str); - else - n = snprintf(pos, query_len - (pos - query), "%s,", insert_str); - if (n >= query_len - (pos - query)) - { - log_text(LOG_FATAL, "query is too long!"); - goto error; - } - if (i+j == args.table_size - 1) - break; - pos += n; - } - - /* Execute query */ - if (db_query(con, query) == NULL) - { - log_text(LOG_FATAL, "failed to create test table!"); - goto error; - } - - if (driver_caps.needs_commit) - { - commit_cntr += nrows; - if (commit_cntr >= ROWS_BEFORE_COMMIT) - { - if (db_query(con, "COMMIT") == NULL) - { - log_text(LOG_FATAL, "failed to commit inserted rows!"); - goto error; - } - commit_cntr -= ROWS_BEFORE_COMMIT; - } - } + log_text(LOG_FATAL, "Failed to initialize insert operation"); + return 1; } - if (driver_caps.needs_commit && db_query(con, "COMMIT") == NULL) + if (args.auto_inc) + snprintf(query, MAX_QUERY_LEN, + "(0,' ','qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt')"); + + for (i = 0; i < args.table_size; i++) { - if (db_query(con, "COMMIT") == NULL) - { - log_text(LOG_FATAL, "failed to commit inserted rows!"); + if (!args.auto_inc) + snprintf(query, MAX_QUERY_LEN, + "(%d,0,' ','qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt')", + i+1); + if (db_bulk_insert_next(con, query)) return 1; - } } + db_bulk_insert_done(con); + oltp_disconnect(con); return 0; error: oltp_disconnect(con); - if (query != NULL) - free(query); return 1; } diff --git a/sysbench/tests/threads/Makefile.in b/sysbench/tests/threads/Makefile.in index e91f24c..7d870da 100644 --- a/sysbench/tests/threads/Makefile.in +++ b/sysbench/tests/threads/Makefile.in @@ -132,6 +132,8 @@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ +LUA_CPPFLAGS = @LUA_CPPFLAGS@ +LUA_LDFLAGS = @LUA_LDFLAGS@ MAKEINFO = @MAKEINFO@ MYSQL_CFLAGS = @MYSQL_CFLAGS@ MYSQL_LIBS = @MYSQL_LIBS@ @@ -156,6 +158,8 @@ SHELL = @SHELL@ STRIP = @STRIP@ USE_AIO_FALSE = @USE_AIO_FALSE@ USE_AIO_TRUE = @USE_AIO_TRUE@ +USE_LUA_FALSE = @USE_LUA_FALSE@ +USE_LUA_TRUE = @USE_LUA_TRUE@ USE_MYSQL_FALSE = @USE_MYSQL_FALSE@ USE_MYSQL_TRUE = @USE_MYSQL_TRUE@ USE_ORACLE_FALSE = @USE_ORACLE_FALSE@ @@ -203,6 +207,7 @@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localstatedir = @localstatedir@ +luaconfig = @luaconfig@ mandir = @mandir@ mkdir_p = @mkdir_p@ mysqlconfig = @mysqlconfig@