~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/logging_stats/stats_schema.cc

  • Committer: Monty Taylor
  • Date: 2010-06-02 22:35:45 UTC
  • mto: This revision was merged to the branch mainline in revision 1586.
  • Revision ID: mordred@inaugust.com-20100602223545-q8ekf9b40a85nwuf
Rearragned unittests into a single exe because of how we need to link it
(thanks lifeless)
Link with server symbols without needing to build a library.
Added an additional atomics test which tests whatever version of the atomics
lib the running platform would actually use.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 *
33
33
 * This class defines the following DATA_DICTIONARY tables:
34
34
 *
35
 
 * drizzle> describe GLOBAL_STATEMENTS;
 
35
 * drizzle> describe GLOBAL_STATEMENTS_NEW;
36
36
 * +----------------+---------+-------+---------+-----------------+-----------+
37
37
 * | Field          | Type    | Null  | Default | Default_is_NULL | On_Update |
38
38
 * +----------------+---------+-------+---------+-----------------+-----------+
40
40
 * | VARIABLE_VALUE | BIGINT  | FALSE |         | FALSE           |           |
41
41
 * +----------------+---------+-------+---------+-----------------+-----------+
42
42
 *
43
 
 * drizzle> describe SESSION_STATEMENTS;
 
43
 * drizzle> describe SESSION_STATEMENTS_NEW;
44
44
 * +----------------+---------+-------+---------+-----------------+-----------+
45
45
 * | Field          | Type    | Null  | Default | Default_is_NULL | On_Update |
46
46
 * +----------------+---------+-------+---------+-----------------+-----------+
82
82
 * | COUNT_DROP     | BIGINT  | FALSE |         | FALSE           |           |
83
83
 * | COUNT_ADMIN    | BIGINT  | FALSE |         | FALSE           |           |
84
84
 * +----------------+---------+-------+---------+-----------------+-----------+
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
 
 *
104
85
 */
105
86
 
106
 
#include "config.h"
107
 
 
 
87
#include <config.h>          
108
88
#include "stats_schema.h"
 
89
#include "scoreboard.h"
109
90
 
110
91
#include <sstream>
111
92
 
121
102
  add_field("VARIABLE_VALUE", 1024);
122
103
}
123
104
 
124
 
SessionStatementsTool::Generator::Generator(Field **arg, LoggingStats *in_logging_stats) :
 
105
SessionStatementsTool::Generator::Generator(Field **arg, LoggingStats *logging_stats) :
125
106
  plugin::TableFunction::Generator(arg)
