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 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
14 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15
16/**
17 @file storage/perfschema/table_esgs_global_by_event_name.cc
18 Table EVENTS_STAGES_SUMMARY_GLOBAL_BY_EVENT_NAME (implementation).
19*/
20
21#include "my_global.h"
22#include "my_pthread.h"
23#include "pfs_instr_class.h"
24#include "pfs_column_types.h"
25#include "pfs_column_values.h"
26#include "table_esgs_global_by_event_name.h"
27#include "pfs_global.h"
28#include "pfs_instr.h"
29#include "pfs_timer.h"
30#include "pfs_visitor.h"
31
32THR_LOCK table_esgs_global_by_event_name::m_table_lock;
33
34PFS_engine_table_share
35table_esgs_global_by_event_name::m_share=
36{
37 { C_STRING_WITH_LEN("events_stages_summary_global_by_event_name") },
38 &pfs_truncatable_acl,
39 table_esgs_global_by_event_name::create,
40 NULL, /* write_row */
41 table_esgs_global_by_event_name::delete_all_rows,
42 NULL, /* get_row_count */
43 1000, /* records */
44 sizeof(PFS_simple_index),
45 &m_table_lock,
46 { C_STRING_WITH_LEN("CREATE TABLE events_stages_summary_global_by_event_name("
47 "EVENT_NAME VARCHAR(128) not null,"
48 "COUNT_STAR BIGINT unsigned not null,"
49 "SUM_TIMER_WAIT BIGINT unsigned not null,"
50 "MIN_TIMER_WAIT BIGINT unsigned not null,"
51 "AVG_TIMER_WAIT BIGINT unsigned not null,"
52 "MAX_TIMER_WAIT BIGINT unsigned not null)") }
53};
54
55PFS_engine_table*
56table_esgs_global_by_event_name::create(void)
57{
58 return new table_esgs_global_by_event_name();
59}
60
61int
62table_esgs_global_by_event_name::delete_all_rows(void)
63{
64 reset_events_stages_by_thread();
65 reset_events_stages_by_account();
66 reset_events_stages_by_user();
67 reset_events_stages_by_host();
68 reset_events_stages_global();
69 return 0;
70}
71
72table_esgs_global_by_event_name::table_esgs_global_by_event_name()
73 : PFS_engine_table(&m_share, &m_pos),
74 m_row_exists(false), m_pos(1), m_next_pos(1)
75{}
76
77void table_esgs_global_by_event_name::reset_position(void)
78{
79 m_pos= 1;
80 m_next_pos= 1;
81}
82
83int table_esgs_global_by_event_name::rnd_init(bool scan)
84{
85 m_normalizer= time_normalizer::get(stage_timer);
86 return 0;
87}
88
89int table_esgs_global_by_event_name::rnd_next(void)
90{
91 PFS_stage_class *stage_class;
92
93 if (global_instr_class_stages_array == NULL)
94 return HA_ERR_END_OF_FILE;
95
96 m_pos.set_at(&m_next_pos);
97
98 stage_class= find_stage_class(m_pos.m_index);
99 if (stage_class)
100 {
101 make_row(stage_class);
102 m_next_pos.set_after(&m_pos);
103 return 0;
104 }
105
106 return HA_ERR_END_OF_FILE;
107}
108
109int
110table_esgs_global_by_event_name::rnd_pos(const void *pos)
111{
112 PFS_stage_class *stage_class;
113
114 set_position(pos);
115
116 if (global_instr_class_stages_array == NULL)
117 return HA_ERR_END_OF_FILE;
118
119 stage_class=find_stage_class(m_pos.m_index);
120 if (stage_class)
121 {
122 make_row(stage_class);
123 return 0;
124 }
125
126 return HA_ERR_RECORD_DELETED;
127}
128
129
130void table_esgs_global_by_event_name
131::make_row(PFS_stage_class *klass)
132{
133 m_row.m_event_name.make_row(klass);
134
135 PFS_connection_stage_visitor visitor(klass);
136 PFS_connection_iterator::visit_global(true, /* hosts */
137 false, /* users */
138 true, true, & visitor);
139
140 m_row.m_stat.set(m_normalizer, & visitor.m_stat);
141 m_row_exists= true;
142}
143
144int table_esgs_global_by_event_name
145::read_row_values(TABLE *table, unsigned char *, Field **fields,
146 bool read_all)
147{
148 Field *f;
149
150 if (unlikely(! m_row_exists))
151 return HA_ERR_RECORD_DELETED;
152
153 /* Set the null bits */
154 DBUG_ASSERT(table->s->null_bytes == 0);
155
156 for (; (f= *fields) ; fields++)
157 {
158 if (read_all || bitmap_is_set(table->read_set, f->field_index))
159 {
160 switch(f->field_index)
161 {
162 case 0: /* NAME */
163 m_row.m_event_name.set_field(f);
164 break;
165 default: /* 1, ... COUNT/SUM/MIN/AVG/MAX */
166 m_row.m_stat.set_field(f->field_index - 1, f);
167 break;
168 }
169 }
170 }
171
172 return 0;
173}
174
175