1 /* Copyright (c) 2010, 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, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23 /**
24 @file storage/perfschema/table_esgs_global_by_event_name.cc
25 Table EVENTS_STAGES_SUMMARY_GLOBAL_BY_EVENT_NAME (implementation).
26 */
27
28 #include "my_global.h"
29 #include "my_pthread.h"
30 #include "pfs_instr_class.h"
31 #include "pfs_column_types.h"
32 #include "pfs_column_values.h"
33 #include "table_esgs_global_by_event_name.h"
34 #include "pfs_global.h"
35 #include "pfs_instr.h"
36 #include "pfs_timer.h"
37 #include "pfs_visitor.h"
38
39 THR_LOCK table_esgs_global_by_event_name::m_table_lock;
40
41 static const TABLE_FIELD_TYPE field_types[]=
42 {
43 {
44 { C_STRING_WITH_LEN("EVENT_NAME") },
45 { C_STRING_WITH_LEN("varchar(128)") },
46 { NULL, 0}
47 },
48 {
49 { C_STRING_WITH_LEN("COUNT_STAR") },
50 { C_STRING_WITH_LEN("bigint(20)") },
51 { NULL, 0}
52 },
53 {
54 { C_STRING_WITH_LEN("SUM_TIMER_WAIT") },
55 { C_STRING_WITH_LEN("bigint(20)") },
56 { NULL, 0}
57 },
58 {
59 { C_STRING_WITH_LEN("MIN_TIMER_WAIT") },
60 { C_STRING_WITH_LEN("bigint(20)") },
61 { NULL, 0}
62 },
63 {
64 { C_STRING_WITH_LEN("AVG_TIMER_WAIT") },
65 { C_STRING_WITH_LEN("bigint(20)") },
66 { NULL, 0}
67 },
68 {
69 { C_STRING_WITH_LEN("MAX_TIMER_WAIT") },
70 { C_STRING_WITH_LEN("bigint(20)") },
71 { NULL, 0}
72 }
73 };
74
75 TABLE_FIELD_DEF
76 table_esgs_global_by_event_name::m_field_def=
77 { 6, field_types };
78
79 PFS_engine_table_share
80 table_esgs_global_by_event_name::m_share=
81 {
82 { C_STRING_WITH_LEN("events_stages_summary_global_by_event_name") },
83 &pfs_truncatable_acl,
84 table_esgs_global_by_event_name::create,
85 NULL, /* write_row */
86 table_esgs_global_by_event_name::delete_all_rows,
87 NULL, /* get_row_count */
88 1000, /* records */
89 sizeof(PFS_simple_index),
90 &m_table_lock,
91 &m_field_def,
92 false /* checked */
93 };
94
95 PFS_engine_table*
create(void)96 table_esgs_global_by_event_name::create(void)
97 {
98 return new table_esgs_global_by_event_name();
99 }
100
101 int
delete_all_rows(void)102 table_esgs_global_by_event_name::delete_all_rows(void)
103 {
104 reset_events_stages_by_thread();
105 reset_events_stages_by_account();
106 reset_events_stages_by_user();
107 reset_events_stages_by_host();
108 reset_events_stages_global();
109 return 0;
110 }
111
table_esgs_global_by_event_name()112 table_esgs_global_by_event_name::table_esgs_global_by_event_name()
113 : PFS_engine_table(&m_share, &m_pos),
114 m_row_exists(false), m_pos(1), m_next_pos(1)
115 {}
116
reset_position(void)117 void table_esgs_global_by_event_name::reset_position(void)
118 {
119 m_pos= 1;
120 m_next_pos= 1;
121 }
122
rnd_init(bool scan)123 int table_esgs_global_by_event_name::rnd_init(bool scan)
124 {
125 m_normalizer= time_normalizer::get(stage_timer);
126 return 0;
127 }
128
rnd_next(void)129 int table_esgs_global_by_event_name::rnd_next(void)
130 {
131 PFS_stage_class *stage_class;
132
133 if (global_instr_class_stages_array == NULL)
134 return HA_ERR_END_OF_FILE;
135
136 m_pos.set_at(&m_next_pos);
137
138 stage_class= find_stage_class(m_pos.m_index);
139 if (stage_class)
140 {
141 make_row(stage_class);
142 m_next_pos.set_after(&m_pos);
143 return 0;
144 }
145
146 return HA_ERR_END_OF_FILE;
147 }
148
149 int
rnd_pos(const void * pos)150 table_esgs_global_by_event_name::rnd_pos(const void *pos)
151 {
152 PFS_stage_class *stage_class;
153
154 set_position(pos);
155
156 if (global_instr_class_stages_array == NULL)
157 return HA_ERR_END_OF_FILE;
158
159 stage_class=find_stage_class(m_pos.m_index);
160 if (stage_class)
161 {
162 make_row(stage_class);
163 return 0;
164 }
165
166 return HA_ERR_RECORD_DELETED;
167 }
168
169
170 void table_esgs_global_by_event_name
make_row(PFS_stage_class * klass)171 ::make_row(PFS_stage_class *klass)
172 {
173 m_row.m_event_name.make_row(klass);
174
175 PFS_connection_stage_visitor visitor(klass);
176 PFS_connection_iterator::visit_global(true, /* hosts */
177 false, /* users */
178 true, true, & visitor);
179
180 m_row.m_stat.set(m_normalizer, & visitor.m_stat);
181 m_row_exists= true;
182 }
183
184 int table_esgs_global_by_event_name
read_row_values(TABLE * table,unsigned char *,Field ** fields,bool read_all)185 ::read_row_values(TABLE *table, unsigned char *, Field **fields,
186 bool read_all)
187 {
188 Field *f;
189
190 if (unlikely(! m_row_exists))
191 return HA_ERR_RECORD_DELETED;
192
193 /* Set the null bits */
194 DBUG_ASSERT(table->s->null_bytes == 0);
195
196 for (; (f= *fields) ; fields++)
197 {
198 if (read_all || bitmap_is_set(table->read_set, f->field_index))
199 {
200 switch(f->field_index)
201 {
202 case 0: /* NAME */
203 m_row.m_event_name.set_field(f);
204 break;
205 default: /* 1, ... COUNT/SUM/MIN/AVG/MAX */
206 m_row.m_stat.set_field(f->field_index - 1, f);
207 break;
208 }
209 }
210 }
211
212 return 0;
213 }
214
215