1 | /* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. |
2 | |
3 | This program is free software; you can redistribute it and/or modify |
4 | it under the terms of the GNU General Public License as published by |
5 | the Free Software Foundation; version 2 of the License. |
6 | |
7 | This program is distributed in the hope that it will be useful, |
8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10 | GNU General Public License for more details. |
11 | |
12 | You should have received a copy of the GNU General Public License |
13 | along with this program; if not, write to the Free Software Foundation, |
14 | 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */ |
15 | |
16 | /** |
17 | @file storage/perfschema/table_setup_consumers.cc |
18 | Table SETUP_CONSUMERS (implementation). |
19 | */ |
20 | |
21 | #include "my_global.h" |
22 | #include "my_pthread.h" |
23 | #include "table_setup_consumers.h" |
24 | #include "pfs_instr.h" |
25 | #include "pfs_events_waits.h" |
26 | #include "pfs_digest.h" |
27 | |
28 | #define COUNT_SETUP_CONSUMERS 12 |
29 | static row_setup_consumers all_setup_consumers_data[COUNT_SETUP_CONSUMERS]= |
30 | { |
31 | { |
32 | { C_STRING_WITH_LEN("events_stages_current" ) }, |
33 | &flag_events_stages_current, |
34 | false |
35 | }, |
36 | { |
37 | { C_STRING_WITH_LEN("events_stages_history" ) }, |
38 | &flag_events_stages_history, |
39 | false |
40 | }, |
41 | { |
42 | { C_STRING_WITH_LEN("events_stages_history_long" ) }, |
43 | &flag_events_stages_history_long, |
44 | false |
45 | }, |
46 | { |
47 | { C_STRING_WITH_LEN("events_statements_current" ) }, |
48 | &flag_events_statements_current, |
49 | false |
50 | }, |
51 | { |
52 | { C_STRING_WITH_LEN("events_statements_history" ) }, |
53 | &flag_events_statements_history, |
54 | false |
55 | }, |
56 | { |
57 | { C_STRING_WITH_LEN("events_statements_history_long" ) }, |
58 | &flag_events_statements_history_long, |
59 | false |
60 | }, |
61 | { |
62 | { C_STRING_WITH_LEN("events_waits_current" ) }, |
63 | &flag_events_waits_current, |
64 | false |
65 | }, |
66 | { |
67 | { C_STRING_WITH_LEN("events_waits_history" ) }, |
68 | &flag_events_waits_history, |
69 | false |
70 | }, |
71 | { |
72 | { C_STRING_WITH_LEN("events_waits_history_long" ) }, |
73 | &flag_events_waits_history_long, |
74 | false |
75 | }, |
76 | { |
77 | { C_STRING_WITH_LEN("global_instrumentation" ) }, |
78 | &flag_global_instrumentation, |
79 | true |
80 | }, |
81 | { |
82 | { C_STRING_WITH_LEN("thread_instrumentation" ) }, |
83 | &flag_thread_instrumentation, |
84 | false |
85 | }, |
86 | { |
87 | { C_STRING_WITH_LEN("statements_digest" ) }, |
88 | &flag_statements_digest, |
89 | false |
90 | } |
91 | }; |
92 | |
93 | THR_LOCK table_setup_consumers::m_table_lock; |
94 | |
95 | PFS_engine_table_share |
96 | table_setup_consumers::m_share= |
97 | { |
98 | { C_STRING_WITH_LEN("setup_consumers" ) }, |
99 | &pfs_updatable_acl, |
100 | &table_setup_consumers::create, |
101 | NULL, /* write_row */ |
102 | NULL, /* delete_all_rows */ |
103 | NULL, /* get_row_count */ |
104 | COUNT_SETUP_CONSUMERS, /* records */ |
105 | sizeof(PFS_simple_index), /* ref length */ |
106 | &m_table_lock, |
107 | { C_STRING_WITH_LEN("CREATE TABLE setup_consumers(" |
108 | "NAME VARCHAR(64) not null," |
109 | "ENABLED ENUM ('YES', 'NO') not null)" ) } |
110 | }; |
111 | |
112 | PFS_engine_table* table_setup_consumers::create(void) |
113 | { |
114 | return new table_setup_consumers(); |
115 | } |
116 | |
117 | table_setup_consumers::table_setup_consumers() |
118 | : PFS_engine_table(&m_share, &m_pos), |
119 | m_row(NULL), m_pos(0), m_next_pos(0) |
120 | {} |
121 | |
122 | void table_setup_consumers::reset_position(void) |
123 | { |
124 | m_pos.m_index= 0; |
125 | m_next_pos.m_index= 0; |
126 | } |
127 | |
128 | int table_setup_consumers::rnd_next(void) |
129 | { |
130 | int result; |
131 | |
132 | m_pos.set_at(&m_next_pos); |
133 | |
134 | if (m_pos.m_index < COUNT_SETUP_CONSUMERS) |
135 | { |
136 | m_row= &all_setup_consumers_data[m_pos.m_index]; |
137 | m_next_pos.set_after(&m_pos); |
138 | result= 0; |
139 | } |
140 | else |
141 | { |
142 | m_row= NULL; |
143 | result= HA_ERR_END_OF_FILE; |
144 | } |
145 | |
146 | return result; |
147 | } |
148 | |
149 | int table_setup_consumers::rnd_pos(const void *pos) |
150 | { |
151 | set_position(pos); |
152 | DBUG_ASSERT(m_pos.m_index < COUNT_SETUP_CONSUMERS); |
153 | m_row= &all_setup_consumers_data[m_pos.m_index]; |
154 | return 0; |
155 | } |
156 | |
157 | int table_setup_consumers::read_row_values(TABLE *table, |
158 | unsigned char *, |
159 | Field **fields, |
160 | bool read_all) |
161 | { |
162 | Field *f; |
163 | |
164 | DBUG_ASSERT(m_row); |
165 | |
166 | |
167 | /* Set the null bits */ |
168 | DBUG_ASSERT(table->s->null_bytes == 0); |
169 | |
170 | for (; (f= *fields) ; fields++) |
171 | { |
172 | if (read_all || bitmap_is_set(table->read_set, f->field_index)) |
173 | { |
174 | switch(f->field_index) |
175 | { |
176 | case 0: /* NAME */ |
177 | set_field_varchar_utf8(f, m_row->m_name.str,(uint) m_row->m_name.length); |
178 | break; |
179 | case 1: /* ENABLED */ |
180 | set_field_enum(f, (*m_row->m_enabled_ptr) ? ENUM_YES : ENUM_NO); |
181 | break; |
182 | default: |
183 | DBUG_ASSERT(false); |
184 | } |
185 | } |
186 | } |
187 | |
188 | return 0; |
189 | } |
190 | |
191 | int table_setup_consumers::update_row_values(TABLE *table, |
192 | const unsigned char *, |
193 | const unsigned char *, |
194 | Field **fields) |
195 | { |
196 | Field *f; |
197 | enum_yes_no value; |
198 | |
199 | DBUG_ASSERT(m_row); |
200 | |
201 | for (; (f= *fields) ; fields++) |
202 | { |
203 | if (bitmap_is_set(table->write_set, f->field_index)) |
204 | { |
205 | switch(f->field_index) |
206 | { |
207 | case 0: /* NAME */ |
208 | return HA_ERR_WRONG_COMMAND; |
209 | case 1: /* ENABLED */ |
210 | { |
211 | value= (enum_yes_no) get_field_enum(f); |
212 | *m_row->m_enabled_ptr= (value == ENUM_YES) ? true : false; |
213 | break; |
214 | } |
215 | default: |
216 | DBUG_ASSERT(false); |
217 | } |
218 | } |
219 | } |
220 | |
221 | if (m_row->m_refresh) |
222 | update_instruments_derived_flags(); |
223 | |
224 | return 0; |
225 | } |
226 | |
227 | |
228 | |