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"
34
using namespace drizzled;
36
CommandsTool::CommandsTool(LoggingStats *logging_stats) :
37
plugin::TableFunction("DATA_DICTIONARY", "SQL_COMMANDS_BY_USER")
39
outer_logging_stats= logging_stats;
43
add_field("COUNT_SELECT", plugin::TableFunction::NUMBER);
44
add_field("COUNT_DELETE", plugin::TableFunction::NUMBER);
45
add_field("COUNT_UPDATE", plugin::TableFunction::NUMBER);
46
add_field("COUNT_INSERT", plugin::TableFunction::NUMBER);
47
add_field("COUNT_ROLLBACK", plugin::TableFunction::NUMBER);
48
add_field("COUNT_COMMIT", plugin::TableFunction::NUMBER);
49
add_field("COUNT_CREATE", plugin::TableFunction::NUMBER);
50
add_field("COUNT_ALTER", plugin::TableFunction::NUMBER);
51
add_field("COUNT_DROP", plugin::TableFunction::NUMBER);
52
add_field("COUNT_ADMIN", plugin::TableFunction::NUMBER);
55
CommandsTool::Generator::Generator(Field **arg, LoggingStats *in_logging_stats) :
56
plugin::TableFunction::Generator(arg)
58
pthread_rwlock_rdlock(&LOCK_scoreboard);
59
logging_stats= in_logging_stats;
61
if (logging_stats->isEnabled())
67
record_number= logging_stats->getScoreBoardSize();
71
CommandsTool::Generator::~Generator()
73
pthread_rwlock_unlock(&LOCK_scoreboard);
76
bool CommandsTool::Generator::populate()
78
if (record_number == logging_stats->getScoreBoardSize())
83
ScoreBoardSlot *score_board_slots= logging_stats->getScoreBoardSlots();
85
while (record_number < logging_stats->getScoreBoardSize())
87
ScoreBoardSlot *score_board_slot= &score_board_slots[record_number];
88
if (score_board_slot->isInUse())
90
UserCommands *user_commands= score_board_slot->getUserCommands();
91
push(score_board_slot->getUser());
92
push(score_board_slot->getIp());
93
push(user_commands->getSelectCount());
94
push(user_commands->getDeleteCount());
95
push(user_commands->getUpdateCount());
96
push(user_commands->getInsertCount());
97
push(user_commands->getRollbackCount());
98
push(user_commands->getCommitCount());
99
push(user_commands->getCreateCount());
100
push(user_commands->getAlterCount());
101
push(user_commands->getDropCount());
102
push(user_commands->getAdminCount());