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
24
#include "drizzled/internal/getrusage.h"
26
#include "drizzled/session.h"
28
namespace performance_dictionary {
30
#define USAGE_MAX_KEPT 5
39
memset(&start, 0, sizeof(struct rusage));
40
memset(&buffer, 0, sizeof(struct rusage));
43
void set(const std::string &sql, const struct rusage &arg)
45
if (getrusage(RUSAGE_THREAD, &buffer))
47
memset(&start, 0, sizeof(struct rusage));
48
memset(&buffer, 0, sizeof(struct rusage));
51
query= sql.substr(0, 512);
54
buffer.ru_utime.tv_sec -= start.ru_utime.tv_sec;
55
buffer.ru_utime.tv_usec -= start.ru_utime.tv_usec;
57
buffer.ru_stime.tv_sec -= start.ru_stime.tv_sec;
58
buffer.ru_stime.tv_usec -= start.ru_stime.tv_usec;
60
buffer.ru_maxrss -= start.ru_maxrss;
61
buffer.ru_ixrss -= start.ru_ixrss;
62
buffer.ru_idrss -= start.ru_idrss;
63
buffer.ru_isrss -= start.ru_isrss;
64
buffer.ru_minflt -= start.ru_minflt;
65
buffer.ru_majflt -= start.ru_majflt;
66
buffer.ru_nswap -= start.ru_nswap;
67
buffer.ru_inblock -= start.ru_inblock;
68
buffer.ru_oublock -= start.ru_oublock;
69
buffer.ru_msgsnd -= start.ru_msgsnd;
70
buffer.ru_msgrcv -= start.ru_msgrcv;
71
buffer.ru_nsignals -= start.ru_nsignals;
72
buffer.ru_nvcsw -= start.ru_nvcsw;
73
buffer.ru_nivcsw -= start.ru_nivcsw;
76
const struct rusage &delta(void) const
85
typedef std::list <query_usage> Query_list;
87
class QueryUsage : public drizzled::util::Storable {
89
Query_list query_list;
93
query_list.resize(USAGE_MAX_KEPT);
96
void push(const std::string &sql, const struct rusage &arg)
98
Query_list::iterator it= query_list.end();
100
query_list.splice(query_list.begin(), query_list, it);
101
query_list.front().set(sql, arg);
104
Query_list &list(void)
111
} /* namespace performance_dictionary */
113
#endif /* PLUGIN_PERFORMANCE_DICTIONARY_QUERY_USAGE_H */