~drizzle-trunk/drizzle/development

1320.4.1 by Joe Daly
scoreboard implementation for statistics
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
1491.4.11 by Joe Daly
move comments to .cc file
30
/**
31
 * @details
32
 *
33
 * This class defines the following DATA_DICTIONARY tables:
34
 *
1561.3.24 by Joe Daly
update comments in various files
35
 * drizzle> describe GLOBAL_STATEMENTS;
1491.4.11 by Joe Daly
move comments to .cc file
36
 * +----------------+---------+-------+---------+-----------------+-----------+
37
 * | Field          | Type    | Null  | Default | Default_is_NULL | On_Update |
38
 * +----------------+---------+-------+---------+-----------------+-----------+
39
 * | VARIABLE_NAME  | VARCHAR | FALSE |         | FALSE           |           |
40
 * | VARIABLE_VALUE | BIGINT  | FALSE |         | FALSE           |           |
41
 * +----------------+---------+-------+---------+-----------------+-----------+
42
 *
1561.3.24 by Joe Daly
update comments in various files
43
 * drizzle> describe SESSION_STATEMENTS;
1491.4.11 by Joe Daly
move comments to .cc file
44
 * +----------------+---------+-------+---------+-----------------+-----------+
45
 * | Field          | Type    | Null  | Default | Default_is_NULL | On_Update |
46
 * +----------------+---------+-------+---------+-----------------+-----------+
47
 * | VARIABLE_NAME  | VARCHAR | FALSE |         | FALSE           |           |
48
 * | VARIABLE_VALUE | BIGINT  | FALSE |         | FALSE           |           |
49
 * +----------------+---------+-------+---------+-----------------+-----------+
50
 *
51
 * drizzle> describe CURRENT_SQL_COMMANDS;
52
 * +----------------+---------+-------+---------+-----------------+-----------+
53
 * | Field          | Type    | Null  | Default | Default_is_NULL | On_Update |
54
 * +----------------+---------+-------+---------+-----------------+-----------+
55
 * | USER           | VARCHAR | FALSE |         | FALSE           |           |
56
 * | IP             | VARCHAR | FALSE |         | FALSE           |           |
57
 * | COUNT_SELECT   | BIGINT  | FALSE |         | FALSE           |           |
58
 * | COUNT_DELETE   | BIGINT  | FALSE |         | FALSE           |           |
59
 * | COUNT_UPDATE   | BIGINT  | FALSE |         | FALSE           |           |
60
 * | COUNT_INSERT   | BIGINT  | FALSE |         | FALSE           |           |
61
 * | COUNT_ROLLBACK | BIGINT  | FALSE |         | FALSE           |           |
62
 * | COUNT_COMMIT   | BIGINT  | FALSE |         | FALSE           |           |
63
 * | COUNT_CREATE   | BIGINT  | FALSE |         | FALSE           |           |
64
 * | COUNT_ALTER    | BIGINT  | FALSE |         | FALSE           |           |
65
 * | COUNT_DROP     | BIGINT  | FALSE |         | FALSE           |           |
66
 * | COUNT_ADMIN    | BIGINT  | FALSE |         | FALSE           |           |
67
 * +----------------+---------+-------+---------+-----------------+-----------+
68
 *
69
 * drizzle> describe CUMULATIVE_SQL_COMMANDS;
70
 * +----------------+---------+-------+---------+-----------------+-----------+
71
 * | Field          | Type    | Null  | Default | Default_is_NULL | On_Update |
72
 * +----------------+---------+-------+---------+-----------------+-----------+
73
 * | USER           | VARCHAR | FALSE |         | FALSE           |           |
74
 * | COUNT_SELECT   | BIGINT  | FALSE |         | FALSE           |           |
75
 * | COUNT_DELETE   | BIGINT  | FALSE |         | FALSE           |           |
76
 * | COUNT_UPDATE   | BIGINT  | FALSE |         | FALSE           |           |
77
 * | COUNT_INSERT   | BIGINT  | FALSE |         | FALSE           |           |
78
 * | COUNT_ROLLBACK | BIGINT  | FALSE |         | FALSE           |           |
79
 * | COUNT_COMMIT   | BIGINT  | FALSE |         | FALSE           |           |
80
 * | COUNT_CREATE   | BIGINT  | FALSE |         | FALSE           |           |
81
 * | COUNT_ALTER    | BIGINT  | FALSE |         | FALSE           |           |
82
 * | COUNT_DROP     | BIGINT  | FALSE |         | FALSE           |           |
83
 * | COUNT_ADMIN    | BIGINT  | FALSE |         | FALSE           |           |
84
 * +----------------+---------+-------+---------+-----------------+-----------+
1625.2.5 by Joe Daly
add comment describing table, and fix up schema_dictionary test
85
 *
86
 * drizzle> describe CUMULATIVE_USER_STATS;
87
 * +---------------------+---------+-------+---------+-----------------+-----------+
88
 * | Field               | Type    | Null  | Default | Default_is_NULL | On_Update |
89
 * +---------------------+---------+-------+---------+-----------------+-----------+
90
 * | USER                | VARCHAR | FALSE |         | FALSE           |           | 
91
 * | BYTES_RECEIVED      | VARCHAR | FALSE |         | FALSE           |           | 
92
 * | BYTES_SENT          | VARCHAR | FALSE |         | FALSE           |           | 
93
 * | DENIED_CONNECTIONS  | VARCHAR | FALSE |         | FALSE           |           | 
94
 * | LOST_CONNECTIONS    | VARCHAR | FALSE |         | FALSE           |           | 
95
 * | ACCESS_DENIED       | VARCHAR | FALSE |         | FALSE           |           | 
96
 * | CONNECTED_TIME_SEC  | VARCHAR | FALSE |         | FALSE           |           | 
97
 * | EXECUTION_TIME_NSEC | VARCHAR | FALSE |         | FALSE           |           | 
98
 * | ROWS_FETCHED        | VARCHAR | FALSE |         | FALSE           |           | 
99
 * | ROWS_UPDATED        | VARCHAR | FALSE |         | FALSE           |           | 
100
 * | ROWS_DELETED        | VARCHAR | FALSE |         | FALSE           |           | 
101
 * | ROWS_INSERTED       | VARCHAR | FALSE |         | FALSE           |           | 
102
 * +---------------------+---------+-------+---------+-----------------+-----------+
103
 *
1491.4.11 by Joe Daly
move comments to .cc file
104
 */
