~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2004 MySQL AB
2
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.
6
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.
11
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
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 */
19
53.2.4 by Monty Taylor
Changes so that client/ builds cleanly with no warnings.
20
/*
1 by brian
clean slate
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.
23
*/
24
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
25
#include "config.h"
1410.3.4 by Djellel E. Difallah
update references to old my_'s
26
#include "drizzled/drizzle_time.h"
1 by brian
clean slate
27
481.1.15 by Monty Taylor
Removed time.h and sys/time.h from global.h.
28
#if TIME_WITH_SYS_TIME
29
# include <sys/time.h>
30
# include <time.h>
31
#else
32
# if HAVE_SYS_TIME_H
33
#  include <sys/time.h>
34
# else
35
#  include <time.h>
36
# endif
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
37
#endif
481.1.15 by Monty Taylor
Removed time.h and sys/time.h from global.h.
38
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
39
namespace drizzled
40
{
41
151 by Brian Aker
Ulonglong to uint64_t
42
uint64_t my_getsystime()
1 by brian
clean slate
43
{
44
#ifdef HAVE_CLOCK_GETTIME
45
  struct timespec tp;
46
  clock_gettime(CLOCK_REALTIME, &tp);
151 by Brian Aker
Ulonglong to uint64_t
47
  return (uint64_t)tp.tv_sec*10000000+(uint64_t)tp.tv_nsec/100;
1 by brian
clean slate
48
#else
49
  /* TODO: check for other possibilities for hi-res timestamping */
50
  struct timeval tv;
51
  gettimeofday(&tv,NULL);
151 by Brian Aker
Ulonglong to uint64_t
52
  return (uint64_t)tv.tv_sec*10000000+(uint64_t)tv.tv_usec*10;
1 by brian
clean slate
53
#endif
54
}
55
56
/*
57
  Return time in micro seconds
58
59
  SYNOPSIS
60
    my_micro_time()
61
62
  NOTES
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.
66
67
    For windows platforms we need the frequency value of the CUP. This is
68
    initalized in my_init.c through QueryPerformanceFrequency().
69
70
    If Windows platform doesn't support QueryPerformanceFrequency() we will
71
    obtain the time via GetClockCount, which only supports milliseconds.
72
73
  RETURN
74
    Value in microseconds from some undefined point in time
75
*/
76
151 by Brian Aker
Ulonglong to uint64_t
77
uint64_t my_micro_time()
1 by brian
clean slate
78
{
79
#if defined(HAVE_GETHRTIME)
80
  return gethrtime()/1000;
81
#else
151 by Brian Aker
Ulonglong to uint64_t
82
  uint64_t newtime;
1 by brian
clean slate
83
  struct timeval t;
84
  /*
85
    The following loop is here because gettimeofday may fail on some systems
86
  */
87
  while (gettimeofday(&t, NULL) != 0)
88
  {}
151 by Brian Aker
Ulonglong to uint64_t
89
  newtime= (uint64_t)t.tv_sec * 1000000 + t.tv_usec;
1 by brian
clean slate
90
  return newtime;
91
#endif  /* defined(HAVE_GETHRTIME) */
92
}
93
94
95
/*
96
  Return time in seconds and timer in microseconds (not different start!)
97
98
  SYNOPSIS
99
    my_micro_time_and_time()
100
    time_arg		Will be set to seconds since epoch (00:00:00 UTC,
101
                        January 1, 1970)
102
103
  NOTES
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)
107
108
  IMPLEMENTATION
109
    Value of time is as in time() call.
110
    Value of microtime is same as my_micro_time(), which may be totally
111
    unrealated to time()
112
113
  RETURN
114
    Value in microseconds from some undefined point in time
115
*/
116
117
151 by Brian Aker
Ulonglong to uint64_t
118
uint64_t my_micro_time_and_time(time_t *time_arg)
1 by brian
clean slate
119
{
151 by Brian Aker
Ulonglong to uint64_t
120
  uint64_t newtime;
1 by brian
clean slate
121
  struct timeval t;
122
  /*
123
    The following loop is here because gettimeofday may fail on some systems
124
  */
873 by Brian Aker
Solaris performanc fix.
125
  while (gettimeofday(&t, NULL) != 0) {}
1 by brian
clean slate
126
  *time_arg= t.tv_sec;
151 by Brian Aker
Ulonglong to uint64_t
127
  newtime= (uint64_t)t.tv_sec * 1000000 + t.tv_usec;
873 by Brian Aker
Solaris performanc fix.
128
1 by brian
clean slate
129
  return newtime;
130
}
131
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
132
} /* namespace drizzled */