]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | /*====== |
2 | This file is part of PerconaFT. | |
3 | ||
4 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. | |
5 | ||
6 | PerconaFT is free software: you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License, version 2, | |
8 | as published by the Free Software Foundation. | |
9 | ||
10 | PerconaFT is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
16 | along with PerconaFT. If not, see <http://www.gnu.org/licenses/>. | |
17 | ||
18 | ---------------------------------------- | |
19 | ||
20 | PerconaFT is free software: you can redistribute it and/or modify | |
21 | it under the terms of the GNU Affero General Public License, version 3, | |
22 | as published by the Free Software Foundation. | |
23 | ||
24 | PerconaFT is distributed in the hope that it will be useful, | |
25 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
27 | GNU Affero General Public License for more details. | |
28 | ||
29 | You should have received a copy of the GNU Affero General Public License | |
30 | along with PerconaFT. If not, see <http://www.gnu.org/licenses/>. | |
31 | ||
32 | ---------------------------------------- | |
33 | ||
34 | Licensed under the Apache License, Version 2.0 (the "License"); | |
35 | you may not use this file except in compliance with the License. | |
36 | You may obtain a copy of the License at | |
37 | ||
38 | http://www.apache.org/licenses/LICENSE-2.0 | |
39 | ||
40 | Unless required by applicable law or agreed to in writing, software | |
41 | distributed under the License is distributed on an "AS IS" BASIS, | |
42 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
43 | See the License for the specific language governing permissions and | |
44 | limitations under the License. | |
45 | ======= */ | |
46 | ||
47 | #pragma once | |
48 | ||
49 | #include <stdio.h> // FILE | |
50 | ||
51 | // Performance instrumentation object identifier type | |
52 | typedef unsigned int pfs_key_t; | |
53 | ||
54 | enum class toku_instr_object_type { mutex, rwlock, cond, thread, file }; | |
55 | ||
56 | struct PSI_file; | |
57 | ||
58 | struct TOKU_FILE { | |
59 | /** The real file. */ | |
60 | FILE *file; | |
61 | struct PSI_file *key; | |
62 | TOKU_FILE() : file(nullptr), key(nullptr) {} | |
63 | }; | |
64 | ||
65 | struct PSI_mutex; | |
66 | struct PSI_cond; | |
67 | struct PSI_rwlock; | |
68 | ||
69 | struct toku_mutex_t; | |
70 | struct toku_cond_t; | |
71 | struct toku_pthread_rwlock_t; | |
72 | ||
73 | class toku_instr_key; | |
74 | ||
75 | class toku_instr_probe_empty { | |
76 | public: | |
77 | explicit toku_instr_probe_empty(UU(const toku_instr_key &key)) {} | |
78 | ||
79 | void start_with_source_location(UU(const char *src_file), UU(int src_line)) {} | |
80 | ||
81 | void stop() {} | |
82 | }; | |
83 | ||
84 | #define TOKU_PROBE_START(p) p->start_with_source_location(__FILE__, __LINE__) | |
85 | #define TOKU_PROBE_STOP(p) p->stop | |
86 | ||
87 | extern toku_instr_key toku_uninstrumented; | |
88 | ||
89 | #ifndef MYSQL_TOKUDB_ENGINE | |
90 | ||
91 | #include <pthread.h> | |
92 | ||
93 | class toku_instr_key { | |
94 | public: | |
95 | toku_instr_key(UU(toku_instr_object_type type), UU(const char *group), | |
96 | UU(const char *name)) {} | |
97 | ||
98 | explicit toku_instr_key(UU(pfs_key_t key_id)) {} | |
99 | // No-instrumentation constructor: | |
100 | toku_instr_key() {} | |
101 | ~toku_instr_key() {} | |
102 | }; | |
103 | ||
104 | typedef toku_instr_probe_empty toku_instr_probe; | |
105 | ||
106 | enum class toku_instr_file_op { | |
107 | file_stream_open, | |
108 | file_create, | |
109 | file_open, | |
110 | file_delete, | |
111 | file_rename, | |
112 | file_read, | |
113 | file_write, | |
114 | file_sync, | |
115 | file_stream_close, | |
116 | file_close, | |
117 | file_stat | |
118 | }; | |
119 | ||
120 | struct PSI_file {}; | |
121 | struct PSI_mutex {}; | |
122 | ||
123 | struct toku_io_instrumentation {}; | |
124 | ||
125 | inline int toku_pthread_create(UU(const toku_instr_key &key), pthread_t *thread, | |
126 | const pthread_attr_t *attr, | |
127 | void *(*start_routine)(void *), void *arg) { | |
128 | return pthread_create(thread, attr, start_routine, arg); | |
129 | } | |
130 | ||
131 | inline void toku_instr_register_current_thread() {} | |
132 | ||
133 | inline void toku_instr_delete_current_thread() {} | |
134 | ||
135 | // Instrument file creation, opening, closing, and renaming | |
136 | inline void toku_instr_file_open_begin(UU(toku_io_instrumentation &io_instr), | |
137 | UU(const toku_instr_key &key), | |
138 | UU(toku_instr_file_op op), | |
139 | UU(const char *name), | |
140 | UU(const char *src_file), | |
141 | UU(int src_line)) {} | |
142 | ||
143 | inline void toku_instr_file_stream_open_end( | |
144 | UU(toku_io_instrumentation &io_instr), UU(TOKU_FILE &file)) {} | |
145 | ||
146 | inline void toku_instr_file_open_end(UU(toku_io_instrumentation &io_instr), | |
147 | UU(int fd)) {} | |
148 | ||
149 | inline void toku_instr_file_name_close_begin( | |
150 | UU(toku_io_instrumentation &io_instr), UU(const toku_instr_key &key), | |
151 | UU(toku_instr_file_op op), UU(const char *name), UU(const char *src_file), | |
152 | UU(int src_line)) {} | |
153 | ||
154 | inline void toku_instr_file_stream_close_begin( | |
155 | UU(toku_io_instrumentation &io_instr), UU(toku_instr_file_op op), | |
156 | UU(TOKU_FILE &file), UU(const char *src_file), UU(int src_line)) {} | |
157 | ||
158 | inline void toku_instr_file_fd_close_begin( | |
159 | UU(toku_io_instrumentation &io_instr), UU(toku_instr_file_op op), | |
160 | UU(int fd), UU(const char *src_file), UU(int src_line)) {} | |
161 | ||
162 | inline void toku_instr_file_close_end(UU(toku_io_instrumentation &io_instr), | |
163 | UU(int result)) {} | |
164 | ||
165 | inline void toku_instr_file_io_begin(UU(toku_io_instrumentation &io_instr), | |
166 | UU(toku_instr_file_op op), UU(int fd), | |
167 | UU(unsigned int count), | |
168 | UU(const char *src_file), | |
169 | UU(int src_line)) {} | |
170 | ||
171 | inline void toku_instr_file_name_io_begin( | |
172 | UU(toku_io_instrumentation &io_instr), UU(const toku_instr_key &key), | |
173 | UU(toku_instr_file_op op), UU(const char *name), UU(unsigned int count), | |
174 | UU(const char *src_file), UU(int src_line)) {} | |
175 | ||
176 | inline void toku_instr_file_stream_io_begin( | |
177 | UU(toku_io_instrumentation &io_instr), UU(toku_instr_file_op op), | |
178 | UU(TOKU_FILE &file), UU(unsigned int count), UU(const char *src_file), | |
179 | UU(int src_line)) {} | |
180 | ||
181 | inline void toku_instr_file_io_end(UU(toku_io_instrumentation &io_instr), | |
182 | UU(unsigned int count)) {} | |
183 | ||
184 | struct toku_mutex_t; | |
185 | ||
186 | struct toku_mutex_instrumentation {}; | |
187 | ||
188 | inline PSI_mutex *toku_instr_mutex_init(UU(const toku_instr_key &key), | |
189 | UU(toku_mutex_t &mutex)) { | |
190 | return nullptr; | |
191 | } | |
192 | ||
193 | inline void toku_instr_mutex_destroy(UU(PSI_mutex *&mutex_instr)) {} | |
194 | ||
195 | inline void toku_instr_mutex_lock_start( | |
196 | UU(toku_mutex_instrumentation &mutex_instr), UU(toku_mutex_t &mutex), | |
197 | UU(const char *src_file), UU(int src_line)) {} | |
198 | ||
199 | inline void toku_instr_mutex_trylock_start( | |
200 | UU(toku_mutex_instrumentation &mutex_instr), UU(toku_mutex_t &mutex), | |
201 | UU(const char *src_file), UU(int src_line)) {} | |
202 | ||
203 | inline void toku_instr_mutex_lock_end( | |
204 | UU(toku_mutex_instrumentation &mutex_instr), | |
205 | UU(int pthread_mutex_lock_result)) {} | |
206 | ||
207 | inline void toku_instr_mutex_unlock(UU(PSI_mutex *mutex_instr)) {} | |
208 | ||
209 | struct toku_cond_instrumentation {}; | |
210 | ||
211 | enum class toku_instr_cond_op { | |
212 | cond_wait, | |
213 | cond_timedwait, | |
214 | }; | |
215 | ||
216 | inline PSI_cond *toku_instr_cond_init(UU(const toku_instr_key &key), | |
217 | UU(toku_cond_t &cond)) { | |
218 | return nullptr; | |
219 | } | |
220 | ||
221 | inline void toku_instr_cond_destroy(UU(PSI_cond *&cond_instr)) {} | |
222 | ||
223 | inline void toku_instr_cond_wait_start( | |
224 | UU(toku_cond_instrumentation &cond_instr), UU(toku_instr_cond_op op), | |
225 | UU(toku_cond_t &cond), UU(toku_mutex_t &mutex), UU(const char *src_file), | |
226 | UU(int src_line)) {} | |
227 | ||
228 | inline void toku_instr_cond_wait_end(UU(toku_cond_instrumentation &cond_instr), | |
229 | UU(int pthread_cond_wait_result)) {} | |
230 | ||
231 | inline void toku_instr_cond_signal(UU(toku_cond_t &cond)) {} | |
232 | ||
233 | inline void toku_instr_cond_broadcast(UU(toku_cond_t &cond)) {} | |
234 | ||
235 | #if 0 | |
236 | // rw locks are not used | |
237 | // rwlock instrumentation | |
238 | struct toku_rwlock_instrumentation {}; | |
239 | ||
240 | inline PSI_rwlock *toku_instr_rwlock_init(UU(const toku_instr_key &key), | |
241 | UU(toku_pthread_rwlock_t &rwlock)) { | |
242 | return nullptr; | |
243 | } | |
244 | ||
245 | inline void toku_instr_rwlock_destroy(UU(PSI_rwlock *&rwlock_instr)) {} | |
246 | ||
247 | inline void toku_instr_rwlock_rdlock_wait_start( | |
248 | UU(toku_rwlock_instrumentation &rwlock_instr), | |
249 | UU(toku_pthread_rwlock_t &rwlock), | |
250 | UU(const char *src_file), | |
251 | UU(int src_line)) {} | |
252 | ||
253 | inline void toku_instr_rwlock_wrlock_wait_start( | |
254 | UU(toku_rwlock_instrumentation &rwlock_instr), | |
255 | UU(toku_pthread_rwlock_t &rwlock), | |
256 | UU(const char *src_file), | |
257 | UU(int src_line)) {} | |
258 | ||
259 | inline void toku_instr_rwlock_rdlock_wait_end( | |
260 | UU(toku_rwlock_instrumentation &rwlock_instr), | |
261 | UU(int pthread_rwlock_wait_result)) {} | |
262 | ||
263 | inline void toku_instr_rwlock_wrlock_wait_end( | |
264 | UU(toku_rwlock_instrumentation &rwlock_instr), | |
265 | UU(int pthread_rwlock_wait_result)) {} | |
266 | ||
267 | inline void toku_instr_rwlock_unlock(UU(toku_pthread_rwlock_t &rwlock)) {} | |
268 | #endif | |
269 | ||
270 | #else // MYSQL_TOKUDB_ENGINE | |
271 | // There can be not only mysql but also mongodb or any other PFS stuff | |
272 | #include <toku_instr_mysql.h> | |
273 | #endif // MYSQL_TOKUDB_ENGINE | |
274 | ||
275 | // Mutexes | |
276 | extern toku_instr_key manager_escalation_mutex_key; | |
277 | extern toku_instr_key manager_escalator_mutex_key; | |
278 | extern toku_instr_key manager_mutex_key; | |
279 | extern toku_instr_key treenode_mutex_key; | |
280 | extern toku_instr_key locktree_request_info_mutex_key; | |
281 | extern toku_instr_key locktree_request_info_retry_mutex_key; | |
282 | ||
283 | // condition vars | |
284 | extern toku_instr_key lock_request_m_wait_cond_key; | |
285 | extern toku_instr_key locktree_request_info_retry_cv_key; | |
286 | extern toku_instr_key manager_m_escalator_done_key; // unused |