105
1561.3.8 by Joe Daly
try and create some logic with header files, and implement flush status properly
106
#include <config.h>
107
1320.4.1 by Joe Daly
scoreboard implementation for statistics
108
#include "stats_schema.h"
109
1491.4.15 by Joe Daly
remove com_stat_vars and rework lock in scoreboard to not lock on Sessions locating a slot they previously owned
110
#include <sstream>
111
1320.4.7 by Joe Daly
fix up some variable names, and namespaces paths in *.cc files, and add constant for UNINITIALIZED
112
using namespace drizzled;
113
using namespace plugin;
1320.4.1 by Joe Daly
scoreboard implementation for statistics
114
using namespace std;
115
1491.4.6 by Joe Daly
rework stats_schema use static char * for command strings
116
SessionStatementsTool::SessionStatementsTool(LoggingStats *in_logging_stats) :
1491.4.25 by Joe Daly
disable logging_stats plugin and rename GLOBAL_STATEMENTS and SESSION_STATEMENTS tables to remove NEW tag
117
  plugin::TableFunction("DATA_DICTIONARY", "SESSION_STATEMENTS")
1491.4.6 by Joe Daly
rework stats_schema use static char * for command strings
118
{
119
  logging_stats= in_logging_stats;
120
  add_field("VARIABLE_NAME");
1491.4.15 by Joe Daly
remove com_stat_vars and rework lock in scoreboard to not lock on Sessions locating a slot they previously owned
121
  add_field("VARIABLE_VALUE", 1024);
1491.4.6 by Joe Daly
rework stats_schema use static char * for command strings
122
}
123
124
SessionStatementsTool::Generator::Generator(Field **arg, LoggingStats *logging_stats) :
125
  plugin::TableFunction::Generator(arg)
