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, Suite 500, Boston, MA 02110-1335 USA */
22 
23 #ifndef MYSQL_PERFORMANCE_SCHEMA_INTERFACE_H
24 #define MYSQL_PERFORMANCE_SCHEMA_INTERFACE_H
25 
26 #ifdef EMBEDDED_LIBRARY
27 #define DISABLE_PSI_MUTEX
28 #define DISABLE_PSI_RWLOCK
29 #define DISABLE_PSI_COND
30 #define DISABLE_PSI_FILE
31 #define DISABLE_PSI_TABLE
32 #define DISABLE_PSI_SOCKET
33 #define DISABLE_PSI_STAGE
34 #define DISABLE_PSI_STATEMENT
35 #define DISABLE_PSI_IDLE
36 #define DISABLE_PSI_STATEMENT_DIGEST
37 #endif /* EMBEDDED_LIBRARY */
38 
39 #ifndef MY_GLOBAL_INCLUDED
40 /*
41   Make sure a .c or .cc file contains an include to my_global.h first.
42   When this include is missing, all the #ifdef HAVE_XXX have no effect,
43   and the resulting binary won't build, or won't link,
44   or will crash at runtime
45   since various structures will have different binary definitions.
46 */
47 #error "You must include my_global.h in the code for the build to be correct."
48 #endif
49 
50 C_MODE_START
51 
52 struct TABLE_SHARE;
53 
54 struct sql_digest_storage;
55 
56 /**
57   @file mysql/psi/psi.h
58   Performance schema instrumentation interface.
59 
60   @defgroup Instrumentation_interface Instrumentation Interface
61   @ingroup Performance_schema
62   @{
63 */
64 
65 /**
66   Interface for an instrumented mutex.
67   This is an opaque structure.
68 */
69 struct PSI_mutex;
70 typedef struct PSI_mutex PSI_mutex;
71 
72 /**
73   Interface for an instrumented rwlock.
74   This is an opaque structure.
75 */
76 struct PSI_rwlock;
77 typedef struct PSI_rwlock PSI_rwlock;
78 
79 /**
80   Interface for an instrumented condition.
81   This is an opaque structure.
82 */
83 struct PSI_cond;
84 typedef struct PSI_cond PSI_cond;
85 
86 /**
87   Interface for an instrumented table share.
88   This is an opaque structure.
89 */
90 struct PSI_table_share;
91 typedef struct PSI_table_share PSI_table_share;
92 
93 /**
94   Interface for an instrumented table handle.
95   This is an opaque structure.
96 */
97 struct PSI_table;
98 typedef struct PSI_table PSI_table;
99 
100 /**
101   Interface for an instrumented thread.
102   This is an opaque structure.
103 */
104 struct PSI_thread;
105 typedef struct PSI_thread PSI_thread;
106 
107 /**
108   Interface for an instrumented file handle.
109   This is an opaque structure.
110 */
111 struct PSI_file;
112 typedef struct PSI_file PSI_file;
113 
114 /**
115   Interface for an instrumented socket descriptor.
116   This is an opaque structure.
117 */
118 struct PSI_socket;
119 typedef struct PSI_socket PSI_socket;
120 
121 /**
122   Interface for an instrumented table operation.
123   This is an opaque structure.
124 */
125 struct PSI_table_locker;
126 typedef struct PSI_table_locker PSI_table_locker;
127 
128 /**
129   Interface for an instrumented statement.
130   This is an opaque structure.
131 */
132 struct PSI_statement_locker;
133 typedef struct PSI_statement_locker PSI_statement_locker;
134 
135 /**
136   Interface for an instrumented idle operation.
137   This is an opaque structure.
138 */
139 struct PSI_idle_locker;
140 typedef struct PSI_idle_locker PSI_idle_locker;
141 
142 /**
143   Interface for an instrumented statement digest operation.
144   This is an opaque structure.
145 */
146 struct PSI_digest_locker;
147 typedef struct PSI_digest_locker PSI_digest_locker;
148 
149 /** Entry point for the performance schema interface. */
150 struct PSI_bootstrap
151 {
152   /**
153     ABI interface finder.
154     Calling this method with an interface version number returns either
155     an instance of the ABI for this version, or NULL.
156     @param version the interface version number to find
157     @return a versioned interface (PSI_v1, PSI_v2 or PSI)
158     @sa PSI_VERSION_1
159     @sa PSI_v1
160     @sa PSI_VERSION_2
161     @sa PSI_v2
162     @sa PSI_CURRENT_VERSION
163     @sa PSI
164   */
165   void* (*get_interface)(int version);
166 };
167 typedef struct PSI_bootstrap PSI_bootstrap;
168 
169 #ifdef HAVE_PSI_INTERFACE
170 
171 /**
172   @def DISABLE_PSI_MUTEX
173   Compiling option to disable the mutex instrumentation.
174   This option is mostly intended to be used during development,
175   when doing special builds with only a subset of the performance schema instrumentation,
176   for code analysis / profiling / performance tuning of a specific instrumentation alone.
177   For this reason, DISABLE_PSI_MUTEX is not advertised in the cmake general options.
178   To disable mutexes, add -DDISABLE_PSI_MUTEX to CFLAGS.
179   @sa DISABLE_PSI_RWLOCK
180   @sa DISABLE_PSI_COND
181   @sa DISABLE_PSI_FILE
182   @sa DISABLE_PSI_THREAD
183   @sa DISABLE_PSI_TABLE
184   @sa DISABLE_PSI_STAGE
185   @sa DISABLE_PSI_STATEMENT
186   @sa DISABLE_PSI_SOCKET
187   @sa DISABLE_PSI_IDLE
188 */
189 
190 #ifndef DISABLE_PSI_MUTEX
191 #define HAVE_PSI_MUTEX_INTERFACE
192 #endif
193 
194 /**
195   @def DISABLE_PSI_RWLOCK
196   Compiling option to disable the rwlock instrumentation.
197   @sa DISABLE_PSI_MUTEX
198 */
199 
200 #ifndef DISABLE_PSI_RWLOCK
201 #define HAVE_PSI_RWLOCK_INTERFACE
202 #endif
203 
204 /**
205   @def DISABLE_PSI_COND
206   Compiling option to disable the cond instrumentation.
207   @sa DISABLE_PSI_MUTEX
208 */
209 
210 #ifndef DISABLE_PSI_COND
211 #define HAVE_PSI_COND_INTERFACE
212 #endif
213 
214 /**
215   @def DISABLE_PSI_FILE
216   Compiling option to disable the file instrumentation.
217   @sa DISABLE_PSI_MUTEX
218 */
219 
220 #ifndef DISABLE_PSI_FILE
221 #define HAVE_PSI_FILE_INTERFACE
222 #endif
223 
224 /**
225   @def DISABLE_PSI_THREAD
226   Compiling option to disable the thread instrumentation.
227   @sa DISABLE_PSI_MUTEX
228 */
229 #ifndef DISABLE_PSI_THREAD
230 #define HAVE_PSI_THREAD_INTERFACE
231 #endif
232 
233 /**
234   @def DISABLE_PSI_TABLE
235   Compiling option to disable the table instrumentation.
236   @sa DISABLE_PSI_MUTEX
237 */
238 
239 #ifndef DISABLE_PSI_TABLE
240 #define HAVE_PSI_TABLE_INTERFACE
241 #endif
242 
243 /**
244   @def DISABLE_PSI_STAGE
245   Compiling option to disable the stage instrumentation.
246   @sa DISABLE_PSI_MUTEX
247 */
248 
249 #ifndef DISABLE_PSI_STAGE
250 #define HAVE_PSI_STAGE_INTERFACE
251 #endif
252 
253 /**
254   @def DISABLE_PSI_STATEMENT
255   Compiling option to disable the statement instrumentation.
256   @sa DISABLE_PSI_MUTEX
257 */
258 
259 #ifndef DISABLE_PSI_STATEMENT
260 #define HAVE_PSI_STATEMENT_INTERFACE
261 #endif
262 
263 /**
264   @def DISABLE_PSI_STATEMENT_DIGEST
265   Compiling option to disable the statement digest instrumentation.
266 */
267 
268 #ifndef DISABLE_PSI_STATEMENT
269 #ifndef DISABLE_PSI_STATEMENT_DIGEST
270 #define HAVE_PSI_STATEMENT_DIGEST_INTERFACE
271 #endif
272 #endif
273 
274 /**
275   @def DISABLE_PSI_SOCKET
276   Compiling option to disable the statement instrumentation.
277   @sa DISABLE_PSI_MUTEX
278 */
279 
280 #ifndef DISABLE_PSI_SOCKET
281 #define HAVE_PSI_SOCKET_INTERFACE
282 #endif
283 
284 /**
285   @def DISABLE_PSI_IDLE
286   Compiling option to disable the idle instrumentation.
287   @sa DISABLE_PSI_MUTEX
288 */
289 
290 #ifndef DISABLE_PSI_IDLE
291 #define HAVE_PSI_IDLE_INTERFACE
292 #endif
293 
294 /**
295   @def PSI_VERSION_1
296   Performance Schema Interface number for version 1.
297   This version is supported.
298 */
299 #define PSI_VERSION_1 1
300 
301 /**
302   @def PSI_VERSION_2
303   Performance Schema Interface number for version 2.
304   This version is not implemented, it's a placeholder.
305 */
306 #define PSI_VERSION_2 2
307 
308 /**
309   @def PSI_CURRENT_VERSION
310   Performance Schema Interface number for the most recent version.
311   The most current version is @c PSI_VERSION_1
312 */
313 #define PSI_CURRENT_VERSION 1
314 
315 #ifndef USE_PSI_2
316 #ifndef USE_PSI_1
317 #define USE_PSI_1
318 #endif
319 #endif
320 
321 /**
322   Interface for an instrumented mutex operation.
323   This is an opaque structure.
324 */
325 struct PSI_mutex_locker;
326 typedef struct PSI_mutex_locker PSI_mutex_locker;
327 
328 /**
329   Interface for an instrumented rwlock operation.
330   This is an opaque structure.
331 */
332 struct PSI_rwlock_locker;
333 typedef struct PSI_rwlock_locker PSI_rwlock_locker;
334 
335 /**
336   Interface for an instrumented condition operation.
337   This is an opaque structure.
338 */
339 struct PSI_cond_locker;
340 typedef struct PSI_cond_locker PSI_cond_locker;
341 
342 /**
343   Interface for an instrumented file operation.
344   This is an opaque structure.
345 */
346 struct PSI_file_locker;
347 typedef struct PSI_file_locker PSI_file_locker;
348 
349 /**
350   Interface for an instrumented socket operation.
351   This is an opaque structure.
352 */
353 struct PSI_socket_locker;
354 typedef struct PSI_socket_locker PSI_socket_locker;
355 
356 /** Operation performed on an instrumented mutex. */
357 enum PSI_mutex_operation
358 {
359   /** Lock. */
360   PSI_MUTEX_LOCK= 0,
361   /** Lock attempt. */
362   PSI_MUTEX_TRYLOCK= 1
363 };
364 typedef enum PSI_mutex_operation PSI_mutex_operation;
365 
366 /** Operation performed on an instrumented rwlock. */
367 enum PSI_rwlock_operation
368 {
369   /** Read lock. */
370   PSI_RWLOCK_READLOCK= 0,
371   /** Write lock. */
372   PSI_RWLOCK_WRITELOCK= 1,
373   /** Read lock attempt. */
374   PSI_RWLOCK_TRYREADLOCK= 2,
375   /** Write lock attempt. */
376   PSI_RWLOCK_TRYWRITELOCK= 3
377 };
378 typedef enum PSI_rwlock_operation PSI_rwlock_operation;
379 
380 /** Operation performed on an instrumented condition. */
381 enum PSI_cond_operation
382 {
383   /** Wait. */
384   PSI_COND_WAIT= 0,
385   /** Wait, with timeout. */
386   PSI_COND_TIMEDWAIT= 1
387 };
388 typedef enum PSI_cond_operation PSI_cond_operation;
389 
390 /** Operation performed on an instrumented file. */
391 enum PSI_file_operation
392 {
393   /** File creation, as in @c create(). */
394   PSI_FILE_CREATE= 0,
395   /** Temporary file creation, as in @c create_temp_file(). */
396   PSI_FILE_CREATE_TMP= 1,
397   /** File open, as in @c open(). */
398   PSI_FILE_OPEN= 2,
399   /** File open, as in @c fopen(). */
400   PSI_FILE_STREAM_OPEN= 3,
401   /** File close, as in @c close(). */
402   PSI_FILE_CLOSE= 4,
403   /** File close, as in @c fclose(). */
404   PSI_FILE_STREAM_CLOSE= 5,
405   /**
406     Generic file read, such as @c fgets(), @c fgetc(), @c fread(), @c read(),
407     @c pread().
408   */
409   PSI_FILE_READ= 6,
410   /**
411     Generic file write, such as @c fputs(), @c fputc(), @c fprintf(),
412     @c vfprintf(), @c fwrite(), @c write(), @c pwrite().
413   */
414   PSI_FILE_WRITE= 7,
415   /** Generic file seek, such as @c fseek() or @c seek(). */
416   PSI_FILE_SEEK= 8,
417   /** Generic file tell, such as @c ftell() or @c tell(). */
418   PSI_FILE_TELL= 9,
419   /** File flush, as in @c fflush(). */
420   PSI_FILE_FLUSH= 10,
421   /** File stat, as in @c stat(). */
422   PSI_FILE_STAT= 11,
423   /** File stat, as in @c fstat(). */
424   PSI_FILE_FSTAT= 12,
425   /** File chsize, as in @c my_chsize(). */
426   PSI_FILE_CHSIZE= 13,
427   /** File delete, such as @c my_delete() or @c my_delete_with_symlink(). */
428   PSI_FILE_DELETE= 14,
429   /** File rename, such as @c my_rename() or @c my_rename_with_symlink(). */
430   PSI_FILE_RENAME= 15,
431   /** File sync, as in @c fsync() or @c my_sync(). */
432   PSI_FILE_SYNC= 16
433 };
434 typedef enum PSI_file_operation PSI_file_operation;
435 
436 /** IO operation performed on an instrumented table. */
437 enum PSI_table_io_operation
438 {
439   /** Row fetch. */
440   PSI_TABLE_FETCH_ROW= 0,
441   /** Row write. */
442   PSI_TABLE_WRITE_ROW= 1,
443   /** Row update. */
444   PSI_TABLE_UPDATE_ROW= 2,
445   /** Row delete. */
446   PSI_TABLE_DELETE_ROW= 3
447 };
448 typedef enum PSI_table_io_operation PSI_table_io_operation;
449 
450 /** Lock operation performed on an instrumented table. */
451 enum PSI_table_lock_operation
452 {
453   /** Table lock, in the server layer. */
454   PSI_TABLE_LOCK= 0,
455   /** Table lock, in the storage engine layer. */
456   PSI_TABLE_EXTERNAL_LOCK= 1
457 };
458 typedef enum PSI_table_lock_operation PSI_table_lock_operation;
459 
460 /** State of an instrumented socket. */
461 enum PSI_socket_state
462 {
463   /** Idle, waiting for the next command. */
464   PSI_SOCKET_STATE_IDLE= 1,
465   /** Active, executing a command. */
466   PSI_SOCKET_STATE_ACTIVE= 2
467 };
468 typedef enum PSI_socket_state PSI_socket_state;
469 
470 /** Operation performed on an instrumented socket. */
471 enum PSI_socket_operation
472 {
473   /** Socket creation, as in @c socket() or @c socketpair(). */
474   PSI_SOCKET_CREATE= 0,
475   /** Socket connection, as in @c connect(), @c listen() and @c accept(). */
476   PSI_SOCKET_CONNECT= 1,
477   /** Socket bind, as in @c bind(), @c getsockname() and @c getpeername(). */
478   PSI_SOCKET_BIND= 2,
479   /** Socket close, as in @c shutdown(). */
480   PSI_SOCKET_CLOSE= 3,
481   /** Socket send, @c send(). */
482   PSI_SOCKET_SEND= 4,
483   /** Socket receive, @c recv(). */
484   PSI_SOCKET_RECV= 5,
485   /** Socket send, @c sendto(). */
486   PSI_SOCKET_SENDTO= 6,
487   /** Socket receive, @c recvfrom). */
488   PSI_SOCKET_RECVFROM= 7,
489   /** Socket send, @c sendmsg(). */
490   PSI_SOCKET_SENDMSG= 8,
491   /** Socket receive, @c recvmsg(). */
492   PSI_SOCKET_RECVMSG= 9,
493   /** Socket seek, such as @c fseek() or @c seek(). */
494   PSI_SOCKET_SEEK= 10,
495   /** Socket options, as in @c getsockopt() and @c setsockopt(). */
496   PSI_SOCKET_OPT= 11,
497   /** Socket status, as in @c sockatmark() and @c isfdtype(). */
498   PSI_SOCKET_STAT= 12,
499   /** Socket shutdown, as in @c shutdown(). */
500   PSI_SOCKET_SHUTDOWN= 13,
501   /** Socket select, as in @c select() and @c poll(). */
502   PSI_SOCKET_SELECT= 14
503 };
504 typedef enum PSI_socket_operation PSI_socket_operation;
505 
506 /**
507   Instrumented mutex key.
508   To instrument a mutex, a mutex key must be obtained using @c register_mutex.
509   Using a zero key always disable the instrumentation.
510 */
511 typedef unsigned int PSI_mutex_key;
512 
513 /**
514   Instrumented rwlock key.
515   To instrument a rwlock, a rwlock key must be obtained
516   using @c register_rwlock.
517   Using a zero key always disable the instrumentation.
518 */
519 typedef unsigned int PSI_rwlock_key;
520 
521 /**
522   Instrumented cond key.
523   To instrument a condition, a condition key must be obtained
524   using @c register_cond.
525   Using a zero key always disable the instrumentation.
526 */
527 typedef unsigned int PSI_cond_key;
528 
529 /**
530   Instrumented thread key.
531   To instrument a thread, a thread key must be obtained
532   using @c register_thread.
533   Using a zero key always disable the instrumentation.
534 */
535 typedef unsigned int PSI_thread_key;
536 
537 /**
538   Instrumented file key.
539   To instrument a file, a file key must be obtained using @c register_file.
540   Using a zero key always disable the instrumentation.
541 */
542 typedef unsigned int PSI_file_key;
543 
544 /**
545   Instrumented stage key.
546   To instrument a stage, a stage key must be obtained using @c register_stage.
547   Using a zero key always disable the instrumentation.
548 */
549 typedef unsigned int PSI_stage_key;
550 
551 /**
552   Instrumented statement key.
553   To instrument a statement, a statement key must be obtained using @c register_statement.
554   Using a zero key always disable the instrumentation.
555 */
556 typedef unsigned int PSI_statement_key;
557 
558 /**
559   Instrumented socket key.
560   To instrument a socket, a socket key must be obtained using @c register_socket.
561   Using a zero key always disable the instrumentation.
562 */
563 typedef unsigned int PSI_socket_key;
564 
565 /**
566   @def USE_PSI_1
567   Define USE_PSI_1 to use the interface version 1.
568 */
569 
570 /**
571   @def USE_PSI_2
572   Define USE_PSI_2 to use the interface version 2.
573 */
574 
575 /**
576   @def HAVE_PSI_1
577   Define HAVE_PSI_1 if the interface version 1 needs to be compiled in.
578 */
579 
580 /**
581   @def HAVE_PSI_2
582   Define HAVE_PSI_2 if the interface version 2 needs to be compiled in.
583 */
584 
585 /**
586   Global flag.
587   This flag indicate that an instrumentation point is a global variable,
588   or a singleton.
589 */
590 #define PSI_FLAG_GLOBAL (1 << 0)
591 
592 /**
593   Global flag.
594   This flag indicate that an instrumentation point is a general placeholder,
595   that can mutate into a more specific instrumentation point.
596 */
597 #define PSI_FLAG_MUTABLE (1 << 1)
598 
599 #ifdef USE_PSI_1
600 #define HAVE_PSI_1
601 #endif
602 
603 #ifdef HAVE_PSI_1
604 
605 /**
606   @defgroup Group_PSI_v1 Application Binary Interface, version 1
607   @ingroup Instrumentation_interface
608   @{
609 */
610 
611 /**
612   Mutex information.
613   @since PSI_VERSION_1
614   This structure is used to register an instrumented mutex.
615 */
616 struct PSI_mutex_info_v1
617 {
618   /**
619     Pointer to the key assigned to the registered mutex.
620   */
621   PSI_mutex_key *m_key;
622   /**
623     The name of the mutex to register.
624   */
625   const char *m_name;
626   /**
627     The flags of the mutex to register.
628     @sa PSI_FLAG_GLOBAL
629   */
630   int m_flags;
631 };
632 
633 /**
634   Rwlock information.
635   @since PSI_VERSION_1
636   This structure is used to register an instrumented rwlock.
637 */
638 struct PSI_rwlock_info_v1
639 {
640   /**
641     Pointer to the key assigned to the registered rwlock.
642   */
643   PSI_rwlock_key *m_key;
644   /**
645     The name of the rwlock to register.
646   */
647   const char *m_name;
648   /**
649     The flags of the rwlock to register.
650     @sa PSI_FLAG_GLOBAL
651   */
652   int m_flags;
653 };
654 
655 /**
656   Condition information.
657   @since PSI_VERSION_1
658   This structure is used to register an instrumented cond.
659 */
660 struct PSI_cond_info_v1
661 {
662   /**
663     Pointer to the key assigned to the registered cond.
664   */
665   PSI_cond_key *m_key;
666   /**
667     The name of the cond to register.
668   */
669   const char *m_name;
670   /**
671     The flags of the cond to register.
672     @sa PSI_FLAG_GLOBAL
673   */
674   int m_flags;
675 };
676 
677 /**
678   Thread instrument information.
679   @since PSI_VERSION_1
680   This structure is used to register an instrumented thread.
681 */
682 struct PSI_thread_info_v1
683 {
684   /**
685     Pointer to the key assigned to the registered thread.
686   */
687   PSI_thread_key *m_key;
688   /**
689     The name of the thread instrument to register.
690   */
691   const char *m_name;
692   /**
693     The flags of the thread to register.
694     @sa PSI_FLAG_GLOBAL
695   */
696   int m_flags;
697 };
698 
699 /**
700   File instrument information.
701   @since PSI_VERSION_1
702   This structure is used to register an instrumented file.
703 */
704 struct PSI_file_info_v1
705 {
706   /**
707     Pointer to the key assigned to the registered file.
708   */
709   PSI_file_key *m_key;
710   /**
711     The name of the file instrument to register.
712   */
713   const char *m_name;
714   /**
715     The flags of the file instrument to register.
716     @sa PSI_FLAG_GLOBAL
717   */
718   int m_flags;
719 };
720 
721 /**
722   Stage instrument information.
723   @since PSI_VERSION_1
724   This structure is used to register an instrumented stage.
725 */
726 struct PSI_stage_info_v1
727 {
728   /** The registered stage key. */
729   PSI_stage_key m_key;
730   /** The name of the stage instrument to register. */
731   const char *m_name;
732   /** The flags of the stage instrument to register. */
733   int m_flags;
734 };
735 
736 /**
737   Statement instrument information.
738   @since PSI_VERSION_1
739   This structure is used to register an instrumented statement.
740 */
741 struct PSI_statement_info_v1
742 {
743   /** The registered statement key. */
744   PSI_statement_key m_key;
745   /** The name of the statement instrument to register. */
746   const char *m_name;
747   /** The flags of the statement instrument to register. */
748   int m_flags;
749 };
750 
751 /**
752   Socket instrument information.
753   @since PSI_VERSION_1
754   This structure is used to register an instrumented socket.
755 */
756 struct PSI_socket_info_v1
757 {
758   /**
759     Pointer to the key assigned to the registered socket.
760   */
761   PSI_socket_key *m_key;
762   /**
763     The name of the socket instrument to register.
764   */
765   const char *m_name;
766   /**
767     The flags of the socket instrument to register.
768     @sa PSI_FLAG_GLOBAL
769   */
770   int m_flags;
771 };
772 
773 /**
774   State data storage for @c start_idle_wait_v1_t.
775   This structure provide temporary storage to an idle locker.
776   The content of this structure is considered opaque,
777   the fields are only hints of what an implementation
778   of the psi interface can use.
779   This memory is provided by the instrumented code for performance reasons.
780   @sa start_idle_wait_v1_t.
781 */
782 struct PSI_idle_locker_state_v1
783 {
784   /** Internal state. */
785   uint m_flags;
786   /** Current thread. */
787   struct PSI_thread *m_thread;
788   /** Timer start. */
789   ulonglong m_timer_start;
790   /** Timer function. */
791   ulonglong (*m_timer)(void);
792   /** Internal data. */
793   void *m_wait;
794 };
795 
796 /**
797   State data storage for @c start_mutex_wait_v1_t.
798   This structure provide temporary storage to a mutex locker.
799   The content of this structure is considered opaque,
800   the fields are only hints of what an implementation
801   of the psi interface can use.
802   This memory is provided by the instrumented code for performance reasons.
803   @sa start_mutex_wait_v1_t
804 */
805 struct PSI_mutex_locker_state_v1
806 {
807   /** Internal state. */
808   uint m_flags;
809   /** Current operation. */
810   enum PSI_mutex_operation m_operation;
811   /** Current mutex. */
812   struct PSI_mutex *m_mutex;
813   /** Current thread. */
814   struct PSI_thread *m_thread;
815   /** Timer start. */
816   ulonglong m_timer_start;
817   /** Timer function. */
818   ulonglong (*m_timer)(void);
819   /** Internal data. */
820   void *m_wait;
821 };
822 
823 /**
824   State data storage for @c start_rwlock_rdwait_v1_t, @c start_rwlock_wrwait_v1_t.
825   This structure provide temporary storage to a rwlock locker.
826   The content of this structure is considered opaque,
827   the fields are only hints of what an implementation
828   of the psi interface can use.
829   This memory is provided by the instrumented code for performance reasons.
830   @sa start_rwlock_rdwait_v1_t
831   @sa start_rwlock_wrwait_v1_t
832 */
833 struct PSI_rwlock_locker_state_v1
834 {
835   /** Internal state. */
836   uint m_flags;
837   /** Current operation. */
838   enum PSI_rwlock_operation m_operation;
839   /** Current rwlock. */
840   struct PSI_rwlock *m_rwlock;
841   /** Current thread. */
842   struct PSI_thread *m_thread;
843   /** Timer start. */
844   ulonglong m_timer_start;
845   /** Timer function. */
846   ulonglong (*m_timer)(void);
847   /** Internal data. */
848   void *m_wait;
849 };
850 
851 /**
852   State data storage for @c start_cond_wait_v1_t.
853   This structure provide temporary storage to a condition locker.
854   The content of this structure is considered opaque,
855   the fields are only hints of what an implementation
856   of the psi interface can use.
857   This memory is provided by the instrumented code for performance reasons.
858   @sa start_cond_wait_v1_t
859 */
860 struct PSI_cond_locker_state_v1
861 {
862   /** Internal state. */
863   uint m_flags;
864   /** Current operation. */
865   enum PSI_cond_operation m_operation;
866   /** Current condition. */
867   struct PSI_cond *m_cond;
868   /** Current mutex. */
869   struct PSI_mutex *m_mutex;
870   /** Current thread. */
871   struct PSI_thread *m_thread;
872   /** Timer start. */
873   ulonglong m_timer_start;
874   /** Timer function. */
875   ulonglong (*m_timer)(void);
876   /** Internal data. */
877   void *m_wait;
878 };
879 
880 /**
881   State data storage for @c get_thread_file_name_locker_v1_t.
882   This structure provide temporary storage to a file locker.
883   The content of this structure is considered opaque,
884   the fields are only hints of what an implementation
885   of the psi interface can use.
886   This memory is provided by the instrumented code for performance reasons.
887   @sa get_thread_file_name_locker_v1_t
888   @sa get_thread_file_stream_locker_v1_t
889   @sa get_thread_file_descriptor_locker_v1_t
890 */
891 struct PSI_file_locker_state_v1
892 {
893   /** Internal state. */
894   uint m_flags;
895   /** Current operation. */
896   enum PSI_file_operation m_operation;
897   /** Current file. */
898   struct PSI_file *m_file;
899   /** Current file name. */
900   const char *m_name;
901   /** Current file class. */
902   void *m_class;
903   /** Current thread. */
904   struct PSI_thread *m_thread;
905   /** Operation number of bytes. */
906   size_t m_number_of_bytes;
907   /** Timer start. */
908   ulonglong m_timer_start;
909   /** Timer function. */
910   ulonglong (*m_timer)(void);
911   /** Internal data. */
912   void *m_wait;
913 };
914 
915 /**
916   State data storage for @c start_table_io_wait_v1_t,
917   @c start_table_lock_wait_v1_t.
918   This structure provide temporary storage to a table locker.
919   The content of this structure is considered opaque,
920   the fields are only hints of what an implementation
921   of the psi interface can use.
922   This memory is provided by the instrumented code for performance reasons.
923   @sa start_table_io_wait_v1_t
924   @sa start_table_lock_wait_v1_t
925 */
926 struct PSI_table_locker_state_v1
927 {
928   /** Internal state. */
929   uint m_flags;
930   /** Current io operation. */
931   enum PSI_table_io_operation m_io_operation;
932   /** Current table handle. */
933   struct PSI_table *m_table;
934   /** Current table share. */
935   struct PSI_table_share *m_table_share;
936   /** Current thread. */
937   struct PSI_thread *m_thread;
938   /** Timer start. */
939   ulonglong m_timer_start;
940   /** Timer function. */
941   ulonglong (*m_timer)(void);
942   /** Internal data. */
943   void *m_wait;
944   /**
945     Implementation specific.
946     For table io, the table io index.
947     For table lock, the lock type.
948   */
949   uint m_index;
950 };
951 
952 /* Duplicate of NAME_LEN, to avoid dependency on mysql_com.h */
953 #define PSI_SCHEMA_NAME_LEN (64 * 3)
954 
955 /**
956   State data storage for @c get_thread_statement_locker_v1_t,
957   @c get_thread_statement_locker_v1_t.
958   This structure provide temporary storage to a statement locker.
959   The content of this structure is considered opaque,
960   the fields are only hints of what an implementation
961   of the psi interface can use.
962   This memory is provided by the instrumented code for performance reasons.
963   @sa get_thread_statement_locker_v1_t
964 */
965 struct PSI_statement_locker_state_v1
966 {
967   /** Discarded flag. */
968   my_bool m_discarded;
969   /** Metric, no index used flag. */
970   uchar m_no_index_used;
971   /** Metric, no good index used flag. */
972   uchar m_no_good_index_used;
973   /** Internal state. */
974   uint m_flags;
975   /** Instrumentation class. */
976   void *m_class;
977   /** Current thread. */
978   struct PSI_thread *m_thread;
979   /** Timer start. */
980   ulonglong m_timer_start;
981   /** Timer function. */
982   ulonglong (*m_timer)(void);
983   /** Internal data. */
984   void *m_statement;
985   /** Locked time. */
986   ulonglong m_lock_time;
987   /** Rows sent. */
988   ulonglong m_rows_sent;
989   /** Rows examined. */
990   ulonglong m_rows_examined;
991   /** Metric, temporary tables created on disk. */
992   ulong m_created_tmp_disk_tables;
993   /** Metric, temporary tables created. */
994   ulong m_created_tmp_tables;
995   /** Metric, number of select full join. */
996   ulong m_select_full_join;
997   /** Metric, number of select full range join. */
998   ulong m_select_full_range_join;
999   /** Metric, number of select range. */
1000   ulong m_select_range;
1001   /** Metric, number of select range check. */
1002   ulong m_select_range_check;
1003   /** Metric, number of select scan. */
1004   ulong m_select_scan;
1005   /** Metric, number of sort merge passes. */
1006   ulong m_sort_merge_passes;
1007   /** Metric, number of sort merge. */
1008   ulong m_sort_range;
1009   /** Metric, number of sort rows. */
1010   ulong m_sort_rows;
1011   /** Metric, number of sort scans. */
1012   ulong m_sort_scan;
1013   /** Statement digest. */
1014   const struct sql_digest_storage *m_digest;
1015   /** Current schema name. */
1016   char m_schema_name[PSI_SCHEMA_NAME_LEN];
1017   /** Length in bytes of @c m_schema_name. */
1018   uint m_schema_name_length;
1019   /** Statement character set number. */
1020   uint m_cs_number;
1021 };
1022 
1023 /**
1024   State data storage for @c start_socket_wait_v1_t.
1025   This structure provide temporary storage to a socket locker.
1026   The content of this structure is considered opaque,
1027   the fields are only hints of what an implementation
1028   of the psi interface can use.
1029   This memory is provided by the instrumented code for performance reasons.
1030   @sa start_socket_wait_v1_t
1031 */
1032 struct PSI_socket_locker_state_v1
1033 {
1034   /** Internal state. */
1035   uint m_flags;
1036   /** Current socket. */
1037   struct PSI_socket *m_socket;
1038   /** Current thread. */
1039   struct PSI_thread *m_thread;
1040   /** Operation number of bytes. */
1041   size_t m_number_of_bytes;
1042   /** Timer start. */
1043   ulonglong m_timer_start;
1044   /** Timer function. */
1045   ulonglong (*m_timer)(void);
1046   /** Current operation. */
1047   enum PSI_socket_operation m_operation;
1048   /** Source file. */
1049   const char* m_src_file;
1050   /** Source line number. */
1051   int m_src_line;
1052   /** Internal data. */
1053   void *m_wait;
1054 };
1055 
1056 /* Using typedef to make reuse between PSI_v1 and PSI_v2 easier later. */
1057 
1058 /**
1059   Mutex registration API.
1060   @param category a category name (typically a plugin name)
1061   @param info an array of mutex info to register
1062   @param count the size of the info array
1063 */
1064 typedef void (*register_mutex_v1_t)
1065   (const char *category, struct PSI_mutex_info_v1 *info, int count);
1066 
1067 /**
1068   Rwlock registration API.
1069   @param category a category name (typically a plugin name)
1070   @param info an array of rwlock info to register
1071   @param count the size of the info array
1072 */
1073 typedef void (*register_rwlock_v1_t)
1074   (const char *category, struct PSI_rwlock_info_v1 *info, int count);
1075 
1076 /**
1077   Cond registration API.
1078   @param category a category name (typically a plugin name)
1079   @param info an array of cond info to register
1080   @param count the size of the info array
1081 */
1082 typedef void (*register_cond_v1_t)
1083   (const char *category, struct PSI_cond_info_v1 *info, int count);
1084 
1085 /**
1086   Thread registration API.
1087   @param category a category name (typically a plugin name)
1088   @param info an array of thread info to register
1089   @param count the size of the info array
1090 */
1091 typedef void (*register_thread_v1_t)
1092   (const char *category, struct PSI_thread_info_v1 *info, int count);
1093 
1094 /**
1095   File registration API.
1096   @param category a category name (typically a plugin name)
1097   @param info an array of file info to register
1098   @param count the size of the info array
1099 */
1100 typedef void (*register_file_v1_t)
1101   (const char *category, struct PSI_file_info_v1 *info, int count);
1102 
1103 /**
1104   Stage registration API.
1105   @param category a category name
1106   @param info an array of stage info to register
1107   @param count the size of the info array
1108 */
1109 typedef void (*register_stage_v1_t)
1110   (const char *category, struct PSI_stage_info_v1 **info, int count);
1111 
1112 /**
1113   Statement registration API.
1114   @param category a category name
1115   @param info an array of stage info to register
1116   @param count the size of the info array
1117 */
1118 typedef void (*register_statement_v1_t)
1119   (const char *category, struct PSI_statement_info_v1 *info, int count);
1120 
1121 /**
1122   Socket registration API.
1123   @param category a category name (typically a plugin name)
1124   @param info an array of socket info to register
1125   @param count the size of the info array
1126 */
1127 typedef void (*register_socket_v1_t)
1128   (const char *category, struct PSI_socket_info_v1 *info, int count);
1129 
1130 /**
1131   Mutex instrumentation initialisation API.
1132   @param key the registered mutex key
1133   @param identity the address of the mutex itself
1134   @return an instrumented mutex
1135 */
1136 typedef struct PSI_mutex* (*init_mutex_v1_t)
1137   (PSI_mutex_key key, const void *identity);
1138 
1139 /**
1140   Mutex instrumentation destruction API.
1141   @param mutex the mutex to destroy
1142 */
1143 typedef void (*destroy_mutex_v1_t)(struct PSI_mutex *mutex);
1144 
1145 /**
1146   Rwlock instrumentation initialisation API.
1147   @param key the registered rwlock key
1148   @param identity the address of the rwlock itself
1149   @return an instrumented rwlock
1150 */
1151 typedef struct PSI_rwlock* (*init_rwlock_v1_t)
1152   (PSI_rwlock_key key, const void *identity);
1153 
1154 /**
1155   Rwlock instrumentation destruction API.
1156   @param rwlock the rwlock to destroy
1157 */
1158 typedef void (*destroy_rwlock_v1_t)(struct PSI_rwlock *rwlock);
1159 
1160 /**
1161   Cond instrumentation initialisation API.
1162   @param key the registered key
1163   @param identity the address of the rwlock itself
1164   @return an instrumented cond
1165 */
1166 typedef struct PSI_cond* (*init_cond_v1_t)
1167   (PSI_cond_key key, const void *identity);
1168 
1169 /**
1170   Cond instrumentation destruction API.
1171   @param cond the rcond to destroy
1172 */
1173 typedef void (*destroy_cond_v1_t)(struct PSI_cond *cond);
1174 
1175 /**
1176   Socket instrumentation initialisation API.
1177   @param key the registered mutex key
1178   @param socket descriptor
1179   @param addr the socket ip address
1180   @param addr_len length of socket ip address
1181   @return an instrumented socket
1182 */
1183 typedef struct PSI_socket* (*init_socket_v1_t)
1184   (PSI_socket_key key, const my_socket *fd,
1185   const struct sockaddr *addr, socklen_t addr_len);
1186 
1187 /**
1188   socket instrumentation destruction API.
1189   @param socket the socket to destroy
1190 */
1191 typedef void (*destroy_socket_v1_t)(struct PSI_socket *socket);
1192 
1193 /**
1194   Acquire a table share instrumentation.
1195   @param temporary True for temporary tables
1196   @param share The SQL layer table share
1197   @return a table share instrumentation, or NULL
1198 */
1199 typedef struct PSI_table_share* (*get_table_share_v1_t)
1200   (my_bool temporary, struct TABLE_SHARE *share);
1201 
1202 /**
1203   Release a table share.
1204   @param info the table share to release
1205 */
1206 typedef void (*release_table_share_v1_t)(struct PSI_table_share *share);
1207 
1208 /**
1209   Drop a table share.
1210   @param temporary True for temporary tables
1211   @param schema_name the table schema name
1212   @param schema_name_length the table schema name length
1213   @param table_name the table name
1214   @param table_name_length the table name length
1215 */
1216 typedef void (*drop_table_share_v1_t)
1217   (my_bool temporary, const char *schema_name, int schema_name_length,
1218    const char *table_name, int table_name_length);
1219 
1220 /**
1221   Open an instrumentation table handle.
1222   @param share the table to open
1223   @param identity table handle identity
1224   @return a table handle, or NULL
1225 */
1226 typedef struct PSI_table* (*open_table_v1_t)
1227   (struct PSI_table_share *share, const void *identity);
1228 
1229 /**
1230   Unbind a table handle from the current thread.
1231   This operation happens when an opened table is added to the open table cache.
1232   @param table the table to unbind
1233 */
1234 typedef void (*unbind_table_v1_t)
1235   (struct PSI_table *table);
1236 
1237 /**
1238   Rebind a table handle to the current thread.
1239   This operation happens when a table from the open table cache
1240   is reused for a thread.
1241   @param table the table to unbind
1242 */
1243 typedef PSI_table* (*rebind_table_v1_t)
1244   (PSI_table_share *share, const void *identity, PSI_table *table);
1245 
1246 /**
1247   Close an instrumentation table handle.
1248   Note that the table handle is invalid after this call.
1249   @param table the table handle to close
1250 */
1251 typedef void (*close_table_v1_t)(struct PSI_table *table);
1252 
1253 /**
1254   Create a file instrumentation for a created file.
1255   This method does not create the file itself, but is used to notify the
1256   instrumentation interface that a file was just created.
1257   @param key the file instrumentation key for this file
1258   @param name the file name
1259   @param file the file handle
1260 */
1261 typedef void (*create_file_v1_t)(PSI_file_key key, const char *name,
1262                                  File file);
1263 
1264 /**
1265   Spawn a thread.
1266   This method creates a new thread, with instrumentation.
1267   @param key the instrumentation key for this thread
1268   @param thread the resulting thread
1269   @param attr the thread attributes
1270   @param start_routine the thread start routine
1271   @param arg the thread start routine argument
1272 */
1273 typedef int (*spawn_thread_v1_t)(PSI_thread_key key,
1274                                  pthread_t *thread,
1275                                  const pthread_attr_t *attr,
1276                                  void *(*start_routine)(void*), void *arg);
1277 
1278 /**
1279   Create instrumentation for a thread.
1280   @param key the registered key
1281   @param identity an address typical of the thread
1282   @return an instrumented thread
1283 */
1284 typedef struct PSI_thread* (*new_thread_v1_t)
1285   (PSI_thread_key key, const void *identity, ulonglong thread_id);
1286 
1287 /**
1288   Assign an id to an instrumented thread.
1289   @param thread the instrumented thread
1290   @param id the id to assign
1291 */
1292 typedef void (*set_thread_id_v1_t)(struct PSI_thread *thread,
1293                                    ulonglong id);
1294 
1295 /**
1296   Get the instrumentation for the running thread.
1297   For this function to return a result,
1298   the thread instrumentation must have been attached to the
1299   running thread using @c set_thread()
1300   @return the instrumentation for the running thread
1301 */
1302 typedef struct PSI_thread* (*get_thread_v1_t)(void);
1303 
1304 /**
1305   Assign a user name to the instrumented thread.
1306   @param user the user name
1307   @param user_len the user name length
1308 */
1309 typedef void (*set_thread_user_v1_t)(const char *user, int user_len);
1310 
1311 /**
1312   Assign a user name and host name to the instrumented thread.
1313   @param user the user name
1314   @param user_len the user name length
1315   @param host the host name
1316   @param host_len the host name length
1317 */
1318 typedef void (*set_thread_user_host_v1_t)(const char *user, int user_len,
1319                                           const char *host, int host_len);
1320 
1321 /**
1322   Assign a current database to the instrumented thread.
1323   @param db the database name
1324   @param db_len the database name length
1325 */
1326 typedef void (*set_thread_db_v1_t)(const char* db, int db_len);
1327 
1328 /**
1329   Assign a current command to the instrumented thread.
1330   @param command the current command
1331 */
1332 typedef void (*set_thread_command_v1_t)(int command);
1333 
1334 /**
1335   Assign a start time to the instrumented thread.
1336   @param start_time the thread start time
1337 */
1338 typedef void (*set_thread_start_time_v1_t)(time_t start_time);
1339 
1340 /**
1341   Assign a state to the instrumented thread.
1342   @param state the thread state
1343 */
1344 typedef void (*set_thread_state_v1_t)(const char* state);
1345 
1346 /**
1347   Assign a process info to the instrumented thread.
1348   @param info the process into string
1349   @param info_len the process into string length
1350 */
1351 typedef void (*set_thread_info_v1_t)(const char* info, uint info_len);
1352 
1353 /**
1354   Attach a thread instrumentation to the running thread.
1355   In case of thread pools, this method should be called when
1356   a worker thread picks a work item and runs it.
1357   Also, this method should be called if the instrumented code does not
1358   keep the pointer returned by @c new_thread() and relies on @c get_thread()
1359   instead.
1360   @param thread the thread instrumentation
1361 */
1362 typedef void (*set_thread_v1_t)(struct PSI_thread *thread);
1363 
1364 /** Delete the current thread instrumentation. */
1365 typedef void (*delete_current_thread_v1_t)(void);
1366 
1367 /** Delete a thread instrumentation. */
1368 typedef void (*delete_thread_v1_t)(struct PSI_thread *thread);
1369 
1370 /**
1371   Get a file instrumentation locker, for opening or creating a file.
1372   @param state data storage for the locker
1373   @param key the file instrumentation key
1374   @param op the operation to perform
1375   @param name the file name
1376   @param identity a pointer representative of this file.
1377   @return a file locker, or NULL
1378 */
1379 typedef struct PSI_file_locker* (*get_thread_file_name_locker_v1_t)
1380   (struct PSI_file_locker_state_v1 *state,
1381    PSI_file_key key, enum PSI_file_operation op, const char *name,
1382    const void *identity);
1383 
1384 /**
1385   Get a file stream instrumentation locker.
1386   @param state data storage for the locker
1387   @param file the file stream to access
1388   @param op the operation to perform
1389   @return a file locker, or NULL
1390 */
1391 typedef struct PSI_file_locker* (*get_thread_file_stream_locker_v1_t)
1392   (struct PSI_file_locker_state_v1 *state,
1393    struct PSI_file *file, enum PSI_file_operation op);
1394 
1395 /**
1396   Get a file instrumentation locker.
1397   @param state data storage for the locker
1398   @param file the file descriptor to access
1399   @param op the operation to perform
1400   @return a file locker, or NULL
1401 */
1402 typedef struct PSI_file_locker* (*get_thread_file_descriptor_locker_v1_t)
1403   (struct PSI_file_locker_state_v1 *state,
1404    File file, enum PSI_file_operation op);
1405 
1406 /**
1407   Record a mutex instrumentation unlock event.
1408   @param mutex the mutex instrumentation
1409 */
1410 typedef void (*unlock_mutex_v1_t)
1411   (struct PSI_mutex *mutex);
1412 
1413 /**
1414   Record a rwlock instrumentation unlock event.
1415   @param rwlock the rwlock instrumentation
1416 */
1417 typedef void (*unlock_rwlock_v1_t)
1418   (struct PSI_rwlock *rwlock);
1419 
1420 /**
1421   Record a condition instrumentation signal event.
1422   @param cond the cond instrumentation
1423 */
1424 typedef void (*signal_cond_v1_t)
1425   (struct PSI_cond *cond);
1426 
1427 /**
1428   Record a condition instrumentation broadcast event.
1429   @param cond the cond instrumentation
1430 */
1431 typedef void (*broadcast_cond_v1_t)
1432   (struct PSI_cond *cond);
1433 
1434 typedef struct PSI_idle_locker* (*start_idle_wait_v1_t)
1435   (struct PSI_idle_locker_state_v1 *state, const char *src_file, uint src_line);
1436 
1437 typedef void (*end_idle_wait_v1_t)
1438   (struct PSI_idle_locker *locker);
1439 
1440 /**
1441   Record a mutex instrumentation wait start event.
1442   @param state data storage for the locker
1443   @param mutex the instrumented mutex to lock
1444   @param op the operation to perform
1445   @param file the source file name
1446   @param line the source line number
1447   @return a mutex locker, or NULL
1448 */
1449 typedef struct PSI_mutex_locker* (*start_mutex_wait_v1_t)
1450   (struct PSI_mutex_locker_state_v1 *state,
1451    struct PSI_mutex *mutex,
1452    enum PSI_mutex_operation op,
1453    const char *src_file, uint src_line);
1454 
1455 /**
1456   Record a mutex instrumentation wait end event.
1457   @param locker a thread locker for the running thread
1458   @param rc the wait operation return code
1459 */
1460 typedef void (*end_mutex_wait_v1_t)
1461   (struct PSI_mutex_locker *locker, int rc);
1462 
1463 /**
1464   Record a rwlock instrumentation read wait start event.
1465   @param locker a thread locker for the running thread
1466   @param must must block: 1 for lock, 0 for trylock
1467 */
1468 typedef struct PSI_rwlock_locker* (*start_rwlock_rdwait_v1_t)
1469   (struct PSI_rwlock_locker_state_v1 *state,
1470    struct PSI_rwlock *rwlock,
1471    enum PSI_rwlock_operation op,
1472    const char *src_file, uint src_line);
1473 
1474 /**
1475   Record a rwlock instrumentation read wait end event.
1476   @param locker a thread locker for the running thread
1477   @param rc the wait operation return code
1478 */
1479 typedef void (*end_rwlock_rdwait_v1_t)
1480   (struct PSI_rwlock_locker *locker, int rc);
1481 
1482 /**
1483   Record a rwlock instrumentation write wait start event.
1484   @param locker a thread locker for the running thread
1485   @param must must block: 1 for lock, 0 for trylock
1486 */
1487 typedef struct PSI_rwlock_locker* (*start_rwlock_wrwait_v1_t)
1488   (struct PSI_rwlock_locker_state_v1 *state,
1489    struct PSI_rwlock *rwlock,
1490    enum PSI_rwlock_operation op,
1491    const char *src_file, uint src_line);
1492 
1493 /**
1494   Record a rwlock instrumentation write wait end event.
1495   @param locker a thread locker for the running thread
1496   @param rc the wait operation return code
1497 */
1498 typedef void (*end_rwlock_wrwait_v1_t)
1499   (struct PSI_rwlock_locker *locker, int rc);
1500 
1501 /**
1502   Record a condition instrumentation wait start event.
1503   @param locker a thread locker for the running thread
1504   @param must must block: 1 for wait, 0 for timedwait
1505 */
1506 typedef struct PSI_cond_locker* (*start_cond_wait_v1_t)
1507   (struct PSI_cond_locker_state_v1 *state,
1508    struct PSI_cond *cond,
1509    struct PSI_mutex *mutex,
1510    enum PSI_cond_operation op,
1511    const char *src_file, uint src_line);
1512 
1513 /**
1514   Record a condition instrumentation wait end event.
1515   @param locker a thread locker for the running thread
1516   @param rc the wait operation return code
1517 */
1518 typedef void (*end_cond_wait_v1_t)
1519   (struct PSI_cond_locker *locker, int rc);
1520 
1521 /**
1522   Record a table instrumentation io wait start event.
1523   @param locker a table locker for the running thread
1524   @param file the source file name
1525   @param line the source line number
1526 */
1527 typedef struct PSI_table_locker* (*start_table_io_wait_v1_t)
1528   (struct PSI_table_locker_state_v1 *state,
1529    struct PSI_table *table,
1530    enum PSI_table_io_operation op,
1531    uint index,
1532    const char *src_file, uint src_line);
1533 
1534 /**
1535   Record a table instrumentation io wait end event.
1536   @param locker a table locker for the running thread
1537 */
1538 typedef void (*end_table_io_wait_v1_t)(struct PSI_table_locker *locker);
1539 
1540 /**
1541   Record a table instrumentation lock wait start event.
1542   @param locker a table locker for the running thread
1543   @param file the source file name
1544   @param line the source line number
1545 */
1546 typedef struct PSI_table_locker* (*start_table_lock_wait_v1_t)
1547   (struct PSI_table_locker_state_v1 *state,
1548    struct PSI_table *table,
1549    enum PSI_table_lock_operation op,
1550    ulong flags,
1551    const char *src_file, uint src_line);
1552 
1553 /**
1554   Record a table instrumentation lock wait end event.
1555   @param locker a table locker for the running thread
1556 */
1557 typedef void (*end_table_lock_wait_v1_t)(struct PSI_table_locker *locker);
1558 
1559 /**
1560   Start a file instrumentation open operation.
1561   @param locker the file locker
1562   @param op the operation to perform
1563   @param src_file the source file name
1564   @param src_line the source line number
1565 */
1566 typedef void (*start_file_open_wait_v1_t)
1567   (struct PSI_file_locker *locker, const char *src_file, uint src_line);
1568 
1569 /**
1570   End a file instrumentation open operation, for file streams.
1571   @param locker the file locker.
1572   @param result the opened file (NULL indicates failure, non NULL success).
1573   @return an instrumented file handle
1574 */
1575 typedef struct PSI_file* (*end_file_open_wait_v1_t)
1576   (struct PSI_file_locker *locker, void *result);
1577 
1578 /**
1579   End a file instrumentation open operation, for non stream files.
1580   @param locker the file locker.
1581   @param file the file number assigned by open() or create() for this file.
1582 */
1583 typedef void (*end_file_open_wait_and_bind_to_descriptor_v1_t)
1584   (struct PSI_file_locker *locker, File file);
1585 
1586 /**
1587   Record a file instrumentation start event.
1588   @param locker a file locker for the running thread
1589   @param op file operation to be performed
1590   @param count the number of bytes requested, or 0 if not applicable
1591   @param src_file the source file name
1592   @param src_line the source line number
1593 */
1594 typedef void (*start_file_wait_v1_t)
1595   (struct PSI_file_locker *locker, size_t count,
1596    const char *src_file, uint src_line);
1597 
1598 /**
1599   Record a file instrumentation end event.
1600   Note that for file close operations, the instrumented file handle
1601   associated with the file (which was provided to obtain a locker)
1602   is invalid after this call.
1603   @param locker a file locker for the running thread
1604   @param count the number of bytes actually used in the operation,
1605   or 0 if not applicable, or -1 if the operation failed
1606   @sa get_thread_file_name_locker
1607   @sa get_thread_file_stream_locker
1608   @sa get_thread_file_descriptor_locker
1609 */
1610 typedef void (*end_file_wait_v1_t)
1611   (struct PSI_file_locker *locker, size_t count);
1612 
1613 /**
1614   Start a file instrumentation close operation.
1615   @param locker the file locker
1616   @param op the operation to perform
1617   @param src_file the source file name
1618   @param src_line the source line number
1619 */
1620 typedef void (*start_file_close_wait_v1_t)
1621   (struct PSI_file_locker *locker, const char *src_file, uint src_line);
1622 
1623 /**
1624   End a file instrumentation close operation.
1625   @param locker the file locker.
1626   @param rc the close operation return code (0 for success).
1627   @return an instrumented file handle
1628 */
1629 typedef void (*end_file_close_wait_v1_t)
1630   (struct PSI_file_locker *locker, int rc);
1631 
1632 /**
1633   Start a new stage, and implicitly end the previous stage.
1634   @param key the key of the new stage
1635   @param src_file the source file name
1636   @param src_line the source line number
1637 */
1638 typedef void (*start_stage_v1_t)
1639   (PSI_stage_key key, const char *src_file, int src_line);
1640 
1641 /** End the current stage. */
1642 typedef void (*end_stage_v1_t) (void);
1643 
1644 /**
1645   Get a statement instrumentation locker.
1646   @param state data storage for the locker
1647   @param key the statement instrumentation key
1648   @param charset client character set
1649   @return a statement locker, or NULL
1650 */
1651 typedef struct PSI_statement_locker* (*get_thread_statement_locker_v1_t)
1652   (struct PSI_statement_locker_state_v1 *state,
1653    PSI_statement_key key, const void *charset);
1654 
1655 /**
1656   Refine a statement locker to a more specific key.
1657   Note that only events declared mutable can be refined.
1658   @param the statement locker for the current event
1659   @param key the new key for the event
1660   @sa PSI_FLAG_MUTABLE
1661 */
1662 typedef struct PSI_statement_locker* (*refine_statement_v1_t)
1663   (struct PSI_statement_locker *locker,
1664    PSI_statement_key key);
1665 
1666 /**
1667   Start a new statement event.
1668   @param locker the statement locker for this event
1669   @param db the active database name for this statement
1670   @param db_length the active database name length for this statement
1671   @param src_file source file name
1672   @param src_line source line number
1673 */
1674 typedef void (*start_statement_v1_t)
1675   (struct PSI_statement_locker *locker,
1676    const char *db, uint db_length,
1677    const char *src_file, uint src_line);
1678 
1679 /**
1680   Set the statement text for a statement event.
1681   @param locker the current statement locker
1682   @param text the statement text
1683   @param text_len the statement text length
1684 */
1685 typedef void (*set_statement_text_v1_t)
1686   (struct PSI_statement_locker *locker,
1687    const char *text, uint text_len);
1688 
1689 /**
1690   Set a statement event lock time.
1691   @param locker the statement locker
1692   @param lock_time the locked time, in microseconds
1693 */
1694 typedef void (*set_statement_lock_time_t)
1695   (struct PSI_statement_locker *locker, ulonglong lock_time);
1696 
1697 /**
1698   Set a statement event rows sent metric.
1699   @param locker the statement locker
1700   @param count the number of rows sent
1701 */
1702 typedef void (*set_statement_rows_sent_t)
1703   (struct PSI_statement_locker *locker, ulonglong count);
1704 
1705 /**
1706   Set a statement event rows examined metric.
1707   @param locker the statement locker
1708   @param count the number of rows examined
1709 */
1710 typedef void (*set_statement_rows_examined_t)
1711   (struct PSI_statement_locker *locker, ulonglong count);
1712 
1713 /**
1714   Increment a statement event "created tmp disk tables" metric.
1715   @param locker the statement locker
1716   @param count the metric increment value
1717 */
1718 typedef void (*inc_statement_created_tmp_disk_tables_t)
1719   (struct PSI_statement_locker *locker, ulong count);
1720 
1721 /**
1722   Increment a statement event "created tmp tables" metric.
1723   @param locker the statement locker
1724   @param count the metric increment value
1725 */
1726 typedef void (*inc_statement_created_tmp_tables_t)
1727   (struct PSI_statement_locker *locker, ulong count);
1728 
1729 /**
1730   Increment a statement event "select full join" metric.
1731   @param locker the statement locker
1732   @param count the metric increment value
1733 */
1734 typedef void (*inc_statement_select_full_join_t)
1735   (struct PSI_statement_locker *locker, ulong count);
1736 
1737 /**
1738   Increment a statement event "select full range join" metric.
1739   @param locker the statement locker
1740   @param count the metric increment value
1741 */
1742 typedef void (*inc_statement_select_full_range_join_t)
1743   (struct PSI_statement_locker *locker, ulong count);
1744 
1745 /**
1746   Increment a statement event "select range join" metric.
1747   @param locker the statement locker
1748   @param count the metric increment value
1749 */
1750 typedef void (*inc_statement_select_range_t)
1751   (struct PSI_statement_locker *locker, ulong count);
1752 
1753 /**
1754   Increment a statement event "select range check" metric.
1755   @param locker the statement locker
1756   @param count the metric increment value
1757 */
1758 typedef void (*inc_statement_select_range_check_t)
1759   (struct PSI_statement_locker *locker, ulong count);
1760 
1761 /**
1762   Increment a statement event "select scan" metric.
1763   @param locker the statement locker
1764   @param count the metric increment value
1765 */
1766 typedef void (*inc_statement_select_scan_t)
1767   (struct PSI_statement_locker *locker, ulong count);
1768 
1769 /**
1770   Increment a statement event "sort merge passes" metric.
1771   @param locker the statement locker
1772   @param count the metric increment value
1773 */
1774 typedef void (*inc_statement_sort_merge_passes_t)
1775   (struct PSI_statement_locker *locker, ulong count);
1776 
1777 /**
1778   Increment a statement event "sort range" metric.
1779   @param locker the statement locker
1780   @param count the metric increment value
1781 */
1782 typedef void (*inc_statement_sort_range_t)
1783   (struct PSI_statement_locker *locker, ulong count);
1784 
1785 /**
1786   Increment a statement event "sort rows" metric.
1787   @param locker the statement locker
1788   @param count the metric increment value
1789 */
1790 typedef void (*inc_statement_sort_rows_t)
1791   (struct PSI_statement_locker *locker, ulong count);
1792 
1793 /**
1794   Increment a statement event "sort scan" metric.
1795   @param locker the statement locker
1796   @param count the metric increment value
1797 */
1798 typedef void (*inc_statement_sort_scan_t)
1799   (struct PSI_statement_locker *locker, ulong count);
1800 
1801 /**
1802   Set a statement event "no index used" metric.
1803   @param locker the statement locker
1804   @param count the metric value
1805 */
1806 typedef void (*set_statement_no_index_used_t)
1807   (struct PSI_statement_locker *locker);
1808 
1809 /**
1810   Set a statement event "no good index used" metric.
1811   @param locker the statement locker
1812   @param count the metric value
1813 */
1814 typedef void (*set_statement_no_good_index_used_t)
1815   (struct PSI_statement_locker *locker);
1816 
1817 /**
1818   End a statement event.
1819   @param locker the statement locker
1820   @param stmt_da the statement diagnostics area.
1821   @sa Diagnostics_area
1822 */
1823 typedef void (*end_statement_v1_t)
1824   (struct PSI_statement_locker *locker, void *stmt_da);
1825 
1826 /**
1827   Record a socket instrumentation start event.
1828   @param locker a socket locker for the running thread
1829   @param op socket operation to be performed
1830   @param count the number of bytes requested, or 0 if not applicable
1831   @param src_file the source file name
1832   @param src_line the source line number
1833 */
1834 typedef struct PSI_socket_locker* (*start_socket_wait_v1_t)
1835   (struct PSI_socket_locker_state_v1 *state,
1836    struct PSI_socket *socket,
1837    enum PSI_socket_operation op,
1838    size_t count,
1839    const char *src_file, uint src_line);
1840 
1841 /**
1842   Record a socket instrumentation end event.
1843   Note that for socket close operations, the instrumented socket handle
1844   associated with the socket (which was provided to obtain a locker)
1845   is invalid after this call.
1846   @param locker a socket locker for the running thread
1847   @param count the number of bytes actually used in the operation,
1848   or 0 if not applicable, or -1 if the operation failed
1849   @sa get_thread_socket_locker
1850 */
1851 typedef void (*end_socket_wait_v1_t)
1852   (struct PSI_socket_locker *locker, size_t count);
1853 
1854 /**
1855   Set the socket state for an instrumented socket.
1856     @param socket the instrumented socket
1857     @param state socket state
1858   */
1859 typedef void (*set_socket_state_v1_t)(struct PSI_socket *socket,
1860                                       enum PSI_socket_state state);
1861 
1862 /**
1863   Set the socket info for an instrumented socket.
1864   @param socket the instrumented socket
1865   @param fd the socket descriptor
1866   @param addr the socket ip address
1867   @param addr_len length of socket ip address
1868   @param thread_id associated thread id
1869 */
1870 typedef void (*set_socket_info_v1_t)(struct PSI_socket *socket,
1871                                      const my_socket *fd,
1872                                      const struct sockaddr *addr,
1873                                      socklen_t addr_len);
1874 
1875 /**
1876   Bind a socket to the thread that owns it.
1877   @param socket instrumented socket
1878 */
1879 typedef void (*set_socket_thread_owner_v1_t)(struct PSI_socket *socket);
1880 
1881 /**
1882   Get a digest locker for the current statement.
1883   @param locker a statement locker for the running thread
1884 */
1885 typedef struct PSI_digest_locker * (*digest_start_v1_t)
1886   (struct PSI_statement_locker *locker);
1887 
1888 typedef void (*digest_end_v1_t)
1889   (struct PSI_digest_locker *locker, const struct sql_digest_storage *digest);
1890 
1891 /**
1892   Stores an array of connection attributes
1893   @param buffer         char array of length encoded connection attributes
1894                         in network format
1895   @param length         legnth of the data in buffer
1896   @param from_cs        charset in which @buffer is encodded
1897   @return state
1898     @retval  non-0    attributes truncated
1899     @retval  0        stored the attribute
1900 */
1901 typedef int (*set_thread_connect_attrs_v1_t)(const char *buffer, uint length,
1902                                              const void *from_cs);
1903 
1904 /**
1905   Performance Schema Interface, version 1.
1906   @since PSI_VERSION_1
1907 */
1908 struct PSI_v1
1909 {
1910   /** @sa register_mutex_v1_t. */
1911   register_mutex_v1_t register_mutex;
1912   /** @sa register_rwlock_v1_t. */
1913   register_rwlock_v1_t register_rwlock;
1914   /** @sa register_cond_v1_t. */
1915   register_cond_v1_t register_cond;
1916   /** @sa register_thread_v1_t. */
1917   register_thread_v1_t register_thread;
1918   /** @sa register_file_v1_t. */
1919   register_file_v1_t register_file;
1920   /** @sa register_stage_v1_t. */
1921   register_stage_v1_t register_stage;
1922   /** @sa register_statement_v1_t. */
1923   register_statement_v1_t register_statement;
1924   /** @sa register_socket_v1_t. */
1925   register_socket_v1_t register_socket;
1926   /** @sa init_mutex_v1_t. */
1927   init_mutex_v1_t init_mutex;
1928   /** @sa destroy_mutex_v1_t. */
1929   destroy_mutex_v1_t destroy_mutex;
1930   /** @sa init_rwlock_v1_t. */
1931   init_rwlock_v1_t init_rwlock;
1932   /** @sa destroy_rwlock_v1_t. */
1933   destroy_rwlock_v1_t destroy_rwlock;
1934   /** @sa init_cond_v1_t. */
1935   init_cond_v1_t init_cond;
1936   /** @sa destroy_cond_v1_t. */
1937   destroy_cond_v1_t destroy_cond;
1938   /** @sa init_socket_v1_t. */
1939   init_socket_v1_t init_socket;
1940   /** @sa destroy_socket_v1_t. */
1941   destroy_socket_v1_t destroy_socket;
1942   /** @sa get_table_share_v1_t. */
1943   get_table_share_v1_t get_table_share;
1944   /** @sa release_table_share_v1_t. */
1945   release_table_share_v1_t release_table_share;
1946   /** @sa drop_table_share_v1_t. */
1947   drop_table_share_v1_t drop_table_share;
1948   /** @sa open_table_v1_t. */
1949   open_table_v1_t open_table;
1950   /** @sa unbind_table_v1_t. */
1951   unbind_table_v1_t unbind_table;
1952   /** @sa rebind_table_v1_t. */
1953   rebind_table_v1_t rebind_table;
1954   /** @sa close_table_v1_t. */
1955   close_table_v1_t close_table;
1956   /** @sa create_file_v1_t. */
1957   create_file_v1_t create_file;
1958   /** @sa spawn_thread_v1_t. */
1959   spawn_thread_v1_t spawn_thread;
1960   /** @sa new_thread_v1_t. */
1961   new_thread_v1_t new_thread;
1962   /** @sa set_thread_id_v1_t. */
1963   set_thread_id_v1_t set_thread_id;
1964   /** @sa get_thread_v1_t. */
1965   get_thread_v1_t get_thread;
1966   /** @sa set_thread_user_v1_t. */
1967   set_thread_user_v1_t set_thread_user;
1968   /** @sa set_thread_user_host_v1_t. */
1969   set_thread_user_host_v1_t set_thread_user_host;
1970   /** @sa set_thread_db_v1_t. */
1971   set_thread_db_v1_t set_thread_db;
1972   /** @sa set_thread_command_v1_t. */
1973   set_thread_command_v1_t set_thread_command;
1974   /** @sa set_thread_start_time_v1_t. */
1975   set_thread_start_time_v1_t set_thread_start_time;
1976   /** @sa set_thread_state_v1_t. */
1977   set_thread_state_v1_t set_thread_state;
1978   /** @sa set_thread_info_v1_t. */
1979   set_thread_info_v1_t set_thread_info;
1980   /** @sa set_thread_v1_t. */
1981   set_thread_v1_t set_thread;
1982   /** @sa delete_current_thread_v1_t. */
1983   delete_current_thread_v1_t delete_current_thread;
1984   /** @sa delete_thread_v1_t. */
1985   delete_thread_v1_t delete_thread;
1986   /** @sa get_thread_file_name_locker_v1_t. */
1987   get_thread_file_name_locker_v1_t get_thread_file_name_locker;
1988   /** @sa get_thread_file_stream_locker_v1_t. */
1989   get_thread_file_stream_locker_v1_t get_thread_file_stream_locker;
1990   /** @sa get_thread_file_descriptor_locker_v1_t. */
1991   get_thread_file_descriptor_locker_v1_t get_thread_file_descriptor_locker;
1992   /** @sa unlock_mutex_v1_t. */
1993   unlock_mutex_v1_t unlock_mutex;
1994   /** @sa unlock_rwlock_v1_t. */
1995   unlock_rwlock_v1_t unlock_rwlock;
1996   /** @sa signal_cond_v1_t. */
1997   signal_cond_v1_t signal_cond;
1998   /** @sa broadcast_cond_v1_t. */
1999   broadcast_cond_v1_t broadcast_cond;
2000   /** @sa start_idle_wait_v1_t. */
2001   start_idle_wait_v1_t start_idle_wait;
2002   /** @sa end_idle_wait_v1_t. */
2003   end_idle_wait_v1_t end_idle_wait;
2004   /** @sa start_mutex_wait_v1_t. */
2005   start_mutex_wait_v1_t start_mutex_wait;
2006   /** @sa end_mutex_wait_v1_t. */
2007   end_mutex_wait_v1_t end_mutex_wait;
2008   /** @sa start_rwlock_rdwait_v1_t. */
2009   start_rwlock_rdwait_v1_t start_rwlock_rdwait;
2010   /** @sa end_rwlock_rdwait_v1_t. */
2011   end_rwlock_rdwait_v1_t end_rwlock_rdwait;
2012   /** @sa start_rwlock_wrwait_v1_t. */
2013   start_rwlock_wrwait_v1_t start_rwlock_wrwait;
2014   /** @sa end_rwlock_wrwait_v1_t. */
2015   end_rwlock_wrwait_v1_t end_rwlock_wrwait;
2016   /** @sa start_cond_wait_v1_t. */
2017   start_cond_wait_v1_t start_cond_wait;
2018   /** @sa end_cond_wait_v1_t. */
2019   end_cond_wait_v1_t end_cond_wait;
2020   /** @sa start_table_io_wait_v1_t. */
2021   start_table_io_wait_v1_t start_table_io_wait;
2022   /** @sa end_table_io_wait_v1_t. */
2023   end_table_io_wait_v1_t end_table_io_wait;
2024   /** @sa start_table_lock_wait_v1_t. */
2025   start_table_lock_wait_v1_t start_table_lock_wait;
2026   /** @sa end_table_lock_wait_v1_t. */
2027   end_table_lock_wait_v1_t end_table_lock_wait;
2028   /** @sa start_file_open_wait_v1_t. */
2029   start_file_open_wait_v1_t start_file_open_wait;
2030   /** @sa end_file_open_wait_v1_t. */
2031   end_file_open_wait_v1_t end_file_open_wait;
2032   /** @sa end_file_open_wait_and_bind_to_descriptor_v1_t. */
2033   end_file_open_wait_and_bind_to_descriptor_v1_t
2034     end_file_open_wait_and_bind_to_descriptor;
2035   /** @sa start_file_wait_v1_t. */
2036   start_file_wait_v1_t start_file_wait;
2037   /** @sa end_file_wait_v1_t. */
2038   end_file_wait_v1_t end_file_wait;
2039   /** @sa start_file_close_wait_v1_t. */
2040   start_file_close_wait_v1_t start_file_close_wait;
2041   /** @sa end_file_close_wait_v1_t. */
2042   end_file_close_wait_v1_t end_file_close_wait;
2043   /** @sa start_stage_v1_t. */
2044   start_stage_v1_t start_stage;
2045   /** @sa end_stage_v1_t. */
2046   end_stage_v1_t end_stage;
2047   /** @sa get_thread_statement_locker_v1_t. */
2048   get_thread_statement_locker_v1_t get_thread_statement_locker;
2049   /** @sa refine_statement_v1_t. */
2050   refine_statement_v1_t refine_statement;
2051   /** @sa start_statement_v1_t. */
2052   start_statement_v1_t start_statement;
2053   /** @sa set_statement_text_v1_t. */
2054   set_statement_text_v1_t set_statement_text;
2055   /** @sa set_statement_lock_time_t. */
2056   set_statement_lock_time_t set_statement_lock_time;
2057   /** @sa set_statement_rows_sent_t. */
2058   set_statement_rows_sent_t set_statement_rows_sent;
2059   /** @sa set_statement_rows_examined_t. */
2060   set_statement_rows_examined_t set_statement_rows_examined;
2061   /** @sa inc_statement_created_tmp_disk_tables. */
2062   inc_statement_created_tmp_disk_tables_t inc_statement_created_tmp_disk_tables;
2063   /** @sa inc_statement_created_tmp_tables. */
2064   inc_statement_created_tmp_tables_t inc_statement_created_tmp_tables;
2065   /** @sa inc_statement_select_full_join. */
2066   inc_statement_select_full_join_t inc_statement_select_full_join;
2067   /** @sa inc_statement_select_full_range_join. */
2068   inc_statement_select_full_range_join_t inc_statement_select_full_range_join;
2069   /** @sa inc_statement_select_range. */
2070   inc_statement_select_range_t inc_statement_select_range;
2071   /** @sa inc_statement_select_range_check. */
2072   inc_statement_select_range_check_t inc_statement_select_range_check;
2073   /** @sa inc_statement_select_scan. */
2074   inc_statement_select_scan_t inc_statement_select_scan;
2075   /** @sa inc_statement_sort_merge_passes. */
2076   inc_statement_sort_merge_passes_t inc_statement_sort_merge_passes;
2077   /** @sa inc_statement_sort_range. */
2078   inc_statement_sort_range_t inc_statement_sort_range;
2079   /** @sa inc_statement_sort_rows. */
2080   inc_statement_sort_rows_t inc_statement_sort_rows;
2081   /** @sa inc_statement_sort_scan. */
2082   inc_statement_sort_scan_t inc_statement_sort_scan;
2083   /** @sa set_statement_no_index_used. */
2084   set_statement_no_index_used_t set_statement_no_index_used;
2085   /** @sa set_statement_no_good_index_used. */
2086   set_statement_no_good_index_used_t set_statement_no_good_index_used;
2087   /** @sa end_statement_v1_t. */
2088   end_statement_v1_t end_statement;
2089   /** @sa start_socket_wait_v1_t. */
2090   start_socket_wait_v1_t start_socket_wait;
2091   /** @sa end_socket_wait_v1_t. */
2092   end_socket_wait_v1_t end_socket_wait;
2093   /** @sa set_socket_state_v1_t. */
2094   set_socket_state_v1_t set_socket_state;
2095   /** @sa set_socket_info_v1_t. */
2096   set_socket_info_v1_t set_socket_info;
2097   /** @sa set_socket_thread_owner_v1_t. */
2098   set_socket_thread_owner_v1_t set_socket_thread_owner;
2099   /** @sa digest_start_v1_t. */
2100   digest_start_v1_t digest_start;
2101   /** @sa digest_end_v1_t. */
2102   digest_end_v1_t digest_end;
2103   /** @sa set_thread_connect_attrs_v1_t. */
2104   set_thread_connect_attrs_v1_t set_thread_connect_attrs;
2105 };
2106 
2107 /** @} (end of group Group_PSI_v1) */
2108 
2109 #endif /* HAVE_PSI_1 */
2110 
2111 #ifdef USE_PSI_2
2112 #define HAVE_PSI_2
2113 #endif
2114 
2115 #ifdef HAVE_PSI_2
2116 
2117 /**
2118   @defgroup Group_PSI_v2 Application Binary Interface, version 2
2119   @ingroup Instrumentation_interface
2120   @{
2121 */
2122 
2123 /**
2124   Performance Schema Interface, version 2.
2125   This is a placeholder, this interface is not defined yet.
2126   @since PSI_VERSION_2
2127 */
2128 struct PSI_v2
2129 {
2130   /** Placeholder */
2131   int placeholder;
2132   /* ... extended interface ... */
2133 };
2134 
2135 /** Placeholder */
2136 struct PSI_mutex_info_v2
2137 {
2138   /** Placeholder */
2139   int placeholder;
2140 };
2141 
2142 /** Placeholder */
2143 struct PSI_rwlock_info_v2
2144 {
2145   /** Placeholder */
2146   int placeholder;
2147 };
2148 
2149 /** Placeholder */
2150 struct PSI_cond_info_v2
2151 {
2152   /** Placeholder */
2153   int placeholder;
2154 };
2155 
2156 /** Placeholder */
2157 struct PSI_thread_info_v2
2158 {
2159   /** Placeholder */
2160   int placeholder;
2161 };
2162 
2163 /** Placeholder */
2164 struct PSI_file_info_v2
2165 {
2166   /** Placeholder */
2167   int placeholder;
2168 };
2169 
2170 /** Placeholder */
2171 struct PSI_stage_info_v2
2172 {
2173   /** Placeholder */
2174   int placeholder;
2175 };
2176 
2177 /** Placeholder */
2178 struct PSI_statement_info_v2
2179 {
2180   /** Placeholder */
2181   int placeholder;
2182 };
2183 
2184 /** Placeholder */
2185 struct PSI_idle_locker_state_v2
2186 {
2187   /** Placeholder */
2188   int placeholder;
2189 };
2190 
2191 /** Placeholder */
2192 struct PSI_mutex_locker_state_v2
2193 {
2194   /** Placeholder */
2195   int placeholder;
2196 };
2197 
2198 /** Placeholder */
2199 struct PSI_rwlock_locker_state_v2
2200 {
2201   /** Placeholder */
2202   int placeholder;
2203 };
2204 
2205 /** Placeholder */
2206 struct PSI_cond_locker_state_v2
2207 {
2208   /** Placeholder */
2209   int placeholder;
2210 };
2211 
2212 /** Placeholder */
2213 struct PSI_file_locker_state_v2
2214 {
2215   /** Placeholder */
2216   int placeholder;
2217 };
2218 
2219 /** Placeholder */
2220 struct PSI_table_locker_state_v2
2221 {
2222   /** Placeholder */
2223   int placeholder;
2224 };
2225 
2226 /** Placeholder */
2227 struct PSI_statement_locker_state_v2
2228 {
2229   /** Placeholder */
2230   int placeholder;
2231 };
2232 
2233 /** Placeholder */
2234 struct PSI_socket_locker_state_v2
2235 {
2236   /** Placeholder */
2237   int placeholder;
2238 };
2239 
2240 /** @} (end of group Group_PSI_v2) */
2241 
2242 #endif /* HAVE_PSI_2 */
2243 
2244 /**
2245   @typedef PSI
2246   The instrumentation interface for the current version.
2247   @sa PSI_CURRENT_VERSION
2248 */
2249 
2250 /**
2251   @typedef PSI_mutex_info
2252   The mutex information structure for the current version.
2253 */
2254 
2255 /**
2256   @typedef PSI_rwlock_info
2257   The rwlock information structure for the current version.
2258 */
2259 
2260 /**
2261   @typedef PSI_cond_info
2262   The cond information structure for the current version.
2263 */
2264 
2265 /**
2266   @typedef PSI_thread_info
2267   The thread information structure for the current version.
2268 */
2269 
2270 /**
2271   @typedef PSI_file_info
2272   The file information structure for the current version.
2273 */
2274 
2275 /* Export the required version */
2276 #ifdef USE_PSI_1
2277 typedef struct PSI_v1 PSI;
2278 typedef struct PSI_mutex_info_v1 PSI_mutex_info;
2279 typedef struct PSI_rwlock_info_v1 PSI_rwlock_info;
2280 typedef struct PSI_cond_info_v1 PSI_cond_info;
2281 typedef struct PSI_thread_info_v1 PSI_thread_info;
2282 typedef struct PSI_file_info_v1 PSI_file_info;
2283 typedef struct PSI_stage_info_v1 PSI_stage_info;
2284 typedef struct PSI_statement_info_v1 PSI_statement_info;
2285 typedef struct PSI_socket_info_v1 PSI_socket_info;
2286 typedef struct PSI_idle_locker_state_v1 PSI_idle_locker_state;
2287 typedef struct PSI_mutex_locker_state_v1 PSI_mutex_locker_state;
2288 typedef struct PSI_rwlock_locker_state_v1 PSI_rwlock_locker_state;
2289 typedef struct PSI_cond_locker_state_v1 PSI_cond_locker_state;
2290 typedef struct PSI_file_locker_state_v1 PSI_file_locker_state;
2291 typedef struct PSI_table_locker_state_v1 PSI_table_locker_state;
2292 typedef struct PSI_statement_locker_state_v1 PSI_statement_locker_state;
2293 typedef struct PSI_socket_locker_state_v1 PSI_socket_locker_state;
2294 #endif
2295 
2296 #ifdef USE_PSI_2
2297 typedef struct PSI_v2 PSI;
2298 typedef struct PSI_mutex_info_v2 PSI_mutex_info;
2299 typedef struct PSI_rwlock_info_v2 PSI_rwlock_info;
2300 typedef struct PSI_cond_info_v2 PSI_cond_info;
2301 typedef struct PSI_thread_info_v2 PSI_thread_info;
2302 typedef struct PSI_file_info_v2 PSI_file_info;
2303 typedef struct PSI_stage_info_v2 PSI_stage_info;
2304 typedef struct PSI_statement_info_v2 PSI_statement_info;
2305 typedef struct PSI_socket_info_v2 PSI_socket_info;
2306 typedef struct PSI_idle_locker_state_v2 PSI_idle_locker_state;
2307 typedef struct PSI_mutex_locker_state_v2 PSI_mutex_locker_state;
2308 typedef struct PSI_rwlock_locker_state_v2 PSI_rwlock_locker_state;
2309 typedef struct PSI_cond_locker_state_v2 PSI_cond_locker_state;
2310 typedef struct PSI_file_locker_state_v2 PSI_file_locker_state;
2311 typedef struct PSI_table_locker_state_v2 PSI_table_locker_state;
2312 typedef struct PSI_statement_locker_state_v2 PSI_statement_locker_state;
2313 typedef struct PSI_socket_locker_state_v2 PSI_socket_locker_state;
2314 #endif
2315 
2316 #else /* HAVE_PSI_INTERFACE */
2317 
2318 /**
2319   Dummy structure, used to declare PSI_server when no instrumentation
2320   is available.
2321   The content does not matter, since PSI_server will be NULL.
2322 */
2323 struct PSI_none
2324 {
2325   int opaque;
2326 };
2327 typedef struct PSI_none PSI;
2328 
2329 /**
2330   Stage instrument information.
2331   @since PSI_VERSION_1
2332   This structure is used to register an instrumented stage.
2333 */
2334 struct PSI_stage_info_none
2335 {
2336   /** Unused stage key. */
2337   unsigned int m_key;
2338   /** The name of the stage instrument. */
2339   const char *m_name;
2340   /** Unused stage flags. */
2341   int m_flags;
2342 };
2343 
2344 /**
2345   The stage instrumentation has to co exist with the legacy
2346   THD::set_proc_info instrumentation.
2347   To avoid duplication of the instrumentation in the server,
2348   the common PSI_stage_info structure is used,
2349   so we export it here, even when not building
2350   with HAVE_PSI_INTERFACE.
2351 */
2352 typedef struct PSI_stage_info_none PSI_stage_info;
2353 
2354 #endif /* HAVE_PSI_INTERFACE */
2355 
2356 extern MYSQL_PLUGIN_IMPORT PSI *PSI_server;
2357 
2358 /*
2359   Allow to override PSI_XXX_CALL at compile time
2360   with more efficient implementations, if available.
2361   If nothing better is available,
2362   make a dynamic call using the PSI_server function pointer.
2363 */
2364 
2365 #ifndef PSI_MUTEX_CALL
2366 #define PSI_MUTEX_CALL(M) PSI_DYNAMIC_CALL(M)
2367 #endif
2368 
2369 #ifndef PSI_RWLOCK_CALL
2370 #define PSI_RWLOCK_CALL(M) PSI_DYNAMIC_CALL(M)
2371 #endif
2372 
2373 #ifndef PSI_COND_CALL
2374 #define PSI_COND_CALL(M) PSI_DYNAMIC_CALL(M)
2375 #endif
2376 
2377 #ifndef PSI_THREAD_CALL
2378 #define PSI_THREAD_CALL(M) PSI_DYNAMIC_CALL(M)
2379 #endif
2380 
2381 #ifndef PSI_FILE_CALL
2382 #define PSI_FILE_CALL(M) PSI_DYNAMIC_CALL(M)
2383 #endif
2384 
2385 #ifndef PSI_SOCKET_CALL
2386 #define PSI_SOCKET_CALL(M) PSI_DYNAMIC_CALL(M)
2387 #endif
2388 
2389 #ifndef PSI_STAGE_CALL
2390 #define PSI_STAGE_CALL(M) PSI_DYNAMIC_CALL(M)
2391 #endif
2392 
2393 #ifndef PSI_STATEMENT_CALL
2394 #define PSI_STATEMENT_CALL(M) PSI_DYNAMIC_CALL(M)
2395 #endif
2396 
2397 #ifndef PSI_DIGEST_CALL
2398 #define PSI_DIGEST_CALL(M) PSI_DYNAMIC_CALL(M)
2399 #endif
2400 
2401 #ifndef PSI_TABLE_CALL
2402 #define PSI_TABLE_CALL(M) PSI_DYNAMIC_CALL(M)
2403 #endif
2404 
2405 #ifndef PSI_IDLE_CALL
2406 #define PSI_IDLE_CALL(M) PSI_DYNAMIC_CALL(M)
2407 #endif
2408 
2409 #define PSI_DYNAMIC_CALL(M) PSI_server->M
2410 
2411 /** @} */
2412 
2413 C_MODE_END
2414 #endif /* MYSQL_PERFORMANCE_SCHEMA_INTERFACE_H */
2415 
2416