1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
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.
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
23
#include "plugin/status_dictionary/dictionary.h"
25
#include <drizzled/pthread_globals.h>
26
#include <drizzled/internal/m_string.h>
27
#include <drizzled/definitions.h>
34
using namespace drizzled;
36
StateTool::StateTool(const char *arg, bool global) :
37
plugin::TableFunction("DATA_DICTIONARY", arg),
38
option_type(global ? OPT_GLOBAL : OPT_SESSION)
40
add_field("VARIABLE_NAME");
41
add_field("VARIABLE_VALUE", 1024);
44
StateTool::Generator::Generator(Field **arg, sql_var_t option_arg,
45
drizzle_show_var *variables_args,
47
plugin::TableFunction::Generator(arg),
48
option_type(option_arg),
49
has_status(status_arg),
50
variables(variables_args)
55
pthread_rwlock_rdlock(&LOCK_system_variables_hash);
57
else if (option_type == OPT_GLOBAL && has_status)
60
pthread_mutex_lock(&LOCK_status);
61
calc_sum_of_all_status(&status);
65
status_ptr= &getSession().status_var;
69
StateTool::Generator::~Generator()
73
pthread_rwlock_unlock(&LOCK_system_variables_hash);
75
else if (option_type == OPT_GLOBAL)
77
pthread_mutex_unlock(&LOCK_status);
81
bool StateTool::Generator::populate()
83
while (variables && variables->name)
85
drizzle_show_var *var;
86
MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, int64_t);
87
char * const buff= (char *) &buff_data;
90
if var->type is SHOW_FUNC, call the function.
91
Repeat as necessary, if new var is again SHOW_FUNC
96
for (var= variables; var->type == SHOW_FUNC; var= &tmp)
97
((mysql_show_var_func)((st_show_var_func_container *)var->value)->func)(&tmp, buff);
100
if (isWild(variables->name))
106
fill(variables->name, var->value, var->type);
117
extern drizzled::KEY_CACHE dflt_key_cache_var, *dflt_key_cache;
118
void StateTool::Generator::fill(const std::string &name, char *value, SHOW_TYPE show_type)
120
struct system_status_var *status_var;
121
std::ostringstream oss;
124
std::string return_value;
126
/* Scope represents if the status should be session or global */
127
status_var= getStatus();
129
pthread_mutex_lock(&LOCK_global_system_variables);
131
if (show_type == SHOW_SYS)
133
show_type= ((sys_var*) value)->show_type();
134
value= (char*) ((sys_var*) value)->value_ptr(&(getSession()), option_type,
139
note that value may be == buff. All SHOW_xxx code below
140
should still work in this case
143
case SHOW_DOUBLE_STATUS:
144
value= ((char *) status_var + (ulong) value);
148
oss << *(double *) value;
149
return_value= oss.str();
151
case SHOW_LONG_STATUS:
152
value= ((char *) status_var + (ulong) value);
155
oss << *(long*) value;
156
return_value= oss.str();
158
case SHOW_LONGLONG_STATUS:
159
value= ((char *) status_var + (uint64_t) value);
162
oss << *(int64_t*) value;
163
return_value= oss.str();
166
oss << *(size_t*) value;
167
return_value= oss.str();
170
oss << (int64_t) *(ha_rows*) value;
171
return_value= oss.str();
175
return_value= *(bool*) value ? "ON" : "OFF";
178
case SHOW_INT_NOFLUSH: // the difference lies in refresh_status()
179
oss << (long) *(uint32_t*) value;
180
return_value= oss.str();
191
return_value= *(char**) value;
195
case SHOW_KEY_CACHE_LONG:
196
value= (char*) dflt_key_cache + (unsigned long)value;
197
oss << *(long*) value;
198
return_value= oss.str();
200
case SHOW_KEY_CACHE_LONGLONG:
201
value= (char*) dflt_key_cache + (unsigned long)value;
202
oss << *(int64_t*) value;
203
return_value= oss.str();
206
break; // Return empty string
207
case SHOW_SYS: // Cannot happen
212
pthread_mutex_unlock(&LOCK_global_system_variables);
214
if (return_value.length())