126
{
127
  count= 0;
128
129
  /* Set user_commands */
130
  Scoreboard *current_scoreboard= logging_stats->getCurrentScoreboard();
131
1603 by Brian Aker
Remove current_session from usage in table stats logging.
132
  uint32_t bucket_number= current_scoreboard->getBucketNumber(&getSession());
1491.4.6 by Joe Daly
rework stats_schema use static char * for command strings
133
134
  vector<ScoreboardSlot* > *scoreboard_vector=
135
     current_scoreboard->getVectorOfScoreboardVectors()->at(bucket_number);
136
137
  vector<ScoreboardSlot *>::iterator scoreboard_vector_it= scoreboard_vector->begin();
138
  vector<ScoreboardSlot *>::iterator scoreboard_vector_end= scoreboard_vector->end();
139
140
  ScoreboardSlot *scoreboard_slot= NULL;
141
  for (vector<ScoreboardSlot *>::iterator it= scoreboard_vector->begin();
142
       it != scoreboard_vector->end(); ++it)
143
  {
144
    scoreboard_slot= *it;
1603 by Brian Aker
Remove current_session from usage in table stats logging.
145
    if (scoreboard_slot->getSessionId() == getSession().getSessionId())
1491.4.6 by Joe Daly
rework stats_schema use static char * for command strings
146
    {
147
      break;
148
    }
149
  }
150
151
  user_commands= NULL;
152
153
  if (scoreboard_slot != NULL)
154
  {
155
    user_commands= scoreboard_slot->getUserCommands();
156
  }
157
}
158
159
bool SessionStatementsTool::Generator::populate()
160
{
161
  if (user_commands == NULL)
162
  {
163
    return false;
164
  } 
165
1491.4.12 by Joe Daly
add all the com_stats vars
166
  uint32_t number_identifiers= UserCommands::getStatusVarsCount();
1491.4.6 by Joe Daly
rework stats_schema use static char * for command strings
167
168
  if (count == number_identifiers)
169
  {
170
    return false;
171
  }
172
1491.4.15 by Joe Daly
remove com_stat_vars and rework lock in scoreboard to not lock on Sessions locating a slot they previously owned
173
  push(UserCommands::COM_STATUS_VARS[count]);
174
  ostringstream oss;
175
  oss << user_commands->getCount(count);
176
  push(oss.str()); 
1491.4.6 by Joe Daly
rework stats_schema use static char * for command strings
177
178
  ++count;
179
  return true;
180
}
181
182
GlobalStatementsTool::GlobalStatementsTool(LoggingStats *in_logging_stats) :
1491.4.25 by Joe Daly
disable logging_stats plugin and rename GLOBAL_STATEMENTS and SESSION_STATEMENTS tables to remove NEW tag
183
  plugin::TableFunction("DATA_DICTIONARY", "GLOBAL_STATEMENTS")
1491.4.2 by Joe Daly
rework atomics on cumulative user tables
184
{   
1491.4.6 by Joe Daly
rework stats_schema use static char * for command strings
185
  logging_stats= in_logging_stats;
1491.4.2 by Joe Daly
rework atomics on cumulative user tables
186
  add_field("VARIABLE_NAME");
1491.4.15 by Joe Daly
remove com_stat_vars and rework lock in scoreboard to not lock on Sessions locating a slot they previously owned
187
  add_field("VARIABLE_VALUE", 1024);
1491.4.2 by Joe Daly
rework atomics on cumulative user tables
188
}
189
1491.4.6 by Joe Daly
rework stats_schema use static char * for command strings
190
GlobalStatementsTool::Generator::Generator(Field **arg, LoggingStats *logging_stats) :
1491.4.2 by Joe Daly
rework atomics on cumulative user tables
191
  plugin::TableFunction::Generator(arg)
