drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
processlist.cc
1/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2009 Sun Microsystems, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <config.h>
22
23#include <plugin/session_dictionary/dictionary.h>
24
25#include <netdb.h>
26
27#include <drizzled/pthread_globals.h>
28#include <drizzled/plugin/client.h>
29#include <drizzled/plugin/authorization.h>
30#include <drizzled/internal/my_sys.h>
31#include <drizzled/internal/thread_var.h>
32#include <drizzled/session/state.h>
33#include <drizzled/session/times.h>
34#include <set>
35
36using namespace std;
37using namespace drizzled;
38
39ProcesslistTool::ProcesslistTool() :
40 plugin::TableFunction("DATA_DICTIONARY", "PROCESSLIST")
41{
42 add_field("ID", plugin::TableFunction::NUMBER, 0, false);
43 add_field("USERNAME", 16);
44 add_field("HOST", NI_MAXHOST);
45 add_field("DB", plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, true);
46 add_field("COMMAND", 16);
47 add_field("TIME", plugin::TableFunction::SIZE, 0, false);
48 add_field("STATE", plugin::TableFunction::STRING, 256, true);
49 add_field("INFO", plugin::TableFunction::STRING, PROCESS_LIST_WIDTH, true);
50 add_field("HAS_GLOBAL_LOCK", plugin::TableFunction::BOOLEAN, 0, false);
51}
52
53ProcesslistTool::Generator::Generator(Field **arg) :
54 plugin::TableFunction::Generator(arg),
55 session_generator(*getSession().user())
56{
57}
58
59bool ProcesslistTool::Generator::populate()
60{
61 while (Session* tmp= session_generator)
62 {
63 std::shared_ptr<session::State> state(tmp->state());
64 identifier::user::ptr tmp_sctx= tmp->user();
65
66 /* ID */
67 push((int64_t) tmp->thread_id);
68
69 /* USER */
70 if (not tmp_sctx->username().empty())
71 push(tmp_sctx->username());
72 else
73 push(_("no user"));
74
75 /* HOST */
76 push(tmp_sctx->address());
77
78 /* DB */
79 util::string::ptr schema(tmp->schema());
80 if (schema and not schema->empty())
81 {
82 push(*schema);
83 }
84 else
85 {
86 push();
87 }
88
89 /* COMMAND */
90 if (tmp->getKilled() == Session::KILL_CONNECTION)
91 {
92 push("Killed");
93 }
94 else
95 {
96 push(getCommandName(tmp->command));
97 }
98
99 /* type::Time */
100 boost::posix_time::time_duration duration_result= getSession().times.start_timer() - getSession().times._start_timer;
101 push(static_cast<uint64_t>(duration_result.is_negative() ? 0 : duration_result.total_seconds()));
102
103 /* STATE */
104 const char *step= tmp->get_proc_info();
105 step ? push(step): push();
106
107 /* INFO */
108 if (state)
109 {
110 size_t length;
111 const char *tmp_ptr= state->query(length);
112 push(tmp_ptr, length);
113 }
114 else
115 {
116 push();
117 }
118
119 /* HAS_GLOBAL_LOCK */
120 bool has_global_lock= tmp->isGlobalReadLock();
121 push(has_global_lock);
122
123 return true;
124 }
125
126 return false;
127}
#define PROCESS_LIST_WIDTH
TODO: Rename this file - func.h is stupid.
STL namespace.