diff -r -N --unified=3 -dp mysql-4.0.17-orig/config.h.in mysql-4.0.17/config.h.in --- config.h.in Fri Feb 6 18:55:05 2004 +++ config.h.in Fri Feb 6 18:55:49 2004 @@ -516,6 +516,9 @@ /* Define to 1 if you have the `mlockall' function. */ #undef HAVE_MLOCKALL +/* Define to 1 if you have the 'gettimeofday' function. */ +#undef HAVE_GETTIMEOFDAY + /* Define to 1 if you have a working `mmap' system call. */ #undef HAVE_MMAP diff -r -N --unified=3 -dp mysql-4.0.17-orig/configure mysql-4.0.17/configure --- configure Fri Feb 6 18:55:05 2004 +++ configure Fri Feb 6 18:57:03 2004 @@ -1145,7 +1145,7 @@ esac # Don't blindly perform a `cd "$ac_dir"/$ac_foo && pwd` since $ac_foo can be # absolute. ac_abs_builddir=`cd "$ac_dir" && cd $ac_builddir && pwd` -ac_abs_top_builddir=`cd "$ac_dir" && cd ${ac_top_builddir}. && pwd` +ac_abs_top_builddir=`cd "$ac_dir" && cd $ac_top_builddir && pwd` ac_abs_srcdir=`cd "$ac_dir" && cd $ac_srcdir && pwd` ac_abs_top_srcdir=`cd "$ac_dir" && cd $ac_top_srcdir && pwd` @@ -1510,8 +1510,6 @@ build_cpu=`echo $ac_cv_build | sed 's/^\ build_vendor=`echo $ac_cv_build | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'` build_os=`echo $ac_cv_build | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'` -test -z "$build_alias" && - build_alias=$ac_cv_build echo "$as_me:$LINENO: checking host system type" >&5 echo $ECHO_N "checking host system type... $ECHO_C" >&6 @@ -1534,8 +1532,6 @@ host_cpu=`echo $ac_cv_host | sed 's/^\([ host_vendor=`echo $ac_cv_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'` host_os=`echo $ac_cv_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'` -test -z "$host_alias" && - host_alias=$ac_cv_host echo "$as_me:$LINENO: checking target system type" >&5 echo $ECHO_N "checking target system type... $ECHO_C" >&6 @@ -1565,9 +1561,6 @@ test -n "$target_alias" && test "$program_prefix$program_suffix$program_transform_name" = \ NONENONEs,x,x, && program_prefix=${target_alias}- -test -z "$target_alias" && - target_alias=$ac_cv_target - # The Docs Makefile.am parses this line! # Find a good install program. We prefer a C program (faster), # so one script is as good as another. But avoid the broken or @@ -4997,7 +4990,7 @@ test "x$enable_libtool_lock" != xno && e case $host in *-*-irix6*) # Find out which ABI we are using. - echo '#line 5000 "configure"' > conftest.$ac_ext + echo '#line 4993 "configure"' > conftest.$ac_ext if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 (eval $ac_compile) 2>&5 ac_status=$? @@ -5536,7 +5529,7 @@ chmod -w . save_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS -o out/conftest2.$ac_objext" compiler_c_o=no -if { (eval echo configure:5539: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>out/conftest.err; } && test -s out/conftest2.$ac_objext; then +if { (eval echo configure:5532: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>out/conftest.err; } && test -s out/conftest2.$ac_objext; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings if test -s out/conftest.err; then @@ -7301,7 +7294,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 @@ -9250,8 +9243,43 @@ fi echo "$as_me:$LINENO: checking \"how to check if pid exists\"" >&5 echo $ECHO_N "checking \"how to check if pid exists\"... $ECHO_C" >&6 PS=$ac_cv_path_PS +# Linux style +if $PS p $$ 2> /dev/null | grep $0 > /dev/null +then + FIND_PROC="$PS p \$\$PID | grep mysqld > /dev/null" +# Solaris +elif $PS -p $$ 2> /dev/null | grep $0 > /dev/null +then + FIND_PROC="$PS -p \$\$PID | grep mysqld > /dev/null" # BSD style +elif $PS -uaxww 2> /dev/null | grep $0 > /dev/null +then FIND_PROC="$PS -uaxww | grep mysqld | grep \" \$\$PID \" > /dev/null" +# SysV style +elif $PS -ef 2> /dev/null | grep $0 > /dev/null +then + FIND_PROC="$PS -ef | grep mysqld | grep \" \$\$PID \" > /dev/null" +# Do anybody use this? +elif $PS $$ 2> /dev/null | grep $0 > /dev/null +then + FIND_PROC="$PS \$\$PID | grep mysqld > /dev/null" +else + case $SYSTEM_TYPE in + *darwin*) + FIND_PROC="$PS -uaxww | grep mysqld | grep \" \$\$PID \" > /dev/null" + ;; + *cygwin*) + FIND_PROC="$PS -e | grep mysqld | grep \" \$\$PID \" > /dev/null" + ;; + *netware* | *modesto*) + FIND_PROC= + ;; + *) + { { echo "$as_me:$LINENO: error: Could not find the right ps switches. Which OS is this ?. See the Installation chapter in the Reference Manual." >&5 +echo "$as_me: error: Could not find the right ps switches. Which OS is this ?. See the Installation chapter in the Reference Manual." >&2;} + { (exit 1); exit 1; }; } + esac +fi echo "$as_me:$LINENO: result: \"$FIND_PROC\"" >&5 echo "${ECHO_T}\"$FIND_PROC\"" >&6 @@ -12633,8 +12661,8 @@ esac # Some system specific hacks # -MAX_C_OPTIMIZE="" -MAX_CXX_OPTIMIZE="" +MAX_C_OPTIMIZE="-O3" +MAX_CXX_OPTIMIZE="-O3" case $SYSTEM_TYPE in *solaris2.7*) @@ -19822,6 +19850,7 @@ done + for ac_func in alarm bmove \ chsize ftruncate rint finite isnan fpsetmask fpresetsticky\ cuserid fcntl fconvert poll \ @@ -19838,7 +19867,7 @@ for ac_func in alarm bmove \ pthread_attr_create pthread_getsequence_np pthread_attr_setstacksize \ pthread_attr_getstacksize \ pthread_condattr_create rwlock_init pthread_rwlock_rdlock \ - fsync fdatasync fchmod getpass getpassphrase initgroups mlockall + fsync fdatasync fchmod getpass getpassphrase gettimeofday initgroups mlockall do as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` echo "$as_me:$LINENO: checking for $ac_func" >&5 @@ -22426,7 +22455,7 @@ EOF /* ) rel_srcdir="$srcdir" ;; * ) rel_srcdir="../$srcdir" ;; esac - if test "x$enable_dependency_tracking" = xno + if test "x$enable_dependency_tracking" == xno then innodb_conf_flags=--disable-dependency-tracking fi @@ -23405,7 +23434,7 @@ esac # Don't blindly perform a `cd "$ac_dir"/$ac_foo && pwd` since $ac_foo can be # absolute. ac_abs_builddir=`cd "$ac_dir" && cd $ac_builddir && pwd` -ac_abs_top_builddir=`cd "$ac_dir" && cd ${ac_top_builddir}. && pwd` +ac_abs_top_builddir=`cd "$ac_dir" && cd $ac_top_builddir && pwd` ac_abs_srcdir=`cd "$ac_dir" && cd $ac_srcdir && pwd` ac_abs_top_srcdir=`cd "$ac_dir" && cd $ac_top_srcdir && pwd` @@ -23758,7 +23787,7 @@ esac # Don't blindly perform a `cd "$ac_dir"/$ac_foo && pwd` since $ac_foo can be # absolute. ac_abs_builddir=`cd "$ac_dir" && cd $ac_builddir && pwd` -ac_abs_top_builddir=`cd "$ac_dir" && cd ${ac_top_builddir}. && pwd` +ac_abs_top_builddir=`cd "$ac_dir" && cd $ac_top_builddir && pwd` ac_abs_srcdir=`cd "$ac_dir" && cd $ac_srcdir && pwd` ac_abs_top_srcdir=`cd "$ac_dir" && cd $ac_top_srcdir && pwd` diff -r -N --unified=3 -dp mysql-4.0.17-orig/configure.in mysql-4.0.17/configure.in --- configure.in Fri Feb 6 18:55:05 2004 +++ configure.in Fri Feb 6 18:55:50 2004 @@ -1817,7 +1817,7 @@ AC_CHECK_FUNCS(alarm bmove \ pthread_attr_create pthread_getsequence_np pthread_attr_setstacksize \ pthread_attr_getstacksize \ pthread_condattr_create rwlock_init pthread_rwlock_rdlock \ - fsync fdatasync fchmod getpass getpassphrase initgroups mlockall) + fsync fdatasync fchmod getpass getpassphrase gettimeofday initgroups mlockall) CFLAGS="$ORG_CFLAGS" diff -r -N --unified=3 -dp mysql-4.0.17-orig/sql/log.cc mysql-4.0.17/sql/log.cc --- sql/log.cc Fri Feb 6 18:53:54 2004 +++ sql/log.cc Fri Feb 6 18:55:50 2004 @@ -1395,10 +1395,17 @@ err: */ bool MYSQL_LOG::write(THD *thd,const char *query, uint query_length, +#ifdef HAVE_GETTIMEOFDAY + struct timeval *query_start_arg) +#else time_t query_start_arg) +#endif { bool error=0; time_t current_time; +#ifdef HAVE_GETTIMEOFDAY + struct timeval current_tv; +#endif if (!is_open()) return 0; VOID(pthread_mutex_lock(&LOCK_log)); @@ -1416,6 +1423,9 @@ bool MYSQL_LOG::write(THD *thd,const cha if ((specialflag & SPECIAL_LONG_LOG_FORMAT) || query_start_arg) { current_time=time(NULL); +#ifdef HAVE_GETTIMEOFDAY + gettimeofday(¤t_tv, NULL); +#endif if (current_time != last_time) { last_time=current_time; @@ -1443,11 +1453,24 @@ bool MYSQL_LOG::write(THD *thd,const cha } if (query_start_arg) { +#ifdef HAVE_GETTIMEOFDAY + struct timeval tv_time = { 0, 0 }; + struct timeval tv_lock = { 0, 0 }; + + timeval_diff(¤t_tv, query_start_arg, &tv_time); + timeval_diff(&(thd->time_after_lock_tv), query_start_arg, &tv_lock); +#endif /* For slow query log */ if (my_b_printf(&log_file, +#ifdef HAVE_GETTIMEOFDAY + "# Query_time: %lu.%03lu Lock_time: %lu.%03lu Rows_sent: %lu Rows_examined: %lu\n", + tv_time.tv_sec, tv_time.tv_usec / 1000, + tv_lock.tv_sec, tv_lock.tv_usec / 1000, +#else "# Query_time: %lu Lock_time: %lu Rows_sent: %lu Rows_examined: %lu\n", (ulong) (current_time - query_start_arg), (ulong) (thd->time_after_lock - query_start_arg), +#endif (ulong) thd->sent_row_count, (ulong) thd->examined_row_count) == (uint) -1) tmp_errno=errno; @@ -1474,11 +1497,18 @@ bool MYSQL_LOG::write(THD *thd,const cha } if (thd->query_start_used) { +#ifdef HAVE_GETTIMEOFDAY + struct timeval tv_start; + + thd->query_start_tv(&tv_start); + if (timeval_diff(query_start_arg, &tv_start, NULL) != 0) +#else if (query_start_arg != thd->query_start()) +#endif { - query_start_arg=thd->query_start(); + MYSQL_LOG::query_start=thd->query_start(); end=strmov(end,",timestamp="); - end=int10_to_str((long) query_start_arg,end,10); + end=int10_to_str((long) MYSQL_LOG::query_start,end,10); } } if (end != buff) diff -r -N --unified=3 -dp mysql-4.0.17-orig/sql/mysql_priv.h mysql-4.0.17/sql/mysql_priv.h --- sql/mysql_priv.h Fri Feb 6 18:53:56 2004 +++ sql/mysql_priv.h Fri Feb 6 18:55:50 2004 @@ -798,6 +798,9 @@ bool str_to_time(const char *str,uint le longlong str_to_datetime(const char *str,uint length,bool fuzzy_date); timestamp_type str_to_TIME(const char *str, uint length, TIME *l_time, bool fuzzy_date); +#ifdef HAVE_GETTIMEOFDAY +int timeval_diff(struct timeval *t1, struct timeval *t0, struct timeval *td); +#endif int test_if_number(char *str,int *res,bool allow_wildcards); void change_byte(byte *,uint,char,char); diff -r -N --unified=3 -dp mysql-4.0.17-orig/sql/mysqld.cc mysql-4.0.17/sql/mysqld.cc --- sql/mysqld.cc Fri Feb 6 18:53:56 2004 +++ sql/mysqld.cc Fri Feb 6 18:55:50 2004 @@ -3837,10 +3837,18 @@ replicating a LOAD DATA INFILE command", REQUIRED_ARG, KEY_CACHE_SIZE, MALLOC_OVERHEAD, (long) ~0, MALLOC_OVERHEAD, IO_SIZE, 0}, {"long_query_time", OPT_LONG_QUERY_TIME, +#ifdef HAVE_GETTIMEOFDAY + "Log all queries that have taken more than long_query_time milliseconds to execute to file.", +#else "Log all queries that have taken more than long_query_time seconds to execute to file.", +#endif (gptr*) &global_system_variables.long_query_time, (gptr*) &max_system_variables.long_query_time, 0, GET_ULONG, +#ifdef HAVE_GETTIMEOFDAY + REQUIRED_ARG, 10000, 1, LONG_TIMEOUT, 0, 1, 0}, +#else REQUIRED_ARG, 10, 1, LONG_TIMEOUT, 0, 1, 0}, +#endif {"lower_case_table_names", OPT_LOWER_CASE_TABLE_NAMES, "If set to 1 table names are stored in lowercase on disk and table names will be case-insensitive.", (gptr*) &lower_case_table_names, diff -r -N --unified=3 -dp mysql-4.0.17-orig/sql/sql_class.h mysql-4.0.17/sql/sql_class.h --- sql/sql_class.h Fri Feb 6 18:53:54 2004 +++ sql/sql_class.h Fri Feb 6 18:55:50 2004 @@ -138,7 +138,11 @@ public: bool write(THD *thd, enum enum_server_command command, const char *format,...); bool write(THD *thd, const char *query, uint query_length, +#ifdef HAVE_GETTIMEOFDAY + struct timeval *query_start=0); +#else time_t query_start=0); +#endif bool write(Log_event* event_info); // binary log write bool write(THD *thd, IO_CACHE *cache, bool commit_or_rollback); @@ -418,6 +422,9 @@ public: will know that the error was in having clause. */ const char *where; +#ifdef HAVE_GETTIMEOFDAY + struct timeval start_time_tv,time_after_lock_tv; +#endif time_t start_time,time_after_lock,user_time; time_t connect_time,thr_create_time; // track down slow pthread_create thr_lock_type update_lock_default; @@ -533,11 +540,66 @@ public: proc_info = old_msg; pthread_mutex_unlock(&mysys_var->mutex); } +#ifdef HAVE_GETTIMEOFDAY + inline void query_start_tv( struct timeval *t ) { query_start_used=1; if (t) *t = start_time_tv; } +#endif inline time_t query_start() { query_start_used=1; return start_time; } - inline void set_time() { if (user_time) start_time=time_after_lock=user_time; else time_after_lock=time(&start_time); } - inline void end_time() { time(&start_time); } - inline void set_time(time_t t) { time_after_lock=start_time=user_time=t; } - inline void lock_time() { time(&time_after_lock); } + + inline void set_time() + { + if (user_time) + { +#ifdef HAVE_GETTIMEOFDAY + start_time_tv.tv_sec = user_time; + start_time_tv.tv_usec = 0; + time_after_lock_tv = start_time_tv; +#endif + start_time = time_after_lock = user_time; + } + else + { +#ifdef HAVE_GETTIMEOFDAY + gettimeofday(&start_time_tv, NULL); + time_after_lock_tv = start_time_tv; +#endif + time_after_lock=time(&start_time); + } + } + inline void end_time() + { +#ifdef HAVE_GETTIMEOFDAY + gettimeofday(&start_time_tv,NULL); +#endif + time(&start_time); + } +#ifdef HAVE_GETTIMEOFDAY + inline void set_time(struct timeval *t) + { + if (t) + { + start_time_tv = *t; + time_after_lock_tv = start_time_tv; + time_after_lock = start_time = user_time = (time_t)t->tv_sec; + } + } +#endif + inline void set_time(time_t t) + { +#ifdef HAVE_GETTIMEOFDAY + start_time_tv.tv_sec = t; + start_time_tv.tv_usec = 0; + time_after_lock_tv = start_time_tv; +#endif + time_after_lock = start_time = user_time = t; + } + inline void lock_time() + { +#ifdef HAVE_GETTIMEOFDAY + gettimeofday(&time_after_lock_tv,NULL); +#endif + time(&time_after_lock); + } + inline void insert_id(ulonglong id) { last_insert_id=id; insert_id_used=1; } inline ulonglong insert_id(void) diff -r -N --unified=3 -dp mysql-4.0.17-orig/sql/sql_parse.cc mysql-4.0.17/sql/sql_parse.cc --- sql/sql_parse.cc Fri Feb 6 18:53:54 2004 +++ sql/sql_parse.cc Fri Feb 6 18:55:50 2004 @@ -1280,16 +1280,30 @@ bool dispatch_command(enum enum_server_c if (thd->fatal_error) send_error(net,0); // End of memory ? - time_t start_of_query=thd->start_time; +#ifdef HAVE_GETTIMEOFDAY + struct timeval start_of_query_tv = thd->start_time_tv; + struct timeval * start_of_query = &start_of_query_tv; +#else + time_t start_of_query=(time_t)thd->start_time; +#endif thd->end_time(); // Set start time /* If not reading from backup and if the query took too long */ if (!slow_command && !thd->user_time) // do not log 'slow_command' queries { +#ifdef HAVE_GETTIMEOFDAY + struct timeval tvdiff = { 0, 0 }; + struct timeval tvlong = { thd->variables.long_query_time/1000, 1000 * (thd->variables.long_query_time%1000) }; +#endif thd->proc_info="logging slow query"; +#ifdef HAVE_GETTIMEOFDAY + timeval_diff(&(thd->start_time_tv), &(thd->time_after_lock_tv), &tvdiff); + if( timeval_diff(&tvdiff, &tvlong, 0) > 0 || +#else if ((ulong) (thd->start_time - thd->time_after_lock) > thd->variables.long_query_time || +#endif ((thd->lex.select_lex.options & (QUERY_NO_INDEX_USED | QUERY_NO_GOOD_INDEX_USED)) && (specialflag & SPECIAL_LONG_LOG_FORMAT))) diff -r -N --unified=3 -dp mysql-4.0.17-orig/sql/time.cc mysql-4.0.17/sql/time.cc --- sql/time.cc Fri Feb 6 18:53:53 2004 +++ sql/time.cc Fri Feb 6 18:55:50 2004 @@ -604,3 +604,59 @@ bool str_to_time(const char *str,uint le } return 0; } + + +/***************************************************************************** +** take the difference between two timeval structures (t1 - t0) +** return 0 if t1 = t0 (or neither t1 nor t0 is specified) +** return 1 if t1 > t0 +** return -1 if t1 < t0 +** +** if td is specified (non-null) the difference is stored there +** td may point to the same address as t1 or t0 +*****************************************************************************/ + +#ifdef HAVE_GETTIMEOFDAY +int timeval_diff( struct timeval * t1, struct timeval * t0, struct timeval * td ) +{ + struct timeval tv; + int direction = 0; + + tv.tv_sec = 0; + tv.tv_usec = 0; + + if( !t1 || !t0 ) + { + if( td ) + { + *td = tv; + } + return 0; + } + + tv.tv_sec = t1->tv_sec - t0->tv_sec; + tv.tv_usec = t1->tv_usec - t0->tv_usec; + if( tv.tv_usec < 0 ) + { + tv.tv_sec--; + tv.tv_usec += 1000000; + } + + if( tv.tv_sec < 0 ) + { + direction = -1; + } + else if( tv.tv_sec > 0 || tv.tv_usec > 0 ) + { + direction = 1; + } + + if( td ) + { + *td = tv; + } + + return direction; +} +#endif +