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
23
#include "plugin/performance_dictionary/dictionary.h"
25
#include <drizzled/atomics.h>
26
#include <drizzled/session.h>
28
#include <sys/resource.h>
30
using namespace drizzled;
33
#define FUNCTION_NAME_LEN 64
35
performance_dictionary::SessionUsage::SessionUsage() :
36
plugin::TableFunction("DATA_DICTIONARY", "SESSION_USAGE")
38
add_field("QUERY", plugin::TableFunction::STRING, FUNCTION_NAME_LEN, false);
39
add_field("USER_TIME_USED_SECONDS", plugin::TableFunction::NUMBER, false);
40
add_field("USER_TIME_USED_MICRO_SECONDS", plugin::TableFunction::NUMBER, false);
41
add_field("SYSTEM_TIME_USED_SECONDS", plugin::TableFunction::NUMBER, false);
42
add_field("SYSTEM_TIME_USED_MICRO_SECONDS", plugin::TableFunction::NUMBER, false);
43
add_field("INTEGRAL_MAX_RESIDENT_SET_SIZE", plugin::TableFunction::NUMBER, 0, false);
44
add_field("INTEGRAL_SHARED_TEXT_MEMORY_SIZE", plugin::TableFunction::NUMBER, 0, false);
45
add_field("INTEGRAL_UNSHARED_DATA_SIZE", plugin::TableFunction::NUMBER, 0, false);
46
add_field("INTEGRAL_UNSHARED_STACK_SIZE", plugin::TableFunction::NUMBER, 0, false);
47
add_field("PAGE_RECLAIMS", plugin::TableFunction::NUMBER, 0, false);
48
add_field("PAGE_FAULTS", plugin::TableFunction::NUMBER, 0, false);
49
add_field("SWAPS", plugin::TableFunction::NUMBER, 0, false);
50
add_field("BLOCK_INPUT_OPERATIONS", plugin::TableFunction::NUMBER, 0, false);
51
add_field("BLOCK_OUTPUT_OPERATIONS", plugin::TableFunction::NUMBER, 0, false);
52
add_field("MESSAGES_SENT", plugin::TableFunction::NUMBER, 0, false);
53
add_field("MESSAGES_RECEIVED", plugin::TableFunction::NUMBER, 0, false);
54
add_field("SIGNALS_RECEIVED", plugin::TableFunction::NUMBER, 0, false);
55
add_field("VOLUNTARY_CONTEXT_SWITCHES", plugin::TableFunction::NUMBER, 0, false);
56
add_field("INVOLUNTARY_CONTEXT_SWITCHES", plugin::TableFunction::NUMBER, 0, false);
60
performance_dictionary::SessionUsage::Generator::Generator(drizzled::Field **arg) :
61
drizzled::plugin::TableFunction::Generator(arg),
64
usage_cache= dynamic_cast<QueryUsage *>(getSession().getProperty("query_usage"));
66
query_iter= usage_cache->list().rbegin();
69
bool performance_dictionary::SessionUsage::Generator::populate()
74
if (query_iter == usage_cache->list().rend())
77
publish((*query_iter).query, (*query_iter).delta());
83
void performance_dictionary::SessionUsage::Generator::publish(const std::string &sql, const struct rusage &usage_arg)
88
/* USER_TIME_USED_SECONDS */
89
push(static_cast<int64_t>(usage_arg.ru_utime.tv_sec));
91
/* USER_TIME_USED_MICRO_SECONDS */
92
push(static_cast<int64_t>(usage_arg.ru_utime.tv_usec));
94
/* SYSTEM_TIME_USED_SECONDS */
95
push(static_cast<int64_t>(usage_arg.ru_stime.tv_sec));
97
/* SYSTEM_TIME_USED_MICRO_SECONDS */
98
push(static_cast<int64_t>(usage_arg.ru_stime.tv_usec));
100
/* INTEGRAL_MAX_RESIDENT_SET_SIZE */
101
push(static_cast<int64_t>(usage_arg.ru_maxrss));
103
/* INTEGRAL_SHARED_TEXT_MEMORY_SIZE */
104
push(static_cast<int64_t>(usage_arg.ru_ixrss));
106
/* INTEGRAL_UNSHARED_DATA_SIZE */
107
push(static_cast<int64_t>(usage_arg.ru_idrss));
109
/* INTEGRAL_UNSHARED_STACK_SIZE */
110
push(static_cast<int64_t>(usage_arg.ru_isrss));
113
push(static_cast<int64_t>(usage_arg.ru_minflt));
116
push(static_cast<int64_t>(usage_arg.ru_majflt));
119
push(static_cast<int64_t>(usage_arg.ru_nswap));
121
/* BLOCK_INPUT_OPERATIONS */
122
push(static_cast<int64_t>(usage_arg.ru_inblock));
124
/* BLOCK_OUTPUT_OPERATIONS */
125
push(static_cast<int64_t>(usage_arg.ru_oublock));
128
push(static_cast<int64_t>(usage_arg.ru_msgsnd));
130
/* MESSAGES_RECEIVED */
131
push(static_cast<int64_t>(usage_arg.ru_msgrcv));
133
/* SIGNALS_RECEIVED */
134
push(static_cast<int64_t>(usage_arg.ru_nsignals));
136
/* VOLUNTARY_CONTEXT_SWITCHES */
137
push(static_cast<int64_t>(usage_arg.ru_nvcsw));
139
/* INVOLUNTARY_CONTEXT_SWITCHES */
140
push(static_cast<int64_t>(usage_arg.ru_nivcsw));