diff --unified -r1.1 -r1.2 --- configure.in 2001/03/21 00:03:52 1.1 +++ configure.in 2001/04/09 18:44:16 1.2 @@ -1301,7 +1301,8 @@ pthread_setschedparam pthread_attr_setprio pthread_attr_setschedparam \ pthread_attr_create pthread_getsequence_np pthread_attr_setstacksize \ pthread_condattr_create rwlock_init pthread_rwlock_rdlock \ - dlopen dlerror fchmod getpass getpassphrase initgroups mlockall) + dlopen dlerror fchmod getpass getpassphrase initgroups mlockall \ + gettimeofday) # Sanity check: We chould not have any fseeko symbol unless # large_file_support=yes diff --unified -r1.1 -r1.2 --- config.h.in 2001/03/21 00:03:52 1.1 +++ config.h.in 2001/04/09 18:44:16 1.2 @@ -393,6 +393,9 @@ /* Define if you have the mlockall function. */ #undef HAVE_MLOCKALL +/* Define if you have the gettimeofday function. */ +#undef HAVE_GETTIMEOFDAY + /* Define if you have the perror function. */ #undef HAVE_PERROR diff --unified -r1.1 -r1.2 --- sql/log.cc 2001/03/21 00:10:56 1.1 +++ sql/log.cc 2001/04/09 18:47:49 1.2 @@ -775,12 +775,19 @@ /* Write update log in a format suitable for incremental backup */ bool MYSQL_LOG::write(THD *thd,const char *query, uint query_length, +#ifdef HAVE_GETTIMEOFDAY + struct timeval *query_start) +#else time_t query_start) +#endif { bool error=0; if (is_open()) { time_t current_time; +#ifdef HAVE_GETTIMEOFDAY + struct timeval current_tv; +#endif VOID(pthread_mutex_lock(&LOCK_log)); if (is_open()) { // Safety agains reopen @@ -796,6 +803,9 @@ if ((specialflag & SPECIAL_LONG_LOG_FORMAT) || query_start) { current_time=time(NULL); +#ifdef HAVE_GETTIMEOFDAY + gettimeofday(¤t_tv, NULL); +#endif if (current_time != last_time) { last_time=current_time; @@ -823,11 +833,24 @@ } if (query_start) { +#ifdef HAVE_GETTIMEOFDAY + struct timeval tv_time = { 0, 0 }; + struct timeval tv_lock = { 0, 0 }; + + timeval_diff(¤t_tv, query_start, &tv_time); + timeval_diff(&(thd->time_after_lock_tv), query_start, &tv_lock); +#endif /* For slow query log */ if (my_b_printf(&log_file, +#ifdef HAVE_GETTIMEOFDAY + "# Time: %lu.%03lu Lock_time: %lu.%03lu Rows_sent: %lu\n", + tv_time.tv_sec, tv_time.tv_usec / 1000, + tv_lock.tv_sec, tv_lock.tv_usec / 1000, +#else "# Time: %lu Lock_time: %lu Rows_sent: %lu\n", (ulong) (current_time - query_start), (ulong) (thd->time_after_lock - query_start), +#endif (ulong) thd->sent_row_count) == (uint) -1) tmp_errno=errno; } @@ -853,11 +876,18 @@ } if (thd->query_start_used) { +#ifdef HAVE_GETTIMEOFDAY + struct timeval tv_start; + + thd->query_start_tv(&tv_start); + if (timeval_diff(query_start, &tv_start, NULL) != 0) +#else if (query_start != thd->query_start()) +#endif { - query_start=thd->query_start(); + MYSQL_LOG::query_start=thd->query_start(); end=strmov(end,",timestamp="); - end=int10_to_str((long) query_start,end,10); + end=int10_to_str((long) MYSQL_LOG::query_start,end,10); } } if (end != buff) diff --unified -r1.1 -r1.2 --- sql/mysqld.cc 2001/03/21 00:10:57 1.1 +++ sql/mysqld.cc 2001/04/09 18:47:50 1.2 @@ -2620,7 +2620,11 @@ { "key_buffer_size", (long*) &keybuff_size, KEY_CACHE_SIZE, MALLOC_OVERHEAD, (long) ~0, MALLOC_OVERHEAD, IO_SIZE }, { "long_query_time", (long*) &long_query_time, +#ifdef HAVE_GETTIMEOFDAY + 10000, 1, ~0L, 0, 1 }, +#else 10, 1, ~0L, 0, 1 }, +#endif { "lower_case_table_names", (long*) &lower_case_table_names, IF_WIN(1,0), 0, 1, 0, 1 }, { "max_allowed_packet", (long*) &max_allowed_packet, diff --unified -r1.1 -r1.3 --- sql/sql_parse.cc 2001/03/21 00:11:01 1.1 +++ sql/sql_parse.cc 2001/04/09 23:08:25 1.3 @@ -1007,15 +1007,29 @@ 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 = { long_query_time/1000, 1000 * (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) > long_query_time || +#endif ((thd->lex.options & (QUERY_NO_INDEX_USED | QUERY_NO_GOOD_INDEX_USED)) && (specialflag & SPECIAL_LONG_LOG_FORMAT))) diff --unified -r1.1 -r1.3 --- sql/time.cc 2001/03/21 00:11:03 1.1 +++ sql/time.cc 2001/04/09 23:08:01 1.3 @@ -678,3 +678,59 @@ } 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 + diff --unified -r1.1 -r1.2 --- sql/mysql_priv.h 2001/03/21 00:10:57 1.1 +++ sql/mysql_priv.h 2001/04/09 18:47:50 1.2 @@ -589,6 +589,9 @@ 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 --unified -r1.1 -r1.2 --- sql/sql_class.h 2001/03/21 00:10:59 1.1 +++ sql/sql_class.h 2001/04/09 18:47:50 1.2 @@ -76,7 +76,11 @@ void new_file(void); 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(Query_log_event* event_info); // binary log write bool write(Load_log_event* event_info); bool write(IO_CACHE *cache); @@ -240,6 +244,9 @@ const char *where; char* last_nx_table; // last non-existent table, we need this for replication char* last_nx_db; // database of the last nx table +#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; @@ -303,11 +339,66 @@ 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)