2 This file is part of PerconaFT.
4 Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved.
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.
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.
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/>.
18 ----------------------------------------
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.
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.
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/>.
32 ----------------------------------------
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
38 http://www.apache.org/licenses/LICENSE-2.0
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.
49 #include <stdio.h> // FILE
51 // Performance instrumentation object identifier type
52 typedef unsigned int pfs_key_t
;
54 enum class toku_instr_object_type
{ mutex
, rwlock
, cond
, thread
, file
};
62 TOKU_FILE() : file(nullptr), key(nullptr) {}
71 struct toku_pthread_rwlock_t
;
75 class toku_instr_probe_empty
{
77 explicit toku_instr_probe_empty(UU(const toku_instr_key
&key
)) {}
79 void start_with_source_location(UU(const char *src_file
), UU(int src_line
)) {}
84 #define TOKU_PROBE_START(p) p->start_with_source_location(__FILE__, __LINE__)
85 #define TOKU_PROBE_STOP(p) p->stop
87 extern toku_instr_key toku_uninstrumented
;
89 #ifndef MYSQL_TOKUDB_ENGINE
93 class toku_instr_key
{
95 toku_instr_key(UU(toku_instr_object_type type
), UU(const char *group
),
96 UU(const char *name
)) {}
98 explicit toku_instr_key(UU(pfs_key_t key_id
)) {}
99 // No-instrumentation constructor:
104 typedef toku_instr_probe_empty toku_instr_probe
;
106 enum class toku_instr_file_op
{
123 struct toku_io_instrumentation
{};
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
);
131 inline void toku_instr_register_current_thread() {}
133 inline void toku_instr_delete_current_thread() {}
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
),
143 inline void toku_instr_file_stream_open_end(
144 UU(toku_io_instrumentation
&io_instr
), UU(TOKU_FILE
&file
)) {}
146 inline void toku_instr_file_open_end(UU(toku_io_instrumentation
&io_instr
),
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
),
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
)) {}
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
)) {}
162 inline void toku_instr_file_close_end(UU(toku_io_instrumentation
&io_instr
),
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
),
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
)) {}
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
),
181 inline void toku_instr_file_io_end(UU(toku_io_instrumentation
&io_instr
),
182 UU(unsigned int count
)) {}
186 struct toku_mutex_instrumentation
{};
188 inline PSI_mutex
*toku_instr_mutex_init(UU(const toku_instr_key
&key
),
189 UU(toku_mutex_t
&mutex
)) {
193 inline void toku_instr_mutex_destroy(UU(PSI_mutex
*&mutex_instr
)) {}
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
)) {}
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
)) {}
203 inline void toku_instr_mutex_lock_end(
204 UU(toku_mutex_instrumentation
&mutex_instr
),
205 UU(int pthread_mutex_lock_result
)) {}
207 inline void toku_instr_mutex_unlock(UU(PSI_mutex
*mutex_instr
)) {}
209 struct toku_cond_instrumentation
{};
211 enum class toku_instr_cond_op
{
216 inline PSI_cond
*toku_instr_cond_init(UU(const toku_instr_key
&key
),
217 UU(toku_cond_t
&cond
)) {
221 inline void toku_instr_cond_destroy(UU(PSI_cond
*&cond_instr
)) {}
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
),
228 inline void toku_instr_cond_wait_end(UU(toku_cond_instrumentation
&cond_instr
),
229 UU(int pthread_cond_wait_result
)) {}
231 inline void toku_instr_cond_signal(UU(toku_cond_t
&cond
)) {}
233 inline void toku_instr_cond_broadcast(UU(toku_cond_t
&cond
)) {}
236 // rw locks are not used
237 // rwlock instrumentation
238 struct toku_rwlock_instrumentation
{};
240 inline PSI_rwlock
*toku_instr_rwlock_init(UU(const toku_instr_key
&key
),
241 UU(toku_pthread_rwlock_t
&rwlock
)) {
245 inline void toku_instr_rwlock_destroy(UU(PSI_rwlock
*&rwlock_instr
)) {}
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
),
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
),
259 inline void toku_instr_rwlock_rdlock_wait_end(
260 UU(toku_rwlock_instrumentation
&rwlock_instr
),
261 UU(int pthread_rwlock_wait_result
)) {}
263 inline void toku_instr_rwlock_wrlock_wait_end(
264 UU(toku_rwlock_instrumentation
&rwlock_instr
),
265 UU(int pthread_rwlock_wait_result
)) {}
267 inline void toku_instr_rwlock_unlock(UU(toku_pthread_rwlock_t
&rwlock
)) {}
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
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
;
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