192
{
193
  count= 0;
1616.2.1 by Joe Daly
update GLOBAL_STATEMENTS logic it was not including a sum of the current scoreboard only sessions that had terminated
194
  /* add the current scoreboard and the saved global statements */
195
  global_stats_to_display= new GlobalStats();
196
  CumulativeStats *cumulativeStats= logging_stats->getCumulativeStats();
197
  cumulativeStats->sumCurrentScoreboard(logging_stats->getCurrentScoreboard(), 
198
                                        NULL, global_stats_to_display->getUserCommands());
199
  global_stats_to_display->merge(logging_stats->getCumulativeStats()->getGlobalStats()); 
200
}
201
202
GlobalStatementsTool::Generator::~Generator()
203
{
204
  delete global_stats_to_display;
1491.4.2 by Joe Daly
rework atomics on cumulative user tables
205
}
206
1491.4.6 by Joe Daly
rework stats_schema use static char * for command strings
207
bool GlobalStatementsTool::Generator::populate()
1491.4.2 by Joe Daly
rework atomics on cumulative user tables
208
{
1491.4.12 by Joe Daly
add all the com_stats vars
209
  uint32_t number_identifiers= UserCommands::getStatusVarsCount(); 
1491.4.6 by Joe Daly
rework stats_schema use static char * for command strings
210
  if (count == number_identifiers)
1491.4.2 by Joe Daly
rework atomics on cumulative user tables
211
  {
212
    return false;
213
  }
214
1491.4.15 by Joe Daly
remove com_stat_vars and rework lock in scoreboard to not lock on Sessions locating a slot they previously owned
215
  push(UserCommands::COM_STATUS_VARS[count]);
216
  ostringstream oss;
1616.2.1 by Joe Daly
update GLOBAL_STATEMENTS logic it was not including a sum of the current scoreboard only sessions that had terminated
217
  oss << global_stats_to_display->getUserCommands()->getCount(count);
1491.4.15 by Joe Daly
remove com_stat_vars and rework lock in scoreboard to not lock on Sessions locating a slot they previously owned
218
  push(oss.str());
1491.4.2 by Joe Daly
rework atomics on cumulative user tables
219
220
  ++count;
221
  return true;
222
}
223
1491.4.4 by Joe Daly
rework UserCommands class to have a simplier interface and remove get/increment functions
224
CurrentCommandsTool::CurrentCommandsTool(LoggingStats *logging_stats) :
1320.5.1 by Joe Daly
add cumulative stats
225
  plugin::TableFunction("DATA_DICTIONARY", "CURRENT_SQL_COMMANDS")
1320.4.1 by Joe Daly
scoreboard implementation for statistics
226
{
1491.4.4 by Joe Daly
rework UserCommands class to have a simplier interface and remove get/increment functions
227
  outer_logging_stats= logging_stats;
1320.4.1 by Joe Daly
scoreboard implementation for statistics
228
229
  add_field("USER");
230
  add_field("IP");
1491.4.4 by Joe Daly
rework UserCommands class to have a simplier interface and remove get/increment functions
231
1491.4.12 by Joe Daly
add all the com_stats vars
232
  uint32_t number_commands= UserCommands::getUserCounts();
1491.4.9 by Joe Daly
remove Identifiers class and fix guard in header
233
234
  for (uint32_t j= 0; j < number_commands; ++j)
1491.4.4 by Joe Daly
rework UserCommands class to have a simplier interface and remove get/increment functions
235
  {
1491.4.12 by Joe Daly
add all the com_stats vars
236
    add_field(UserCommands::USER_COUNTS[j], TableFunction::NUMBER);
1491.4.9 by Joe Daly
remove Identifiers class and fix guard in header
237
  } 
1320.4.1 by Joe Daly
scoreboard implementation for statistics
238
}
239
1320.5.6 by Joe Daly
first pass at using a module vector approach of scoreboard
240
CurrentCommandsTool::Generator::Generator(Field **arg, LoggingStats *logging_stats) :
1320.4.1 by Joe Daly
scoreboard implementation for statistics
241
  plugin::TableFunction::Generator(arg)
