107 #include <drizzled/statistics_variables.h>
108 #include "stats_schema.h"
111 using namespace drizzled;
112 using namespace plugin;
115 SessionStatementsTool::SessionStatementsTool(
LoggingStats *in_logging_stats) :
116 plugin::TableFunction(
"DATA_DICTIONARY",
"SESSION_STATEMENTS")
118 logging_stats= in_logging_stats;
119 add_field(
"VARIABLE_NAME");
120 add_field(
"VARIABLE_VALUE", 1024);
123 SessionStatementsTool::Generator::Generator(
Field **arg,
LoggingStats *in_logging_stats) :
124 plugin::TableFunction::Generator(arg)
129 Scoreboard *current_scoreboard= in_logging_stats->getCurrentScoreboard();
131 uint32_t bucket_number= current_scoreboard->getBucketNumber(&getSession());
133 std::vector<ScoreboardSlot* > *scoreboard_vector=
134 current_scoreboard->getVectorOfScoreboardVectors()->at(bucket_number);
137 for (std::vector<ScoreboardSlot *>::iterator it= scoreboard_vector->begin();
138 it != scoreboard_vector->end(); ++it)
140 scoreboard_slot= *it;
141 if (scoreboard_slot->getSessionId() == getSession().getSessionId())
149 if (scoreboard_slot != NULL)
151 user_commands= scoreboard_slot->getUserCommands();
155 bool SessionStatementsTool::Generator::populate()
157 if (user_commands == NULL)
162 uint32_t number_identifiers= UserCommands::getStatusVarsCount();
164 if (count == number_identifiers)
169 push(UserCommands::COM_STATUS_VARS[count]);
171 oss << user_commands->getCount(count);
178 GlobalStatementsTool::GlobalStatementsTool(
LoggingStats *in_logging_stats) :
179 plugin::TableFunction(
"DATA_DICTIONARY",
"GLOBAL_STATEMENTS")
181 logging_stats= in_logging_stats;
182 add_field(
"VARIABLE_NAME");
183 add_field(
"VARIABLE_VALUE", 1024);
186 GlobalStatementsTool::Generator::Generator(
Field **arg,
LoggingStats *in_logging_stats) :
187 plugin::TableFunction::Generator(arg)
192 CumulativeStats *cumulativeStats= in_logging_stats->getCumulativeStats();
193 cumulativeStats->sumCurrentScoreboard(in_logging_stats->getCurrentScoreboard(),
194 NULL, global_stats_to_display->getUserCommands());
195 global_stats_to_display->merge(in_logging_stats->getCumulativeStats()->getGlobalStats());
198 GlobalStatementsTool::Generator::~Generator()
200 delete global_stats_to_display;
203 bool GlobalStatementsTool::Generator::populate()
205 uint32_t number_identifiers= UserCommands::getStatusVarsCount();
206 if (count == number_identifiers)
211 push(UserCommands::COM_STATUS_VARS[count]);
213 oss << global_stats_to_display->getUserCommands()->getCount(count);
220 CurrentCommandsTool::CurrentCommandsTool(
LoggingStats *logging_stats) :
221 plugin::TableFunction(
"DATA_DICTIONARY",
"CURRENT_SQL_COMMANDS")
223 outer_logging_stats= logging_stats;
225 add_field(
"USERNAME");
228 uint32_t number_commands= UserCommands::getUserCounts();
230 for (uint32_t j= 0; j < number_commands; ++j)
232 add_field(UserCommands::USER_COUNTS[j], TableFunction::NUMBER);
236 CurrentCommandsTool::Generator::Generator(
Field **arg,
LoggingStats *logging_stats) :
237 plugin::TableFunction::Generator(arg)
239 inner_logging_stats= logging_stats;
241 isEnabled= inner_logging_stats->isEnabled();
243 if (isEnabled ==
false)
248 current_scoreboard= logging_stats->getCurrentScoreboard();
251 vector_of_scoreboard_vectors_it= current_scoreboard->getVectorOfScoreboardVectors()->begin();
252 vector_of_scoreboard_vectors_end= current_scoreboard->getVectorOfScoreboardVectors()->end();
254 setVectorIteratorsAndLock(current_bucket);
257 void CurrentCommandsTool::Generator::setVectorIteratorsAndLock(uint32_t bucket_number)
259 std::vector<ScoreboardSlot* > *scoreboard_vector=
260 current_scoreboard->getVectorOfScoreboardVectors()->at(bucket_number);
262 current_lock= current_scoreboard->getVectorOfScoreboardLocks()->at(bucket_number);
264 scoreboard_vector_it= scoreboard_vector->begin();
265 scoreboard_vector_end= scoreboard_vector->end();
266 current_lock->lock_shared();
269 bool CurrentCommandsTool::Generator::populate()
271 if (isEnabled ==
false)
276 while (vector_of_scoreboard_vectors_it != vector_of_scoreboard_vectors_end)
278 while (scoreboard_vector_it != scoreboard_vector_end)
281 if (scoreboard_slot->isInUse())
283 UserCommands *user_commands= scoreboard_slot->getUserCommands();
284 push(scoreboard_slot->getUser());
285 push(scoreboard_slot->getIp());
287 uint32_t number_commands= UserCommands::getUserCounts();
289 for (uint32_t j= 0; j < number_commands; ++j)
291 push(user_commands->getUserCount(j));
294 ++scoreboard_vector_it;
297 ++scoreboard_vector_it;
300 ++vector_of_scoreboard_vectors_it;
301 current_lock->unlock_shared();
303 if (vector_of_scoreboard_vectors_it != vector_of_scoreboard_vectors_end)
305 setVectorIteratorsAndLock(current_bucket);
312 CumulativeCommandsTool::CumulativeCommandsTool(
LoggingStats *logging_stats) :
313 plugin::TableFunction(
"DATA_DICTIONARY",
"CUMULATIVE_SQL_COMMANDS")
315 outer_logging_stats= logging_stats;
317 add_field(
"USERNAME");
319 uint32_t number_commands= UserCommands::getUserCounts();
321 for (uint32_t j= 0; j < number_commands; ++j)
323 add_field(UserCommands::USER_COUNTS[j], TableFunction::NUMBER);
327 CumulativeCommandsTool::Generator::Generator(
Field **arg,
LoggingStats *logging_stats) :
328 plugin::TableFunction::Generator(arg)
330 inner_logging_stats= logging_stats;
333 if (inner_logging_stats->isEnabled())
335 last_valid_index= inner_logging_stats->getCumulativeStats()->getCumulativeStatsLastValidIndex();
339 last_valid_index= INVALID_INDEX;
343 bool CumulativeCommandsTool::Generator::populate()
345 if ((record_number > last_valid_index) || (last_valid_index == INVALID_INDEX))
350 while (record_number <= last_valid_index)
353 inner_logging_stats->getCumulativeStats()->getCumulativeStatsByUserVector()->at(record_number);
355 if (cumulative_scoreboard_slot->isInUse())
357 UserCommands *user_commands= cumulative_scoreboard_slot->getUserCommands();
358 push(cumulative_scoreboard_slot->getUser());
360 uint32_t number_commands= UserCommands::getUserCounts();
362 for (uint32_t j= 0; j < number_commands; ++j)
364 push(user_commands->getUserCount(j));
378 CumulativeUserStatsTool::CumulativeUserStatsTool(
LoggingStats *logging_stats) :
379 plugin::TableFunction(
"DATA_DICTIONARY",
"CUMULATIVE_USER_STATS")
381 outer_logging_stats= logging_stats;
383 add_field(
"USERNAME");
384 add_field(
"BYTES_RECEIVED");
385 add_field(
"BYTES_SENT");
386 add_field(
"DENIED_CONNECTIONS");
387 add_field(
"LOST_CONNECTIONS");
388 add_field(
"ACCESS_DENIED");
389 add_field(
"CONNECTED_TIME_SEC");
390 add_field(
"EXECUTION_TIME_NSEC");
391 add_field(
"ROWS_FETCHED");
392 add_field(
"ROWS_UPDATED");
393 add_field(
"ROWS_DELETED");
394 add_field(
"ROWS_INSERTED");
397 CumulativeUserStatsTool::Generator::Generator(
Field **arg,
LoggingStats *logging_stats) :
398 plugin::TableFunction::Generator(arg)
400 inner_logging_stats= logging_stats;
403 if (inner_logging_stats->isEnabled())
405 last_valid_index= inner_logging_stats->getCumulativeStats()->getCumulativeStatsLastValidIndex();
409 last_valid_index= INVALID_INDEX;
413 bool CumulativeUserStatsTool::Generator::populate()
415 if ((record_number > last_valid_index) || (last_valid_index == INVALID_INDEX))
420 while (record_number <= last_valid_index)
423 inner_logging_stats->getCumulativeStats()->getCumulativeStatsByUserVector()->at(record_number);
425 if (cumulative_scoreboard_slot->isInUse())
427 StatusVars *status_vars= cumulative_scoreboard_slot->getStatusVars();
428 push(cumulative_scoreboard_slot->getUser());
430 push(status_vars->getStatusVarCounters()->bytes_received);
431 push(status_vars->getStatusVarCounters()->bytes_sent);
432 push(status_vars->getStatusVarCounters()->aborted_connects);
433 push(status_vars->getStatusVarCounters()->aborted_threads);
434 push(status_vars->getStatusVarCounters()->access_denied);
435 push(status_vars->getStatusVarCounters()->connection_time);
436 push(status_vars->getStatusVarCounters()->execution_time_nsec);
437 push(status_vars->sent_row_count);
438 push(status_vars->getStatusVarCounters()->updated_row_count);
439 push(status_vars->getStatusVarCounters()->deleted_row_count);
440 push(status_vars->getStatusVarCounters()->inserted_row_count);
454 ScoreboardStatsTool::ScoreboardStatsTool(
LoggingStats *logging_stats) :
455 plugin::TableFunction(
"DATA_DICTIONARY",
"SCOREBOARD_STATISTICS")
457 outer_logging_stats= logging_stats;
459 add_field(
"SCOREBOARD_SIZE", TableFunction::NUMBER);
460 add_field(
"NUMBER_OF_RANGE_LOCKS", TableFunction::NUMBER);
461 add_field(
"MAX_USERS_LOGGED", TableFunction::NUMBER);
462 add_field(
"MEMORY_USAGE_BYTES", TableFunction::NUMBER);
465 ScoreboardStatsTool::Generator::Generator(
Field **arg,
LoggingStats *logging_stats) :
466 plugin::TableFunction::Generator(arg)
468 inner_logging_stats= logging_stats;
469 is_last_record=
false;
472 bool ScoreboardStatsTool::Generator::populate()
479 Scoreboard *scoreboard= inner_logging_stats->getCurrentScoreboard();
480 CumulativeStats *cumulativeStats= inner_logging_stats->getCumulativeStats();
482 push(static_cast<uint64_t>(scoreboard->getNumberPerBucket() * scoreboard->getNumberBuckets()));
483 push(static_cast<uint64_t>(scoreboard->getNumberBuckets()));
484 push(static_cast<uint64_t>(cumulativeStats->getCumulativeStatsByUserMax()));
485 push(cumulativeStats->getCumulativeSizeBytes() + scoreboard->getScoreboardSizeBytes());
487 is_last_record=
true;