~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/performance_dictionary/session_usage.cc

  • Committer: lbieber
  • Date: 2010-09-23 20:19:20 UTC
  • mfrom: (1789.1.2 session_usage)
  • Revision ID: lbieber@orisndriz08-20100923201920-helm9tnadwf8p9dg
Merge Brian - Merge in session performance table (this is not built by default)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#include "config.h"
 
22
 
 
23
#include "plugin/performance_dictionary/dictionary.h"
 
24
 
 
25
#include <drizzled/atomics.h>
 
26
#include <drizzled/session.h>
 
27
 
 
28
#include <sys/resource.h>
 
29
 
 
30
using namespace drizzled;
 
31
using namespace std;
 
32
 
 
33
#define FUNCTION_NAME_LEN 64
 
34
 
 
35
performance_dictionary::SessionUsage::SessionUsage() :
 
36
  plugin::TableFunction("DATA_DICTIONARY", "SESSION_USAGE")
 
37
{
 
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);
 
57
}
 
58
 
 
59
 
 
60
performance_dictionary::SessionUsage::Generator::Generator(drizzled::Field **arg) :
 
61
  drizzled::plugin::TableFunction::Generator(arg),
 
62
  usage_cache(0)
 
63
 
64
  usage_cache= dynamic_cast<QueryUsage *>(getSession().getProperty("query_usage"));
 
65
  if (usage_cache)
 
66
    query_iter= usage_cache->list().rbegin();
 
67
}
 
68
 
 
69
bool performance_dictionary::SessionUsage::Generator::populate()
 
70
{
 
71
  if (not usage_cache)
 
72
    return false;
 
73
 
 
74
  if (query_iter ==  usage_cache->list().rend())
 
75
    return false;
 
76
 
 
77
  publish((*query_iter).query, (*query_iter).delta());
 
78
  query_iter++;
 
79
 
 
80
  return true;
 
81
}
 
82
 
 
83
void performance_dictionary::SessionUsage::Generator::publish(const std::string &sql, const struct rusage &usage_arg)
 
84
{
 
85
  /* SQL */
 
86
  push(sql);
 
87
 
 
88
  /* USER_TIME_USED_SECONDS */
 
89
  push(static_cast<int64_t>(usage_arg.ru_utime.tv_sec));
 
90
 
 
91
  /* USER_TIME_USED_MICRO_SECONDS */
 
92
  push(static_cast<int64_t>(usage_arg.ru_utime.tv_usec));
 
93
 
 
94
  /* SYSTEM_TIME_USED_SECONDS */
 
95
  push(static_cast<int64_t>(usage_arg.ru_stime.tv_sec));
 
96
 
 
97
  /* SYSTEM_TIME_USED_MICRO_SECONDS */
 
98
  push(static_cast<int64_t>(usage_arg.ru_stime.tv_usec));
 
99
 
 
100
  /* INTEGRAL_MAX_RESIDENT_SET_SIZE */
 
101
  push(static_cast<int64_t>(usage_arg.ru_maxrss));
 
102
 
 
103
  /* INTEGRAL_SHARED_TEXT_MEMORY_SIZE */
 
104
  push(static_cast<int64_t>(usage_arg.ru_ixrss));
 
105
 
 
106
  /* INTEGRAL_UNSHARED_DATA_SIZE */
 
107
  push(static_cast<int64_t>(usage_arg.ru_idrss));
 
108
 
 
109
  /* INTEGRAL_UNSHARED_STACK_SIZE */
 
110
  push(static_cast<int64_t>(usage_arg.ru_isrss));
 
111
 
 
112
  /* PAGE_RECLAIMS */
 
113
  push(static_cast<int64_t>(usage_arg.ru_minflt));
 
114
 
 
115
  /* PAGE_FAULTS */
 
116
  push(static_cast<int64_t>(usage_arg.ru_majflt));
 
117
 
 
118
  /* SWAPS */
 
119
  push(static_cast<int64_t>(usage_arg.ru_nswap));
 
120
 
 
121
  /* BLOCK_INPUT_OPERATIONS */
 
122
  push(static_cast<int64_t>(usage_arg.ru_inblock));
 
123
 
 
124
  /* BLOCK_OUTPUT_OPERATIONS */
 
125
  push(static_cast<int64_t>(usage_arg.ru_oublock));
 
126
 
 
127
  /* MESSAGES_SENT */
 
128
  push(static_cast<int64_t>(usage_arg.ru_msgsnd));
 
129
 
 
130
  /* MESSAGES_RECEIVED */
 
131
  push(static_cast<int64_t>(usage_arg.ru_msgrcv));
 
132
 
 
133
  /* SIGNALS_RECEIVED */
 
134
  push(static_cast<int64_t>(usage_arg.ru_nsignals));
 
135
 
 
136
  /* VOLUNTARY_CONTEXT_SWITCHES */
 
137
  push(static_cast<int64_t>(usage_arg.ru_nvcsw));
 
138
 
 
139
  /* INVOLUNTARY_CONTEXT_SWITCHES */
 
140
  push(static_cast<int64_t>(usage_arg.ru_nivcsw));
 
141
}