drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
query_usage.h
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#pragma once
22
23#include <drizzled/session.h>
24#include <drizzled/util/storable.h>
25
26namespace performance_dictionary {
27
28#define USAGE_MAX_KEPT 5
29
30struct 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
83typedef std::list <query_usage> Query_list;
84
85class QueryUsage : public drizzled::util::Storable
86{
87public:
88 Query_list query_list;
89
90 QueryUsage()
91 {
92 query_list.resize(USAGE_MAX_KEPT);
93 }
94
95 void push(drizzled::Session::QueryString query_string, const struct rusage &arg);
96
97 Query_list &list(void)
98 {
99 return query_list;
100 }
101};
102
103
104} /* namespace performance_dictionary */
105
std::shared_ptr< const std::string > QueryString
Definition session.h:133