List:Commits« Previous MessageNext Message »
From:Marc Alff Date:August 29 2012 9:10am
Subject:bzr push into mysql-5.6-marc branch (marc.alff:4198 to 4199)
View as plain text  
 4199 Marc Alff	2012-08-29
      Performance schema, performance tuning: static calls.

    removed:
      storage/perfschema/unittest/stub_server_misc.h
    added:
      include/pfs_file_provider.h
      include/pfs_idle_provider.h
      include/pfs_socket_provider.h
      include/pfs_stage_provider.h
      include/pfs_statement_provider.h
      include/pfs_table_provider.h
      include/pfs_thread_provider.h
      storage/perfschema/unittest/pfs_server_stubs.cc
    modified:
      include/my_pthread.h
      include/mysql/psi/mysql_file.h
      include/mysql/psi/mysql_idle.h
      include/mysql/psi/mysql_socket.h
      include/mysql/psi/mysql_stage.h
      include/mysql/psi/mysql_statement.h
      include/mysql/psi/mysql_table.h
      include/mysql/psi/mysql_thread.h
      include/mysql/psi/psi.h
      include/mysql/psi/psi_abi_v1.h.pp
      include/violite.h
      libmysqld/lib_sql.cc
      mysys/my_thr_init.c
      sql/binlog.cc
      sql/events.cc
      sql/ha_ndbcluster.cc
      sql/ha_ndbcluster_binlog.cc
      sql/handler.cc
      sql/mdl.cc
      sql/mysqld.cc
      sql/mysqld.h
      sql/rpl_info_table_access.cc
      sql/sql_acl.cc
      sql/sql_base.cc
      sql/sql_base.h
      sql/sql_class.cc
      sql/sql_class.h
      sql/sql_parse.cc
      sql/sql_plugin.cc
      sql/sql_reload.cc
      sql/sql_servers.cc
      sql/sql_table.cc
      sql/sql_udf.cc
      sql/table.cc
      sql/thr_malloc.cc
      sql/tztime.cc
      storage/innobase/include/univ.i
      storage/perfschema/pfs.cc
      storage/perfschema/pfs_digest.h
      storage/perfschema/pfs_events_stages.cc
      storage/perfschema/pfs_events_statements.cc
      storage/perfschema/pfs_events_waits.cc
      storage/perfschema/pfs_instr.cc
      storage/perfschema/pfs_server.cc
      storage/perfschema/pfs_server.h
      storage/perfschema/unittest/CMakeLists.txt
      storage/perfschema/unittest/pfs-t.cc
      storage/perfschema/unittest/pfs_account-oom-t.cc
      storage/perfschema/unittest/pfs_host-oom-t.cc
      storage/perfschema/unittest/pfs_instr-oom-t.cc
      storage/perfschema/unittest/pfs_instr-t.cc
      storage/perfschema/unittest/pfs_instr_class-oom-t.cc
      storage/perfschema/unittest/pfs_instr_class-t.cc
      storage/perfschema/unittest/pfs_user-oom-t.cc
      unittest/gunit/CMakeLists.txt
      unittest/gunit/dynarray-t.cc
      unittest/gunit/gunit_test_main_server.cc
      unittest/gunit/sql_list-t.cc
 4198 Marc Alff	2012-08-28
      Prototyping, Marc Alff

    modified:
      .bzr-mysql/default.conf
=== modified file 'include/my_pthread.h'
--- a/include/my_pthread.h	2012-05-08 18:01:19 +0000
+++ b/include/my_pthread.h	2012-08-29 09:08:27 +0000
@@ -815,6 +815,7 @@ extern int pthread_dummy(int);
 #endif
 #endif
 
+#include <pfs_thread_provider.h>
 #include <mysql/psi/mysql_thread.h>
 
 #define INSTRUMENT_ME 0

=== modified file 'include/mysql/psi/mysql_file.h'
--- a/include/mysql/psi/mysql_file.h	2012-08-07 15:41:51 +0000
+++ b/include/mysql/psi/mysql_file.h	2012-08-29 09:08:27 +0000
@@ -43,6 +43,10 @@
 
 #include "mysql/psi/psi.h"
 
+#ifndef PSI_FILE_CALL
+#define PSI_FILE_CALL(M) PSI_DYNAMIC_CALL(M)
+#endif
+
 /**
   @defgroup File_instrumentation File Instrumentation
   @ingroup Instrumentation_interface

=== modified file 'include/mysql/psi/mysql_idle.h'
--- a/include/mysql/psi/mysql_idle.h	2012-05-15 09:39:47 +0000
+++ b/include/mysql/psi/mysql_idle.h	2012-08-29 09:08:27 +0000
@@ -23,6 +23,10 @@
 
 #include "mysql/psi/psi.h"
 
+#ifndef PSI_IDLE_CALL
+#define PSI_IDLE_CALL(M) PSI_DYNAMIC_CALL(M)
+#endif
+
 /**
   @defgroup Idle_instrumentation Idle Instrumentation
   @ingroup Instrumentation_interface

=== modified file 'include/mysql/psi/mysql_socket.h'
--- a/include/mysql/psi/mysql_socket.h	2012-07-19 16:03:43 +0000
+++ b/include/mysql/psi/mysql_socket.h	2012-08-29 09:08:27 +0000
@@ -42,6 +42,10 @@ Foundation, Inc., 51 Franklin St, Fifth
 
 #include "mysql/psi/psi.h"
 
+#ifndef PSI_SOCKET_CALL
+#define PSI_SOCKET_CALL(M) PSI_DYNAMIC_CALL(M)
+#endif
+
 /**
   @defgroup Socket_instrumentation Socket Instrumentation
   @ingroup Instrumentation_interface

=== modified file 'include/mysql/psi/mysql_stage.h'
--- a/include/mysql/psi/mysql_stage.h	2012-05-15 09:39:47 +0000
+++ b/include/mysql/psi/mysql_stage.h	2012-08-29 09:08:27 +0000
@@ -23,6 +23,10 @@
 
 #include "mysql/psi/psi.h"
 
+#ifndef PSI_STAGE_CALL
+#define PSI_STAGE_CALL(M) PSI_DYNAMIC_CALL(M)
+#endif
+
 /**
   @defgroup Stage_instrumentation Stage Instrumentation
   @ingroup Instrumentation_interface

=== modified file 'include/mysql/psi/mysql_statement.h'
--- a/include/mysql/psi/mysql_statement.h	2012-05-15 09:39:47 +0000
+++ b/include/mysql/psi/mysql_statement.h	2012-08-29 09:08:27 +0000
@@ -23,6 +23,10 @@
 
 #include "mysql/psi/psi.h"
 
+#ifndef PSI_STATEMENT_CALL
+#define PSI_STATEMENT_CALL(M) PSI_DYNAMIC_CALL(M)
+#endif
+
 /**
   @defgroup Statement_instrumentation Statement Instrumentation
   @ingroup Instrumentation_interface

=== modified file 'include/mysql/psi/mysql_table.h'
--- a/include/mysql/psi/mysql_table.h	2012-05-15 09:39:47 +0000
+++ b/include/mysql/psi/mysql_table.h	2012-08-29 09:08:27 +0000
@@ -23,6 +23,10 @@
 
 #include "mysql/psi/psi.h"
 
+#ifndef PSI_TABLE_CALL
+#define PSI_TABLE_CALL(M) PSI_DYNAMIC_CALL(M)
+#endif
+
 /**
   @defgroup Table_instrumentation Table Instrumentation
   @ingroup Instrumentation_interface

=== modified file 'include/mysql/psi/mysql_thread.h'
--- a/include/mysql/psi/mysql_thread.h	2012-05-15 09:39:47 +0000
+++ b/include/mysql/psi/mysql_thread.h	2012-08-29 09:08:27 +0000
@@ -56,6 +56,23 @@
 
 #include "mysql/psi/psi.h"
 
+#ifndef PSI_MUTEX_CALL
+
+#define PSI_MUTEX_CALL(M) PSI_DYNAMIC_CALL(M)
+#endif
+
+#ifndef PSI_RWLOCK_CALL
+#define PSI_RWLOCK_CALL(M) PSI_DYNAMIC_CALL(M)
+#endif
+
+#ifndef PSI_COND_CALL
+#define PSI_COND_CALL(M) PSI_DYNAMIC_CALL(M)
+#endif
+
+#ifndef PSI_THREAD_CALL
+#define PSI_THREAD_CALL(M) PSI_DYNAMIC_CALL(M)
+#endif
+
 /**
   @defgroup Thread_instrumentation Thread Instrumentation
   @ingroup Instrumentation_interface

=== modified file 'include/mysql/psi/psi.h'
--- a/include/mysql/psi/psi.h	2012-08-07 15:41:51 +0000
+++ b/include/mysql/psi/psi.h	2012-08-29 09:08:27 +0000
@@ -17,16 +17,7 @@
 #define MYSQL_PERFORMANCE_SCHEMA_INTERFACE_H
 
 #ifdef EMBEDDED_LIBRARY
-#define DISABLE_PSI_MUTEX
-#define DISABLE_PSI_RWLOCK
-#define DISABLE_PSI_COND
-#define DISABLE_PSI_FILE
-#define DISABLE_PSI_TABLE
-#define DISABLE_PSI_SOCKET
-#define DISABLE_PSI_STAGE
-#define DISABLE_PSI_STATEMENT
-#define DISABLE_PSI_IDLE
-#define DISABLE_PSI_STATEMENT_DIGEST
+#define DISABLE_ALL_PSI
 #endif /* EMBEDDED_LIBRARY */
 
 #ifndef MY_GLOBAL_INCLUDED
@@ -40,6 +31,13 @@
 #error "You must include my_global.h in the code for the build to be correct."
 #endif
 
+/*
+  MAINTAINER:
+  The following pattern:
+    typedef struct XYZ XYZ;
+  is not needed in C++, but required for C.
+*/
+
 C_MODE_START
 
 struct TABLE_SHARE;
@@ -171,6 +169,19 @@ typedef struct PSI_bootstrap PSI_bootstr
 
 #ifdef HAVE_PSI_INTERFACE
 
+#ifdef DISABLE_ALL_PSI
+#define DISABLE_PSI_MUTEX
+#define DISABLE_PSI_RWLOCK
+#define DISABLE_PSI_COND
+#define DISABLE_PSI_FILE
+#define DISABLE_PSI_TABLE
+#define DISABLE_PSI_SOCKET
+#define DISABLE_PSI_STAGE
+#define DISABLE_PSI_STATEMENT
+#define DISABLE_PSI_IDLE
+#define DISABLE_PSI_STATEMENT_DIGEST
+#endif
+
 /**
   @def DISABLE_PSI_MUTEX
   Compiling option to disable the mutex instrumentation.
@@ -593,7 +604,7 @@ typedef unsigned int PSI_socket_key;
 #define PSI_FLAG_GLOBAL (1 << 0)
 
 /**
-  Global flag.
+  Mutable flag.
   This flag indicate that an instrumentation point is a general placeholder,
   that can mutate into a more specific instrumentation point.
 */
@@ -632,6 +643,7 @@ struct PSI_mutex_info_v1
   */
   int m_flags;
 };
+typedef struct PSI_mutex_info_v1 PSI_mutex_info_v1;
 
 /**
   Rwlock information.
@@ -654,6 +666,7 @@ struct PSI_rwlock_info_v1
   */
   int m_flags;
 };
+typedef struct PSI_rwlock_info_v1 PSI_rwlock_info_v1;
 
 /**
   Condition information.
@@ -676,6 +689,7 @@ struct PSI_cond_info_v1
   */
   int m_flags;
 };
+typedef struct PSI_cond_info_v1 PSI_cond_info_v1;
 
 /**
   Thread instrument information.
@@ -698,6 +712,7 @@ struct PSI_thread_info_v1
   */
   int m_flags;
 };
+typedef struct PSI_thread_info_v1 PSI_thread_info_v1;
 
 /**
   File instrument information.
@@ -720,6 +735,7 @@ struct PSI_file_info_v1
   */
   int m_flags;
 };
+typedef struct PSI_file_info_v1 PSI_file_info_v1;
 
 /**
   Stage instrument information.
@@ -735,6 +751,7 @@ struct PSI_stage_info_v1
   /** The flags of the stage instrument to register. */
   int m_flags;
 };
+typedef struct PSI_stage_info_v1 PSI_stage_info_v1;
 
 /**
   Statement instrument information.
@@ -750,6 +767,7 @@ struct PSI_statement_info_v1
   /** The flags of the statement instrument to register. */
   int m_flags;
 };
+typedef struct PSI_statement_info_v1 PSI_statement_info_v1;
 
 /**
   Socket instrument information.
@@ -772,6 +790,7 @@ struct PSI_socket_info_v1
   */
   int m_flags;
 };
+typedef struct PSI_socket_info_v1 PSI_socket_info_v1;
 
 /**
   State data storage for @c start_idle_wait_v1_t.
@@ -795,6 +814,7 @@ struct PSI_idle_locker_state_v1
   /** Internal data. */
   void *m_wait;
 };
+typedef struct PSI_idle_locker_state_v1 PSI_idle_locker_state_v1;
 
 /**
   State data storage for @c start_mutex_wait_v1_t.
@@ -822,6 +842,7 @@ struct PSI_mutex_locker_state_v1
   /** Internal data. */
   void *m_wait;
 };
+typedef struct PSI_mutex_locker_state_v1 PSI_mutex_locker_state_v1;
 
 /**
   State data storage for @c start_rwlock_rdwait_v1_t, @c start_rwlock_wrwait_v1_t.
@@ -850,6 +871,7 @@ struct PSI_rwlock_locker_state_v1
   /** Internal data. */
   void *m_wait;
 };
+typedef struct PSI_rwlock_locker_state_v1 PSI_rwlock_locker_state_v1;
 
 /**
   State data storage for @c start_cond_wait_v1_t.
@@ -879,6 +901,7 @@ struct PSI_cond_locker_state_v1
   /** Internal data. */
   void *m_wait;
 };
+typedef struct PSI_cond_locker_state_v1 PSI_cond_locker_state_v1;
 
 /**
   State data storage for @c get_thread_file_name_locker_v1_t.
@@ -914,6 +937,7 @@ struct PSI_file_locker_state_v1
   /** Internal data. */
   void *m_wait;
 };
+typedef struct PSI_file_locker_state_v1 PSI_file_locker_state_v1;
 
 /**
   State data storage for @c start_table_io_wait_v1_t,
@@ -951,6 +975,7 @@ struct PSI_table_locker_state_v1
   */
   uint m_index;
 };
+typedef struct PSI_table_locker_state_v1 PSI_table_locker_state_v1;
 
 #define PSI_MAX_DIGEST_STORAGE_SIZE 1024
 
@@ -1036,6 +1061,7 @@ struct PSI_statement_locker_state_v1
   /** Statement digest. */
   PSI_digest_locker_state m_digest_state;
 };
+typedef struct PSI_statement_locker_state_v1 PSI_statement_locker_state_v1;
 
 /**
   State data storage for @c start_socket_wait_v1_t.
@@ -1069,6 +1095,7 @@ struct PSI_socket_locker_state_v1
   /** Internal data. */
   void *m_wait;
 };
+typedef struct PSI_socket_locker_state_v1 PSI_socket_locker_state_v1;
 
 /* Using typedef to make reuse between PSI_v1 and PSI_v2 easier later. */
 
@@ -1332,8 +1359,8 @@ typedef void (*set_thread_user_v1_t)(con
   @param host the host name
   @param host_len the host name length
 */
-typedef void (*set_thread_user_host_v1_t)(const char *user, int user_len,
-                                          const char *host, int host_len);
+typedef void (*set_thread_account_v1_t)(const char *user, int user_len,
+                                        const char *host, int host_len);
 
 /**
   Assign a current database to the instrumented thread.
@@ -1978,8 +2005,8 @@ struct PSI_v1
   get_thread_v1_t get_thread;
   /** @sa set_thread_user_v1_t. */
   set_thread_user_v1_t set_thread_user;
-  /** @sa set_thread_user_host_v1_t. */
-  set_thread_user_host_v1_t set_thread_user_host;
+  /** @sa set_thread_account_v1_t. */
+  set_thread_account_v1_t set_thread_account;
   /** @sa set_thread_db_v1_t. */
   set_thread_db_v1_t set_thread_db;
   /** @sa set_thread_command_v1_t. */
@@ -2375,46 +2402,6 @@ extern MYSQL_PLUGIN_IMPORT PSI *PSI_serv
   make a dynamic call using the PSI_server function pointer.
 */
 
-#ifndef PSI_MUTEX_CALL
-#define PSI_MUTEX_CALL(M) PSI_DYNAMIC_CALL(M)
-#endif
-
-#ifndef PSI_RWLOCK_CALL
-#define PSI_RWLOCK_CALL(M) PSI_DYNAMIC_CALL(M)
-#endif
-
-#ifndef PSI_COND_CALL
-#define PSI_COND_CALL(M) PSI_DYNAMIC_CALL(M)
-#endif
-
-#ifndef PSI_THREAD_CALL
-#define PSI_THREAD_CALL(M) PSI_DYNAMIC_CALL(M)
-#endif
-
-#ifndef PSI_FILE_CALL
-#define PSI_FILE_CALL(M) PSI_DYNAMIC_CALL(M)
-#endif
-
-#ifndef PSI_SOCKET_CALL
-#define PSI_SOCKET_CALL(M) PSI_DYNAMIC_CALL(M)
-#endif
-
-#ifndef PSI_STAGE_CALL
-#define PSI_STAGE_CALL(M) PSI_DYNAMIC_CALL(M)
-#endif
-
-#ifndef PSI_STATEMENT_CALL
-#define PSI_STATEMENT_CALL(M) PSI_DYNAMIC_CALL(M)
-#endif
-
-#ifndef PSI_TABLE_CALL
-#define PSI_TABLE_CALL(M) PSI_DYNAMIC_CALL(M)
-#endif
-
-#ifndef PSI_IDLE_CALL
-#define PSI_IDLE_CALL(M) PSI_DYNAMIC_CALL(M)
-#endif
-
 #define PSI_DYNAMIC_CALL(M) PSI_server->M
 
 /** @} */

=== modified file 'include/mysql/psi/psi_abi_v1.h.pp'
--- a/include/mysql/psi/psi_abi_v1.h.pp	2012-08-07 15:41:51 +0000
+++ b/include/mysql/psi/psi_abi_v1.h.pp	2012-08-29 09:08:27 +0000
@@ -135,48 +135,56 @@ struct PSI_mutex_info_v1
   const char *m_name;
   int m_flags;
 };
+typedef struct PSI_mutex_info_v1 PSI_mutex_info_v1;
 struct PSI_rwlock_info_v1
 {
   PSI_rwlock_key *m_key;
   const char *m_name;
   int m_flags;
 };
+typedef struct PSI_rwlock_info_v1 PSI_rwlock_info_v1;
 struct PSI_cond_info_v1
 {
   PSI_cond_key *m_key;
   const char *m_name;
   int m_flags;
 };
+typedef struct PSI_cond_info_v1 PSI_cond_info_v1;
 struct PSI_thread_info_v1
 {
   PSI_thread_key *m_key;
   const char *m_name;
   int m_flags;
 };
+typedef struct PSI_thread_info_v1 PSI_thread_info_v1;
 struct PSI_file_info_v1
 {
   PSI_file_key *m_key;
   const char *m_name;
   int m_flags;
 };
+typedef struct PSI_file_info_v1 PSI_file_info_v1;
 struct PSI_stage_info_v1
 {
   PSI_stage_key m_key;
   const char *m_name;
   int m_flags;
 };
+typedef struct PSI_stage_info_v1 PSI_stage_info_v1;
 struct PSI_statement_info_v1
 {
   PSI_statement_key m_key;
   const char *m_name;
   int m_flags;
 };
+typedef struct PSI_statement_info_v1 PSI_statement_info_v1;
 struct PSI_socket_info_v1
 {
   PSI_socket_key *m_key;
   const char *m_name;
   int m_flags;
 };
+typedef struct PSI_socket_info_v1 PSI_socket_info_v1;
 struct PSI_idle_locker_state_v1
 {
   uint m_flags;
@@ -185,6 +193,7 @@ struct PSI_idle_locker_state_v1
   ulonglong (*m_timer)(void);
   void *m_wait;
 };
+typedef struct PSI_idle_locker_state_v1 PSI_idle_locker_state_v1;
 struct PSI_mutex_locker_state_v1
 {
   uint m_flags;
@@ -195,6 +204,7 @@ struct PSI_mutex_locker_state_v1
   ulonglong (*m_timer)(void);
   void *m_wait;
 };
+typedef struct PSI_mutex_locker_state_v1 PSI_mutex_locker_state_v1;
 struct PSI_rwlock_locker_state_v1
 {
   uint m_flags;
@@ -205,6 +215,7 @@ struct PSI_rwlock_locker_state_v1
   ulonglong (*m_timer)(void);
   void *m_wait;
 };
+typedef struct PSI_rwlock_locker_state_v1 PSI_rwlock_locker_state_v1;
 struct PSI_cond_locker_state_v1
 {
   uint m_flags;
@@ -216,6 +227,7 @@ struct PSI_cond_locker_state_v1
   ulonglong (*m_timer)(void);
   void *m_wait;
 };
+typedef struct PSI_cond_locker_state_v1 PSI_cond_locker_state_v1;
 struct PSI_file_locker_state_v1
 {
   uint m_flags;
@@ -229,6 +241,7 @@ struct PSI_file_locker_state_v1
   ulonglong (*m_timer)(void);
   void *m_wait;
 };
