~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/logging_stats/status_tool.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-10-02 14:17:48 UTC
  • mfrom: (1.1.1 upstream)
  • mto: (2.1.17 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20101002141748-m6vbfbfjhrw1153e
Tags: 2010.09.1802-1
* New upstream release.
* Removed pid-file argument hack.
* Updated GPL-2 address to be new address.
* Directly copy in drizzledump.1 since debian doesn't have sphinx 1.0 yet.
* Link to jquery from libjs-jquery. Add it as a depend.
* Add drizzled.8 symlink to the install files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2010, Joseph Daly <skinny.moey@gmail.com>
 
3
 * All rights reserved.
 
4
 *
 
5
 * Redistribution and use in source and binary forms, with or without
 
6
 * modification, are permitted provided that the following conditions are met:
 
7
 *
 
8
 *   * Redistributions of source code must retain the above copyright notice,
 
9
 *     this list of conditions and the following disclaimer.
 
10
 *   * Redistributions in binary form must reproduce the above copyright notice,
 
11
 *     this list of conditions and the following disclaimer in the documentation
 
12
 *     and/or other materials provided with the distribution.
 
13
 *   * Neither the name of Joseph Daly nor the names of its contributors
 
14
 *     may be used to endorse or promote products derived from this software
 
15
 *     without specific prior written permission.
 
16
 *
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 
18
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
20
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 
21
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 
22
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 
23
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 
24
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 
25
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 
26
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 
27
 * THE POSSIBILITY OF SUCH DAMAGE.
 
28
 */
 
29
 
 
30
/**
 
31
 * @details
 
32
 *
 
33
 * This class defines the "show status" and "show global status" 
 
34
 * DATA_DICTIONARY tables:
 
35
 * 
 
36
 * drizzle> describe SESSION_STATUS;
 
37
 * +----------------+---------+-------+---------+-----------------+-----------+
 
38
 * | Field          | Type    | Null  | Default | Default_is_NULL | On_Update |
 
39
 * +----------------+---------+-------+---------+-----------------+-----------+
 
40
 * | VARIABLE_NAME  | VARCHAR | FALSE |         | FALSE           |           | 
 
41
 * | VARIABLE_VALUE | VARCHAR | FALSE |         | FALSE           |           | 
 
42
 * +----------------+---------+-------+---------+-----------------+-----------+
 
43
 *
 
44
 * drizzle> describe GLOBAL_STATUS;
 
45
 * +----------------+---------+-------+---------+-----------------+-----------+
 
46
 * | Field          | Type    | Null  | Default | Default_is_NULL | On_Update |
 
47
 * +----------------+---------+-------+---------+-----------------+-----------+
 
48
 * | VARIABLE_NAME  | VARCHAR | FALSE |         | FALSE           |           | 
 
49
 * | VARIABLE_VALUE | VARCHAR | FALSE |         | FALSE           |           | 
 
50
 * +----------------+---------+-------+---------+-----------------+-----------+
 
51
 *
 
52
 */
 
53
 
 
54
#include "config.h"
 
55
 
 
56
#include "status_tool.h"
 
57
#include "drizzled/status_helper.h"
 
58
 
 
59
#include <vector>
 
60
#include <sstream>
 
61
 
 
62
using namespace drizzled;
 
63
using namespace plugin;
 
64
using namespace std;
 
65
 
 
66
 
 
67
class ShowVarCmpFunctor 
 
68
{
 
69
  public:
 
70
  ShowVarCmpFunctor() { }
 
71
  inline bool operator()(const drizzle_show_var *var1, const drizzle_show_var *var2) const
 
72
  {
 
73
    int val= strcmp(var1->name, var2->name);
 
74
    return (val < 0);
 
75
  }
 
76
};
 
77
 
 
78
StatusTool::StatusTool(LoggingStats *in_logging_stats, bool inIsLocal) :
 
79
  TableFunction("DATA_DICTIONARY", inIsLocal ? "SESSION_STATUS" : "GLOBAL_STATUS"),
 
80
  outer_logging_stats(in_logging_stats),
 
81
  isLocal(inIsLocal)
 
82
{
 
83
  add_field("VARIABLE_NAME");
 
84
  add_field("VARIABLE_VALUE", 1024);
 
85
 
 
86
  drizzle_show_var *var= NULL;
 
87
  uint32_t count= 0;
 
88
  vector<drizzle_show_var *>::iterator all_status_vars_iterator= all_status_vars.begin();
 
89
  while (true)
 
90
  {
 
91
    var= &StatusHelper::status_vars_defs[count];
 
92
    if ((var == NULL) || (var->name == NULL))
 
93
    {
 
94
      break;
 
95
    }
 
96
    all_status_vars_iterator= all_status_vars.insert(all_status_vars_iterator, var);
 
97
    ++count;
 
98
  }
 
99
  sort(all_status_vars.begin(), all_status_vars.end(), ShowVarCmpFunctor());
 
100
}
 
101
 
 
102
StatusTool::Generator::Generator(Field **arg, LoggingStats *in_logging_stats,
 
103
                                 vector<drizzle_show_var *> *all_status_vars, 
 
104
                                 bool inIsLocal) :
 
105
  TableFunction::Generator(arg),
 
106
  logging_stats(in_logging_stats),
 
107
  isLocal(inIsLocal)   
 
108
{
 
109
  all_status_vars_it= all_status_vars->begin();
 
110
  all_status_vars_end= all_status_vars->end();
 
111
 
 
112
  status_var_to_display= NULL;
 
113
  if (isLocal)
 
114
  {
 
115
    ScoreboardSlot *scoreboard_slot= logging_stats->getCurrentScoreboard()->findOurScoreboardSlot(&getSession());
 
116
 
 
117
    if (scoreboard_slot != NULL)
 
118
    {
 
119
      /* A copy of the current status vars for a particular session */ 
 
120
      status_var_to_display= new StatusVars(*scoreboard_slot->getStatusVars());
 
121
 
 
122
      /* Sum the current scoreboard this will give us a value for any variables that have global meaning */
 
123
      StatusVars current_scoreboard_status_vars;
 
124
      CumulativeStats *cumulativeStats= logging_stats->getCumulativeStats();
 
125
      cumulativeStats->sumCurrentScoreboard(logging_stats->getCurrentScoreboard(), &current_scoreboard_status_vars, NULL);
 
126
 
 
127
      /* Copy the above to get a value for any variables that have global meaning */  
 
128
      status_var_to_display->copyGlobalVariables(logging_stats->getCumulativeStats()->getGlobalStatusVars());
 
129
      status_var_to_display->copyGlobalVariables(&current_scoreboard_status_vars); 
 
130
    } 
 
131
    else 
 
132
    {
 
133
      status_var_to_display= NULL;
 
134
    }
 
135
  }
 
136
  else // global status 
 
137
  {
 
138
    status_var_to_display= new StatusVars();
 
139
    CumulativeStats *cumulativeStats= logging_stats->getCumulativeStats();
 
140
    cumulativeStats->sumCurrentScoreboard(logging_stats->getCurrentScoreboard(), status_var_to_display, NULL);
 
141
    status_var_to_display->merge(logging_stats->getCumulativeStats()->getGlobalStatusVars());
 
142
  }
 
143
}
 
144
 
 
145
StatusTool::Generator::~Generator()
 
146
{
 
147
  delete status_var_to_display;
 
148
}
 
149
 
 
150
bool StatusTool::Generator::populate()
 
151
{
 
152
  if (status_var_to_display == NULL)
 
153
  {
 
154
    return false;
 
155
  }
 
156
 
 
157
  while (all_status_vars_it != all_status_vars_end)
 
158
  {
 
159
    drizzle_show_var *variables= *all_status_vars_it;
 
160
 
 
161
    if ((variables == NULL) || (variables->name == NULL))
 
162
    {
 
163
      return false;
 
164
    }
 
165
 
 
166
    drizzle_show_var *var;
 
167
    MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, int64_t);
 
168
    char * const buff= (char *) &buff_data;
 
169
 
 
170
    /*
 
171
      if var->type is SHOW_FUNC, call the function.
 
172
      Repeat as necessary, if new var is again SHOW_FUNC
 
173
    */
 
174
    {
 
175
      drizzle_show_var tmp;
 
176
 
 
177
      for (var= variables; var->type == SHOW_FUNC; var= &tmp)
 
178
        ((mysql_show_var_func)((st_show_var_func_container *)var->value)->func)(&tmp, buff);
 
179
    }
 
180
 
 
181
    if (isWild(variables->name))
 
182
    {
 
183
      ++all_status_vars_it;
 
184
      continue;
 
185
    }
 
186
 
 
187
    fill(variables->name, var->value, var->type);
 
188
 
 
189
    ++all_status_vars_it;
 
190
 
 
191
    return true;
 
192
  }
 
193
 
 
194
  return false;
 
195
}
 
196
 
 
197
void StatusTool::Generator::fill(const string &name, char *value, SHOW_TYPE show_type)
 
198
{
 
199
  struct system_status_var *status_var;
 
200
  ostringstream oss;
 
201
  string return_value;
 
202
 
 
203
  status_var= status_var_to_display->getStatusVarCounters();
 
204
 
 
205
  return_value= StatusHelper::fillHelper(status_var, value, show_type);
 
206
 
 
207
  push(name);
 
208
  if (return_value.length())
 
209
  {
 
210
    push(return_value);
 
211
  }
 
212
  else
 
213
  {
 
214
    push(" ");
 
215
  }
 
216
}