1273.13.1
by Brian Aker
First pass through data dictionary. |
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
|
|
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 |
||
1273.14.5
by Monty Taylor
Merged trunk. |
21 |
#include "config.h" |
22 |
||
1273.13.55
by Brian Aker
Naming fixes. |
23 |
#include "plugin/session_dictionary/dictionary.h" |
1273.13.32
by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names |
24 |
|
25 |
#include <netdb.h> |
|
26 |
||
27 |
#include "drizzled/pthread_globals.h" |
|
28 |
#include "drizzled/session.h" |
|
29 |
#include "drizzled/session_list.h" |
|
1273.13.1
by Brian Aker
First pass through data dictionary. |
30 |
#include "drizzled/plugin/client.h" |
31 |
#include "drizzled/internal/my_sys.h" |
|
32 |
||
1273.13.51
by Brian Aker
Fix plugin definitions. |
33 |
#include <set> |
34 |
||
1273.13.1
by Brian Aker
First pass through data dictionary. |
35 |
using namespace std; |
36 |
using namespace drizzled; |
|
37 |
||
1273.13.7
by Brian Aker
Updates to the classes (first pass). |
38 |
ProcesslistTool::ProcesslistTool() : |
1273.13.32
by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names |
39 |
plugin::TableFunction("DATA_DICTIONARY", "PROCESSLIST") |
1273.13.1
by Brian Aker
First pass through data dictionary. |
40 |
{
|
1273.13.32
by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names |
41 |
add_field("ID", plugin::TableFunction::NUMBER); |
1273.13.19
by Brian Aker
Updated for longer hostname (aka... follow what the machine would actually |
42 |
add_field("USER", 16); |
43 |
add_field("HOST", NI_MAXHOST); |
|
44 |
add_field("DB"); |
|
45 |
add_field("COMMAND", 16); |
|
1273.13.32
by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names |
46 |
add_field("TIME", plugin::TableFunction::NUMBER); |
1273.13.35
by Brian Aker
Remove processlist from old I_S. |
47 |
add_field("STATE"); |
1273.13.19
by Brian Aker
Updated for longer hostname (aka... follow what the machine would actually |
48 |
add_field("INFO", PROCESS_LIST_WIDTH); |
1273.13.1
by Brian Aker
First pass through data dictionary. |
49 |
}
|
50 |
||
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
51 |
ProcesslistTool::Generator::Generator(Field **arg) : |
1273.13.32
by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names |
52 |
plugin::TableFunction::Generator(arg) |
1273.13.1
by Brian Aker
First pass through data dictionary. |
53 |
{
|
54 |
now= time(NULL); |
|
55 |
||
56 |
pthread_mutex_lock(&LOCK_thread_count); |
|
57 |
it= getSessionList().begin(); |
|
58 |
}
|
|
59 |
||
60 |
ProcesslistTool::Generator::~Generator() |
|
61 |
{
|
|
62 |
pthread_mutex_unlock(&LOCK_thread_count); |
|
63 |
}
|
|
64 |
||
1273.13.21
by Brian Aker
Fix interface (we no longer need Fields passed around). |
65 |
bool ProcesslistTool::Generator::populate() |
1273.13.1
by Brian Aker
First pass through data dictionary. |
66 |
{
|
67 |
const char *val; |
|
68 |
Session* tmp; |
|
69 |
Security_context *tmp_sctx; |
|
70 |
||
71 |
if (it == getSessionList().end()) |
|
72 |
return false; |
|
73 |
||
74 |
tmp= *it; |
|
75 |
tmp_sctx= &tmp->security_ctx; |
|
76 |
||
77 |
/* ID */
|
|
1273.13.21
by Brian Aker
Fix interface (we no longer need Fields passed around). |
78 |
push((int64_t) tmp->thread_id); |
1273.13.1
by Brian Aker
First pass through data dictionary. |
79 |
|
80 |
||
81 |
/* USER */
|
|
1273.13.45
by Brian Aker
Update for test split. |
82 |
if (tmp_sctx->user.length()) |
83 |
push(tmp_sctx->user); |
|
84 |
else
|
|
85 |
push("unauthenticated user"); |
|
1273.13.1
by Brian Aker
First pass through data dictionary. |
86 |
|
87 |
/* HOST */
|
|
1273.13.45
by Brian Aker
Update for test split. |
88 |
push(tmp_sctx->ip); |
1273.13.1
by Brian Aker
First pass through data dictionary. |
89 |
|
90 |
/* DB */
|
|
91 |
if (! tmp->db.empty()) |
|
92 |
{
|
|
1273.13.45
by Brian Aker
Update for test split. |
93 |
push(tmp->db); |
1273.13.1
by Brian Aker
First pass through data dictionary. |
94 |
}
|
95 |
else
|
|
96 |
{
|
|
1273.13.45
by Brian Aker
Update for test split. |
97 |
push(); |
1273.13.1
by Brian Aker
First pass through data dictionary. |
98 |
}
|
99 |
||
100 |
/* COMMAND */
|
|
1273.13.19
by Brian Aker
Updated for longer hostname (aka... follow what the machine would actually |
101 |
if ((val= const_cast<char *>(tmp->killed == Session::KILL_CONNECTION ? "Killed" : 0))) |
102 |
{
|
|
103 |
push(val); |
|
104 |
}
|
|
1273.13.1
by Brian Aker
First pass through data dictionary. |
105 |
else
|
1273.13.19
by Brian Aker
Updated for longer hostname (aka... follow what the machine would actually |
106 |
{
|
107 |
push(command_name[tmp->command].str, command_name[tmp->command].length); |
|
108 |
}
|
|
1273.13.1
by Brian Aker
First pass through data dictionary. |
109 |
|
110 |
/* DRIZZLE_TIME */
|
|
1273.13.19
by Brian Aker
Updated for longer hostname (aka... follow what the machine would actually |
111 |
push((uint32_t)(tmp->start_time ? now - tmp->start_time : 0)); |
1273.13.1
by Brian Aker
First pass through data dictionary. |
112 |
|
113 |
/* STATE */
|
|
114 |
val= (char*) (tmp->client->isWriting() ? |
|
115 |
"Writing to net" : |
|
116 |
tmp->client->isReading() ? |
|
117 |
(tmp->command == COM_SLEEP ? |
|
118 |
NULL : "Reading from net") : |
|
119 |
tmp->get_proc_info() ? tmp->get_proc_info() : |
|
120 |
tmp->mysys_var && |
|
121 |
tmp->mysys_var->current_cond ? |
|
122 |
"Waiting on cond" : NULL); |
|
1273.13.45
by Brian Aker
Update for test split. |
123 |
val ? push(val) : push(); |
1273.13.1
by Brian Aker
First pass through data dictionary. |
124 |
|
125 |
/* INFO */
|
|
1273.13.19
by Brian Aker
Updated for longer hostname (aka... follow what the machine would actually |
126 |
size_t length= strlen(tmp->process_list_info); |
1273.13.45
by Brian Aker
Update for test split. |
127 |
length ? push(tmp->process_list_info, length) : push(); |
1273.13.1
by Brian Aker
First pass through data dictionary. |
128 |
|
129 |
it++; |
|
130 |
||
131 |
return true; |
|
132 |
}
|