~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/logging_stats/stats_schema.cc

  • Committer: Siddharth Prakash Singh
  • Date: 2010-03-26 19:25:23 UTC
  • mfrom: (1410 drizzle)
  • mto: This revision was merged to the branch mainline in revision 1425.
  • Revision ID: spsneo@spsneo-laptop-20100326192523-ibjlbt1p692vobtj
merging with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2010, Joseph Daly <skinny.moey@gmail.com>
 
3
 * All rights reserved.
 
4
 *
 
5
 * Redistribution and use in source and binary forms, with or without
 
6
 * modification, are permitted provided that the following conditions are met:
 
7
 *
 
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.
 
16
 *
 
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.
 
28
 */
 
29
 
 
30
#include <config.h>          
 
31
#include "stats_schema.h"
 
32
 
 
33
using namespace drizzled;
 
34
using namespace plugin;
 
35
using namespace std;
 
36
 
 
37
CommandsTool::CommandsTool(LoggingStats *logging_stats) :
 
38
  plugin::TableFunction("DATA_DICTIONARY", "SQL_COMMANDS_BY_USER")
 
39
{
 
40
  outer_logging_stats= logging_stats;  
 
41
 
 
42
  add_field("USER");
 
43
  add_field("IP");
 
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);
 
54
}
 
55
 
 
56
CommandsTool::Generator::Generator(Field **arg, LoggingStats *in_logging_stats) :
 
57
  plugin::TableFunction::Generator(arg)
 
58
{
 
59
  pthread_rwlock_rdlock(&LOCK_scoreboard);
 
60
  logging_stats= in_logging_stats;
 
61
 
 
62
  if (logging_stats->isEnabled())
 
63
  {
 
64
    record_number= 0;
 
65
  } 
 
66
  else 
 
67
  {
 
68
    record_number= logging_stats->getScoreBoardSize(); 
 
69
  }
 
70
}
 
71
 
 
72
CommandsTool::Generator::~Generator()
 
73
{
 
74
  pthread_rwlock_unlock(&LOCK_scoreboard);
 
75
}
 
76
 
 
77
bool CommandsTool::Generator::populate()
 
78
{
 
79
  if (record_number == logging_stats->getScoreBoardSize())
 
80
  {
 
81
    return false;
 
82
  }
 
83
  
 
84
  ScoreBoardSlot *score_board_slots= logging_stats->getScoreBoardSlots();
 
85
 
 
86
  while (record_number < logging_stats->getScoreBoardSize())
 
87
  {
 
88
    ScoreBoardSlot *score_board_slot= &score_board_slots[record_number];
 
89
    if (score_board_slot->isInUse())
 
90
    {
 
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());
 
104
      record_number++;
 
105
      return true;
 
106
    }
 
107
    else 
 
108
    {
 
109
      record_number++;
 
110
    }
 
111
  }
 
112
 
 
113
  return false;
 
114
}