~drizzle-trunk/drizzle/development

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* Drizzle
 * Copyright (C) 2011 Olaf van der Spek
 * 
 * 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
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 * 
 * 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, see <http://www.gnu.org/licenses/>.
 */

#include <config.h>
#include <drizzled/session/times.h>
#include <drizzled/session.h>
#include <drizzled/statistics_variables.h>

namespace drizzled {
namespace session {

type::epoch_t Times::getCurrentTimestamp(bool actual) const
{
  return ((actual ? boost::posix_time::microsec_clock::universal_time() : _end_timer) - _epoch).total_microseconds();
}

type::epoch_t Times::getCurrentTimestampEpoch() const
{
	return ((_user_time.is_not_a_date_time() ? _start_timer : _user_time) - _epoch).total_seconds();
}

type::epoch_t Times::getCurrentTimestampEpoch(type::usec_t &fraction_arg) const
{
  if (not _user_time.is_not_a_date_time())
  {
    fraction_arg= 0;
    return (_user_time - _epoch).total_seconds();
  }

  fraction_arg= _start_timer.time_of_day().fractional_seconds() % 1000000;
  return (_start_timer - _epoch).total_seconds();
}

uint64_t Times::getElapsedTime() const
{
  return (_end_timer - _start_timer).total_microseconds();
}

void Times::resetUserTime()
{
  _user_time= boost::posix_time::not_a_date_time;
}

boost::posix_time::ptime Times::start_timer() const
{
  return _start_timer;
}

boost::posix_time::ptime Times::epoch() const
{
  return _epoch;
}

void Times::set_time()
{
  _end_timer= _start_timer= boost::posix_time::microsec_clock::universal_time();
  utime_after_lock= (_start_timer - _epoch).total_microseconds();
}

void Times::set_time_after_lock()
{
  utime_after_lock= (boost::posix_time::microsec_clock::universal_time() - _epoch).total_microseconds();
}

type::epoch_t Times::query_start()
{
  return getCurrentTimestampEpoch();
}

void Times::set_time(time_t t) // This is done by a sys_var, as long as user_time is set, we will use that for all references to time
{
  _user_time= boost::posix_time::from_time_t(t);
}

uint64_t Times::getConnectMicroseconds() const
{
  return (_connect_time - _epoch).total_microseconds();
}

uint64_t Times::getConnectSeconds() const
{
  return (_connect_time - _epoch).total_seconds();
}

void Times::set_end_timer(Session& session)
{
  _end_timer= boost::posix_time::microsec_clock::universal_time();
  session.status_var.execution_time_nsec+= (_end_timer - _start_timer).total_microseconds();
}

}
}