1 /* Copyright (c) 2008, 2021, Oracle and/or its affiliates.
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 Foundation,
21   51 Franklin Street, Suite 500, Boston, MA 02110-1335 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 #define PFS_AUTOSCALE_VALUE (-1)
32 #define PFS_AUTOSIZE_VALUE (-1)
33 
34 #ifndef PFS_MAX_MUTEX_CLASS
35   #define PFS_MAX_MUTEX_CLASS 250
36 #endif
37 #ifndef PFS_MAX_RWLOCK_CLASS
38   #define PFS_MAX_RWLOCK_CLASS 50
39 #endif
40 #ifndef PFS_MAX_COND_CLASS
41   #define PFS_MAX_COND_CLASS 80
42 #endif
43 #ifndef PFS_MAX_THREAD_CLASS
44   #define PFS_MAX_THREAD_CLASS 50
45 #endif
46 #ifndef PFS_MAX_FILE_CLASS
47   #define PFS_MAX_FILE_CLASS 80
48 #endif
49 #ifndef PFS_MAX_FILE_HANDLE
50   #define PFS_MAX_FILE_HANDLE 32768
51 #endif
52 #ifndef PFS_MAX_SOCKET_CLASS
53   #define PFS_MAX_SOCKET_CLASS 10
54 #endif
55 #ifndef PFS_MAX_STAGE_CLASS
56   #define PFS_MAX_STAGE_CLASS 150
57 #endif
58 #ifndef PFS_STATEMENTS_STACK_SIZE
59   #define PFS_STATEMENTS_STACK_SIZE 10
60 #endif
61 #ifndef PFS_MAX_MEMORY_CLASS
62   #define PFS_MAX_MEMORY_CLASS 400
63 #endif
64 
65 /** Sizing hints, from the server configuration. */
66 struct PFS_sizing_hints
67 {
68   /** Value of @c Sys_table_def_size */
69   long m_table_definition_cache;
70   /** Value of @c Sys_table_cache_size */
71   long m_table_open_cache;
72   /** Value of @c Sys_max_connections */
73   long m_max_connections;
74   /** Value of @c Sys_open_files_limit */
75   long m_open_files_limit;
76   /** Value of @c Sys_max_prepared_stmt_count */
77   long m_max_prepared_stmt_count;
78 };
79 
80 /** Performance schema global sizing parameters. */
81 struct PFS_global_param
82 {
83   /** True if the performance schema is enabled. */
84   bool m_enabled;
85   /** Default values for SETUP_CONSUMERS. */
86   bool m_consumer_events_stages_current_enabled;
87   bool m_consumer_events_stages_history_enabled;
88   bool m_consumer_events_stages_history_long_enabled;
89   bool m_consumer_events_statements_current_enabled;
90   bool m_consumer_events_statements_history_enabled;
91   bool m_consumer_events_statements_history_long_enabled;
92   bool m_consumer_events_transactions_current_enabled;
93   bool m_consumer_events_transactions_history_enabled;
94   bool m_consumer_events_transactions_history_long_enabled;
95   bool m_consumer_events_waits_current_enabled;
96   bool m_consumer_events_waits_history_enabled;
97   bool m_consumer_events_waits_history_long_enabled;
98   bool m_consumer_global_instrumentation_enabled;
99   bool m_consumer_thread_instrumentation_enabled;
100   bool m_consumer_statement_digest_enabled;
101 
102   /** Default instrument configuration option. */
103   char *m_pfs_instrument;
104 
105   /**
106     Maximum number of instrumented mutex classes.
107     @sa mutex_class_lost.
108   */
109   ulong m_mutex_class_sizing;
110   /**
111     Maximum number of instrumented rwlock classes.
112     @sa rwlock_class_lost.
113   */
114   ulong m_rwlock_class_sizing;
115   /**
116     Maximum number of instrumented cond classes.
117     @sa cond_class_lost.
118   */
119   ulong m_cond_class_sizing;
120   /**
121     Maximum number of instrumented thread classes.
122     @sa thread_class_lost.
123   */
124   ulong m_thread_class_sizing;
125   /**
126     Maximum number of instrumented table share.
127     @sa table_share_lost.
128   */
129   long m_table_share_sizing;
130   /**
131     Maximum number of lock statistics collected for tables.
132     @sa table_lock_stat_lost.
133   */
134   long m_table_lock_stat_sizing;
135   /**
136     Maximum number of index statistics collected for tables.
137     @sa table_index_lost.
138   */
139   long m_index_stat_sizing;
140   /**
141     Maximum number of instrumented file classes.
142     @sa file_class_lost.
143   */
144   ulong m_file_class_sizing;
145   /**
146     Maximum number of instrumented mutex instances.
147     @sa mutex_lost.
148   */
149   long m_mutex_sizing;
150   /**
151     Maximum number of instrumented rwlock instances.
152     @sa rwlock_lost.
153   */
154   long m_rwlock_sizing;
155   /**
156     Maximum number of instrumented cond instances.
157     @sa cond_lost.
158   */
159   long m_cond_sizing;
160   /**
161     Maximum number of instrumented thread instances.
162     @sa thread_lost.
163   */
164   long m_thread_sizing;
165   /**
166     Maximum number of instrumented table handles.
167     @sa table_lost.
168   */
169   long m_table_sizing;
170   /**
171     Maximum number of instrumented file instances.
172     @sa file_lost.
173   */
174   long m_file_sizing;
175   /**
176     Maximum number of instrumented file handles.
177     @sa file_handle_lost.
178   */
179   long m_file_handle_sizing;
180   /**
181     Maxium number of instrumented socket instances
182     @sa socket_lost
183   */
184   long m_socket_sizing;
185   /**
186     Maximum number of instrumented socket classes.
187     @sa socket_class_lost.
188   */
189   ulong m_socket_class_sizing;
190   /** Maximum number of rows per thread in table EVENTS_WAITS_HISTORY. */
191   long m_events_waits_history_sizing;
192   /** Maximum number of rows in table EVENTS_WAITS_HISTORY_LONG. */
193   long m_events_waits_history_long_sizing;
194   /** Maximum number of rows in table SETUP_ACTORS. */
195   long m_setup_actor_sizing;
196   /** Maximum number of rows in table SETUP_OBJECTS. */
197   long m_setup_object_sizing;
198   /** Maximum number of rows in table HOSTS. */
199   long m_host_sizing;
200   /** Maximum number of rows in table USERS. */
201   long m_user_sizing;
202   /** Maximum number of rows in table ACCOUNTS. */
203   long m_account_sizing;
204   /**
205     Maximum number of instrumented stage classes.
206     @sa stage_class_lost.
207   */
208   ulong m_stage_class_sizing;
209   /** Maximum number of rows per thread in table EVENTS_STAGES_HISTORY. */
210   long m_events_stages_history_sizing;
211   /** Maximum number of rows in table EVENTS_STAGES_HISTORY_LONG. */
212   long m_events_stages_history_long_sizing;
213   /**
214     Maximum number of instrumented statement classes.
215     @sa statement_class_lost.
216   */
217   ulong m_statement_class_sizing;
218   /** Maximum number of rows per thread in table EVENTS_STATEMENTS_HISTORY. */
219   long m_events_statements_history_sizing;
220   /** Maximum number of rows in table EVENTS_STATEMENTS_HISTORY_LONG. */
221   long m_events_statements_history_long_sizing;
222   /** Maximum number of digests to be captured */
223   long m_digest_sizing;
224   /** Maximum number of programs to be captured */
225   long m_program_sizing;
226   /** Maximum number of prepared statements to be captured */
227   long m_prepared_stmt_sizing;
228   /** Maximum number of rows per thread in table EVENTS_TRANSACTIONS_HISTORY. */
229   long m_events_transactions_history_sizing;
230   /** Maximum number of rows in table EVENTS_TRANSACTIONS_HISTORY_LONG. */
231   long m_events_transactions_history_long_sizing;
232 
233   /** Maximum number of session attribute strings per thread */
234   long m_session_connect_attrs_sizing;
235   /** Maximum size of statement stack */
236   ulong m_statement_stack_sizing;
237 
238   /**
239     Maximum number of instrumented memory classes.
240     @sa memory_class_lost.
241   */
242   ulong m_memory_class_sizing;
243 
244   long m_metadata_lock_sizing;
245 
246   long m_max_digest_length;
247   ulong m_max_sql_text_length;
248 
249   /** Sizing hints, for auto tuning. */
250   PFS_sizing_hints m_hints;
251 };
252 
253 /**
254   Performance schema sizing values for the server.
255   This global variable is set when parsing server startup options.
256 */
257 extern PFS_global_param pfs_param;
258 
259 /**
260   Null initialization.
261   Disable all instrumentation, size all internal buffers to 0.
262   This pre initialization step is needed to ensure that events can be collected
263   and discarded, until such time @c initialize_performance_schema() is called.
264 */
265 void pre_initialize_performance_schema();
266 
267 /**
268   Initialize the performance schema.
269   @param param Size parameters to use.
270   @return A bootstrap handle, or NULL.
271 */
272 struct PSI_bootstrap*
273 initialize_performance_schema(PFS_global_param *param);
274 
275 void pfs_automated_sizing(PFS_global_param *param);
276 
277 /**
278   Initialize the performance schema ACL.
279   ACL is strictly enforced when the server is running in normal mode,
280   to enforce that only legal operations are allowed.
281   When running in bootstrap mode, ACL restrictions are relaxed,
282   to allow the bootstrap scripts to DROP / CREATE performance schema tables.
283   @sa ACL_internal_schema_registry
284   @param bootstrap True if the server is starting in bootstrap mode.
285 */
286 void initialize_performance_schema_acl(bool bootstrap);
287 
288 void check_performance_schema();
289 
290 /**
291   Reset the aggregated status counter stats.
292 */
293 void reset_pfs_status_stats();
294 
295 /**
296   Initialize the dynamic array holding individual instrument settings collected
297   from the server configuration options.
298 */
299 void init_pfs_instrument_array();
300 
301 /**
302   Process one PFS_INSTRUMENT configuration string.
303 */
304 int add_pfs_instr_to_array(const char* name, const char* value);
305 
306 /**
307   Shutdown the performance schema.
308 */
309 void shutdown_performance_schema();
310 
311 #endif
312