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

« back to all changes in this revision

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