1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Brian Aker
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.
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.
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
21
#ifndef PLUGIN_PERFORMANCE_DICTIONARY_QUERY_USAGE_H
22
#define PLUGIN_PERFORMANCE_DICTIONARY_QUERY_USAGE_H
25
#include <sys/resource.h>
27
#include "drizzled/session.h"
29
namespace performance_dictionary {
31
#define USAGE_MAX_KEPT 5
40
memset(&start, 0, sizeof(struct rusage));
41
memset(&buffer, 0, sizeof(struct rusage));
44
void set(const std::string &sql, const struct rusage &arg)
46
if (getrusage(RUSAGE_THREAD, &buffer))
48
memset(&start, 0, sizeof(struct rusage));
49
memset(&buffer, 0, sizeof(struct rusage));
52
query= sql.substr(0, 512);
55
buffer.ru_utime.tv_sec -= start.ru_utime.tv_sec;
56
buffer.ru_utime.tv_usec -= start.ru_utime.tv_usec;
58
buffer.ru_stime.tv_sec -= start.ru_stime.tv_sec;
59
buffer.ru_stime.tv_usec -= start.ru_stime.tv_usec;
61
buffer.ru_maxrss -= start.ru_maxrss;
62
buffer.ru_ixrss -= start.ru_ixrss;
63
buffer.ru_idrss -= start.ru_idrss;
64
buffer.ru_isrss -= start.ru_isrss;
65
buffer.ru_minflt -= start.ru_minflt;
66
buffer.ru_majflt -= start.ru_majflt;
67
buffer.ru_nswap -= start.ru_nswap;
68
buffer.ru_inblock -= start.ru_inblock;
69
buffer.ru_oublock -= start.ru_oublock;
70
buffer.ru_msgsnd -= start.ru_msgsnd;
71
buffer.ru_msgrcv -= start.ru_msgrcv;
72
buffer.ru_nsignals -= start.ru_nsignals;
73
buffer.ru_nvcsw -= start.ru_nvcsw;
74
buffer.ru_nivcsw -= start.ru_nivcsw;
77
const struct rusage &delta(void) const
86
typedef std::list <query_usage> Query_list;
88
class QueryUsage : public drizzled::util::Storable {
90
Query_list query_list;
94
query_list.resize(USAGE_MAX_KEPT);
97
void push(const std::string &sql, const struct rusage &arg)
99
Query_list::iterator it= query_list.end();
101
query_list.splice(query_list.begin(), query_list, it);
102
query_list.front().set(sql, arg);
105
Query_list &list(void)
112
} /* namespace performance_dictionary */
114
#endif /* PLUGIN_PERFORMANCE_DICTIONARY_QUERY_USAGE_H */