+typedef struct PSI_file_locker_state_v1 PSI_file_locker_state_v1;
 struct PSI_table_locker_state_v1
 {
   uint m_flags;
@@ -241,6 +254,7 @@ struct PSI_table_locker_state_v1
   void *m_wait;
   uint m_index;
 };
+typedef struct PSI_table_locker_state_v1 PSI_table_locker_state_v1;
 struct PSI_digest_storage
 {
   my_bool m_full;
@@ -282,6 +296,7 @@ struct PSI_statement_locker_state_v1
   ulong m_sort_scan;
   PSI_digest_locker_state m_digest_state;
 };
+typedef struct PSI_statement_locker_state_v1 PSI_statement_locker_state_v1;
 struct PSI_socket_locker_state_v1
 {
   uint m_flags;
@@ -295,6 +310,7 @@ struct PSI_socket_locker_state_v1
   int m_src_line;
   void *m_wait;
 };
+typedef struct PSI_socket_locker_state_v1 PSI_socket_locker_state_v1;
 typedef void (*register_mutex_v1_t)
   (const char *category, struct PSI_mutex_info_v1 *info, int count);
 typedef void (*register_rwlock_v1_t)
@@ -349,8 +365,8 @@ typedef void (*set_thread_id_v1_t)(struc
                                    unsigned long id);
 typedef struct PSI_thread* (*get_thread_v1_t)(void);
 typedef void (*set_thread_user_v1_t)(const char *user, int user_len);
-typedef void (*set_thread_user_host_v1_t)(const char *user, int user_len,
-                                          const char *host, int host_len);
+typedef void (*set_thread_account_v1_t)(const char *user, int user_len,
+                                        const char *host, int host_len);
 typedef void (*set_thread_db_v1_t)(const char* db, int db_len);
 typedef void (*set_thread_command_v1_t)(int command);
 typedef void (*set_thread_start_time_v1_t)(time_t start_time);
@@ -541,7 +557,7 @@ struct PSI_v1
   set_thread_id_v1_t set_thread_id;
   get_thread_v1_t get_thread;
   set_thread_user_v1_t set_thread_user;
-  set_thread_user_host_v1_t set_thread_user_host;
+  set_thread_account_v1_t set_thread_account;
   set_thread_db_v1_t set_thread_db;
   set_thread_command_v1_t set_thread_command;
   set_thread_start_time_v1_t set_thread_start_time;

=== added file 'include/pfs_file_provider.h'
--- a/include/pfs_file_provider.h	1970-01-01 00:00:00 +0000
+++ b/include/pfs_file_provider.h	2012-08-29 09:08:27 +0000
@@ -0,0 +1,86 @@
+/* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; version 2 of the License.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program; if not, write to the Free Software Foundation,
+  51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
+
+#ifndef PFS_FILE_PROVIDER_H
+#define PFS_FILE_PROVIDER_H
+
+/**
+  @file include/pfs_file_provider.h
+  Performance schema instrumentation (declarations).
+*/
+
+#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
+#ifdef MYSQL_SERVER
+#ifndef EMBEDDED_LIBRARY
+#ifndef MYSQL_DYNAMIC_PLUGIN
+
+#include "mysql/psi/psi.h"
+
+#define PSI_FILE_CALL(M) pfs_ ## M ## _v1
+
+C_MODE_START
+
+void pfs_register_file_v1(const char *category,
+                          PSI_file_info_v1 *info,
+                          int count);
+
+void pfs_create_file_v1(PSI_file_key key, const char *name, File file);
+
+PSI_file_locker*
+pfs_get_thread_file_name_locker_v1(PSI_file_locker_state *state,
+                                   PSI_file_key key,
+                                   PSI_file_operation op,
+                                   const char *name, const void *identity);
+
+PSI_file_locker*
+pfs_get_thread_file_stream_locker_v1(PSI_file_locker_state *state,
+                                     PSI_file *file, PSI_file_operation op);
+
+PSI_file_locker*
+pfs_get_thread_file_descriptor_locker_v1(PSI_file_locker_state *state,
+                                         File file, PSI_file_operation op);
+
+void pfs_start_file_open_wait_v1(PSI_file_locker *locker,
+                                 const char *src_file,
+                                 uint src_line);
+
+PSI_file* pfs_end_file_open_wait_v1(PSI_file_locker *locker, void *result);
+
+void pfs_end_file_open_wait_and_bind_to_descriptor_v1
+  (PSI_file_locker *locker, File file);
+
+void pfs_start_file_wait_v1(PSI_file_locker *locker,
+                            size_t count,
+                            const char *src_file,
+                            uint src_line);
+
+void pfs_end_file_wait_v1(PSI_file_locker *locker,
+                          size_t byte_count);
+
+void pfs_start_file_close_wait_v1(PSI_file_locker *locker,
+                                  const char *src_file,
+                                  uint src_line);
+
+void pfs_end_file_close_wait_v1(PSI_file_locker *locker, int rc);
+
+C_MODE_END
+
+#endif /* EMBEDDED_LIBRARY */
+#endif /* MYSQL_DYNAMIC_PLUGIN */
+#endif /* MYSQL_SERVER */
+#endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
+
+#endif
+

=== added file 'include/pfs_idle_provider.h'
--- a/include/pfs_idle_provider.h	1970-01-01 00:00:00 +0000
+++ b/include/pfs_idle_provider.h	2012-08-29 09:08:27 +0000
@@ -0,0 +1,48 @@
+/* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; version 2 of the License.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program; if not, write to the Free Software Foundation,
+  51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
+
+#ifndef PFS_IDLE_PROVIDER_H
+#define PFS_IDLE_PROVIDER_H
+
+/**
+  @file include/pfs_idle_provider.h
+  Performance schema instrumentation (declarations).
+*/
+
+#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
+#ifdef MYSQL_SERVER
+#ifndef EMBEDDED_LIBRARY
+#ifndef MYSQL_DYNAMIC_PLUGIN
+
+#include "mysql/psi/psi.h"
+
+#define PSI_IDLE_CALL(M) pfs_ ## M ## _v1
+
+C_MODE_START
+
+PSI_idle_locker*
+pfs_start_idle_wait_v1(PSI_idle_locker_state* state, const char *src_file, uint src_line);
+
+void pfs_end_idle_wait_v1(PSI_idle_locker* locker);
+
+C_MODE_END
+
+#endif /* MYSQL_DYNAMIC_PLUGIN */
+#endif /* EMBEDDED_LIBRARY */
+#endif /* MYSQL_SERVER */
+#endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
+
+#endif
+

=== added file 'include/pfs_socket_provider.h'
--- a/include/pfs_socket_provider.h	1970-01-01 00:00:00 +0000
+++ b/include/pfs_socket_provider.h	2012-08-29 09:08:27 +0000
@@ -0,0 +1,71 @@
+/* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; version 2 of the License.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program; if not, write to the Free Software Foundation,
+  51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
+
+#ifndef PFS_SOCKET_PROVIDER_H
+#define PFS_SOCKET_PROVIDER_H
+
+/**
+  @file include/pfs_socket_provider.h
+  Performance schema instrumentation (declarations).
+*/
+
+#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
+#ifdef MYSQL_SERVER
+#ifndef EMBEDDED_LIBRARY
+#ifndef MYSQL_DYNAMIC_PLUGIN
+
+#include "mysql/psi/psi.h"
+
+#define PSI_SOCKET_CALL(M) pfs_ ## M ## _v1
+
+C_MODE_START
+
+void pfs_register_socket_v1(const char *category,
+                            PSI_socket_info_v1 *info,
+                            int count);
+
+PSI_socket*
+pfs_init_socket_v1(PSI_socket_key key, const my_socket *fd,
+                   const struct sockaddr *addr, socklen_t addr_len);
+
+void pfs_destroy_socket_v1(PSI_socket *socket);
+
+PSI_socket_locker*
+pfs_start_socket_wait_v1(PSI_socket_locker_state *state,
+                         PSI_socket *socket,
+                         PSI_socket_operation op,
+                         size_t count,
+                         const char *src_file, uint src_line);
+
+void pfs_end_socket_wait_v1(PSI_socket_locker *locker, size_t byte_count);
+
+void pfs_set_socket_state_v1(PSI_socket *socket, PSI_socket_state state);
+
+void pfs_set_socket_info_v1(PSI_socket *socket,
+                            const my_socket *fd,
+                            const struct sockaddr *addr,
+                            socklen_t addr_len);
+
+void pfs_set_socket_thread_owner_v1(PSI_socket *socket);
+
+C_MODE_END
+
+#endif /* EMBEDDED_LIBRARY */
+#endif /* MYSQL_DYNAMIC_PLUGIN */
+#endif /* MYSQL_SERVER */
+#endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
+
+#endif
+

=== added file 'include/pfs_stage_provider.h'
--- a/include/pfs_stage_provider.h	1970-01-01 00:00:00 +0000
+++ b/include/pfs_stage_provider.h	2012-08-29 09:08:27 +0000
@@ -0,0 +1,51 @@
+/* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; version 2 of the License.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program; if not, write to the Free Software Foundation,
+  51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
+
+#ifndef PFS_STAGE_PROVIDER_H
+#define PFS_STAGE_PROVIDER_H
+
+/**
+  @file include/pfs_stage_provider.h
+  Performance schema instrumentation (declarations).
+*/
+
+#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
+#ifdef MYSQL_SERVER
+#ifndef EMBEDDED_LIBRARY
+#ifndef MYSQL_DYNAMIC_PLUGIN
+
+#include "mysql/psi/psi.h"
+
+#define PSI_STAGE_CALL(M) pfs_ ## M ## _v1
+
+C_MODE_START
+
+void pfs_register_stage_v1(const char *category,
+                           PSI_stage_info_v1 **info_array,
+                           int count);
+
+void pfs_start_stage_v1(PSI_stage_key key, const char *src_file, int src_line);
+
+void pfs_end_stage_v1();
+
+C_MODE_END
+
+#endif /* MYSQL_DYNAMIC_PLUGIN */
+#endif /* EMBEDDED_LIBRARY */
+#endif /* MYSQL_SERVER */
+#endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
+
+#endif
+

=== added file 'include/pfs_statement_provider.h'
--- a/include/pfs_statement_provider.h	1970-01-01 00:00:00 +0000
+++ b/include/pfs_statement_provider.h	2012-08-29 09:08:27 +0000
@@ -0,0 +1,117 @@
+/* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; version 2 of the License.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program; if not, write to the Free Software Foundation,
+  51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
+
+#ifndef PFS_STATEMENT_PROVIDER_H
+#define PFS_STATEMENT_PROVIDER_H
+
+/**
+  @file include/pfs_statement_provider.h
+  Performance schema instrumentation (declarations).
+*/
+
+#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
+#ifdef MYSQL_SERVER
+#ifndef EMBEDDED_LIBRARY
+#ifndef MYSQL_DYNAMIC_PLUGIN
+
+#include "mysql/psi/psi.h"
+
+#define PSI_STATEMENT_CALL(M) pfs_ ## M ## _v1
+
+C_MODE_START
+
+void pfs_register_statement_v1(const char *category,
+                               PSI_statement_info_v1 *info,
+                               int count);
+
+PSI_statement_locker*
+pfs_get_thread_statement_locker_v1(PSI_statement_locker_state *state,
+                                   PSI_statement_key key,
+                                   const void *charset);
+
+PSI_statement_locker*
+pfs_refine_statement_v1(PSI_statement_locker *locker,
+                        PSI_statement_key key);
+
+void pfs_start_statement_v1(PSI_statement_locker *locker,
+                            const char *db, uint db_len,
+                            const char *src_file, uint src_line);
+
+void pfs_set_statement_text_v1(PSI_statement_locker *locker,
+                               const char *text, uint text_len);
+
+void pfs_set_statement_lock_time_v1(PSI_statement_locker *locker,
+                                    ulonglong count);
+
+void pfs_set_statement_rows_sent_v1(PSI_statement_locker *locker,
+                                    ulonglong count);
+
+void pfs_set_statement_rows_examined_v1(PSI_statement_locker *locker,
+                                        ulonglong count);
+
+void pfs_inc_statement_created_tmp_disk_tables_v1(PSI_statement_locker *locker,
+                                                  ulong count);
+
+void pfs_inc_statement_created_tmp_tables_v1(PSI_statement_locker *locker,
+                                             ulong count);
+
+void pfs_inc_statement_select_full_join_v1(PSI_statement_locker *locker,
+                                           ulong count);
+
+void pfs_inc_statement_select_full_range_join_v1(PSI_statement_locker *locker,
+                                                 ulong count);
+
+void pfs_inc_statement_select_range_v1(PSI_statement_locker *locker,
+                                       ulong count);
+
+void pfs_inc_statement_select_range_check_v1(PSI_statement_locker *locker,
+                                             ulong count);
+
+void pfs_inc_statement_select_scan_v1(PSI_statement_locker *locker,
+                                      ulong count);
+
+void pfs_inc_statement_sort_merge_passes_v1(PSI_statement_locker *locker,
+                                            ulong count);
+
+void pfs_inc_statement_sort_range_v1(PSI_statement_locker *locker,
+                                     ulong count);
+
+void pfs_inc_statement_sort_rows_v1(PSI_statement_locker *locker,
+                                    ulong count);
+
+void pfs_inc_statement_sort_scan_v1(PSI_statement_locker *locker,
+                                    ulong count);
+
+void pfs_set_statement_no_index_used_v1(PSI_statement_locker *locker);
+
+void pfs_set_statement_no_good_index_used_v1(PSI_statement_locker *locker);
+
+void pfs_end_statement_v1(PSI_statement_locker *locker, void *stmt_da);
+
+PSI_digest_locker *pfs_digest_start_v1(PSI_statement_locker *locker);
+
+PSI_digest_locker *pfs_digest_add_token_v1(PSI_digest_locker *locker,
+                                           uint token,
+                                           OPAQUE_LEX_YYSTYPE *yylval);
+
+C_MODE_END
+
+#endif /* MYSQL_DYNAMIC_PLUGIN */
+#endif /* EMBEDDED_LIBRARY */
+#endif /* MYSQL_SERVER */
+#endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
+
+#endif
+

=== added file 'include/pfs_table_provider.h'
--- a/include/pfs_table_provider.h	1970-01-01 00:00:00 +0000
+++ b/include/pfs_table_provider.h	2012-08-29 09:08:27 +0000
@@ -0,0 +1,81 @@
+/* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; version 2 of the License.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program; if not, write to the Free Software Foundation,
+  51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
+
+#ifndef PFS_TABLE_PROVIDER_H
+#define PFS_TABLE_PROVIDER_H
+
+/**
+  @file include/pfs_table_provider.h
+  Performance schema instrumentation (declarations).
+*/
+
+#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
+#ifdef MYSQL_SERVER
+#ifndef EMBEDDED_LIBRARY
+#ifndef MYSQL_DYNAMIC_PLUGIN
+
+#include "mysql/psi/psi.h"
+
+#define PSI_TABLE_CALL(M) pfs_ ## M ## _v1
+
+C_MODE_START
+
+PSI_table_share*
+pfs_get_table_share_v1(my_bool temporary, struct TABLE_SHARE *share);
+
+void pfs_release_table_share_v1(PSI_table_share* share);
+
+void
+pfs_drop_table_share_v1(my_bool temporary,
+                        const char *schema_name, int schema_name_length,
+                        const char *table_name, int table_name_length);
+
+PSI_table*
+pfs_open_table_v1(PSI_table_share *share, const void *identity);
+
+void pfs_unbind_table_v1(PSI_table *table);
+
+PSI_table *
+pfs_rebind_table_v1(PSI_table_share *share, const void *identity, PSI_table *table);
+
+void pfs_close_table_v1(PSI_table *table);
+
+PSI_table_locker*
+pfs_start_table_io_wait_v1(PSI_table_locker_state *state,
+                           PSI_table *table,
+                           PSI_table_io_operation op,
+                           uint index,
+                           const char *src_file, uint src_line);
+
+PSI_table_locker*
+pfs_start_table_lock_wait_v1(PSI_table_locker_state *state,
+                             PSI_table *table,
+                             PSI_table_lock_operation op,
+                             ulong op_flags,
+                             const char *src_file, uint src_line);
+
+void pfs_end_table_io_wait_v1(PSI_table_locker* locker);
+
+void pfs_end_table_lock_wait_v1(PSI_table_locker* locker);
+
+C_MODE_END
+
+#endif /* MYSQL_DYNAMIC_PLUGIN */
+#endif /* EMBEDDED_LIBRARY */
+#endif /* MYSQL_SERVER */
+#endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
+
+#endif
+

=== added file 'include/pfs_thread_provider.h'
--- a/include/pfs_thread_provider.h	1970-01-01 00:00:00 +0000
+++ b/include/pfs_thread_provider.h	2012-08-29 09:08:27 +0000
@@ -0,0 +1,166 @@
+/* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; version 2 of the License.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program; if not, write to the Free Software Foundation,
+  51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
+
+#ifndef PFS_THREAD_PROVIDER_H
+#define PFS_THREAD_PROVIDER_H
+
+/**
+  @file include/pfs_thread_provider.h
+  Performance schema instrumentation (declarations).
+*/
+
+#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
+#ifdef MYSQL_SERVER
+#ifndef EMBEDDED_LIBRARY
+#ifndef MYSQL_DYNAMIC_PLUGIN
+
+#include "mysql/psi/psi.h"
+
+#define PSI_MUTEX_CALL(M) pfs_ ## M ## _v1
+#define PSI_RWLOCK_CALL(M) pfs_ ## M ## _v1
+#define PSI_COND_CALL(M) pfs_ ## M ## _v1
+#define PSI_THREAD_CALL(M) pfs_ ## M ## _v1
+
+C_MODE_START
+
+void pfs_register_mutex_v1(const char *category,
+                           PSI_mutex_info_v1 *info,
+                           int count);
+
+void pfs_register_rwlock_v1(const char *category,
+                            PSI_rwlock_info_v1 *info,
+                            int count);
+
+void pfs_register_cond_v1(const char *category,
+                          PSI_cond_info_v1 *info,
+                          int count);
+
+void pfs_register_thread_v1(const char *category,
+                            PSI_thread_info_v1 *info,
+                            int count);
+
+PSI_mutex*
+pfs_init_mutex_v1(PSI_mutex_key key, const void *identity);
+
+void pfs_destroy_mutex_v1(PSI_mutex* mutex);
+
+PSI_rwlock*
+pfs_init_rwlock_v1(PSI_rwlock_key key, const void *identity);
+
+void pfs_destroy_rwlock_v1(PSI_rwlock* rwlock);
+
+PSI_cond*
+pfs_init_cond_v1(PSI_cond_key key, const void *identity);
+
+void pfs_destroy_cond_v1(PSI_cond* cond);
+
+int pfs_spawn_thread_v1(PSI_thread_key key,
+                        pthread_t *thread, const pthread_attr_t *attr,
+                        void *(*start_routine)(void*), void *arg);
+
+PSI_thread*
+pfs_new_thread_v1(PSI_thread_key key, const void *identity, ulong thread_id);
+
+void pfs_set_thread_id_v1(PSI_thread *thread, unsigned long id);
+
+PSI_thread*
+pfs_get_thread_v1(void);
+
+void pfs_set_thread_user_v1(const char *user, int user_len);
+
+void pfs_set_thread_account_v1(const char *user, int user_len,
+                               const char *host, int host_len);
+
+void pfs_set_thread_db_v1(const char* db, int db_len);
+
+void pfs_set_thread_command_v1(int command);
+
+void pfs_set_thread_start_time_v1(time_t start_time);
+
+void pfs_set_thread_state_v1(const char* state);
+
+void pfs_set_thread_info_v1(const char* info, int info_len);
+
+void pfs_set_thread_v1(PSI_thread* thread);
+
+void pfs_delete_current_thread_v1(void);
+
+void pfs_delete_thread_v1(PSI_thread *thread);
+
+PSI_mutex_locker*
+pfs_start_mutex_wait_v1(PSI_mutex_locker_state *state,
+                        PSI_mutex *mutex, PSI_mutex_operation op,
+                        const char *src_file, uint src_line);
+
+PSI_rwlock_locker*
+pfs_start_rwlock_rdwait_v1(PSI_rwlock_locker_state *state,
+                           PSI_rwlock *rwlock,
+                           PSI_rwlock_operation op,
+                           const char *src_file, uint src_line);
+
+PSI_rwlock_locker*
+pfs_start_rwlock_wrwait_v1(PSI_rwlock_locker_state *state,
+                           PSI_rwlock *rwlock,
+                           PSI_rwlock_operation op,
+                           const char *src_file, uint src_line);
+
+PSI_cond_locker*
+pfs_start_cond_wait_v1(PSI_cond_locker_state *state,
+                       PSI_cond *cond, PSI_mutex *mutex,
+                       PSI_cond_operation op,
+                       const char *src_file, uint src_line);
+
+PSI_table_locker*
+pfs_start_table_io_wait_v1(PSI_table_locker_state *state,
+                           PSI_table *table,
+                           PSI_table_io_operation op,
+                           uint index,
+                           const char *src_file, uint src_line);
+
+PSI_table_locker*
+pfs_start_table_lock_wait_v1(PSI_table_locker_state *state,
+                             PSI_table *table,
+                             PSI_table_lock_operation op,
+                             ulong op_flags,
+                             const char *src_file, uint src_line);
+
+void pfs_unlock_mutex_v1(PSI_mutex *mutex);
+
+void pfs_unlock_rwlock_v1(PSI_rwlock *rwlock);
+
+void pfs_signal_cond_v1(PSI_cond* cond);
+
+void pfs_broadcast_cond_v1(PSI_cond* cond);
+
+void pfs_end_mutex_wait_v1(PSI_mutex_locker* locker, int rc);
+
+void pfs_end_rwlock_rdwait_v1(PSI_rwlock_locker* locker, int rc);
+
+void pfs_end_rwlock_wrwait_v1(PSI_rwlock_locker* locker, int rc);
+
+void pfs_end_cond_wait_v1(PSI_cond_locker* locker, int rc);
+
+int pfs_set_thread_connect_attrs_v1(const char *buffer, uint length,
+                                      const void *from_cs);
+
+C_MODE_END
+
+#endif /* EMBEDDED_LIBRARY */
+#endif /* MYSQL_DYNAMIC_PLUGIN */
+#endif /* MYSQL_SERVER */
+#endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
+
+#endif
+

