~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/status_dictionary/status.cc

  • Committer: Brian Aker
  • Date: 2010-06-11 17:26:39 UTC
  • mto: This revision was merged to the branch mainline in revision 1610.
  • Revision ID: brian@gaz-20100611172639-e9q2sliqizeoz4yd
Update for having share declared type.

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>
29
28
 
30
29
#include <vector>
31
30
#include <string>
43
42
}
44
43
 
45
44
StateTool::Generator::Generator(Field **arg, sql_var_t option_arg,
46
 
                                drizzle_show_var *variables_args)
47
 
                                :
 
45
                                drizzle_show_var *variables_args,
 
46
                                bool status_arg) :
48
47
  plugin::TableFunction::Generator(arg),
49
48
  option_type(option_arg),
 
49
  has_status(status_arg),
50
50
  variables(variables_args)
51
51
{
52
 
  pthread_rwlock_rdlock(&LOCK_system_variables_hash);
 
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
  }
53
67
}
54
68
 
55
69
StateTool::Generator::~Generator()
56
70
{
57
 
  pthread_rwlock_unlock(&LOCK_system_variables_hash);
 
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
  }
58
79
}
59
80
 
60
81
bool StateTool::Generator::populate()
92
113
  return false;
93
114
}
94
115
 
 
116
 
 
117
extern drizzled::KEY_CACHE dflt_key_cache_var, *dflt_key_cache;
95
118
void StateTool::Generator::fill(const std::string &name, char *value, SHOW_TYPE show_type)
96
119
{
 
120
  struct system_status_var *status_var;
97
121
  std::ostringstream oss;
 
122
 
 
123
 
98
124
  std::string return_value;
99
125
 
 
126
  /* Scope represents if the status should be session or global */
 
127
  status_var= getStatus();
 
128
 
100
129
  pthread_mutex_lock(&LOCK_global_system_variables);
101
130
 
102
131
  if (show_type == SHOW_SYS)
106
135
                                                 &null_lex_str);
107
136
  }
108
137
 
109
 
  return_value= StatusHelper::fillHelper(NULL, value, show_type); 
 
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;
110
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
  }
111
212
  pthread_mutex_unlock(&LOCK_global_system_variables);
112
213
  push(name);
113
214
  if (return_value.length())