242
{
1491.4.4 by Joe Daly
rework UserCommands class to have a simplier interface and remove get/increment functions
243
  inner_logging_stats= logging_stats;
244
245
  isEnabled= inner_logging_stats->isEnabled();
1320.5.17 by Joe Daly
clean up some unneeded destructors and add update comments
246
247
  if (isEnabled == false)
248
  {
249
    return;
250
  }
251
1320.5.6 by Joe Daly
first pass at using a module vector approach of scoreboard
252
  current_scoreboard= logging_stats->getCurrentScoreboard();
253
  current_bucket= 0;
1320.5.7 by Joe Daly
get tests to work, need to fix read lock on stats_schema current commands
254
255
  vector_of_scoreboard_vectors_it= current_scoreboard->getVectorOfScoreboardVectors()->begin();
256
  vector_of_scoreboard_vectors_end= current_scoreboard->getVectorOfScoreboardVectors()->end();
257
1320.5.6 by Joe Daly
first pass at using a module vector approach of scoreboard
258
  setVectorIteratorsAndLock(current_bucket);
1320.4.1 by Joe Daly
scoreboard implementation for statistics
259
}
260
1320.5.6 by Joe Daly
first pass at using a module vector approach of scoreboard
261
void CurrentCommandsTool::Generator::setVectorIteratorsAndLock(uint32_t bucket_number)
262
{
263
  vector<ScoreboardSlot* > *scoreboard_vector= 
264
    current_scoreboard->getVectorOfScoreboardVectors()->at(bucket_number); 
265
266
  current_lock= current_scoreboard->getVectorOfScoreboardLocks()->at(bucket_number);
267
1320.5.7 by Joe Daly
get tests to work, need to fix read lock on stats_schema current commands
268
  scoreboard_vector_it= scoreboard_vector->begin();
269
  scoreboard_vector_end= scoreboard_vector->end();
1683.1.1 by Joe Daly
use boost for locking instead of pthread
270
  current_lock->lock_shared();
1320.4.1 by Joe Daly
scoreboard implementation for statistics
271
}
272
1320.5.1 by Joe Daly
add cumulative stats
273
bool CurrentCommandsTool::Generator::populate()
1320.4.1 by Joe Daly
scoreboard implementation for statistics
274
{
1320.5.7 by Joe Daly
get tests to work, need to fix read lock on stats_schema current commands
275
  if (isEnabled == false)
1320.4.1 by Joe Daly
scoreboard implementation for statistics
276
  {
277
    return false;
278
  }
1320.5.6 by Joe Daly
first pass at using a module vector approach of scoreboard
279
1320.5.7 by Joe Daly
get tests to work, need to fix read lock on stats_schema current commands
280
  while (vector_of_scoreboard_vectors_it != vector_of_scoreboard_vectors_end)
1320.5.6 by Joe Daly
first pass at using a module vector approach of scoreboard
281
  {
1320.5.7 by Joe Daly
get tests to work, need to fix read lock on stats_schema current commands
282
    while (scoreboard_vector_it != scoreboard_vector_end)
283
    {
284
      ScoreboardSlot *scoreboard_slot= *scoreboard_vector_it; 
285
      if (scoreboard_slot->isInUse())
286
      {
287
        UserCommands *user_commands= scoreboard_slot->getUserCommands();
288
        push(scoreboard_slot->getUser());
289
        push(scoreboard_slot->getIp());
1491.4.4 by Joe Daly
rework UserCommands class to have a simplier interface and remove get/increment functions
290
1491.4.12 by Joe Daly
add all the com_stats vars
291
        uint32_t number_commands= UserCommands::getUserCounts(); 
1491.4.4 by Joe Daly
rework UserCommands class to have a simplier interface and remove get/increment functions
292
1491.4.9 by Joe Daly
remove Identifiers class and fix guard in header
293
        for (uint32_t j= 0; j < number_commands; ++j)
1491.4.4 by Joe Daly
rework UserCommands class to have a simplier interface and remove get/increment functions
294
        {
1491.4.12 by Joe Daly
add all the com_stats vars
295
          push(user_commands->getUserCount(j));
1491.4.4 by Joe Daly
rework UserCommands class to have a simplier interface and remove get/increment functions
296
        }
297
1320.5.20 by Joe Daly
fix incrementors
298
        ++scoreboard_vector_it;
1320.5.7 by Joe Daly
get tests to work, need to fix read lock on stats_schema current commands
299
        return true;
300
      }
1320.5.20 by Joe Daly
fix incrementors
301
      ++scoreboard_vector_it;
1320.5.7 by Joe Daly
get tests to work, need to fix read lock on stats_schema current commands
302
    }
303
    
1320.5.20 by Joe Daly
fix incrementors
304
    ++vector_of_scoreboard_vectors_it;
1683.1.1 by Joe Daly
use boost for locking instead of pthread
305
    current_lock->unlock_shared();
1320.5.21 by Joe Daly
fix incrementors to be prefix
306
    ++current_bucket;
1320.5.7 by Joe Daly
get tests to work, need to fix read lock on stats_schema current commands
307
    if (vector_of_scoreboard_vectors_it != vector_of_scoreboard_vectors_end)
308
    {
309
      setVectorIteratorsAndLock(current_bucket); 
310
    } 
311
  }
312
313
  return false;
1320.4.1 by Joe Daly
scoreboard implementation for statistics
314
}
1320.5.1 by Joe Daly
add cumulative stats
315
316
CumulativeCommandsTool::CumulativeCommandsTool(LoggingStats *logging_stats) :
317
  plugin::TableFunction("DATA_DICTIONARY", "CUMULATIVE_SQL_COMMANDS")
