Drizzled Public API Documentation

times.cc
00001 /* Drizzle
00002  * Copyright (C) 2011 Olaf van der Spek
00003  * 
00004  * This program is free software: you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation, either version 2 of the License, or
00007  * (at your option) any later version.
00008  * 
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00012  * GNU General Public License for more details.
00013  * 
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 #include <config.h>
00019 #include <drizzled/session/times.h>
00020 #include <drizzled/session.h>
00021 #include <drizzled/statistics_variables.h>
00022 
00023 namespace drizzled {
00024 namespace session {
00025 
00026 type::epoch_t Times::getCurrentTimestamp(bool actual) const
00027 {
00028   return ((actual ? boost::posix_time::microsec_clock::universal_time() : _end_timer) - _epoch).total_microseconds();
00029 }
00030 
00031 type::epoch_t Times::getCurrentTimestampEpoch() const
00032 {
00033   return ((_user_time.is_not_a_date_time() ? _start_timer : _user_time) - _epoch).total_seconds();
00034 }
00035 
00036 type::epoch_t Times::getCurrentTimestampEpoch(type::usec_t &fraction_arg) const
00037 {
00038   if (not _user_time.is_not_a_date_time())
00039   {
00040     fraction_arg= 0;
00041     return (_user_time - _epoch).total_seconds();
00042   }
00043 
00044   fraction_arg= _start_timer.time_of_day().fractional_seconds() % 1000000;
00045   return (_start_timer - _epoch).total_seconds();
00046 }
00047 
00048 uint64_t Times::getElapsedTime() const
00049 {
00050   return (_end_timer - _start_timer).total_microseconds();
00051 }
00052 
00053 void Times::resetUserTime()
00054 {
00055   _user_time= boost::posix_time::not_a_date_time;
00056 }
00057 
00058 boost::posix_time::ptime Times::start_timer() const
00059 {
00060   return _start_timer;
00061 }
00062 
00063 boost::posix_time::ptime Times::epoch() const
00064 {
00065   return _epoch;
00066 }
00067 
00068 void Times::set_time()
00069 {
00070   _end_timer= _start_timer= boost::posix_time::microsec_clock::universal_time();
00071   utime_after_lock= (_start_timer - _epoch).total_microseconds();
00072 }
00073 
00074 void Times::set_time_after_lock()
00075 {
00076   utime_after_lock= (boost::posix_time::microsec_clock::universal_time() - _epoch).total_microseconds();
00077 }
00078 
00079 type::epoch_t Times::query_start()
00080 {
00081   return getCurrentTimestampEpoch();
00082 }
00083 
00084 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
00085 {
00086   _user_time= boost::posix_time::from_time_t(t);
00087 }
00088 
00089 uint64_t Times::getConnectMicroseconds() const
00090 {
00091   return (_connect_time - _epoch).total_microseconds();
00092 }
00093 
00094 uint64_t Times::getConnectSeconds() const
00095 {
00096   return (_connect_time - _epoch).total_seconds();
00097 }
00098 
00099 void Times::set_end_timer(Session& session)
00100 {
00101   _end_timer= boost::posix_time::microsec_clock::universal_time();
00102   session.status_var.execution_time_nsec+= (_end_timer - _start_timer).total_microseconds();
00103 }
00104 
00105 }
00106 }