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