126
107
{
127
108
  count= 0;
128
109
 
129
110
  /* Set user_commands */
130
 
  Scoreboard *current_scoreboard= in_logging_stats->getCurrentScoreboard();
131
 
 
132
 
  uint32_t bucket_number= current_scoreboard->getBucketNumber(&getSession());
133
 
 
134
 
  std::vector<ScoreboardSlot* > *scoreboard_vector=
 
111
  Scoreboard *current_scoreboard= logging_stats->getCurrentScoreboard();
 
112
 
 
113
  Session *this_session= current_session;
 
114
 
 
115
  uint32_t bucket_number= current_scoreboard->getBucketNumber(this_session);
 
116
 
 
117
  vector<ScoreboardSlot* > *scoreboard_vector=
135
118
     current_scoreboard->getVectorOfScoreboardVectors()->at(bucket_number);
136
119
 
137
 
  std::vector<ScoreboardSlot *>::iterator scoreboard_vector_it= scoreboard_vector->begin();
138
 
  std::vector<ScoreboardSlot *>::iterator scoreboard_vector_end= scoreboard_vector->end();
 
120
  vector<ScoreboardSlot *>::iterator scoreboard_vector_it= scoreboard_vector->begin();
 
121
  vector<ScoreboardSlot *>::iterator scoreboard_vector_end= scoreboard_vector->end();
139
122
 
140
123
  ScoreboardSlot *scoreboard_slot= NULL;
141
 
  for (std::vector<ScoreboardSlot *>::iterator it= scoreboard_vector->begin();
 
124
  for (vector<ScoreboardSlot *>::iterator it= scoreboard_vector->begin();
142
125
       it != scoreboard_vector->end(); ++it)
143
126
  {
144
127
    scoreboard_slot= *it;
145
 
    if (scoreboard_slot->getSessionId() == getSession().getSessionId())
 
128
    if (scoreboard_slot->getSessionId() == this_session->getSessionId())
146
129
    {
147
130
      break;
148
131
    }
187
170
  add_field("VARIABLE_VALUE", 1024);
188
171
}
189
172
 
190
 
GlobalStatementsTool::Generator::Generator(Field **arg, LoggingStats *in_logging_stats) :
 
173
GlobalStatementsTool::Generator::Generator(Field **arg, LoggingStats *logging_stats) :
191
174
  plugin::TableFunction::Generator(arg)
192
175
{
193
176
  count= 0;
194
 
  /* add the current scoreboard and the saved global statements */
195
 
  global_stats_to_display= new GlobalStats();
196
 
  CumulativeStats *cumulativeStats= in_logging_stats->getCumulativeStats();
197
 
  cumulativeStats->sumCurrentScoreboard(in_logging_stats->getCurrentScoreboard(), 
198
 
                                        NULL, global_stats_to_display->getUserCommands());
199
 
  global_stats_to_display->merge(in_logging_stats->getCumulativeStats()->getGlobalStats()); 
200
 
}
201
 
 
202
 
GlobalStatementsTool::Generator::~Generator()
203
 
{
204
 
  delete global_stats_to_display;
 
177
  global_stats= logging_stats->getCumulativeStats()->getGlobalStats();
205
178
}
206
179
 
207
180
bool GlobalStatementsTool::Generator::populate()
214
187
 
215
188
  push(UserCommands::COM_STATUS_VARS[count]);
216
189
  ostringstream oss;
217
 
  oss << global_stats_to_display->getUserCommands()->getCount(count);
 
190
  oss << global_stats->getUserCommands()->getCount(count);
218
191
  push(oss.str());
219
192
 
220
193
  ++count;
260
233
 
261
234
void CurrentCommandsTool::Generator::setVectorIteratorsAndLock(uint32_t bucket_number)
262
235
{
263
 
  std::vector<ScoreboardSlot* > *scoreboard_vector= 
 
236
  vector<ScoreboardSlot* > *scoreboard_vector= 
264
237
    current_scoreboard->getVectorOfScoreboardVectors()->at(bucket_number); 
265
238
 
266
239
  current_lock= current_scoreboard->getVectorOfScoreboardLocks()->at(bucket_number);
267
240
 
268
241
  scoreboard_vector_it= scoreboard_vector->begin();
269
242
  scoreboard_vector_end= scoreboard_vector->end();
270
 
  current_lock->lock_shared();
 
243
  pthread_rwlock_rdlock(current_lock);
271
244
}
272
245
 
273
246
bool CurrentCommandsTool::Generator::populate()
302
275
    }
303
276
    
304
277
    ++vector_of_scoreboard_vectors_it;
305
 
    current_lock->unlock_shared();
 
278
    pthread_rwlock_unlock(current_lock); 
306
279
    ++current_bucket;
307
280
    if (vector_of_scoreboard_vectors_it != vector_of_scoreboard_vectors_end)
308
281
    {
378
351
 
379
352
  return false;
380
353
}
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");
395
 
  add_field("ROWS_FETCHED");
396
 
  add_field("ROWS_UPDATED");
397
 
  add_field("ROWS_DELETED");
398
 
  add_field("ROWS_INSERTED");
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);
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
 
 
446
 
      ++record_number;
447
 
      return true;
448
 
    }
449
 
    else
450
 
    {
451
 
      ++record_number;
452
 
    }
453
 
  }
454
 
 
455
 
  return false;
456
 
}
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
 
}