2009-12-10 04:19:51 +01:00
|
|
|
/* Copyright (C) 2004 MySQL AB, 2008-2009 Sun Microsystems, Inc
|
2004-03-02 22:21:12 +01:00
|
|
|
|
|
|
|
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
|
2006-12-23 20:17:15 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2004-03-02 22:21:12 +01:00
|
|
|
|
|
|
|
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 */
|
|
|
|
|
|
|
|
/* get time since epoc in 100 nanosec units */
|
|
|
|
/* thus to get the current time we should use the system function
|
|
|
|
with the highest possible resolution */
|
|
|
|
|
2007-11-08 12:25:26 +01:00
|
|
|
/*
|
|
|
|
TODO: in functions my_micro_time() and my_micro_time_and_time() there
|
|
|
|
exists some common code that should be merged into a function.
|
|
|
|
*/
|
|
|
|
|
2007-08-01 21:59:05 +02:00
|
|
|
#include "mysys_priv.h"
|
|
|
|
#include "my_static.h"
|
|
|
|
|
2004-03-05 00:59:04 +01:00
|
|
|
#ifdef __NETWARE__
|
|
|
|
#include <nks/time.h>
|
|
|
|
#endif
|
|
|
|
|
2004-03-02 22:21:12 +01:00
|
|
|
ulonglong my_getsystime()
|
|
|
|
{
|
|
|
|
#ifdef HAVE_CLOCK_GETTIME
|
|
|
|
struct timespec tp;
|
|
|
|
clock_gettime(CLOCK_REALTIME, &tp);
|
|
|
|
return (ulonglong)tp.tv_sec*10000000+(ulonglong)tp.tv_nsec/100;
|
|
|
|
#elif defined(__WIN__)
|
2004-05-05 07:59:17 +02:00
|
|
|
LARGE_INTEGER t_cnt;
|
2007-07-30 10:33:50 +02:00
|
|
|
if (query_performance_frequency)
|
2004-05-05 07:59:17 +02:00
|
|
|
{
|
2004-05-05 15:54:11 +02:00
|
|
|
QueryPerformanceCounter(&t_cnt);
|
2007-10-29 17:18:49 +01:00
|
|
|
return ((t_cnt.QuadPart / query_performance_frequency * 10000000) +
|
2008-02-18 15:47:00 +01:00
|
|
|
((t_cnt.QuadPart % query_performance_frequency) * 10000000 /
|
2007-10-29 17:18:49 +01:00
|
|
|
query_performance_frequency) + query_performance_offset);
|
2004-05-05 07:59:17 +02:00
|
|
|
}
|
2007-08-01 21:59:05 +02:00
|
|
|
return 0;
|
2004-03-05 00:59:04 +01:00
|
|
|
#elif defined(__NETWARE__)
|
|
|
|
NXTime_t tm;
|
|
|
|
NXGetTime(NX_SINCE_1970, NX_NSECONDS, &tm);
|
|
|
|
return (ulonglong)tm/100;
|
2004-03-02 22:21:12 +01:00
|
|
|
#else
|
|
|
|
/* TODO: check for other possibilities for hi-res timestamping */
|
|
|
|
struct timeval tv;
|
|
|
|
gettimeofday(&tv,NULL);
|
|
|
|
return (ulonglong)tv.tv_sec*10000000+(ulonglong)tv.tv_usec*10;
|
|
|
|
#endif
|
|
|
|
}
|
2007-07-30 10:33:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Return current time
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
my_time()
|
|
|
|
flags If MY_WME is set, write error if time call fails
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
time_t my_time(myf flags __attribute__((unused)))
|
|
|
|
{
|
2007-08-01 21:59:05 +02:00
|
|
|
time_t t;
|
2007-07-30 10:33:50 +02:00
|
|
|
#ifdef HAVE_GETHRTIME
|
2007-08-01 21:59:05 +02:00
|
|
|
(void) my_micro_time_and_time(&t);
|
|
|
|
return t;
|
2007-07-30 10:33:50 +02:00
|
|
|
#else
|
|
|
|
/* The following loop is here beacuse time() may fail on some systems */
|
|
|
|
while ((t= time(0)) == (time_t) -1)
|
|
|
|
{
|
|
|
|
if (flags & MY_WME)
|
|
|
|
fprintf(stderr, "%s: Warning: time() call failed\n", my_progname);
|
|
|
|
}
|
|
|
|
return t;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Return time in micro seconds
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
my_micro_time()
|
|
|
|
|
|
|
|
NOTES
|
|
|
|
This function is to be used to measure performance in micro seconds.
|
|
|
|
As it's not defined whats the start time for the clock, this function
|
|
|
|
us only useful to measure time between two moments.
|
|
|
|
|
|
|
|
For windows platforms we need the frequency value of the CUP. This is
|
|
|
|
initalized in my_init.c through QueryPerformanceFrequency().
|
|
|
|
|
|
|
|
If Windows platform doesn't support QueryPerformanceFrequency() we will
|
|
|
|
obtain the time via GetClockCount, which only supports milliseconds.
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
Value in microseconds from some undefined point in time
|
|
|
|
*/
|
|
|
|
|
|
|
|
ulonglong my_micro_time()
|
|
|
|
{
|
|
|
|
#if defined(__WIN__)
|
2008-02-18 15:47:00 +01:00
|
|
|
ulonglong newtime;
|
|
|
|
GetSystemTimeAsFileTime((FILETIME*)&newtime);
|
|
|
|
return (newtime/10);
|
2007-07-30 10:33:50 +02:00
|
|
|
#elif defined(HAVE_GETHRTIME)
|
|
|
|
return gethrtime()/1000;
|
|
|
|
#else
|
2008-02-18 15:47:00 +01:00
|
|
|
ulonglong newtime;
|
2007-07-30 10:33:50 +02:00
|
|
|
struct timeval t;
|
2007-10-29 17:18:49 +01:00
|
|
|
/*
|
|
|
|
The following loop is here because gettimeofday may fail on some systems
|
|
|
|
*/
|
2007-07-30 10:33:50 +02:00
|
|
|
while (gettimeofday(&t, NULL) != 0)
|
|
|
|
{}
|
|
|
|
newtime= (ulonglong)t.tv_sec * 1000000 + t.tv_usec;
|
|
|
|
return newtime;
|
2007-08-01 21:59:05 +02:00
|
|
|
#endif /* defined(__WIN__) */
|
2007-07-30 10:33:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2007-08-01 21:59:05 +02:00
|
|
|
Return time in seconds and timer in microseconds (not different start!)
|
2007-07-30 10:33:50 +02:00
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
my_micro_time_and_time()
|
2007-10-29 17:18:49 +01:00
|
|
|
time_arg Will be set to seconds since epoch (00:00:00 UTC,
|
|
|
|
January 1, 1970)
|
2007-07-30 10:33:50 +02:00
|
|
|
|
|
|
|
NOTES
|
|
|
|
This function is to be useful when we need both the time and microtime.
|
2007-10-29 17:18:49 +01:00
|
|
|
For example in MySQL this is used to get the query time start of a query
|
|
|
|
and to measure the time of a query (for the slow query log)
|
2007-07-30 10:33:50 +02:00
|
|
|
|
|
|
|
IMPLEMENTATION
|
2007-08-01 21:59:05 +02:00
|
|
|
Value of time is as in time() call.
|
2007-10-29 17:18:49 +01:00
|
|
|
Value of microtime is same as my_micro_time(), which may be totally
|
|
|
|
unrealated to time()
|
2007-07-30 10:33:50 +02:00
|
|
|
|
|
|
|
RETURN
|
|
|
|
Value in microseconds from some undefined point in time
|
|
|
|
*/
|
|
|
|
|
WL#5161 : Cross-platform build with CMake
BUILD-CMAKE:
WL#5161 : Documentation on how to build with CMake on Unix/Windows
BUILD/Makefile.am:
Add new file
BUILD/autorun.sh:
WL#5161 : use choose_configure instead of autotools configure script
(choose configure will call cmake if cmake is available)
BUILD/choose_configure.sh:
WL#5161 : use choose_configure instead of autotools configure script
(choose configure will call cmake if cmake is available)
CMakeLists.txt:
WL#5161 : Rewrite top-level CMakeLists.txt.
Remove Windows specifics
- compiler flags handling moved to configure.cmake
- storage engine/plugin stuff moved into cmake/plugin.cmake
- copy docs
Makefile.am:
Added new files
client/CMakeLists.txt:
WL#5161 : Rewrite CMakeLists.txt to be platform-independent
Handle packagng (add INSTALL commands)
cmake/Makefile.am:
WL#5161 : use choose_configure instead of autotools configure script
(choose configure will call cmake if cmake is available)
cmake/abi_check.cmake:
Custom targets for abi_check (for cmake)
cmake/bison.cmake:
- Check bison availability
- Add RUN_BISON macro (used to create sql_yacc.cc and sql_yacc.h)
cmake/cat.cmake:
Add helper script to concatenate files.
cmake/character_sets.cmake:
Handle configuration parameters WITH_EXTRA_CHARSETS
cmake/check_minimal_version.cmake:
Helper script to check the minimum required version of cmake
cmake/configure.pl:
Add perl script to convert ./configure parameters for cmake
cmake/create_initial_db.cmake.in:
Add script helper to create initial database.
(on Windows, we pack initial db with the redistribution
package)
cmake/do_abi_check.cmake:
Perform abi check
cmake/dtrace.cmake:
Handle dtrace in CMake Build.
Check for dtrace availablility,
run dtrace -G on solaris in prelink step
cmake/dtrace_prelink.cmake:
Run dtrace -G on Solaris in pre-link step,
link the object it creates together with library or
executable
cmake/install_macros.cmake:
Helper macros for packaging
(install pdb on Windows, install symlinks on Unix)
cmake/make_dist.cmake.in:
"make dist" -
- pack autotools ./configure script with the source
(renamed to configure.am)
- pack bison output
cmake/merge_archives_unix.cmake.in:
script to merge static libraries on Unix
cmake/misc.cmake:
Build helper macros
- MERGE_STATIC_LIBS
We use it when building client library and embedded
(avoid recompilation)
- Convert source file paths to absolute names.
We use it in to locate files of a different project,
when the files need to be recompiled (e.g in embedded
several storage engines are recompiled with
-DEMBEDDED_LIBRARY)
cmake/mysql_version.cmake:
Extract version info from configure.in
Handle package names.
cmake/plugin.cmake:
Rewrote storage/mysql_storage_engine.cmake to handle
other types of plugins and do it in OS-independent manner.
cmake/readline.cmake:
Macros to handle WITH_READLINE/WITH_LIBEDIT parameters
cmake/ssl.cmake:
Add macros to handle WITH_SSL parameter.
cmake/stack_direction.c:
Helper to check stack direction.
cmake/zlib.cmake:
Add macros to handle WITH_ZLIB parameter
cmd-line-utils/libedit/CMakeLists.txt:
Build libedit with cmake.
cmd-line-utils/libedit/Makefile.am:
Add new file
cmd-line-utils/readline/CMakeLists.txt:
Build readline with CMake.
cmd-line-utils/readline/Makefile.am:
Add new file
config.h.cmake:
WL#5161 : Add config.h template for cmake
configure.cmake:
WL#5161 : Add platform tests ( for cmake)
configure.in:
Added new subdirectories
dbug/CMakeLists.txt:
WL#5161
extra/CMakeLists.txt:
WL#5161
extra/yassl/CMakeLists.txt:
WL#5161
extra/yassl/taocrypt/CMakeLists.txt:
WL#5161
include/Makefile.am:
Add new file
include/keycache.h:
remove configure-win.h and remove HUGE_PTR defined there.
include/my_global.h:
use my_config.h for Windows, not config-win.h anymore
include/my_pthread.h:
- Move thread_safe_increment from config-win.h to other headers
(config-win.h is not used anymore)
- Declare pthread_cancel on Windows (it is used in daemon_example)
include/my_sys.h:
Add malloc.h on Windows (we use -D_WIN32_LEAN_AND_MEAN now, and
with this define malloc.h is not included automatically via windows.h)
include/mysql/plugin.h:
Handle pure-C plugins with Microsoft compiler.
include/thr_alarm.h:
remove rf_SetTimer that used to be defined in config-win.h
Replace with UINT_PTR (we do not use config-win.h anymore
and typedef was needed in this single place only)
libmysql/CMakeLists.txt:
Avoid pointless recompilation of source files
in client library if possible. Merge static
libs (dbug, mysys) to create static client
library.
libmysqld/CMakeLists.txt:
Avoid pointless recompilation of source files
when building embedded. Instead, merge dbug and
mysys (and some other static libs) into embedded.
libmysqld/examples/CMakeLists.txt:
Embedded compilation on Unix
libmysqld/lib_sql.cc:
Do not define THD::clear_error() in lib_sql.cc
for embedded. Instead, use the same inline
definition from sql_class.h as in none-embedded
case (fixes duplicate symbol errors on Windows
and removes pointless #ifdef EMBEDDED)
man/CMakeLists.txt:
Install man files.
man/Makefile.am:
Add new file.
mysql-test/CMakeLists.txt:
Install mysql-test files
mysql-test/Makefile.am:
Add new files
mysql-test/lib/My/ConfigFactory.pm:
Allow testing with mtr in out-of-source builds.
mysql-test/lib/My/Find.pm:
the build configurations are now also available on Unix
Xcode on Mac uses the Release, RelwithDebinfo and Debug
subdirectories for executables. Earlier, build configurations
were available only on Windows.
mysql-test/lib/My/SafeProcess.pm:
Allow testing with mtr in out-of-source builds.
mysql-test/lib/My/SafeProcess/CMakeLists.txt:
Port CMakeLists.txt to Unix
mysql-test/lib/My/SafeProcess/safe_kill_win.cc:
add stdlib.h (to be able to compile with -DWIN32_LEAN_AND_MEAN)
mysql-test/lib/My/SafeProcess/safe_process_win.cc:
Add stdlib.h (to be able to compile with -DWIN32_LEAN_AND_MEAN)
define JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE if not defined
(can happen using MinGW compiler that comes with old SDK)
mysql-test/mtr.out-of-source:
Allow testing with mtr in out-of-source builds.
mysql-test/mysql-test-run.pl:
Allow testing with mtr in out-of-source builds.
Use common find_plugin macro for Windows and unix.
mysql-test/t/fulltext_plugin.test:
This test can now run on Windows as well.
mysys/CMakeLists.txt:
Port CMakeLists.txt to Unix
mysys/my_create.c:
config-win.h is dead => NO_OPEN_3 is never defined.
mysys/my_getsystime.c:
config-win.h is dead => define OFFSET_TO_EPOCH where it is used.
mysys/my_winthread.c:
Add win32 pthread_cancel - used by daemon_example
mysys/mysys_priv.h:
config-win.h is dead => include <sys/stat.h> where it is used
fix prototype of my_win_(f)stat
plugin/daemon_example/CMakeLists.txt:
Compile daemon_example with CMake
plugin/daemon_example/Makefile.am:
Add new file
plugin/fulltext/CMakeLists.txt:
Compile full-text example with CMake
plugin/fulltext/Makefile.am:
Add new file.
plugin/semisync/CMakeLists.txt:
Fix semisync to use common macro for plugins.
regex/CMakeLists.txt:
Use absolute filenames, when adding regex library
(we recompile files in embedded, and want to locate
sources via GET_TARGET_PROPERTY( ... SOURCES ..))
regex/regex2.h:
Remove pointless typedef (produces error with MinGW compiler)
scripts/CMakeLists.txt:
Add configure/install for scripts
sql-bench/CMakeLists.txt:
install sql-bench files
sql-bench/Makefile.am:
Add new file
sql/CMakeLists.txt:
Port CmakeLists.txt to Unix
sql/nt_servc.cc:
compile server with -DWIN32_LEAN_AND_MEAN
sql/share/CMakeLists.txt:
Install charsets
sql/share/Makefile.am:
Add new file
sql/sql_builtin.cc.in:
Handle pure-C plugins on Windows.
sql/sql_class.h:
Use the same clear_error macro in embedded and not embedded.
Fixes pointless #ifdef and avoids duplicate symbols when linking
on Windows.
storage/Makefile.am:
storage/mysql_storage_engine.cmake => cmake/plugin.cmake
storage/archive/CMakeLists.txt:
Add names for static and dynamic plugin libraries.
Link archive with zlib
storage/blackhole/CMakeLists.txt:
Add names for static and dynamic storage
engine libraries
storage/csv/CMakeLists.txt:
Add names for static and dynamic storage engine
libraries
storage/example/CMakeLists.txt:
Add names for static and dynamic storage engine
libraries
storage/federated/CMakeLists.txt:
Add names for static and dynamic storage engine
libraries
storage/heap/CMakeLists.txt:
Add names for static and dynamic storage engine
libraries
storage/ibmdb2i/CMakeLists.txt:
Better port for ibmdb2i plugin
storage/innobase/CMakeLists.txt:
Run system checks.
Add names for static and dynamic storage engine
libraries.
storage/innobase/include/page0page.ic:
Fix compile error on OpenSolaris.
storage/myisam/CMakeLists.txt:
Port CmakeLists.txt to Unix
storage/myisammrg/CMakeLists.txt:
Add names for static and dynamic storage engine
libraries
storage/mysql_storage_engine.cmake:
storage/mysql_storage_engine.cmake => cmake/plugin.cmake
support-files/CMakeLists.txt:
Configure and install some files from support-files.
support-files/Makefile.am:
Add new file
tests/CMakeLists.txt:
In general case, mysqlclient library can be dependent
on C++ runtime(if it includes yassl and is not compiled
with gcc or MSVC)
unittest/mysys/CMakeLists.txt:
Add unit tests
unittest/mysys/Makefile.am:
Add new file
unittest/mytap/CMakeLists.txt:
Add library for unit tests
unittest/mytap/Makefile.am:
Add new file
unittest/mytap/tap.c:
fix function definitions to match declarations
win/create_def_file.js:
Fix link error with intel compiler (icl
defines of special label for exception handler)
2009-11-09 12:32:48 +01:00
|
|
|
#define DELTA_FOR_SECONDS 500000000LL /* Half a second */
|
|
|
|
|
|
|
|
/* Difference between GetSystemTimeAsFileTime() and now() */
|
|
|
|
#define OFFSET_TO_EPOCH 116444736000000000ULL
|
2007-08-01 21:59:05 +02:00
|
|
|
|
2007-07-30 10:33:50 +02:00
|
|
|
ulonglong my_micro_time_and_time(time_t *time_arg)
|
|
|
|
{
|
|
|
|
#if defined(__WIN__)
|
2008-02-18 15:47:00 +01:00
|
|
|
ulonglong newtime;
|
|
|
|
GetSystemTimeAsFileTime((FILETIME*)&newtime);
|
2008-02-26 17:44:04 +01:00
|
|
|
*time_arg= (time_t) ((newtime - OFFSET_TO_EPOCH) / 10000000);
|
2008-02-18 15:47:00 +01:00
|
|
|
return (newtime/10);
|
2007-08-01 21:59:05 +02:00
|
|
|
#elif defined(HAVE_GETHRTIME)
|
|
|
|
/*
|
2007-10-29 17:18:49 +01:00
|
|
|
Solaris has a very slow time() call. We optimize this by using the very
|
|
|
|
fast gethrtime() call and only calling time() every 1/2 second
|
2007-08-01 21:59:05 +02:00
|
|
|
*/
|
|
|
|
static hrtime_t prev_gethrtime= 0;
|
|
|
|
static time_t cur_time= 0;
|
|
|
|
hrtime_t cur_gethrtime;
|
|
|
|
|
2009-12-10 04:19:51 +01:00
|
|
|
mysql_mutex_lock(&THR_LOCK_time);
|
2007-08-01 21:59:05 +02:00
|
|
|
cur_gethrtime= gethrtime();
|
|
|
|
if ((cur_gethrtime - prev_gethrtime) > DELTA_FOR_SECONDS)
|
|
|
|
{
|
|
|
|
cur_time= time(0);
|
|
|
|
prev_gethrtime= cur_gethrtime;
|
|
|
|
}
|
|
|
|
*time_arg= cur_time;
|
2009-12-10 04:19:51 +01:00
|
|
|
mysql_mutex_unlock(&THR_LOCK_time);
|
2007-08-01 21:59:05 +02:00
|
|
|
return cur_gethrtime/1000;
|
2007-07-30 10:33:50 +02:00
|
|
|
#else
|
2008-02-18 15:47:00 +01:00
|
|
|
ulonglong newtime;
|
2007-07-30 10:33:50 +02:00
|
|
|
struct timeval t;
|
2007-10-29 17:18:49 +01:00
|
|
|
/*
|
|
|
|
The following loop is here because gettimeofday may fail on some systems
|
|
|
|
*/
|
2007-07-30 10:33:50 +02:00
|
|
|
while (gettimeofday(&t, NULL) != 0)
|
|
|
|
{}
|
|
|
|
*time_arg= t.tv_sec;
|
|
|
|
newtime= (ulonglong)t.tv_sec * 1000000 + t.tv_usec;
|
|
|
|
return newtime;
|
2007-08-01 21:59:05 +02:00
|
|
|
#endif /* defined(__WIN__) */
|
2007-07-30 10:33:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Returns current time
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
my_time_possible_from_micro()
|
|
|
|
microtime Value from very recent my_micro_time()
|
|
|
|
|
|
|
|
NOTES
|
|
|
|
This function returns the current time. The microtime argument is only used
|
2007-10-29 17:18:49 +01:00
|
|
|
if my_micro_time() uses a function that can safely be converted to the
|
|
|
|
current time.
|
2007-07-30 10:33:50 +02:00
|
|
|
|
|
|
|
RETURN
|
|
|
|
current time
|
|
|
|
*/
|
|
|
|
|
|
|
|
time_t my_time_possible_from_micro(ulonglong microtime __attribute__((unused)))
|
|
|
|
{
|
|
|
|
#if defined(__WIN__)
|
|
|
|
time_t t;
|
|
|
|
while ((t= time(0)) == (time_t) -1)
|
|
|
|
{}
|
|
|
|
return t;
|
|
|
|
#elif defined(HAVE_GETHRTIME)
|
|
|
|
return my_time(0); /* Cached time */
|
|
|
|
#else
|
|
|
|
return (time_t) (microtime / 1000000);
|
|
|
|
#endif /* defined(__WIN__) */
|
|
|
|
}
|
|
|
|
|