~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/status_dictionary/status.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-09-13 00:53:34 UTC
  • mto: (1126.9.2 captain-20090915-01)
  • mto: This revision was merged to the branch mainline in revision 1133.
  • Revision ID: osullivan.padraig@gmail.com-20090913005334-6wio2sbjugskfbm3
Added calls to the connection start/end dtrace probes.

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 Sun Microsystems
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/status_dictionary/dictionary.h"
24
 
 
25
 
#include <drizzled/pthread_globals.h>
26
 
#include <drizzled/internal/m_string.h>
27
 
#include <drizzled/definitions.h>
28
 
 
29
 
#include <vector>
30
 
#include <string>
31
 
#include <sstream>
32
 
 
33
 
using namespace std;
34
 
using namespace drizzled;
35
 
 
36
 
StateTool::StateTool(const char *arg, bool global) :
37
 
  plugin::TableFunction("DATA_DICTIONARY", arg),
38
 
  option_type(global ? OPT_GLOBAL : OPT_SESSION)
39
 
{
40
 
  add_field("VARIABLE_NAME");
41
 
  add_field("VARIABLE_VALUE", 1024);
42
 
}
43
 
 
44
 
StateTool::Generator::Generator(Field **arg, sql_var_t option_arg,
45
 
                                drizzle_show_var *variables_args,
46
 
                                bool status_arg) :
47
 
  plugin::TableFunction::Generator(arg),
48
 
  option_type(option_arg),
49
 
  has_status(status_arg),
50
 
  variables(variables_args)
51
 
{
52
 
  if (not has_status)
53
 
  {
54
 
    status_ptr= NULL;
55
 
    pthread_rwlock_rdlock(&LOCK_system_variables_hash);
56
 
  }
57
 
  else if (option_type == OPT_GLOBAL  && has_status)
58
 
  {
59
 
    status_ptr= &status;
60
 
    pthread_mutex_lock(&LOCK_status);
61
 
    calc_sum_of_all_status(&status);
62
 
  }
63
 
  else
64
 
  {
65
 
    status_ptr= &getSession().status_var;
66
 
  }
67
 
}
68
 
 
69
 
StateTool::Generator::~Generator()
70
 
{
71
 
  if (not has_status)
72
 
  {
73
 
    pthread_rwlock_unlock(&LOCK_system_variables_hash);
74
 
  }
75
 
  else if (option_type == OPT_GLOBAL)
76
 
  {
77
 
    pthread_mutex_unlock(&LOCK_status);
78
 
  }
79
 
}
80
 
 
81
 
bool StateTool::Generator::populate()
82
 
{
83
 
  while (variables && variables->name)
84
 
  {
85
 
    drizzle_show_var *var;
86
 
    MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, int64_t);
87
 
    char * const buff= (char *) &buff_data;
88
 
 
89
 
    /*
90
 
      if var->type is SHOW_FUNC, call the function.
91
 
      Repeat as necessary, if new var is again SHOW_FUNC
92
 
    */
93
 
    {
94
 
      drizzle_show_var tmp;
95
 
 
96
 
      for (var= variables; var->type == SHOW_FUNC; var= &tmp)
97
 
        ((mysql_show_var_func)((st_show_var_func_container *)var->value)->func)(&tmp, buff);
98
 
    }
99
 
 
100
 
    if (isWild(variables->name))
101
 
    {
102
 
      variables++;
103
 
      continue;
104
 
    }
105
 
 
106
 
    fill(variables->name, var->value, var->type);
107
 
 
108
 
    variables++;
109
 
 
110
 
    return true;
111
 
  }
112
 
 
113
 
  return false;
114
 
}
115
 
 
116
 
 
117
 
extern drizzled::KEY_CACHE dflt_key_cache_var, *dflt_key_cache;
118
 
void StateTool::Generator::fill(const std::string &name, char *value, SHOW_TYPE show_type)
119
 
{
120
 
  struct system_status_var *status_var;
121
 
  std::ostringstream oss;
122
 
 
123
 
 
124
 
  std::string return_value;
125
 
 
126
 
  /* Scope represents if the status should be session or global */
127
 
  status_var= getStatus();
128
 
 
129
 
  pthread_mutex_lock(&LOCK_global_system_variables);
130
 
 
131
 
  if (show_type == SHOW_SYS)
132
 
  {
133
 
    show_type= ((sys_var*) value)->show_type();
134
 
    value= (char*) ((sys_var*) value)->value_ptr(&(getSession()), option_type,
135
 
                                                 &null_lex_str);
136
 
  }
137
 
 
138
 
  /*
139
 
    note that value may be == buff. All SHOW_xxx code below
140
 
    should still work in this case
141
 
  */
142
 
  switch (show_type) {
143
 
  case SHOW_DOUBLE_STATUS:
144
 
    value= ((char *) status_var + (ulong) value);
145
 
    /* fall through */
146
 
  case SHOW_DOUBLE:
147
 
    oss.precision(6);
148
 
    oss << *(double *) value;
149
 
    return_value= oss.str();
150
 
    break;
151
 
  case SHOW_LONG_STATUS:
152
 
    value= ((char *) status_var + (ulong) value);
153
 
    /* fall through */
154
 
  case SHOW_LONG:
155
 
    oss << *(long*) value;
156
 
    return_value= oss.str();
157
 
    break;
158
 
  case SHOW_LONGLONG_STATUS:
159
 
    value= ((char *) status_var + (uint64_t) value);
160
 
    /* fall through */
161
 
  case SHOW_LONGLONG:
162
 
    oss << *(int64_t*) value;
163
 
    return_value= oss.str();
164
 
    break;
165
 
  case SHOW_SIZE:
166
 
    oss << *(size_t*) value;
167
 
    return_value= oss.str();
168
 
    break;
169
 
  case SHOW_HA_ROWS:
170
 
    oss << (int64_t) *(ha_rows*) value;
171
 
    return_value= oss.str();
172
 
    break;
173
 
  case SHOW_BOOL:
174
 
  case SHOW_MY_BOOL:
175
 
    return_value= *(bool*) value ? "ON" : "OFF";
176
 
    break;
177
 
  case SHOW_INT:
178
 
  case SHOW_INT_NOFLUSH: // the difference lies in refresh_status()
179
 
    oss << (long) *(uint32_t*) value;
180
 
    return_value= oss.str();
181
 
    break;
182
 
  case SHOW_CHAR:
183
 
    {
184
 
      if (value)
185
 
        return_value= value;
186
 
      break;
187
 
    }
188
 
  case SHOW_CHAR_PTR:
189
 
    {
190
 
      if (*(char**) value)
191
 
        return_value= *(char**) value;
192
 
 
193
 
      break;
194
 
    }
195
 
  case SHOW_KEY_CACHE_LONG:
196
 
    value= (char*) dflt_key_cache + (unsigned long)value;
197
 
    oss << *(long*) value;
198
 
    return_value= oss.str();
199
 
    break;
200
 
  case SHOW_KEY_CACHE_LONGLONG:
201
 
    value= (char*) dflt_key_cache + (unsigned long)value;
202
 
    oss << *(int64_t*) value;
203
 
    return_value= oss.str();
204
 
    break;
205
 
  case SHOW_UNDEF:
206
 
    break;                                        // Return empty string
207
 
  case SHOW_SYS:                                  // Cannot happen
208
 
  default:
209
 
    assert(0);
210
 
    break;
211
 
  }
212
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
213
 
  push(name);
214
 
  if (return_value.length())
215
 
    push(return_value);
216
 
  else 
217
 
    push(" ");
218
 
}