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>
31
#define USAGE_VISABILITY RUSAGE_THREAD
33
#define USAGE_VISABILITY RUSAGE_SELF
36
using namespace drizzled;
39
#define FUNCTION_NAME_LEN 64
41
performance_dictionary::SessionUsage::SessionUsage() :
42
plugin::TableFunction("DATA_DICTIONARY", "SESSION_USAGE")
44
add_field("QUERY", plugin::TableFunction::STRING, FUNCTION_NAME_LEN, false);
45
add_field("USER_TIME_USED_SECONDS", plugin::TableFunction::STRING, FUNCTION_NAME_LEN, false);
46
add_field("USER_TIME_USED_MICRO_SECONDS", plugin::TableFunction::STRING, FUNCTION_NAME_LEN, false);
47
add_field("SYSTEM_TIME_USED_SECONDS", plugin::TableFunction::STRING, FUNCTION_NAME_LEN, false);
48
add_field("SYSTEM_TIME_USED_MICRO_SECONDS", plugin::TableFunction::STRING, FUNCTION_NAME_LEN, false);
49
add_field("INTEGRAL_MAX_RESIDENT_SET_SIZE", plugin::TableFunction::NUMBER, 0, false);
50
add_field("INTEGRAL_SHARED_TEXT_MEMORY_SIZE", plugin::TableFunction::NUMBER, 0, false);
51
add_field("INTEGRAL_UNSHARED_DATA_SIZE", plugin::TableFunction::NUMBER, 0, false);
52
add_field("INTEGRAL_UNSHARED_STACK_SIZE", plugin::TableFunction::NUMBER, 0, false);
53
add_field("PAGE_RECLAIMS", plugin::TableFunction::NUMBER, 0, false);
54
add_field("PAGE_FAULTS", plugin::TableFunction::NUMBER, 0, false);
55
add_field("SWAPS", plugin::TableFunction::NUMBER, 0, false);
56
add_field("BLOCK_INPUT_OPERATIONS", plugin::TableFunction::NUMBER, 0, false);
57
add_field("BLOCK_OUTPUT_OPERATIONS", plugin::TableFunction::NUMBER, 0, false);
58
add_field("MESSAGES_SENT", plugin::TableFunction::NUMBER, 0, false);
59
add_field("MESSAGES_RECEIVED", plugin::TableFunction::NUMBER, 0, false);
60
add_field("SIGNALS_RECEIVED", plugin::TableFunction::NUMBER, 0, false);
61
add_field("VOLUNTARY_CONTEXT_SWITCHES", plugin::TableFunction::NUMBER, 0, false);
62
add_field("INVOLUNTARY_CONTEXT_SWITCHES", plugin::TableFunction::NUMBER, 0, false);
65
bool performance_dictionary::SessionUsage::Generator::populate()
67
struct rusage r_usage;
73
if (getrusage(USAGE_VISABILITY, &r_usage))
78
/* USER_TIME_USED_SECONDS */
81
/* USER_TIME_USED_SECONDS */
82
push(static_cast<int64_t>(r_usage.ru_utime.tv_sec));
84
/* USER_TIME_USED_MICRO_SECONDS */
85
push(static_cast<int64_t>(r_usage.ru_utime.tv_usec));
87
/* SYSTEM_TIME_USED_SECONDS */
88
push(static_cast<int64_t>(r_usage.ru_stime.tv_sec));
90
/* SYSTEM_TIME_USED_MICRO_SECONDS */
91
push(static_cast<int64_t>(r_usage.ru_stime.tv_usec));
93
/* INTEGRAL_MAX_RESIDENT_SET_SIZE */
94
push(static_cast<int64_t>(r_usage.ru_maxrss));
96
/* INTEGRAL_SHARED_TEXT_MEMORY_SIZE */
97
push(static_cast<int64_t>(r_usage.ru_ixrss));
99
/* INTEGRAL_UNSHARED_DATA_SIZE */
100
push(static_cast<int64_t>(r_usage.ru_idrss));
102
/* INTEGRAL_UNSHARED_STACK_SIZE */
103
push(static_cast<int64_t>(r_usage.ru_isrss));
106
push(static_cast<int64_t>(r_usage.ru_minflt));
109
push(static_cast<int64_t>(r_usage.ru_majflt));
112
push(static_cast<int64_t>(r_usage.ru_nswap));
114
/* BLOCK_INPUT_OPERATIONS */
115
push(static_cast<int64_t>(r_usage.ru_inblock));
117
/* BLOCK_OUTPUT_OPERATIONS */
118
push(static_cast<int64_t>(r_usage.ru_oublock));
121
push(static_cast<int64_t>(r_usage.ru_msgsnd));
123
/* MESSAGES_RECEIVED */
124
push(static_cast<int64_t>(r_usage.ru_msgrcv));
126
/* SIGNALS_RECEIVED */
127
push(static_cast<int64_t>(r_usage.ru_nsignals));
129
/* VOLUNTARY_CONTEXT_SWITCHES */
130
push(static_cast<int64_t>(r_usage.ru_nvcsw));
132
/* INVOLUNTARY_CONTEXT_SWITCHES */
133
push(static_cast<int64_t>(r_usage.ru_nivcsw));