00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022 #include "status_helper.h"
00023 #include <boost/lexical_cast.hpp>
00024 #include <drizzled/open_tables_state.h>
00025 #include <drizzled/set_var.h>
00026 #include <drizzled/drizzled.h>
00027 #include <plugin/myisam/myisam.h>
00028 #include <sstream>
00029
00030 using namespace std;
00031
00032 namespace drizzled {
00033
00034 extern time_t server_start_time;
00035 extern time_t flush_status_time;
00036
00037 static int show_starttime_new(drizzle_show_var *var, char *buff)
00038 {
00039 var->type= SHOW_LONG;
00040 var->value= buff;
00041 *((long *)buff)= (long) (time(NULL) - server_start_time);
00042 return 0;
00043 }
00044
00045 static int show_flushstatustime_new(drizzle_show_var *var, char *buff)
00046 {
00047 var->type= SHOW_LONG;
00048 var->value= buff;
00049 *((long *)buff)= (long) (time(NULL) - flush_status_time);
00050 return 0;
00051 }
00052
00053 static int show_connection_count_new(drizzle_show_var *var, char *buff)
00054 {
00055 var->type= SHOW_INT;
00056 var->value= buff;
00057 *((uint32_t *)buff)= connection_count;
00058 return 0;
00059 }
00060
00061 static st_show_var_func_container show_starttime_cont_new= { &show_starttime_new };
00062
00063 static st_show_var_func_container show_flushstatustime_cont_new= { &show_flushstatustime_new };
00064
00065 static st_show_var_func_container show_connection_count_cont_new= { &show_connection_count_new };
00066
00067 string StatusHelper::fillHelper(system_status_var *status_var, const char *value, SHOW_TYPE show_type)
00068 {
00069 ostringstream oss;
00070 switch (show_type)
00071 {
00072 case SHOW_DOUBLE_STATUS:
00073 value= ((char *) status_var + (ulong) value);
00074
00075 case SHOW_DOUBLE:
00076 oss.precision(6);
00077 oss << *(double *) value;
00078 return oss.str();
00079 case SHOW_LONG_STATUS:
00080 value= ((char *) status_var + (ulong) value);
00081
00082 case SHOW_LONG:
00083 return boost::lexical_cast<std::string>(*(long*) value);
00084 break;
00085 case SHOW_LONGLONG_STATUS:
00086 value= ((char *) status_var + (uint64_t) value);
00087
00088 case SHOW_LONGLONG:
00089 return boost::lexical_cast<std::string>(*(int64_t*) value);
00090 case SHOW_SIZE:
00091 return boost::lexical_cast<std::string>(*(size_t*) value);
00092 case SHOW_HA_ROWS:
00093 return boost::lexical_cast<std::string>((int64_t) *(ha_rows*) value);
00094 case SHOW_BOOL:
00095 case SHOW_MY_BOOL:
00096 return *(bool*) value ? "ON" : "OFF";
00097 case SHOW_INT:
00098 case SHOW_INT_NOFLUSH:
00099 return boost::lexical_cast<std::string>((long) *(uint32_t*) value);
00100 case SHOW_CHAR:
00101 if (value)
00102 return value;
00103 break;
00104 case SHOW_CHAR_PTR:
00105 if (*(char**) value)
00106 return *(char**) value;
00107 break;
00108 case SHOW_UNDEF:
00109 break;
00110 case SHOW_SYS:
00111 default:
00112 assert(0);
00113 }
00114 return string();
00115 }
00116
00117 drizzle_show_var StatusHelper::status_vars_defs[]=
00118 {
00119 {"Aborted_clients", (char*) offsetof(system_status_var, aborted_threads), SHOW_LONGLONG_STATUS},
00120 {"Aborted_connects", (char*) offsetof(system_status_var, aborted_connects), SHOW_LONGLONG_STATUS},
00121 {"Bytes_received", (char*) offsetof(system_status_var, bytes_received), SHOW_LONGLONG_STATUS},
00122 {"Bytes_sent", (char*) offsetof(system_status_var, bytes_sent), SHOW_LONGLONG_STATUS},
00123 {"Connections", (char*) ¤t_global_counters.connections, SHOW_LONGLONG},
00124 {"Created_tmp_disk_tables", (char*) offsetof(system_status_var, created_tmp_disk_tables), SHOW_LONGLONG_STATUS},
00125 {"Created_tmp_tables", (char*) offsetof(system_status_var, created_tmp_tables), SHOW_LONGLONG_STATUS},
00126 {"Flush_commands", (char*) &g_refresh_version, SHOW_INT_NOFLUSH},
00127 {"Handler_commit", (char*) offsetof(system_status_var, ha_commit_count), SHOW_LONGLONG_STATUS},
00128 {"Handler_delete", (char*) offsetof(system_status_var, ha_delete_count), SHOW_LONGLONG_STATUS},
00129 {"Handler_prepare", (char*) offsetof(system_status_var, ha_prepare_count), SHOW_LONGLONG_STATUS},
00130 {"Handler_read_first", (char*) offsetof(system_status_var, ha_read_first_count), SHOW_LONGLONG_STATUS},
00131 {"Handler_read_key", (char*) offsetof(system_status_var, ha_read_key_count), SHOW_LONGLONG_STATUS},
00132 {"Handler_read_next", (char*) offsetof(system_status_var, ha_read_next_count), SHOW_LONGLONG_STATUS},
00133 {"Handler_read_prev", (char*) offsetof(system_status_var, ha_read_prev_count), SHOW_LONGLONG_STATUS},
00134 {"Handler_read_rnd", (char*) offsetof(system_status_var, ha_read_rnd_count), SHOW_LONGLONG_STATUS},
00135 {"Handler_read_rnd_next", (char*) offsetof(system_status_var, ha_read_rnd_next_count), SHOW_LONGLONG_STATUS},
00136 {"Handler_rollback", (char*) offsetof(system_status_var, ha_rollback_count), SHOW_LONGLONG_STATUS},
00137 {"Handler_savepoint", (char*) offsetof(system_status_var, ha_savepoint_count), SHOW_LONGLONG_STATUS},
00138 {"Handler_savepoint_rollback",(char*) offsetof(system_status_var, ha_savepoint_rollback_count), SHOW_LONGLONG_STATUS},
00139 {"Handler_update", (char*) offsetof(system_status_var, ha_update_count), SHOW_LONGLONG_STATUS},
00140 {"Handler_write", (char*) offsetof(system_status_var, ha_write_count), SHOW_LONGLONG_STATUS},
00141 {"Last_query_cost", (char*) offsetof(system_status_var, last_query_cost), SHOW_DOUBLE_STATUS},
00142 {"Max_used_connections", (char*) ¤t_global_counters.max_used_connections, SHOW_LONGLONG},
00143 {"Questions", (char*) offsetof(system_status_var, questions), SHOW_LONGLONG_STATUS},
00144 {"Select_full_join", (char*) offsetof(system_status_var, select_full_join_count), SHOW_LONGLONG_STATUS},
00145 {"Select_full_range_join", (char*) offsetof(system_status_var, select_full_range_join_count), SHOW_LONGLONG_STATUS},
00146 {"Select_range", (char*) offsetof(system_status_var, select_range_count), SHOW_LONGLONG_STATUS},
00147 {"Select_range_check", (char*) offsetof(system_status_var, select_range_check_count), SHOW_LONGLONG_STATUS},
00148 {"Select_scan", (char*) offsetof(system_status_var, select_scan_count), SHOW_LONGLONG_STATUS},
00149 {"Sessions_connected", (char*) &show_connection_count_cont_new, SHOW_FUNC},
00150 {"Slow_queries", (char*) offsetof(system_status_var, long_query_count), SHOW_LONGLONG_STATUS},
00151 {"Sort_merge_passes", (char*) offsetof(system_status_var, filesort_merge_passes), SHOW_LONGLONG_STATUS},
00152 {"Sort_range", (char*) offsetof(system_status_var, filesort_range_count), SHOW_LONGLONG_STATUS},
00153 {"Sort_rows", (char*) offsetof(system_status_var, filesort_rows), SHOW_LONGLONG_STATUS},
00154 {"Sort_scan", (char*) offsetof(system_status_var, filesort_scan_count), SHOW_LONGLONG_STATUS},
00155 {"Table_locks_immediate", (char*) ¤t_global_counters.locks_immediate, SHOW_LONGLONG},
00156 {"Table_locks_waited", (char*) ¤t_global_counters.locks_waited, SHOW_LONGLONG},
00157 {"Uptime", (char*) &show_starttime_cont_new, SHOW_FUNC},
00158 {"Uptime_since_flush_status", (char*) &show_flushstatustime_cont_new, SHOW_FUNC},
00159 {NULL, NULL, SHOW_LONGLONG}
00160 };
00161
00162 }