~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/logging_query/logging_query.cc

  • Committer: Monty Taylor
  • Date: 2010-12-26 03:15:44 UTC
  • mto: This revision was merged to the branch mainline in revision 2038.
  • Revision ID: mordred@inaugust.com-20101226031544-1cf3raipu53fnmyj
Through page.

Show diffs side-by-side

added added

removed removed

Lines of Context:
171
171
    fd= open(_filename.c_str(),
172
172
             O_WRONLY | O_APPEND | O_CREAT,
173
173
             S_IRUSR|S_IWUSR);
174
 
 
175
174
    if (fd < 0)
176
175
    {
177
 
      sql_perror( _("fail open()"), _filename);
 
176
      char errmsg[STRERROR_MAX];
 
177
      strerror_r(errno, errmsg, sizeof(errmsg));
 
178
      errmsg_printf(ERRMSG_LVL_ERROR, _("fail open() fn=%s er=%s\n"),
 
179
                    _filename.c_str(),
 
180
                    errmsg);
178
181
      return;
179
182
    }
180
183
 
231
234
    if (session->examined_row_count < sysvar_logging_query_threshold_big_examined.get())
232
235
      return false;
233
236
 
234
 
    /*
235
 
      TODO, the session object should have a "utime command completed"
236
 
      inside itself, so be more accurate, and so this doesnt have to
237
 
      keep calling current_utime, which can be slow.
238
 
    */
239
 
    uint64_t t_mark= session->getCurrentTimestamp(false);
 
237
    /* TODO, the session object should have a "utime command completed"
 
238
       inside itself, so be more accurate, and so this doesnt have to
 
239
       keep calling current_utime, which can be slow */
 
240
  
 
241
    boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time());
 
242
    boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
 
243
    uint64_t t_mark= (mytime-epoch).total_microseconds();
240
244
 
241
 
    if (session->getElapsedTime() < (sysvar_logging_query_threshold_slow.get()))
 
245
    if ((t_mark - session->start_utime) < (sysvar_logging_query_threshold_slow.get()))
242
246
      return false;
243
247
 
244
248
    Session::QueryString query_string(session->getQueryString());
268
272
              % session->getQueryId()
269
273
              % dbs
270
274
              % qs
271
 
              % getCommandName(session->command)
 
275
              % command_name[session->command].str
272
276
              % (t_mark - session->getConnectMicroseconds())
273
 
              % session->getElapsedTime()
 
277
              % (t_mark - session->start_utime)
274
278
              % (t_mark - session->utime_after_lock)
275
279
              % session->sent_row_count
276
280
              % session->examined_row_count
313
317
{
314
318
  context("enable",
315
319
          po::value<bool>(&sysvar_logging_query_enable)->default_value(false)->zero_tokens(),
316
 
          _("Enable logging to CSV file"));
 
320
          N_("Enable logging to CSV file"));
317
321
  context("filename",
318
322
          po::value<string>(),
319
 
          _("File to log to"));
 
323
          N_("File to log to"));
320
324
  context("pcre",
321
325
          po::value<string>()->default_value(""),
322
 
          _("PCRE to match the query against"));
 
326
          N_("PCRE to match the query against"));
323
327
  context("threshold-slow",
324
328
          po::value<uint32_constraint>(&sysvar_logging_query_threshold_slow)->default_value(0),
325
 
          _("Threshold for logging slow queries, in microseconds"));
 
329
          N_("Threshold for logging slow queries, in microseconds"));
326
330
  context("threshold-big-resultset",
327
331
          po::value<uint32_constraint>(&sysvar_logging_query_threshold_big_resultset)->default_value(0),
328
 
          _("Threshold for logging big queries, for rows returned"));
 
332
          N_("Threshold for logging big queries, for rows returned"));
329
333
  context("threshold-big-examined",
330
334
          po::value<uint32_constraint>(&sysvar_logging_query_threshold_big_examined)->default_value(0),
331
 
          _("Threshold for logging big queries, for rows examined"));
 
335
          N_("Threshold for logging big queries, for rows examined"));
332
336
}
333
337
 
334
338
} /* namespace drizzle_plugin */