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
00023 #include <plugin/session_dictionary/dictionary.h>
00024
00025 #include <netdb.h>
00026
00027 #include <drizzled/pthread_globals.h>
00028 #include <drizzled/plugin/client.h>
00029 #include <drizzled/plugin/authorization.h>
00030 #include <drizzled/internal/my_sys.h>
00031 #include <drizzled/internal/thread_var.h>
00032
00033 #include <set>
00034
00035 using namespace std;
00036 using namespace drizzled;
00037
00038 ProcesslistTool::ProcesslistTool() :
00039 plugin::TableFunction("DATA_DICTIONARY", "PROCESSLIST")
00040 {
00041 add_field("ID", plugin::TableFunction::NUMBER, 0, false);
00042 add_field("USERNAME", 16);
00043 add_field("HOST", NI_MAXHOST);
00044 add_field("DB", plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, true);
00045 add_field("COMMAND", 16);
00046 add_field("TIME", plugin::TableFunction::SIZE, 0, false);
00047 add_field("STATE", plugin::TableFunction::STRING, 256, true);
00048 add_field("INFO", plugin::TableFunction::STRING, PROCESS_LIST_WIDTH, true);
00049 add_field("HAS_GLOBAL_LOCK", plugin::TableFunction::BOOLEAN, 0, false);
00050 }
00051
00052 ProcesslistTool::Generator::Generator(Field **arg) :
00053 plugin::TableFunction::Generator(arg),
00054 session_generator(*getSession().user())
00055 {
00056 }
00057
00058 bool ProcesslistTool::Generator::populate()
00059 {
00060 drizzled::Session::pointer tmp;
00061
00062 while ((tmp= session_generator))
00063 {
00064 drizzled::session::State::const_shared_ptr state(tmp->state());
00065 identifier::User::const_shared_ptr tmp_sctx= tmp->user();
00066
00067
00068 push((int64_t) tmp->thread_id);
00069
00070
00071 if (not tmp_sctx->username().empty())
00072 push(tmp_sctx->username());
00073 else
00074 push(_("no user"));
00075
00076
00077 push(tmp_sctx->address());
00078
00079
00080 drizzled::util::string::const_shared_ptr schema(tmp->schema());
00081 if (schema and not schema->empty())
00082 {
00083 push(*schema);
00084 }
00085 else
00086 {
00087 push();
00088 }
00089
00090
00091 const char *val= tmp->getKilled() == Session::KILL_CONNECTION ? "Killed" : NULL;
00092 if (val)
00093 {
00094 push(val);
00095 }
00096 else
00097 {
00098 push(getCommandName(tmp->command));
00099 }
00100
00101
00102 boost::posix_time::time_duration duration_result;
00103 getSession().getTimeDifference(duration_result, getSession().start_timer());
00104 duration_result.is_negative() ? push(static_cast<uint64_t>(0)) : push(static_cast<uint64_t>(duration_result.total_seconds()));
00105
00106
00107 const char *step= tmp->get_proc_info();
00108 step ? push(step): push();
00109
00110
00111 if (state)
00112 {
00113 size_t length;
00114 const char *tmp_ptr= state->query(length);
00115 push(tmp_ptr, length);
00116 }
00117 else
00118 {
00119 push();
00120 }
00121
00122
00123 bool has_global_lock= tmp->isGlobalReadLock();
00124 push(has_global_lock);
00125
00126 return true;
00127 }
00128
00129 return false;
00130 }