318
{
319
  outer_logging_stats= logging_stats;
320
321
  add_field("USER");
1491.4.4 by Joe Daly
rework UserCommands class to have a simplier interface and remove get/increment functions
322
1491.4.12 by Joe Daly
add all the com_stats vars
323
  uint32_t number_commands= UserCommands::getUserCounts();
1491.4.9 by Joe Daly
remove Identifiers class and fix guard in header
324
325
  for (uint32_t j= 0; j < number_commands; ++j)
1491.4.4 by Joe Daly
rework UserCommands class to have a simplier interface and remove get/increment functions
326
  {
1491.4.12 by Joe Daly
add all the com_stats vars
327
    add_field(UserCommands::USER_COUNTS[j], TableFunction::NUMBER);
1491.4.4 by Joe Daly
rework UserCommands class to have a simplier interface and remove get/increment functions
328
  }
1320.5.1 by Joe Daly
add cumulative stats
329
}
330
1491.4.4 by Joe Daly
rework UserCommands class to have a simplier interface and remove get/increment functions
331
CumulativeCommandsTool::Generator::Generator(Field **arg, LoggingStats *logging_stats) :
1320.5.1 by Joe Daly
add cumulative stats
332
  plugin::TableFunction::Generator(arg)
333
{
1491.4.4 by Joe Daly
rework UserCommands class to have a simplier interface and remove get/increment functions
334
  inner_logging_stats= logging_stats;
1320.5.1 by Joe Daly
add cumulative stats
335
  record_number= 0;
336
1491.4.4 by Joe Daly
rework UserCommands class to have a simplier interface and remove get/increment functions
337
  if (inner_logging_stats->isEnabled())
1320.5.1 by Joe Daly
add cumulative stats
338
  {
1491.4.4 by Joe Daly
rework UserCommands class to have a simplier interface and remove get/increment functions
339
    last_valid_index= inner_logging_stats->getCumulativeStats()->getCumulativeStatsLastValidIndex();
1320.5.1 by Joe Daly
add cumulative stats
340
  }
341
  else
342
  {
1491.4.2 by Joe Daly
rework atomics on cumulative user tables
343
    last_valid_index= INVALID_INDEX; 
1320.5.1 by Joe Daly
add cumulative stats
344
  }
345
}
346
347
bool CumulativeCommandsTool::Generator::populate()
348
{
1491.4.2 by Joe Daly
rework atomics on cumulative user tables
349
  if ((record_number > last_valid_index) || (last_valid_index == INVALID_INDEX))
1320.5.1 by Joe Daly
add cumulative stats
350
  {
351
    return false;
352
  }
353
1491.4.2 by Joe Daly
rework atomics on cumulative user tables
354
  while (record_number <= last_valid_index)
355
  {
356
    ScoreboardSlot *cumulative_scoreboard_slot= 
1491.4.4 by Joe Daly
rework UserCommands class to have a simplier interface and remove get/increment functions
357
      inner_logging_stats->getCumulativeStats()->getCumulativeStatsByUserVector()->at(record_number);
1491.4.2 by Joe Daly
rework atomics on cumulative user tables
358
359
    if (cumulative_scoreboard_slot->isInUse())
360
    {
1491.4.4 by Joe Daly
rework UserCommands class to have a simplier interface and remove get/increment functions
361
      UserCommands *user_commands= cumulative_scoreboard_slot->getUserCommands(); 
1491.4.2 by Joe Daly
rework atomics on cumulative user tables
362
      push(cumulative_scoreboard_slot->getUser());
1491.4.4 by Joe Daly
rework UserCommands class to have a simplier interface and remove get/increment functions
363
1491.4.12 by Joe Daly
add all the com_stats vars
364
      uint32_t number_commands= UserCommands::getUserCounts();
1491.4.4 by Joe Daly
rework UserCommands class to have a simplier interface and remove get/increment functions
365
1491.4.9 by Joe Daly
remove Identifiers class and fix guard in header
366
      for (uint32_t j= 0; j < number_commands; ++j)
1491.4.4 by Joe Daly
rework UserCommands class to have a simplier interface and remove get/increment functions
367
      {
1491.4.12 by Joe Daly
add all the com_stats vars
368
        push(user_commands->getUserCount(j));
1491.4.4 by Joe Daly
rework UserCommands class to have a simplier interface and remove get/increment functions
369
      }
1491.4.2 by Joe Daly
rework atomics on cumulative user tables
370
      ++record_number;
371
      return true;
372
    } 
373
    else 
374
    {
375
      ++record_number;
376
    }
377
  }
378
379
  return false;
1320.5.1 by Joe Daly
add cumulative stats
380
}
1625.2.1 by Joe Daly
initial user stats impl
381
382
CumulativeUserStatsTool::CumulativeUserStatsTool(LoggingStats *logging_stats) :
383
  plugin::TableFunction("DATA_DICTIONARY", "CUMULATIVE_USER_STATS")
