1 /* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved. 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 21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 22 23 #ifndef PFS_SERVER_H 24 #define PFS_SERVER_H 25 26 /** 27 @file storage/perfschema/pfs_server.h 28 Private interface for the server (declarations). 29 */ 30 31 #include <sys/types.h> 32 33 #include "my_psi_config.h" 34 #include "mysql/psi/psi_cond.h" 35 #include "mysql/psi/psi_data_lock.h" 36 #include "mysql/psi/psi_error.h" 37 #include "mysql/psi/psi_file.h" 38 #include "mysql/psi/psi_idle.h" 39 #include "mysql/psi/psi_mdl.h" 40 #include "mysql/psi/psi_memory.h" 41 #include "mysql/psi/psi_mutex.h" 42 #include "mysql/psi/psi_rwlock.h" 43 #include "mysql/psi/psi_socket.h" 44 #include "mysql/psi/psi_stage.h" 45 #include "mysql/psi/psi_statement.h" 46 #include "mysql/psi/psi_system.h" 47 #include "mysql/psi/psi_table.h" 48 #include "mysql/psi/psi_thread.h" 49 #include "mysql/psi/psi_tls_channel.h" 50 #include "mysql/psi/psi_transaction.h" 51 52 #ifdef HAVE_PSI_INTERFACE 53 54 #define PFS_AUTOSCALE_VALUE (-1) 55 #define PFS_AUTOSIZE_VALUE (-1) 56 57 #ifndef PFS_MAX_MUTEX_CLASS 58 #define PFS_MAX_MUTEX_CLASS 300 59 #endif 60 #ifndef PFS_MAX_RWLOCK_CLASS 61 #define PFS_MAX_RWLOCK_CLASS 60 62 #endif 63 #ifndef PFS_MAX_COND_CLASS 64 #define PFS_MAX_COND_CLASS 100 65 #endif 66 #ifndef PFS_MAX_THREAD_CLASS 67 #define PFS_MAX_THREAD_CLASS 100 68 #endif 69 #ifndef PFS_MAX_FILE_CLASS 70 #define PFS_MAX_FILE_CLASS 80 71 #endif 72 #ifndef PFS_MAX_FILE_HANDLE 73 #define PFS_MAX_FILE_HANDLE 32768 74 #endif 75 #ifndef PFS_MAX_SOCKET_CLASS 76 #define PFS_MAX_SOCKET_CLASS 10 77 #endif 78 #ifndef PFS_MAX_STAGE_CLASS 79 #define PFS_MAX_STAGE_CLASS 175 80 #endif 81 #ifndef PFS_STATEMENTS_STACK_SIZE 82 #define PFS_STATEMENTS_STACK_SIZE 10 83 #endif 84 #ifndef PFS_MAX_MEMORY_CLASS 85 #define PFS_MAX_MEMORY_CLASS 450 86 #endif 87 88 #ifndef PFS_MAX_GLOBAL_SERVER_ERRORS 89 #define PFS_MAX_GLOBAL_SERVER_ERRORS \ 90 (1 + pfs_session_error_stat_count + pfs_global_error_stat_count) 91 #endif 92 93 #ifndef PFS_MAX_SESSION_SERVER_ERRORS 94 #define PFS_MAX_SESSION_SERVER_ERRORS (1 + pfs_session_error_stat_count) 95 #endif 96 97 /** Sizing hints, from the server configuration. */ 98 struct PFS_sizing_hints { 99 /** Value of @c Sys_table_def_size */ 100 ulong m_table_definition_cache; 101 /** Value of @c Sys_table_cache_size */ 102 long m_table_open_cache; 103 /** Value of @c Sys_max_connections */ 104 long m_max_connections; 105 /** Value of @c Sys_open_files_limit */ 106 long m_open_files_limit; 107 /** Value of @c Sys_max_prepared_stmt_count */ 108 long m_max_prepared_stmt_count; 109 }; 110 111 /** Performance schema global sizing parameters. */ 112 struct PFS_global_param { 113 /** True if the performance schema is enabled. */ 114 bool m_enabled; 115 /** Default values for SETUP_CONSUMERS. */ 116 bool m_consumer_events_stages_current_enabled; 117 bool m_consumer_events_stages_history_enabled; 118 bool m_consumer_events_stages_history_long_enabled; 119 bool m_consumer_events_statements_current_enabled; 120 bool m_consumer_events_statements_history_enabled; 121 bool m_consumer_events_statements_history_long_enabled; 122 bool m_consumer_events_transactions_current_enabled; 123 bool m_consumer_events_transactions_history_enabled; 124 bool m_consumer_events_transactions_history_long_enabled; 125 bool m_consumer_events_waits_current_enabled; 126 bool m_consumer_events_waits_history_enabled; 127 bool m_consumer_events_waits_history_long_enabled; 128 bool m_consumer_global_instrumentation_enabled; 129 bool m_consumer_thread_instrumentation_enabled; 130 bool m_consumer_statement_digest_enabled; 131 132 /** Default instrument configuration option. */ 133 char *m_pfs_instrument; 134 135 /** 136 Maximum number of instrumented mutex classes. 137 @sa mutex_class_lost. 138 */ 139 ulong m_mutex_class_sizing; 140 /** 141 Maximum number of instrumented rwlock classes. 142 @sa rwlock_class_lost. 143 */ 144 ulong m_rwlock_class_sizing; 145 /** 146 Maximum number of instrumented cond classes. 147 @sa cond_class_lost. 148 */ 149 ulong m_cond_class_sizing; 150 /** 151 Maximum number of instrumented thread classes. 152 @sa thread_class_lost. 153 */ 154 ulong m_thread_class_sizing; 155 /** 156 Maximum number of instrumented table share. 157 @sa table_share_lost. 158 */ 159 long m_table_share_sizing; 160 /** 161 Maximum number of lock statistics collected for tables. 162 @sa table_lock_stat_lost. 163 */ 164 long m_table_lock_stat_sizing; 165 /** 166 Maximum number of index statistics collected for tables. 167 @sa table_index_lost. 168 */ 169 long m_index_stat_sizing; 170 /** 171 Maximum number of instrumented file classes. 172 @sa file_class_lost. 173 */ 174 ulong m_file_class_sizing; 175 /** 176 Maximum number of instrumented mutex instances. 177 @sa mutex_lost. 178 */ 179 long m_mutex_sizing; 180 /** 181 Maximum number of instrumented rwlock instances. 182 @sa rwlock_lost. 183 */ 184 long m_rwlock_sizing; 185 /** 186 Maximum number of instrumented cond instances. 187 @sa cond_lost. 188 */ 189 long m_cond_sizing; 190 /** 191 Maximum number of instrumented thread instances. 192 @sa thread_lost. 193 */ 194 long m_thread_sizing; 195 /** 196 Maximum number of instrumented table handles. 197 @sa table_lost. 198 */ 199 long m_table_sizing; 200 /** 201 Maximum number of instrumented file instances. 202 @sa file_lost. 203 */ 204 long m_file_sizing; 205 /** 206 Maximum number of instrumented file handles. 207 @sa file_handle_lost. 208 */ 209 long m_file_handle_sizing; 210 /** 211 Maximum number of instrumented socket instances 212 @sa socket_lost 213 */ 214 long m_socket_sizing; 215 /** 216 Maximum number of instrumented socket classes. 217 @sa socket_class_lost. 218 */ 219 ulong m_socket_class_sizing; 220 /** Maximum number of rows per thread in table EVENTS_WAITS_HISTORY. */ 221 long m_events_waits_history_sizing; 222 /** Maximum number of rows in table EVENTS_WAITS_HISTORY_LONG. */ 223 long m_events_waits_history_long_sizing; 224 /** Maximum number of rows in table SETUP_ACTORS. */ 225 long m_setup_actor_sizing; 226 /** Maximum number of rows in table SETUP_OBJECTS. */ 227 long m_setup_object_sizing; 228 /** Maximum number of rows in table HOSTS. */ 229 long m_host_sizing; 230 /** Maximum number of rows in table USERS. */ 231 long m_user_sizing; 232 /** Maximum number of rows in table ACCOUNTS. */ 233 long m_account_sizing; 234 /** 235 Maximum number of instrumented stage classes. 236 @sa stage_class_lost. 237 */ 238 ulong m_stage_class_sizing; 239 /** Maximum number of rows per thread in table EVENTS_STAGES_HISTORY. */ 240 long m_events_stages_history_sizing; 241 /** Maximum number of rows in table EVENTS_STAGES_HISTORY_LONG. */ 242 long m_events_stages_history_long_sizing; 243 /** 244 Maximum number of instrumented statement classes. 245 @sa statement_class_lost. 246 */ 247 ulong m_statement_class_sizing; 248 /** Maximum number of rows per thread in table EVENTS_STATEMENTS_HISTORY. */ 249 long m_events_statements_history_sizing; 250 /** Maximum number of rows in table EVENTS_STATEMENTS_HISTORY_LONG. */ 251 long m_events_statements_history_long_sizing; 252 /** Maximum number of digests to be captured */ 253 long m_digest_sizing; 254 /** Maximum number of programs to be captured */ 255 long m_program_sizing; 256 /** Maximum number of prepared statements to be captured */ 257 long m_prepared_stmt_sizing; 258 /** Maximum number of rows per thread in table EVENTS_TRANSACTIONS_HISTORY. */ 259 long m_events_transactions_history_sizing; 260 /** Maximum number of rows in table EVENTS_TRANSACTIONS_HISTORY_LONG. */ 261 long m_events_transactions_history_long_sizing; 262 263 /** Maximum number of session attribute strings per thread */ 264 long m_session_connect_attrs_sizing; 265 /** Maximum size of statement stack */ 266 ulong m_statement_stack_sizing; 267 268 /** 269 Maximum number of instrumented memory classes. 270 @sa memory_class_lost. 271 */ 272 ulong m_memory_class_sizing; 273 274 long m_metadata_lock_sizing; 275 276 long m_max_digest_length; 277 ulong m_max_sql_text_length; 278 279 /** Maximum age in seconds for a query sample. */ 280 ulong m_max_digest_sample_age; 281 282 /** Maximum number of error instrumented */ 283 ulong m_error_sizing; 284 285 /** Sizing hints, for auto tuning. */ 286 PFS_sizing_hints m_hints; 287 }; 288 289 /** 290 Performance schema sizing values for the server. 291 This global variable is set when parsing server startup options. 292 */ 293 extern PFS_global_param pfs_param; 294 295 /** 296 Null initialization. 297 Disable all instrumentation, size all internal buffers to 0. 298 This pre initialization step is needed to ensure that events can be collected 299 and discarded, until such time @c initialize_performance_schema() is called. 300 */ 301 void pre_initialize_performance_schema(); 302 303 /** 304 Initialize the performance schema. 305 The performance schema implement several instrumentation services. 306 Each instrumentation service is versioned, and accessible through 307 a bootstrap structure, returned as output parameter. 308 @param param Size parameters to use. 309 @param [out] thread_bootstrap Thread instrumentation service bootstrap 310 @param [out] mutex_bootstrap Mutex instrumentation service bootstrap 311 @param [out] rwlock_bootstrap Rwlock instrumentation service bootstrap 312 @param [out] cond_bootstrap Condition instrumentation service bootstrap 313 @param [out] file_bootstrap File instrumentation service bootstrap 314 @param [out] socket_bootstrap Socket instrumentation service bootstrap 315 @param [out] table_bootstrap Table instrumentation service bootstrap 316 @param [out] mdl_bootstrap Metadata Lock instrumentation service bootstrap 317 @param [out] idle_bootstrap Idle instrumentation service bootstrap 318 @param [out] stage_bootstrap Stage instrumentation service bootstrap 319 @param [out] statement_bootstrap Statement instrumentation service bootstrap 320 @param [out] transaction_bootstrap Transaction instrumentation service 321 bootstrap 322 @param [out] memory_bootstrap Memory instrumentation service bootstrap 323 @param [out] error_bootstrap Error instrumentation service bootstrap 324 @param [out] data_lock_bootstrap Data Lock instrumentation service bootstrap 325 @param [out] system_bootstrap System instrumentation service bootstrap 326 @param [out] tls_channel_bootstrap TLS channel instrumentation service 327 bootstrap 328 @returns 329 @retval 0 success 330 */ 331 int initialize_performance_schema( 332 PFS_global_param *param, PSI_thread_bootstrap **thread_bootstrap, 333 PSI_mutex_bootstrap **mutex_bootstrap, 334 PSI_rwlock_bootstrap **rwlock_bootstrap, 335 PSI_cond_bootstrap **cond_bootstrap, PSI_file_bootstrap **file_bootstrap, 336 PSI_socket_bootstrap **socket_bootstrap, 337 PSI_table_bootstrap **table_bootstrap, PSI_mdl_bootstrap **mdl_bootstrap, 338 PSI_idle_bootstrap **idle_bootstrap, PSI_stage_bootstrap **stage_bootstrap, 339 PSI_statement_bootstrap **statement_bootstrap, 340 PSI_transaction_bootstrap **transaction_bootstrap, 341 PSI_memory_bootstrap **memory_bootstrap, 342 PSI_error_bootstrap **error_bootstrap, 343 PSI_data_lock_bootstrap **data_lock_bootstrap, 344 PSI_system_bootstrap **system_bootstrap, 345 PSI_tls_channel_bootstrap **tls_channel_bootstrap); 346 347 void pfs_automated_sizing(PFS_global_param *param); 348 349 /** 350 Initialize the performance schema ACL. 351 ACL is strictly enforced when the server is running in normal mode, 352 to enforce that only legal operations are allowed. 353 When running in bootstrap mode, ACL restrictions are relaxed, 354 to allow the bootstrap scripts to DROP / CREATE performance schema tables. 355 @sa ACL_internal_schema_registry 356 @param bootstrap True if the server is starting in bootstrap mode. 357 */ 358 void initialize_performance_schema_acl(bool bootstrap); 359 360 /** 361 Reset the aggregated status counter stats. 362 */ 363 void reset_pfs_status_stats(); 364 365 /** 366 Initialize the dynamic array holding individual instrument settings collected 367 from the server configuration options. 368 */ 369 void init_pfs_instrument_array(); 370 371 /** 372 Process one PFS_INSTRUMENT configuration string. 373 */ 374 int add_pfs_instr_to_array(const char *name, const char *value); 375 376 /** 377 Register/unregister notification service. 378 */ 379 int register_pfs_notification_service(); 380 int unregister_pfs_notification_service(); 381 382 /** 383 Register/unregister resource group service. 384 */ 385 int register_pfs_resource_group_service(); 386 int unregister_pfs_resource_group_service(); 387 388 /** 389 Shutdown the performance schema. 390 */ 391 void shutdown_performance_schema(); 392 393 #endif /* HAVE_PSI_INTERFACE */ 394 395 #endif /* PFS_SERVER_H */ 396