drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
times.cc
1/* Drizzle
2 * Copyright (C) 2011 Olaf van der Spek
3 *
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.
8 *
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.
13 *
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/>.
16 */
17
18#include <config.h>
19#include <drizzled/session/times.h>
20#include <drizzled/session.h>
21#include <drizzled/statistics_variables.h>
22
23namespace drizzled {
24namespace session {
25
26type::epoch_t Times::getCurrentTimestamp(bool actual) const
27{
28 return ((actual ? boost::posix_time::microsec_clock::universal_time() : _end_timer) - _epoch).total_microseconds();
29}
30
31type::epoch_t Times::getCurrentTimestampEpoch() const
32{
33 return ((_user_time.is_not_a_date_time() ? _start_timer : _user_time) - _epoch).total_seconds();
34}
35
36type::epoch_t Times::getCurrentTimestampEpoch(type::usec_t &fraction_arg) const
37{
38 if (not _user_time.is_not_a_date_time())
39 {
40 fraction_arg= 0;
41 return (_user_time - _epoch).total_seconds();
42 }
43
44 fraction_arg= _start_timer.time_of_day().fractional_seconds() % 1000000;
45 return (_start_timer - _epoch).total_seconds();
46}
47
48uint64_t Times::getElapsedTime() const
49{
50 return (_end_timer - _start_timer).total_microseconds();
51}
52
53void Times::resetUserTime()
54{
55 _user_time= boost::posix_time::not_a_date_time;
56}
57
58boost::posix_time::ptime Times::start_timer() const
59{
60 return _start_timer;
61}
62
63boost::posix_time::ptime Times::epoch() const
64{
65 return _epoch;
66}
67
68void Times::set_time()
69{
70 _end_timer= _start_timer= boost::posix_time::microsec_clock::universal_time();
71 utime_after_lock= (_start_timer - _epoch).total_microseconds();
72}
73
74void Times::set_time_after_lock()
75{
76 utime_after_lock= (boost::posix_time::microsec_clock::universal_time() - _epoch).total_microseconds();
77}
78
79type::epoch_t Times::query_start()
80{
81 return getCurrentTimestampEpoch();
82}
83
84void 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
85{
86 _user_time= boost::posix_time::from_time_t(t);
87}
88
89uint64_t Times::getConnectMicroseconds() const
90{
91 return (_connect_time - _epoch).total_microseconds();
92}
93
94uint64_t Times::getConnectSeconds() const
95{
96 return (_connect_time - _epoch).total_seconds();
97}
98
99void Times::set_end_timer(Session& session)
100{
101 _end_timer= boost::posix_time::microsec_clock::universal_time();
102 session.status_var.execution_time_nsec+= (_end_timer - _start_timer).total_microseconds();
103}
104
105}
106}
TODO: Rename this file - func.h is stupid.