=== modified file 'include/violite.h'
--- a/include/violite.h	2012-05-09 16:53:03 +0000
+++ b/include/violite.h	2012-08-29 09:08:27 +0000
@@ -22,9 +22,11 @@
 #define	vio_violite_h_
 
 #include "my_net.h"   /* needed because of struct in_addr */
+#include <my_pthread.h> /* For pthread_t */
+#include <mysql/psi/psi.h>
+#include <pfs_socket_provider.h>
 #include <mysql/psi/mysql_socket.h>
 
-
 /* Simple vio interface in C;  The functions are implemented in violite.c */
 
 #ifdef	__cplusplus

=== modified file 'libmysqld/lib_sql.cc'
--- a/libmysqld/lib_sql.cc	2012-08-09 07:52:11 +0000
+++ b/libmysqld/lib_sql.cc	2012-08-29 09:08:27 +0000
@@ -517,6 +517,20 @@ int init_embedded_server(int argc, char
   char fake_name[]= "fake_name";
   my_bool acl_error;
 
+#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
+  /*
+    It makes no sense to build with both:
+    - WITH_EMBEDDED_SERVER
+    - WITH_PERFSCHEMA_STORAGE_ENGINE
+    because nobody is going to look at performance_schema.* tables
+    in a server that can not be connected to.
+    Now, if the build really uses both (this is not prevented),
+    the performance schema must have the very basic initialization
+    done to make sure that calls compiled statically don't fail.
+  */
+  pre_initialize_performance_schema();
+#endif /*WITH_PERFSCHEMA_STORAGE_ENGINE */
+
   if (my_thread_init())
     return 1;
 

=== modified file 'mysys/my_thr_init.c'
--- a/mysys/my_thr_init.c	2012-05-17 12:51:37 +0000
+++ b/mysys/my_thr_init.c	2012-08-29 09:08:27 +0000
@@ -23,6 +23,7 @@
 #include <signal.h>
 
 pthread_key(struct st_my_thread_var*, THR_KEY_mysys);
+my_bool THR_KEY_mysys_initialized= FALSE;
 mysql_mutex_t THR_LOCK_malloc, THR_LOCK_open,
               THR_LOCK_lock, THR_LOCK_myisam, THR_LOCK_heap,
               THR_LOCK_net, THR_LOCK_charset, THR_LOCK_threads,
@@ -109,7 +110,7 @@ void my_thread_global_reinit(void)
   mysql_cond_destroy(&THR_COND_threads);
   mysql_cond_init(key_THR_COND_threads, &THR_COND_threads, NULL);
 
-  tmp= my_pthread_getspecific(struct st_my_thread_var*, THR_KEY_mysys);
+  tmp= _my_thread_var();
   DBUG_ASSERT(tmp);
 
   mysql_mutex_destroy(&tmp->mutex);
@@ -162,12 +163,14 @@ my_bool my_thread_global_init(void)
                             PTHREAD_MUTEX_ERRORCHECK);
 #endif
 
+  DBUG_ASSERT(! THR_KEY_mysys_initialized);
   if ((pth_ret= pthread_key_create(&THR_KEY_mysys, NULL)) != 0)
   {
     fprintf(stderr, "Can't initialize threads: error %d\n", pth_ret);
     return 1;
   }
 
+  THR_KEY_mysys_initialized= TRUE;
   mysql_mutex_init(key_THR_LOCK_malloc, &THR_LOCK_malloc, MY_MUTEX_INIT_FAST);
   mysql_mutex_init(key_THR_LOCK_open, &THR_LOCK_open, MY_MUTEX_INIT_FAST);
   mysql_mutex_init(key_THR_LOCK_charset, &THR_LOCK_charset, MY_MUTEX_INIT_FAST);
@@ -254,7 +257,9 @@ void my_thread_global_end(void)
   }
   mysql_mutex_unlock(&THR_LOCK_threads);
 
+  DBUG_ASSERT(THR_KEY_mysys_initialized);
   pthread_key_delete(THR_KEY_mysys);
+  THR_KEY_mysys_initialized= FALSE;
 #ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
   pthread_mutexattr_destroy(&my_fast_mutexattr);
 #endif
@@ -313,7 +318,7 @@ my_bool my_thread_init(void)
           (ulong) pthread_self());
 #endif  
 
