2
* Copyright (C) 2010 Joseph Daly <skinny.moey@gmail.com>
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
8
* * Redistributions of source code must retain the above copyright notice,
9
* this list of conditions and the following disclaimer.
10
* * Redistributions in binary form must reproduce the above copyright notice,
11
* this list of conditions and the following disclaimer in the documentation
12
* and/or other materials provided with the distribution.
13
* * Neither the name of Joseph Daly nor the names of its contributors
14
* may be used to endorse or promote products derived from this software
15
* without specific prior written permission.
17
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27
* THE POSSIBILITY OF SUCH DAMAGE.
33
* This class defines the "show status" and "show global status"
34
* DATA_DICTIONARY tables:
36
* drizzle> describe SESSION_STATUS;
37
* +----------------+---------+-------+---------+-----------------+-----------+
38
* | Field | Type | Null | Default | Default_is_NULL | On_Update |
39
* +----------------+---------+-------+---------+-----------------+-----------+
40
* | VARIABLE_NAME | VARCHAR | FALSE | | FALSE | |
41
* | VARIABLE_VALUE | VARCHAR | FALSE | | FALSE | |
42
* +----------------+---------+-------+---------+-----------------+-----------+
44
* drizzle> describe GLOBAL_STATUS;
45
* +----------------+---------+-------+---------+-----------------+-----------+
46
* | Field | Type | Null | Default | Default_is_NULL | On_Update |
47
* +----------------+---------+-------+---------+-----------------+-----------+
48
* | VARIABLE_NAME | VARCHAR | FALSE | | FALSE | |
49
* | VARIABLE_VALUE | VARCHAR | FALSE | | FALSE | |
50
* +----------------+---------+-------+---------+-----------------+-----------+
56
#include "status_tool.h"
57
#include "drizzled/status_helper.h"
62
using namespace drizzled;
63
using namespace plugin;
67
class ShowVarCmpFunctor
70
ShowVarCmpFunctor() { }
71
inline bool operator()(const drizzle_show_var *var1, const drizzle_show_var *var2) const
73
int val= strcmp(var1->name, var2->name);
78
StatusTool::StatusTool(LoggingStats *in_logging_stats, bool inIsLocal) :
79
TableFunction("DATA_DICTIONARY", inIsLocal ? "SESSION_STATUS" : "GLOBAL_STATUS"),
80
outer_logging_stats(in_logging_stats),
83
add_field("VARIABLE_NAME");
84
add_field("VARIABLE_VALUE", 1024);
86
drizzle_show_var *var= NULL;
88
std::vector<drizzle_show_var *>::iterator all_status_vars_iterator= all_status_vars.begin();
91
var= &StatusHelper::status_vars_defs[count];
92
if ((var == NULL) || (var->name == NULL))
96
all_status_vars_iterator= all_status_vars.insert(all_status_vars_iterator, var);
99
sort(all_status_vars.begin(), all_status_vars.end(), ShowVarCmpFunctor());
102
StatusTool::Generator::Generator(Field **arg, LoggingStats *in_logging_stats,
103
std::vector<drizzle_show_var *> *in_all_status_vars,
105
TableFunction::Generator(arg),
106
logging_stats(in_logging_stats),
109
all_status_vars_it= in_all_status_vars->begin();
110
all_status_vars_end= in_all_status_vars->end();
112
status_var_to_display= NULL;
115
ScoreboardSlot *scoreboard_slot= logging_stats->getCurrentScoreboard()->findOurScoreboardSlot(&getSession());
117
if (scoreboard_slot != NULL)
119
/* A copy of the current status vars for a particular session */
120
status_var_to_display= new StatusVars(*scoreboard_slot->getStatusVars());
122
/* Sum the current scoreboard this will give us a value for any variables that have global meaning */
123
StatusVars current_scoreboard_status_vars;
124
CumulativeStats *cumulativeStats= logging_stats->getCumulativeStats();
125
cumulativeStats->sumCurrentScoreboard(logging_stats->getCurrentScoreboard(), ¤t_scoreboard_status_vars, NULL);
127
/* Copy the above to get a value for any variables that have global meaning */
128
status_var_to_display->copyGlobalVariables(logging_stats->getCumulativeStats()->getGlobalStatusVars());
129
status_var_to_display->copyGlobalVariables(¤t_scoreboard_status_vars);
133
status_var_to_display= NULL;
136
else // global status
138
status_var_to_display= new StatusVars();
139
CumulativeStats *cumulativeStats= logging_stats->getCumulativeStats();
140
cumulativeStats->sumCurrentScoreboard(logging_stats->getCurrentScoreboard(), status_var_to_display, NULL);
141
status_var_to_display->merge(logging_stats->getCumulativeStats()->getGlobalStatusVars());
145
StatusTool::Generator::~Generator()
147
delete status_var_to_display;
150
bool StatusTool::Generator::populate()
152
if (status_var_to_display == NULL)
157
while (all_status_vars_it != all_status_vars_end)
159
drizzle_show_var *variables= *all_status_vars_it;
161
if ((variables == NULL) || (variables->name == NULL))
166
drizzle_show_var *var;
167
MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, int64_t);
168
char * const buff= (char *) &buff_data;
171
if var->type is SHOW_FUNC, call the function.
172
Repeat as necessary, if new var is again SHOW_FUNC
175
drizzle_show_var tmp;
177
for (var= variables; var->type == SHOW_FUNC; var= &tmp)
178
((drizzle_show_var_func)((st_show_var_func_container *)var->value)->func)(&tmp, buff);
181
if (isWild(variables->name))
183
++all_status_vars_it;
187
fill(variables->name, var->value, var->type);
189
++all_status_vars_it;
197
void StatusTool::Generator::fill(const string &name, char *value, SHOW_TYPE show_type)
199
struct system_status_var *status_var;
203
status_var= status_var_to_display->getStatusVarCounters();
205
return_value= StatusHelper::fillHelper(status_var, value, show_type);
208
if (return_value.length())