~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/logging_stats/logging_stats.cc

  • Committer: LinuxJedi
  • Date: 2010-08-28 09:23:52 UTC
  • mto: (1738.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1739.
  • Revision ID: linuxjedi@linuxjedi-laptop-20100828092352-oe3zbtdy05kq9dtq
Make exit happen in main thread rather than signal handler thread thus avoiding a segfault due to a double kill of the signal handler thread

Show diffs side-by-side

added added

removed removed

Lines of Context:
102
102
 
103
103
static bool sysvar_logging_stats_enabled= true;
104
104
 
105
 
typedef constrained_check<uint32_t, 50000, 10> scoreboard_size_constraint;
106
 
static scoreboard_size_constraint sysvar_logging_stats_scoreboard_size;
107
 
 
108
 
typedef constrained_check<uint32_t, 50000, 100> max_user_count_constraint;
109
 
static max_user_count_constraint sysvar_logging_stats_max_user_count;
110
 
 
111
 
typedef constrained_check<uint32_t, 500, 5> bucket_count_constraint;
112
 
static bucket_count_constraint sysvar_logging_stats_bucket_count;
 
105
static uint32_t sysvar_logging_stats_scoreboard_size= 2000;
 
106
 
 
107
static uint32_t sysvar_logging_stats_max_user_count= 500;
 
108
 
 
109
static uint32_t sysvar_logging_stats_bucket_count= 10;
113
110
 
114
111
LoggingStats::LoggingStats(string name_arg) : Logging(name_arg)
115
112
{
140
137
  scoreboard_slot->getStatusVars()->logStatusVar(session);
141
138
}
142
139
 
143
 
bool LoggingStats::resetGlobalScoreboard()
144
 
{
145
 
  cumulative_stats->getGlobalStatusVars()->reset();
146
 
  cumulative_stats->getGlobalStats()->getUserCommands()->reset();
147
 
 
148
 
  ScoreBoardVectors *vector_of_scoreboard_vectors=
149
 
    current_scoreboard->getVectorOfScoreboardVectors();
150
 
 
151
 
  ScoreBoardVectors::iterator v_of_scoreboard_v_begin_it= vector_of_scoreboard_vectors->begin();
152
 
 
153
 
  ScoreBoardVectors::iterator v_of_scoreboard_v_end_it= vector_of_scoreboard_vectors->end();
154
 
 
155
 
  for (; v_of_scoreboard_v_begin_it != v_of_scoreboard_v_end_it; ++v_of_scoreboard_v_begin_it)
156
 
  {
157
 
    std::vector<ScoreboardSlot* > *scoreboard_vector= *v_of_scoreboard_v_begin_it;
158
 
 
159
 
    std::vector<ScoreboardSlot* >::iterator scoreboard_vector_it= scoreboard_vector->begin();
160
 
    std::vector<ScoreboardSlot* >::iterator scoreboard_vector_end= scoreboard_vector->end();
161
 
    for (; scoreboard_vector_it != scoreboard_vector_end; ++scoreboard_vector_it)
162
 
    {
163
 
      ScoreboardSlot *scoreboard_slot= *scoreboard_vector_it;
164
 
      scoreboard_slot->getStatusVars()->reset();
165
 
      scoreboard_slot->getUserCommands()->reset();
166
 
    }
167
 
  }
168
 
 
169
 
  return false;
170
 
}
171
 
 
172
140
bool LoggingStats::post(Session *session)
173
141
{
174
142
  if (! isEnabled() || (session->getSessionId() == 0))
253
221
 
254
222
static ScoreboardStatsTool *scoreboard_stats_tool= NULL;
255
223
 
256
 
static void enable(Session *, sql_var_t)
 
224
static void enable(Session *,
 
225
                   drizzle_sys_var *,
 
226
                   void *var_ptr,
 
227
                   const void *save)
257
228
{
258
229
  if (logging_stats)
259
230
  {
260
 
    if (sysvar_logging_stats_enabled)
 
231
    if (*(bool *)save != false)
261
232
    {
262
233
      logging_stats->enable();
 
234
      *(bool *) var_ptr= (bool) true;
263
235
    }
264
236
    else
265
237
    {
266
238
      logging_stats->disable();
 
239
      *(bool *) var_ptr= (bool) false;
267
240
    }
268
241
  }
269
242
}
332
305
static int init(drizzled::module::Context &context)
333
306
{
334
307
  const module::option_map &vm= context.getOptions();
 
308
  if (vm.count("max-user-count"))
 
309
  {
 
310
    if (sysvar_logging_stats_max_user_count < 100 || sysvar_logging_stats_max_user_count > 50000)
 
311
    {
 
312
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for max-user-count\n"));
 
313
      exit(-1);
 
314
    }
 
315
  }
 
316
  if (vm.count("bucket-count"))
 
317
  {
 
318
    if (sysvar_logging_stats_bucket_count < 5 || sysvar_logging_stats_bucket_count > 500)
 
319
    {
 
320
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for bucket-count\n"));
 
321
      exit(-1);
 
322
    }
 
323
  }
335
324
 
336
 
  sysvar_logging_stats_enabled= (vm.count("disable")) ? false : true;
 
325
  if (vm.count("scoreboard-size"))
 
326
  {
 
327
    if (sysvar_logging_stats_scoreboard_size < 10 || sysvar_logging_stats_scoreboard_size > 50000)
 
328
    {
 
329
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for scoreboard-size\n"));
 
330
      exit(-1);
 
331
    }
 
332
    else
 
333
      sysvar_logging_stats_scoreboard_size= vm["scoreboard-size"].as<uint32_t>(); 
 
334
  }
337
335
 
338
336
  logging_stats= new LoggingStats("logging_stats");
339
337
 
357
355
    logging_stats->enable();
358
356
  }
359
357
 
360
 
  context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("max_user_count", sysvar_logging_stats_max_user_count));
361
 
  context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("bucket_count", sysvar_logging_stats_bucket_count));
