~drizzle-trunk/drizzle/development

1561.3.19 by Joe Daly
move GPL code back to the core from logging_stats plugin
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
1561.3.19 by Joe Daly
move GPL code back to the core from logging_stats plugin
5
 *  Copyright (C) 2010 Joseph Daly 
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; version 2 of the License.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU General Public License
17
 *  along with this program; if not, write to the Free Software
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 */
20
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
21
#include <config.h>
2263.3.5 by Olaf van der Spek
Refactor Open_tables_state
22
#include "status_helper.h"
1775.5.1 by earney
modified files containing stringstream to use boost:lexical_cast instead as
23
#include <boost/lexical_cast.hpp>
2263.3.5 by Olaf van der Spek
Refactor Open_tables_state
24
#include <drizzled/open_tables_state.h>
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
25
#include <drizzled/set_var.h>
26
#include <drizzled/drizzled.h>
27
#include <plugin/myisam/myisam.h>
1561.3.19 by Joe Daly
move GPL code back to the core from logging_stats plugin
28
#include <sstream>
29
30
using namespace std;
31
2263.3.5 by Olaf van der Spek
Refactor Open_tables_state
32
namespace drizzled {
1878.3.1 by Monty Taylor
Split set_var.* into sys_var.* and set_var.*
33
34
extern time_t server_start_time;
35
extern time_t flush_status_time;
36
1561.3.19 by Joe Daly
move GPL code back to the core from logging_stats plugin
37
static int show_starttime_new(drizzle_show_var *var, char *buff)
38
{
39
  var->type= SHOW_LONG;
40
  var->value= buff;
41
  *((long *)buff)= (long) (time(NULL) - server_start_time);
42
  return 0;
43
}
44
45
static int show_flushstatustime_new(drizzle_show_var *var, char *buff)
46
{
47
  var->type= SHOW_LONG;
48
  var->value= buff;
49
  *((long *)buff)= (long) (time(NULL) - flush_status_time);
50
  return 0;
51
}
52
53
static int show_connection_count_new(drizzle_show_var *var, char *buff)
54
{
55
  var->type= SHOW_INT;
56
  var->value= buff;
57
  *((uint32_t *)buff)= connection_count;
58
  return 0;
59
}
60
61
static st_show_var_func_container show_starttime_cont_new= { &show_starttime_new };
62
63
static st_show_var_func_container show_flushstatustime_cont_new= { &show_flushstatustime_new };
64
65
static st_show_var_func_container show_connection_count_cont_new= { &show_connection_count_new };
66
2445.1.16 by Olaf van der Spek
Refactor
67
string StatusHelper::fillHelper(system_status_var *status_var, const char *value, SHOW_TYPE show_type)
1561.3.19 by Joe Daly
move GPL code back to the core from logging_stats plugin
68
{
69
  ostringstream oss;
2445.1.16 by Olaf van der Spek
Refactor
70
  switch (show_type) 
71
  {
1561.3.19 by Joe Daly
move GPL code back to the core from logging_stats plugin
72
  case SHOW_DOUBLE_STATUS:
73
    value= ((char *) status_var + (ulong) value);
74
    /* fall through */
75
  case SHOW_DOUBLE:
76
    oss.precision(6);
77
    oss << *(double *) value;
2445.1.16 by Olaf van der Spek
Refactor
78
    return oss.str();
1561.3.19 by Joe Daly
move GPL code back to the core from logging_stats plugin
79
  case SHOW_LONG_STATUS:
80
    value= ((char *) status_var + (ulong) value);
81
    /* fall through */
82
  case SHOW_LONG:
2445.1.16 by Olaf van der Spek
Refactor
83
    return boost::lexical_cast<std::string>(*(long*) value);
1561.3.19 by Joe Daly
move GPL code back to the core from logging_stats plugin
84
    break;
85
  case SHOW_LONGLONG_STATUS:
86
    value= ((char *) status_var + (uint64_t) value);
87
    /* fall through */
88
  case SHOW_LONGLONG:
2445.1.16 by Olaf van der Spek
Refactor
89
    return boost::lexical_cast<std::string>(*(int64_t*) value);
1561.3.19 by Joe Daly
move GPL code back to the core from logging_stats plugin
90
  case SHOW_SIZE:
2445.1.16 by Olaf van der Spek
Refactor
91
    return boost::lexical_cast<std::string>(*(size_t*) value);
1561.3.19 by Joe Daly
move GPL code back to the core from logging_stats plugin
92
  case SHOW_HA_ROWS:
2445.1.16 by Olaf van der Spek
Refactor
93
    return boost::lexical_cast<std::string>((int64_t) *(ha_rows*) value);
1561.3.19 by Joe Daly
move GPL code back to the core from logging_stats plugin
94
  case SHOW_BOOL:
95
  case SHOW_MY_BOOL:
2445.1.16 by Olaf van der Spek
Refactor
96
    return *(bool*) value ? "ON" : "OFF";
1561.3.19 by Joe Daly
move GPL code back to the core from logging_stats plugin
97
  case SHOW_INT:
98
  case SHOW_INT_NOFLUSH: // the difference lies in refresh_status()
2445.1.16 by Olaf van der Spek
Refactor
99
    return boost::lexical_cast<std::string>((long) *(uint32_t*) value);
1561.3.19 by Joe Daly
move GPL code back to the core from logging_stats plugin
100
  case SHOW_CHAR:
2445.1.16 by Olaf van der Spek
Refactor
101
    if (value)
102
      return value;
103
    break;
1561.3.19 by Joe Daly
move GPL code back to the core from logging_stats plugin
104
  case SHOW_CHAR_PTR:
2445.1.16 by Olaf van der Spek
Refactor
105
    if (*(char**) value)
106
      return *(char**) value;
107
    break;
1561.3.19 by Joe Daly
move GPL code back to the core from logging_stats plugin
108
  case SHOW_UNDEF:
109
    break;                                        // Return empty string
110
  case SHOW_SYS:                                  // Cannot happen
111
  default:
112
    assert(0);
113
  }
2445.1.16 by Olaf van der Spek
Refactor
114
  return string();
1561.3.19 by Joe Daly
move GPL code back to the core from logging_stats plugin
115
}
116
117
drizzle_show_var StatusHelper::status_vars_defs[]=
118
{
1625.2.1 by Joe Daly
initial user stats impl
119
  {"Aborted_clients",           (char*) offsetof(system_status_var, aborted_threads), SHOW_LONGLONG_STATUS},
120
  {"Aborted_connects",          (char*) offsetof(system_status_var, aborted_connects), SHOW_LONGLONG_STATUS},
1561.3.19 by Joe Daly
move GPL code back to the core from logging_stats plugin
121
  {"Bytes_received",            (char*) offsetof(system_status_var, bytes_received), SHOW_LONGLONG_STATUS},
122
  {"Bytes_sent",                (char*) offsetof(system_status_var, bytes_sent), SHOW_LONGLONG_STATUS},
1726.3.3 by LinuxJedi
Add a proper connections counter.
123
  {"Connections",               (char*) &current_global_counters.connections,  SHOW_LONGLONG},
1561.3.19 by Joe Daly
move GPL code back to the core from logging_stats plugin
124
  {"Created_tmp_disk_tables",   (char*) offsetof(system_status_var, created_tmp_disk_tables), SHOW_LONGLONG_STATUS},
125
  {"Created_tmp_tables",        (char*) offsetof(system_status_var, created_tmp_tables), SHOW_LONGLONG_STATUS},
2263.3.4 by Olaf van der Spek
Prefix global refresh_version
126
  {"Flush_commands",            (char*) &g_refresh_version, SHOW_INT_NOFLUSH},
1561.3.19 by Joe Daly
move GPL code back to the core from logging_stats plugin
127
  {"Handler_commit",            (char*) offsetof(system_status_var, ha_commit_count), SHOW_LONGLONG_STATUS},
128
  {"Handler_delete",            (char*) offsetof(system_status_var, ha_delete_count), SHOW_LONGLONG_STATUS},
129
  {"Handler_prepare",           (char*) offsetof(system_status_var, ha_prepare_count),  SHOW_LONGLONG_STATUS},
130
  {"Handler_read_first",        (char*) offsetof(system_status_var, ha_read_first_count), SHOW_LONGLONG_STATUS},
131
  {"Handler_read_key",          (char*) offsetof(system_status_var, ha_read_key_count), SHOW_LONGLONG_STATUS},
132
  {"Handler_read_next",         (char*) offsetof(system_status_var, ha_read_next_count), SHOW_LONGLONG_STATUS},
133
  {"Handler_read_prev",         (char*) offsetof(system_status_var, ha_read_prev_count), SHOW_LONGLONG_STATUS},
134
  {"Handler_read_rnd",          (char*) offsetof(system_status_var, ha_read_rnd_count), SHOW_LONGLONG_STATUS},
135
  {"Handler_read_rnd_next",     (char*) offsetof(system_status_var, ha_read_rnd_next_count), SHOW_LONGLONG_STATUS},
136
  {"Handler_rollback",          (char*) offsetof(system_status_var, ha_rollback_count), SHOW_LONGLONG_STATUS},
137
  {"Handler_savepoint",         (char*) offsetof(system_status_var, ha_savepoint_count), SHOW_LONGLONG_STATUS},
138
  {"Handler_savepoint_rollback",(char*) offsetof(system_status_var, ha_savepoint_rollback_count), SHOW_LONGLONG_STATUS},
139
  {"Handler_update",            (char*) offsetof(system_status_var, ha_update_count), SHOW_LONGLONG_STATUS},
140
  {"Handler_write",             (char*) offsetof(system_status_var, ha_write_count), SHOW_LONGLONG_STATUS},
141
  {"Last_query_cost",           (char*) offsetof(system_status_var, last_query_cost), SHOW_DOUBLE_STATUS},
142
  {"Max_used_connections",      (char*) &current_global_counters.max_used_connections,  SHOW_LONGLONG},
143
  {"Questions",                 (char*) offsetof(system_status_var, questions), SHOW_LONGLONG_STATUS},
144
  {"Select_full_join",          (char*) offsetof(system_status_var, select_full_join_count), SHOW_LONGLONG_STATUS},
145
  {"Select_full_range_join",    (char*) offsetof(system_status_var, select_full_range_join_count), SHOW_LONGLONG_STATUS},
146
  {"Select_range",              (char*) offsetof(system_status_var, select_range_count), SHOW_LONGLONG_STATUS},
147
  {"Select_range_check",        (char*) offsetof(system_status_var, select_range_check_count), SHOW_LONGLONG_STATUS},
148
  {"Select_scan",               (char*) offsetof(system_status_var, select_scan_count), SHOW_LONGLONG_STATUS},
1843.7.6 by Brian Aker
This cleans up error messages to state "schema" instead of database.
149
  {"Sessions_connected",         (char*) &show_connection_count_cont_new,  SHOW_FUNC},
1561.3.19 by Joe Daly
move GPL code back to the core from logging_stats plugin
150
  {"Slow_queries",              (char*) offsetof(system_status_var, long_query_count), SHOW_LONGLONG_STATUS},
151
  {"Sort_merge_passes",         (char*) offsetof(system_status_var, filesort_merge_passes), SHOW_LONGLONG_STATUS},
152
  {"Sort_range",                (char*) offsetof(system_status_var, filesort_range_count), SHOW_LONGLONG_STATUS},
153
  {"Sort_rows",                 (char*) offsetof(system_status_var, filesort_rows), SHOW_LONGLONG_STATUS},
154
  {"Sort_scan",                 (char*) offsetof(system_status_var, filesort_scan_count), SHOW_LONGLONG_STATUS},
155
  {"Table_locks_immediate",     (char*) &current_global_counters.locks_immediate,        SHOW_LONGLONG},
156
  {"Table_locks_waited",        (char*) &current_global_counters.locks_waited,           SHOW_LONGLONG},
157
  {"Uptime",                    (char*) &show_starttime_cont_new,         SHOW_FUNC},
158
  {"Uptime_since_flush_status", (char*) &show_flushstatustime_cont_new,   SHOW_FUNC},
159
  {NULL, NULL, SHOW_LONGLONG}
160
};
1878.3.1 by Monty Taylor
Split set_var.* into sys_var.* and set_var.*
161
162
} /* namespace drizzled */