| 1 | #pragma once | 
| 2 |  | 
| 3 | #include <stdio.h>  // FILE | 
| 4 |  | 
| 5 | // Performance instrumentation object identifier type | 
| 6 | typedef unsigned int pfs_key_t; | 
| 7 |  | 
| 8 | enum class toku_instr_object_type { mutex, rwlock, cond, thread, file }; | 
| 9 |  | 
| 10 | struct PSI_file; | 
| 11 |  | 
| 12 | struct TOKU_FILE { | 
| 13 |     /** The real file. */ | 
| 14 |     FILE *file; | 
| 15 |     struct PSI_file *key; | 
| 16 |     TOKU_FILE() : file(nullptr), key(nullptr) {} | 
| 17 | }; | 
| 18 |  | 
| 19 | struct PSI_mutex; | 
| 20 | struct PSI_cond; | 
| 21 | struct PSI_rwlock; | 
| 22 |  | 
| 23 | struct toku_mutex_t; | 
| 24 | struct toku_cond_t; | 
| 25 | struct toku_pthread_rwlock_t; | 
| 26 |  | 
| 27 | class toku_instr_key; | 
| 28 |  | 
| 29 | class 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 |  | 
| 42 | extern toku_instr_key toku_uninstrumented; | 
| 43 |  | 
| 44 | #ifndef MYSQL_TOKUDB_ENGINE | 
| 45 |  | 
| 46 | #include <pthread.h> | 
| 47 |  | 
| 48 | class 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 |  | 
| 59 | typedef toku_instr_probe_empty toku_instr_probe; | 
| 60 |  | 
| 61 | enum 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 |  | 
| 75 | struct PSI_file {}; | 
| 76 | struct PSI_mutex {}; | 
| 77 |  | 
| 78 | struct toku_io_instrumentation {}; | 
| 79 |  | 
| 80 | inline 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 |  | 
| 88 | inline void toku_instr_register_current_thread() {} | 
| 89 |  | 
| 90 | inline void toku_instr_delete_current_thread() {} | 
| 91 |  | 
| 92 | // Instrument file creation, opening, closing, and renaming | 
| 93 | inline 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 |  | 
| 100 | inline void toku_instr_file_stream_open_end( | 
| 101 |     UU(toku_io_instrumentation &io_instr), | 
| 102 |     UU(TOKU_FILE &file)) {} | 
| 103 |  | 
| 104 | inline void toku_instr_file_open_end(UU(toku_io_instrumentation &io_instr), | 
| 105 |                                      UU(int fd)) {} | 
| 106 |  | 
| 107 | inline 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 |  | 
| 115 | inline 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 |  | 
| 122 | inline 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 |  | 
| 129 | inline void toku_instr_file_close_end(UU(toku_io_instrumentation &io_instr), | 
| 130 |                                       UU(int result)) {} | 
| 131 |  | 
| 132 | inline 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 |  | 
| 139 | inline 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 |  | 
| 147 | inline 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 |  | 
| 155 | inline void toku_instr_file_io_end(UU(toku_io_instrumentation &io_instr), | 
| 156 |                                    UU(unsigned int count)) {} | 
| 157 |  | 
| 158 | struct toku_mutex_t; | 
| 159 |  | 
| 160 | struct toku_mutex_instrumentation {}; | 
| 161 |  | 
| 162 | inline PSI_mutex *toku_instr_mutex_init(UU(const toku_instr_key &key), | 
| 163 |                                         UU(toku_mutex_t &mutex)) { | 
| 164 |     return nullptr; | 
| 165 | } | 
| 166 |  | 
| 167 | inline void toku_instr_mutex_destroy(UU(PSI_mutex *&mutex_instr)) {} | 
| 168 |  | 
| 169 | inline 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 |  | 
| 175 | inline 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 |  | 
| 181 | inline void toku_instr_mutex_lock_end( | 
| 182 |     UU(toku_mutex_instrumentation &mutex_instr), | 
| 183 |     UU(int pthread_mutex_lock_result)) {} | 
| 184 |  | 
| 185 | inline void toku_instr_mutex_unlock(UU(PSI_mutex *mutex_instr)) {} | 
| 186 |  | 
| 187 | struct toku_cond_instrumentation {}; | 
| 188 |  | 
| 189 | enum class toku_instr_cond_op { | 
| 190 |     cond_wait, | 
| 191 |     cond_timedwait, | 
| 192 | }; | 
| 193 |  | 
| 194 | inline PSI_cond *toku_instr_cond_init(UU(const toku_instr_key &key), | 
| 195 |                                       UU(toku_cond_t &cond)) { | 
| 196 |     return nullptr; | 
| 197 | } | 
| 198 |  | 
| 199 | inline void toku_instr_cond_destroy(UU(PSI_cond *&cond_instr)) {} | 
| 200 |  | 
| 201 | inline 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 |  | 
| 209 | inline void toku_instr_cond_wait_end(UU(toku_cond_instrumentation &cond_instr), | 
| 210 |                                      UU(int pthread_cond_wait_result)) {} | 
| 211 |  | 
| 212 | inline void toku_instr_cond_signal(UU(toku_cond_t &cond)) {} | 
| 213 |  | 
| 214 | inline void toku_instr_cond_broadcast(UU(toku_cond_t &cond)) {} | 
| 215 |  | 
| 216 | // rwlock instrumentation | 
| 217 | struct toku_rwlock_instrumentation {}; | 
| 218 |  | 
| 219 | inline PSI_rwlock *toku_instr_rwlock_init(UU(const toku_instr_key &key), | 
| 220 |                                           UU(toku_pthread_rwlock_t &rwlock)) { | 
| 221 |     return nullptr; | 
| 222 | } | 
| 223 |  | 
| 224 | inline void toku_instr_rwlock_destroy(UU(PSI_rwlock *&rwlock_instr)) {} | 
| 225 |  | 
| 226 | inline 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 |  | 
| 232 | inline 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 |  | 
| 238 | inline void toku_instr_rwlock_rdlock_wait_end( | 
| 239 |     UU(toku_rwlock_instrumentation &rwlock_instr), | 
| 240 |     UU(int pthread_rwlock_wait_result)) {} | 
| 241 |  | 
| 242 | inline void toku_instr_rwlock_wrlock_wait_end( | 
| 243 |     UU(toku_rwlock_instrumentation &rwlock_instr), | 
| 244 |     UU(int pthread_rwlock_wait_result)) {} | 
| 245 |  | 
| 246 | inline 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 |  | 
| 253 | extern toku_instr_key toku_uninstrumented; | 
| 254 |  | 
| 255 | extern toku_instr_probe *toku_instr_probe_1; | 
| 256 |  | 
| 257 | // threads | 
| 258 | extern toku_instr_key *; | 
| 259 | extern toku_instr_key *fractal_thread_key; | 
| 260 | extern toku_instr_key *io_thread_key; | 
| 261 | extern toku_instr_key *eviction_thread_key; | 
| 262 | extern toku_instr_key *kibbutz_thread_key; | 
| 263 | extern toku_instr_key *minicron_thread_key; | 
| 264 | extern toku_instr_key *tp_internal_thread_key; | 
| 265 |  | 
| 266 | // Files | 
| 267 | extern toku_instr_key *tokudb_file_data_key; | 
| 268 | extern toku_instr_key *tokudb_file_load_key; | 
| 269 | extern toku_instr_key *tokudb_file_tmp_key; | 
| 270 | extern toku_instr_key *tokudb_file_log_key; | 
| 271 |  | 
| 272 | // Mutexes | 
| 273 | extern toku_instr_key *kibbutz_mutex_key; | 
| 274 | extern toku_instr_key *minicron_p_mutex_key; | 
| 275 | extern toku_instr_key *queue_result_mutex_key; | 
| 276 | extern toku_instr_key *tpool_lock_mutex_key; | 
| 277 | extern toku_instr_key *workset_lock_mutex_key; | 
| 278 | extern toku_instr_key *bjm_jobs_lock_mutex_key; | 
| 279 | extern toku_instr_key *log_internal_lock_mutex_key; | 
| 280 | extern toku_instr_key *cachetable_ev_thread_lock_mutex_key; | 
| 281 | extern toku_instr_key *cachetable_disk_nb_mutex_key; | 
| 282 | extern toku_instr_key *cachetable_m_mutex_key; | 
| 283 | extern toku_instr_key *safe_file_size_lock_mutex_key; | 
| 284 | extern toku_instr_key *checkpoint_safe_mutex_key; | 
| 285 | extern toku_instr_key *ft_ref_lock_mutex_key; | 
| 286 | extern toku_instr_key *loader_error_mutex_key; | 
| 287 | extern toku_instr_key *bfs_mutex_key; | 
| 288 | extern toku_instr_key *loader_bl_mutex_key; | 
| 289 | extern toku_instr_key *loader_fi_lock_mutex_key; | 
| 290 | extern toku_instr_key *loader_out_mutex_key; | 
| 291 | extern toku_instr_key *result_output_condition_lock_mutex_key; | 
| 292 | extern toku_instr_key *block_table_mutex_key; | 
| 293 | extern toku_instr_key *rollback_log_node_cache_mutex_key; | 
| 294 | extern toku_instr_key *txn_lock_mutex_key; | 
| 295 | extern toku_instr_key *txn_state_lock_mutex_key; | 
| 296 | extern toku_instr_key *txn_child_manager_mutex_key; | 
| 297 | extern toku_instr_key *txn_manager_lock_mutex_key; | 
| 298 | extern toku_instr_key *treenode_mutex_key; | 
| 299 | extern toku_instr_key *manager_mutex_key; | 
| 300 | extern toku_instr_key *manager_escalation_mutex_key; | 
| 301 | extern toku_instr_key *manager_escalator_mutex_key; | 
| 302 | extern toku_instr_key *db_txn_struct_i_txn_mutex_key; | 
| 303 | extern toku_instr_key *indexer_i_indexer_lock_mutex_key; | 
| 304 | extern toku_instr_key *indexer_i_indexer_estimate_lock_mutex_key; | 
| 305 | extern toku_instr_key *locktree_request_info_mutex_key; | 
| 306 | extern toku_instr_key *locktree_request_info_retry_mutex_key; | 
| 307 |  | 
| 308 | // condition vars | 
| 309 | extern toku_instr_key *result_state_cond_key; | 
| 310 | extern toku_instr_key *bjm_jobs_wait_key; | 
| 311 | extern toku_instr_key *cachetable_p_refcount_wait_key; | 
| 312 | extern toku_instr_key *cachetable_m_flow_control_cond_key; | 
| 313 | extern toku_instr_key *cachetable_m_ev_thread_cond_key; | 
| 314 | extern toku_instr_key *bfs_cond_key; | 
| 315 | extern toku_instr_key *result_output_condition_key; | 
| 316 | extern toku_instr_key *manager_m_escalator_done_key; | 
| 317 | extern toku_instr_key *lock_request_m_wait_cond_key; | 
| 318 | extern toku_instr_key *queue_result_cond_key; | 
| 319 | extern toku_instr_key *ws_worker_wait_key; | 
| 320 | extern toku_instr_key *rwlock_wait_read_key; | 
| 321 | extern toku_instr_key *rwlock_wait_write_key; | 
| 322 | extern toku_instr_key *rwlock_cond_key; | 
| 323 | extern toku_instr_key *tp_thread_wait_key; | 
| 324 | extern toku_instr_key *tp_pool_wait_free_key; | 
| 325 | extern toku_instr_key *frwlock_m_wait_read_key; | 
| 326 | extern toku_instr_key *kibbutz_k_cond_key; | 
| 327 | extern toku_instr_key *minicron_p_condvar_key; | 
| 328 | extern toku_instr_key *locktree_request_info_retry_cv_key; | 
| 329 |  | 
| 330 | // rwlocks | 
| 331 | extern toku_instr_key *multi_operation_lock_key; | 
| 332 | extern toku_instr_key *low_priority_multi_operation_lock_key; | 
| 333 | extern toku_instr_key *cachetable_m_list_lock_key; | 
| 334 | extern toku_instr_key *cachetable_m_pending_lock_expensive_key; | 
| 335 | extern toku_instr_key *cachetable_m_pending_lock_cheap_key; | 
| 336 | extern toku_instr_key *cachetable_m_lock_key; | 
| 337 | extern toku_instr_key *result_i_open_dbs_rwlock_key; | 
| 338 | extern toku_instr_key *checkpoint_safe_rwlock_key; | 
| 339 | extern toku_instr_key *cachetable_value_key; | 
| 340 | extern toku_instr_key *safe_file_size_lock_rwlock_key; | 
| 341 | extern toku_instr_key *cachetable_disk_nb_rwlock_key; | 
| 342 |  |