OSDN Git Service

First version
[st-ro/stro.git] / 3rdparty / mysql / include / mysql / psi / psi.h
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 as published by
5   the Free Software Foundation; version 2 of the License.
6
7   This program is distributed in the hope that it will be useful,
8   but WITHOUT ANY WARRANTY; without even the implied warranty of
9   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10   GNU General Public License for more details.
11
12   You should have received a copy of the GNU General Public License
13   along with this program; if not, write to the Free Software Foundation,
14   51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
15
16 #ifndef MYSQL_PERFORMANCE_SCHEMA_INTERFACE_H
17 #define MYSQL_PERFORMANCE_SCHEMA_INTERFACE_H
18
19 #ifdef EMBEDDED_LIBRARY
20 #define DISABLE_ALL_PSI
21 #endif /* EMBEDDED_LIBRARY */
22
23 #ifndef MY_GLOBAL_INCLUDED
24 /*
25   Make sure a .c or .cc file contains an include to my_global.h first.
26   When this include is missing, all the #ifdef HAVE_XXX have no effect,
27   and the resulting binary won't build, or won't link,
28   or will crash at runtime
29   since various structures will have different binary definitions.
30 */
31 #error "You must include my_global.h in the code for the build to be correct."
32 #endif
33
34 #include "psi_base.h"
35 #include "psi_memory.h"
36
37 /*
38   MAINTAINER:
39   The following pattern:
40     typedef struct XYZ XYZ;
41   is not needed in C++, but required for C.
42 */
43
44 C_MODE_START
45
46 /** @sa MDL_key. */
47 struct MDL_key;
48 typedef struct MDL_key MDL_key;
49
50 /** @sa enum_mdl_type. */
51 typedef int opaque_mdl_type;
52
53 /** @sa enum_mdl_duration. */
54 typedef int opaque_mdl_duration;
55
56 /** @sa MDL_wait::enum_wait_status. */
57 typedef int opaque_mdl_status;
58
59 /** @sa enum_vio_type. */
60 typedef int opaque_vio_type;
61
62 struct TABLE_SHARE;
63
64 struct sql_digest_storage;
65
66 #ifdef __cplusplus
67   class THD;
68 #else
69   /*
70     Phony declaration when compiling C code.
71     This is ok, because the C code will never have a THD anyway.
72   */
73   struct opaque_THD
74   {
75     int dummy;
76   };
77   typedef struct opaque_THD THD;
78 #endif
79
80 /**
81   @file mysql/psi/psi.h
82   Performance schema instrumentation interface.
83
84   @defgroup Instrumentation_interface Instrumentation Interface
85   @ingroup Performance_schema
86   @{
87 */
88
89 /**
90   Interface for an instrumented mutex.
91   This is an opaque structure.
92 */
93 struct PSI_mutex;
94 typedef struct PSI_mutex PSI_mutex;
95
96 /**
97   Interface for an instrumented rwlock.
98   This is an opaque structure.
99 */
100 struct PSI_rwlock;
101 typedef struct PSI_rwlock PSI_rwlock;
102
103 /**
104   Interface for an instrumented condition.
105   This is an opaque structure.
106 */
107 struct PSI_cond;
108 typedef struct PSI_cond PSI_cond;
109
110 /**
111   Interface for an instrumented table share.
112   This is an opaque structure.
113 */
114 struct PSI_table_share;
115 typedef struct PSI_table_share PSI_table_share;
116
117 /**
118   Interface for an instrumented table handle.
119   This is an opaque structure.
120 */
121 struct PSI_table;
122 typedef struct PSI_table PSI_table;
123
124 /**
125   Interface for an instrumented thread.
126   This is an opaque structure.
127 */
128 struct PSI_thread;
129 typedef struct PSI_thread PSI_thread;
130
131 /**
132   Interface for an instrumented file handle.
133   This is an opaque structure.
134 */
135 struct PSI_file;
136 typedef struct PSI_file PSI_file;
137
138 /**
139   Interface for an instrumented socket descriptor.
140   This is an opaque structure.
141 */
142 struct PSI_socket;
143 typedef struct PSI_socket PSI_socket;
144
145 /**
146   Interface for an instrumented prepared statement.
147   This is an opaque structure.
148 */
149 struct PSI_prepared_stmt;
150 typedef struct PSI_prepared_stmt PSI_prepared_stmt;
151
152 /**
153   Interface for an instrumented table operation.
154   This is an opaque structure.
155 */
156 struct PSI_table_locker;
157 typedef struct PSI_table_locker PSI_table_locker;
158
159 /**
160   Interface for an instrumented statement.
161   This is an opaque structure.
162 */
163 struct PSI_statement_locker;
164 typedef struct PSI_statement_locker PSI_statement_locker;
165
166 /**
167   Interface for an instrumented transaction.
168   This is an opaque structure.
169 */
170 struct PSI_transaction_locker;
171 typedef struct PSI_transaction_locker PSI_transaction_locker;
172
173 /**
174   Interface for an instrumented idle operation.
175   This is an opaque structure.
176 */
177 struct PSI_idle_locker;
178 typedef struct PSI_idle_locker PSI_idle_locker;
179
180 /**
181   Interface for an instrumented statement digest operation.
182   This is an opaque structure.
183 */
184 struct PSI_digest_locker;
185 typedef struct PSI_digest_locker PSI_digest_locker;
186
187 /**
188   Interface for an instrumented stored procedure share.
189   This is an opaque structure.
190 */
191 struct PSI_sp_share;
192 typedef struct PSI_sp_share PSI_sp_share;
193
194 /**
195   Interface for an instrumented stored program.
196   This is an opaque structure.
197 */
198 struct PSI_sp_locker;
199 typedef struct PSI_sp_locker PSI_sp_locker;
200
201 /**
202   Interface for an instrumented metadata lock.
203   This is an opaque structure.
204 */
205 struct PSI_metadata_lock;
206 typedef struct PSI_metadata_lock PSI_metadata_lock;
207
208 /**
209   Interface for an instrumented stage progress.
210   This is a public structure, for efficiency.
211 */
212 struct PSI_stage_progress
213 {
214   ulonglong m_work_completed;
215   ulonglong m_work_estimated;
216 };
217 typedef struct PSI_stage_progress PSI_stage_progress;
218
219 /** IO operation performed on an instrumented table. */
220 enum PSI_table_io_operation
221 {
222   /** Row fetch. */
223   PSI_TABLE_FETCH_ROW= 0,
224   /** Row write. */
225   PSI_TABLE_WRITE_ROW= 1,
226   /** Row update. */
227   PSI_TABLE_UPDATE_ROW= 2,
228   /** Row delete. */
229   PSI_TABLE_DELETE_ROW= 3
230 };
231 typedef enum PSI_table_io_operation PSI_table_io_operation;
232
233 /**
234   State data storage for @c start_table_io_wait_v1_t,
235   @c start_table_lock_wait_v1_t.
236   This structure provide temporary storage to a table locker.
237   The content of this structure is considered opaque,
238   the fields are only hints of what an implementation
239   of the psi interface can use.
240   This memory is provided by the instrumented code for performance reasons.
241   @sa start_table_io_wait_v1_t
242   @sa start_table_lock_wait_v1_t
243 */
244 struct PSI_table_locker_state
245 {
246   /** Internal state. */
247   uint m_flags;
248   /** Current io operation. */
249   enum PSI_table_io_operation m_io_operation;
250   /** Current table handle. */
251   struct PSI_table *m_table;
252   /** Current table share. */
253   struct PSI_table_share *m_table_share;
254   /** Current thread. */
255   struct PSI_thread *m_thread;
256   /** Timer start. */
257   ulonglong m_timer_start;
258   /** Timer function. */
259   ulonglong (*m_timer)(void);
260   /** Internal data. */
261   void *m_wait;
262   /**
263     Implementation specific.
264     For table io, the table io index.
265     For table lock, the lock type.
266   */
267   uint m_index;
268 };
269 typedef struct PSI_table_locker_state PSI_table_locker_state;
270
271 /** Entry point for the performance schema interface. */
272 struct PSI_bootstrap
273 {
274   /**
275     ABI interface finder.
276     Calling this method with an interface version number returns either
277     an instance of the ABI for this version, or NULL.
278     @param version the interface version number to find
279     @return a versioned interface (PSI_v1, PSI_v2 or PSI)
280     @sa PSI_VERSION_1
281     @sa PSI_v1
282     @sa PSI_VERSION_2
283     @sa PSI_v2
284     @sa PSI_CURRENT_VERSION
285     @sa PSI
286   */
287   void* (*get_interface)(int version);
288 };
289 typedef struct PSI_bootstrap PSI_bootstrap;
290
291 #ifdef HAVE_PSI_INTERFACE
292
293 #ifdef DISABLE_ALL_PSI
294
295 #ifndef DISABLE_PSI_THREAD
296 #define DISABLE_PSI_THREAD
297 #endif
298
299 #ifndef DISABLE_PSI_MUTEX
300 #define DISABLE_PSI_MUTEX
301 #endif
302
303 #ifndef DISABLE_PSI_RWLOCK
304 #define DISABLE_PSI_RWLOCK
305 #endif
306
307 #ifndef DISABLE_PSI_COND
308 #define DISABLE_PSI_COND
309 #endif
310
311 #ifndef DISABLE_PSI_FILE
312 #define DISABLE_PSI_FILE
313 #endif
314
315 #ifndef DISABLE_PSI_TABLE
316 #define DISABLE_PSI_TABLE
317 #endif
318
319 #ifndef DISABLE_PSI_SOCKET
320 #define DISABLE_PSI_SOCKET
321 #endif
322
323 #ifndef DISABLE_PSI_STAGE
324 #define DISABLE_PSI_STAGE
325 #endif
326
327 #ifndef DISABLE_PSI_STATEMENT
328 #define DISABLE_PSI_STATEMENT
329 #endif
330
331 #ifndef DISABLE_PSI_SP
332 #define DISABLE_PSI_SP
333 #endif
334
335 #ifndef DISABLE_PSI_IDLE
336 #define DISABLE_PSI_IDLE
337 #endif
338
339 #ifndef DISABLE_PSI_STATEMENT_DIGEST
340 #define DISABLE_PSI_STATEMENT_DIGEST
341 #endif
342
343 #ifndef DISABLE_PSI_METADATA
344 #define DISABLE_PSI_METADATA
345 #endif
346
347 #ifndef DISABLE_PSI_MEMORY
348 #define DISABLE_PSI_MEMORY
349 #endif
350
351 #ifndef DISABLE_PSI_TRANSACTION
352 #define DISABLE_PSI_TRANSACTION
353 #endif
354
355 #ifndef DISABLE_PSI_SP
356 #define DISABLE_PSI_SP
357 #endif
358
359 #ifndef DISABLE_PSI_PS
360 #define DISABLE_PSI_PS
361 #endif
362
363 #endif
364
365 /**
366   @def DISABLE_PSI_MUTEX
367   Compiling option to disable the mutex instrumentation.
368   This option is mostly intended to be used during development,
369   when doing special builds with only a subset of the performance schema instrumentation,
370   for code analysis / profiling / performance tuning of a specific instrumentation alone.
371   @sa DISABLE_PSI_RWLOCK
372   @sa DISABLE_PSI_COND
373   @sa DISABLE_PSI_FILE
374   @sa DISABLE_PSI_THREAD
375   @sa DISABLE_PSI_TABLE
376   @sa DISABLE_PSI_STAGE
377   @sa DISABLE_PSI_STATEMENT
378   @sa DISABLE_PSI_SP
379   @sa DISABLE_PSI_STATEMENT_DIGEST
380   @sa DISABLE_PSI_SOCKET
381   @sa DISABLE_PSI_MEMORY
382   @sa DISABLE_PSI_IDLE
383   @sa DISABLE_PSI_METADATA
384   @sa DISABLE PSI_TRANSACTION
385 */
386
387 #ifndef DISABLE_PSI_MUTEX
388 #define HAVE_PSI_MUTEX_INTERFACE
389 #endif
390
391 /**
392   @def DISABLE_PSI_RWLOCK
393   Compiling option to disable the rwlock instrumentation.
394   @sa DISABLE_PSI_MUTEX
395 */
396
397 #ifndef DISABLE_PSI_RWLOCK
398 #define HAVE_PSI_RWLOCK_INTERFACE
399 #endif
400
401 /**
402   @def DISABLE_PSI_COND
403   Compiling option to disable the cond instrumentation.
404   @sa DISABLE_PSI_MUTEX
405 */
406
407 #ifndef DISABLE_PSI_COND
408 #define HAVE_PSI_COND_INTERFACE
409 #endif
410
411 /**
412   @def DISABLE_PSI_FILE
413   Compiling option to disable the file instrumentation.
414   @sa DISABLE_PSI_MUTEX
415 */
416
417 #ifndef DISABLE_PSI_FILE
418 #define HAVE_PSI_FILE_INTERFACE
419 #endif
420
421 /**
422   @def DISABLE_PSI_THREAD
423   Compiling option to disable the thread instrumentation.
424   @sa DISABLE_PSI_MUTEX
425 */
426 #ifndef DISABLE_PSI_THREAD
427 #define HAVE_PSI_THREAD_INTERFACE
428 #endif
429
430 /**
431   @def DISABLE_PSI_TABLE
432   Compiling option to disable the table instrumentation.
433   @sa DISABLE_PSI_MUTEX
434 */
435
436 #ifndef DISABLE_PSI_TABLE
437 #define HAVE_PSI_TABLE_INTERFACE
438 #endif
439
440 /**
441   @def DISABLE_PSI_STAGE
442   Compiling option to disable the stage instrumentation.
443   @sa DISABLE_PSI_MUTEX
444 */
445
446 #ifndef DISABLE_PSI_STAGE
447 #define HAVE_PSI_STAGE_INTERFACE
448 #endif
449
450 /**
451   @def DISABLE_PSI_STATEMENT
452   Compiling option to disable the statement instrumentation.
453   @sa DISABLE_PSI_MUTEX
454 */
455
456 #ifndef DISABLE_PSI_STATEMENT
457 #define HAVE_PSI_STATEMENT_INTERFACE
458 #endif
459
460 /**
461   @def DISABLE_PSI_SP
462   Compiling option to disable the stored program instrumentation.
463   @sa DISABLE_PSI_MUTEX
464 */
465 #ifndef DISABLE_PSI_SP
466 #define HAVE_PSI_SP_INTERFACE
467 #endif
468
469 /**
470   @def DISABLE_PSI_PS
471   Compiling option to disable the prepared statement instrumentation.
472   @sa DISABLE_PSI_MUTEX
473 */
474 #ifndef DISABLE_PSI_STATEMENT
475 #ifndef DISABLE_PSI_PS
476 #define HAVE_PSI_PS_INTERFACE
477 #endif
478 #endif
479
480 /**
481   @def DISABLE_PSI_STATEMENT_DIGEST
482   Compiling option to disable the statement digest instrumentation.
483 */
484
485 #ifndef DISABLE_PSI_STATEMENT
486 #ifndef DISABLE_PSI_STATEMENT_DIGEST
487 #define HAVE_PSI_STATEMENT_DIGEST_INTERFACE
488 #endif
489 #endif
490
491 /**
492   @def DISABLE_PSI_TRANSACTION
493   Compiling option to disable the transaction instrumentation.
494   @sa DISABLE_PSI_MUTEX
495 */
496
497 #ifndef DISABLE_PSI_TRANSACTION
498 #define HAVE_PSI_TRANSACTION_INTERFACE
499 #endif
500
501 /**
502   @def DISABLE_PSI_SOCKET
503   Compiling option to disable the statement instrumentation.
504   @sa DISABLE_PSI_MUTEX
505 */
506
507 #ifndef DISABLE_PSI_SOCKET
508 #define HAVE_PSI_SOCKET_INTERFACE
509 #endif
510
511 /**
512   @def DISABLE_PSI_MEMORY
513   Compiling option to disable the memory instrumentation.
514   @sa DISABLE_PSI_MUTEX
515 */
516
517 #ifndef DISABLE_PSI_MEMORY
518 #define HAVE_PSI_MEMORY_INTERFACE
519 #endif
520
521 /**
522   @def DISABLE_PSI_IDLE
523   Compiling option to disable the idle instrumentation.
524   @sa DISABLE_PSI_MUTEX
525 */
526
527 #ifndef DISABLE_PSI_IDLE
528 #define HAVE_PSI_IDLE_INTERFACE
529 #endif
530
531 /**
532   @def DISABLE_PSI_METADATA
533   Compiling option to disable the metadata instrumentation.
534   @sa DISABLE_PSI_MUTEX
535 */
536
537 #ifndef DISABLE_PSI_METADATA
538 #define HAVE_PSI_METADATA_INTERFACE
539 #endif
540
541 /**
542   @def PSI_VERSION_1
543   Performance Schema Interface number for version 1.
544   This version is supported.
545 */
546 #define PSI_VERSION_1 1
547
548 /**
549   @def PSI_VERSION_2
550   Performance Schema Interface number for version 2.
551   This version is not implemented, it's a placeholder.
552 */
553 #define PSI_VERSION_2 2
554
555 /**
556   @def PSI_CURRENT_VERSION
557   Performance Schema Interface number for the most recent version.
558   The most current version is @c PSI_VERSION_1
559 */
560 #define PSI_CURRENT_VERSION 1
561
562 #ifndef USE_PSI_2
563 #ifndef USE_PSI_1
564 #define USE_PSI_1
565 #endif
566 #endif
567
568 /**
569   Interface for an instrumented mutex operation.
570   This is an opaque structure.
571 */
572 struct PSI_mutex_locker;
573 typedef struct PSI_mutex_locker PSI_mutex_locker;
574
575 /**
576   Interface for an instrumented rwlock operation.
577   This is an opaque structure.
578 */
579 struct PSI_rwlock_locker;
580 typedef struct PSI_rwlock_locker PSI_rwlock_locker;
581
582 /**
583   Interface for an instrumented condition operation.
584   This is an opaque structure.
585 */
586 struct PSI_cond_locker;
587 typedef struct PSI_cond_locker PSI_cond_locker;
588
589 /**
590   Interface for an instrumented file operation.
591   This is an opaque structure.
592 */
593 struct PSI_file_locker;
594 typedef struct PSI_file_locker PSI_file_locker;
595
596 /**
597   Interface for an instrumented socket operation.
598   This is an opaque structure.
599 */
600 struct PSI_socket_locker;
601 typedef struct PSI_socket_locker PSI_socket_locker;
602
603 /**
604   Interface for an instrumented MDL operation.
605   This is an opaque structure.
606 */
607 struct PSI_metadata_locker;
608 typedef struct PSI_metadata_locker PSI_metadata_locker;
609
610 /** Operation performed on an instrumented mutex. */
611 enum PSI_mutex_operation
612 {
613   /** Lock. */
614   PSI_MUTEX_LOCK= 0,
615   /** Lock attempt. */
616   PSI_MUTEX_TRYLOCK= 1
617 };
618 typedef enum PSI_mutex_operation PSI_mutex_operation;
619
620 /**
621   Operation performed on an instrumented rwlock.
622   For basic READ / WRITE lock,
623   operations are "READ" or "WRITE".
624   For SX-locks, operations are "SHARED", "SHARED-EXCLUSIVE" or "EXCLUSIVE".
625 */
626 enum PSI_rwlock_operation
627 {
628   /** Read lock. */
629   PSI_RWLOCK_READLOCK= 0,
630   /** Write lock. */
631   PSI_RWLOCK_WRITELOCK= 1,
632   /** Read lock attempt. */
633   PSI_RWLOCK_TRYREADLOCK= 2,
634   /** Write lock attempt. */
635   PSI_RWLOCK_TRYWRITELOCK= 3,
636
637   /** Shared lock. */
638   PSI_RWLOCK_SHAREDLOCK= 4,
639   /** Shared Exclusive lock. */
640   PSI_RWLOCK_SHAREDEXCLUSIVELOCK= 5,
641   /** Exclusive lock. */
642   PSI_RWLOCK_EXCLUSIVELOCK= 6,
643   /** Shared lock attempt. */
644   PSI_RWLOCK_TRYSHAREDLOCK= 7,
645   /** Shared Exclusive lock attempt. */
646   PSI_RWLOCK_TRYSHAREDEXCLUSIVELOCK= 8,
647   /** Exclusive lock attempt. */
648   PSI_RWLOCK_TRYEXCLUSIVELOCK= 9
649
650 };
651 typedef enum PSI_rwlock_operation PSI_rwlock_operation;
652
653 /** Operation performed on an instrumented condition. */
654 enum PSI_cond_operation
655 {
656   /** Wait. */
657   PSI_COND_WAIT= 0,
658   /** Wait, with timeout. */
659   PSI_COND_TIMEDWAIT= 1
660 };
661 typedef enum PSI_cond_operation PSI_cond_operation;
662
663 /** Operation performed on an instrumented file. */
664 enum PSI_file_operation
665 {
666   /** File creation, as in @c create(). */
667   PSI_FILE_CREATE= 0,
668   /** Temporary file creation, as in @c create_temp_file(). */
669   PSI_FILE_CREATE_TMP= 1,
670   /** File open, as in @c open(). */
671   PSI_FILE_OPEN= 2,
672   /** File open, as in @c fopen(). */
673   PSI_FILE_STREAM_OPEN= 3,
674   /** File close, as in @c close(). */
675   PSI_FILE_CLOSE= 4,
676   /** File close, as in @c fclose(). */
677   PSI_FILE_STREAM_CLOSE= 5,
678   /**
679     Generic file read, such as @c fgets(), @c fgetc(), @c fread(), @c read(),
680     @c pread().
681   */
682   PSI_FILE_READ= 6,
683   /**
684     Generic file write, such as @c fputs(), @c fputc(), @c fprintf(),
685     @c vfprintf(), @c fwrite(), @c write(), @c pwrite().
686   */
687   PSI_FILE_WRITE= 7,
688   /** Generic file seek, such as @c fseek() or @c seek(). */
689   PSI_FILE_SEEK= 8,
690   /** Generic file tell, such as @c ftell() or @c tell(). */
691   PSI_FILE_TELL= 9,
692   /** File flush, as in @c fflush(). */
693   PSI_FILE_FLUSH= 10,
694   /** File stat, as in @c stat(). */
695   PSI_FILE_STAT= 11,
696   /** File stat, as in @c fstat(). */
697   PSI_FILE_FSTAT= 12,
698   /** File chsize, as in @c my_chsize(). */
699   PSI_FILE_CHSIZE= 13,
700   /** File delete, such as @c my_delete() or @c my_delete_with_symlink(). */
701   PSI_FILE_DELETE= 14,
702   /** File rename, such as @c my_rename() or @c my_rename_with_symlink(). */
703   PSI_FILE_RENAME= 15,
704   /** File sync, as in @c fsync() or @c my_sync(). */
705   PSI_FILE_SYNC= 16
706 };
707 typedef enum PSI_file_operation PSI_file_operation;
708
709 /** Lock operation performed on an instrumented table. */
710 enum PSI_table_lock_operation
711 {
712   /** Table lock, in the server layer. */
713   PSI_TABLE_LOCK= 0,
714   /** Table lock, in the storage engine layer. */
715   PSI_TABLE_EXTERNAL_LOCK= 1
716 };
717 typedef enum PSI_table_lock_operation PSI_table_lock_operation;
718
719 /** State of an instrumented socket. */
720 enum PSI_socket_state
721 {
722   /** Idle, waiting for the next command. */
723   PSI_SOCKET_STATE_IDLE= 1,
724   /** Active, executing a command. */
725   PSI_SOCKET_STATE_ACTIVE= 2
726 };
727 typedef enum PSI_socket_state PSI_socket_state;
728
729 /** Operation performed on an instrumented socket. */
730 enum PSI_socket_operation
731 {
732   /** Socket creation, as in @c socket() or @c socketpair(). */
733   PSI_SOCKET_CREATE= 0,
734   /** Socket connection, as in @c connect(), @c listen() and @c accept(). */
735   PSI_SOCKET_CONNECT= 1,
736   /** Socket bind, as in @c bind(), @c getsockname() and @c getpeername(). */
737   PSI_SOCKET_BIND= 2,
738   /** Socket close, as in @c shutdown(). */
739   PSI_SOCKET_CLOSE= 3,
740   /** Socket send, @c send(). */
741   PSI_SOCKET_SEND= 4,
742   /** Socket receive, @c recv(). */
743   PSI_SOCKET_RECV= 5,
744   /** Socket send, @c sendto(). */
745   PSI_SOCKET_SENDTO= 6,
746   /** Socket receive, @c recvfrom). */
747   PSI_SOCKET_RECVFROM= 7,
748   /** Socket send, @c sendmsg(). */
749   PSI_SOCKET_SENDMSG= 8,
750   /** Socket receive, @c recvmsg(). */
751   PSI_SOCKET_RECVMSG= 9,
752   /** Socket seek, such as @c fseek() or @c seek(). */
753   PSI_SOCKET_SEEK= 10,
754   /** Socket options, as in @c getsockopt() and @c setsockopt(). */
755   PSI_SOCKET_OPT= 11,
756   /** Socket status, as in @c sockatmark() and @c isfdtype(). */
757   PSI_SOCKET_STAT= 12,
758   /** Socket shutdown, as in @c shutdown(). */
759   PSI_SOCKET_SHUTDOWN= 13,
760   /** Socket select, as in @c select() and @c poll(). */
761   PSI_SOCKET_SELECT= 14
762 };
763 typedef enum PSI_socket_operation PSI_socket_operation;
764
765 /**
766   Instrumented mutex key.
767   To instrument a mutex, a mutex key must be obtained using @c register_mutex.
768   Using a zero key always disable the instrumentation.
769 */
770 typedef unsigned int PSI_mutex_key;
771
772 /**
773   Instrumented rwlock key.
774   To instrument a rwlock, a rwlock key must be obtained
775   using @c register_rwlock.
776   Using a zero key always disable the instrumentation.
777 */
778 typedef unsigned int PSI_rwlock_key;
779
780 /**
781   Instrumented cond key.
782   To instrument a condition, a condition key must be obtained
783   using @c register_cond.
784   Using a zero key always disable the instrumentation.
785 */
786 typedef unsigned int PSI_cond_key;
787
788 /**
789   Instrumented thread key.
790   To instrument a thread, a thread key must be obtained
791   using @c register_thread.
792   Using a zero key always disable the instrumentation.
793 */
794 typedef unsigned int PSI_thread_key;
795
796 /**
797   Instrumented file key.
798   To instrument a file, a file key must be obtained using @c register_file.
799   Using a zero key always disable the instrumentation.
800 */
801 #ifndef PSI_FILE_KEY_DEFINED
802 typedef unsigned int PSI_file_key;
803 #define PSI_FILE_KEY_DEFINED
804 #endif
805
806 /**
807   Instrumented stage key.
808   To instrument a stage, a stage key must be obtained using @c register_stage.
809   Using a zero key always disable the instrumentation.
810 */
811 typedef unsigned int PSI_stage_key;
812
813 /**
814   Instrumented statement key.
815   To instrument a statement, a statement key must be obtained using @c register_statement.
816   Using a zero key always disable the instrumentation.
817 */
818 typedef unsigned int PSI_statement_key;
819
820 /**
821   Instrumented socket key.
822   To instrument a socket, a socket key must be obtained using @c register_socket.
823   Using a zero key always disable the instrumentation.
824 */
825 typedef unsigned int PSI_socket_key;
826
827 #ifdef HAVE_PSI_1
828
829 /**
830   @defgroup Group_PSI_v1 Application Binary Interface, version 1
831   @ingroup Instrumentation_interface
832   @{
833 */
834
835 /**
836   Mutex information.
837   @since PSI_VERSION_1
838   This structure is used to register an instrumented mutex.
839 */
840 struct PSI_mutex_info_v1
841 {
842   /**
843     Pointer to the key assigned to the registered mutex.
844   */
845   PSI_mutex_key *m_key;
846   /**
847     The name of the mutex to register.
848   */
849   const char *m_name;
850   /**
851     The flags of the mutex to register.
852     @sa PSI_FLAG_GLOBAL
853   */
854   int m_flags;
855 };
856 typedef struct PSI_mutex_info_v1 PSI_mutex_info_v1;
857
858 /**
859   Rwlock information.
860   @since PSI_VERSION_1
861   This structure is used to register an instrumented rwlock.
862 */
863 struct PSI_rwlock_info_v1
864 {
865   /**
866     Pointer to the key assigned to the registered rwlock.
867   */
868   PSI_rwlock_key *m_key;
869   /**
870     The name of the rwlock to register.
871   */
872   const char *m_name;
873   /**
874     The flags of the rwlock to register.
875     @sa PSI_FLAG_GLOBAL
876   */
877   int m_flags;
878 };
879 typedef struct PSI_rwlock_info_v1 PSI_rwlock_info_v1;
880
881 /**
882   Condition information.
883   @since PSI_VERSION_1
884   This structure is used to register an instrumented cond.
885 */
886 struct PSI_cond_info_v1
887 {
888   /**
889     Pointer to the key assigned to the registered cond.
890   */
891   PSI_cond_key *m_key;
892   /**
893     The name of the cond to register.
894   */
895   const char *m_name;
896   /**
897     The flags of the cond to register.
898     @sa PSI_FLAG_GLOBAL
899   */
900   int m_flags;
901 };
902 typedef struct PSI_cond_info_v1 PSI_cond_info_v1;
903
904 /**
905   Thread instrument information.
906   @since PSI_VERSION_1
907   This structure is used to register an instrumented thread.
908 */
909 struct PSI_thread_info_v1
910 {
911   /**
912     Pointer to the key assigned to the registered thread.
913   */
914   PSI_thread_key *m_key;
915   /**
916     The name of the thread instrument to register.
917   */
918   const char *m_name;
919   /**
920     The flags of the thread to register.
921     @sa PSI_FLAG_GLOBAL
922   */
923   int m_flags;
924 };
925 typedef struct PSI_thread_info_v1 PSI_thread_info_v1;
926
927 /**
928   File instrument information.
929   @since PSI_VERSION_1
930   This structure is used to register an instrumented file.
931 */
932 struct PSI_file_info_v1
933 {
934   /**
935     Pointer to the key assigned to the registered file.
936   */
937   PSI_file_key *m_key;
938   /**
939     The name of the file instrument to register.
940   */
941   const char *m_name;
942   /**
943     The flags of the file instrument to register.
944     @sa PSI_FLAG_GLOBAL
945   */
946   int m_flags;
947 };
948 typedef struct PSI_file_info_v1 PSI_file_info_v1;
949
950 /**
951   Stage instrument information.
952   @since PSI_VERSION_1
953   This structure is used to register an instrumented stage.
954 */
955 struct PSI_stage_info_v1
956 {
957   /** The registered stage key. */
958   PSI_stage_key m_key;
959   /** The name of the stage instrument to register. */
960   const char *m_name;
961   /** The flags of the stage instrument to register. */
962   int m_flags;
963 };
964 typedef struct PSI_stage_info_v1 PSI_stage_info_v1;
965
966 /**
967   Statement instrument information.
968   @since PSI_VERSION_1
969   This structure is used to register an instrumented statement.
970 */
971 struct PSI_statement_info_v1
972 {
973   /** The registered statement key. */
974   PSI_statement_key m_key;
975   /** The name of the statement instrument to register. */
976   const char *m_name;
977   /** The flags of the statement instrument to register. */
978   int m_flags;
979 };
980 typedef struct PSI_statement_info_v1 PSI_statement_info_v1;
981
982 /**
983   Socket instrument information.
984   @since PSI_VERSION_1
985   This structure is used to register an instrumented socket.
986 */
987 struct PSI_socket_info_v1
988 {
989   /**
990     Pointer to the key assigned to the registered socket.
991   */
992   PSI_socket_key *m_key;
993   /**
994     The name of the socket instrument to register.
995   */
996   const char *m_name;
997   /**
998     The flags of the socket instrument to register.
999     @sa PSI_FLAG_GLOBAL
1000   */
1001   int m_flags;
1002 };
1003 typedef struct PSI_socket_info_v1 PSI_socket_info_v1;
1004
1005 /**
1006   State data storage for @c start_idle_wait_v1_t.
1007   This structure provide temporary storage to an idle locker.
1008   The content of this structure is considered opaque,
1009   the fields are only hints of what an implementation
1010   of the psi interface can use.
1011   This memory is provided by the instrumented code for performance reasons.
1012   @sa start_idle_wait_v1_t.
1013 */
1014 struct PSI_idle_locker_state_v1
1015 {
1016   /** Internal state. */
1017   uint m_flags;
1018   /** Current thread. */
1019   struct PSI_thread *m_thread;
1020   /** Timer start. */
1021   ulonglong m_timer_start;
1022   /** Timer function. */
1023   ulonglong (*m_timer)(void);
1024   /** Internal data. */
1025   void *m_wait;
1026 };
1027 typedef struct PSI_idle_locker_state_v1 PSI_idle_locker_state_v1;
1028
1029 /**
1030   State data storage for @c start_mutex_wait_v1_t.
1031   This structure provide temporary storage to a mutex locker.
1032   The content of this structure is considered opaque,
1033   the fields are only hints of what an implementation
1034   of the psi interface can use.
1035   This memory is provided by the instrumented code for performance reasons.
1036   @sa start_mutex_wait_v1_t
1037 */
1038 struct PSI_mutex_locker_state_v1
1039 {
1040   /** Internal state. */
1041   uint m_flags;
1042   /** Current operation. */
1043   enum PSI_mutex_operation m_operation;
1044   /** Current mutex. */
1045   struct PSI_mutex *m_mutex;
1046   /** Current thread. */
1047   struct PSI_thread *m_thread;
1048   /** Timer start. */
1049   ulonglong m_timer_start;
1050   /** Timer function. */
1051   ulonglong (*m_timer)(void);
1052   /** Internal data. */
1053   void *m_wait;
1054 };
1055 typedef struct PSI_mutex_locker_state_v1 PSI_mutex_locker_state_v1;
1056
1057 /**
1058   State data storage for @c start_rwlock_rdwait_v1_t, @c start_rwlock_wrwait_v1_t.
1059   This structure provide temporary storage to a rwlock locker.
1060   The content of this structure is considered opaque,
1061   the fields are only hints of what an implementation
1062   of the psi interface can use.
1063   This memory is provided by the instrumented code for performance reasons.
1064   @sa start_rwlock_rdwait_v1_t
1065   @sa start_rwlock_wrwait_v1_t
1066 */
1067 struct PSI_rwlock_locker_state_v1
1068 {
1069   /** Internal state. */
1070   uint m_flags;
1071   /** Current operation. */
1072   enum PSI_rwlock_operation m_operation;
1073   /** Current rwlock. */
1074   struct PSI_rwlock *m_rwlock;
1075   /** Current thread. */
1076   struct PSI_thread *m_thread;
1077   /** Timer start. */
1078   ulonglong m_timer_start;
1079   /** Timer function. */
1080   ulonglong (*m_timer)(void);
1081   /** Internal data. */
1082   void *m_wait;
1083 };
1084 typedef struct PSI_rwlock_locker_state_v1 PSI_rwlock_locker_state_v1;
1085
1086 /**
1087   State data storage for @c start_cond_wait_v1_t.
1088   This structure provide temporary storage to a condition locker.
1089   The content of this structure is considered opaque,
1090   the fields are only hints of what an implementation
1091   of the psi interface can use.
1092   This memory is provided by the instrumented code for performance reasons.
1093   @sa start_cond_wait_v1_t
1094 */
1095 struct PSI_cond_locker_state_v1
1096 {
1097   /** Internal state. */
1098   uint m_flags;
1099   /** Current operation. */
1100   enum PSI_cond_operation m_operation;
1101   /** Current condition. */
1102   struct PSI_cond *m_cond;
1103   /** Current mutex. */
1104   struct PSI_mutex *m_mutex;
1105   /** Current thread. */
1106   struct PSI_thread *m_thread;
1107   /** Timer start. */
1108   ulonglong m_timer_start;
1109   /** Timer function. */
1110   ulonglong (*m_timer)(void);
1111   /** Internal data. */
1112   void *m_wait;
1113 };
1114 typedef struct PSI_cond_locker_state_v1 PSI_cond_locker_state_v1;
1115
1116 /**
1117   State data storage for @c get_thread_file_name_locker_v1_t.
1118   This structure provide temporary storage to a file locker.
1119   The content of this structure is considered opaque,
1120   the fields are only hints of what an implementation
1121   of the psi interface can use.
1122   This memory is provided by the instrumented code for performance reasons.
1123   @sa get_thread_file_name_locker_v1_t
1124   @sa get_thread_file_stream_locker_v1_t
1125   @sa get_thread_file_descriptor_locker_v1_t
1126 */
1127 struct PSI_file_locker_state_v1
1128 {
1129   /** Internal state. */
1130   uint m_flags;
1131   /** Current operation. */
1132   enum PSI_file_operation m_operation;
1133   /** Current file. */
1134   struct PSI_file *m_file;
1135   /** Current file name. */
1136   const char *m_name;
1137   /** Current file class. */
1138   void *m_class;
1139   /** Current thread. */
1140   struct PSI_thread *m_thread;
1141   /** Operation number of bytes. */
1142   size_t m_number_of_bytes;
1143   /** Timer start. */
1144   ulonglong m_timer_start;
1145   /** Timer function. */
1146   ulonglong (*m_timer)(void);
1147   /** Internal data. */
1148   void *m_wait;
1149 };
1150 typedef struct PSI_file_locker_state_v1 PSI_file_locker_state_v1;
1151
1152 /**
1153   State data storage for @c start_metadata_wait_v1_t.
1154   This structure provide temporary storage to a metadata locker.
1155   The content of this structure is considered opaque,
1156   the fields are only hints of what an implementation
1157   of the psi interface can use.
1158   This memory is provided by the instrumented code for performance reasons.
1159   @sa start_metadata_wait_v1_t
1160 */
1161 struct PSI_metadata_locker_state_v1
1162 {
1163   /** Internal state. */
1164   uint m_flags;
1165   /** Current metadata lock. */
1166   struct PSI_metadata_lock *m_metadata_lock;
1167   /** Current thread. */
1168   struct PSI_thread *m_thread;
1169   /** Timer start. */
1170   ulonglong m_timer_start;
1171   /** Timer function. */
1172   ulonglong (*m_timer)(void);
1173   /** Internal data. */
1174   void *m_wait;
1175 };
1176 typedef struct PSI_metadata_locker_state_v1 PSI_metadata_locker_state_v1;
1177
1178 /* Duplicate of NAME_LEN, to avoid dependency on mysql_com.h */
1179 #define PSI_SCHEMA_NAME_LEN (64 * 3)
1180
1181 /**
1182   State data storage for @c get_thread_statement_locker_v1_t,
1183   @c get_thread_statement_locker_v1_t.
1184   This structure provide temporary storage to a statement locker.
1185   The content of this structure is considered opaque,
1186   the fields are only hints of what an implementation
1187   of the psi interface can use.
1188   This memory is provided by the instrumented code for performance reasons.
1189   @sa get_thread_statement_locker_v1_t
1190 */
1191 struct PSI_statement_locker_state_v1
1192 {
1193   /** Discarded flag. */
1194   my_bool m_discarded;
1195   /** In prepare flag. */
1196   my_bool m_in_prepare;
1197   /** Metric, no index used flag. */
1198   uchar m_no_index_used;
1199   /** Metric, no good index used flag. */
1200   uchar m_no_good_index_used;
1201   /** Internal state. */
1202   uint m_flags;
1203   /** Instrumentation class. */
1204   void *m_class;
1205   /** Current thread. */
1206   struct PSI_thread *m_thread;
1207   /** Timer start. */
1208   ulonglong m_timer_start;
1209   /** Timer function. */
1210   ulonglong (*m_timer)(void);
1211   /** Internal data. */
1212   void *m_statement;
1213   /** Locked time. */
1214   ulonglong m_lock_time;
1215   /** Rows sent. */
1216   ulonglong m_rows_sent;
1217   /** Rows examined. */
1218   ulonglong m_rows_examined;
1219   /** Metric, temporary tables created on disk. */
1220   ulong m_created_tmp_disk_tables;
1221   /** Metric, temporary tables created. */
1222   ulong m_created_tmp_tables;
1223   /** Metric, number of select full join. */
1224   ulong m_select_full_join;
1225   /** Metric, number of select full range join. */
1226   ulong m_select_full_range_join;
1227   /** Metric, number of select range. */
1228   ulong m_select_range;
1229   /** Metric, number of select range check. */
1230   ulong m_select_range_check;
1231   /** Metric, number of select scan. */
1232   ulong m_select_scan;
1233   /** Metric, number of sort merge passes. */
1234   ulong m_sort_merge_passes;
1235   /** Metric, number of sort merge. */
1236   ulong m_sort_range;
1237   /** Metric, number of sort rows. */
1238   ulong m_sort_rows;
1239   /** Metric, number of sort scans. */
1240   ulong m_sort_scan;
1241   /** Statement digest. */
1242   const struct sql_digest_storage *m_digest;
1243   /** Current schema name. */
1244   char m_schema_name[PSI_SCHEMA_NAME_LEN];
1245   /** Length in bytes of @c m_schema_name. */
1246   uint m_schema_name_length;
1247   /** Statement character set number. */
1248   uint m_cs_number;
1249   PSI_sp_share *m_parent_sp_share;
1250   PSI_prepared_stmt *m_parent_prepared_stmt;
1251 };
1252 typedef struct PSI_statement_locker_state_v1 PSI_statement_locker_state_v1;
1253
1254 /**
1255   State data storage for @c get_thread_transaction_locker_v1_t,
1256   @c get_thread_transaction_locker_v1_t.
1257   This structure provide temporary storage to a transaction locker.
1258   The content of this structure is considered opaque,
1259   the fields are only hints of what an implementation
1260   of the psi interface can use.
1261   This memory is provided by the instrumented code for performance reasons.
1262   @sa get_thread_transaction_locker_v1_t
1263 */
1264 struct PSI_transaction_locker_state_v1
1265 {
1266   /** Internal state. */
1267   uint m_flags;
1268   /** Instrumentation class. */
1269   void *m_class;
1270   /** Current thread. */
1271   struct PSI_thread *m_thread;
1272   /** Timer start. */
1273   ulonglong m_timer_start;
1274   /** Timer function. */
1275   ulonglong (*m_timer)(void);
1276   /** Internal data. */
1277   void *m_transaction;
1278   /** True if read-only transaction, false if read-write. */
1279   my_bool m_read_only;
1280   /** True if transaction is autocommit. */
1281   my_bool m_autocommit;
1282   /** Number of statements. */
1283   ulong m_statement_count;
1284   /** Total number of savepoints. */
1285   ulong m_savepoint_count;
1286   /** Number of rollback_to_savepoint. */
1287   ulong m_rollback_to_savepoint_count;
1288   /** Number of release_savepoint. */
1289   ulong m_release_savepoint_count;
1290 };
1291
1292 typedef struct PSI_transaction_locker_state_v1 PSI_transaction_locker_state_v1;
1293
1294 /**
1295   State data storage for @c start_socket_wait_v1_t.
1296   This structure provide temporary storage to a socket locker.
1297   The content of this structure is considered opaque,
1298   the fields are only hints of what an implementation
1299   of the psi interface can use.
1300   This memory is provided by the instrumented code for performance reasons.
1301   @sa start_socket_wait_v1_t
1302 */
1303 struct PSI_socket_locker_state_v1
1304 {
1305   /** Internal state. */
1306   uint m_flags;
1307   /** Current socket. */
1308   struct PSI_socket *m_socket;
1309   /** Current thread. */
1310   struct PSI_thread *m_thread;
1311   /** Operation number of bytes. */
1312   size_t m_number_of_bytes;
1313   /** Timer start. */
1314   ulonglong m_timer_start;
1315   /** Timer function. */
1316   ulonglong (*m_timer)(void);
1317   /** Current operation. */
1318   enum PSI_socket_operation m_operation;
1319   /** Source file. */
1320   const char* m_src_file;
1321   /** Source line number. */
1322   int m_src_line;
1323   /** Internal data. */
1324   void *m_wait;
1325 };
1326 typedef struct PSI_socket_locker_state_v1 PSI_socket_locker_state_v1;
1327
1328 struct PSI_sp_locker_state_v1
1329 {
1330   /** Internal state. */
1331   uint m_flags;
1332   /** Current thread. */
1333   struct PSI_thread *m_thread;
1334   /** Timer start. */
1335   ulonglong m_timer_start;
1336   /** Timer function. */
1337   ulonglong (*m_timer)(void);
1338   /** Stored Procedure share. */
1339   PSI_sp_share* m_sp_share;
1340 };
1341 typedef struct PSI_sp_locker_state_v1 PSI_sp_locker_state_v1;
1342
1343 /* Using typedef to make reuse between PSI_v1 and PSI_v2 easier later. */
1344
1345 /**
1346   Mutex registration API.
1347   @param category a category name (typically a plugin name)
1348   @param info an array of mutex info to register
1349   @param count the size of the info array
1350 */
1351 typedef void (*register_mutex_v1_t)
1352   (const char *category, struct PSI_mutex_info_v1 *info, int count);
1353
1354 /**
1355   Rwlock registration API.
1356   @param category a category name (typically a plugin name)
1357   @param info an array of rwlock info to register
1358   @param count the size of the info array
1359 */
1360 typedef void (*register_rwlock_v1_t)
1361   (const char *category, struct PSI_rwlock_info_v1 *info, int count);
1362
1363 /**
1364   Cond registration API.
1365   @param category a category name (typically a plugin name)
1366   @param info an array of cond info to register
1367   @param count the size of the info array
1368 */
1369 typedef void (*register_cond_v1_t)
1370   (const char *category, struct PSI_cond_info_v1 *info, int count);
1371
1372 /**
1373   Thread registration API.
1374   @param category a category name (typically a plugin name)
1375   @param info an array of thread info to register
1376   @param count the size of the info array
1377 */
1378 typedef void (*register_thread_v1_t)
1379   (const char *category, struct PSI_thread_info_v1 *info, int count);
1380
1381 /**
1382   File registration API.
1383   @param category a category name (typically a plugin name)
1384   @param info an array of file info to register
1385   @param count the size of the info array
1386 */
1387 typedef void (*register_file_v1_t)
1388   (const char *category, struct PSI_file_info_v1 *info, int count);
1389
1390 /**
1391   Stage registration API.
1392   @param category a category name
1393   @param info an array of stage info to register
1394   @param count the size of the info array
1395 */
1396 typedef void (*register_stage_v1_t)
1397   (const char *category, struct PSI_stage_info_v1 **info, int count);
1398
1399 /**
1400   Statement registration API.
1401   @param category a category name
1402   @param info an array of stage info to register
1403   @param count the size of the info array
1404 */
1405 typedef void (*register_statement_v1_t)
1406   (const char *category, struct PSI_statement_info_v1 *info, int count);
1407
1408 /**
1409   Socket registration API.
1410   @param category a category name (typically a plugin name)
1411   @param info an array of socket info to register
1412   @param count the size of the info array
1413 */
1414 typedef void (*register_socket_v1_t)
1415   (const char *category, struct PSI_socket_info_v1 *info, int count);
1416
1417 /**
1418   Mutex instrumentation initialisation API.
1419   @param key the registered mutex key
1420   @param identity the address of the mutex itself
1421   @return an instrumented mutex
1422 */
1423 typedef struct PSI_mutex* (*init_mutex_v1_t)
1424   (PSI_mutex_key key, const void *identity);
1425
1426 /**
1427   Mutex instrumentation destruction API.
1428   @param mutex the mutex to destroy
1429 */
1430 typedef void (*destroy_mutex_v1_t)(struct PSI_mutex *mutex);
1431
1432 /**
1433   Rwlock instrumentation initialisation API.
1434   @param key the registered rwlock key
1435   @param identity the address of the rwlock itself
1436   @return an instrumented rwlock
1437 */
1438 typedef struct PSI_rwlock* (*init_rwlock_v1_t)
1439   (PSI_rwlock_key key, const void *identity);
1440
1441 /**
1442   Rwlock instrumentation destruction API.
1443   @param rwlock the rwlock to destroy
1444 */
1445 typedef void (*destroy_rwlock_v1_t)(struct PSI_rwlock *rwlock);
1446
1447 /**
1448   Cond instrumentation initialisation API.
1449   @param key the registered key
1450   @param identity the address of the rwlock itself
1451   @return an instrumented cond
1452 */
1453 typedef struct PSI_cond* (*init_cond_v1_t)
1454   (PSI_cond_key key, const void *identity);
1455
1456 /**
1457   Cond instrumentation destruction API.
1458   @param cond the rcond to destroy
1459 */
1460 typedef void (*destroy_cond_v1_t)(struct PSI_cond *cond);
1461
1462 /**
1463   Socket instrumentation initialisation API.
1464   @param key the registered mutex key
1465   @param socket descriptor
1466   @param addr the socket ip address
1467   @param addr_len length of socket ip address
1468   @return an instrumented socket
1469 */
1470 typedef struct PSI_socket* (*init_socket_v1_t)
1471   (PSI_socket_key key, const my_socket *fd,
1472   const struct sockaddr *addr, socklen_t addr_len);
1473
1474 /**
1475   socket instrumentation destruction API.
1476   @param socket the socket to destroy
1477 */
1478 typedef void (*destroy_socket_v1_t)(struct PSI_socket *socket);
1479
1480 /**
1481   Acquire a table share instrumentation.
1482   @param temporary True for temporary tables
1483   @param share The SQL layer table share
1484   @return a table share instrumentation, or NULL
1485 */
1486 typedef struct PSI_table_share* (*get_table_share_v1_t)
1487   (my_bool temporary, struct TABLE_SHARE *share);
1488
1489 /**
1490   Release a table share.
1491   @param info the table share to release
1492 */
1493 typedef void (*release_table_share_v1_t)(struct PSI_table_share *share);
1494
1495 /**
1496   Drop a table share.
1497   @param temporary True for temporary tables
1498   @param schema_name the table schema name
1499   @param schema_name_length the table schema name length
1500   @param table_name the table name
1501   @param table_name_length the table name length
1502 */
1503 typedef void (*drop_table_share_v1_t)
1504   (my_bool temporary, const char *schema_name, int schema_name_length,
1505    const char *table_name, int table_name_length);
1506
1507 /**
1508   Open an instrumentation table handle.
1509   @param share the table to open
1510   @param identity table handle identity
1511   @return a table handle, or NULL
1512 */
1513 typedef struct PSI_table* (*open_table_v1_t)
1514   (struct PSI_table_share *share, const void *identity);
1515
1516 /**
1517   Unbind a table handle from the current thread.
1518   This operation happens when an opened table is added to the open table cache.
1519   @param table the table to unbind
1520 */
1521 typedef void (*unbind_table_v1_t)
1522   (struct PSI_table *table);
1523
1524 /**
1525   Rebind a table handle to the current thread.
1526   This operation happens when a table from the open table cache
1527   is reused for a thread.
1528   @param table the table to unbind
1529 */
1530 typedef PSI_table* (*rebind_table_v1_t)
1531   (PSI_table_share *share, const void *identity, PSI_table *table);
1532
1533 /**
1534   Close an instrumentation table handle.
1535   Note that the table handle is invalid after this call.
1536   @param table the table handle to close
1537 */
1538 typedef void (*close_table_v1_t)(struct TABLE_SHARE *server_share,
1539                                  struct PSI_table *table);
1540
1541 /**
1542   Create a file instrumentation for a created file.
1543   This method does not create the file itself, but is used to notify the
1544   instrumentation interface that a file was just created.
1545   @param key the file instrumentation key for this file
1546   @param name the file name
1547   @param file the file handle
1548 */
1549 typedef void (*create_file_v1_t)(PSI_file_key key, const char *name,
1550                                  File file);
1551
1552 /**
1553   Spawn a thread.
1554   This method creates a new thread, with instrumentation.
1555   @param key the instrumentation key for this thread
1556   @param thread the resulting thread
1557   @param attr the thread attributes
1558   @param start_routine the thread start routine
1559   @param arg the thread start routine argument
1560 */
1561 typedef int (*spawn_thread_v1_t)(PSI_thread_key key,
1562                                  my_thread_handle *thread,
1563                                  const my_thread_attr_t *attr,
1564                                  void *(*start_routine)(void*), void *arg);
1565
1566 /**
1567   Create instrumentation for a thread.
1568   @param key the registered key
1569   @param identity an address typical of the thread
1570   @return an instrumented thread
1571 */
1572 typedef struct PSI_thread* (*new_thread_v1_t)
1573   (PSI_thread_key key, const void *identity, ulonglong thread_id);
1574
1575 /**
1576   Assign a THD to an instrumented thread.
1577   @param thread the instrumented thread
1578   @param THD the sql layer THD to assign
1579 */
1580 typedef void (*set_thread_THD_v1_t)(struct PSI_thread *thread,
1581                                     THD *thd);
1582
1583 /**
1584   Assign an id to an instrumented thread.
1585   @param thread the instrumented thread
1586   @param id the id to assign
1587 */
1588 typedef void (*set_thread_id_v1_t)(struct PSI_thread *thread,
1589                                    ulonglong id);
1590
1591 /**
1592   Assign the current operating system thread id to an instrumented thread.
1593   The operating system task id is obtained from @c gettid()
1594   @param thread the instrumented thread
1595 */
1596 typedef void (*set_thread_os_id_v1_t)(struct PSI_thread *thread);
1597
1598 /**
1599   Get the instrumentation for the running thread.
1600   For this function to return a result,
1601   the thread instrumentation must have been attached to the
1602   running thread using @c set_thread()
1603   @return the instrumentation for the running thread
1604 */
1605 typedef struct PSI_thread* (*get_thread_v1_t)(void);
1606
1607 /**
1608   Assign a user name to the instrumented thread.
1609   @param user the user name
1610   @param user_len the user name length
1611 */
1612 typedef void (*set_thread_user_v1_t)(const char *user, int user_len);
1613
1614 /**
1615   Assign a user name and host name to the instrumented thread.
1616   @param user the user name
1617   @param user_len the user name length
1618   @param host the host name
1619   @param host_len the host name length
1620 */
1621 typedef void (*set_thread_account_v1_t)(const char *user, int user_len,
1622                                         const char *host, int host_len);
1623
1624 /**
1625   Assign a current database to the instrumented thread.
1626   @param db the database name
1627   @param db_len the database name length
1628 */
1629 typedef void (*set_thread_db_v1_t)(const char* db, int db_len);
1630
1631 /**
1632   Assign a current command to the instrumented thread.
1633   @param command the current command
1634 */
1635 typedef void (*set_thread_command_v1_t)(int command);
1636
1637 /**
1638   Assign a connection type to the instrumented thread.
1639   @param conn_type the connection type
1640 */
1641 typedef void (*set_connection_type_v1_t)(opaque_vio_type conn_type);
1642
1643
1644 /**
1645   Assign a start time to the instrumented thread.
1646   @param start_time the thread start time
1647 */
1648 typedef void (*set_thread_start_time_v1_t)(time_t start_time);
1649
1650 /**
1651   Assign a state to the instrumented thread.
1652   @param state the thread state
1653 */
1654 typedef void (*set_thread_state_v1_t)(const char* state);
1655
1656 /**
1657   Assign a process info to the instrumented thread.
1658   @param info the process into string
1659   @param info_len the process into string length
1660 */
1661 typedef void (*set_thread_info_v1_t)(const char* info, uint info_len);
1662
1663 /**
1664   Attach a thread instrumentation to the running thread.
1665   In case of thread pools, this method should be called when
1666   a worker thread picks a work item and runs it.
1667   Also, this method should be called if the instrumented code does not
1668   keep the pointer returned by @c new_thread() and relies on @c get_thread()
1669   instead.
1670   @param thread the thread instrumentation
1671 */
1672 typedef void (*set_thread_v1_t)(struct PSI_thread *thread);
1673
1674 /** Delete the current thread instrumentation. */
1675 typedef void (*delete_current_thread_v1_t)(void);
1676
1677 /** Delete a thread instrumentation. */
1678 typedef void (*delete_thread_v1_t)(struct PSI_thread *thread);
1679
1680 /**
1681   Get a file instrumentation locker, for opening or creating a file.
1682   @param state data storage for the locker
1683   @param key the file instrumentation key
1684   @param op the operation to perform
1685   @param name the file name
1686   @param identity a pointer representative of this file.
1687   @return a file locker, or NULL
1688 */
1689 typedef struct PSI_file_locker* (*get_thread_file_name_locker_v1_t)
1690   (struct PSI_file_locker_state_v1 *state,
1691    PSI_file_key key, enum PSI_file_operation op, const char *name,
1692    const void *identity);
1693
1694 /**
1695   Get a file stream instrumentation locker.
1696   @param state data storage for the locker
1697   @param file the file stream to access
1698   @param op the operation to perform
1699   @return a file locker, or NULL
1700 */
1701 typedef struct PSI_file_locker* (*get_thread_file_stream_locker_v1_t)
1702   (struct PSI_file_locker_state_v1 *state,
1703    struct PSI_file *file, enum PSI_file_operation op);
1704
1705 /**
1706   Get a file instrumentation locker.
1707   @param state data storage for the locker
1708   @param file the file descriptor to access
1709   @param op the operation to perform
1710   @return a file locker, or NULL
1711 */
1712 typedef struct PSI_file_locker* (*get_thread_file_descriptor_locker_v1_t)
1713   (struct PSI_file_locker_state_v1 *state,
1714    File file, enum PSI_file_operation op);
1715
1716 /**
1717   Record a mutex instrumentation unlock event.
1718   @param mutex the mutex instrumentation
1719 */
1720 typedef void (*unlock_mutex_v1_t)
1721   (struct PSI_mutex *mutex);
1722
1723 /**
1724   Record a rwlock instrumentation unlock event.
1725   @param rwlock the rwlock instrumentation
1726 */
1727 typedef void (*unlock_rwlock_v1_t)
1728   (struct PSI_rwlock *rwlock);
1729
1730 /**
1731   Record a condition instrumentation signal event.
1732   @param cond the cond instrumentation
1733 */
1734 typedef void (*signal_cond_v1_t)
1735   (struct PSI_cond *cond);
1736
1737 /**
1738   Record a condition instrumentation broadcast event.
1739   @param cond the cond instrumentation
1740 */
1741 typedef void (*broadcast_cond_v1_t)
1742   (struct PSI_cond *cond);
1743
1744 /**
1745   Record an idle instrumentation wait start event.
1746   @param state data storage for the locker
1747   @param file the source file name
1748   @param line the source line number
1749   @return an idle locker, or NULL
1750 */
1751 typedef struct PSI_idle_locker* (*start_idle_wait_v1_t)
1752   (struct PSI_idle_locker_state_v1 *state, const char *src_file, uint src_line);
1753
1754 /**
1755   Record an idle instrumentation wait end event.
1756   @param locker a thread locker for the running thread
1757 */
1758 typedef void (*end_idle_wait_v1_t)
1759   (struct PSI_idle_locker *locker);
1760
1761 /**
1762   Record a mutex instrumentation wait start event.
1763   @param state data storage for the locker
1764   @param mutex the instrumented mutex to lock
1765   @param op the operation to perform
1766   @param file the source file name
1767   @param line the source line number
1768   @return a mutex locker, or NULL
1769 */
1770 typedef struct PSI_mutex_locker* (*start_mutex_wait_v1_t)
1771   (struct PSI_mutex_locker_state_v1 *state,
1772    struct PSI_mutex *mutex,
1773    enum PSI_mutex_operation op,
1774    const char *src_file, uint src_line);
1775
1776 /**
1777   Record a mutex instrumentation wait end event.
1778   @param locker a thread locker for the running thread
1779   @param rc the wait operation return code
1780 */
1781 typedef void (*end_mutex_wait_v1_t)
1782   (struct PSI_mutex_locker *locker, int rc);
1783
1784 /**
1785   Record a rwlock instrumentation read wait start event.
1786   @param locker a thread locker for the running thread
1787   @param must must block: 1 for lock, 0 for trylock
1788 */
1789 typedef struct PSI_rwlock_locker* (*start_rwlock_rdwait_v1_t)
1790   (struct PSI_rwlock_locker_state_v1 *state,
1791    struct PSI_rwlock *rwlock,
1792    enum PSI_rwlock_operation op,
1793    const char *src_file, uint src_line);
1794
1795 /**
1796   Record a rwlock instrumentation read wait end event.
1797   @param locker a thread locker for the running thread
1798   @param rc the wait operation return code
1799 */
1800 typedef void (*end_rwlock_rdwait_v1_t)
1801   (struct PSI_rwlock_locker *locker, int rc);
1802
1803 /**
1804   Record a rwlock instrumentation write wait start event.
1805   @param locker a thread locker for the running thread
1806   @param must must block: 1 for lock, 0 for trylock
1807 */
1808 typedef struct PSI_rwlock_locker* (*start_rwlock_wrwait_v1_t)
1809   (struct PSI_rwlock_locker_state_v1 *state,
1810    struct PSI_rwlock *rwlock,
1811    enum PSI_rwlock_operation op,
1812    const char *src_file, uint src_line);
1813
1814 /**
1815   Record a rwlock instrumentation write wait end event.
1816   @param locker a thread locker for the running thread
1817   @param rc the wait operation return code
1818 */
1819 typedef void (*end_rwlock_wrwait_v1_t)
1820   (struct PSI_rwlock_locker *locker, int rc);
1821
1822 /**
1823   Record a condition instrumentation wait start event.
1824   @param locker a thread locker for the running thread
1825   @param must must block: 1 for wait, 0 for timedwait
1826 */
1827 typedef struct PSI_cond_locker* (*start_cond_wait_v1_t)
1828   (struct PSI_cond_locker_state_v1 *state,
1829    struct PSI_cond *cond,
1830    struct PSI_mutex *mutex,
1831    enum PSI_cond_operation op,
1832    const char *src_file, uint src_line);
1833
1834 /**
1835   Record a condition instrumentation wait end event.
1836   @param locker a thread locker for the running thread
1837   @param rc the wait operation return code
1838 */
1839 typedef void (*end_cond_wait_v1_t)
1840   (struct PSI_cond_locker *locker, int rc);
1841
1842 /**
1843   Record a table instrumentation io wait start event.
1844   @param locker a table locker for the running thread
1845   @param file the source file name
1846   @param line the source line number
1847 */
1848 typedef struct PSI_table_locker* (*start_table_io_wait_v1_t)
1849   (struct PSI_table_locker_state *state,
1850    struct PSI_table *table,
1851    enum PSI_table_io_operation op,
1852    uint index,
1853    const char *src_file, uint src_line);
1854
1855 /**
1856   Record a table instrumentation io wait end event.
1857   @param locker a table locker for the running thread
1858   @param numrows the number of rows involved in io
1859 */
1860 typedef void (*end_table_io_wait_v1_t)
1861   (struct PSI_table_locker *locker,
1862    ulonglong numrows);
1863
1864 /**
1865   Record a table instrumentation lock wait start event.
1866   @param locker a table locker for the running thread
1867   @param file the source file name
1868   @param line the source line number
1869 */
1870 typedef struct PSI_table_locker* (*start_table_lock_wait_v1_t)
1871   (struct PSI_table_locker_state *state,
1872    struct PSI_table *table,
1873    enum PSI_table_lock_operation op,
1874    ulong flags,
1875    const char *src_file, uint src_line);
1876
1877 /**
1878   Record a table instrumentation lock wait end event.
1879   @param locker a table locker for the running thread
1880 */
1881 typedef void (*end_table_lock_wait_v1_t)(struct PSI_table_locker *locker);
1882
1883 typedef void (*unlock_table_v1_t)(struct PSI_table *table);
1884
1885 /**
1886   Start a file instrumentation open operation.
1887   @param locker the file locker
1888   @param op the operation to perform
1889   @param src_file the source file name
1890   @param src_line the source line number
1891 */
1892 typedef void (*start_file_open_wait_v1_t)
1893   (struct PSI_file_locker *locker, const char *src_file, uint src_line);
1894
1895 /**
1896   End a file instrumentation open operation, for file streams.
1897   @param locker the file locker.
1898   @param result the opened file (NULL indicates failure, non NULL success).
1899   @return an instrumented file handle
1900 */
1901 typedef struct PSI_file* (*end_file_open_wait_v1_t)
1902   (struct PSI_file_locker *locker, void *result);
1903
1904 /**
1905   End a file instrumentation open operation, for non stream files.
1906   @param locker the file locker.
1907   @param file the file number assigned by open() or create() for this file.
1908 */
1909 typedef void (*end_file_open_wait_and_bind_to_descriptor_v1_t)
1910   (struct PSI_file_locker *locker, File file);
1911
1912 /**
1913   End a file instrumentation open operation, for non stream temporary files.
1914   @param locker the file locker.
1915   @param file the file number assigned by open() or create() for this file.
1916   @param filename the file name generated during temporary file creation.
1917 */
1918 typedef void (*end_temp_file_open_wait_and_bind_to_descriptor_v1_t)
1919   (struct PSI_file_locker *locker, File file, const char *filename);
1920
1921 /**
1922   Record a file instrumentation start event.
1923   @param locker a file locker for the running thread
1924   @param op file operation to be performed
1925   @param count the number of bytes requested, or 0 if not applicable
1926   @param src_file the source file name
1927   @param src_line the source line number
1928 */
1929 typedef void (*start_file_wait_v1_t)
1930   (struct PSI_file_locker *locker, size_t count,
1931    const char *src_file, uint src_line);
1932
1933 /**
1934   Record a file instrumentation end event.
1935   Note that for file close operations, the instrumented file handle
1936   associated with the file (which was provided to obtain a locker)
1937   is invalid after this call.
1938   @param locker a file locker for the running thread
1939   @param count the number of bytes actually used in the operation,
1940   or 0 if not applicable, or -1 if the operation failed
1941   @sa get_thread_file_name_locker
1942   @sa get_thread_file_stream_locker
1943   @sa get_thread_file_descriptor_locker
1944 */
1945 typedef void (*end_file_wait_v1_t)
1946   (struct PSI_file_locker *locker, size_t count);
1947
1948 /**
1949   Start a file instrumentation close operation.
1950   @param locker the file locker
1951   @param op the operation to perform
1952   @param src_file the source file name
1953   @param src_line the source line number
1954 */
1955 typedef void (*start_file_close_wait_v1_t)
1956   (struct PSI_file_locker *locker, const char *src_file, uint src_line);
1957
1958 /**
1959   End a file instrumentation close operation.
1960   @param locker the file locker.
1961   @param rc the close operation return code (0 for success).
1962   @return an instrumented file handle
1963 */
1964 typedef void (*end_file_close_wait_v1_t)
1965   (struct PSI_file_locker *locker, int rc);
1966
1967 /**
1968   Start a new stage, and implicitly end the previous stage.
1969   @param key the key of the new stage
1970   @param src_file the source file name
1971   @param src_line the source line number
1972   @return the new stage progress
1973 */
1974 typedef PSI_stage_progress* (*start_stage_v1_t)
1975   (PSI_stage_key key, const char *src_file, int src_line);
1976
1977 typedef PSI_stage_progress* (*get_current_stage_progress_v1_t)(void);
1978
1979 /** End the current stage. */
1980 typedef void (*end_stage_v1_t) (void);
1981
1982 /**
1983   Get a statement instrumentation locker.
1984   @param state data storage for the locker
1985   @param key the statement instrumentation key
1986   @param charset client character set
1987   @return a statement locker, or NULL
1988 */
1989 typedef struct PSI_statement_locker* (*get_thread_statement_locker_v1_t)
1990   (struct PSI_statement_locker_state_v1 *state,
1991    PSI_statement_key key, const void *charset, PSI_sp_share *sp_share);
1992
1993 /**
1994   Refine a statement locker to a more specific key.
1995   Note that only events declared mutable can be refined.
1996   @param the statement locker for the current event
1997   @param key the new key for the event
1998   @sa PSI_FLAG_MUTABLE
1999 */
2000 typedef struct PSI_statement_locker* (*refine_statement_v1_t)
2001   (struct PSI_statement_locker *locker,
2002    PSI_statement_key key);
2003
2004 /**
2005   Start a new statement event.
2006   @param locker the statement locker for this event
2007   @param db the active database name for this statement
2008   @param db_length the active database name length for this statement
2009   @param src_file source file name
2010   @param src_line source line number
2011 */
2012 typedef void (*start_statement_v1_t)
2013   (struct PSI_statement_locker *locker,
2014    const char *db, uint db_length,
2015    const char *src_file, uint src_line);
2016
2017 /**
2018   Set the statement text for a statement event.
2019   @param locker the current statement locker
2020   @param text the statement text
2021   @param text_len the statement text length
2022 */
2023 typedef void (*set_statement_text_v1_t)
2024   (struct PSI_statement_locker *locker,
2025    const char *text, uint text_len);
2026
2027 /**
2028   Set a statement event lock time.
2029   @param locker the statement locker
2030   @param lock_time the locked time, in microseconds
2031 */
2032 typedef void (*set_statement_lock_time_t)
2033   (struct PSI_statement_locker *locker, ulonglong lock_time);
2034
2035 /**
2036   Set a statement event rows sent metric.
2037   @param locker the statement locker
2038   @param count the number of rows sent
2039 */
2040 typedef void (*set_statement_rows_sent_t)
2041   (struct PSI_statement_locker *locker, ulonglong count);
2042
2043 /**
2044   Set a statement event rows examined metric.
2045   @param locker the statement locker
2046   @param count the number of rows examined
2047 */
2048 typedef void (*set_statement_rows_examined_t)
2049   (struct PSI_statement_locker *locker, ulonglong count);
2050
2051 /**
2052   Increment a statement event "created tmp disk tables" metric.
2053   @param locker the statement locker
2054   @param count the metric increment value
2055 */
2056 typedef void (*inc_statement_created_tmp_disk_tables_t)
2057   (struct PSI_statement_locker *locker, ulong count);
2058
2059 /**
2060   Increment a statement event "created tmp tables" metric.
2061   @param locker the statement locker
2062   @param count the metric increment value
2063 */
2064 typedef void (*inc_statement_created_tmp_tables_t)
2065   (struct PSI_statement_locker *locker, ulong count);
2066
2067 /**
2068   Increment a statement event "select full join" metric.
2069   @param locker the statement locker
2070   @param count the metric increment value
2071 */
2072 typedef void (*inc_statement_select_full_join_t)
2073   (struct PSI_statement_locker *locker, ulong count);
2074
2075 /**
2076   Increment a statement event "select full range join" metric.
2077   @param locker the statement locker
2078   @param count the metric increment value
2079 */
2080 typedef void (*inc_statement_select_full_range_join_t)
2081   (struct PSI_statement_locker *locker, ulong count);
2082
2083 /**
2084   Increment a statement event "select range join" metric.
2085   @param locker the statement locker
2086   @param count the metric increment value
2087 */
2088 typedef void (*inc_statement_select_range_t)
2089   (struct PSI_statement_locker *locker, ulong count);
2090
2091 /**
2092   Increment a statement event "select range check" metric.
2093   @param locker the statement locker
2094   @param count the metric increment value
2095 */
2096 typedef void (*inc_statement_select_range_check_t)
2097   (struct PSI_statement_locker *locker, ulong count);
2098
2099 /**
2100   Increment a statement event "select scan" metric.
2101   @param locker the statement locker
2102   @param count the metric increment value
2103 */
2104 typedef void (*inc_statement_select_scan_t)
2105   (struct PSI_statement_locker *locker, ulong count);
2106
2107 /**
2108   Increment a statement event "sort merge passes" metric.
2109   @param locker the statement locker
2110   @param count the metric increment value
2111 */
2112 typedef void (*inc_statement_sort_merge_passes_t)
2113   (struct PSI_statement_locker *locker, ulong count);
2114
2115 /**
2116   Increment a statement event "sort range" metric.
2117   @param locker the statement locker
2118   @param count the metric increment value
2119 */
2120 typedef void (*inc_statement_sort_range_t)
2121   (struct PSI_statement_locker *locker, ulong count);
2122
2123 /**
2124   Increment a statement event "sort rows" metric.
2125   @param locker the statement locker
2126   @param count the metric increment value
2127 */
2128 typedef void (*inc_statement_sort_rows_t)
2129   (struct PSI_statement_locker *locker, ulong count);
2130
2131 /**
2132   Increment a statement event "sort scan" metric.
2133   @param locker the statement locker
2134   @param count the metric increment value
2135 */
2136 typedef void (*inc_statement_sort_scan_t)
2137   (struct PSI_statement_locker *locker, ulong count);
2138
2139 /**
2140   Set a statement event "no index used" metric.
2141   @param locker the statement locker
2142   @param count the metric value
2143 */
2144 typedef void (*set_statement_no_index_used_t)
2145   (struct PSI_statement_locker *locker);
2146
2147 /**
2148   Set a statement event "no good index used" metric.
2149   @param locker the statement locker
2150   @param count the metric value
2151 */
2152 typedef void (*set_statement_no_good_index_used_t)
2153   (struct PSI_statement_locker *locker);
2154
2155 /**
2156   End a statement event.
2157   @param locker the statement locker
2158   @param stmt_da the statement diagnostics area.
2159   @sa Diagnostics_area
2160 */
2161 typedef void (*end_statement_v1_t)
2162   (struct PSI_statement_locker *locker, void *stmt_da);
2163
2164 /**
2165   Get a transaction instrumentation locker.
2166   @param state data storage for the locker
2167   @param xid the xid for this transaction
2168   @param trxid the InnoDB transaction id
2169   @param iso_level isolation level for this transaction
2170   @param read_only true if transaction access mode is read-only
2171   @param autocommit true if transaction is autocommit
2172   @return a transaction locker, or NULL
2173 */
2174 typedef struct PSI_transaction_locker* (*get_thread_transaction_locker_v1_t)
2175   (struct PSI_transaction_locker_state_v1 *state, const void *xid,
2176    const ulonglong *trxid, int isolation_level, my_bool read_only,
2177    my_bool autocommit);
2178
2179 /**
2180   Start a new transaction event.
2181   @param locker the transaction locker for this event
2182   @param src_file source file name
2183   @param src_line source line number
2184 */
2185 typedef void (*start_transaction_v1_t)
2186   (struct PSI_transaction_locker *locker,
2187    const char *src_file, uint src_line);
2188
2189 /**
2190   Set the transaction xid.
2191   @param locker the transaction locker for this event
2192   @param xid the id of the XA transaction
2193   #param xa_state is the state of the XA transaction
2194 */
2195 typedef void (*set_transaction_xid_v1_t)
2196   (struct PSI_transaction_locker *locker,
2197    const void *xid, int xa_state);
2198
2199 /**
2200   Set the state of the XA transaction.
2201   @param locker the transaction locker for this event
2202   @param xa_state the new state of the xa transaction
2203 */
2204 typedef void (*set_transaction_xa_state_v1_t)
2205   (struct PSI_transaction_locker *locker,
2206    int xa_state);
2207
2208 /**
2209   Set the transaction gtid.
2210   @param locker the transaction locker for this event
2211   @param sid the source id for the transaction, mapped from sidno
2212   @param gtid_spec the gtid specifier for the transaction
2213 */
2214 typedef void (*set_transaction_gtid_v1_t)
2215   (struct PSI_transaction_locker *locker,
2216    const void *sid, const void *gtid_spec);
2217
2218 /**
2219   Set the transaction trx_id.
2220   @param locker the transaction locker for this event
2221   @param trxid the storage engine transaction ID
2222 */
2223 typedef void (*set_transaction_trxid_v1_t)
2224   (struct PSI_transaction_locker *locker,
2225    const ulonglong *trxid);
2226
2227 /**
2228   Increment a transaction event savepoint count.
2229   @param locker the transaction locker
2230   @param count the increment value
2231 */
2232 typedef void (*inc_transaction_savepoints_v1_t)
2233   (struct PSI_transaction_locker *locker, ulong count);
2234
2235 /**
2236   Increment a transaction event rollback to savepoint count.
2237   @param locker the transaction locker
2238   @param count the increment value
2239 */
2240 typedef void (*inc_transaction_rollback_to_savepoint_v1_t)
2241   (struct PSI_transaction_locker *locker, ulong count);
2242
2243 /**
2244   Increment a transaction event release savepoint count.
2245   @param locker the transaction locker
2246   @param count the increment value
2247 */
2248 typedef void (*inc_transaction_release_savepoint_v1_t)
2249   (struct PSI_transaction_locker *locker, ulong count);
2250
2251 /**
2252   Commit or rollback the transaction.
2253   @param locker the transaction locker for this event
2254   @param commit true if transaction was committed, false if rolled back
2255 */
2256 typedef void (*end_transaction_v1_t)
2257   (struct PSI_transaction_locker *locker,
2258    my_bool commit);
2259
2260 /**
2261   Record a socket instrumentation start event.
2262   @param locker a socket locker for the running thread
2263   @param op socket operation to be performed
2264   @param count the number of bytes requested, or 0 if not applicable
2265   @param src_file the source file name
2266   @param src_line the source line number
2267 */
2268 typedef struct PSI_socket_locker* (*start_socket_wait_v1_t)
2269   (struct PSI_socket_locker_state_v1 *state,
2270    struct PSI_socket *socket,
2271    enum PSI_socket_operation op,
2272    size_t count,
2273    const char *src_file, uint src_line);
2274
2275 /**
2276   Record a socket instrumentation end event.
2277   Note that for socket close operations, the instrumented socket handle
2278   associated with the socket (which was provided to obtain a locker)
2279   is invalid after this call.
2280   @param locker a socket locker for the running thread
2281   @param count the number of bytes actually used in the operation,
2282   or 0 if not applicable, or -1 if the operation failed
2283   @sa get_thread_socket_locker
2284 */
2285 typedef void (*end_socket_wait_v1_t)
2286   (struct PSI_socket_locker *locker, size_t count);
2287
2288 /**
2289   Set the socket state for an instrumented socket.
2290     @param socket the instrumented socket
2291     @param state socket state
2292   */
2293 typedef void (*set_socket_state_v1_t)(struct PSI_socket *socket,
2294                                       enum PSI_socket_state state);
2295
2296 /**
2297   Set the socket info for an instrumented socket.
2298   @param socket the instrumented socket
2299   @param fd the socket descriptor
2300   @param addr the socket ip address
2301   @param addr_len length of socket ip address
2302   @param thread_id associated thread id
2303 */
2304 typedef void (*set_socket_info_v1_t)(struct PSI_socket *socket,
2305                                      const my_socket *fd,
2306                                      const struct sockaddr *addr,
2307                                      socklen_t addr_len);
2308
2309 /**
2310   Bind a socket to the thread that owns it.
2311   @param socket instrumented socket
2312 */
2313 typedef void (*set_socket_thread_owner_v1_t)(struct PSI_socket *socket);
2314
2315 /**
2316   Get a prepare statement.
2317   @param locker a statement locker for the running thread.
2318 */
2319 typedef PSI_prepared_stmt* (*create_prepared_stmt_v1_t)
2320   (void *identity, uint stmt_id, PSI_statement_locker *locker,
2321    const char *stmt_name, size_t stmt_name_length,
2322    const char *name, size_t length);
2323
2324 /**
2325   destroy a prepare statement.
2326   @param prepared_stmt prepared statement.
2327 */
2328 typedef void (*destroy_prepared_stmt_v1_t)
2329   (PSI_prepared_stmt *prepared_stmt);
2330
2331 /**
2332   repreare a prepare statement.
2333   @param prepared_stmt prepared statement.
2334 */
2335 typedef void (*reprepare_prepared_stmt_v1_t)
2336   (PSI_prepared_stmt *prepared_stmt);
2337
2338 /**
2339   Record a prepare statement instrumentation execute event.
2340   @param locker a statement locker for the running thread.
2341   @param prepared_stmt prepared statement.
2342 */
2343 typedef void (*execute_prepared_stmt_v1_t)
2344   (PSI_statement_locker *locker, PSI_prepared_stmt* prepared_stmt);
2345
2346 /**
2347   Get a digest locker for the current statement.
2348   @param locker a statement locker for the running thread
2349 */
2350 typedef struct PSI_digest_locker * (*digest_start_v1_t)
2351   (struct PSI_statement_locker *locker);
2352
2353 /**
2354   Add a token to the current digest instrumentation.
2355   @param locker a digest locker for the current statement
2356   @param token the lexical token to add
2357   @param yylval the lexical token attributes
2358 */
2359 typedef void (*digest_end_v1_t)
2360   (struct PSI_digest_locker *locker, const struct sql_digest_storage *digest);
2361
2362 typedef PSI_sp_locker* (*start_sp_v1_t)
2363   (struct PSI_sp_locker_state_v1 *state, struct PSI_sp_share* sp_share);
2364
2365 typedef void (*end_sp_v1_t)
2366   (struct PSI_sp_locker *locker);
2367
2368 typedef void (*drop_sp_v1_t)
2369   (uint object_type,
2370    const char *schema_name, uint schema_name_length,
2371    const char *object_name, uint object_name_length);
2372
2373 /**
2374   Acquire a sp share instrumentation.
2375   @param type of stored program
2376   @param schema name of stored program
2377   @param name of stored program
2378   @return a stored program share instrumentation, or NULL
2379 */
2380 typedef struct PSI_sp_share* (*get_sp_share_v1_t)
2381   (uint object_type,
2382    const char *schema_name, uint schema_name_length,
2383    const char *object_name, uint object_name_length);
2384
2385 /**
2386   Release a stored program share.
2387   @param info the stored program share to release
2388 */
2389 typedef void (*release_sp_share_v1_t)(struct PSI_sp_share *share);
2390
2391 typedef PSI_metadata_lock* (*create_metadata_lock_v1_t)
2392   (void *identity,
2393    const MDL_key *key,
2394    opaque_mdl_type mdl_type,
2395    opaque_mdl_duration mdl_duration,
2396    opaque_mdl_status mdl_status,
2397    const char *src_file,
2398    uint src_line);
2399
2400 typedef void (*set_metadata_lock_status_v1_t)(PSI_metadata_lock *lock,
2401                                               opaque_mdl_status mdl_status);
2402
2403 typedef void (*destroy_metadata_lock_v1_t)(PSI_metadata_lock *lock);
2404
2405 typedef struct PSI_metadata_locker* (*start_metadata_wait_v1_t)
2406   (struct PSI_metadata_locker_state_v1 *state,
2407    struct PSI_metadata_lock *mdl,
2408    const char *src_file, uint src_line);
2409
2410 typedef void (*end_metadata_wait_v1_t)
2411   (struct PSI_metadata_locker *locker, int rc);
2412
2413 /**
2414   Stores an array of connection attributes
2415   @param buffer         char array of length encoded connection attributes
2416                         in network format
2417   @param length         length of the data in buffer
2418   @param from_cs        charset in which @c buffer is encoded
2419   @return state
2420     @retval  non_0    attributes truncated
2421     @retval  0        stored the attribute
2422 */
2423 typedef int (*set_thread_connect_attrs_v1_t)(const char *buffer, uint length,
2424                                              const void *from_cs);
2425
2426 /**
2427   Performance Schema Interface, version 1.
2428   @since PSI_VERSION_1
2429 */
2430 struct PSI_v1
2431 {
2432   /** @sa register_mutex_v1_t. */
2433   register_mutex_v1_t register_mutex;
2434   /** @sa register_rwlock_v1_t. */
2435   register_rwlock_v1_t register_rwlock;
2436   /** @sa register_cond_v1_t. */
2437   register_cond_v1_t register_cond;
2438   /** @sa register_thread_v1_t. */
2439   register_thread_v1_t register_thread;
2440   /** @sa register_file_v1_t. */
2441   register_file_v1_t register_file;
2442   /** @sa register_stage_v1_t. */
2443   register_stage_v1_t register_stage;
2444   /** @sa register_statement_v1_t. */
2445   register_statement_v1_t register_statement;
2446   /** @sa register_socket_v1_t. */
2447   register_socket_v1_t register_socket;
2448   /** @sa init_mutex_v1_t. */
2449   init_mutex_v1_t init_mutex;
2450   /** @sa destroy_mutex_v1_t. */
2451   destroy_mutex_v1_t destroy_mutex;
2452   /** @sa init_rwlock_v1_t. */
2453   init_rwlock_v1_t init_rwlock;
2454   /** @sa destroy_rwlock_v1_t. */
2455   destroy_rwlock_v1_t destroy_rwlock;
2456   /** @sa init_cond_v1_t. */
2457   init_cond_v1_t init_cond;
2458   /** @sa destroy_cond_v1_t. */
2459   destroy_cond_v1_t destroy_cond;
2460   /** @sa init_socket_v1_t. */
2461   init_socket_v1_t init_socket;
2462   /** @sa destroy_socket_v1_t. */
2463   destroy_socket_v1_t destroy_socket;
2464
2465   /** @sa get_table_share_v1_t. */
2466   get_table_share_v1_t get_table_share;
2467   /** @sa release_table_share_v1_t. */
2468   release_table_share_v1_t release_table_share;
2469   /** @sa drop_table_share_v1_t. */
2470   drop_table_share_v1_t drop_table_share;
2471   /** @sa open_table_v1_t. */
2472   open_table_v1_t open_table;
2473   /** @sa unbind_table_v1_t. */
2474   unbind_table_v1_t unbind_table;
2475   /** @sa rebind_table_v1_t. */
2476   rebind_table_v1_t rebind_table;
2477   /** @sa close_table_v1_t. */
2478   close_table_v1_t close_table;
2479   /** @sa create_file_v1_t. */
2480   create_file_v1_t create_file;
2481   /** @sa spawn_thread_v1_t. */
2482   spawn_thread_v1_t spawn_thread;
2483   /** @sa new_thread_v1_t. */
2484   new_thread_v1_t new_thread;
2485   /** @sa set_thread_id_v1_t. */
2486   set_thread_id_v1_t set_thread_id;
2487   /** @sa set_thread_THD_v1_t. */
2488   set_thread_THD_v1_t set_thread_THD;
2489   /** @sa set_thread_os_id_v1_t. */
2490   set_thread_os_id_v1_t set_thread_os_id;
2491   /** @sa get_thread_v1_t. */
2492   get_thread_v1_t get_thread;
2493   /** @sa set_thread_user_v1_t. */
2494   set_thread_user_v1_t set_thread_user;
2495   /** @sa set_thread_account_v1_t. */
2496   set_thread_account_v1_t set_thread_account;
2497   /** @sa set_thread_db_v1_t. */
2498   set_thread_db_v1_t set_thread_db;
2499   /** @sa set_thread_command_v1_t. */
2500   set_thread_command_v1_t set_thread_command;
2501   /** @sa set_connection_type_v1_t. */
2502   set_connection_type_v1_t set_connection_type;
2503   /** @sa set_thread_start_time_v1_t. */
2504   set_thread_start_time_v1_t set_thread_start_time;
2505   /** @sa set_thread_state_v1_t. */
2506   set_thread_state_v1_t set_thread_state;
2507   /** @sa set_thread_info_v1_t. */
2508   set_thread_info_v1_t set_thread_info;
2509   /** @sa set_thread_v1_t. */
2510   set_thread_v1_t set_thread;
2511   /** @sa delete_current_thread_v1_t. */
2512   delete_current_thread_v1_t delete_current_thread;
2513   /** @sa delete_thread_v1_t. */
2514   delete_thread_v1_t delete_thread;
2515   /** @sa get_thread_file_name_locker_v1_t. */
2516   get_thread_file_name_locker_v1_t get_thread_file_name_locker;
2517   /** @sa get_thread_file_stream_locker_v1_t. */
2518   get_thread_file_stream_locker_v1_t get_thread_file_stream_locker;
2519   /** @sa get_thread_file_descriptor_locker_v1_t. */
2520   get_thread_file_descriptor_locker_v1_t get_thread_file_descriptor_locker;
2521   /** @sa unlock_mutex_v1_t. */
2522   unlock_mutex_v1_t unlock_mutex;
2523   /** @sa unlock_rwlock_v1_t. */
2524   unlock_rwlock_v1_t unlock_rwlock;
2525   /** @sa signal_cond_v1_t. */
2526   signal_cond_v1_t signal_cond;
2527   /** @sa broadcast_cond_v1_t. */
2528   broadcast_cond_v1_t broadcast_cond;
2529   /** @sa start_idle_wait_v1_t. */
2530   start_idle_wait_v1_t start_idle_wait;
2531   /** @sa end_idle_wait_v1_t. */
2532   end_idle_wait_v1_t end_idle_wait;
2533   /** @sa start_mutex_wait_v1_t. */
2534   start_mutex_wait_v1_t start_mutex_wait;
2535   /** @sa end_mutex_wait_v1_t. */
2536   end_mutex_wait_v1_t end_mutex_wait;
2537   /** @sa start_rwlock_rdwait_v1_t. */
2538   start_rwlock_rdwait_v1_t start_rwlock_rdwait;
2539   /** @sa end_rwlock_rdwait_v1_t. */
2540   end_rwlock_rdwait_v1_t end_rwlock_rdwait;
2541   /** @sa start_rwlock_wrwait_v1_t. */
2542   start_rwlock_wrwait_v1_t start_rwlock_wrwait;
2543   /** @sa end_rwlock_wrwait_v1_t. */
2544   end_rwlock_wrwait_v1_t end_rwlock_wrwait;
2545   /** @sa start_cond_wait_v1_t. */
2546   start_cond_wait_v1_t start_cond_wait;
2547   /** @sa end_cond_wait_v1_t. */
2548   end_cond_wait_v1_t end_cond_wait;
2549   /** @sa start_table_io_wait_v1_t. */
2550   start_table_io_wait_v1_t start_table_io_wait;
2551   /** @sa end_table_io_wait_v1_t. */
2552   end_table_io_wait_v1_t end_table_io_wait;
2553   /** @sa start_table_lock_wait_v1_t. */
2554   start_table_lock_wait_v1_t start_table_lock_wait;
2555   /** @sa end_table_lock_wait_v1_t. */
2556   end_table_lock_wait_v1_t end_table_lock_wait;
2557   /** @sa start_file_open_wait_v1_t. */
2558   start_file_open_wait_v1_t start_file_open_wait;
2559   /** @sa end_file_open_wait_v1_t. */
2560   end_file_open_wait_v1_t end_file_open_wait;
2561   /** @sa end_file_open_wait_and_bind_to_descriptor_v1_t. */
2562   end_file_open_wait_and_bind_to_descriptor_v1_t
2563     end_file_open_wait_and_bind_to_descriptor;
2564   /** @sa end_temp_file_open_wait_and_bind_to_descriptor_v1_t. */
2565   end_temp_file_open_wait_and_bind_to_descriptor_v1_t
2566     end_temp_file_open_wait_and_bind_to_descriptor;
2567   /** @sa start_file_wait_v1_t. */
2568   start_file_wait_v1_t start_file_wait;
2569   /** @sa end_file_wait_v1_t. */
2570   end_file_wait_v1_t end_file_wait;
2571   /** @sa start_file_close_wait_v1_t. */
2572   start_file_close_wait_v1_t start_file_close_wait;
2573   /** @sa end_file_close_wait_v1_t. */
2574   end_file_close_wait_v1_t end_file_close_wait;
2575   /** @sa start_stage_v1_t. */
2576   start_stage_v1_t start_stage;
2577   /** @sa get_current_stage_progress_v1_t. */
2578   get_current_stage_progress_v1_t get_current_stage_progress;
2579   /** @sa end_stage_v1_t. */
2580   end_stage_v1_t end_stage;
2581   /** @sa get_thread_statement_locker_v1_t. */
2582   get_thread_statement_locker_v1_t get_thread_statement_locker;
2583   /** @sa refine_statement_v1_t. */
2584   refine_statement_v1_t refine_statement;
2585   /** @sa start_statement_v1_t. */
2586   start_statement_v1_t start_statement;
2587   /** @sa set_statement_text_v1_t. */
2588   set_statement_text_v1_t set_statement_text;
2589   /** @sa set_statement_lock_time_t. */
2590   set_statement_lock_time_t set_statement_lock_time;
2591   /** @sa set_statement_rows_sent_t. */
2592   set_statement_rows_sent_t set_statement_rows_sent;
2593   /** @sa set_statement_rows_examined_t. */
2594   set_statement_rows_examined_t set_statement_rows_examined;
2595   /** @sa inc_statement_created_tmp_disk_tables. */
2596   inc_statement_created_tmp_disk_tables_t inc_statement_created_tmp_disk_tables;
2597   /** @sa inc_statement_created_tmp_tables. */
2598   inc_statement_created_tmp_tables_t inc_statement_created_tmp_tables;
2599   /** @sa inc_statement_select_full_join. */
2600   inc_statement_select_full_join_t inc_statement_select_full_join;
2601   /** @sa inc_statement_select_full_range_join. */
2602   inc_statement_select_full_range_join_t inc_statement_select_full_range_join;
2603   /** @sa inc_statement_select_range. */
2604   inc_statement_select_range_t inc_statement_select_range;
2605   /** @sa inc_statement_select_range_check. */
2606   inc_statement_select_range_check_t inc_statement_select_range_check;
2607   /** @sa inc_statement_select_scan. */
2608   inc_statement_select_scan_t inc_statement_select_scan;
2609   /** @sa inc_statement_sort_merge_passes. */
2610   inc_statement_sort_merge_passes_t inc_statement_sort_merge_passes;
2611   /** @sa inc_statement_sort_range. */
2612   inc_statement_sort_range_t inc_statement_sort_range;
2613   /** @sa inc_statement_sort_rows. */
2614   inc_statement_sort_rows_t inc_statement_sort_rows;
2615   /** @sa inc_statement_sort_scan. */
2616   inc_statement_sort_scan_t inc_statement_sort_scan;
2617   /** @sa set_statement_no_index_used. */
2618   set_statement_no_index_used_t set_statement_no_index_used;
2619   /** @sa set_statement_no_good_index_used. */
2620   set_statement_no_good_index_used_t set_statement_no_good_index_used;
2621   /** @sa end_statement_v1_t. */
2622   end_statement_v1_t end_statement;
2623   /** @sa get_thread_transaction_locker_v1_t. */
2624   get_thread_transaction_locker_v1_t get_thread_transaction_locker;
2625   /** @sa start_transaction_v1_t. */
2626   start_transaction_v1_t start_transaction;
2627   /** @sa set_transaction_xid_v1_t. */
2628   set_transaction_xid_v1_t set_transaction_xid;
2629   /** @sa set_transaction_xa_state_v1_t. */
2630   set_transaction_xa_state_v1_t set_transaction_xa_state;
2631   /** @sa set_transaction_gtid_v1_t. */
2632   set_transaction_gtid_v1_t set_transaction_gtid;
2633   /** @sa set_transaction_trxid_v1_t. */
2634   set_transaction_trxid_v1_t set_transaction_trxid;
2635   /** @sa inc_transaction_savepoints_v1_t. */
2636   inc_transaction_savepoints_v1_t inc_transaction_savepoints;
2637   /** @sa inc_transaction_rollback_to_savepoint_v1_t. */
2638   inc_transaction_rollback_to_savepoint_v1_t inc_transaction_rollback_to_savepoint;
2639   /** @sa inc_transaction_release_savepoint_v1_t. */
2640   inc_transaction_release_savepoint_v1_t inc_transaction_release_savepoint;
2641   /** @sa end_transaction_v1_t. */
2642   end_transaction_v1_t end_transaction;
2643   /** @sa start_socket_wait_v1_t. */
2644   start_socket_wait_v1_t start_socket_wait;
2645   /** @sa end_socket_wait_v1_t. */
2646   end_socket_wait_v1_t end_socket_wait;
2647   /** @sa set_socket_state_v1_t. */
2648   set_socket_state_v1_t set_socket_state;
2649   /** @sa set_socket_info_v1_t. */
2650   set_socket_info_v1_t set_socket_info;
2651   /** @sa set_socket_thread_owner_v1_t. */
2652   set_socket_thread_owner_v1_t set_socket_thread_owner;
2653   /** @sa create_prepared_stmt_v1_t. */
2654   create_prepared_stmt_v1_t create_prepared_stmt;
2655   /** @sa destroy_prepared_stmt_v1_t. */
2656   destroy_prepared_stmt_v1_t destroy_prepared_stmt;
2657   /** @sa reprepare_prepared_stmt_v1_t. */
2658   reprepare_prepared_stmt_v1_t reprepare_prepared_stmt;
2659   /** @sa execute_prepared_stmt_v1_t. */
2660   execute_prepared_stmt_v1_t execute_prepared_stmt;
2661   /** @sa digest_start_v1_t. */
2662   digest_start_v1_t digest_start;
2663   /** @sa digest_end_v1_t. */
2664   digest_end_v1_t digest_end;
2665   /** @sa set_thread_connect_attrs_v1_t. */
2666   set_thread_connect_attrs_v1_t set_thread_connect_attrs;
2667   /** @sa start_sp_v1_t. */
2668   start_sp_v1_t start_sp;
2669   /** @sa start_sp_v1_t. */
2670   end_sp_v1_t end_sp;
2671   /** @sa drop_sp_v1_t. */
2672   drop_sp_v1_t drop_sp;
2673   /** @sa get_sp_share_v1_t. */
2674   get_sp_share_v1_t get_sp_share;
2675   /** @sa release_sp_share_v1_t. */
2676   release_sp_share_v1_t release_sp_share;
2677   /** @sa register_memory_v1_t. */
2678   register_memory_v1_t register_memory;
2679   /** @sa memory_alloc_v1_t. */
2680   memory_alloc_v1_t memory_alloc;
2681   /** @sa memory_realloc_v1_t. */
2682   memory_realloc_v1_t memory_realloc;
2683   /** @sa memory_claim_v1_t. */
2684   memory_claim_v1_t memory_claim;
2685   /** @sa memory_free_v1_t. */
2686   memory_free_v1_t memory_free;
2687
2688   unlock_table_v1_t unlock_table;
2689
2690   create_metadata_lock_v1_t create_metadata_lock;
2691   set_metadata_lock_status_v1_t set_metadata_lock_status;
2692   destroy_metadata_lock_v1_t destroy_metadata_lock;
2693
2694   start_metadata_wait_v1_t start_metadata_wait;
2695   end_metadata_wait_v1_t end_metadata_wait;
2696 };
2697
2698 /** @} (end of group Group_PSI_v1) */
2699
2700 #endif /* HAVE_PSI_1 */
2701
2702 #ifdef USE_PSI_2
2703 #define HAVE_PSI_2
2704 #endif
2705
2706 #ifdef HAVE_PSI_2
2707
2708 /**
2709   @defgroup Group_PSI_v2 Application Binary Interface, version 2
2710   @ingroup Instrumentation_interface
2711   @{
2712 */
2713
2714 /**
2715   Performance Schema Interface, version 2.
2716   This is a placeholder, this interface is not defined yet.
2717   @since PSI_VERSION_2
2718 */
2719 struct PSI_v2
2720 {
2721   /** Placeholder */
2722   int placeholder;
2723   /* ... extended interface ... */
2724 };
2725
2726 /** Placeholder */
2727 struct PSI_mutex_info_v2
2728 {
2729   /** Placeholder */
2730   int placeholder;
2731 };
2732
2733 /** Placeholder */
2734 struct PSI_rwlock_info_v2
2735 {
2736   /** Placeholder */
2737   int placeholder;
2738 };
2739
2740 /** Placeholder */
2741 struct PSI_cond_info_v2
2742 {
2743   /** Placeholder */
2744   int placeholder;
2745 };
2746
2747 /** Placeholder */
2748 struct PSI_thread_info_v2
2749 {
2750   /** Placeholder */
2751   int placeholder;
2752 };
2753
2754 /** Placeholder */
2755 struct PSI_file_info_v2
2756 {
2757   /** Placeholder */
2758   int placeholder;
2759 };
2760
2761 /** Placeholder */
2762 struct PSI_stage_info_v2
2763 {
2764   /** Placeholder */
2765   int placeholder;
2766 };
2767
2768 /** Placeholder */
2769 struct PSI_statement_info_v2
2770 {
2771   /** Placeholder */
2772   int placeholder;
2773 };
2774
2775 /** Placeholder */
2776 struct PSI_transaction_info_v2
2777 {
2778   /** Placeholder */
2779   int placeholder;
2780 };
2781
2782 /** Placeholder */
2783 struct PSI_idle_locker_state_v2
2784 {
2785   /** Placeholder */
2786   int placeholder;
2787 };
2788
2789 /** Placeholder */
2790 struct PSI_mutex_locker_state_v2
2791 {
2792   /** Placeholder */
2793   int placeholder;
2794 };
2795
2796 /** Placeholder */
2797 struct PSI_rwlock_locker_state_v2
2798 {
2799   /** Placeholder */
2800   int placeholder;
2801 };
2802
2803 /** Placeholder */
2804 struct PSI_cond_locker_state_v2
2805 {
2806   /** Placeholder */
2807   int placeholder;
2808 };
2809
2810 /** Placeholder */
2811 struct PSI_file_locker_state_v2
2812 {
2813   /** Placeholder */
2814   int placeholder;
2815 };
2816
2817 /** Placeholder */
2818 struct PSI_statement_locker_state_v2
2819 {
2820   /** Placeholder */
2821   int placeholder;
2822 };
2823
2824 /** Placeholder */
2825 struct PSI_transaction_locker_state_v2
2826 {
2827   /** Placeholder */
2828   int placeholder;
2829 };
2830
2831 /** Placeholder */
2832 struct PSI_socket_locker_state_v2
2833 {
2834   /** Placeholder */
2835   int placeholder;
2836 };
2837
2838 struct PSI_metadata_locker_state_v2
2839 {
2840   int placeholder;
2841 };
2842
2843 /** @} (end of group Group_PSI_v2) */
2844
2845 #endif /* HAVE_PSI_2 */
2846
2847 /**
2848   @typedef PSI
2849   The instrumentation interface for the current version.
2850   @sa PSI_CURRENT_VERSION
2851 */
2852
2853 /**
2854   @typedef PSI_mutex_info
2855   The mutex information structure for the current version.
2856 */
2857
2858 /**
2859   @typedef PSI_rwlock_info
2860   The rwlock information structure for the current version.
2861 */
2862
2863 /**
2864   @typedef PSI_cond_info
2865   The cond information structure for the current version.
2866 */
2867
2868 /**
2869   @typedef PSI_thread_info
2870   The thread information structure for the current version.
2871 */
2872
2873 /**
2874   @typedef PSI_file_info
2875   The file information structure for the current version.
2876 */
2877
2878 /* Export the required version */
2879 #ifdef USE_PSI_1
2880 typedef struct PSI_v1 PSI;
2881 typedef struct PSI_mutex_info_v1 PSI_mutex_info;
2882 typedef struct PSI_rwlock_info_v1 PSI_rwlock_info;
2883 typedef struct PSI_cond_info_v1 PSI_cond_info;
2884 typedef struct PSI_thread_info_v1 PSI_thread_info;
2885 typedef struct PSI_file_info_v1 PSI_file_info;
2886 typedef struct PSI_stage_info_v1 PSI_stage_info;
2887 typedef struct PSI_statement_info_v1 PSI_statement_info;
2888 typedef struct PSI_transaction_info_v1 PSI_transaction_info;
2889 typedef struct PSI_socket_info_v1 PSI_socket_info;
2890 typedef struct PSI_idle_locker_state_v1 PSI_idle_locker_state;
2891 typedef struct PSI_mutex_locker_state_v1 PSI_mutex_locker_state;
2892 typedef struct PSI_rwlock_locker_state_v1 PSI_rwlock_locker_state;
2893 typedef struct PSI_cond_locker_state_v1 PSI_cond_locker_state;
2894 typedef struct PSI_file_locker_state_v1 PSI_file_locker_state;
2895 typedef struct PSI_statement_locker_state_v1 PSI_statement_locker_state;
2896 typedef struct PSI_transaction_locker_state_v1 PSI_transaction_locker_state;
2897 typedef struct PSI_socket_locker_state_v1 PSI_socket_locker_state;
2898 typedef struct PSI_sp_locker_state_v1 PSI_sp_locker_state;
2899 typedef struct PSI_metadata_locker_state_v1 PSI_metadata_locker_state;
2900 #endif
2901
2902 #ifdef USE_PSI_2
2903 typedef struct PSI_v2 PSI;
2904 typedef struct PSI_mutex_info_v2 PSI_mutex_info;
2905 typedef struct PSI_rwlock_info_v2 PSI_rwlock_info;
2906 typedef struct PSI_cond_info_v2 PSI_cond_info;
2907 typedef struct PSI_thread_info_v2 PSI_thread_info;
2908 typedef struct PSI_file_info_v2 PSI_file_info;
2909 typedef struct PSI_stage_info_v2 PSI_stage_info;
2910 typedef struct PSI_statement_info_v2 PSI_statement_info;
2911 typedef struct PSI_transaction_info_v2 PSI_transaction_info;
2912 typedef struct PSI_socket_info_v2 PSI_socket_info;
2913 typedef struct PSI_idle_locker_state_v2 PSI_idle_locker_state;
2914 typedef struct PSI_mutex_locker_state_v2 PSI_mutex_locker_state;
2915 typedef struct PSI_rwlock_locker_state_v2 PSI_rwlock_locker_state;
2916 typedef struct PSI_cond_locker_state_v2 PSI_cond_locker_state;
2917 typedef struct PSI_file_locker_state_v2 PSI_file_locker_state;
2918 typedef struct PSI_statement_locker_state_v2 PSI_statement_locker_state;
2919 typedef struct PSI_transaction_locker_state_v2 PSI_transaction_locker_state;
2920 typedef struct PSI_socket_locker_state_v2 PSI_socket_locker_state;
2921 typedef struct PSI_sp_locker_state_v2 PSI_sp_locker_state;
2922 typedef struct PSI_metadata_locker_state_v2 PSI_metadata_locker_state;
2923 #endif
2924
2925 #else /* HAVE_PSI_INTERFACE */
2926
2927 /**
2928   Dummy structure, used to declare PSI_server when no instrumentation
2929   is available.
2930   The content does not matter, since PSI_server will be NULL.
2931 */
2932 struct PSI_none
2933 {
2934   int opaque;
2935 };
2936 typedef struct PSI_none PSI;
2937
2938 /**
2939   Stage instrument information.
2940   @since PSI_VERSION_1
2941   This structure is used to register an instrumented stage.
2942 */
2943 struct PSI_stage_info_none
2944 {
2945   /** Unused stage key. */
2946   unsigned int m_key;
2947   /** The name of the stage instrument. */
2948   const char *m_name;
2949   /** Unused stage flags. */
2950   int m_flags;
2951 };
2952
2953 /**
2954   The stage instrumentation has to co exist with the legacy
2955   THD::set_proc_info instrumentation.
2956   To avoid duplication of the instrumentation in the server,
2957   the common PSI_stage_info structure is used,
2958   so we export it here, even when not building
2959   with HAVE_PSI_INTERFACE.
2960 */
2961 typedef struct PSI_stage_info_none PSI_stage_info;
2962
2963 #endif /* HAVE_PSI_INTERFACE */
2964
2965 extern MYSQL_PLUGIN_IMPORT PSI *PSI_server;
2966
2967 /*
2968   Allow to override PSI_XXX_CALL at compile time
2969   with more efficient implementations, if available.
2970   If nothing better is available,
2971   make a dynamic call using the PSI_server function pointer.
2972 */
2973
2974 #define PSI_DYNAMIC_CALL(M) PSI_server->M
2975
2976 /** @} */
2977
2978 C_MODE_END
2979 #endif /* MYSQL_PERFORMANCE_SCHEMA_INTERFACE_H */
2980