1
/* Copyright (C) 2004 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
/* get time since epoc in 100 nanosec units */
17
/* thus to get the current time we should use the system function
18
with the highest possible resolution */
21
TODO: in functions my_micro_time() and my_micro_time_and_time() there
22
exists some common code that should be merged into a function.
26
#include "drizzled/drizzle_time.h"
28
#if TIME_WITH_SYS_TIME
29
# include <sys/time.h>
33
# include <sys/time.h>
42
uint64_t my_getsystime()
44
#ifdef HAVE_CLOCK_GETTIME
46
clock_gettime(CLOCK_REALTIME, &tp);
47
return (uint64_t)tp.tv_sec*10000000+(uint64_t)tp.tv_nsec/100;
49
/* TODO: check for other possibilities for hi-res timestamping */
51
gettimeofday(&tv,NULL);
52
return (uint64_t)tv.tv_sec*10000000+(uint64_t)tv.tv_usec*10;
57
Return time in micro seconds
63
This function is to be used to measure performance in micro seconds.
64
As it's not defined whats the start time for the clock, this function
65
us only useful to measure time between two moments.
67
For windows platforms we need the frequency value of the CUP. This is
68
initalized in my_init.c through QueryPerformanceFrequency().
70
If Windows platform doesn't support QueryPerformanceFrequency() we will
71
obtain the time via GetClockCount, which only supports milliseconds.
74
Value in microseconds from some undefined point in time
77
uint64_t my_micro_time()
79
#if defined(HAVE_GETHRTIME)
80
return gethrtime()/1000;
85
The following loop is here because gettimeofday may fail on some systems
87
while (gettimeofday(&t, NULL) != 0)
89
newtime= (uint64_t)t.tv_sec * 1000000 + t.tv_usec;
91
#endif /* defined(HAVE_GETHRTIME) */
96
Return time in seconds and timer in microseconds (not different start!)
99
my_micro_time_and_time()
100
time_arg Will be set to seconds since epoch (00:00:00 UTC,
104
This function is to be useful when we need both the time and microtime.
105
For example in MySQL this is used to get the query time start of a query
106
and to measure the time of a query (for the slow query log)
109
Value of time is as in time() call.
110
Value of microtime is same as my_micro_time(), which may be totally
114
Value in microseconds from some undefined point in time
118
uint64_t my_micro_time_and_time(time_t *time_arg)
123
The following loop is here because gettimeofday may fail on some systems
125
while (gettimeofday(&t, NULL) != 0) {}
127
newtime= (uint64_t)t.tv_sec * 1000000 + t.tv_usec;
132
} /* namespace drizzled */