-  if (my_pthread_getspecific(struct st_my_thread_var *,THR_KEY_mysys))
+  if (_my_thread_var())
   {
 #ifdef EXTRA_DEBUG_THREADS
     fprintf(stderr,"my_thread_init() called more than once in thread 0x%lx\n",
@@ -331,7 +336,7 @@ my_bool my_thread_init(void)
     error= 1;
     goto end;
   }
-  pthread_setspecific(THR_KEY_mysys,tmp);
+  set_mysys_var(tmp);
   tmp->pthread_self= pthread_self();
   mysql_mutex_init(key_my_thread_var_mutex, &tmp->mutex, MY_MUTEX_INIT_FAST);
   mysql_cond_init(key_my_thread_var_suspend, &tmp->suspend, NULL);
@@ -369,7 +374,7 @@ end:
 void my_thread_end(void)
 {
   struct st_my_thread_var *tmp;
-  tmp= my_pthread_getspecific(struct st_my_thread_var*,THR_KEY_mysys);
+  tmp= _my_thread_var();
 
 #ifdef EXTRA_DEBUG_THREADS
   fprintf(stderr,"my_thread_end(): tmp: 0x%lx  pthread_self: 0x%lx  thread_id: %ld\n",
@@ -415,16 +420,18 @@ void my_thread_end(void)
       mysql_cond_signal(&THR_COND_threads);
     mysql_mutex_unlock(&THR_LOCK_threads);
   }
-  pthread_setspecific(THR_KEY_mysys,0);
+  set_mysys_var(NULL);
 }
 
 struct st_my_thread_var *_my_thread_var(void)
 {
+  DBUG_ASSERT(THR_KEY_mysys_initialized);
   return  my_pthread_getspecific(struct st_my_thread_var*,THR_KEY_mysys);
 }
 
 int set_mysys_var(struct st_my_thread_var *mysys_var)
 {
+  DBUG_ASSERT(THR_KEY_mysys_initialized);
   return my_pthread_setspecific_ptr(THR_KEY_mysys, mysys_var);
 }
 
@@ -462,8 +469,17 @@ const char *my_thread_name(void)
 
 extern void **my_thread_var_dbug()
 {
-  struct st_my_thread_var *tmp=
-    my_pthread_getspecific(struct st_my_thread_var*,THR_KEY_mysys);
+  struct st_my_thread_var *tmp;
+  /*
+    Instead of enforcing DBUG_ASSERT(THR_KEY_mysys_initialized) here,
+    which causes any DBUG_ENTER and related traces to fail when
+    used in init / cleanup code, we are more tolerant:
+    using DBUG_ENTER / DBUG_PRINT / DBUG_RETURN
+    when the dbug instrumentation is not in place will do nothing.
+  */
+  if (! THR_KEY_mysys_initialized)
+    return NULL;
+  tmp= _my_thread_var();
   return tmp && tmp->init ? &tmp->dbug : 0;
 }
 #endif /* DBUG_OFF */

=== modified file 'sql/binlog.cc'
--- a/sql/binlog.cc	2012-08-22 12:30:48 +0000
+++ b/sql/binlog.cc	2012-08-29 09:08:27 +0000
@@ -140,17 +140,16 @@ class Thread_excursion
 public:
   Thread_excursion(THD *thd)
     : m_original_thd(thd)
-#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
-    , m_saved_psi(PSI_server ? PSI_server->get_thread() : NULL)
-#endif
+#ifdef HAVE_PSI_THREAD_INTERFACE
+    , m_saved_psi(PSI_THREAD_CALL(get_thread)())
+#endif /* HAVE_PSI_THREAD_INTERFACE */
   {
   }
 
   ~Thread_excursion() {
-#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
-    if (PSI_server)
-      PSI_server->set_thread(m_saved_psi);
-#endif
+#ifdef HAVE_PSI_THREAD_INTERFACE
+    PSI_THREAD_CALL(set_thread)(m_saved_psi);
+#endif /* HAVE_PSI_THREAD_INTERFACE */
 #ifndef EMBEDDED_LIBRARY
     if (unlikely(setup_thread_globals(m_original_thd)))
       DBUG_ASSERT(0);                           // Out of memory?!
@@ -162,17 +161,15 @@ public:
    */
   int attach_to(THD *thd)
   {
-#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
-    if (PSI_server)
-      PSI_server->set_thread(thd_get_psi(thd));
-#endif
+#ifdef HAVE_PSI_THREAD_INTERFACE
+    PSI_THREAD_CALL(set_thread)(thd_get_psi(thd));
+#endif /* HAVE_PSI_THREAD_INTERFACE */
 #ifndef EMBEDDED_LIBRARY
     if (unlikely(setup_thread_globals(thd)))
     {
-#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
-      if (PSI_server)
-        PSI_server->set_thread(m_saved_psi);
-#endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
+#ifdef HAVE_PSI_THREAD_INTERFACE
+      PSI_THREAD_CALL(set_thread)(m_saved_psi);
+#endif /* HAVE_PSI_THREAD_INTERFACE */
       /*
         Indirectly uses pthread_setspecific, which can only return
         ENOMEM or EINVAL. Since store_globals are using correct keys,
@@ -188,19 +185,19 @@ private:
 
   int setup_thread_globals(THD *thd) const {
     int error= 0;
-    THD *original_thd= my_pthread_getspecific(THD*, THR_THD);
-    MEM_ROOT* original_mem_root= my_pthread_getspecific(MEM_ROOT*, THR_MALLOC);
-    if ((error= my_pthread_setspecific_ptr(THR_THD, thd)))
+    THD *original_thd= my_pthread_get_THR_THD();
+    MEM_ROOT ** original_mem_root= my_pthread_get_THR_MALLOC();
+    if ((error= my_pthread_set_THR_THD(thd)))
       goto exit0;
-    if ((error= my_pthread_setspecific_ptr(THR_MALLOC, &thd->mem_root)))
+    if ((error= my_pthread_set_THR_MALLOC(&thd->mem_root)))
       goto exit1;
     if ((error= set_mysys_var(thd->mysys_var)))
       goto exit2;
     goto exit0;
 exit2:
-    error= my_pthread_setspecific_ptr(THR_MALLOC,  original_mem_root);
+    error= my_pthread_set_THR_MALLOC(original_mem_root);
 exit1:
-    error= my_pthread_setspecific_ptr(THR_THD,  original_thd);
+    error= my_pthread_set_THR_THD(original_thd);
 exit0:
     return error;
   }

=== modified file 'sql/events.cc'
--- a/sql/events.cc	2012-03-06 14:29:42 +0000
+++ b/sql/events.cc	2012-08-29 09:08:27 +0000
@@ -905,7 +905,7 @@ end:
   }
   delete thd;
   /* Remember that we don't have a THD */
-  my_pthread_setspecific_ptr(THR_THD,  NULL);
+  my_pthread_set_THR_THD(NULL);
 
   DBUG_RETURN(res);
 }

=== modified file 'sql/ha_ndbcluster.cc'
--- a/sql/ha_ndbcluster.cc	2012-06-22 10:11:31 +0000
+++ b/sql/ha_ndbcluster.cc	2012-08-29 09:08:27 +0000
@@ -13025,8 +13025,7 @@ NDB_SHARE *ndbcluster_get_share(const ch
     if ((share= (NDB_SHARE*) my_malloc(sizeof(*share),
                                        MYF(MY_WME | MY_ZEROFILL))))
     {
-      MEM_ROOT **root_ptr=
-        my_pthread_getspecific_ptr(MEM_ROOT**, THR_MALLOC);
+      MEM_ROOT **root_ptr= my_pthread_get_THR_MALLOC();
       MEM_ROOT *old_root= *root_ptr;
       init_sql_alloc(&share->mem_root, 1024, 0);
       *root_ptr= &share->mem_root; // remember to reset before return

=== modified file 'sql/ha_ndbcluster_binlog.cc'
--- a/sql/ha_ndbcluster_binlog.cc	2012-04-19 11:13:17 +0000
+++ b/sql/ha_ndbcluster_binlog.cc	2012-08-29 09:08:27 +0000
@@ -323,7 +323,7 @@ ndb_binlog_open_shadow_table(THD *thd, N
   DBUG_ENTER("ndb_binlog_open_shadow_table");
 
   MEM_ROOT **root_ptr=
-    my_pthread_getspecific_ptr(MEM_ROOT**, THR_MALLOC);
+    my_pthread_get_THR_MALLOC(MEM_ROOT**, THR_MALLOC);
   MEM_ROOT *old_root= *root_ptr;
   init_sql_alloc(&event_data->mem_root, 1024, 0);
   *root_ptr= &event_data->mem_root;
@@ -6754,8 +6754,7 @@ restart_cluster_failure:
          !ndb_binlog_running))
       break; /* Shutting down server */
 
-    MEM_ROOT **root_ptr=
-      my_pthread_getspecific_ptr(MEM_ROOT**, THR_MALLOC);
+    MEM_ROOT **root_ptr= my_pthread_get_THR_MALLOC();
     MEM_ROOT *old_root= *root_ptr;
     MEM_ROOT mem_root;
     init_sql_alloc(&mem_root, 4096, 0);

=== modified file 'sql/handler.cc'
--- a/sql/handler.cc	2012-08-22 16:31:19 +0000
+++ b/sql/handler.cc	2012-08-29 09:08:27 +0000
@@ -36,6 +36,7 @@
 #include "transaction.h"
 #include <errno.h>
 #include "probes_mysql.h"
+#include <pfs_table_provider.h>
 #include <mysql/psi/mysql_table.h>
 #include "debug_sync.h"         // DEBUG_SYNC
 #include <my_bit.h>

=== modified file 'sql/mdl.cc'
--- a/sql/mdl.cc	2012-08-07 06:34:04 +0000
+++ b/sql/mdl.cc	2012-08-29 09:08:27 +0000
@@ -20,6 +20,7 @@
 #include <mysqld_error.h>
 #include <mysql/plugin.h>
 #include <mysql/service_thd_wait.h>
+#include <pfs_stage_provider.h>
 #include <mysql/psi/mysql_stage.h>
 
 #ifdef HAVE_PSI_INTERFACE

=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc	2012-08-28 14:34:40 +0000
+++ b/sql/mysqld.cc	2012-08-29 09:08:27 +0000
@@ -80,10 +80,13 @@
 
 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
 #include "../storage/perfschema/pfs_server.h"
+#include <pfs_idle_provider.h>
 #endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
+
 #include <mysql/psi/mysql_idle.h>
 #include <mysql/psi/mysql_socket.h>
 #include <mysql/psi/mysql_statement.h>
+
 #include "mysql_com_server.h"
 
 #include "keycaches.h"
@@ -684,7 +687,9 @@ SHOW_COMP_OPTION have_profiling;
 /* Thread specific variables */
 
 pthread_key(MEM_ROOT**,THR_MALLOC);
+bool THR_MALLOC_initialized= false;
 pthread_key(THD*, THR_THD);
+bool THR_THD_initialized= false;
 mysql_mutex_t LOCK_thread_count;
 mysql_mutex_t
   LOCK_status, LOCK_error_log, LOCK_uuid_generator,
@@ -1837,11 +1842,17 @@ void clean_up(bool print_message)
 #endif
   free_list(opt_plugin_load_list_ptr);
 
-  if (THR_THD)
+  if (THR_THD_initialized)
+  {
     (void) pthread_key_delete(THR_THD);
+    THR_THD_initialized= false;
+  }
 
-  if (THR_MALLOC)
+  if (THR_MALLOC_initialized)
+  {
     (void) pthread_key_delete(THR_MALLOC);
+    THR_MALLOC_initialized= false;
+  }
 
   /*
     The following lines may never be executed as the main thread may have
@@ -4110,12 +4121,16 @@ static int init_thread_environment()
              PTHREAD_CREATE_DETACHED);
   pthread_attr_setscope(&connection_attrib, PTHREAD_SCOPE_SYSTEM);
 
+  DBUG_ASSERT(! THR_THD_initialized);
+  DBUG_ASSERT(! THR_MALLOC_initialized);
   if (pthread_key_create(&THR_THD,NULL) ||
       pthread_key_create(&THR_MALLOC,NULL))
   {
     sql_print_error("Can't create thread-keys");
     return 1;
   }
+  THR_THD_initialized= true;
+  THR_MALLOC_initialized= true;
   return 0;
 }
 
@@ -4276,7 +4291,7 @@ static int generate_server_uuid()
   func_uuid->val_str(&uuid);
   delete thd;
   /* Remember that we don't have a THD */
-  my_pthread_setspecific_ptr(THR_THD,  0);
+  my_pthread_set_THR_THD(0);
 
   strncpy(server_uuid, uuid.c_ptr(), UUID_LENGTH);
   server_uuid[UUID_LENGTH]= '\0';
@@ -5029,14 +5044,18 @@ int mysqld_main(int argc, char **argv)
 #ifdef HAVE_NPTL
   ld_assume_kernel_is_set= (getenv("LD_ASSUME_KERNEL") != 0);
 #endif
+
 #ifndef _WIN32
+#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
+  pre_initialize_performance_schema();
+#endif /*WITH_PERFSCHEMA_STORAGE_ENGINE */
   // For windows, my_init() is called from the win specific mysqld_main
   if (my_init())                 // init my_sys library & pthreads
   {
     fprintf(stderr, "my_init() failed.");
     return 1;
   }
-#endif
+#endif /* _WIN32 */
 
   orig_argc= argc;
   orig_argv= argv;
@@ -5655,6 +5674,10 @@ int mysqld_main(int argc, char **argv)
   /* Must be initialized early for comparison of service name */
   system_charset_info= &my_charset_utf8_general_ci;
 
+#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
+  pre_initialize_performance_schema();
+#endif /*WITH_PERFSCHEMA_STORAGE_ENGINE */
+
   if (my_init())
   {
     fprintf(stderr, "my_init() failed.");

=== modified file 'sql/mysqld.h'
--- a/sql/mysqld.h	2012-08-16 13:11:09 +0000
+++ b/sql/mysqld.h	2012-08-29 09:08:27 +0000
@@ -21,6 +21,7 @@
 #include "my_decimal.h"                         /* my_decimal */
 #include "mysql_com.h"                     /* SERVER_VERSION_LENGTH */
 #include "my_atomic.h"                     /* my_atomic_rwlock_t */
+#include "pfs_file_provider.h"
 #include "mysql/psi/mysql_file.h"          /* MYSQL_FILE */
 #include "sql_list.h"                      /* I_List */
 #include "sql_cmd.h"                       /* SQLCOM_END */
@@ -286,6 +287,21 @@ extern ulong log_warnings;
   using my_pthread_setspecific_ptr()/my_thread_getspecific_ptr().
 */
 extern pthread_key(MEM_ROOT**,THR_MALLOC);
+extern bool THR_MALLOC_initialized;
+
+static inline MEM_ROOT **
+my_pthread_get_THR_MALLOC()
+{
+  DBUG_ASSERT(THR_MALLOC_initialized);
+  return my_pthread_getspecific(MEM_ROOT **, THR_MALLOC);
+}
+
+static inline int
+my_pthread_set_THR_MALLOC(MEM_ROOT ** hdl)
+{
+  DBUG_ASSERT(THR_MALLOC_initialized);
+  return my_pthread_setspecific_ptr(THR_MALLOC, hdl);
+}
 
 #ifdef HAVE_PSI_INTERFACE
 #ifdef HAVE_MMAP
@@ -569,6 +585,21 @@ extern char *opt_ssl_ca, *opt_ssl_capath
             *opt_ssl_key, *opt_ssl_crl, *opt_ssl_crlpath;
 
 extern MYSQL_PLUGIN_IMPORT pthread_key(THD*, THR_THD);
+extern bool THR_THD_initialized;
+
+static inline THD *
+my_pthread_get_THR_THD()
+{
+  DBUG_ASSERT(THR_THD_initialized);
+  return my_pthread_getspecific(THD *, THR_THD);
+}
+
+static inline int
+my_pthread_set_THR_THD(THD *thd)
+{
+  DBUG_ASSERT(THR_THD_initialized);
+  return my_pthread_setspecific_ptr(THR_THD, thd);
+}
 
 /**
   only options that need special treatment in get_one_option() deserve
@@ -718,9 +749,10 @@ extern "C" THD *_current_thd_noinline();
   using my_pthread_setspecific_ptr()/my_thread_getspecific_ptr().
 */
 extern pthread_key(THD*, THR_THD);
+extern bool THR_THD_initialized;
 inline THD *_current_thd(void)
 {
-  return my_pthread_getspecific_ptr(THD*,THR_THD);
+  return my_pthread_get_THR_THD();
 }
 #endif
 #define current_thd _current_thd()

=== modified file 'sql/rpl_info_table_access.cc'
--- a/sql/rpl_info_table_access.cc	2012-08-09 10:05:01 +0000
+++ b/sql/rpl_info_table_access.cc	2012-08-29 09:08:27 +0000
@@ -464,7 +464,7 @@ bool Rpl_info_table_access::drop_thd(THD
   if (saved_current_thd != current_thd)
   {
     delete thd;
-    my_pthread_setspecific_ptr(THR_THD,  NULL);
+    my_pthread_set_THR_THD(NULL);
   }
 
   DBUG_RETURN(FALSE);

=== modified file 'sql/sql_acl.cc'
--- a/sql/sql_acl.cc	2012-07-05 14:54:08 +0000
+++ b/sql/sql_acl.cc	2012-08-29 09:08:27 +0000
@@ -970,7 +970,7 @@ my_bool acl_init(bool dont_read_acl_tabl
   return_val= acl_reload(thd);
   delete thd;
   /* Remember that we don't have a THD */
-  my_pthread_setspecific_ptr(THR_THD,  0);
+  my_pthread_set_THR_THD(0);
   DBUG_RETURN(return_val);
 }
 
@@ -5001,7 +5001,7 @@ my_bool grant_init()
   return_val=  grant_reload(thd);
   delete thd;
   /* Remember that we don't have a THD */
-  my_pthread_setspecific_ptr(THR_THD,  0);
+  my_pthread_set_THR_THD(0);
   DBUG_RETURN(return_val);
 }
 
@@ -5026,8 +5026,7 @@ static my_bool grant_load_procs_priv(TAB
   MEM_ROOT *memex_ptr;
   my_bool return_val= 1;
   bool check_no_resolve= specialflag & SPECIAL_NO_RESOLVE;
-  MEM_ROOT **save_mem_root_ptr= my_pthread_getspecific_ptr(MEM_ROOT**,
-                                                           THR_MALLOC);
+  MEM_ROOT **save_mem_root_ptr= my_pthread_get_THR_MALLOC();
   DBUG_ENTER("grant_load_procs_priv");
   (void) my_hash_init(&proc_priv_hash, &my_charset_utf8_bin,
                       0,0,0, (my_hash_get_key) get_grant_table,
@@ -5042,7 +5041,7 @@ static my_bool grant_load_procs_priv(TAB
   if (!p_table->file->ha_index_first(p_table->record[0]))
   {
     memex_ptr= &memex;
-    my_pthread_setspecific_ptr(THR_MALLOC, &memex_ptr);
+    my_pthread_set_THR_MALLOC(&memex_ptr);
     do
     {
       GRANT_NAME *mem_check;
@@ -5098,7 +5097,7 @@ static my_bool grant_load_procs_priv(TAB
 
 end_unlock:
   p_table->file->ha_index_end();
-  my_pthread_setspecific_ptr(THR_MALLOC, save_mem_root_ptr);
+  my_pthread_set_THR_MALLOC(save_mem_root_ptr);
   DBUG_RETURN(return_val);
 }
 
@@ -5124,8 +5123,7 @@ static my_bool grant_load(THD *thd, TABL
   my_bool return_val= 1;
   TABLE *t_table= 0, *c_table= 0;
   bool check_no_resolve= specialflag & SPECIAL_NO_RESOLVE;
-  MEM_ROOT **save_mem_root_ptr= my_pthread_getspecific_ptr(MEM_ROOT**,
-                                                           THR_MALLOC);
+  MEM_ROOT **save_mem_root_ptr= my_pthread_get_THR_MALLOC();
   sql_mode_t old_sql_mode= thd->variables.sql_mode;
   DBUG_ENTER("grant_load");
 
@@ -5145,7 +5143,7 @@ static my_bool grant_load(THD *thd, TABL
   if (!t_table->file->ha_index_first(t_table->record[0]))
   {
     memex_ptr= &memex;
-    my_pthread_setspecific_ptr(THR_MALLOC, &memex_ptr);
+    my_pthread_set_THR_MALLOC(&memex_ptr);
     do
     {
       GRANT_TABLE *mem_check;
@@ -5184,7 +5182,7 @@ static my_bool grant_load(THD *thd, TABL
 
 end_unlock:
   t_table->file->ha_index_end();
-  my_pthread_setspecific_ptr(THR_MALLOC, save_mem_root_ptr);
+  my_pthread_set_THR_MALLOC(save_mem_root_ptr);
 end_index_init:
   thd->variables.sql_mode= old_sql_mode;
   DBUG_RETURN(return_val);
@@ -10861,7 +10859,7 @@ acl_authenticate(THD *thd, uint com_chan
     my_ok(thd);
 
 #ifdef HAVE_PSI_THREAD_INTERFACE
-  PSI_THREAD_CALL(set_thread_user_host)
+  PSI_THREAD_CALL(set_thread_account)
     (thd->main_security_ctx.user, strlen(thd->main_security_ctx.user),
     thd->main_security_ctx.host_or_ip, strlen(thd->main_security_ctx.host_or_ip));
 #endif

=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc	2012-08-24 04:26:40 +0000
+++ b/sql/sql_base.cc	2012-08-29 09:08:27 +0000
@@ -9088,7 +9088,7 @@ my_bool mysql_rm_tmp_tables(void)
     my_dirend(dirp);
   }
   delete thd;
-  my_pthread_setspecific_ptr(THR_THD,  0);
+  my_pthread_set_THR_THD(0);
   DBUG_RETURN(0);
 }
 

=== modified file 'sql/sql_base.h'
--- a/sql/sql_base.h	2012-07-24 07:02:51 +0000
+++ b/sql/sql_base.h	2012-08-29 09:08:27 +0000
@@ -606,4 +606,7 @@ private:
   int m_unhandled_errors;
 };
 
+#include "pfs_table_provider.h"
+#include "mysql/psi/mysql_table.h"
+
 #endif /* SQL_BASE_INCLUDED */

=== modified file 'sql/sql_class.cc'
--- a/sql/sql_class.cc	2012-08-21 06:58:05 +0000
+++ b/sql/sql_class.cc	2012-08-29 09:08:27 +0000
@@ -1330,7 +1330,7 @@ void thd_get_xid(const MYSQL_THD thd, MY
 #ifdef _WIN32
 extern "C"   THD *_current_thd_noinline(void)
 {
-  return my_pthread_getspecific_ptr(THD*,THR_THD);
+  return my_pthread_get_THR_THD();
 }
 #endif
 /*
@@ -1863,8 +1863,8 @@ bool THD::store_globals()
   */
   DBUG_ASSERT(thread_stack);
 
-  if (my_pthread_setspecific_ptr(THR_THD,  this) ||
-      my_pthread_setspecific_ptr(THR_MALLOC, &mem_root))
+  if (my_pthread_set_THR_THD(this) ||
+      my_pthread_set_THR_MALLOC(&mem_root))
     return 1;
   /*
     mysys_var is concurrently readable by a killer thread.
@@ -1903,11 +1903,11 @@ bool THD::restore_globals()
     to track stack overrun.
   */
   DBUG_ASSERT(thread_stack);
-  
+
   /* Undocking the thread specific data. */
-  my_pthread_setspecific_ptr(THR_THD, NULL);
-  my_pthread_setspecific_ptr(THR_MALLOC, NULL);
-  
+  my_pthread_set_THR_THD(NULL);
+  my_pthread_set_THR_MALLOC(NULL);
+
   return 0;
 }
 

=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h	2012-08-27 11:23:37 +0000
+++ b/sql/sql_class.h	2012-08-29 09:08:27 +0000
@@ -37,9 +37,15 @@
 #include "opt_trace_context.h"    /* Opt_trace_context */
 #include "rpl_gtid.h"
 
+#include <pfs_stage_provider.h>
 #include <mysql/psi/mysql_stage.h>
+
+#include <pfs_statement_provider.h>
 #include <mysql/psi/mysql_statement.h>
+
+#include <pfs_idle_provider.h>
 #include <mysql/psi/mysql_idle.h>
+
 #include <mysql_com_server.h>
 #include "sql_data_change.h"
 

=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc	2012-07-26 16:05:43 +0000
+++ b/sql/sql_parse.cc	2012-08-29 09:08:27 +0000
@@ -1539,10 +1539,10 @@ bool dispatch_command(enum enum_server_c
         and flushes tables.
       */
       bool res;
-      my_pthread_setspecific_ptr(THR_THD, NULL);
+      my_pthread_set_THR_THD(NULL);
       res= reload_acl_and_cache(NULL, options | REFRESH_FAST,
                                 NULL, &not_used);
-      my_pthread_setspecific_ptr(THR_THD, thd);
+      my_pthread_set_THR_THD(thd);
       if (res)
         break;
     }

=== modified file 'sql/sql_plugin.cc'
--- a/sql/sql_plugin.cc	2012-08-24 12:32:55 +0000
+++ b/sql/sql_plugin.cc	2012-08-29 09:08:27 +0000
@@ -1555,7 +1555,7 @@ static void plugin_load(MEM_ROOT *tmp_ro
   close_mysql_tables(new_thd);
 end:
   /* Remember that we don't have a THD */
-  my_pthread_setspecific_ptr(THR_THD, 0);
+  my_pthread_set_THR_THD(0);
   DBUG_VOID_RETURN;
 }
 

=== modified file 'sql/sql_reload.cc'
--- a/sql/sql_reload.cc	2012-05-30 10:03:45 +0000
+++ b/sql/sql_reload.cc	2012-08-29 09:08:27 +0000
@@ -97,7 +97,7 @@ bool reload_acl_and_cache(THD *thd, unsi
     {
       delete tmp_thd;
       /* Remember that we don't have a THD */
-      my_pthread_setspecific_ptr(THR_THD,  0);
+      my_pthread_set_THR_THD(0);
       thd= 0;
     }
     reset_mqh((LEX_USER *)NULL, TRUE);

=== modified file 'sql/sql_servers.cc'
--- a/sql/sql_servers.cc	2012-07-30 13:28:51 +0000
+++ b/sql/sql_servers.cc	2012-08-29 09:08:27 +0000
@@ -177,7 +177,7 @@ bool servers_init(bool dont_read_servers
   return_val= servers_reload(thd);
   delete thd;
   /* Remember that we don't have a THD */
-  my_pthread_setspecific_ptr(THR_THD,  0);
+  my_pthread_set_THR_THD(0);
 
 end:
   DBUG_RETURN(return_val);

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2012-08-24 11:56:19 +0000
+++ b/sql/sql_table.cc	2012-08-29 09:08:27 +0000
@@ -54,7 +54,6 @@
 #include "transaction.h"
 #include "datadict.h"  // dd_frm_type()
 #include "sql_resolver.h"              // setup_order, fix_inner_refs
-#include <mysql/psi/mysql_table.h>
 
 #ifdef __WIN__
 #include <io.h>
@@ -1703,7 +1702,7 @@ void execute_ddl_log_recovery()
   mysql_mutex_unlock(&LOCK_gdl);
   delete thd;
   /* Remember that we don't have a THD */
-  my_pthread_setspecific_ptr(THR_THD,  0);
+  my_pthread_set_THR_THD(0);
   DBUG_VOID_RETURN;
 }
 

=== modified file 'sql/sql_udf.cc'
--- a/sql/sql_udf.cc	2012-03-06 14:29:42 +0000
+++ b/sql/sql_udf.cc	2012-08-29 09:08:27 +0000
@@ -249,7 +249,7 @@ end:
   close_mysql_tables(new_thd);
   delete new_thd;
   /* Remember that we don't have a THD */
-  my_pthread_setspecific_ptr(THR_THD,  0);
+  my_pthread_set_THR_THD(0);
   DBUG_VOID_RETURN;
 }
 

=== modified file 'sql/table.cc'
--- a/sql/table.cc	2012-08-28 11:31:48 +0000
+++ b/sql/table.cc	2012-08-29 09:08:27 +0000
@@ -739,7 +739,7 @@ int open_table_def(THD *thd, TABLE_SHARE
 
   if (table_type == 1)
   {
-    root_ptr= my_pthread_getspecific_ptr(MEM_ROOT**, THR_MALLOC);
+    root_ptr= my_pthread_get_THR_MALLOC();
     old_root= *root_ptr;
     *root_ptr= &share->mem_root;
     error= open_binary_frm(thd, share, head, file);

=== modified file 'sql/thr_malloc.cc'
--- a/sql/thr_malloc.cc	2011-12-09 21:08:37 +0000
+++ b/sql/thr_malloc.cc	2012-08-29 09:08:27 +0000
@@ -37,7 +37,7 @@ void init_sql_alloc(MEM_ROOT *mem_root,
 
 void *sql_alloc(size_t Size)
 {
-  MEM_ROOT *root= *my_pthread_getspecific_ptr(MEM_ROOT**,THR_MALLOC);
+  MEM_ROOT *root= *my_pthread_get_THR_MALLOC();
   return alloc_root(root,Size);
 }
 

=== modified file 'sql/tztime.cc'
--- a/sql/tztime.cc	2012-05-29 19:18:45 +0000
+++ b/sql/tztime.cc	2012-08-29 09:08:27 +0000
@@ -1784,8 +1784,8 @@ end:
   else
   {
     /* Remember that we don't have a THD */
-    my_pthread_setspecific_ptr(THR_THD,  0);
-    my_pthread_setspecific_ptr(THR_MALLOC,  0);
+    my_pthread_set_THR_THD(0);
+    my_pthread_set_THR_MALLOC(0);
   }
   
   default_tz= default_tz_name ? global_system_variables.time_zone

=== modified file 'storage/innobase/include/univ.i'
--- a/storage/innobase/include/univ.i	2012-07-13 13:03:40 +0000
+++ b/storage/innobase/include/univ.i	2012-08-29 09:08:27 +0000
@@ -127,21 +127,42 @@ Sun Studio */
 #include <inttypes.h>
 #endif /* !__WIN__ */
 
+#ifndef UNIV_HOTBACKUP
+# ifdef HAVE_PSI_INTERFACE
+#  include "mysql/psi/psi.h"
+# endif
+
 /* Following defines are to enable performance schema
-instrumentation in each of four InnoDB modules if
-HAVE_PSI_INTERFACE is defined. */
-#if defined HAVE_PSI_INTERFACE && !defined UNIV_HOTBACKUP
-# define UNIV_PFS_MUTEX
-# define UNIV_PFS_RWLOCK
+instrumentation in each of four InnoDB modules if the
+corresponding HAVE_PSI_XXX_INTERFACE is defined. */
+# ifdef HAVE_PSI_MUTEX_INTERFACE
+#  define UNIV_PFS_MUTEX
+# endif
+# ifdef HAVE_PSI_RWLOCK_INTERFACE
+#  define UNIV_PFS_RWLOCK
+# endif
 /* For I/O instrumentation, performance schema rely
 on a native descriptor to identify the file, this
 descriptor could conflict with our OS level descriptor.
 Disable IO instrumentation on Windows until this is
 resolved */
 # ifndef __WIN__
-#  define UNIV_PFS_IO
+#  ifdef HAVE_PSI_FILE_INTERFACE
+#   define UNIV_PFS_IO
+/* Compile with pfs static calls if available */
+#   include "pfs_file_provider.h"
+#   include "mysql/psi/mysql_file.h"
+#  endif
+# endif
+# ifdef HAVE_PSI_THREAD_INTERFACE
+#  define UNIV_PFS_THREAD
+# endif
+
+# if defined(UNIV_PFS_MUTEX) || defined (UNIV_PFS_RWLOCK) || defined (UNIV_PFS_THREAD)
+/* Compile with pfs static calls if available */
+#  include "pfs_thread_provider.h"
+#  include "mysql/psi/mysql_thread.h"
 # endif
-# define UNIV_PFS_THREAD
 
 /* There are mutexes/rwlocks that we want to exclude from
 instrumentation even if their corresponding performance schema
@@ -152,7 +173,7 @@ be excluded from instrumentation. */
 
 # define PFS_IS_INSTRUMENTED(key)	((key) != PFS_NOT_INSTRUMENTED)
 
-#endif /* HAVE_PSI_INTERFACE */
+#endif /* ! UNIV_HOTBACKUP */
 
 #ifdef __WIN__
 # define YY_NO_UNISTD_H 1

=== modified file 'storage/perfschema/pfs.cc'
--- a/storage/perfschema/pfs.cc	2012-08-20 10:22:12 +0000
+++ b/storage/perfschema/pfs.cc	2012-08-29 09:08:27 +0000
@@ -386,14 +386,14 @@ static inline int mysql_mutex_lock(
   struct PSI_mutex_locker *locker= NULL;
 
   ............... (a)
-  locker= PSI_server->start_mutex_wait(&state, that->p_psi,
-                                       PSI_MUTEX_LOCK, locker, src_file, src_line);
+  locker= PSI_MUTEX_CALL(start_mutex_wait)(&state, that->p_psi, PSI_MUTEX_LOCK,
+                                           locker, src_file, src_line);
 
   ............... (b)
   result= pthread_mutex_lock(&that->m_mutex);
 
   ............... (c)
-  PSI_server->end_mutex_wait(locker, result);
+  PSI_MUTEX_CALL(end_mutex_wait)(locker, result);
 
   return result;
 }
@@ -413,6 +413,62 @@ static inline int mysql_mutex_lock(...)
   return result;
 }
 @endverbatim
+
+  When the performance schema instrumentation is compiled in,
+  and when the code compiled is internal to the server implementation,
+  PSI_MUTEX_CALL expands directly to functions calls in the performance schema,
+  to make (a) and (c) calls as efficient as possible.
+
+@verbatim
+static inline int mysql_mutex_lock(...)
+{
+  int result;
+  struct PSI_mutex_locker_state state;
+  struct PSI_mutex_locker *locker= NULL;
+
+  ............... (a)
+  locker= pfs_start_mutex_wait_v1(&state, that->p_psi, PSI_MUTEX_LOCK,
+                                  locker, src_file, src_line);
+
+  ............... (b)
+  result= pthread_mutex_lock(&that->m_mutex);
+
+  ............... (c)
+  pfs_end_mutex_wait_v1(locker, result);
+
+  return result;
+}
+@endverbatim
+
+  When the performance schema instrumentation is compiled in,
+  and when the code compiled is external to the server implementation
+  (typically, a dynamic plugin),
+  PSI_MUTEX_CALL expands to dynamic calls to the underlying implementation,
+  using the PSI_server entry point.
+  This makes (a) and (c) slower, as a function pointer is used instead of a static call,
+  but also independent of the implementation, for binary compatibility.
+
+@verbatim
+static inline int mysql_mutex_lock(...)
+{
+  int result;
+  struct PSI_mutex_locker_state state;
+  struct PSI_mutex_locker *locker= NULL;
+
+  ............... (a)
+  locker= PSI_server->start_mutex_wait(&state, that->p_psi, PSI_MUTEX_LOCK,
+                                       locker, src_file, src_line);
+
+  ............... (b)
+  result= pthread_mutex_lock(&that->m_mutex);
+
+  ............... (c)
+  PSI_server->end_mutex_wait(locker, result);
+
+  return result;
+}
+@endverbatim
+
 */
 
 /**
@@ -1113,6 +1169,20 @@ static inline int mysql_mutex_lock(...)
 pthread_key(PFS_thread*, THR_PFS);
 bool THR_PFS_initialized= false;
 
+static inline PFS_thread*
+my_pthread_get_THR_PFS()
+{
+  DBUG_ASSERT(THR_PFS_initialized);
+  return my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
+}
+
+static inline void
+my_pthread_set_THR_PFS(PFS_thread *pfs)
+{
+  DBUG_ASSERT(THR_PFS_initialized);
+  my_pthread_setspecific_ptr(THR_PFS, pfs);
+}
+
 /**
   Conversion map from PSI_mutex_operation to enum_operation_type.
   Indexed by enum PSI_mutex_operation.
@@ -1280,7 +1350,8 @@ static int build_prefix(const LEX_STRING
   DBUG_ASSERT(category != NULL);                                      \
   DBUG_ASSERT(info != NULL);                                          \
   if (unlikely(build_prefix(&PREFIX, category,                        \
-                   formatted_name, &prefix_length)))                  \
+                   formatted_name, &prefix_length)) ||                \
+      ! pfs_initialized)                                              \
   {                                                                   \
     for (; count>0; count--, info++)                                  \
       *(info->m_key)= 0;                                              \
@@ -1317,9 +1388,9 @@ C_MODE_START
   Implementation of the mutex instrumentation interface.
   @sa PSI_v1::register_mutex.
 */
-static void register_mutex_v1(const char *category,
-                              PSI_mutex_info_v1 *info,
-                              int count)
+void pfs_register_mutex_v1(const char *category,
+                           PSI_mutex_info_v1 *info,
+                           int count)
 {
   REGISTER_BODY_V1(PSI_mutex_key,
                    mutex_instrument_prefix,
@@ -1330,9 +1401,9 @@ static void register_mutex_v1(const char
   Implementation of the rwlock instrumentation interface.
   @sa PSI_v1::register_rwlock.
 */
-static void register_rwlock_v1(const char *category,
-                               PSI_rwlock_info_v1 *info,
-                               int count)
+void pfs_register_rwlock_v1(const char *category,
+                            PSI_rwlock_info_v1 *info,
+                            int count)
 {
   REGISTER_BODY_V1(PSI_rwlock_key,
                    rwlock_instrument_prefix,
@@ -1343,9 +1414,9 @@ static void register_rwlock_v1(const cha
   Implementation of the cond instrumentation interface.
   @sa PSI_v1::register_cond.
 */
-static void register_cond_v1(const char *category,
-                             PSI_cond_info_v1 *info,
-                             int count)
+void pfs_register_cond_v1(const char *category,
+                          PSI_cond_info_v1 *info,
+                          int count)
 {
   REGISTER_BODY_V1(PSI_cond_key,
                    cond_instrument_prefix,
@@ -1356,9 +1427,9 @@ static void register_cond_v1(const char
   Implementation of the thread instrumentation interface.
   @sa PSI_v1::register_thread.
 */
-static void register_thread_v1(const char *category,
-                               PSI_thread_info_v1 *info,
-                               int count)
+void pfs_register_thread_v1(const char *category,
+                            PSI_thread_info_v1 *info,
+                            int count)
 {
   REGISTER_BODY_V1(PSI_thread_key,
                    thread_instrument_prefix,
@@ -1369,18 +1440,18 @@ static void register_thread_v1(const cha
   Implementation of the file instrumentation interface.
   @sa PSI_v1::register_file.
 */
-static void register_file_v1(const char *category,
-                             PSI_file_info_v1 *info,
-                             int count)
+void pfs_register_file_v1(const char *category,
+                          PSI_file_info_v1 *info,
+                          int count)
 {
   REGISTER_BODY_V1(PSI_file_key,
                    file_instrument_prefix,
                    register_file_class)
 }
 
-static void register_stage_v1(const char *category,
-                              PSI_stage_info_v1 **info_array,
-                              int count)
+void pfs_register_stage_v1(const char *category,
+                           PSI_stage_info_v1 **info_array,
+                           int count)
 {
   char formatted_name[PFS_MAX_INFO_NAME_LENGTH];
   int prefix_length;
@@ -1391,7 +1462,8 @@ static void register_stage_v1(const char
   DBUG_ASSERT(category != NULL);
   DBUG_ASSERT(info_array != NULL);
   if (unlikely(build_prefix(&stage_instrument_prefix, category,
-               formatted_name, &prefix_length)))
+               formatted_name, &prefix_length)) ||
+      ! pfs_initialized)
   {
     for (; count>0; count--, info_array++)
       (*info_array)->m_key= 0;
@@ -1421,9 +1493,9 @@ static void register_stage_v1(const char
   return;
 }
 
-static void register_statement_v1(const char *category,
-                                  PSI_statement_info_v1 *info,
-                                  int count)
+void pfs_register_statement_v1(const char *category,
+                               PSI_statement_info_v1 *info,
+                               int count)
 {
   char formatted_name[PFS_MAX_INFO_NAME_LENGTH];
   int prefix_length;
@@ -1433,7 +1505,8 @@ static void register_statement_v1(const
   DBUG_ASSERT(category != NULL);
   DBUG_ASSERT(info != NULL);
   if (unlikely(build_prefix(&statement_instrument_prefix,
-                            category, formatted_name, &prefix_length)))
+                            category, formatted_name, &prefix_length)) ||
+      ! pfs_initialized)
   {
     for (; count>0; count--, info++)
       info->m_key= 0;
@@ -1460,9 +1533,9 @@ static void register_statement_v1(const
   return;
 }
 
-static void register_socket_v1(const char *category,
-                             PSI_socket_info_v1 *info,
-                             int count)
+void pfs_register_socket_v1(const char *category,
+                            PSI_socket_info_v1 *info,
+                            int count)
 {
   REGISTER_BODY_V1(PSI_socket_key,
                    socket_instrument_prefix,
@@ -1484,8 +1557,8 @@ static void register_socket_v1(const cha
   Implementation of the mutex instrumentation interface.
   @sa PSI_v1::init_mutex.
 */
-static PSI_mutex*
-init_mutex_v1(PSI_mutex_key key, const void *identity)
+PSI_mutex*
+pfs_init_mutex_v1(PSI_mutex_key key, const void *identity)
 {
   INIT_BODY_V1(mutex, key, identity);
 }
@@ -1494,7 +1567,7 @@ init_mutex_v1(PSI_mutex_key key, const v
   Implementation of the mutex instrumentation interface.
   @sa PSI_v1::destroy_mutex.
 */
-static void destroy_mutex_v1(PSI_mutex* mutex)
+void pfs_destroy_mutex_v1(PSI_mutex* mutex)
 {
   PFS_mutex *pfs= reinterpret_cast<PFS_mutex*> (mutex);
 
@@ -1507,8 +1580,8 @@ static void destroy_mutex_v1(PSI_mutex*
   Implementation of the rwlock instrumentation interface.
   @sa PSI_v1::init_rwlock.
 */
-static PSI_rwlock*
-init_rwlock_v1(PSI_rwlock_key key, const void *identity)
+PSI_rwlock*
+pfs_init_rwlock_v1(PSI_rwlock_key key, const void *identity)
 {
   INIT_BODY_V1(rwlock, key, identity);
 }
@@ -1517,7 +1590,7 @@ init_rwlock_v1(PSI_rwlock_key key, const
   Implementation of the rwlock instrumentation interface.
   @sa PSI_v1::destroy_rwlock.
 */
-static void destroy_rwlock_v1(PSI_rwlock* rwlock)
+void pfs_destroy_rwlock_v1(PSI_rwlock* rwlock)
 {
   PFS_rwlock *pfs= reinterpret_cast<PFS_rwlock*> (rwlock);
 
@@ -1530,8 +1603,8 @@ static void destroy_rwlock_v1(PSI_rwlock
   Implementation of the cond instrumentation interface.
   @sa PSI_v1::init_cond.
 */
-static PSI_cond*
-init_cond_v1(PSI_cond_key key, const void *identity)
+PSI_cond*
+pfs_init_cond_v1(PSI_cond_key key, const void *identity)
 {
   INIT_BODY_V1(cond, key, identity);
 }
@@ -1540,7 +1613,7 @@ init_cond_v1(PSI_cond_key key, const voi
   Implementation of the cond instrumentation interface.
   @sa PSI_v1::destroy_cond.
 */
-static void destroy_cond_v1(PSI_cond* cond)
+void pfs_destroy_cond_v1(PSI_cond* cond)
 {
   PFS_cond *pfs= reinterpret_cast<PFS_cond*> (cond);
 
@@ -1553,14 +1626,14 @@ static void destroy_cond_v1(PSI_cond* co
   Implementation of the table instrumentation interface.
   @sa PSI_v1::get_table_share.
 */
-static PSI_table_share*
-get_table_share_v1(my_bool temporary, TABLE_SHARE *share)
+PSI_table_share*
+pfs_get_table_share_v1(my_bool temporary, TABLE_SHARE *share)
 {
   /* Ignore temporary tables and views. */
   if (temporary || share->is_view)
     return NULL;
   /* An instrumented thread is required, for LF_PINS. */
-  PFS_thread *pfs_thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
+  PFS_thread *pfs_thread= my_pthread_get_THR_PFS();
   if (unlikely(pfs_thread == NULL))
     return NULL;
   PFS_table_share* pfs_share;
@@ -1572,7 +1645,7 @@ get_table_share_v1(my_bool temporary, TA
   Implementation of the table instrumentation interface.
   @sa PSI_v1::release_table_share.
 */
-static void release_table_share_v1(PSI_table_share* share)
+void pfs_release_table_share_v1(PSI_table_share* share)
 {
   PFS_table_share* pfs= reinterpret_cast<PFS_table_share*> (share);
 
@@ -1586,15 +1659,15 @@ static void release_table_share_v1(PSI_t
   Implementation of the table instrumentation interface.
   @sa PSI_v1::drop_table_share.
 */
-static void
-drop_table_share_v1(my_bool temporary,
-                    const char *schema_name, int schema_name_length,
-                    const char *table_name, int table_name_length)
+void
+pfs_drop_table_share_v1(my_bool temporary,
+                        const char *schema_name, int schema_name_length,
+                        const char *table_name, int table_name_length)
 {
   /* Ignore temporary tables. */
   if (temporary)
     return;
-  PFS_thread *pfs_thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
+  PFS_thread *pfs_thread= my_pthread_get_THR_PFS();
   if (unlikely(pfs_thread == NULL))
     return;
   /* TODO: temporary tables */
@@ -1606,8 +1679,8 @@ drop_table_share_v1(my_bool temporary,
   Implementation of the table instrumentation interface.
   @sa PSI_v1::open_table.
 */
-static PSI_table*
-open_table_v1(PSI_table_share *share, const void *identity)
+PSI_table*
+pfs_open_table_v1(PSI_table_share *share, const void *identity)
 {
   PFS_table_share *pfs_table_share= reinterpret_cast<PFS_table_share*> (share);
 
@@ -1630,7 +1703,7 @@ open_table_v1(PSI_table_share *share, co
   if (! flag_global_instrumentation)
     return NULL;
 
-  PFS_thread *thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
+  PFS_thread *thread= my_pthread_get_THR_PFS();
   if (unlikely(thread == NULL))
     return NULL;
 
@@ -1642,7 +1715,7 @@ open_table_v1(PSI_table_share *share, co
   Implementation of the table instrumentation interface.
   @sa PSI_v1::unbind_table.
 */
-static void unbind_table_v1(PSI_table *table)
+void pfs_unbind_table_v1(PSI_table *table)
 {
   PFS_table *pfs= reinterpret_cast<PFS_table*> (table);
   if (likely(pfs != NULL))
@@ -1655,18 +1728,14 @@ static void unbind_table_v1(PSI_table *t
   Implementation of the table instrumentation interface.
   @sa PSI_v1::rebind_table.
 */
-static PSI_table *
-rebind_table_v1(PSI_table_share *share, const void *identity, PSI_table *table)
+PSI_table *
+pfs_rebind_table_v1(PSI_table_share *share, const void *identity, PSI_table *table)
 {
   PFS_table *pfs= reinterpret_cast<PFS_table*> (table);
   if (likely(pfs != NULL))
   {
-    PFS_thread *thread;
     DBUG_ASSERT(pfs->m_thread_owner == NULL);
 
-    /* The table handle was already instrumented, reuse it for this thread. */
-    thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
-
     if (unlikely(! pfs->m_share->m_enabled))
     {
       destroy_table(pfs);
@@ -1685,6 +1754,8 @@ rebind_table_v1(PSI_table_share *share,
       return NULL;
     }
 
+    /* The table handle was already instrumented, reuse it for this thread. */
+    PFS_thread *thread= my_pthread_get_THR_PFS();
     pfs->m_thread_owner= thread;
     return table;
   }
@@ -1705,8 +1776,7 @@ rebind_table_v1(PSI_table_share *share,
   if (! flag_global_instrumentation)
     return NULL;
 
-  PFS_thread *thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
-
+  PFS_thread *thread= my_pthread_get_THR_PFS();
   PFS_table *pfs_table= create_table(pfs_table_share, thread, identity);
   return reinterpret_cast<PSI_table *> (pfs_table);
 }
@@ -1715,7 +1785,7 @@ rebind_table_v1(PSI_table_share *share,
   Implementation of the table instrumentation interface.
   @sa PSI_v1::close_table.
 */
-static void close_table_v1(PSI_table *table)
+void pfs_close_table_v1(PSI_table *table)
 {
   PFS_table *pfs= reinterpret_cast<PFS_table*> (table);
   if (unlikely(pfs == NULL))
@@ -1724,9 +1794,9 @@ static void close_table_v1(PSI_table *ta
   destroy_table(pfs);
 }
 
-static PSI_socket*
-init_socket_v1(PSI_socket_key key, const my_socket *fd,
-               const struct sockaddr *addr, socklen_t addr_len)
+PSI_socket*
+pfs_init_socket_v1(PSI_socket_key key, const my_socket *fd,
+                   const struct sockaddr *addr, socklen_t addr_len)
 {
   PFS_socket_class *klass;
   PFS_socket *pfs;
@@ -1739,7 +1809,7 @@ init_socket_v1(PSI_socket_key key, const
   return reinterpret_cast<PSI_socket *> (pfs);
 }
 
-static void destroy_socket_v1(PSI_socket *socket)
+void pfs_destroy_socket_v1(PSI_socket *socket)
 {
   PFS_socket *pfs= reinterpret_cast<PFS_socket*> (socket);
 
@@ -1752,7 +1822,7 @@ static void destroy_socket_v1(PSI_socket
   Implementation of the file instrumentation interface.
   @sa PSI_v1::create_file.
 */
-static void create_file_v1(PSI_file_key key, const char *name, File file)
+void pfs_create_file_v1(PSI_file_key key, const char *name, File file)
 {
   if (! flag_global_instrumentation)
     return;
@@ -1766,7 +1836,7 @@ static void create_file_v1(PSI_file_key
     return;
 
   /* A thread is needed for LF_PINS */
-  PFS_thread *pfs_thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
+  PFS_thread *pfs_thread= my_pthread_get_THR_PFS();
   if (unlikely(pfs_thread == NULL))
     return;
 
@@ -1837,7 +1907,7 @@ void* pfs_spawn_thread(void *arg)
   {
     pfs= NULL;
   }
-  my_pthread_setspecific_ptr(THR_PFS, pfs);
+  my_pthread_set_THR_PFS(pfs);
 
   /*
     Secondly, free the memory allocated in spawn_thread_v1().
@@ -1859,9 +1929,9 @@ void* pfs_spawn_thread(void *arg)
   Implementation of the thread instrumentation interface.
   @sa PSI_v1::spawn_thread.
 */
-static int spawn_thread_v1(PSI_thread_key key,
-                           pthread_t *thread, const pthread_attr_t *attr,
-                           void *(*start_routine)(void*), void *arg)
+int pfs_spawn_thread_v1(PSI_thread_key key,
+                        pthread_t *thread, const pthread_attr_t *attr,
+                        void *(*start_routine)(void*), void *arg)
 {
   PFS_spawn_thread_arg *psi_arg;
 
@@ -1871,7 +1941,7 @@ static int spawn_thread_v1(PSI_thread_ke
   if (unlikely(psi_arg == NULL))
     return EAGAIN;
 
-  psi_arg->m_parent_thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
+  psi_arg->m_parent_thread= my_pthread_get_THR_PFS();
   psi_arg->m_child_key= key;
   psi_arg->m_child_identity= (arg ? arg : thread);
   psi_arg->m_user_start_routine= start_routine;
@@ -1887,8 +1957,8 @@ static int spawn_thread_v1(PSI_thread_ke
   Implementation of the thread instrumentation interface.
   @sa PSI_v1::new_thread.
 */
-static PSI_thread*
-new_thread_v1(PSI_thread_key key, const void *identity, ulong thread_id)
+PSI_thread*
+pfs_new_thread_v1(PSI_thread_key key, const void *identity, ulong thread_id)
 {
   PFS_thread *pfs;
 
@@ -1905,7 +1975,7 @@ new_thread_v1(PSI_thread_key key, const
   Implementation of the thread instrumentation interface.
   @sa PSI_v1::set_thread_id.
 */
-static void set_thread_id_v1(PSI_thread *thread, unsigned long id)
+void pfs_set_thread_id_v1(PSI_thread *thread, unsigned long id)
 {
   PFS_thread *pfs= reinterpret_cast<PFS_thread*> (thread);
   if (unlikely(pfs == NULL))
@@ -1917,10 +1987,10 @@ static void set_thread_id_v1(PSI_thread
   Implementation of the thread instrumentation interface.
   @sa PSI_v1::get_thread_id.
 */
-static PSI_thread*
-get_thread_v1(void)
+PSI_thread*
+pfs_get_thread_v1(void)
 {
-  PFS_thread *pfs= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
+  PFS_thread *pfs= my_pthread_get_THR_PFS();
   return reinterpret_cast<PSI_thread*> (pfs);
 }
 
@@ -1928,9 +1998,9 @@ get_thread_v1(void)
   Implementation of the thread instrumentation interface.
   @sa PSI_v1::set_thread_user.
 */
-static void set_thread_user_v1(const char *user, int user_len)
+void pfs_set_thread_user_v1(const char *user, int user_len)
 {
-  PFS_thread *pfs= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
+  PFS_thread *pfs= my_pthread_get_THR_PFS();
 
   DBUG_ASSERT((user != NULL) || (user_len == 0));
   DBUG_ASSERT(user_len >= 0);
@@ -1978,10 +2048,10 @@ static void set_thread_user_v1(const cha
   Implementation of the thread instrumentation interface.
   @sa PSI_v1::set_thread_account.
 */
-static void set_thread_account_v1(const char *user, int user_len,
-                                    const char *host, int host_len)
+void pfs_set_thread_account_v1(const char *user, int user_len,
+                               const char *host, int host_len)
 {
-  PFS_thread *pfs= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
+  PFS_thread *pfs= my_pthread_get_THR_PFS();
 
   DBUG_ASSERT((user != NULL) || (user_len == 0));
   DBUG_ASSERT(user_len >= 0);
@@ -2033,9 +2103,9 @@ static void set_thread_account_v1(const
   Implementation of the thread instrumentation interface.
   @sa PSI_v1::set_thread_db.
 */
-static void set_thread_db_v1(const char* db, int db_len)
+void pfs_set_thread_db_v1(const char* db, int db_len)
 {
-  PFS_thread *pfs= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
+  PFS_thread *pfs= my_pthread_get_THR_PFS();
 
   DBUG_ASSERT((db != NULL) || (db_len == 0));
   DBUG_ASSERT(db_len >= 0);
@@ -2055,9 +2125,9 @@ static void set_thread_db_v1(const char*
   Implementation of the thread instrumentation interface.
   @sa PSI_v1::set_thread_command.
 */
-static void set_thread_command_v1(int command)
+void pfs_set_thread_command_v1(int command)
 {
-  PFS_thread *pfs= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
+  PFS_thread *pfs= my_pthread_get_THR_PFS();
 
   DBUG_ASSERT(command >= 0);
   DBUG_ASSERT(command <= (int) COM_END);
@@ -2074,9 +2144,9 @@ static void set_thread_command_v1(int co
   Implementation of the thread instrumentation interface.
   @sa PSI_v1::set_thread_start_time.
 */
-static void set_thread_start_time_v1(time_t start_time)
+void pfs_set_thread_start_time_v1(time_t start_time)
 {
-  PFS_thread *pfs= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
+  PFS_thread *pfs= my_pthread_get_THR_PFS();
 
   if (likely(pfs != NULL))
   {
@@ -2090,9 +2160,9 @@ static void set_thread_start_time_v1(tim
   Implementation of the thread instrumentation interface.
   @sa PSI_v1::set_thread_state.
 */
-static void set_thread_state_v1(const char* state)
+void pfs_set_thread_state_v1(const char* state)
 {
-  PFS_thread *pfs= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
+  PFS_thread *pfs= my_pthread_get_THR_PFS();
 
   if (likely(pfs != NULL))
   {
@@ -2109,9 +2179,9 @@ static void set_thread_state_v1(const ch
   Implementation of the thread instrumentation interface.
   @sa PSI_v1::set_thread_info.
 */
-static void set_thread_info_v1(const char* info, int info_len)
+void pfs_set_thread_info_v1(const char* info, int info_len)
 {
-  PFS_thread *pfs= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
+  PFS_thread *pfs= my_pthread_get_THR_PFS();
 
   if (likely(pfs != NULL))
   {
@@ -2126,19 +2196,19 @@ static void set_thread_info_v1(const cha
   Implementation of the thread instrumentation interface.
   @sa PSI_v1::set_thread.
 */
-static void set_thread_v1(PSI_thread* thread)
+void pfs_set_thread_v1(PSI_thread* thread)
 {
   PFS_thread *pfs= reinterpret_cast<PFS_thread*> (thread);
-  my_pthread_setspecific_ptr(THR_PFS, pfs);
+  my_pthread_set_THR_PFS(pfs);
 }
 
 /**
   Implementation of the thread instrumentation interface.
   @sa PSI_v1::delete_current_thread.
 */
-static void delete_current_thread_v1(void)
+void pfs_delete_current_thread_v1(void)
 {
-  PFS_thread *thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
+  PFS_thread *thread= my_pthread_get_THR_PFS();
   if (thread != NULL)
   {
     aggregate_thread(thread);
@@ -2151,7 +2221,7 @@ static void delete_current_thread_v1(voi
   Implementation of the thread instrumentation interface.
   @sa PSI_v1::delete_thread.
 */
-static void delete_thread_v1(PSI_thread *thread)
+void pfs_delete_thread_v1(PSI_thread *thread)
 {
   PFS_thread *pfs= reinterpret_cast<PFS_thread*> (thread);
 
@@ -2166,10 +2236,10 @@ static void delete_thread_v1(PSI_thread
   Implementation of the mutex instrumentation interface.
   @sa PSI_v1::start_mutex_wait.
 */
-static PSI_mutex_locker*
-start_mutex_wait_v1(PSI_mutex_locker_state *state,
-                    PSI_mutex *mutex, PSI_mutex_operation op,
-                    const char *src_file, uint src_line)
+PSI_mutex_locker*
+pfs_start_mutex_wait_v1(PSI_mutex_locker_state *state,
+                        PSI_mutex *mutex, PSI_mutex_operation op,
+                        const char *src_file, uint src_line)
 {
   PFS_mutex *pfs_mutex= reinterpret_cast<PFS_mutex*> (mutex);
   DBUG_ASSERT((int) op >= 0);
@@ -2187,7 +2257,7 @@ start_mutex_wait_v1(PSI_mutex_locker_sta
 
   if (flag_thread_instrumentation)
   {
-    PFS_thread *pfs_thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
+    PFS_thread *pfs_thread= my_pthread_get_THR_PFS();
     if (unlikely(pfs_thread == NULL))
       return NULL;
     if (! pfs_thread->m_enabled)
@@ -2264,11 +2334,11 @@ start_mutex_wait_v1(PSI_mutex_locker_sta
   @sa PSI_v1::start_rwlock_rdwait
   @sa PSI_v1::start_rwlock_wrwait
 */
-static PSI_rwlock_locker*
-start_rwlock_wait_v1(PSI_rwlock_locker_state *state,
-                     PSI_rwlock *rwlock,
-                     PSI_rwlock_operation op,
-                     const char *src_file, uint src_line)
+PSI_rwlock_locker*
+pfs_start_rwlock_rdwait_v1(PSI_rwlock_locker_state *state,
+                           PSI_rwlock *rwlock,
+                           PSI_rwlock_operation op,
+                           const char *src_file, uint src_line)
 {
   PFS_rwlock *pfs_rwlock= reinterpret_cast<PFS_rwlock*> (rwlock);
   DBUG_ASSERT(static_cast<int> (op) >= 0);
@@ -2285,7 +2355,7 @@ start_rwlock_wait_v1(PSI_rwlock_locker_s
 
   if (flag_thread_instrumentation)
   {
-    PFS_thread *pfs_thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
+    PFS_thread *pfs_thread= my_pthread_get_THR_PFS();
     if (unlikely(pfs_thread == NULL))
       return NULL;
     if (! pfs_thread->m_enabled)
@@ -2357,15 +2427,24 @@ start_rwlock_wait_v1(PSI_rwlock_locker_s
   return reinterpret_cast<PSI_rwlock_locker*> (state);
 }
 
+PSI_rwlock_locker*
+pfs_start_rwlock_wrwait_v1(PSI_rwlock_locker_state *state,
+                           PSI_rwlock *rwlock,
+                           PSI_rwlock_operation op,
+                           const char *src_file, uint src_line)
+{
+  return pfs_start_rwlock_rdwait_v1(state, rwlock, op, src_file, src_line);
+}
+
 /**
   Implementation of the cond instrumentation interface.
   @sa PSI_v1::start_cond_wait.
 */
-static PSI_cond_locker*
-start_cond_wait_v1(PSI_cond_locker_state *state,
-                   PSI_cond *cond, PSI_mutex *mutex,
-                   PSI_cond_operation op,
-                   const char *src_file, uint src_line)
+PSI_cond_locker*
+pfs_start_cond_wait_v1(PSI_cond_locker_state *state,
+                       PSI_cond *cond, PSI_mutex *mutex,
+                       PSI_cond_operation op,
+                       const char *src_file, uint src_line)
 {
   /*
     Note about the unused PSI_mutex *mutex parameter:
@@ -2393,7 +2472,7 @@ start_cond_wait_v1(PSI_cond_locker_state
 
   if (flag_thread_instrumentation)
   {
-    PFS_thread *pfs_thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
+    PFS_thread *pfs_thread= my_pthread_get_THR_PFS();
     if (unlikely(pfs_thread == NULL))
       return NULL;
     if (! pfs_thread->m_enabled)
@@ -2513,12 +2592,12 @@ static inline PFS_TL_LOCK_TYPE external_
   Implementation of the table instrumentation interface.
   @sa PSI_v1::start_table_io_wait_v1
 */
-static PSI_table_locker*
-start_table_io_wait_v1(PSI_table_locker_state *state,
-                       PSI_table *table,
-                       PSI_table_io_operation op,
-                       uint index,
-                       const char *src_file, uint src_line)
+PSI_table_locker*
+pfs_start_table_io_wait_v1(PSI_table_locker_state *state,
+                           PSI_table *table,
+                           PSI_table_io_operation op,
+                           uint index,
+                           const char *src_file, uint src_line)
 {
   DBUG_ASSERT(static_cast<int> (op) >= 0);
   DBUG_ASSERT(static_cast<uint> (op) < array_elements(table_io_operation_map));
@@ -2532,8 +2611,7 @@ start_table_io_wait_v1(PSI_table_locker_
 
   PFS_thread *pfs_thread= pfs_table->m_thread_owner;
 
-  DBUG_ASSERT(pfs_thread ==
-              my_pthread_getspecific_ptr(PFS_thread*, THR_PFS));
+  DBUG_ASSERT(pfs_thread == my_pthread_get_THR_PFS());
 
   register uint flags;
   ulonglong timer_start= 0;
@@ -2618,12 +2696,12 @@ start_table_io_wait_v1(PSI_table_locker_
   Implementation of the table instrumentation interface.
   @sa PSI_v1::start_table_lock_wait.
 */
-static PSI_table_locker*
-start_table_lock_wait_v1(PSI_table_locker_state *state,
-                         PSI_table *table,
-                         PSI_table_lock_operation op,
-                         ulong op_flags,
-                         const char *src_file, uint src_line)
+PSI_table_locker*
+pfs_start_table_lock_wait_v1(PSI_table_locker_state *state,
+                             PSI_table *table,
+                             PSI_table_lock_operation op,
+                             ulong op_flags,
+                             const char *src_file, uint src_line)
 {
   DBUG_ASSERT(state != NULL);
   DBUG_ASSERT((op == PSI_TABLE_LOCK) || (op == PSI_TABLE_EXTERNAL_LOCK));
@@ -2743,11 +2821,11 @@ start_table_lock_wait_v1(PSI_table_locke
   Implementation of the file instrumentation interface.
   @sa PSI_v1::get_thread_file_name_locker.
 */
-static PSI_file_locker*
-get_thread_file_name_locker_v1(PSI_file_locker_state *state,
-                               PSI_file_key key,
-                               PSI_file_operation op,
-                               const char *name, const void *identity)
+PSI_file_locker*
+pfs_get_thread_file_name_locker_v1(PSI_file_locker_state *state,
+                                   PSI_file_key key,
+                                   PSI_file_operation op,
+                                   const char *name, const void *identity)
 {
   DBUG_ASSERT(static_cast<int> (op) >= 0);
   DBUG_ASSERT(static_cast<uint> (op) < array_elements(file_operation_map));
@@ -2761,8 +2839,8 @@ get_thread_file_name_locker_v1(PSI_file_
   if (! klass->m_enabled)
     return NULL;
 
-  /* Needed for the LF_HASH */
-  PFS_thread *pfs_thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
+  /* Needed for the LF_HASH */ 
+  PFS_thread *pfs_thread= my_pthread_get_THR_PFS();
   if (unlikely(pfs_thread == NULL))
     return NULL;
 
@@ -2821,9 +2899,9 @@ get_thread_file_name_locker_v1(PSI_file_
   Implementation of the file instrumentation interface.
   @sa PSI_v1::get_thread_file_stream_locker.
 */
-static PSI_file_locker*
-get_thread_file_stream_locker_v1(PSI_file_locker_state *state,
-                                 PSI_file *file, PSI_file_operation op)
+PSI_file_locker*
+pfs_get_thread_file_stream_locker_v1(PSI_file_locker_state *state,
+                                     PSI_file *file, PSI_file_operation op)
 {
   PFS_file *pfs_file= reinterpret_cast<PFS_file*> (file);
   DBUG_ASSERT(static_cast<int> (op) >= 0);
@@ -2842,7 +2920,7 @@ get_thread_file_stream_locker_v1(PSI_fil
 
   if (flag_thread_instrumentation)
   {
-    PFS_thread *pfs_thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
+    PFS_thread *pfs_thread= my_pthread_get_THR_PFS();
     if (unlikely(pfs_thread == NULL))
       return NULL;
     if (! pfs_thread->m_enabled)
@@ -2911,9 +2989,9 @@ get_thread_file_stream_locker_v1(PSI_fil
   Implementation of the file instrumentation interface.
   @sa PSI_v1::get_thread_file_descriptor_locker.
 */
-static PSI_file_locker*
-get_thread_file_descriptor_locker_v1(PSI_file_locker_state *state,
-                                     File file, PSI_file_operation op)
+PSI_file_locker*
+pfs_get_thread_file_descriptor_locker_v1(PSI_file_locker_state *state,
+                                         File file, PSI_file_operation op)
 {
   int index= static_cast<int> (file);
   DBUG_ASSERT(static_cast<int> (op) >= 0);
@@ -2948,7 +3026,7 @@ get_thread_file_descriptor_locker_v1(PSI
 
   if (flag_thread_instrumentation)
   {
-    PFS_thread *pfs_thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
+    PFS_thread *pfs_thread= my_pthread_get_THR_PFS();
     if (unlikely(pfs_thread == NULL))
       return NULL;
     if (! pfs_thread->m_enabled)
@@ -3015,12 +3093,12 @@ get_thread_file_descriptor_locker_v1(PSI
 
 /** Socket locker */
 
-static PSI_socket_locker*
-start_socket_wait_v1(PSI_socket_locker_state *state,
-                     PSI_socket *socket,
-                     PSI_socket_operation op,
-                     size_t count,
-                     const char *src_file, uint src_line)
+PSI_socket_locker*
+pfs_start_socket_wait_v1(PSI_socket_locker_state *state,
+                         PSI_socket *socket,
+                         PSI_socket_operation op,
+                         size_t count,
+                         const char *src_file, uint src_line)
 {
   DBUG_ASSERT(static_cast<int> (op) >= 0);
   DBUG_ASSERT(static_cast<uint> (op) < array_elements(socket_operation_map));
@@ -3135,7 +3213,7 @@ start_socket_wait_v1(PSI_socket_locker_s
   Implementation of the mutex instrumentation interface.
   @sa PSI_v1::unlock_mutex.
 */
-static void unlock_mutex_v1(PSI_mutex *mutex)
+void pfs_unlock_mutex_v1(PSI_mutex *mutex)
 {
   PFS_mutex *pfs_mutex= reinterpret_cast<PFS_mutex*> (mutex);
 
@@ -3172,7 +3250,7 @@ static void unlock_mutex_v1(PSI_mutex *m
   Implementation of the rwlock instrumentation interface.
   @sa PSI_v1::unlock_rwlock.
 */
-static void unlock_rwlock_v1(PSI_rwlock *rwlock)
+void pfs_unlock_rwlock_v1(PSI_rwlock *rwlock)
 {
   PFS_rwlock *pfs_rwlock= reinterpret_cast<PFS_rwlock*> (rwlock);
   DBUG_ASSERT(pfs_rwlock != NULL);
@@ -3250,7 +3328,7 @@ static void unlock_rwlock_v1(PSI_rwlock
   Implementation of the cond instrumentation interface.
   @sa PSI_v1::signal_cond.
 */
-static void signal_cond_v1(PSI_cond* cond)
+void pfs_signal_cond_v1(PSI_cond* cond)
 {
   PFS_cond *pfs_cond= reinterpret_cast<PFS_cond*> (cond);
 
@@ -3263,7 +3341,7 @@ static void signal_cond_v1(PSI_cond* con
   Implementation of the cond instrumentation interface.
   @sa PSI_v1::broadcast_cond.
 */
-static void broadcast_cond_v1(PSI_cond* cond)
+void pfs_broadcast_cond_v1(PSI_cond* cond)
 {
   PFS_cond *pfs_cond= reinterpret_cast<PFS_cond*> (cond);
 
@@ -3276,8 +3354,8 @@ static void broadcast_cond_v1(PSI_cond*
   Implementation of the idle instrumentation interface.
   @sa PSI_v1::start_idle_wait.
 */
-static PSI_idle_locker*
-start_idle_wait_v1(PSI_idle_locker_state* state, const char *src_file, uint src_line)
+PSI_idle_locker*
+pfs_start_idle_wait_v1(PSI_idle_locker_state* state, const char *src_file, uint src_line)
 {
   DBUG_ASSERT(state != NULL);
 
@@ -3292,7 +3370,7 @@ start_idle_wait_v1(PSI_idle_locker_state
 
   if (flag_thread_instrumentation)
   {
-    PFS_thread *pfs_thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
+    PFS_thread *pfs_thread= my_pthread_get_THR_PFS();
     if (unlikely(pfs_thread == NULL))
       return NULL;
     if (!pfs_thread->m_enabled)
@@ -3360,7 +3438,7 @@ start_idle_wait_v1(PSI_idle_locker_state
   Implementation of the mutex instrumentation interface.
   @sa PSI_v1::end_idle_wait.
 */
-static void end_idle_wait_v1(PSI_idle_locker* locker)
+void pfs_end_idle_wait_v1(PSI_idle_locker* locker)
 {
   PSI_idle_locker_state *state= reinterpret_cast<PSI_idle_locker_state*> (locker);
   DBUG_ASSERT(state != NULL);
@@ -3423,7 +3501,7 @@ static void end_idle_wait_v1(PSI_idle_lo
   Implementation of the mutex instrumentation interface.
   @sa PSI_v1::end_mutex_wait.
 */
-static void end_mutex_wait_v1(PSI_mutex_locker* locker, int rc)
+void pfs_end_mutex_wait_v1(PSI_mutex_locker* locker, int rc)
 {
   PSI_mutex_locker_state *state= reinterpret_cast<PSI_mutex_locker_state*> (locker);
   DBUG_ASSERT(state != NULL);
@@ -3493,7 +3571,7 @@ static void end_mutex_wait_v1(PSI_mutex_
   Implementation of the rwlock instrumentation interface.
   @sa PSI_v1::end_rwlock_rdwait.
 */
-static void end_rwlock_rdwait_v1(PSI_rwlock_locker* locker, int rc)
+void pfs_end_rwlock_rdwait_v1(PSI_rwlock_locker* locker, int rc)
 {
   PSI_rwlock_locker_state *state= reinterpret_cast<PSI_rwlock_locker_state*> (locker);
   DBUG_ASSERT(state != NULL);
@@ -3572,7 +3650,7 @@ static void end_rwlock_rdwait_v1(PSI_rwl
   Implementation of the rwlock instrumentation interface.
   @sa PSI_v1::end_rwlock_wrwait.
 */
-static void end_rwlock_wrwait_v1(PSI_rwlock_locker* locker, int rc)
+void pfs_end_rwlock_wrwait_v1(PSI_rwlock_locker* locker, int rc)
 {
   PSI_rwlock_locker_state *state= reinterpret_cast<PSI_rwlock_locker_state*> (locker);
   DBUG_ASSERT(state != NULL);
@@ -3644,7 +3722,7 @@ static void end_rwlock_wrwait_v1(PSI_rwl
   Implementation of the cond instrumentation interface.
   @sa PSI_v1::end_cond_wait.
 */
-static void end_cond_wait_v1(PSI_cond_locker* locker, int rc)
+void pfs_end_cond_wait_v1(PSI_cond_locker* locker, int rc)
 {
   PSI_cond_locker_state *state= reinterpret_cast<PSI_cond_locker_state*> (locker);
   DBUG_ASSERT(state != NULL);
@@ -3708,7 +3786,7 @@ static void end_cond_wait_v1(PSI_cond_lo
   Implementation of the table instrumentation interface.
   @sa PSI_v1::end_table_io_wait.
 */
-static void end_table_io_wait_v1(PSI_table_locker* locker)
+void pfs_end_table_io_wait_v1(PSI_table_locker* locker)
 {
   PSI_table_locker_state *state= reinterpret_cast<PSI_table_locker_state*> (locker);
   DBUG_ASSERT(state != NULL);
@@ -3804,7 +3882,7 @@ static void end_table_io_wait_v1(PSI_tab
   Implementation of the table instrumentation interface.
   @sa PSI_v1::end_table_lock_wait.
 */
-static void end_table_lock_wait_v1(PSI_table_locker* locker)
+void pfs_end_table_lock_wait_v1(PSI_table_locker* locker)
 {
   PSI_table_locker_state *state= reinterpret_cast<PSI_table_locker_state*> (locker);
   DBUG_ASSERT(state != NULL);
@@ -3869,23 +3947,23 @@ static void end_table_lock_wait_v1(PSI_t
   table->m_has_lock_stats= true;
 }
 
-static void start_file_wait_v1(PSI_file_locker *locker,
-                               size_t count,
-                               const char *src_file,
-                               uint src_line);
+void pfs_start_file_wait_v1(PSI_file_locker *locker,
+                            size_t count,
+                            const char *src_file,
+                            uint src_line);
 
-static void end_file_wait_v1(PSI_file_locker *locker,
-                             size_t count);
+void pfs_end_file_wait_v1(PSI_file_locker *locker,
+                          size_t count);
 
 /**
   Implementation of the file instrumentation interface.
   @sa PSI_v1::start_file_open_wait.
 */
-static void start_file_open_wait_v1(PSI_file_locker *locker,
-                                    const char *src_file,
-                                    uint src_line)
+void pfs_start_file_open_wait_v1(PSI_file_locker *locker,
+                                 const char *src_file,
+                                 uint src_line)
 {
-  start_file_wait_v1(locker, 0, src_file, src_line);
+  pfs_start_file_wait_v1(locker, 0, src_file, src_line);
 
   return;
 }
@@ -3894,8 +3972,9 @@ static void start_file_open_wait_v1(PSI_
   Implementation of the file instrumentation interface.
   @sa PSI_v1::end_file_open_wait.
 */
-static PSI_file* end_file_open_wait_v1(PSI_file_locker *locker,
-                                       void *result)
+PSI_file*
+pfs_end_file_open_wait_v1(PSI_file_locker *locker,
+                          void *result)
 {
   PSI_file_locker_state *state= reinterpret_cast<PSI_file_locker_state*> (locker);
   DBUG_ASSERT(state != NULL);
@@ -3922,7 +4001,7 @@ static PSI_file* end_file_open_wait_v1(P
     break;
   }
 
-  end_file_wait_v1(locker, 0);
+  pfs_end_file_wait_v1(locker, 0);
 
   return state->m_file;
 }
@@ -3931,7 +4010,7 @@ static PSI_file* end_file_open_wait_v1(P
   Implementation of the file instrumentation interface.
   @sa PSI_v1::end_file_open_wait_and_bind_to_descriptor.
 */
-static void end_file_open_wait_and_bind_to_descriptor_v1
+void pfs_end_file_open_wait_and_bind_to_descriptor_v1
   (PSI_file_locker *locker, File file)
 {
   PFS_file *pfs_file= NULL;
@@ -3949,7 +4028,7 @@ static void end_file_open_wait_and_bind_
     state->m_file= reinterpret_cast<PSI_file*> (pfs_file);
   }
 
-  end_file_wait_v1(locker, 0);
+  pfs_end_file_wait_v1(locker, 0);
 
   if (likely(index >= 0))
   {
@@ -3967,10 +4046,10 @@ static void end_file_open_wait_and_bind_
   Implementation of the file instrumentation interface.
   @sa PSI_v1::start_file_wait.
 */
-static void start_file_wait_v1(PSI_file_locker *locker,
-                               size_t count,
-                               const char *src_file,
-                               uint src_line)
+void pfs_start_file_wait_v1(PSI_file_locker *locker,
+                            size_t count,
+                            const char *src_file,
+                            uint src_line)
 {
   ulonglong timer_start= 0;
   PSI_file_locker_state *state= reinterpret_cast<PSI_file_locker_state*> (locker);
@@ -4000,8 +4079,8 @@ static void start_file_wait_v1(PSI_file_
   Implementation of the file instrumentation interface.
   @sa PSI_v1::end_file_wait.
 */
-static void end_file_wait_v1(PSI_file_locker *locker,
-                             size_t byte_count)
+void pfs_end_file_wait_v1(PSI_file_locker *locker,
+                          size_t byte_count)
 {
   PSI_file_locker_state *state= reinterpret_cast<PSI_file_locker_state*> (locker);
   DBUG_ASSERT(state != NULL);
@@ -4118,9 +4197,9 @@ static void end_file_wait_v1(PSI_file_lo
   Implementation of the file instrumentation interface.
   @sa PSI_v1::start_file_close_wait.
 */
-static void start_file_close_wait_v1(PSI_file_locker *locker,
-                                     const char *src_file,
-                                     uint src_line)
+void pfs_start_file_close_wait_v1(PSI_file_locker *locker,
+                                  const char *src_file,
+                                  uint src_line)
 {
   PFS_thread *thread;
   const char *name;
@@ -4146,7 +4225,7 @@ static void start_file_close_wait_v1(PSI
     break;
   }
 
-  start_file_wait_v1(locker, 0, src_file, src_line);
+  pfs_start_file_wait_v1(locker, 0, src_file, src_line);
 
   return;
 }
@@ -4155,12 +4234,12 @@ static void start_file_close_wait_v1(PSI
   Implementation of the file instrumentation interface.
   @sa PSI_v1::end_file_close_wait.
 */
-static void end_file_close_wait_v1(PSI_file_locker *locker, int rc)
+void pfs_end_file_close_wait_v1(PSI_file_locker *locker, int rc)
 {
   PSI_file_locker_state *state= reinterpret_cast<PSI_file_locker_state*> (locker);
   DBUG_ASSERT(state != NULL);
 
-  end_file_wait_v1(locker, 0);
+  pfs_end_file_wait_v1(locker, 0);
 
   if (rc == 0)
   {
@@ -4187,14 +4266,14 @@ static void end_file_close_wait_v1(PSI_f
   return;
 }
 
-static void start_stage_v1(PSI_stage_key key, const char *src_file, int src_line)
+void pfs_start_stage_v1(PSI_stage_key key, const char *src_file, int src_line)
 {
   ulonglong timer_value= 0;
 
   if (! flag_global_instrumentation)
     return;
 
-  PFS_thread *pfs_thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
+  PFS_thread *pfs_thread= my_pthread_get_THR_PFS();
   if (unlikely(pfs_thread == NULL))
     return;
 
@@ -4285,14 +4364,14 @@ static void start_stage_v1(PSI_stage_key
   }
 }
 
-static void end_stage_v1()
+void pfs_end_stage_v1()
 {
   ulonglong timer_value= 0;
 
   if (! flag_global_instrumentation)
     return;
 
-  PFS_thread *pfs_thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
+  PFS_thread *pfs_thread= my_pthread_get_THR_PFS();
   if (unlikely(pfs_thread == NULL))
     return;
 
@@ -4344,10 +4423,10 @@ static void end_stage_v1()
   }
 }
 
-static PSI_statement_locker*
-get_thread_statement_locker_v1(PSI_statement_locker_state *state,
-                               PSI_statement_key key,
-                               const void *charset)
+PSI_statement_locker*
+pfs_get_thread_statement_locker_v1(PSI_statement_locker_state *state,
+                                   PSI_statement_key key,
+                                   const void *charset)
 {
   DBUG_ASSERT(state != NULL);
   if (! flag_global_instrumentation)
@@ -4362,7 +4441,7 @@ get_thread_statement_locker_v1(PSI_state
 
   if (flag_thread_instrumentation)
   {
-    PFS_thread *pfs_thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
+    PFS_thread *pfs_thread= my_pthread_get_THR_PFS();
     if (unlikely(pfs_thread == NULL))
       return NULL;
     if (! pfs_thread->m_enabled)
@@ -4475,9 +4554,9 @@ get_thread_statement_locker_v1(PSI_state
   return reinterpret_cast<PSI_statement_locker*> (state);
 }
 
-static PSI_statement_locker*
-refine_statement_v1(PSI_statement_locker *locker,
-                    PSI_statement_key key)
+PSI_statement_locker*
+pfs_refine_statement_v1(PSI_statement_locker *locker,
+                        PSI_statement_key key)
 {
   PSI_statement_locker_state *state= reinterpret_cast<PSI_statement_locker_state*> (locker);
   if (state == NULL)
@@ -4520,9 +4599,9 @@ refine_statement_v1(PSI_statement_locker
   return reinterpret_cast<PSI_statement_locker*> (state);
 }
 
-static void start_statement_v1(PSI_statement_locker *locker,
-                               const char *db, uint db_len,
-                               const char *src_file, uint src_line)
+void pfs_start_statement_v1(PSI_statement_locker *locker,
+                            const char *db, uint db_len,
+                            const char *src_file, uint src_line)
 {
   PSI_statement_locker_state *state= reinterpret_cast<PSI_statement_locker_state*> (locker);
   DBUG_ASSERT(state != NULL);
@@ -4552,8 +4631,8 @@ static void start_statement_v1(PSI_state
   }
 }
 
-static void set_statement_text_v1(PSI_statement_locker *locker,
-                                  const char *text, uint text_len)
+void pfs_set_statement_text_v1(PSI_statement_locker *locker,
+                               const char *text, uint text_len)
 {
   PSI_statement_locker_state *state= reinterpret_cast<PSI_statement_locker_state*> (locker);
   DBUG_ASSERT(state != NULL);
@@ -4609,101 +4688,101 @@ static void set_statement_text_v1(PSI_st
   }                                                                     \
   return;
 
-static void set_statement_lock_time_v1(PSI_statement_locker *locker,
-                                       ulonglong count)
+void pfs_set_statement_lock_time_v1(PSI_statement_locker *locker,
+                                    ulonglong count)
 {
   SET_STATEMENT_ATTR_BODY(locker, m_lock_time, count);
 }
 
-static void set_statement_rows_sent_v1(PSI_statement_locker *locker,
-                                       ulonglong count)
+void pfs_set_statement_rows_sent_v1(PSI_statement_locker *locker,
+                                    ulonglong count)
 {
   SET_STATEMENT_ATTR_BODY(locker, m_rows_sent, count);
 }
 
-static void set_statement_rows_examined_v1(PSI_statement_locker *locker,
-                                           ulonglong count)
+void pfs_set_statement_rows_examined_v1(PSI_statement_locker *locker,
+                                        ulonglong count)
 {
   SET_STATEMENT_ATTR_BODY(locker, m_rows_examined, count);
 }
 
-static void inc_statement_created_tmp_disk_tables_v1(PSI_statement_locker *locker,
-                                                    ulong count)
+void pfs_inc_statement_created_tmp_disk_tables_v1(PSI_statement_locker *locker,
+                                                  ulong count)
 {
   INC_STATEMENT_ATTR_BODY(locker, m_created_tmp_disk_tables, count);
 }
 
-static void inc_statement_created_tmp_tables_v1(PSI_statement_locker *locker,
-                                                ulong count)
+void pfs_inc_statement_created_tmp_tables_v1(PSI_statement_locker *locker,
+                                             ulong count)
 {
   INC_STATEMENT_ATTR_BODY(locker, m_created_tmp_tables, count);
 }
 
-static void inc_statement_select_full_join_v1(PSI_statement_locker *locker,
-                                              ulong count)
+void pfs_inc_statement_select_full_join_v1(PSI_statement_locker *locker,
+                                           ulong count)
 {
   INC_STATEMENT_ATTR_BODY(locker, m_select_full_join, count);
 }
 
-static void inc_statement_select_full_range_join_v1(PSI_statement_locker *locker,
-                                                    ulong count)
+void pfs_inc_statement_select_full_range_join_v1(PSI_statement_locker *locker,
+                                                 ulong count)
 {
   INC_STATEMENT_ATTR_BODY(locker, m_select_full_range_join, count);
 }
 
-static void inc_statement_select_range_v1(PSI_statement_locker *locker,
-                                          ulong count)
+void pfs_inc_statement_select_range_v1(PSI_statement_locker *locker,
+                                       ulong count)
 {
   INC_STATEMENT_ATTR_BODY(locker, m_select_range, count);
 }
 
-static void inc_statement_select_range_check_v1(PSI_statement_locker *locker,
-                                                ulong count)
+void pfs_inc_statement_select_range_check_v1(PSI_statement_locker *locker,
+                                             ulong count)
 {
   INC_STATEMENT_ATTR_BODY(locker, m_select_range_check, count);
 }
 
-static void inc_statement_select_scan_v1(PSI_statement_locker *locker,
-                                         ulong count)
+void pfs_inc_statement_select_scan_v1(PSI_statement_locker *locker,
+                                      ulong count)
 {
   INC_STATEMENT_ATTR_BODY(locker, m_select_scan, count);
 }
 
-static void inc_statement_sort_merge_passes_v1(PSI_statement_locker *locker,
-                                               ulong count)
+void pfs_inc_statement_sort_merge_passes_v1(PSI_statement_locker *locker,
+                                            ulong count)
 {
   INC_STATEMENT_ATTR_BODY(locker, m_sort_merge_passes, count);
 }
 
-static void inc_statement_sort_range_v1(PSI_statement_locker *locker,
-                                        ulong count)
+void pfs_inc_statement_sort_range_v1(PSI_statement_locker *locker,
+                                     ulong count)
 {
   INC_STATEMENT_ATTR_BODY(locker, m_sort_range, count);
 }
 
-static void inc_statement_sort_rows_v1(PSI_statement_locker *locker,
-                                       ulong count)
+void pfs_inc_statement_sort_rows_v1(PSI_statement_locker *locker,
+                                    ulong count)
 {
   INC_STATEMENT_ATTR_BODY(locker, m_sort_rows, count);
 }
 
-static void inc_statement_sort_scan_v1(PSI_statement_locker *locker,
-                                       ulong count)
+void pfs_inc_statement_sort_scan_v1(PSI_statement_locker *locker,
+                                    ulong count)
 {
   INC_STATEMENT_ATTR_BODY(locker, m_sort_scan, count);
 }
 
-static void set_statement_no_index_used_v1(PSI_statement_locker *locker)
+void pfs_set_statement_no_index_used_v1(PSI_statement_locker *locker)
 {
   SET_STATEMENT_ATTR_BODY(locker, m_no_index_used, 1);
 }
 
-static void set_statement_no_good_index_used_v1(PSI_statement_locker *locker)
+void pfs_set_statement_no_good_index_used_v1(PSI_statement_locker *locker)
 {
   SET_STATEMENT_ATTR_BODY(locker, m_no_good_index_used, 1);
 }
 
-static void end_statement_v1(PSI_statement_locker *locker, void *stmt_da)
+void pfs_end_statement_v1(PSI_statement_locker *locker, void *stmt_da)
 {
   PSI_statement_locker_state *state= reinterpret_cast<PSI_statement_locker_state*> (locker);
   Diagnostics_area *da= reinterpret_cast<Diagnostics_area*> (stmt_da);
@@ -4807,7 +4886,7 @@ static void end_statement_v1(PSI_stateme
   {
     if (flags & STATE_FLAG_DIGEST)
     {
-      PFS_thread *thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
+      PFS_thread *thread= my_pthread_get_THR_PFS();
 
       /* An instrumented thread is required, for LF_PINS. */
       if (thread != NULL)
@@ -4917,7 +4996,7 @@ static void end_statement_v1(PSI_stateme
   Implementation of the socket instrumentation interface.
   @sa PSI_v1::end_socket_wait.
 */
-static void end_socket_wait_v1(PSI_socket_locker *locker, size_t byte_count)
+void pfs_end_socket_wait_v1(PSI_socket_locker *locker, size_t byte_count)
 {
   PSI_socket_locker_state *state= reinterpret_cast<PSI_socket_locker_state*> (locker);
   DBUG_ASSERT(state != NULL);
@@ -4998,7 +5077,7 @@ static void end_socket_wait_v1(PSI_socke
   }
 }
 
-static void set_socket_state_v1(PSI_socket *socket, PSI_socket_state state)
+void pfs_set_socket_state_v1(PSI_socket *socket, PSI_socket_state state)
 {
   DBUG_ASSERT((state == PSI_SOCKET_STATE_IDLE) || (state == PSI_SOCKET_STATE_ACTIVE));
   PFS_socket *pfs= reinterpret_cast<PFS_socket*>(socket);
@@ -5011,10 +5090,10 @@ static void set_socket_state_v1(PSI_sock
 /**
   Set socket descriptor and address info.
 */
-static void set_socket_info_v1(PSI_socket *socket,
-                               const my_socket *fd,
-                               const struct sockaddr *addr,
-                               socklen_t addr_len)
+void pfs_set_socket_info_v1(PSI_socket *socket,
+                            const my_socket *fd,
+                            const struct sockaddr *addr,
+                            socklen_t addr_len)
 {
   PFS_socket *pfs= reinterpret_cast<PFS_socket*>(socket);
   DBUG_ASSERT(pfs != NULL);
@@ -5040,11 +5119,11 @@ static void set_socket_info_v1(PSI_socke
   Implementation of the socket instrumentation interface.
   @sa PSI_v1::set_socket_info.
 */
-static void set_socket_thread_owner_v1(PSI_socket *socket)
+void pfs_set_socket_thread_owner_v1(PSI_socket *socket)
 {
   PFS_socket *pfs_socket= reinterpret_cast<PFS_socket*>(socket);
   DBUG_ASSERT(pfs_socket != NULL);
-  pfs_socket->m_thread_owner= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
+  pfs_socket->m_thread_owner= my_pthread_get_THR_PFS();
 }
 
 
@@ -5052,11 +5131,10 @@ static void set_socket_thread_owner_v1(P
   Implementation of the thread attribute connection interface
   @sa PSI_v1::set_thread_connect_attr.
 */
-static int set_thread_connect_attrs_v1(const char *buffer, uint length,
-                                       const void *from_cs)
+int pfs_set_thread_connect_attrs_v1(const char *buffer, uint length,
+                                    const void *from_cs)
 {
-
-  PFS_thread *thd= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
+  PFS_thread *thd= my_pthread_get_THR_PFS();
 
   DBUG_ASSERT(buffer != NULL);
 
@@ -5089,103 +5167,103 @@ static int set_thread_connect_attrs_v1(c
 */
 PSI_v1 PFS_v1=
 {
-  register_mutex_v1,
-  register_rwlock_v1,
-  register_cond_v1,
-  register_thread_v1,
-  register_file_v1,
-  register_stage_v1,
-  register_statement_v1,
-  register_socket_v1,
-  init_mutex_v1,
-  destroy_mutex_v1,
-  init_rwlock_v1,
-  destroy_rwlock_v1,
-  init_cond_v1,
-  destroy_cond_v1,
-  init_socket_v1,
-  destroy_socket_v1,
-  get_table_share_v1,
-  release_table_share_v1,
-  drop_table_share_v1,
-  open_table_v1,
-  unbind_table_v1,
-  rebind_table_v1,
-  close_table_v1,
-  create_file_v1,
-  spawn_thread_v1,
-  new_thread_v1,
-  set_thread_id_v1,
-  get_thread_v1,
-  set_thread_user_v1,
-  set_thread_account_v1,
-  set_thread_db_v1,
-  set_thread_command_v1,
-  set_thread_start_time_v1,
-  set_thread_state_v1,
-  set_thread_info_v1,
-  set_thread_v1,
-  delete_current_thread_v1,
-  delete_thread_v1,
-  get_thread_file_name_locker_v1,
-  get_thread_file_stream_locker_v1,
-  get_thread_file_descriptor_locker_v1,
-  unlock_mutex_v1,
-  unlock_rwlock_v1,
-  signal_cond_v1,
-  broadcast_cond_v1,
-  start_idle_wait_v1,
-  end_idle_wait_v1,
-  start_mutex_wait_v1,
-  end_mutex_wait_v1,
-  start_rwlock_wait_v1, /* read */
-  end_rwlock_rdwait_v1,
-  start_rwlock_wait_v1, /* write */
-  end_rwlock_wrwait_v1,
-  start_cond_wait_v1,
-  end_cond_wait_v1,
-  start_table_io_wait_v1,
-  end_table_io_wait_v1,
-  start_table_lock_wait_v1,
-  end_table_lock_wait_v1,
-  start_file_open_wait_v1,
-  end_file_open_wait_v1,
-  end_file_open_wait_and_bind_to_descriptor_v1,
-  start_file_wait_v1,
-  end_file_wait_v1,
-  start_file_close_wait_v1,
-  end_file_close_wait_v1,
-  start_stage_v1,
-  end_stage_v1,
-  get_thread_statement_locker_v1,
-  refine_statement_v1,
-  start_statement_v1,
-  set_statement_text_v1,
-  set_statement_lock_time_v1,
-  set_statement_rows_sent_v1,
-  set_statement_rows_examined_v1,
-  inc_statement_created_tmp_disk_tables_v1,
-  inc_statement_created_tmp_tables_v1,
-  inc_statement_select_full_join_v1,
-  inc_statement_select_full_range_join_v1,
-  inc_statement_select_range_v1,
-  inc_statement_select_range_check_v1,
-  inc_statement_select_scan_v1,
-  inc_statement_sort_merge_passes_v1,
-  inc_statement_sort_range_v1,
-  inc_statement_sort_rows_v1,
-  inc_statement_sort_scan_v1,
-  set_statement_no_index_used_v1,
-  set_statement_no_good_index_used_v1,
-  end_statement_v1,
-  start_socket_wait_v1,
-  end_socket_wait_v1,
-  set_socket_state_v1,
-  set_socket_info_v1,
-  set_socket_thread_owner_v1,
+  pfs_register_mutex_v1,
+  pfs_register_rwlock_v1,
+  pfs_register_cond_v1,
+  pfs_register_thread_v1,
+  pfs_register_file_v1,
+  pfs_register_stage_v1,
+  pfs_register_statement_v1,
+  pfs_register_socket_v1,
+  pfs_init_mutex_v1,
+  pfs_destroy_mutex_v1,
+  pfs_init_rwlock_v1,
+  pfs_destroy_rwlock_v1,
+  pfs_init_cond_v1,
+  pfs_destroy_cond_v1,
+  pfs_init_socket_v1,
+  pfs_destroy_socket_v1,
+  pfs_get_table_share_v1,
+  pfs_release_table_share_v1,
+  pfs_drop_table_share_v1,
+  pfs_open_table_v1,
+  pfs_unbind_table_v1,
+  pfs_rebind_table_v1,
+  pfs_close_table_v1,
+  pfs_create_file_v1,
+  pfs_spawn_thread_v1,
+  pfs_new_thread_v1,
+  pfs_set_thread_id_v1,
+  pfs_get_thread_v1,
+  pfs_set_thread_user_v1,
+  pfs_set_thread_account_v1,
+  pfs_set_thread_db_v1,
+  pfs_set_thread_command_v1,
+  pfs_set_thread_start_time_v1,
+  pfs_set_thread_state_v1,
+  pfs_set_thread_info_v1,
+  pfs_set_thread_v1,
+  pfs_delete_current_thread_v1,
+  pfs_delete_thread_v1,
+  pfs_get_thread_file_name_locker_v1,
+  pfs_get_thread_file_stream_locker_v1,
+  pfs_get_thread_file_descriptor_locker_v1,
+  pfs_unlock_mutex_v1,
+  pfs_unlock_rwlock_v1,
+  pfs_signal_cond_v1,
+  pfs_broadcast_cond_v1,
+  pfs_start_idle_wait_v1,
+  pfs_end_idle_wait_v1,
+  pfs_start_mutex_wait_v1,
+  pfs_end_mutex_wait_v1,
+  pfs_start_rwlock_rdwait_v1,
+  pfs_end_rwlock_rdwait_v1,
+  pfs_start_rwlock_wrwait_v1,
+  pfs_end_rwlock_wrwait_v1,
+  pfs_start_cond_wait_v1,
+  pfs_end_cond_wait_v1,
+  pfs_start_table_io_wait_v1,
+  pfs_end_table_io_wait_v1,
+  pfs_start_table_lock_wait_v1,
+  pfs_end_table_lock_wait_v1,
+  pfs_start_file_open_wait_v1,
+  pfs_end_file_open_wait_v1,
+  pfs_end_file_open_wait_and_bind_to_descriptor_v1,
+  pfs_start_file_wait_v1,
+  pfs_end_file_wait_v1,
+  pfs_start_file_close_wait_v1,
+  pfs_end_file_close_wait_v1,
+  pfs_start_stage_v1,
+  pfs_end_stage_v1,
+  pfs_get_thread_statement_locker_v1,
+  pfs_refine_statement_v1,
+  pfs_start_statement_v1,
+  pfs_set_statement_text_v1,
+  pfs_set_statement_lock_time_v1,
+  pfs_set_statement_rows_sent_v1,
+  pfs_set_statement_rows_examined_v1,
+  pfs_inc_statement_created_tmp_disk_tables_v1,
+  pfs_inc_statement_created_tmp_tables_v1,
+  pfs_inc_statement_select_full_join_v1,
+  pfs_inc_statement_select_full_range_join_v1,
+  pfs_inc_statement_select_range_v1,
+  pfs_inc_statement_select_range_check_v1,
+  pfs_inc_statement_select_scan_v1,
+  pfs_inc_statement_sort_merge_passes_v1,
+  pfs_inc_statement_sort_range_v1,
+  pfs_inc_statement_sort_rows_v1,
+  pfs_inc_statement_sort_scan_v1,
+  pfs_set_statement_no_index_used_v1,
+  pfs_set_statement_no_good_index_used_v1,
+  pfs_end_statement_v1,
+  pfs_start_socket_wait_v1,
+  pfs_end_socket_wait_v1,
+  pfs_set_socket_state_v1,
+  pfs_set_socket_info_v1,
+  pfs_set_socket_thread_owner_v1,
   pfs_digest_start_v1,
   pfs_digest_add_token_v1,
-  set_thread_connect_attrs_v1,
+  pfs_set_thread_connect_attrs_v1
 };
 
 static void* get_interface(int version)

=== modified file 'storage/perfschema/pfs_digest.h'
--- a/storage/perfschema/pfs_digest.h	2012-07-19 09:08:39 +0000
+++ b/storage/perfschema/pfs_digest.h	2012-08-29 09:08:27 +0000
@@ -80,13 +80,6 @@ void reset_esms_by_digest();
 /* Exposing the data directly, for iterators. */
 extern PFS_statements_digest_stat *statements_digest_stat_array;
 
-/* Instrumentation callbacks for pfs.cc */
-
-struct PSI_digest_locker *pfs_digest_start_v1(PSI_statement_locker *locker);
-PSI_digest_locker *pfs_digest_add_token_v1(PSI_digest_locker *locker,
-                                           uint token,
-                                           OPAQUE_LEX_YYSTYPE *yylval);
-
 static inline void digest_reset(PSI_digest_storage *digest)
 {
   digest->m_full= false;

=== modified file 'storage/perfschema/pfs_events_stages.cc'
--- a/storage/perfschema/pfs_events_stages.cc	2011-11-18 16:49:29 +0000
+++ b/storage/perfschema/pfs_events_stages.cc	2012-08-29 09:08:27 +0000
@@ -30,20 +30,20 @@
 #include "pfs_atomic.h"
 #include "m_string.h"
 
-ulong events_stages_history_long_size= 0;
+PFS_ALIGNED ulong events_stages_history_long_size= 0;
 /** Consumer flag for table EVENTS_STAGES_CURRENT. */
-bool flag_events_stages_current= false;
+PFS_ALIGNED bool flag_events_stages_current= false;
 /** Consumer flag for table EVENTS_STAGES_HISTORY. */
-bool flag_events_stages_history= false;
+PFS_ALIGNED bool flag_events_stages_history= false;
 /** Consumer flag for table EVENTS_STAGES_HISTORY_LONG. */
-bool flag_events_stages_history_long= false;
+PFS_ALIGNED bool flag_events_stages_history_long= false;
 
 /** True if EVENTS_STAGES_HISTORY_LONG circular buffer is full. */
-bool events_stages_history_long_full= false;
+PFS_ALIGNED bool events_stages_history_long_full= false;
 /** Index in EVENTS_STAGES_HISTORY_LONG circular buffer. */
-volatile uint32 events_stages_history_long_index= 0;
+PFS_ALIGNED volatile uint32 events_stages_history_long_index= 0;
 /** EVENTS_STAGES_HISTORY_LONG circular buffer. */
-PFS_events_stages *events_stages_history_long_array= NULL;
+PFS_ALIGNED PFS_events_stages *events_stages_history_long_array= NULL;
 
 /**
   Initialize table EVENTS_STAGES_HISTORY_LONG.

=== modified file 'storage/perfschema/pfs_events_statements.cc'
--- a/storage/perfschema/pfs_events_statements.cc	2011-11-18 16:49:29 +0000
+++ b/storage/perfschema/pfs_events_statements.cc	2012-08-29 09:08:27 +0000
@@ -30,20 +30,20 @@
 #include "pfs_atomic.h"
 #include "m_string.h"
 
-ulong events_statements_history_long_size= 0;
+PFS_ALIGNED ulong events_statements_history_long_size= 0;
 /** Consumer flag for table EVENTS_STATEMENTS_CURRENT. */
-bool flag_events_statements_current= false;
+PFS_ALIGNED bool flag_events_statements_current= false;
 /** Consumer flag for table EVENTS_STATEMENTS_HISTORY. */
-bool flag_events_statements_history= false;
+PFS_ALIGNED bool flag_events_statements_history= false;
 /** Consumer flag for table EVENTS_STATEMENTS_HISTORY_LONG. */
-bool flag_events_statements_history_long= false;
+PFS_ALIGNED bool flag_events_statements_history_long= false;
 
 /** True if EVENTS_STATEMENTS_HISTORY_LONG circular buffer is full. */
-bool events_statements_history_long_full= false;
+PFS_ALIGNED bool events_statements_history_long_full= false;
 /** Index in EVENTS_STATEMENTS_HISTORY_LONG circular buffer. */
-volatile uint32 events_statements_history_long_index= 0;
+PFS_ALIGNED volatile uint32 events_statements_history_long_index= 0;
 /** EVENTS_STATEMENTS_HISTORY_LONG circular buffer. */
-PFS_events_statements *events_statements_history_long_array= NULL;
+PFS_ALIGNED PFS_events_statements *events_statements_history_long_array= NULL;
 
 /**
   Initialize table EVENTS_STATEMENTS_HISTORY_LONG.

=== modified file 'storage/perfschema/pfs_events_waits.cc'
--- a/storage/perfschema/pfs_events_waits.cc	2012-06-11 14:36:24 +0000
+++ b/storage/perfschema/pfs_events_waits.cc	2012-08-29 09:08:27 +0000
@@ -30,24 +30,24 @@
 #include "pfs_atomic.h"
 #include "m_string.h"
 
-ulong events_waits_history_long_size= 0;
+PFS_ALIGNED ulong events_waits_history_long_size= 0;
 /** Consumer flag for table EVENTS_WAITS_CURRENT. */
-bool flag_events_waits_current= false;
+PFS_ALIGNED bool flag_events_waits_current= false;
 /** Consumer flag for table EVENTS_WAITS_HISTORY. */
-bool flag_events_waits_history= false;
+PFS_ALIGNED bool flag_events_waits_history= false;
 /** Consumer flag for table EVENTS_WAITS_HISTORY_LONG. */
-bool flag_events_waits_history_long= false;
+PFS_ALIGNED bool flag_events_waits_history_long= false;
 /** Consumer flag for the global instrumentation. */
-bool flag_global_instrumentation= false;
+PFS_ALIGNED bool flag_global_instrumentation= false;
 /** Consumer flag for the per thread instrumentation. */
-bool flag_thread_instrumentation= false;
+PFS_ALIGNED bool flag_thread_instrumentation= false;
 
 /** True if EVENTS_WAITS_HISTORY_LONG circular buffer is full. */
-bool events_waits_history_long_full= false;
+PFS_ALIGNED bool events_waits_history_long_full= false;
 /** Index in EVENTS_WAITS_HISTORY_LONG circular buffer. */
-volatile uint32 events_waits_history_long_index= 0;
+PFS_ALIGNED volatile uint32 events_waits_history_long_index= 0;
 /** EVENTS_WAITS_HISTORY_LONG circular buffer. */
-PFS_events_waits *events_waits_history_long_array= NULL;
+PFS_ALIGNED PFS_events_waits *events_waits_history_long_array= NULL;
 
 /**
   Initialize table EVENTS_WAITS_HISTORY_LONG.

=== modified file 'storage/perfschema/pfs_instr.cc'
--- a/storage/perfschema/pfs_instr.cc	2012-08-20 09:41:04 +0000
+++ b/storage/perfschema/pfs_instr.cc	2012-08-29 09:08:27 +0000
@@ -37,47 +37,47 @@
 */
 
 /** Size of the mutex instances array. @sa mutex_array */
-ulong mutex_max;
+ulong mutex_max= 0;
 /** Number of mutexes instance lost. @sa mutex_array */
-ulong mutex_lost;
+ulong mutex_lost= 0;
 /** Size of the rwlock instances array. @sa rwlock_array */
-ulong rwlock_max;
+ulong rwlock_max= 0;
 /** Number or rwlock instances lost. @sa rwlock_array */
-ulong rwlock_lost;
+ulong rwlock_lost= 0;
 /** Size of the conditions instances array. @sa cond_array */
-ulong cond_max;
+ulong cond_max= 0;
 /** Number of conditions instances lost. @sa cond_array */
-ulong cond_lost;
+ulong cond_lost= 0;
 /** Size of the thread instances array. @sa thread_array */
-ulong thread_max;
+ulong thread_max= 0;
 /** Number or thread instances lost. @sa thread_array */
-ulong thread_lost;
+ulong thread_lost= 0;
 /** Size of the file instances array. @sa file_array */
-ulong file_max;
+ulong file_max= 0;
 /** Number of file instances lost. @sa file_array */
-ulong file_lost;
+ulong file_lost= 0;
 /**
   Size of the file handle array. @sa file_handle_array.
   Signed value, for easier comparisons with a file descriptor number.
 */
-long file_handle_max;
+long file_handle_max= 0;
 /** Number of file handle lost. @sa file_handle_array */
-ulong file_handle_lost;
+ulong file_handle_lost= 0;
 /** Size of the table instances array. @sa table_array */
-ulong table_max;
+ulong table_max= 0;
 /** Number of table instances lost. @sa table_array */
-ulong table_lost;
+ulong table_lost= 0;
 /** Size of the socket instances array. @sa socket_array */
-ulong socket_max;
+ulong socket_max= 0;
 /** Number of socket instances lost. @sa socket_array */
-ulong socket_lost;
+ulong socket_lost= 0;
 /** Number of EVENTS_WAITS_HISTORY records per thread. */
-ulong events_waits_history_per_thread;
+ulong events_waits_history_per_thread= 0;
 /** Number of EVENTS_STAGES_HISTORY records per thread. */
-ulong events_stages_history_per_thread;
+ulong events_stages_history_per_thread= 0;
 /** Number of EVENTS_STATEMENTS_HISTORY records per thread. */
-ulong events_statements_history_per_thread;
-uint statement_stack_max;
+ulong events_statements_history_per_thread= 0;
+uint statement_stack_max= 0;
 /** Number of locker lost. @sa LOCKER_STACK_SIZE. */
 ulong locker_lost= 0;
 /** Number of statement lost. @sa STATEMENT_STACK_SIZE. */
@@ -149,9 +149,9 @@ PFS_statement_stat *global_instr_class_s
 
 static volatile uint32 thread_internal_id_counter= 0;
 
-static uint thread_instr_class_waits_sizing;
-static uint thread_instr_class_stages_sizing;
-static uint thread_instr_class_statements_sizing;
+static uint thread_instr_class_waits_sizing= 0;
+static uint thread_instr_class_stages_sizing= 0;
+static uint thread_instr_class_statements_sizing= 0;
 static PFS_single_stat *thread_instr_class_waits_array= NULL;
 static PFS_stage_stat *thread_instr_class_stages_array= NULL;
 static PFS_statement_stat *thread_instr_class_statements_array= NULL;

=== modified file 'storage/perfschema/pfs_server.cc'
--- a/storage/perfschema/pfs_server.cc	2012-06-11 14:36:24 +0000
+++ b/storage/perfschema/pfs_server.cc	2012-08-29 09:08:27 +0000
@@ -49,8 +49,7 @@ C_MODE_END
 static void cleanup_performance_schema(void);
 void cleanup_instrument_config(void);
 
-struct PSI_bootstrap*
-initialize_performance_schema(PFS_global_param *param)
+void pre_initialize_performance_schema()
 {
   pfs_initialized= false;
 
@@ -59,6 +58,18 @@ initialize_performance_schema(PFS_global
   global_table_io_stat.reset();
   global_table_lock_stat.reset();
 
+  init_timers();
+  PFS_atomic::init();
+
+  if (pthread_key_create(&THR_PFS, destroy_pfs_thread))
+    return;
+
+  THR_PFS_initialized= true;
+}
+
+struct PSI_bootstrap*
+initialize_performance_schema(PFS_global_param *param)
+{
   pfs_automated_sizing(param);
 
   if (! param->m_enabled)
@@ -70,17 +81,9 @@ initialize_performance_schema(PFS_global
     return NULL;
   }
 
-  init_timers();
-  PFS_atomic::init();
-
   init_event_name_sizing(param);
   register_global_classes();
 
-  if (pthread_key_create(&THR_PFS, destroy_pfs_thread))
-    return NULL;
-
-  THR_PFS_initialized= true;
-
   if (init_sync_class(param->m_mutex_class_sizing,
                       param->m_rwlock_class_sizing,
                       param->m_cond_class_sizing) ||

=== modified file 'storage/perfschema/pfs_server.h'
--- a/storage/perfschema/pfs_server.h	2012-06-01 08:39:34 +0000
+++ b/storage/perfschema/pfs_server.h	2012-08-29 09:08:27 +0000
@@ -208,6 +208,14 @@ struct PFS_global_param
 extern PFS_global_param pfs_param;
 
 /**
+  Null initialization.
+  Disable all instrumentation, size all internal buffers to 0.
+  This pre initialization step is needed to ensure that events can be collected
+  and discarded, until such time @c initialize_performance_schema() is called.
+*/
+void pre_initialize_performance_schema();
+
+/**
   Initialize the performance schema.
   @param param Size parameters to use.
   @return A boostrap handle, or NULL.

=== modified file 'storage/perfschema/unittest/CMakeLists.txt'
--- a/storage/perfschema/unittest/CMakeLists.txt	2012-08-23 09:18:04 +0000
+++ b/storage/perfschema/unittest/CMakeLists.txt	2012-08-29 09:08:27 +0000
@@ -23,9 +23,11 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/
 
 ADD_DEFINITIONS(-DMYSQL_SERVER ${SSL_DEFINES})
 
+ADD_CONVENIENCE_LIBRARY(pfs_server_stubs pfs_server_stubs.cc)
+
 MACRO (PFS_ADD_TEST name)
   ADD_EXECUTABLE(${name}-t ${name}-t.cc)
-  TARGET_LINK_LIBRARIES(${name}-t mytap perfschema mysys)
+  TARGET_LINK_LIBRARIES(${name}-t mytap perfschema mysys pfs_server_stubs)
   ADD_TEST(${name} ${name}-t)
 ENDMACRO()
 
@@ -54,3 +56,8 @@ TARGET_LINK_LIBRARIES(pfs_connect_attr-t
   mysys mysys_ssl)
 TARGET_LINK_LIBRARIES(pfs_connect_attr-t vio ${SSL_LIBRARIES})
 ADD_TEST(pfs_connect_attr pfs_connect_attr-t)
+
+ADD_EXECUTABLE(pfs_benchmark-t pfs_benchmark-t.cc pfs_benchmark_helper.cc)
+TARGET_LINK_LIBRARIES(pfs_benchmark-t mytap perfschema mysys pfs_server_stubs)
+ADD_TEST(pfs_benchmark pfs_benchmark-t)
+

=== modified file 'storage/perfschema/unittest/pfs-t.cc'
--- a/storage/perfschema/unittest/pfs-t.cc	2012-08-07 15:41:51 +0000
+++ b/storage/perfschema/unittest/pfs-t.cc	2012-08-29 09:08:27 +0000
@@ -26,7 +26,6 @@
 
 #include "stub_print_error.h"
 #include "stub_pfs_defaults.h"
-#include "stub_server_misc.h"
 
 /* test helpers, to simulate the setup */
 
@@ -113,6 +112,7 @@ void test_bootstrap()
   param.m_digest_sizing= 0;
   param.m_session_connect_attrs_sizing= 0;
 
+  pre_initialize_performance_schema();
   boot= initialize_performance_schema(& param);
   ok(boot != NULL, "boot");
   ok(boot->get_interface != NULL, "boot->get_interface");

=== modified file 'storage/perfschema/unittest/pfs_account-oom-t.cc'
--- a/storage/perfschema/unittest/pfs_account-oom-t.cc	2012-05-31 15:15:33 +0000
+++ b/storage/perfschema/unittest/pfs_account-oom-t.cc	2012-08-29 09:08:27 +0000
@@ -22,7 +22,6 @@
 #include <tap.h>
 
 #include "stub_pfs_global.h"
-#include "stub_server_misc.h"
 
 #include <string.h> /* memset */
 

=== modified file 'storage/perfschema/unittest/pfs_host-oom-t.cc'
--- a/storage/perfschema/unittest/pfs_host-oom-t.cc	2012-05-31 15:15:33 +0000
+++ b/storage/perfschema/unittest/pfs_host-oom-t.cc	2012-08-29 09:08:27 +0000
@@ -22,7 +22,6 @@
 #include <tap.h>
 
 #include "stub_pfs_global.h"
-#include "stub_server_misc.h"
 
 #include <string.h> /* memset */
 

=== modified file 'storage/perfschema/unittest/pfs_instr-oom-t.cc'
--- a/storage/perfschema/unittest/pfs_instr-oom-t.cc	2012-06-12 09:29:24 +0000
+++ b/storage/perfschema/unittest/pfs_instr-oom-t.cc	2012-08-29 09:08:27 +0000
@@ -22,7 +22,6 @@
 #include <tap.h>
 
 #include "stub_pfs_global.h"
-#include "stub_server_misc.h"
 
 #include <string.h> /* memset */
 

=== modified file 'storage/perfschema/unittest/pfs_instr-t.cc'
--- a/storage/perfschema/unittest/pfs_instr-t.cc	2012-08-20 09:41:04 +0000
+++ b/storage/perfschema/unittest/pfs_instr-t.cc	2012-08-29 09:08:27 +0000
@@ -23,8 +23,6 @@
 
 #include <memory.h>
 
-#include "stub_server_misc.h"
-
 void test_no_instruments()
 {
   int rc;

=== modified file 'storage/perfschema/unittest/pfs_instr_class-oom-t.cc'
--- a/storage/perfschema/unittest/pfs_instr_class-oom-t.cc	2011-08-11 03:11:58 +0000
+++ b/storage/perfschema/unittest/pfs_instr_class-oom-t.cc	2012-08-29 09:08:27 +0000
@@ -20,7 +20,6 @@
 #include <tap.h>
 
 #include "stub_pfs_global.h"
-#include "stub_server_misc.h"
 
 void test_oom()
 {

=== modified file 'storage/perfschema/unittest/pfs_instr_class-t.cc'
--- a/storage/perfschema/unittest/pfs_instr_class-t.cc	2012-06-11 14:36:24 +0000
+++ b/storage/perfschema/unittest/pfs_instr_class-t.cc	2012-08-29 09:08:27 +0000
@@ -21,7 +21,6 @@
 #include <pfs_global.h>
 #include <tap.h>
 
-#include "stub_server_misc.h"
 
 void test_no_registration()
 {

=== added file 'storage/perfschema/unittest/pfs_server_stubs.cc'
--- a/storage/perfschema/unittest/pfs_server_stubs.cc	1970-01-01 00:00:00 +0000
+++ b/storage/perfschema/unittest/pfs_server_stubs.cc	2012-08-29 09:08:27 +0000
@@ -0,0 +1,31 @@
+/* Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; version 2 of the License.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+
+/*
+  Minimal code to be able to link a unit test.
+*/
+
+#include "my_global.h"
+#include "m_ctype.h"
+
+volatile bool ready_to_exit= false;
+
+uint lower_case_table_names= 0;
+CHARSET_INFO *files_charset_info= NULL;
+
+extern "C" void compute_md5_hash(char *, const char *, int)
+{
+}
+

=== modified file 'storage/perfschema/unittest/pfs_user-oom-t.cc'
--- a/storage/perfschema/unittest/pfs_user-oom-t.cc	2011-07-29 09:10:56 +0000
+++ b/storage/perfschema/unittest/pfs_user-oom-t.cc	2012-08-29 09:08:27 +0000
@@ -22,7 +22,6 @@
 #include <tap.h>
 
 #include "stub_pfs_global.h"
-#include "stub_server_misc.h"
 
 #include <string.h> /* memset */
 

=== removed file 'storage/perfschema/unittest/stub_server_misc.h'
--- a/storage/perfschema/unittest/stub_server_misc.h	2012-02-20 20:56:20 +0000
+++ b/storage/perfschema/unittest/stub_server_misc.h	1970-01-01 00:00:00 +0000
@@ -1,28 +0,0 @@
-/* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
-
-  This program is free software; you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published by
-  the Free Software Foundation; version 2 of the License.
-
-  This program is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  GNU General Public License for more details.
-
-  You should have received a copy of the GNU General Public License
-  along with this program; if not, write to the Free Software
-  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
-
-/*
-  Minimal code to be able to link a unit test.
-*/
-
-volatile bool ready_to_exit= false;
-
-uint lower_case_table_names= 0;
-CHARSET_INFO *files_charset_info= NULL;
-
-extern "C" void compute_md5_hash(char *, const char *, int)
-{
-}
-

=== modified file 'unittest/gunit/CMakeLists.txt'
--- a/unittest/gunit/CMakeLists.txt	2012-06-20 09:31:36 +0000
+++ b/unittest/gunit/CMakeLists.txt	2012-08-29 09:08:27 +0000
@@ -278,6 +278,9 @@ SET(SERVER_TESTS
 FOREACH(test ${TESTS})
   ADD_EXECUTABLE(${test}-t ${test}-t.cc)
   TARGET_LINK_LIBRARIES(${test}-t gunit_small sqlgunitlib strings dbug regex)
+  IF(WITH_PERFSCHEMA_STORAGE_ENGINE)
+    TARGET_LINK_LIBRARIES(${test}-t perfschema pfs_server_stubs)
+  ENDIF()
   IF(APPLE AND GTEST_DYLIB_LOCATION)
     ADD_CUSTOM_COMMAND(TARGET ${test}-t POST_BUILD
       COMMAND install_name_tool -change

=== modified file 'unittest/gunit/dynarray-t.cc'
--- a/unittest/gunit/dynarray-t.cc	2012-04-27 11:57:38 +0000
+++ b/unittest/gunit/dynarray-t.cc	2012-08-29 09:08:27 +0000
@@ -34,7 +34,9 @@
 */
 
 pthread_key(MEM_ROOT**, THR_MALLOC);
+bool THR_MALLOC_initialized= false;
 pthread_key(THD*, THR_THD);
+bool THR_THD_initialized= false;
 
 extern "C" void sql_alloc_error_handler(void)
 {
@@ -254,13 +256,17 @@ protected:
   {
     generate_test_data(test_data, table_list, num_elements);
     ASSERT_EQ(0, pthread_key_create(&THR_THD, NULL));
+    THR_THD_initialized= true;
     ASSERT_EQ(0, pthread_key_create(&THR_MALLOC, NULL));
+    THR_MALLOC_initialized= true;
   }
 
   static void TearDownTestCase()
   {
     pthread_key_delete(THR_THD);
+    THR_THD_initialized= false;
     pthread_key_delete(THR_MALLOC);
+    THR_MALLOC_initialized= false;
   }
 
   void insert_and_sort_mysys()

=== modified file 'unittest/gunit/gunit_test_main_server.cc'
--- a/unittest/gunit/gunit_test_main_server.cc	2012-05-07 12:05:48 +0000
+++ b/unittest/gunit/gunit_test_main_server.cc	2012-08-29 09:08:27 +0000
@@ -21,6 +21,10 @@
 #include "test_utils.h"
 #include <stdlib.h>
 
+#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
+#include "../storage/perfschema/pfs_server.h"
+#endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
+
 namespace {
 
 my_bool opt_use_tap= true;
@@ -57,6 +61,11 @@ extern void install_tap_listener();
 int main(int argc, char **argv)
 {
   ::testing::InitGoogleTest(&argc, argv);
+
+#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
+  pre_initialize_performance_schema();
+#endif /*WITH_PERFSCHEMA_STORAGE_ENGINE */
+
   MY_INIT(argv[0]);
 
   if (handle_options(&argc, &argv, unittest_options, get_one_option))

=== modified file 'unittest/gunit/sql_list-t.cc'
--- a/unittest/gunit/sql_list-t.cc	2012-02-15 13:57:17 +0000
+++ b/unittest/gunit/sql_list-t.cc	2012-08-29 09:08:27 +0000
@@ -32,7 +32,9 @@
 #include <my_pthread.h>
 
 pthread_key(MEM_ROOT**, THR_MALLOC);
+bool THR_MALLOC_initialized= false;
 pthread_key(THD*, THR_THD);
+bool THR_THD_initialized= false;
 
 extern "C" void sql_alloc_error_handler(void)
 {
@@ -89,13 +91,17 @@ protected:
   static void SetUpTestCase()
   {
     ASSERT_EQ(0, pthread_key_create(&THR_THD, NULL));
+    THR_THD_initialized= true;
     ASSERT_EQ(0, pthread_key_create(&THR_MALLOC, NULL));
+    THR_MALLOC_initialized= true;
   }
 
   static void TearDownTestCase()
   {
     pthread_key_delete(THR_THD);
+    THR_THD_initialized= false;
     pthread_key_delete(THR_MALLOC);
+    THR_MALLOC_initialized= false;
   }
 
   MEM_ROOT m_mem_root;

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-5.6-marc branch (marc.alff:4198 to 4199) Marc Alff29 Aug