~drizzle-trunk/drizzle/development

1764.3.6 by Brian Aker
This includes a query_usage table for looking at performance of previous
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2010 Brian Aker
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  (at your option) any later version.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU General Public License
17
 *  along with this program; if not, write to the Free Software
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 */
20
21
#ifndef PLUGIN_PERFORMANCE_DICTIONARY_QUERY_USAGE_H
22
#define PLUGIN_PERFORMANCE_DICTIONARY_QUERY_USAGE_H
23
24
#include "drizzled/session.h"
25
26
namespace performance_dictionary {
27
28
#define USAGE_MAX_KEPT 5
29
30
struct query_usage {
31
  std::string query;
32
  struct rusage start;
33
  struct rusage buffer;
34
35
  query_usage()
36
  {
37
    memset(&start, 0, sizeof(struct rusage));
38
    memset(&buffer, 0, sizeof(struct rusage));
39
  }
40
41
  void set(const std::string &sql, const struct rusage &arg)
42
  {
43
    if (getrusage(RUSAGE_THREAD, &buffer))
44
    {
45
      memset(&start, 0, sizeof(struct rusage));
46
      memset(&buffer, 0, sizeof(struct rusage));
47
      return;
48
    }
49
    query= sql.substr(0, 512);
50
    start= arg;
51
52
    buffer.ru_utime.tv_sec -= start.ru_utime.tv_sec;
53
    buffer.ru_utime.tv_usec -= start.ru_utime.tv_usec;
54
55
    buffer.ru_stime.tv_sec -= start.ru_stime.tv_sec;
56
    buffer.ru_stime.tv_usec -= start.ru_stime.tv_usec;
57
58
    buffer.ru_maxrss -= start.ru_maxrss;
59
    buffer.ru_ixrss -= start.ru_ixrss;
60
    buffer.ru_idrss -= start.ru_idrss;
61
    buffer.ru_isrss -= start.ru_isrss;
62
    buffer.ru_minflt -= start.ru_minflt;
63
    buffer.ru_majflt -= start.ru_majflt;
64
    buffer.ru_nswap -= start.ru_nswap;
65
    buffer.ru_inblock -= start.ru_inblock;
66
    buffer.ru_oublock -= start.ru_oublock;
67
    buffer.ru_msgsnd -= start.ru_msgsnd;
68
    buffer.ru_msgrcv -= start.ru_msgrcv;
69
    buffer.ru_nsignals -= start.ru_nsignals;
70
    buffer.ru_nvcsw -= start.ru_nvcsw;
71
    buffer.ru_nivcsw -= start.ru_nivcsw;
72
  }
73
74
  const struct rusage &delta(void) const
75
  {
76
    return buffer;
77
  }
78
79
  ~query_usage()
80
  { }
81
};
82
83
typedef std::list <query_usage> Query_list;
84
85
class QueryUsage : public drizzled::util::Storable {
86
public:
87
  Query_list query_list;
88
89
  QueryUsage()
90
  {
91
    query_list.resize(USAGE_MAX_KEPT);
92
  }
93
1932.3.2 by Brian Aker
1) Make sure the query string always has an std::string in it.
94
  void push(drizzled::Session::QueryString query_string, const struct rusage &arg);
1764.3.6 by Brian Aker
This includes a query_usage table for looking at performance of previous
95
96
  Query_list &list(void)
97
  {
98
    return query_list;
99
  }
100
};
101
102
103
} /* namespace performance_dictionary */
104
105
#endif /* PLUGIN_PERFORMANCE_DICTIONARY_QUERY_USAGE_H */