~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/logging_stats/stats_schema.cc

  • Committer: Brian Aker
  • Date: 2010-06-22 01:08:50 UTC
  • mto: This revision was merged to the branch mainline in revision 1635.
  • Revision ID: brian@gaz-20100622010850-eh2gi2i0e1kp0jye
Put a copy of the Session in the root of function to make use of.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2010 Joseph Daly <skinny.moey@gmail.com>
 
2
 * Copyright (c) 2010, Joseph Daly <skinny.moey@gmail.com>
3
3
 * All rights reserved.
4
4
 *
5
5
 * Redistribution and use in source and binary forms, with or without
52
52
 * +----------------+---------+-------+---------+-----------------+-----------+
53
53
 * | Field          | Type    | Null  | Default | Default_is_NULL | On_Update |
54
54
 * +----------------+---------+-------+---------+-----------------+-----------+
55
 
 * | USERNAME       | VARCHAR | FALSE |         | FALSE           |           |
 
55
 * | USER           | VARCHAR | FALSE |         | FALSE           |           |
56
56
 * | IP             | VARCHAR | FALSE |         | FALSE           |           |
57
57
 * | COUNT_SELECT   | BIGINT  | FALSE |         | FALSE           |           |
58
58
 * | COUNT_DELETE   | BIGINT  | FALSE |         | FALSE           |           |
70
70
 * +----------------+---------+-------+---------+-----------------+-----------+
71
71
 * | Field          | Type    | Null  | Default | Default_is_NULL | On_Update |
72
72
 * +----------------+---------+-------+---------+-----------------+-----------+
73
 
 * | USERNAME       | VARCHAR | FALSE |         | FALSE           |           |
 
73
 * | USER           | VARCHAR | FALSE |         | FALSE           |           |
74
74
 * | COUNT_SELECT   | BIGINT  | FALSE |         | FALSE           |           |
75
75
 * | COUNT_DELETE   | BIGINT  | FALSE |         | FALSE           |           |
76
76
 * | COUNT_UPDATE   | BIGINT  | FALSE |         | FALSE           |           |
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
 
 * | USERNAME            | 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
87
#include <config.h>
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();
 
111
  Scoreboard *current_scoreboard= logging_stats->getCurrentScoreboard();
131
112
 
132
113
  uint32_t bucket_number= current_scoreboard->getBucketNumber(&getSession());
133
114
 
134
 
  std::vector<ScoreboardSlot* > *scoreboard_vector=
 
115
  vector<ScoreboardSlot* > *scoreboard_vector=
135
116
     current_scoreboard->getVectorOfScoreboardVectors()->at(bucket_number);
136
117
 
137
 
  std::vector<ScoreboardSlot *>::iterator scoreboard_vector_it= scoreboard_vector->begin();
138
 
  std::vector<ScoreboardSlot *>::iterator scoreboard_vector_end= scoreboard_vector->end();
 
118
  vector<ScoreboardSlot *>::iterator scoreboard_vector_it= scoreboard_vector->begin();
 
119
  vector<ScoreboardSlot *>::iterator scoreboard_vector_end= scoreboard_vector->end();
139
120
 
140
121
  ScoreboardSlot *scoreboard_slot= NULL;
141
 
  for (std::vector<ScoreboardSlot *>::iterator it= scoreboard_vector->begin();
 
122
  for (vector<ScoreboardSlot *>::iterator it= scoreboard_vector->begin();
142
123
       it != scoreboard_vector->end(); ++it)
143
124
  {
144
125
    scoreboard_slot= *it;
187
168
  add_field("VARIABLE_VALUE", 1024);
188
169
}
189
170
 
190
 
GlobalStatementsTool::Generator::Generator(Field **arg, LoggingStats *in_logging_stats) :
 
171
GlobalStatementsTool::Generator::Generator(Field **arg, LoggingStats *logging_stats) :
191
172
  plugin::TableFunction::Generator(arg)
192
173
{
193
174
  count= 0;
194
175
  /* add the current scoreboard and the saved global statements */
195
176
  global_stats_to_display= new GlobalStats();
196
 
  CumulativeStats *cumulativeStats= in_logging_stats->getCumulativeStats();
197
 
  cumulativeStats->sumCurrentScoreboard(in_logging_stats->getCurrentScoreboard(), 
 
177
  CumulativeStats *cumulativeStats= logging_stats->getCumulativeStats();
 
178
  cumulativeStats->sumCurrentScoreboard(logging_stats->getCurrentScoreboard(), 
198
179
                                        NULL, global_stats_to_display->getUserCommands());
199
 
  global_stats_to_display->merge(in_logging_stats->getCumulativeStats()->getGlobalStats()); 
 
180
  global_stats_to_display->merge(logging_stats->getCumulativeStats()->getGlobalStats()); 
200
181
}
201
182
 
202
183
GlobalStatementsTool::Generator::~Generator()
226
207
{
227
208
  outer_logging_stats= logging_stats;
228
209
 
229
 
  add_field("USERNAME");
 
210
  add_field("USER");
230
211
  add_field("IP");
231
212
 
232
213
  uint32_t number_commands= UserCommands::getUserCounts();
260
241
 
261
242
void CurrentCommandsTool::Generator::setVectorIteratorsAndLock(uint32_t bucket_number)
262
243
{
263
 
  std::vector<ScoreboardSlot* > *scoreboard_vector= 
 
244
  vector<ScoreboardSlot* > *scoreboard_vector= 
264
245
    current_scoreboard->getVectorOfScoreboardVectors()->at(bucket_number); 
265
246
 
266
247
  current_lock= current_scoreboard->getVectorOfScoreboardLocks()->at(bucket_number);
267
248
 
268
249
  scoreboard_vector_it= scoreboard_vector->begin();
269
250
  scoreboard_vector_end= scoreboard_vector->end();
270
 
  current_lock->lock_shared();
 
251
  pthread_rwlock_rdlock(current_lock);
271
252
}
272
253
 
273
254
bool CurrentCommandsTool::Generator::populate()
302
283
    }
303
284
    
304
285
    ++vector_of_scoreboard_vectors_it;
305
 
    current_lock->unlock_shared();
 
286
    pthread_rwlock_unlock(current_lock); 
306
287
    ++current_bucket;
307
288
    if (vector_of_scoreboard_vectors_it != vector_of_scoreboard_vectors_end)
308
289
    {
318
299
{
319
300
  outer_logging_stats= logging_stats;
320
301
 
321
 
  add_field("USERNAME");
 
302
  add_field("USER");
322
303
 
323
304
  uint32_t number_commands= UserCommands::getUserCounts();
324
305
 
378
359
 
379
360
  return false;
380
361
}
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("USERNAME");
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
 
}