Drizzled Public API Documentation

status_helper.cc

00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *  Copyright (C) 2010 Joseph Daly 
00006  *
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; version 2 of the License.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 #include <config.h>
00022 #include <boost/lexical_cast.hpp>
00023 #include "status_helper.h"
00024 #include <drizzled/set_var.h>
00025 #include <drizzled/drizzled.h>
00026 #include <plugin/myisam/myisam.h>
00027 
00028 #include <drizzled/refresh_version.h>
00029 
00030 #include <sstream>
00031 
00032 using namespace std;
00033 
00034 namespace drizzled
00035 {
00036 
00037 extern time_t server_start_time;
00038 extern time_t flush_status_time;
00039 
00040 static int show_starttime_new(drizzle_show_var *var, char *buff)
00041 {
00042   var->type= SHOW_LONG;
00043   var->value= buff;
00044   *((long *)buff)= (long) (time(NULL) - server_start_time);
00045   return 0;
00046 }
00047 
00048 static int show_flushstatustime_new(drizzle_show_var *var, char *buff)
00049 {
00050   var->type= SHOW_LONG;
00051   var->value= buff;
00052   *((long *)buff)= (long) (time(NULL) - flush_status_time);
00053   return 0;
00054 }
00055 
00056 static int show_connection_count_new(drizzle_show_var *var, char *buff)
00057 {
00058   var->type= SHOW_INT;
00059   var->value= buff;
00060   *((uint32_t *)buff)= connection_count;
00061   return 0;
00062 }
00063 
00064 static st_show_var_func_container show_starttime_cont_new= { &show_starttime_new };
00065 
00066 static st_show_var_func_container show_flushstatustime_cont_new= { &show_flushstatustime_new };
00067 
00068 static st_show_var_func_container show_connection_count_cont_new= { &show_connection_count_new };
00069 
00070 string StatusHelper::fillHelper(system_status_var *status_var, char *value, SHOW_TYPE show_type)
00071 {
00072   ostringstream oss;
00073   string return_value;
00074 
00075   switch (show_type) {
00076   case SHOW_DOUBLE_STATUS:
00077     value= ((char *) status_var + (ulong) value);
00078     /* fall through */
00079   case SHOW_DOUBLE:
00080     oss.precision(6);
00081     oss << *(double *) value;
00082     return_value= oss.str();
00083     break;
00084   case SHOW_LONG_STATUS:
00085     value= ((char *) status_var + (ulong) value);
00086     /* fall through */
00087   case SHOW_LONG:
00088     return_value=boost::lexical_cast<std::string>(*(long*) value);
00089     break;
00090   case SHOW_LONGLONG_STATUS:
00091     value= ((char *) status_var + (uint64_t) value);
00092     /* fall through */
00093   case SHOW_LONGLONG:
00094     return_value=boost::lexical_cast<std::string>(*(int64_t*) value);
00095     break;
00096   case SHOW_SIZE:
00097     return_value=boost::lexical_cast<std::string>(*(size_t*) value);
00098     break;
00099   case SHOW_HA_ROWS:
00100     return_value=boost::lexical_cast<std::string>((int64_t) *(ha_rows*) value);
00101     break;
00102   case SHOW_BOOL:
00103   case SHOW_MY_BOOL:
00104     return_value= *(bool*) value ? "ON" : "OFF";
00105     break;
00106   case SHOW_INT:
00107   case SHOW_INT_NOFLUSH: // the difference lies in refresh_status()
00108     return_value=boost::lexical_cast<std::string>((long) *(uint32_t*) value);
00109     break;
00110   case SHOW_CHAR:
00111     {
00112       if (value)
00113         return_value= value;
00114       break;
00115     }
00116   case SHOW_CHAR_PTR:
00117     {
00118       if (*(char**) value)
00119         return_value= *(char**) value;
00120 
00121       break;
00122     }
00123   case SHOW_UNDEF:
00124     break;                                        // Return empty string
00125   case SHOW_SYS:                                  // Cannot happen
00126   default:
00127     assert(0);
00128     break;
00129   }
00130 
00131   return return_value;
00132 }
00133 
00134 drizzle_show_var StatusHelper::status_vars_defs[]=
00135 {
00136   {"Aborted_clients",           (char*) offsetof(system_status_var, aborted_threads), SHOW_LONGLONG_STATUS},
00137   {"Aborted_connects",          (char*) offsetof(system_status_var, aborted_connects), SHOW_LONGLONG_STATUS},
00138   {"Bytes_received",            (char*) offsetof(system_status_var, bytes_received), SHOW_LONGLONG_STATUS},
00139   {"Bytes_sent",                (char*) offsetof(system_status_var, bytes_sent), SHOW_LONGLONG_STATUS},
00140   {"Connections",               (char*) &current_global_counters.connections,  SHOW_LONGLONG},
00141   {"Created_tmp_disk_tables",   (char*) offsetof(system_status_var, created_tmp_disk_tables), SHOW_LONGLONG_STATUS},
00142   {"Created_tmp_tables",        (char*) offsetof(system_status_var, created_tmp_tables), SHOW_LONGLONG_STATUS},
00143   {"Flush_commands",            (char*) &refresh_version,    SHOW_INT_NOFLUSH},
00144   {"Handler_commit",            (char*) offsetof(system_status_var, ha_commit_count), SHOW_LONGLONG_STATUS},
00145   {"Handler_delete",            (char*) offsetof(system_status_var, ha_delete_count), SHOW_LONGLONG_STATUS},
00146   {"Handler_prepare",           (char*) offsetof(system_status_var, ha_prepare_count),  SHOW_LONGLONG_STATUS},
00147   {"Handler_read_first",        (char*) offsetof(system_status_var, ha_read_first_count), SHOW_LONGLONG_STATUS},
00148   {"Handler_read_key",          (char*) offsetof(system_status_var, ha_read_key_count), SHOW_LONGLONG_STATUS},
00149   {"Handler_read_next",         (char*) offsetof(system_status_var, ha_read_next_count), SHOW_LONGLONG_STATUS},
00150   {"Handler_read_prev",         (char*) offsetof(system_status_var, ha_read_prev_count), SHOW_LONGLONG_STATUS},
00151   {"Handler_read_rnd",          (char*) offsetof(system_status_var, ha_read_rnd_count), SHOW_LONGLONG_STATUS},
00152   {"Handler_read_rnd_next",     (char*) offsetof(system_status_var, ha_read_rnd_next_count), SHOW_LONGLONG_STATUS},
00153   {"Handler_rollback",          (char*) offsetof(system_status_var, ha_rollback_count), SHOW_LONGLONG_STATUS},
00154   {"Handler_savepoint",         (char*) offsetof(system_status_var, ha_savepoint_count), SHOW_LONGLONG_STATUS},
00155   {"Handler_savepoint_rollback",(char*) offsetof(system_status_var, ha_savepoint_rollback_count), SHOW_LONGLONG_STATUS},
00156   {"Handler_update",            (char*) offsetof(system_status_var, ha_update_count), SHOW_LONGLONG_STATUS},
00157   {"Handler_write",             (char*) offsetof(system_status_var, ha_write_count), SHOW_LONGLONG_STATUS},
00158   {"Last_query_cost",           (char*) offsetof(system_status_var, last_query_cost), SHOW_DOUBLE_STATUS},
00159   {"Max_used_connections",      (char*) &current_global_counters.max_used_connections,  SHOW_LONGLONG},
00160   {"Questions",                 (char*) offsetof(system_status_var, questions), SHOW_LONGLONG_STATUS},
00161   {"Select_full_join",          (char*) offsetof(system_status_var, select_full_join_count), SHOW_LONGLONG_STATUS},
00162   {"Select_full_range_join",    (char*) offsetof(system_status_var, select_full_range_join_count), SHOW_LONGLONG_STATUS},
00163   {"Select_range",              (char*) offsetof(system_status_var, select_range_count), SHOW_LONGLONG_STATUS},
00164   {"Select_range_check",        (char*) offsetof(system_status_var, select_range_check_count), SHOW_LONGLONG_STATUS},
00165   {"Select_scan",               (char*) offsetof(system_status_var, select_scan_count), SHOW_LONGLONG_STATUS},
00166   {"Sessions_connected",         (char*) &show_connection_count_cont_new,  SHOW_FUNC},
00167   {"Slow_queries",              (char*) offsetof(system_status_var, long_query_count), SHOW_LONGLONG_STATUS},
00168   {"Sort_merge_passes",         (char*) offsetof(system_status_var, filesort_merge_passes), SHOW_LONGLONG_STATUS},
00169   {"Sort_range",                (char*) offsetof(system_status_var, filesort_range_count), SHOW_LONGLONG_STATUS},
00170   {"Sort_rows",                 (char*) offsetof(system_status_var, filesort_rows), SHOW_LONGLONG_STATUS},
00171   {"Sort_scan",                 (char*) offsetof(system_status_var, filesort_scan_count), SHOW_LONGLONG_STATUS},
00172   {"Table_locks_immediate",     (char*) &current_global_counters.locks_immediate,        SHOW_LONGLONG},
00173   {"Table_locks_waited",        (char*) &current_global_counters.locks_waited,           SHOW_LONGLONG},
00174   {"Uptime",                    (char*) &show_starttime_cont_new,         SHOW_FUNC},
00175   {"Uptime_since_flush_status", (char*) &show_flushstatustime_cont_new,   SHOW_FUNC},
00176   {NULL, NULL, SHOW_LONGLONG}
00177 };
00178 
00179 } /* namespace drizzled */