~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/logging_stats/stats_schema.cc

  • Committer: Joe Daly
  • Date: 2010-03-08 04:23:54 UTC
  • mto: This revision was merged to the branch mainline in revision 1380.
  • Revision ID: skinny.moey@gmail.com-20100308042354-7k0jibdqaxkhac7o
scoreboardĀ implementationĀ forĀ statistics

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 std;
 
34
using namespace drizzled;
 
35
 
 
36
CommandsTool::CommandsTool(LoggingStats *logging_stats) :
 
37
  plugin::TableFunction("DATA_DICTIONARY", "SQL_COMMANDS_BY_USER")
 
38
{
 
39
  outer_logging_stats= logging_stats;  
 
40
 
 
41
  add_field("USER");
 
42
  add_field("IP");
 
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);
 
53
}
 
54
 
 
55
CommandsTool::Generator::Generator(Field **arg, LoggingStats *in_logging_stats) :
 
56
  plugin::TableFunction::Generator(arg)
 
57
{
 
58
  pthread_rwlock_rdlock(&LOCK_scoreboard);
 
59
  logging_stats= in_logging_stats;
 
60
 
 
61
  if (logging_stats->isEnabled())
 
62
  {
 
63
    record_number= 0;
 
64
  } 
 
65
  else 
 
66
  {
 
67
    record_number= logging_stats->getScoreBoardSize(); 
 
68
  }
 
69
}
 
70
 
 
71
CommandsTool::Generator::~Generator()
 
72
{
 
73
  pthread_rwlock_unlock(&LOCK_scoreboard);
 
74
}
 
75
 
 
76
bool CommandsTool::Generator::populate()
 
77
{
 
78
  if (record_number == logging_stats->getScoreBoardSize())
 
79
  {
 
80
    return false;
 
81
  }
 
82
  
 
83
  ScoreBoardSlot *score_board_slots= logging_stats->getScoreBoardSlots();
 
84
 
 
85
  while (record_number < logging_stats->getScoreBoardSize())
 
86
  {
 
87
    ScoreBoardSlot *score_board_slot= &score_board_slots[record_number];
 
88
    if (score_board_slot->isInUse())
 
89
    {
 
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());
 
103
      record_number++;
 
104
      break;
 
105
    }
 
106
    else 
 
107
    {
 
108
      record_number++;
 
109
    }
 
110
  }
 
111
 
 
112
  return true;
 
113
}