384
{
385
  outer_logging_stats= logging_stats;
386
387
  add_field("USER");
388
  add_field("BYTES_RECEIVED");
389
  add_field("BYTES_SENT");
390
  add_field("DENIED_CONNECTIONS");
391
  add_field("LOST_CONNECTIONS");
392
  add_field("ACCESS_DENIED");
393
  add_field("CONNECTED_TIME_SEC");
394
  add_field("EXECUTION_TIME_NSEC");
1625.2.2 by Joe Daly
add counter logic for rows sent/received/inserted/updated
395
  add_field("ROWS_FETCHED");
396
  add_field("ROWS_UPDATED");
397
  add_field("ROWS_DELETED");
398
  add_field("ROWS_INSERTED");
1625.2.1 by Joe Daly
initial user stats impl
399
}
400
401
CumulativeUserStatsTool::Generator::Generator(Field **arg, LoggingStats *logging_stats) :
402
  plugin::TableFunction::Generator(arg)
403
{
404
  inner_logging_stats= logging_stats;
405
  record_number= 0;
406
407
  if (inner_logging_stats->isEnabled())
408
  {
409
    last_valid_index= inner_logging_stats->getCumulativeStats()->getCumulativeStatsLastValidIndex();
410
  }
411
  else
412
  {
413
    last_valid_index= INVALID_INDEX;
414
  }
415
}
416
417
bool CumulativeUserStatsTool::Generator::populate()
418
{
419
  if ((record_number > last_valid_index) || (last_valid_index == INVALID_INDEX))
420
  {
421
    return false;
422
  }
423
424
  while (record_number <= last_valid_index)
425
  {
426
    ScoreboardSlot *cumulative_scoreboard_slot=
427
      inner_logging_stats->getCumulativeStats()->getCumulativeStatsByUserVector()->at(record_number);
428
429
    if (cumulative_scoreboard_slot->isInUse())
430
    {
431
      StatusVars *status_vars= cumulative_scoreboard_slot->getStatusVars();
432
      push(cumulative_scoreboard_slot->getUser());
433
434
      push(status_vars->getStatusVarCounters()->bytes_received);
435
      push(status_vars->getStatusVarCounters()->bytes_sent);
436
      push(status_vars->getStatusVarCounters()->aborted_connects);
437
      push(status_vars->getStatusVarCounters()->aborted_threads);
438
      push(status_vars->getStatusVarCounters()->access_denied);
439
      push(status_vars->getStatusVarCounters()->connection_time);
440
      push(status_vars->getStatusVarCounters()->execution_time_nsec);
1625.2.2 by Joe Daly
add counter logic for rows sent/received/inserted/updated
441
      push(status_vars->sent_row_count);
442
      push(status_vars->getStatusVarCounters()->updated_row_count);
443
      push(status_vars->getStatusVarCounters()->deleted_row_count);
444
      push(status_vars->getStatusVarCounters()->inserted_row_count);
445
1625.2.1 by Joe Daly
initial user stats impl
446
      ++record_number;
447
      return true;
448
    }
449
    else
450
    {
451
      ++record_number;
452
    }
453
  }
454
455
  return false;
456
}
1711.7.2 by Joseph Daly
add memory usage
457
458
ScoreboardStatsTool::ScoreboardStatsTool(LoggingStats *logging_stats) :
459
  plugin::TableFunction("DATA_DICTIONARY", "SCOREBOARD_STATISTICS")
