~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/logging_query/logging_query.cc

  • Committer: Monty Taylor
  • Date: 2011-02-13 17:26:39 UTC
  • mfrom: (2157.2.2 give-in-to-pkg-config)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110213172639-nhy7i72sfhoq13ms
Merged in pkg-config fixes.

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