~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/status_helper.cc

  • Committer: Joe Daly
  • Date: 2010-06-08 01:34:00 UTC
  • mto: This revision was merged to the branch mainline in revision 1614.
  • Revision ID: skinny.moey@gmail.com-20100608013400-3qpmg8oimd2acumn
move GPL code back to the core from logging_stats plugin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008 Sun Microsystems
 
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
 
 
21
#include "config.h"
 
22
#include "status_helper.h"
 
23
#include "drizzled/set_var.h"
 
24
#include "drizzled/drizzled.h"
 
25
#include "plugin/myisam/myisam.h"
 
26
 
 
27
#include <sstream>
 
28
 
 
29
using namespace drizzled;
 
30
using namespace std;
 
31
 
 
32
static int show_starttime_new(drizzle_show_var *var, char *buff)
 
33
{
 
34
  var->type= SHOW_LONG;
 
35
  var->value= buff;
 
36
  *((long *)buff)= (long) (time(NULL) - server_start_time);
 
37
  return 0;
 
38
}
 
39
 
 
40
static int show_flushstatustime_new(drizzle_show_var *var, char *buff)
 
41
{
 
42
  var->type= SHOW_LONG;
 
43
  var->value= buff;
 
44
  *((long *)buff)= (long) (time(NULL) - flush_status_time);
 
45
  return 0;
 
46
}
 
47
 
 
48
static int show_connection_count_new(drizzle_show_var *var, char *buff)
 
49
{
 
50
  var->type= SHOW_INT;
 
51
  var->value= buff;
 
52
  *((uint32_t *)buff)= connection_count;
 
53
  return 0;
 
54
}
 
55
 
 
56
static st_show_var_func_container show_starttime_cont_new= { &show_starttime_new };
 
57
 
 
58
static st_show_var_func_container show_flushstatustime_cont_new= { &show_flushstatustime_new };
 
59
 
 
60
static st_show_var_func_container show_connection_count_cont_new= { &show_connection_count_new };
 
61
 
 
62
extern drizzled::KEY_CACHE dflt_key_cache_var, *dflt_key_cache;
 
63
 
 
64
string StatusHelper::fillHelper(system_status_var *status_var, char *value, SHOW_TYPE show_type)
 
65
{
 
66
  ostringstream oss;
 
67
  string return_value;
 
68
 
 
69
  switch (show_type) {
 
70
  case SHOW_DOUBLE_STATUS:
 
71
    value= ((char *) status_var + (ulong) value);
 
72
    /* fall through */
 
73
  case SHOW_DOUBLE:
 
74
    oss.precision(6);
 
75
    oss << *(double *) value;
 
76
    return_value= oss.str();
 
77
    break;
 
78
  case SHOW_LONG_STATUS:
 
79
    value= ((char *) status_var + (ulong) value);
 
80
    /* fall through */
 
81
  case SHOW_LONG:
 
82
    oss << *(long*) value;
 
83
    return_value= oss.str();
 
84
    break;
 
85
  case SHOW_LONGLONG_STATUS:
 
86
    value= ((char *) status_var + (uint64_t) value);
 
87
    /* fall through */
 
88
  case SHOW_LONGLONG:
 
89
    oss << *(int64_t*) value;
 
90
    return_value= oss.str();
 
91
    break;
 
92
  case SHOW_SIZE:
 
93
    oss << *(size_t*) value;
 
94
    return_value= oss.str();
 
95
    break;
 
96
  case SHOW_HA_ROWS:
 
97
    oss << (int64_t) *(ha_rows*) value;
 
98
    return_value= oss.str();
 
99
    break;
 
100
  case SHOW_BOOL:
 
101
  case SHOW_MY_BOOL:
 
102
    return_value= *(bool*) value ? "ON" : "OFF";
 
103
    break;
 
104
  case SHOW_INT:
 
105
  case SHOW_INT_NOFLUSH: // the difference lies in refresh_status()
 
106
    oss << (long) *(uint32_t*) value;
 
107
    return_value= oss.str();
 
108
    break;
 
109
  case SHOW_CHAR:
 
110
    {
 
111
      if (value)
 
112
        return_value= value;
 
113
      break;
 
114
    }
 
115
  case SHOW_CHAR_PTR:
 
116
    {
 
117
      if (*(char**) value)
 
118
        return_value= *(char**) value;
 
119
 
 
120
      break;
 
121
    }
 
122
  case SHOW_KEY_CACHE_LONG:
 
123
    value= (char*) dflt_key_cache + (unsigned long)value;
 
124
    oss << *(long*) value;
 
125
    return_value= oss.str();
 
126
    break;
 
127
  case SHOW_KEY_CACHE_LONGLONG:
 
128
    value= (char*) dflt_key_cache + (unsigned long)value;
 
129
    oss << *(int64_t*) value;
 
130
    return_value= oss.str();
 
131
    break;
 
132
  case SHOW_UNDEF:
 
133
    break;                                        // Return empty string
 
134
  case SHOW_SYS:                                  // Cannot happen
 
135
  default:
 
136
    assert(0);
 
137
    break;
 
138
  }
 
139
 
 
140
  return return_value;
 
141
}
 
