~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session/times.cc

  • Committer: Lee Bieber
  • Date: 2011-04-13 18:54:56 UTC
  • mfrom: (2275.1.2 build)
  • Revision ID: kalebral@gmail.com-20110413185456-ygv8a7lxf92ttoee
Merge Joe - 755201: slave plugin queryForReplicationEvents() query needs to be ordered
Merge Olaf - Refactor Session

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
23
namespace drizzled {
 
24
namespace session {
 
25
 
 
26
type::Time::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
 
 
31
type::Time::epoch_t Times::getCurrentTimestampEpoch() const
 
32
{
 
33
        return ((_user_time.is_not_a_date_time() ? _start_timer : _user_time) - _epoch).total_seconds();
 
34
}
 
35
 
 
36
type::Time::epoch_t Times::getCurrentTimestampEpoch(type::Time::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
 
 
48
uint64_t Times::getElapsedTime() const
 
49
{
 
50
  return (_end_timer - _start_timer).total_microseconds();
 
51
}
 
52
 
 
53
void Times::resetUserTime()
 
54
{
 
55
  _user_time= boost::posix_time::not_a_date_time;
 
56
}
 
57
 
 
58
boost::posix_time::ptime Times::start_timer() const
 
59
{
 
60
  return _start_timer;
 
61
}
 
62
 
 
63
void Times::set_time()
 
64
{
 
65
  _end_timer= _start_timer= boost::posix_time::microsec_clock::universal_time();
 
66
  utime_after_lock= (_start_timer - _epoch).total_microseconds();
 
67
}
 
68
 
 
69
void Times::set_time_after_lock()
 
70
{
 
71
  utime_after_lock= (boost::posix_time::microsec_clock::universal_time() - _epoch).total_microseconds();
 
72
}
 
73
 
 
74
type::Time::epoch_t Times::query_start()
 
75
{
 
76
  return getCurrentTimestampEpoch();
 
77
}
 
78
 
 
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
 
80
{
 
81
  _user_time= boost::posix_time::from_time_t(t);
 
82
}
 
83
 
 
84
uint64_t Times::getConnectMicroseconds() const
 
85
{
 
86
  return (_connect_time - _epoch).total_microseconds();
 
87
}
 
88
 
 
89
uint64_t Times::getConnectSeconds() const
 
90
{
 
91
  return (_connect_time - _epoch).total_seconds();
 
92
}
 
93
 
 
94
void Times::set_end_timer(Session& session)
 
95
{
 
96
  _end_timer= boost::posix_time::microsec_clock::universal_time();
 
97
  session.status_var.execution_time_nsec+= (_end_timer - _start_timer).total_microseconds();
 
98
}
 
99
 
 
100
}
 
101
}