~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/logging_query/logging_query.cc

  • Committer: Brian Aker
  • Date: 2011-02-14 05:47:07 UTC
  • mto: This revision was merged to the branch mainline in revision 2167.
  • Revision ID: brian@tangent.org-20110214054707-61nsqgg1g4w1zhx1
Merge in all changes for current_session, etc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008,2009 Sun Microsystems
 
4
 *  Copyright (C) 2008, 2009 Sun Microsystems, Inc.
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
171
171
    fd= open(_filename.c_str(),
172
172
             O_WRONLY | O_APPEND | O_CREAT,
173
173
             S_IRUSR|S_IWUSR);
 
174
 
174
175
    if (fd < 0)
175
176
    {
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);
 
177
      sql_perror( _("fail open()"), _filename);
181
178
      return;
182
179
    }
183
180
 
234
231
    if (session->examined_row_count < sysvar_logging_query_threshold_big_examined.get())
235
232
      return false;
236
233
 
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();
 
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);
244
240
 
245
 
    if ((t_mark - session->start_utime) < (sysvar_logging_query_threshold_slow.get()))
 
241
    if (session->getElapsedTime() < (sysvar_logging_query_threshold_slow.get()))
246
242
      return false;
247
243
 
248
244
    Session::QueryString query_string(session->getQueryString());
272
268
              % session->getQueryId()
273
269
              % dbs
274
270
              % qs
275
 
              % command_name[session->command].str
 
271
              % getCommandName(session->command)
276
272
              % (t_mark - session->getConnectMicroseconds())
277
 
              % (t_mark - session->start_utime)
 
273
              % session->getElapsedTime()
278
274
              % (t_mark - session->utime_after_lock)
279
275
              % session->sent_row_count
280
276
              % session->examined_row_count
317
313
{
318
314
  context("enable",
319
315
          po::value<bool>(&sysvar_logging_query_enable)->default_value(false)->zero_tokens(),
320
 
          N_("Enable logging to CSV file"));
 
316
          _("Enable logging to CSV file"));
321
317
  context("filename",
322
318
          po::value<string>(),
323
 
          N_("File to log to"));
 
319
          _("File to log to"));
324
320
  context("pcre",
325
321
          po::value<string>()->default_value(""),
326
 
          N_("PCRE to match the query against"));
 
322
          _("PCRE to match the query against"));
327
323
  context("threshold-slow",
328
324
          po::value<uint32_constraint>(&sysvar_logging_query_threshold_slow)->default_value(0),
329
 
          N_("Threshold for logging slow queries, in microseconds"));
 
325
          _("Threshold for logging slow queries, in microseconds"));
330
326
  context("threshold-big-resultset",
331
327
          po::value<uint32_constraint>(&sysvar_logging_query_threshold_big_resultset)->default_value(0),
332
 
          N_("Threshold for logging big queries, for rows returned"));
 
328
          _("Threshold for logging big queries, for rows returned"));
333
329
  context("threshold-big-examined",
334
330
          po::value<uint32_constraint>(&sysvar_logging_query_threshold_big_examined)->default_value(0),
335
 
          N_("Threshold for logging big queries, for rows examined"));
 
331
          _("Threshold for logging big queries, for rows examined"));
336
332
}
337
333
 
338
334
} /* namespace drizzle_plugin */