1#pragma once
2
3#include <stdio.h> // FILE
4
5// Performance instrumentation object identifier type
6typedef unsigned int pfs_key_t;
7
8enum class toku_instr_object_type { mutex, rwlock, cond, thread, file };
9
10struct PSI_file;
11
12struct TOKU_FILE {
13 /** The real file. */
14 FILE *file;
15 struct PSI_file *key;
16 TOKU_FILE() : file(nullptr), key(nullptr) {}
17};
18
19struct PSI_mutex;
20struct PSI_cond;
21struct PSI_rwlock;
22
23struct toku_mutex_t;
24struct toku_cond_t;
25struct toku_pthread_rwlock_t;
26
27class toku_instr_key;
28
29class toku_instr_probe_empty {
30 public:
31 explicit toku_instr_probe_empty(UU(const toku_instr_key &key)) {}
32
33 void start_with_source_location(UU(const char *src_file),
34 UU(int src_line)) {}
35
36 void stop() {}
37};
38
39#define TOKU_PROBE_START(p) p->start_with_source_location(__FILE__, __LINE__)
40#define TOKU_PROBE_STOP(p) p->stop
41
42extern toku_instr_key toku_uninstrumented;
43
44#ifndef MYSQL_TOKUDB_ENGINE
45
46#include <pthread.h>
47
48class toku_instr_key {
49 public:
50 toku_instr_key(UU(toku_instr_object_type type),
51 UU(const char *group),
52 UU(const char *name)) {}
53
54 explicit toku_instr_key(UU(pfs_key_t key_id)) {}
55
56 ~toku_instr_key() {}
57};
58
59typedef toku_instr_probe_empty toku_instr_probe;
60
61enum class toku_instr_file_op {
62 file_stream_open,
63 file_create,
64 file_open,
65 file_delete,
66 file_rename,
67 file_read,
68 file_write,
69 file_sync,
70 file_stream_close,
71 file_close,
72 file_stat
73};
74
75struct PSI_file {};
76struct PSI_mutex {};
77
78struct toku_io_instrumentation {};
79
80inline int toku_pthread_create(UU(const toku_instr_key &key),
81 pthread_t *thread,
82 const pthread_attr_t *attr,
83 void *(*start_routine)(void *),
84 void *arg) {
85 return pthread_create(thread, attr, start_routine, arg);
86}
87
88inline void toku_instr_register_current_thread() {}
89
90inline void toku_instr_delete_current_thread() {}
91
92// Instrument file creation, opening, closing, and renaming
93inline void toku_instr_file_open_begin(UU(toku_io_instrumentation &io_instr),
94 UU(const toku_instr_key &key),
95 UU(toku_instr_file_op op),
96 UU(const char *name),
97 UU(const char *src_file),
98 UU(int src_line)) {}
99
100inline void toku_instr_file_stream_open_end(
101 UU(toku_io_instrumentation &io_instr),
102 UU(TOKU_FILE &file)) {}
103
104inline void toku_instr_file_open_end(UU(toku_io_instrumentation &io_instr),
105 UU(int fd)) {}
106
107inline void toku_instr_file_name_close_begin(
108 UU(toku_io_instrumentation &io_instr),
109 UU(const toku_instr_key &key),
110 UU(toku_instr_file_op op),
111 UU(const char *name),
112 UU(const char *src_file),
113 UU(int src_line)) {}
114
115inline void toku_instr_file_stream_close_begin(
116 UU(toku_io_instrumentation &io_instr),
117 UU(toku_instr_file_op op),
118 UU(TOKU_FILE &file),
119 UU(const char *src_file),
120 UU(int src_line)) {}
121
122inline void toku_instr_file_fd_close_begin(
123 UU(toku_io_instrumentation &io_instr),
124 UU(toku_instr_file_op op),
125 UU(int fd),
126 UU(const char *src_file),
127 UU(int src_line)) {}
128
129inline void toku_instr_file_close_end(UU(toku_io_instrumentation &io_instr),
130 UU(int result)) {}
131
132inline void toku_instr_file_io_begin(UU(toku_io_instrumentation &io_instr),
133 UU(toku_instr_file_op op),
134 UU(int fd),
135 UU(unsigned int count),
136 UU(const char *src_file),
137 UU(int src_line)) {}
138
139inline void toku_instr_file_name_io_begin(UU(toku_io_instrumentation &io_instr),
140 UU(const toku_instr_key &key),
141 UU(toku_instr_file_op op),
142 UU(const char *name),
143 UU(unsigned int count),
144 UU(const char *src_file),
145 UU(int src_line)) {}
146
147inline void toku_instr_file_stream_io_begin(
148 UU(toku_io_instrumentation &io_instr),
149 UU(toku_instr_file_op op),
150 UU(TOKU_FILE &file),
151 UU(unsigned int count),
152 UU(const char *src_file),
153 UU(int src_line)) {}
154
155inline void toku_instr_file_io_end(UU(toku_io_instrumentation &io_instr),
156 UU(unsigned int count)) {}
157
158struct toku_mutex_t;
159
160struct toku_mutex_instrumentation {};
161
162inline PSI_mutex *toku_instr_mutex_init(UU(const toku_instr_key &key),
163 UU(toku_mutex_t &mutex)) {
164 return nullptr;
165}
166
167inline void toku_instr_mutex_destroy(UU(PSI_mutex *&mutex_instr)) {}
168
169inline void toku_instr_mutex_lock_start(
170 UU(toku_mutex_instrumentation &mutex_instr),
171 UU(toku_mutex_t &mutex),
172 UU(const char *src_file),
173 UU(int src_line)) {}
174
175inline void toku_instr_mutex_trylock_start(
176 UU(toku_mutex_instrumentation &mutex_instr),
177 UU(toku_mutex_t &mutex),
178 UU(const char *src_file),
179 UU(int src_line)) {}
180
181inline void toku_instr_mutex_lock_end(
182 UU(toku_mutex_instrumentation &mutex_instr),
183 UU(int pthread_mutex_lock_result)) {}
184
185inline void toku_instr_mutex_unlock(UU(PSI_mutex *mutex_instr)) {}
186
187struct toku_cond_instrumentation {};
188
189enum class toku_instr_cond_op {
190 cond_wait,
191 cond_timedwait,
192};
193
194inline PSI_cond *toku_instr_cond_init(UU(const toku_instr_key &key),
195 UU(toku_cond_t &cond)) {
196 return nullptr;
197}
198
199inline void toku_instr_cond_destroy(UU(PSI_cond *&cond_instr)) {}
200
201inline void toku_instr_cond_wait_start(
202 UU(toku_cond_instrumentation &cond_instr),
203 UU(toku_instr_cond_op op),
204 UU(toku_cond_t &cond),
205 UU(toku_mutex_t &mutex),
206 UU(const char *src_file),
207 UU(int src_line)) {}
208
209inline void toku_instr_cond_wait_end(UU(toku_cond_instrumentation &cond_instr),
210 UU(int pthread_cond_wait_result)) {}
211
212inline void toku_instr_cond_signal(UU(toku_cond_t &cond)) {}
213
214inline void toku_instr_cond_broadcast(UU(toku_cond_t &cond)) {}
215
216// rwlock instrumentation
217struct toku_rwlock_instrumentation {};
218
219inline PSI_rwlock *toku_instr_rwlock_init(UU(const toku_instr_key &key),
220 UU(toku_pthread_rwlock_t &rwlock)) {
221 return nullptr;
222}
223
224inline void toku_instr_rwlock_destroy(UU(PSI_rwlock *&rwlock_instr)) {}
225
226inline void toku_instr_rwlock_rdlock_wait_start(
227 UU(toku_rwlock_instrumentation &rwlock_instr),
228 UU(toku_pthread_rwlock_t &rwlock),
229 UU(const char *src_file),
230 UU(int src_line)) {}
231
232inline void toku_instr_rwlock_wrlock_wait_start(
233 UU(toku_rwlock_instrumentation &rwlock_instr),
234 UU(toku_pthread_rwlock_t &rwlock),
235 UU(const char *src_file),
236 UU(int src_line)) {}
237
238inline void toku_instr_rwlock_rdlock_wait_end(
239 UU(toku_rwlock_instrumentation &rwlock_instr),
240 UU(int pthread_rwlock_wait_result)) {}
241
242inline void toku_instr_rwlock_wrlock_wait_end(
243 UU(toku_rwlock_instrumentation &rwlock_instr),
244 UU(int pthread_rwlock_wait_result)) {}
245
246inline void toku_instr_rwlock_unlock(UU(toku_pthread_rwlock_t &rwlock)) {}
247
248#else // MYSQL_TOKUDB_ENGINE
249// There can be not only mysql but also mongodb or any other PFS stuff
250#include <toku_instr_mysql.h>
251#endif // MYSQL_TOKUDB_ENGINE
252
253extern toku_instr_key toku_uninstrumented;
254
255extern toku_instr_probe *toku_instr_probe_1;
256
257// threads
258extern toku_instr_key *extractor_thread_key;
259extern toku_instr_key *fractal_thread_key;
260extern toku_instr_key *io_thread_key;
261extern toku_instr_key *eviction_thread_key;
262extern toku_instr_key *kibbutz_thread_key;
263extern toku_instr_key *minicron_thread_key;
264extern toku_instr_key *tp_internal_thread_key;
265
266// Files
267extern toku_instr_key *tokudb_file_data_key;
268extern toku_instr_key *tokudb_file_load_key;
269extern toku_instr_key *tokudb_file_tmp_key;
270extern toku_instr_key *tokudb_file_log_key;
271
272// Mutexes
273extern toku_instr_key *kibbutz_mutex_key;
274extern toku_instr_key *minicron_p_mutex_key;
275extern toku_instr_key *queue_result_mutex_key;
276extern toku_instr_key *tpool_lock_mutex_key;
277extern toku_instr_key *workset_lock_mutex_key;
278extern toku_instr_key *bjm_jobs_lock_mutex_key;
279extern toku_instr_key *log_internal_lock_mutex_key;
280extern toku_instr_key *cachetable_ev_thread_lock_mutex_key;
281extern toku_instr_key *cachetable_disk_nb_mutex_key;
282extern toku_instr_key *cachetable_m_mutex_key;
283extern toku_instr_key *safe_file_size_lock_mutex_key;
284extern toku_instr_key *checkpoint_safe_mutex_key;
285extern toku_instr_key *ft_ref_lock_mutex_key;
286extern toku_instr_key *loader_error_mutex_key;
287extern toku_instr_key *bfs_mutex_key;
288extern toku_instr_key *loader_bl_mutex_key;
289extern toku_instr_key *loader_fi_lock_mutex_key;
290extern toku_instr_key *loader_out_mutex_key;
291extern toku_instr_key *result_output_condition_lock_mutex_key;
292extern toku_instr_key *block_table_mutex_key;
293extern toku_instr_key *rollback_log_node_cache_mutex_key;
294extern toku_instr_key *txn_lock_mutex_key;
295extern toku_instr_key *txn_state_lock_mutex_key;
296extern toku_instr_key *txn_child_manager_mutex_key;
297extern toku_instr_key *txn_manager_lock_mutex_key;
298extern toku_instr_key *treenode_mutex_key;
299extern toku_instr_key *manager_mutex_key;
300extern toku_instr_key *manager_escalation_mutex_key;
301extern toku_instr_key *manager_escalator_mutex_key;
302extern toku_instr_key *db_txn_struct_i_txn_mutex_key;
303extern toku_instr_key *indexer_i_indexer_lock_mutex_key;
304extern toku_instr_key *indexer_i_indexer_estimate_lock_mutex_key;
305extern toku_instr_key *locktree_request_info_mutex_key;
306extern toku_instr_key *locktree_request_info_retry_mutex_key;
307
308// condition vars
309extern toku_instr_key *result_state_cond_key;
310extern toku_instr_key *bjm_jobs_wait_key;
311extern toku_instr_key *cachetable_p_refcount_wait_key;
312extern toku_instr_key *cachetable_m_flow_control_cond_key;
313extern toku_instr_key *cachetable_m_ev_thread_cond_key;
314extern toku_instr_key *bfs_cond_key;
315extern toku_instr_key *result_output_condition_key;
316extern toku_instr_key *manager_m_escalator_done_key;
317extern toku_instr_key *lock_request_m_wait_cond_key;
318extern toku_instr_key *queue_result_cond_key;
319extern toku_instr_key *ws_worker_wait_key;
320extern toku_instr_key *rwlock_wait_read_key;
321extern toku_instr_key *rwlock_wait_write_key;
322extern toku_instr_key *rwlock_cond_key;
323extern toku_instr_key *tp_thread_wait_key;
324extern toku_instr_key *tp_pool_wait_free_key;
325extern toku_instr_key *frwlock_m_wait_read_key;
326extern toku_instr_key *kibbutz_k_cond_key;
327extern toku_instr_key *minicron_p_condvar_key;
328extern toku_instr_key *locktree_request_info_retry_cv_key;
329
330// rwlocks
331extern toku_instr_key *multi_operation_lock_key;
332extern toku_instr_key *low_priority_multi_operation_lock_key;
333extern toku_instr_key *cachetable_m_list_lock_key;
334extern toku_instr_key *cachetable_m_pending_lock_expensive_key;
335extern toku_instr_key *cachetable_m_pending_lock_cheap_key;
336extern toku_instr_key *cachetable_m_lock_key;
337extern toku_instr_key *result_i_open_dbs_rwlock_key;
338extern toku_instr_key *checkpoint_safe_rwlock_key;
339extern toku_instr_key *cachetable_value_key;
340extern toku_instr_key *safe_file_size_lock_rwlock_key;
341extern toku_instr_key *cachetable_disk_nb_rwlock_key;
342