2
* Copyright (C) 2011 Olaf van der Spek
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation, either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
#include <drizzled/session/times.h>
20
#include <drizzled/session.h>
21
#include <drizzled/statistics_variables.h>
26
type::Time::epoch_t Times::getCurrentTimestamp(bool actual) const
28
return ((actual ? boost::posix_time::microsec_clock::universal_time() : _end_timer) - _epoch).total_microseconds();
31
type::Time::epoch_t Times::getCurrentTimestampEpoch() const
33
return ((_user_time.is_not_a_date_time() ? _start_timer : _user_time) - _epoch).total_seconds();
36
type::Time::epoch_t Times::getCurrentTimestampEpoch(type::Time::usec_t &fraction_arg) const
38
if (not _user_time.is_not_a_date_time())
41
return (_user_time - _epoch).total_seconds();
44
fraction_arg= _start_timer.time_of_day().fractional_seconds() % 1000000;
45
return (_start_timer - _epoch).total_seconds();
48
uint64_t Times::getElapsedTime() const
50
return (_end_timer - _start_timer).total_microseconds();
53
void Times::resetUserTime()
55
_user_time= boost::posix_time::not_a_date_time;
58
boost::posix_time::ptime Times::start_timer() const
63
void Times::set_time()
65
_end_timer= _start_timer= boost::posix_time::microsec_clock::universal_time();
66
utime_after_lock= (_start_timer - _epoch).total_microseconds();
69
void Times::set_time_after_lock()
71
utime_after_lock= (boost::posix_time::microsec_clock::universal_time() - _epoch).total_microseconds();
74
type::Time::epoch_t Times::query_start()
76
return getCurrentTimestampEpoch();
79
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
81
_user_time= boost::posix_time::from_time_t(t);
84
uint64_t Times::getConnectMicroseconds() const
86
return (_connect_time - _epoch).total_microseconds();
89
uint64_t Times::getConnectSeconds() const
91
return (_connect_time - _epoch).total_seconds();
94
void Times::set_end_timer(Session& session)
96
_end_timer= boost::posix_time::microsec_clock::universal_time();
97
session.status_var.execution_time_nsec+= (_end_timer - _start_timer).total_microseconds();