362
 
  context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("scoreboard_size", sysvar_logging_stats_scoreboard_size));
363
 
  context.registerVariable(new sys_var_bool_ptr("enable", &sysvar_logging_stats_enabled, enable));
364
 
 
365
358
  return 0;
366
359
}
367
360
 
 
361
static DRIZZLE_SYSVAR_UINT(max_user_count,
 
362
                           sysvar_logging_stats_max_user_count,
 
363
                           PLUGIN_VAR_RQCMDARG,
 
364
                           N_("Max number of users that will be logged"),
 
365
                           NULL, /* check func */
 
366
                           NULL, /* update func */
 
367
                           500, /* default */
 
368
                           100, /* minimum */
 
369
                           50000,
 
370
                           0);
 
371
 
 
372
static DRIZZLE_SYSVAR_UINT(bucket_count,
 
373
                           sysvar_logging_stats_bucket_count,
 
374
                           PLUGIN_VAR_RQCMDARG,
 
375
                           N_("Max number of range locks to use for Scoreboard"),
 
376
                           NULL, /* check func */
 
377
                           NULL, /* update func */
 
378
                           10, /* default */
 
379
                           5, /* minimum */
 
380
                           500,
 
381
                           0);
 
382
 
 
383
static DRIZZLE_SYSVAR_UINT(scoreboard_size,
 
384
                           sysvar_logging_stats_scoreboard_size,
 
385
                           PLUGIN_VAR_RQCMDARG,
 
386
                           N_("Max number of concurrent sessions that will be logged"),
 
387
                           NULL, /* check func */
 
388
                           NULL, /* update func */
 
389
                           2000, /* default */
 
390
                           10, /* minimum */
 
391
                           50000, 
 
392
                           0);
 
393
 
 
394
static DRIZZLE_SYSVAR_BOOL(enable,
 
395
                           sysvar_logging_stats_enabled,
 
396
                           PLUGIN_VAR_NOCMDARG,
 
397
                           N_("Enable Logging Statistics Collection"),
 
398
                           NULL, /* check func */
 
399
                           enable, /* update func */
 
400
                           true /* default */);
368
401
 
369
402
static void init_options(drizzled::module::option_context &context)
370
403
{
371
404
  context("max-user-count",
372
 
          po::value<max_user_count_constraint>(&sysvar_logging_stats_max_user_count)->default_value(500),
 
405
          po::value<uint32_t>(&sysvar_logging_stats_max_user_count)->default_value(500),
373
406
          N_("Max number of users that will be logged"));
374
407
  context("bucket-count",
375
 
          po::value<bucket_count_constraint>(&sysvar_logging_stats_bucket_count)->default_value(10),
 
408
          po::value<uint32_t>(&sysvar_logging_stats_bucket_count)->default_value(10),
376
409
          N_("Max number of range locks to use for Scoreboard"));
377
410
  context("scoreboard-size",
378
 
          po::value<scoreboard_size_constraint>(&sysvar_logging_stats_scoreboard_size)->default_value(2000),
 
411
          po::value<uint32_t>(&sysvar_logging_stats_scoreboard_size)->default_value(2000),
379
412
          N_("Max number of concurrent sessions that will be logged"));
380
 
  context("disable", N_("Enable Logging Statistics Collection"));
 
413
  context("enable",
 
414
          po::value<bool>(&sysvar_logging_stats_enabled)->default_value(true)->zero_tokens(),
 
415
          N_("Enable Logging Statistics Collection"));
381
416
}
382
417
 
 
418
static drizzle_sys_var* system_var[]= {
 
419
  DRIZZLE_SYSVAR(max_user_count),
 
420
  DRIZZLE_SYSVAR(bucket_count),
 
421
  DRIZZLE_SYSVAR(scoreboard_size),
 
422
  DRIZZLE_SYSVAR(enable),
 
423
  NULL
 
424
};
 
425
 
383
426
DRIZZLE_DECLARE_PLUGIN
384
427
{
385
428
  DRIZZLE_VERSION_ID,
389
432
  N_("User Statistics as DATA_DICTIONARY tables"),
390
433
  PLUGIN_LICENSE_BSD,
391
434
  init,   /* Plugin Init      */
392
 
  NULL, /* system variables */
 
435
  system_var, /* system variables */
393
436
  init_options    /* config options   */
394
437
}
395
438
DRIZZLE_DECLARE_PLUGIN_END;