1 /* Copyright (c) 2008, 2015, 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 Foundation,
21   51 Franklin Street, Fifth Floor, 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 #ifndef PFS_MAX_MUTEX_CLASS
32   #define PFS_MAX_MUTEX_CLASS 200
33 #endif
34 #ifndef PFS_MAX_RWLOCK_CLASS
35   #define PFS_MAX_RWLOCK_CLASS 40
36 #endif
37 #ifndef PFS_MAX_COND_CLASS
38   #define PFS_MAX_COND_CLASS 80
39 #endif
40 #ifndef PFS_MAX_THREAD_CLASS
41   #define PFS_MAX_THREAD_CLASS 50
42 #endif
43 #ifndef PFS_MAX_FILE_CLASS
44   #define PFS_MAX_FILE_CLASS 50
45 #endif
46 #ifndef PFS_MAX_FILE_HANDLE
47   #define PFS_MAX_FILE_HANDLE 32768
48 #endif
49 #ifndef PFS_MAX_SOCKET_CLASS
50   #define PFS_MAX_SOCKET_CLASS 10
51 #endif
52 #ifndef PFS_MAX_SETUP_ACTOR
53   #define PFS_MAX_SETUP_ACTOR 100
54 #endif
55 #ifndef PFS_MAX_SETUP_OBJECT
56   #define PFS_MAX_SETUP_OBJECT 100
57 #endif
58 #ifndef PFS_MAX_STAGE_CLASS
59   #define PFS_MAX_STAGE_CLASS 160
60 #endif
61 #ifndef PFS_STATEMENTS_STACK_SIZE
62   #define PFS_STATEMENTS_STACK_SIZE 10
63 #endif
64 #ifndef PFS_CONNECT_ATTRS_SIZE
65   #define PFS_SESSION_CONNECT_ATTRS_SIZE 2048
66 #endif
67 
68 struct PFS_sizing_hints
69 {
70   long m_table_definition_cache;
71   long m_table_open_cache;
72   long m_max_connections;
73   long m_open_files_limit;
74 };
75 
76 /** Performance schema global sizing parameters. */
77 struct PFS_global_param
78 {
79   /** True if the performance schema is enabled. */
80   bool m_enabled;
81   /** Default values for SETUP_CONSUMERS. */
82   bool m_consumer_events_stages_current_enabled;
83   bool m_consumer_events_stages_history_enabled;
84   bool m_consumer_events_stages_history_long_enabled;
85   bool m_consumer_events_statements_current_enabled;
86   bool m_consumer_events_statements_history_enabled;
87   bool m_consumer_events_statements_history_long_enabled;
88   bool m_consumer_events_waits_current_enabled;
89   bool m_consumer_events_waits_history_enabled;
90   bool m_consumer_events_waits_history_long_enabled;
91   bool m_consumer_global_instrumentation_enabled;
92   bool m_consumer_thread_instrumentation_enabled;
93   bool m_consumer_statement_digest_enabled;
94 
95   /** Default instrument configuration option. */
96   char *m_pfs_instrument;
97 
98   /**
99     Maximum number of instrumented mutex classes.
100     @sa mutex_class_lost.
101   */
102   ulong m_mutex_class_sizing;
103   /**
104     Maximum number of instrumented rwlock classes.
105     @sa rwlock_class_lost.
106   */
107   ulong m_rwlock_class_sizing;
108   /**
109     Maximum number of instrumented cond classes.
110     @sa cond_class_lost.
111   */
112   ulong m_cond_class_sizing;
113   /**
114     Maximum number of instrumented thread classes.
115     @sa thread_class_lost.
116   */
117   ulong m_thread_class_sizing;
118   /**
119     Maximum number of instrumented table share.
120     @sa table_share_lost.
121   */
122   long m_table_share_sizing;
123   /**
124     Maximum number of instrumented file classes.
125     @sa file_class_lost.
126   */
127   ulong m_file_class_sizing;
128   /**
129     Maximum number of instrumented mutex instances.
130     @sa mutex_lost.
131   */
132   long m_mutex_sizing;
133   /**
134     Maximum number of instrumented rwlock instances.
135     @sa rwlock_lost.
136   */
137   long m_rwlock_sizing;
138   /**
139     Maximum number of instrumented cond instances.
140     @sa cond_lost.
141   */
142   long m_cond_sizing;
143   /**
144     Maximum number of instrumented thread instances.
145     @sa thread_lost.
146   */
147   long m_thread_sizing;
148   /**
149     Maximum number of instrumented table handles.
150     @sa table_lost.
151   */
152   long m_table_sizing;
153   /**
154     Maximum number of instrumented file instances.
155     @sa file_lost.
156   */
157   long m_file_sizing;
158   /**
159     Maximum number of instrumented file handles.
160     @sa file_handle_lost.
161   */
162   long m_file_handle_sizing;
163   /**
164     Maxium number of instrumented socket instances
165     @sa socket_lost
166   */
167   long m_socket_sizing;
168   /**
169     Maximum number of instrumented socket classes.
170     @sa socket_class_lost.
171   */
172   ulong m_socket_class_sizing;
173   /** Maximum number of rows per thread in table EVENTS_WAITS_HISTORY. */
174   long m_events_waits_history_sizing;
175   /** Maximum number of rows in table EVENTS_WAITS_HISTORY_LONG. */
176   long m_events_waits_history_long_sizing;
177   /** Maximum number of rows in table SETUP_ACTORS. */
178   ulong m_setup_actor_sizing;
179   /** Maximum number of rows in table SETUP_OBJECTS. */
180   ulong m_setup_object_sizing;
181   /** Maximum number of rows in table HOSTS. */
182   long m_host_sizing;
183   /** Maximum number of rows in table USERS. */
184   long m_user_sizing;
185   /** Maximum number of rows in table ACCOUNTS. */
186   long m_account_sizing;
187   /**
188     Maximum number of instrumented stage classes.
189     @sa stage_class_lost.
190   */
191   ulong m_stage_class_sizing;
192   /** Maximum number of rows per thread in table EVENTS_STAGES_HISTORY. */
193   long m_events_stages_history_sizing;
194   /** Maximum number of rows in table EVENTS_STAGES_HISTORY_LONG. */
195   long m_events_stages_history_long_sizing;
196   /**
197     Maximum number of instrumented statement classes.
198     @sa statement_class_lost.
199   */
200   ulong m_statement_class_sizing;
201   /** Maximum number of rows per thread in table EVENTS_STATEMENT_HISTORY. */
202   long m_events_statements_history_sizing;
203   /** Maximum number of rows in table EVENTS_STATEMENTS_HISTORY_LONG. */
204   long m_events_statements_history_long_sizing;
205   /** Maximum number of digests to be captured */
206   long m_digest_sizing;
207   /** Maximum number of session attribute strings per thread */
208   long m_session_connect_attrs_sizing;
209 
210   long m_max_digest_length;
211 
212   /** Sizing hints, for auto tuning. */
213   PFS_sizing_hints m_hints;
214 };
215 
216 /**
217   Performance schema sizing values for the server.
218   This global variable is set when parsing server startup options.
219 */
220 extern PFS_global_param pfs_param;
221 
222 /**
223   Initialize the performance schema.
224   @param param Size parameters to use.
225   @return A boostrap handle, or NULL.
226 */
227 struct PSI_bootstrap*
228 initialize_performance_schema(PFS_global_param *param);
229 
230 void pfs_automated_sizing(PFS_global_param *param);
231 
232 /**
233   Initialize the performance schema ACL.
234   ACL is strictly enforced when the server is running in normal mode,
235   to enforce that only legal operations are allowed.
236   When running in boostrap mode, ACL restrictions are relaxed,
237   to allow the boostrap scripts to DROP / CREATE performance schema tables.
238   @sa ACL_internal_schema_registry
239   @param bootstrap True if the server is starting in bootstrap mode.
240 */
241 void initialize_performance_schema_acl(bool bootstrap);
242 
243 /**
244   Initialize the dynamic array holding individual instrument settings collected
245   from the server configuration options.
246 */
247 void init_pfs_instrument_array();
248 
249 /**
250   Process one PFS_INSTRUMENT configuration string.
251 */
252 int add_pfs_instr_to_array(const char* name, const char* value);
253 
254 /**
255   Shutdown the performance schema.
256 */
257 void shutdown_performance_schema();
258 
259 #endif
260