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.
31
#include "stats_schema.h"
33
using namespace drizzled;
34
using namespace plugin;
37
CommandsTool::CommandsTool(LoggingStats *logging_stats) :
38
plugin::TableFunction("DATA_DICTIONARY", "SQL_COMMANDS_BY_USER")
40
outer_logging_stats= logging_stats;
44
add_field("COUNT_SELECT", TableFunction::NUMBER);
45
add_field("COUNT_DELETE", TableFunction::NUMBER);
46
add_field("COUNT_UPDATE", TableFunction::NUMBER);
47
add_field("COUNT_INSERT", TableFunction::NUMBER);
48
add_field("COUNT_ROLLBACK", TableFunction::NUMBER);
49
add_field("COUNT_COMMIT", TableFunction::NUMBER);
50
add_field("COUNT_CREATE", TableFunction::NUMBER);
51
add_field("COUNT_ALTER", TableFunction::NUMBER);
52
add_field("COUNT_DROP", TableFunction::NUMBER);
53
add_field("COUNT_ADMIN", TableFunction::NUMBER);
56
CommandsTool::Generator::Generator(Field **arg, LoggingStats *in_logging_stats) :
57
plugin::TableFunction::Generator(arg)
59
pthread_rwlock_rdlock(&LOCK_scoreboard);
60
logging_stats= in_logging_stats;
62
if (logging_stats->isEnabled())
68
record_number= logging_stats->getScoreBoardSize();
72
CommandsTool::Generator::~Generator()
74
pthread_rwlock_unlock(&LOCK_scoreboard);
77
bool CommandsTool::Generator::populate()
79
if (record_number == logging_stats->getScoreBoardSize())
84
ScoreBoardSlot *score_board_slots= logging_stats->getScoreBoardSlots();
86
while (record_number < logging_stats->getScoreBoardSize())
88
ScoreBoardSlot *score_board_slot= &score_board_slots[record_number];
89
if (score_board_slot->isInUse())
91
UserCommands *user_commands= score_board_slot->getUserCommands();
92
push(score_board_slot->getUser());
93
push(score_board_slot->getIp());
94
push(user_commands->getSelectCount());
95
push(user_commands->getDeleteCount());
96
push(user_commands->getUpdateCount());
97
push(user_commands->getInsertCount());
98
push(user_commands->getRollbackCount());
99
push(user_commands->getCommitCount());
100
push(user_commands->getCreateCount());
101
push(user_commands->getAlterCount());
102
push(user_commands->getDropCount());
103
push(user_commands->getAdminCount());