142
 
 
143
drizzle_show_var StatusHelper::status_vars_defs[]=
 
144
{
 
145
  {"Aborted_clients",           (char*) &current_global_counters.aborted_threads, SHOW_LONGLONG},
 
146
  {"Aborted_connects",          (char*) &current_global_counters.aborted_connects, SHOW_LONGLONG},
 
147
  {"Bytes_received",            (char*) offsetof(system_status_var, bytes_received), SHOW_LONGLONG_STATUS},
 
148
  {"Bytes_sent",                (char*) offsetof(system_status_var, bytes_sent), SHOW_LONGLONG_STATUS},
 
149
  {"Connections",               (char*) &global_thread_id, SHOW_INT_NOFLUSH},
 
150
  {"Created_tmp_disk_tables",   (char*) offsetof(system_status_var, created_tmp_disk_tables), SHOW_LONGLONG_STATUS},
 
151
  {"Created_tmp_tables",        (char*) offsetof(system_status_var, created_tmp_tables), SHOW_LONGLONG_STATUS},
 
152
  {"Flush_commands",            (char*) &refresh_version,    SHOW_INT_NOFLUSH},
 
153
  {"Handler_commit",            (char*) offsetof(system_status_var, ha_commit_count), SHOW_LONGLONG_STATUS},
 
154
  {"Handler_delete",            (char*) offsetof(system_status_var, ha_delete_count), SHOW_LONGLONG_STATUS},
 
155
  {"Handler_prepare",           (char*) offsetof(system_status_var, ha_prepare_count),  SHOW_LONGLONG_STATUS},
 
156
  {"Handler_read_first",        (char*) offsetof(system_status_var, ha_read_first_count), SHOW_LONGLONG_STATUS},
 
157
  {"Handler_read_key",          (char*) offsetof(system_status_var, ha_read_key_count), SHOW_LONGLONG_STATUS},
 
158
  {"Handler_read_next",         (char*) offsetof(system_status_var, ha_read_next_count), SHOW_LONGLONG_STATUS},
 
159
  {"Handler_read_prev",         (char*) offsetof(system_status_var, ha_read_prev_count), SHOW_LONGLONG_STATUS},
 
160
  {"Handler_read_rnd",          (char*) offsetof(system_status_var, ha_read_rnd_count), SHOW_LONGLONG_STATUS},
 
161
  {"Handler_read_rnd_next",     (char*) offsetof(system_status_var, ha_read_rnd_next_count), SHOW_LONGLONG_STATUS},
 
162
  {"Handler_rollback",          (char*) offsetof(system_status_var, ha_rollback_count), SHOW_LONGLONG_STATUS},
 
163
  {"Handler_savepoint",         (char*) offsetof(system_status_var, ha_savepoint_count), SHOW_LONGLONG_STATUS},
 
164
  {"Handler_savepoint_rollback",(char*) offsetof(system_status_var, ha_savepoint_rollback_count), SHOW_LONGLONG_STATUS},
 
165
  {"Handler_update",            (char*) offsetof(system_status_var, ha_update_count), SHOW_LONGLONG_STATUS},
 
166
  {"Handler_write",             (char*) offsetof(system_status_var, ha_write_count), SHOW_LONGLONG_STATUS},
 
167
  {"Key_blocks_not_flushed",    (char*) offsetof(KEY_CACHE, global_blocks_changed), SHOW_KEY_CACHE_LONG},
 
168
  {"Key_blocks_unused",         (char*) offsetof(KEY_CACHE, blocks_unused), SHOW_KEY_CACHE_LONG},
 
169
  {"Key_blocks_used",           (char*) offsetof(KEY_CACHE, blocks_used), SHOW_KEY_CACHE_LONG},
 
170
  {"Key_read_requests",         (char*) offsetof(KEY_CACHE, global_cache_r_requests), SHOW_KEY_CACHE_LONGLONG},
 
171
  {"Key_reads",                 (char*) offsetof(KEY_CACHE, global_cache_read), SHOW_KEY_CACHE_LONGLONG},
 
172
  {"Key_write_requests",        (char*) offsetof(KEY_CACHE, global_cache_w_requests), SHOW_KEY_CACHE_LONGLONG},
 
173
  {"Key_writes",                (char*) offsetof(KEY_CACHE, global_cache_write), SHOW_KEY_CACHE_LONGLONG},
 
174
  {"Last_query_cost",           (char*) offsetof(system_status_var, last_query_cost), SHOW_DOUBLE_STATUS},
 
175
  {"Max_used_connections",      (char*) &current_global_counters.max_used_connections,  SHOW_LONGLONG},
 
176
  {"Questions",                 (char*) offsetof(system_status_var, questions), SHOW_LONGLONG_STATUS},
 
177
  {"Select_full_join",          (char*) offsetof(system_status_var, select_full_join_count), SHOW_LONGLONG_STATUS},
 
178
  {"Select_full_range_join",    (char*) offsetof(system_status_var, select_full_range_join_count), SHOW_LONGLONG_STATUS},
 
179
  {"Select_range",              (char*) offsetof(system_status_var, select_range_count), SHOW_LONGLONG_STATUS},
 
180
  {"Select_range_check",        (char*) offsetof(system_status_var, select_range_check_count), SHOW_LONGLONG_STATUS},
 
181
  {"Select_scan",               (char*) offsetof(system_status_var, select_scan_count), SHOW_LONGLONG_STATUS},
 
182
  {"Slow_queries",              (char*) offsetof(system_status_var, long_query_count), SHOW_LONGLONG_STATUS},
 
183
  {"Sort_merge_passes",         (char*) offsetof(system_status_var, filesort_merge_passes), SHOW_LONGLONG_STATUS},
 
184
  {"Sort_range",                (char*) offsetof(system_status_var, filesort_range_count), SHOW_LONGLONG_STATUS},
 
185
  {"Sort_rows",                 (char*) offsetof(system_status_var, filesort_rows), SHOW_LONGLONG_STATUS},
 
186
  {"Sort_scan",                 (char*) offsetof(system_status_var, filesort_scan_count), SHOW_LONGLONG_STATUS},
 
187
  {"Table_locks_immediate",     (char*) &current_global_counters.locks_immediate,        SHOW_LONGLONG},
 
188
  {"Table_locks_waited",        (char*) &current_global_counters.locks_waited,           SHOW_LONGLONG},
 
189
  {"Threads_connected",         (char*) &show_connection_count_cont_new,  SHOW_FUNC},
 
190
  {"Uptime",                    (char*) &show_starttime_cont_new,         SHOW_FUNC},
 
191
  {"Uptime_since_flush_status", (char*) &show_flushstatustime_cont_new,   SHOW_FUNC},
 
192
  {NULL, NULL, SHOW_LONGLONG}
 
193
};