00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00054 #include <config.h>
00055
00056 #include "status_tool.h"
00057 #include <drizzled/status_helper.h>
00058
00059 #include <vector>
00060 #include <sstream>
00061
00062 using namespace drizzled;
00063 using namespace plugin;
00064 using namespace std;
00065
00066
00067 class ShowVarCmpFunctor
00068 {
00069 public:
00070 ShowVarCmpFunctor() { }
00071 inline bool operator()(const drizzle_show_var *var1, const drizzle_show_var *var2) const
00072 {
00073 int val= strcmp(var1->name, var2->name);
00074 return (val < 0);
00075 }
00076 };
00077
00078 StatusTool::StatusTool(LoggingStats *in_logging_stats, bool inIsLocal) :
00079 TableFunction("DATA_DICTIONARY", inIsLocal ? "SESSION_STATUS" : "GLOBAL_STATUS"),
00080 outer_logging_stats(in_logging_stats),
00081 isLocal(inIsLocal)
00082 {
00083 add_field("VARIABLE_NAME");
00084 add_field("VARIABLE_VALUE", 1024);
00085
00086 drizzle_show_var *var= NULL;
00087 uint32_t count= 0;
00088 std::vector<drizzle_show_var *>::iterator all_status_vars_iterator= all_status_vars.begin();
00089 while (true)
00090 {
00091 var= &StatusHelper::status_vars_defs[count];
00092 if ((var == NULL) || (var->name == NULL))
00093 {
00094 break;
00095 }
00096 all_status_vars_iterator= all_status_vars.insert(all_status_vars_iterator, var);
00097 ++count;
00098 }
00099 sort(all_status_vars.begin(), all_status_vars.end(), ShowVarCmpFunctor());
00100 }
00101
00102 StatusTool::Generator::Generator(Field **arg, LoggingStats *in_logging_stats,
00103 std::vector<drizzle_show_var *> *in_all_status_vars,
00104 bool inIsLocal) :
00105 TableFunction::Generator(arg),
00106 logging_stats(in_logging_stats),
00107 isLocal(inIsLocal)
00108 {
00109 all_status_vars_it= in_all_status_vars->begin();
00110 all_status_vars_end= in_all_status_vars->end();
00111
00112 status_var_to_display= NULL;
00113 if (isLocal)
00114 {
00115 ScoreboardSlot *scoreboard_slot= logging_stats->getCurrentScoreboard()->findOurScoreboardSlot(&getSession());
00116
00117 if (scoreboard_slot != NULL)
00118 {
00119
00120 status_var_to_display= new StatusVars(*scoreboard_slot->getStatusVars());
00121
00122
00123 StatusVars current_scoreboard_status_vars;
00124 CumulativeStats *cumulativeStats= logging_stats->getCumulativeStats();
00125 cumulativeStats->sumCurrentScoreboard(logging_stats->getCurrentScoreboard(), ¤t_scoreboard_status_vars, NULL);
00126
00127
00128 status_var_to_display->copyGlobalVariables(logging_stats->getCumulativeStats()->getGlobalStatusVars());
00129 status_var_to_display->copyGlobalVariables(¤t_scoreboard_status_vars);
00130 }
00131 else
00132 {
00133 status_var_to_display= NULL;
00134 }
00135 }
00136 else
00137 {
00138 status_var_to_display= new StatusVars();
00139 CumulativeStats *cumulativeStats= logging_stats->getCumulativeStats();
00140 cumulativeStats->sumCurrentScoreboard(logging_stats->getCurrentScoreboard(), status_var_to_display, NULL);
00141 status_var_to_display->merge(logging_stats->getCumulativeStats()->getGlobalStatusVars());
00142 }
00143 }
00144
00145 StatusTool::Generator::~Generator()
00146 {
00147 delete status_var_to_display;
00148 }
00149
00150 bool StatusTool::Generator::populate()
00151 {
00152 if (status_var_to_display == NULL)
00153 {
00154 return false;
00155 }
00156
00157 while (all_status_vars_it != all_status_vars_end)
00158 {
00159 drizzle_show_var *variables= *all_status_vars_it;
00160
00161 if ((variables == NULL) || (variables->name == NULL))
00162 {
00163 return false;
00164 }
00165
00166 drizzle_show_var *var;
00167 MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, int64_t);
00168 char * const buff= (char *) &buff_data;
00169
00170
00171
00172
00173
00174 {
00175 drizzle_show_var tmp;
00176
00177 for (var= variables; var->type == SHOW_FUNC; var= &tmp)
00178 ((drizzle_show_var_func)((st_show_var_func_container *)var->value)->func)(&tmp, buff);
00179 }
00180
00181 if (isWild(variables->name))
00182 {
00183 ++all_status_vars_it;
00184 continue;
00185 }
00186
00187 fill(variables->name, var->value, var->type);
00188
00189 ++all_status_vars_it;
00190
00191 return true;
00192 }
00193
00194 return false;
00195 }
00196
00197 void StatusTool::Generator::fill(const string &name, char *value, SHOW_TYPE show_type)
00198 {
00199 struct system_status_var *status_var;
00200 ostringstream oss;
00201 string return_value;
00202
00203 status_var= status_var_to_display->getStatusVarCounters();
00204
00205 return_value= StatusHelper::fillHelper(status_var, value, show_type);
00206
00207 push(name);
00208 if (return_value.length())
00209 {
00210 push(return_value);
00211 }
00212 else
00213 {
00214 push(" ");
00215 }
00216 }