460
{
461
  outer_logging_stats= logging_stats;
462
463
  add_field("SCOREBOARD_SIZE", TableFunction::NUMBER);
464
  add_field("NUMBER_OF_RANGE_LOCKS", TableFunction::NUMBER);
465
  add_field("MAX_USERS_LOGGED", TableFunction::NUMBER);
466
  add_field("MEMORY_USAGE_BYTES", TableFunction::NUMBER);
467
}
468
469
ScoreboardStatsTool::Generator::Generator(Field **arg, LoggingStats *logging_stats) :
470
  plugin::TableFunction::Generator(arg)
471
{
472
  inner_logging_stats= logging_stats;
473
  is_last_record= false; 
474
}
475
476
bool ScoreboardStatsTool::Generator::populate()
477
{
478
  if (is_last_record)
479
  {
480
    return false;
481
  }
482
483
  Scoreboard *scoreboard= inner_logging_stats->getCurrentScoreboard();
484
  CumulativeStats *cumulativeStats= inner_logging_stats->getCumulativeStats();
485
486
  push(static_cast<uint64_t>(scoreboard->getNumberPerBucket() * scoreboard->getNumberBuckets()));
487
  push(static_cast<uint64_t>(scoreboard->getNumberBuckets()));
488
  push(static_cast<uint64_t>(cumulativeStats->getCumulativeStatsByUserMax()));
489
  push(cumulativeStats->getCumulativeSizeBytes() + scoreboard->getScoreboardSizeBytes()); 
490
  
491
  is_last_record= true;
492
493
  return true;
494
}