1 /* Copyright (c) 2008, 2021, Oracle and/or its affiliates.
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 Foundation,
21 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
22
23 /**
24 @file storage/perfschema/table_all_instr.cc
25 Abstract tables for all instruments (implementation).
26 */
27
28 #include "my_global.h"
29 #include "my_thread.h"
30 #include "table_all_instr.h"
31 #include "pfs_global.h"
32 #include "pfs_buffer_container.h"
33
34 ha_rows
get_row_count(void)35 table_all_instr::get_row_count(void)
36 {
37 return global_mutex_container.get_row_count()
38 + global_rwlock_container.get_row_count()
39 + global_cond_container.get_row_count()
40 + global_file_container.get_row_count()
41 + global_socket_container.get_row_count() ;
42 }
43
table_all_instr(const PFS_engine_table_share * share)44 table_all_instr::table_all_instr(const PFS_engine_table_share *share)
45 : PFS_engine_table(share, &m_pos),
46 m_pos(), m_next_pos()
47 {}
48
reset_position(void)49 void table_all_instr::reset_position(void)
50 {
51 m_pos.reset();
52 m_next_pos.reset();
53 }
54
rnd_next(void)55 int table_all_instr::rnd_next(void)
56 {
57 PFS_mutex *mutex;
58 PFS_rwlock *rwlock;
59 PFS_cond *cond;
60 PFS_file *file;
61 PFS_socket *socket;
62
63 for (m_pos.set_at(&m_next_pos);
64 m_pos.has_more_view();
65 m_pos.next_view())
66 {
67 switch (m_pos.m_index_1) {
68 case pos_all_instr::VIEW_MUTEX:
69 {
70 PFS_mutex_iterator it= global_mutex_container.iterate(m_pos.m_index_2);
71 mutex= it.scan_next(& m_pos.m_index_2);
72 if (mutex != NULL)
73 {
74 make_mutex_row(mutex);
75 m_next_pos.set_after(&m_pos);
76 return 0;
77 }
78 }
79 break;
80 case pos_all_instr::VIEW_RWLOCK:
81 {
82 PFS_rwlock_iterator it= global_rwlock_container.iterate(m_pos.m_index_2);
83 rwlock= it.scan_next(& m_pos.m_index_2);
84 if (rwlock != NULL)
85 {
86 make_rwlock_row(rwlock);
87 m_next_pos.set_after(&m_pos);
88 return 0;
89 }
90 }
91 break;
92 case pos_all_instr::VIEW_COND:
93 {
94 PFS_cond_iterator it= global_cond_container.iterate(m_pos.m_index_2);
95 cond= it.scan_next(& m_pos.m_index_2);
96 if (cond != NULL)
97 {
98 make_cond_row(cond);
99 m_next_pos.set_after(&m_pos);
100 return 0;
101 }
102 }
103 break;
104 case pos_all_instr::VIEW_FILE:
105 {
106 PFS_file_iterator it= global_file_container.iterate(m_pos.m_index_2);
107 file= it.scan_next(& m_pos.m_index_2);
108 if (file != NULL)
109 {
110 make_file_row(file);
111 m_next_pos.set_after(&m_pos);
112 return 0;
113 }
114 }
115 break;
116 case pos_all_instr::VIEW_SOCKET:
117 {
118 PFS_socket_iterator it= global_socket_container.iterate(m_pos.m_index_2);
119 socket= it.scan_next(& m_pos.m_index_2);
120 if (socket != NULL)
121 {
122 make_socket_row(socket);
123 m_next_pos.set_after(&m_pos);
124 return 0;
125 }
126 }
127 break;
128 }
129 }
130
131 return HA_ERR_END_OF_FILE;
132 }
133
rnd_pos(const void * pos)134 int table_all_instr::rnd_pos(const void *pos)
135 {
136 PFS_mutex *mutex;
137 PFS_rwlock *rwlock;
138 PFS_cond *cond;
139 PFS_file *file;
140 PFS_socket *socket;
141
142 set_position(pos);
143
144 switch (m_pos.m_index_1) {
145 case pos_all_instr::VIEW_MUTEX:
146 mutex= global_mutex_container.get(m_pos.m_index_2);
147 if (mutex != NULL)
148 {
149 make_mutex_row(mutex);
150 return 0;
151 }
152 break;
153 case pos_all_instr::VIEW_RWLOCK:
154 rwlock= global_rwlock_container.get(m_pos.m_index_2);
155 if (rwlock != NULL)
156 {
157 make_rwlock_row(rwlock);
158 return 0;
159 }
160 break;
161 case pos_all_instr::VIEW_COND:
162 cond= global_cond_container.get(m_pos.m_index_2);
163 if (cond != NULL)
164 {
165 make_cond_row(cond);
166 return 0;
167 }
168 break;
169 case pos_all_instr::VIEW_FILE:
170 file= global_file_container.get(m_pos.m_index_2);
171 if (file != NULL)
172 {
173 make_file_row(file);
174 return 0;
175 }
176 break;
177 case pos_all_instr::VIEW_SOCKET:
178 socket= global_socket_container.get(m_pos.m_index_2);
179 if (socket != NULL)
180 {
181 make_socket_row(socket);
182 return 0;
183 }
184 break;
185 }
186
187 return HA_ERR_RECORD_DELETED;
188 }
189