~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/logging_query/logging_query.cc

  • Committer: Mark Atwood
  • Date: 2011-08-11 03:05:03 UTC
  • mfrom: (2385.1.12 refactor4)
  • Revision ID: me@mark.atwood.name-20110811030503-rp9xjihc5x3y0x4q
merge lp:~olafvdspek/drizzle/refactor4

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
 
20
#include <config.h>
 
21
#include <drizzled/plugin.h>
21
22
#include <drizzled/plugin/logging.h>
22
23
#include <drizzled/gettext.h>
23
24
#include <drizzled/session.h>
 
25
#include <drizzled/session/times.h>
 
26
#include <drizzled/sql_parse.h>
24
27
#include PCRE_HEADER
25
28
#include <limits.h>
26
29
#include <sys/time.h>
71
74
  static const char hexit[]= { '0', '1', '2', '3', '4', '5', '6', '7',
72
75
                          '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
73
76
  string::const_iterator src_iter;
74
 
  
 
77
 
75
78
  for (src_iter= src.begin(); src_iter < src.end(); ++src_iter)
76
79
  {
77
80
    if (static_cast<unsigned char>(*src_iter) > 0x7f)
236
239
      inside itself, so be more accurate, and so this doesnt have to
237
240
      keep calling current_utime, which can be slow.
238
241
    */
239
 
    uint64_t t_mark= session->getCurrentTimestamp(false);
 
242
    uint64_t t_mark= session->times.getCurrentTimestamp(false);
240
243
 
241
 
    if (session->getElapsedTime() < (sysvar_logging_query_threshold_slow.get()))
 
244
    if (session->times.getElapsedTime() < sysvar_logging_query_threshold_slow.get())
242
245
      return false;
243
246
 
244
247
    Session::QueryString query_string(session->getQueryString());
 
248
    if (query_string == NULL)
 
249
    {
 
250
      return false;
 
251
    }
 
252
 
245
253
    if (re)
246
254
    {
247
255
      int this_pcre_rc;
252
260
 
253
261
    // buffer to quotify the query
254
262
    string qs;
255
 
    
 
263
 
256
264
    // Since quotify() builds the quoted string incrementally, we can
257
265
    // avoid some reallocating if we reserve some space up front.
258
266
    qs.reserve(query_string->length());
259
 
    
 
267
 
260
268
    quotify(*query_string, qs);
261
 
    
 
269
 
262
270
    // to avoid trying to printf %s something that is potentially NULL
263
 
    util::string::const_shared_ptr schema(session->schema());
264
 
    const char *dbs= (schema and not schema->empty()) ? schema->c_str() : "";
265
 
 
 
271
    util::string::ptr schema(session->schema());
266
272
    formatter % t_mark
267
273
              % session->thread_id
268
274
              % session->getQueryId()
269
 
              % dbs
 
275
              % (schema ? schema->c_str() : "")
270
276
              % qs
271
277
              % getCommandName(session->command)
272
 
              % (t_mark - session->getConnectMicroseconds())
273
 
              % session->getElapsedTime()
274
 
              % (t_mark - session->utime_after_lock)
 
278
              % (t_mark - session->times.getConnectMicroseconds())
 
279
              % session->times.getElapsedTime()
 
280
              % (t_mark - session->times.utime_after_lock)
275
281
              % session->sent_row_count
276
282
              % session->examined_row_count
277
283
              % session->tmp_table
278
284
              % session->total_warn_count
279
285
              % session->getServerId()
280
 
              % glob_hostname;
 
286
              % getServerHostname();
281
287
 
282
288
    string msgbuf= formatter.str();
283
289
 
291
297
 
292
298
static int logging_query_plugin_init(drizzled::module::Context &context)
293
299
{
294
 
 
295
300
  const module::option_map &vm= context.getOptions();
296
301
 
297
 
  if (vm.count("filename") > 0)
 
302
  if (vm.count("filename"))
298
303
  {
299
304
    context.add(new Logging_query(vm["filename"].as<string>(),
300
305
                                  vm["pcre"].as<string>()));