List:Commits« Previous MessageNext Message »
From:Christopher Powers Date:June 22 2010 11:03pm
Subject:bzr push into mysql-next-mr-wl4896 branch (chris.powers:3148 to 3149) WL#4896
View as plain text  
 3149 Christopher Powers	2010-06-22
      WL#4896 PERFORMANCE_SCHEMA Instrumenting Net IO
      - Added socket operation PSI_SOCKET_SHUTDOWN
      - Refined socket api helpers
      - Added methods to create/destroy/register socket instrumentation
      
      Code compiles but is not fully debugged.
     @ include/mysql/psi/mysql_socket.h
        Refined socket api helper methods
     @ sql/mysqld.cc
        Completed socket api instrumentation
     @ storage/perfschema/pfs.cc
        Added OPERATION_TYPE_SOCKETSHUTDOWN

    modified:
      include/mysql/psi/mysql_socket.h
      include/mysql/psi/psi.h
      include/mysql/psi/psi_abi_v1.h.pp
      include/mysql/psi/psi_abi_v2.h.pp
      sql/mysqld.cc
      sql/mysqld.h
      storage/perfschema/pfs.cc
      storage/perfschema/pfs_column_types.h
      storage/perfschema/pfs_events_waits.h
      storage/perfschema/pfs_instr.cc
      storage/perfschema/pfs_instr.h
      storage/perfschema/pfs_instr_class.cc
      vio/viosocket.c
 3148 Christopher Powers	2010-06-09
      WL#4896 PERFORMANCE_SCHEMA Instrumenting Net IO
            
      Socket API helpers and instrumentation, intermediate version

    modified:
      include/mysql/psi/mysql_socket.h
      include/mysql/psi/psi.h
      include/mysql/psi/psi_abi_v1.h.pp
      include/mysql/psi/psi_abi_v2.h.pp
      storage/perfschema/pfs.cc
      storage/perfschema/pfs_column_types.h
      storage/perfschema/pfs_column_values.cc
      storage/perfschema/pfs_column_values.h
      storage/perfschema/pfs_instr_class.cc
      storage/perfschema/pfs_instr_class.h
      storage/perfschema/pfs_stat.h
=== modified file 'include/mysql/psi/mysql_socket.h'
--- a/include/mysql/psi/mysql_socket.h	2010-06-09 20:19:47 +0000
+++ b/include/mysql/psi/mysql_socket.h	2010-06-22 23:02:37 +0000
@@ -36,193 +36,244 @@ Foundation, Inc., 51 Franklin St, Fifth
 #include "mysql/psi/psi.h"
 
 /**
-  @defgroup Network_instrumentation Network Instrumentation
+  @defgroup Socket_instrumentation Socket Instrumentation
   @ingroup Instrumentation_interface
   @{
 */
 
+/**
+  @def MYSQL_START_SOCKET_WAIT
+  Instrumentation helper for socket waits.
+  This instrumentation marks the start of a wait event.
+  @param PSI The instrumented socket
+  @param OP The socket operation to be performed
+  @param INDEX The socket index used if any, or MAY_KEY.
+  @param FLAGS Per socket operation flags.
+  @sa MYSQL_END_SOCKET_WAIT.
+*/
+#ifdef HAVE_PSI_INTERFACE
+  #define MYSQL_START_SOCKET_WAIT(PSI, OP, INDEX, FLAGS) \
+    inline_mysql_start_socket_wait(PSI, OP, INDEX, FLAGS, __FILE__, __LINE__)
+#else
+  #define MYSQL_START_SOCKET_WAIT(PSI, OP, INDEX, FLAGS) \
+    NULL
+#endif
+
+/**
+  @def MYSQL_END_SOCKET_WAIT
+  Instrumentation helper for socket waits.
+  This instrumentation marks the end of a wait event.
+  @sa MYSQL_START_SOCKET_WAIT.
+*/
+#ifdef HAVE_PSI_INTERFACE
+  #define MYSQL_END_SOCKET_WAIT(L) \
+    inline_mysql_end_socket_wait(L)
+#else
+  #define MYSQL_END_SOCKET_WAIT(L) \
+    do {} while (0)
+#endif
+
+
+#ifdef HAVE_PSI_INTERFACE
+/**
+  Instrumentation calls for MYSQL_START_SOCKET_WAIT.
+  @sa MYSQL_START_SOCKET_WAIT.
+*/
+static inline struct PSI_socket_locker *
+inline_mysql_start_socket_wait(struct PSI_socket *psi, enum PSI_socket_operation op,
+                              uint index, ulong flags,
+                              const char *src_file, int src_line)
+{
+  struct PSI_socket_locker *locker= NULL;
+  if (likely(PSI_server && psi))
+  {
+    locker= PSI_server->get_thread_socket_locker(psi, op);
+    if (likely(locker != NULL))
+      PSI_server->start_socket_wait(locker, src_file, src_line);
+  }
+  return locker;
+}
+
+/**
+  Instrumentation calls for MYSQL_END_SOCKET_WAIT.
+  @sa MYSQL_END_SOCKET_WAIT.
+*/
+static inline void
+inline_mysql_end_socket_wait(struct PSI_socket_locker *locker)
+{
+  if (likely(locker != NULL))
+    PSI_server->end_socket_wait(locker);
+}
+#endif
+
+
 #ifdef HAVE_PSI_INTERFACE
-  #define mysql_socket_socket(D, T, P) \
-    inline mysql_socket_socket(__FILE__, __LINE__, D, T, P)
+  #define mysql_socket_socket(K, D, T, P) \
+    inline_mysql_socket_socket(K, __FILE__, __LINE__, D, T, P)
 #else
-  #define mysql_socket_socket(D, T, P) \
+  #define mysql_socket_socket(K, D, T, P) \
     inline_mysql_socket_socket(D, T, P)
 #endif
-		
+
 #ifdef HAVE_PSI_INTERFACE
   #define mysql_socket_socketpair(D, T, P, SDS) \
-    inline mysql_socket_socketpair(__FILE__, __LINE__, D, T, P, SDS)
+    inline_mysql_socket_socketpair(__FILE__, __LINE__, D, T, P, SDS)
 #else
   #define mysql_socket_socketpair(D, T, P, SDS) \
     inline_mysql_socket_socketpair(D, T, P, SDS)
 #endif
-		
+
 #ifdef HAVE_PSI_INTERFACE
   #define mysql_socket_bind(SD, A, L) \
-    inline mysql_socket_bind(__FILE__, __LINE__, SD, A, L)
+    inline_mysql_socket_bind(__FILE__, __LINE__, SD, A, L)
 #else
   #define mysql_socket_bind(SD, A, L) \
     inline_mysql_socket_bind(SD, A, L)
 #endif
-		
+
 #ifdef HAVE_PSI_INTERFACE
   #define mysql_socket_getsockname(SD, A, LP) \
-    inline mysql_socket_getsockname(__FILE__, __LINE__, SD, A, LP)
+    inline_mysql_socket_getsockname(__FILE__, __LINE__, SD, A, LP)
 #else
   #define mysql_socket_getsockname(SD, A, LP) \
     inline_mysql_socket_getsockname(SD, A, LP)
 #endif
-		
+
 #ifdef HAVE_PSI_INTERFACE
   #define mysql_socket_connect(SD, A, L) \
-    inline mysql_socket_connect(__FILE__, __LINE__, SD, A, L)
+    inline_mysql_socket_connect(__FILE__, __LINE__, SD, A, L)
 #else
   #define mysql_socket_connect(SD, A, L) \
     inline_mysql_socket_connect(SD, A, L)
 #endif
-		
+
 #ifdef HAVE_PSI_INTERFACE
   #define mysql_socket_getpeername(SD, A, LP) \
-    inline mysql_socket_getpeername(__FILE__, __LINE__, SD, A, LP)
+    inline_mysql_socket_getpeername(__FILE__, __LINE__, SD, A, LP)
 #else
   #define mysql_socket_getpeername(SD, A, LP) \
     inline_mysql_socket_getpeername(SD, A, LP)
 #endif
-		
+
 #ifdef HAVE_PSI_INTERFACE
   #define mysql_socket_send(SD, B, N, FL) \
-    inline mysql_socket_send(__FILE__, __LINE__, SD, B, N, FL)
+    inline_mysql_socket_send(__FILE__, __LINE__, SD, B, N, FL)
 #else
   #define mysql_socket_send(SD, B, N, FL) \
     inline_mysql_socket_send(SD, B, N, FL)
 #endif
-		
+
 #ifdef HAVE_PSI_INTERFACE
   #define mysql_socket_recv(SD, B, N, FL) \
-    inline mysql_socket_recv(__FILE__, __LINE__, SD, B, N, FL)
+    inline_mysql_socket_recv(__FILE__, __LINE__, SD, B, N, FL)
 #else
   #define mysql_socket_recv(SD, B, N, FL) \
     inline_mysql_socket_recv(SD, B, N, FL)
 #endif
-		
+
 #ifdef HAVE_PSI_INTERFACE
   #define mysql_socket_sendto(SD, B, N, FL, A, L) \
-    inline mysql_socket_sendto(__FILE__, __LINE__, SD, B, N, FL, A, L)
+    inline_mysql_socket_sendto(__FILE__, __LINE__, SD, B, N, FL, A, L)
 #else
   #define mysql_socket_sendto(SD, B, N, FL, A, L) \
     inline_mysql_socket_sendto(SD, B, N, FL, A, L)
 #endif
-		
+
 #ifdef HAVE_PSI_INTERFACE
   #define mysql_socket_recvfrom(SD, B, N, FL, A, LP) \
-    inline mysql_socket_recvfrom(__FILE__, __LINE__, SD, B, N, FL, A, LP)
+    inline_mysql_socket_recvfrom(__FILE__, __LINE__, SD, B, N, FL, A, LP)
 #else
   #define mysql_socket_recvfrom(SD, B, N, FL, A, LP) \
     inline_mysql_socket_recvfrom(SD, B, N, FL, A, LP)
 #endif
-		
+
 #ifdef HAVE_PSI_INTERFACE
   #define mysql_socket_sendmsg(SD, M, FL) \
-    inline mysql_socket_sendmsg(__FILE__, __LINE__, SD, M, FL)
+    inline_mysql_socket_sendmsg(__FILE__, __LINE__, SD, M, FL)
 #else
   #define mysql_socket_sendmsg(SD, M, FL) \
     inline_mysql_socket_sendmsg(SD, M, FL)
 #endif
-		
+
 #ifdef HAVE_PSI_INTERFACE
   #define mysql_socket_recvmsg(SD, M, FL) \
-    inline mysql_socket_recvmsg(__FILE__, __LINE__, SD, M, FL)
+    inline_mysql_socket_recvmsg(__FILE__, __LINE__, SD, M, FL)
 #else
-  #define mysql_socket_recvmsg(SD, M, FL) \
+  #define_mysql_socket_recvmsg(SD, M, FL) \
     inline_mysql_socket_recvmsg(SD, M, FL)
 #endif
-		
+
 #ifdef HAVE_PSI_INTERFACE
   #define mysql_socket_getsockopt(SD, LV, ON, OP, OL) \
-    inline mysql_socket_getsockopt(__FILE__, __LINE__, SD, LV, ON, OP, OL)
+    inline_mysql_socket_getsockopt(__FILE__, __LINE__, SD, LV, ON, OP, OL)
 #else
   #define mysql_socket_getsockopt(SD, LV, ON, OP, OL) \
     inline_mysql_socket_getsockopt(SD, LV, ON, OP, OL)
 #endif
-		
+
 #ifdef HAVE_PSI_INTERFACE
   #define mysql_socket_setsockopt(SD, LV, ON, OP, OL) \
-    inline mysql_socket_setsockopt(__FILE__, __LINE__, SD, LV, ON, OP, OL)
+    inline_mysql_socket_setsockopt(__FILE__, __LINE__, SD, LV, ON, OP, OL)
 #else
   #define mysql_socket_setsockopt(SD, LV, ON, OP, OL) \
     inline_mysql_socket_setsockopt(SD, LV, ON, OP, OL)
 #endif
-		
+
 #ifdef HAVE_PSI_INTERFACE
   #define mysql_socket_listen(SD, N) \
-    inline mysql_socket_listen(__FILE__, __LINE__, SD, N)
+    inline_mysql_socket_listen(__FILE__, __LINE__, SD, N)
 #else
   #define mysql_socket_listen(SD, N) \
     inline_mysql_socket_listen(SD, N)
 #endif
-		
+
 #ifdef HAVE_PSI_INTERFACE
   #define mysql_socket_accept(SD, A, LP) \
-    inline mysql_socket_accept(__FILE__, __LINE__, SD, A, LP)
+    inline_mysql_socket_accept(__FILE__, __LINE__, SD, A, LP)
 #else
   #define mysql_socket_accept(SD, A, LP) \
     inline_mysql_socket_accept(SD, A, LP)
 #endif
-		
+
 #ifdef HAVE_PSI_INTERFACE
   #define mysql_socket_accept4(SD, A, LP, FL) \
-    inline mysql_socket_accept4(__FILE__, __LINE__, SD, A, LP, FL)
+    inline_mysql_socket_accept4(__FILE__, __LINE__, SD, A, LP, FL)
 #else
   #define mysql_socket_accept4(SD, A, LP, FL) \
     inline_mysql_socket_accept4(SD, A, LP, FL)
 #endif
-		
+
+#ifdef HAVE_PSI_INTERFACE
+  #define mysql_socket_close(SD) \
+    inline_mysql_socket_close(__FILE__, __LINE__, SD)
+#else
+  #define mysql_socket_close(SD) \
+    inline_mysql_socket_close(SD)
+#endif
+
 #ifdef HAVE_PSI_INTERFACE
   #define mysql_socket_shutdown(SD, H) \
-    inline mysql_socket_shutdown(__FILE__, __LINE__, SD, H)
+    inline_mysql_socket_shutdown(__FILE__, __LINE__, SD, H)
 #else
   #define mysql_socket_shutdown(SD, H) \
     inline_mysql_socket_shutdown(SD, H)
 #endif
-		
+
 #ifdef HAVE_PSI_INTERFACE
   #define mysql_socket_sockatmark(SD) \
-    inline mysql_socket_sockatmark(__FILE__, __LINE__, SD)
+    inline_mysql_socket_sockatmark(__FILE__, __LINE__, SD)
 #else
   #define mysql_socket_sockatmark(SD) \
     inline_mysql_socket_sockatmark(SD)
 #endif
-		
+
 #ifdef HAVE_PSI_INTERFACE
   #define mysql_socket_isfdtype(SD, FT) \
-    inline mysql_socket_isfdtype(__FILE__, __LINE__, SD, FT)
+    inline_mysql_socket_isfdtype(__FILE__, __LINE__, SD, FT)
 #else
   #define mysql_socket_isfdtype(SD, FT) \
     inline_mysql_socket_isfdtype(SD, FT)
 #endif
-		
-/**
-int socket (int domain, int type, int protocol);
-int socketpair (int domain, int type, int protocol, int fds[2]);
-int bind (int fd, CONST_SOCKADDR_ARG addr, socklen_t len);
-int getsockname (int fd, SOCKADDR_ARG addr, socklen_t *restrict len);
-int connect (int fd, CONST_SOCKADDR_ARG addr, socklen_t len);
-int getpeername (int fd, SOCKADDR_ARG addr, socklen_t *restrict len);
-ssize_t send (int fd, const void *buf, size_t n, int flags);
-ssize_t recv (int fd, void *buf, size_t n, int flags);
-ssize_t sendto (int fd, const void *buf, size_t n, int flags, CONST_SOCKADDR_ARG addr, socklen_t addr_len);
-ssize_t recvfrom (int fd, void *restrict buf, size_t n, int flags, SOCKADDR_ARG addr, socklen_t *restrict addr_len);
-ssize_t sendmsg (int fd, const struct msghdr *message, int flags);
-ssize_t recvmsg (int fd, struct msghdr *message, int flags);
-int getsockopt (int fd, int level, int optname, void *restrict optval, socklen_t *restrict optlen);
-int setsockopt (int fd, int level, int optname, const void *optval, socklen_t optlen);
-int listen (int fd, int n);
-int accept (int fd, SOCKADDR_ARG addr, socklen_t *restrict addr_len);
-int accept4 (int fd, SOCKADDR_ARG addr, socklen_t *restrict addr_len, int flags);
-int shutdown (int fd, int how);
-int sockatmark (int fd);
-int isfdtype (int fd, int fdtype);
-*/
 
 struct st_mysql_socket
 {
@@ -244,37 +295,28 @@ struct st_mysql_socket
   @sa mysql_file_open
 */
 
-typedef struct st_mysql_socket_t MYSQL_SOCKET;
+typedef struct st_mysql_socket MYSQL_SOCKET;
 
+#define mysql_socket_getsd(SD) ((SD).sd)
 
 /** mysql_socket_socket */
 
-static inline int
+static inline MYSQL_SOCKET
 inline_mysql_socket_socket
 (
 #ifdef HAVE_PSI_INTERFACE
-  const char *src_file, uint src_line,
+  PSI_socket_key key, const char *src_file, uint src_line,
 #endif
   int domain, int type, int protocol)
 {
-  int result = 0;
-#if 0  
+  MYSQL_SOCKET mysql_socket = {0, NULL};
 #ifdef HAVE_PSI_INTERFACE
-  struct PSI_socket_locker *locker= NULL;
-  if (likely(PSI_server != NULL))
-  {
-    locker= PSI_server->get_thread_socket_locker(sd->m_psi, PSI_SOCKET_CREATE);
-	if (likely(locker !=NULL))
-	  PSI_server->start_socket_wait(locker, src_file, src_line);
-  }
+  mysql_socket.m_psi = PSI_server ? PSI_server->init_socket(key, &mysql_socket.sd)
+                                  : NULL;
 #endif
-  result= socket(int domain, int type, int protocol);
-#ifdef HAVE_PSI_INTERFACE
-  if (likely(locker != NULL))
-    PSI_server->end_socket_wait(locker, socket);
-#endif
-#endif
-  return result;
+  mysql_socket.sd= socket(domain, type, protocol);
+
+  return mysql_socket;
 }
 
 /** mysql_socket_socketpair */
@@ -288,20 +330,20 @@ inline_mysql_socket_socketpair
   int domain, int type, int protocol, int fds[2])
 {
   int result = 0;
-#if 0
+#if 0 //TBD
 #ifdef HAVE_PSI_INTERFACE
   struct PSI_socket_locker *locker= NULL;
   if (likely(PSI_server != NULL))
   {
-    locker= PSI_server->get_thread_socket_locker(sd->m_psi, PSI_SOCKET_CREATE);
-	if (likely(locker !=NULL))
-	  PSI_server->start_socket_wait(locker, src_file, src_line);
+    locker= PSI_server->get_thread_socket_locker(mysql_socket.m_psi, PSI_SOCKET_CREATE);
+  if (likely(locker !=NULL))
+    PSI_server->start_socket_wait(locker, src_file, src_line);
   }
 #endif
   result= socketpair(int domain, int type, int protocol, int fds[2]);
 #ifdef HAVE_PSI_INTERFACE
   if (likely(locker != NULL))
-    PSI_server->end_socket_wait(locker, socket);
+    PSI_server->end_socket_wait(locker);
 #endif
 #endif
   return result;
@@ -315,22 +357,22 @@ inline_mysql_socket_bind
 #ifdef HAVE_PSI_INTERFACE
   const char *src_file, uint src_line,
 #endif
-  MYSQL_SOCKET *sd, CONST_SOCKADDR_ARG addr, socklen_t len)
+  MYSQL_SOCKET mysql_socket, __CONST_SOCKADDR_ARG addr, socklen_t len)
 {
   int result;
 #ifdef HAVE_PSI_INTERFACE
   struct PSI_socket_locker *locker= NULL;
   if (likely(PSI_server != NULL))
   {
-    locker= PSI_server->get_thread_socket_locker(sd->m_psi, PSI_SOCKET_BIND);
-	if (likely(locker !=NULL))
-	  PSI_server->start_socket_wait(locker, src_file, src_line);
+    locker= PSI_server->get_thread_socket_locker(mysql_socket.m_psi, PSI_SOCKET_BIND);
+    if (likely(locker !=NULL))
+      PSI_server->start_socket_wait(locker, src_file, src_line);
   }
 #endif
-  result= bind(sd->sd, addr, len);
+  result= bind(mysql_socket.sd, addr, len);
 #ifdef HAVE_PSI_INTERFACE
   if (likely(locker != NULL))
-    PSI_server->end_socket_wait(locker, socket);
+    PSI_server->end_socket_wait(locker);
 #endif
   return result;
 }
@@ -343,22 +385,22 @@ inline_mysql_socket_getsockname
 #ifdef HAVE_PSI_INTERFACE
   const char *src_file, uint src_line,
 #endif
- MYSQL_SOCKET *sd, SOCKADDR_ARG addr, socklen_t *restrict len)
+ MYSQL_SOCKET mysql_socket, __SOCKADDR_ARG addr, socklen_t *len)
 {
   int result;
 #ifdef HAVE_PSI_INTERFACE
   struct PSI_socket_locker *locker= NULL;
   if (likely(PSI_server != NULL))
   {
-    locker= PSI_server->get_thread_socket_locker(sd->m_psi, PSI_SOCKET_BIND);
-	if (likely(locker !=NULL))
-	  PSI_server->start_socket_wait(locker, src_file, src_line);
+    locker= PSI_server->get_thread_socket_locker(mysql_socket.m_psi, PSI_SOCKET_BIND);
+    if (likely(locker !=NULL))
+      PSI_server->start_socket_wait(locker, src_file, src_line);
   }
 #endif
-  result= getsockname(sd->sd, addr, len);
+  result= getsockname(mysql_socket.sd, addr, len);
 #ifdef HAVE_PSI_INTERFACE
   if (likely(locker != NULL))
-    PSI_server->end_socket_wait(locker, socket);
+    PSI_server->end_socket_wait(locker);
 #endif
   return result;
 }
@@ -371,22 +413,22 @@ inline_mysql_socket_connect
 #ifdef HAVE_PSI_INTERFACE
   const char *src_file, uint src_line,
 #endif
- MYSQL_SOCKET *sd,  CONST_SOCKADDR_ARG addr, socklen_t len)
+ MYSQL_SOCKET mysql_socket, __CONST_SOCKADDR_ARG addr, socklen_t len)
 {
   int result;
 #ifdef HAVE_PSI_INTERFACE
   struct PSI_socket_locker *locker= NULL;
   if (likely(PSI_server != NULL))
   {
-    locker= PSI_server->get_thread_socket_locker(sd->m_psi, PSI_SOCKET_CONNECT);
-	if (likely(locker !=NULL))
-	  PSI_server->start_socket_wait(locker, src_file, src_line);
+    locker= PSI_server->get_thread_socket_locker(mysql_socket.m_psi, PSI_SOCKET_CONNECT);
+    if (likely(locker !=NULL))
+      PSI_server->start_socket_wait(locker, src_file, src_line);
   }
 #endif
-  result= connect(sd->sd, addr, len);
+  result= connect(mysql_socket.sd, addr, len);
 #ifdef HAVE_PSI_INTERFACE
   if (likely(locker != NULL))
-    PSI_server->end_socket_wait(locker, socket);
+    PSI_server->end_socket_wait(locker);
 #endif
   return result;
 }
@@ -399,22 +441,22 @@ inline_mysql_socket_getpeername
 #ifdef HAVE_PSI_INTERFACE
   const char *src_file, uint src_line,
 #endif
- MYSQL_SOCKET *sd,  SOCKADDR_ARG addr, socklen_t *restrict len)
+ MYSQL_SOCKET mysql_socket, __SOCKADDR_ARG addr, socklen_t *len)
 {
   int result;
 #ifdef HAVE_PSI_INTERFACE
   struct PSI_socket_locker *locker= NULL;
   if (likely(PSI_server != NULL))
   {
-    locker= PSI_server->get_thread_socket_locker(sd->m_psi, PSI_SOCKET_BIND);
-	if (likely(locker !=NULL))
-	  PSI_server->start_socket_wait(locker, src_file, src_line);
+    locker= PSI_server->get_thread_socket_locker(mysql_socket.m_psi, PSI_SOCKET_BIND);
+    if (likely(locker !=NULL))
+      PSI_server->start_socket_wait(locker, src_file, src_line);
   }
 #endif
-  result= getpeername(sd->sd, addr, *restrict len);
+  result= getpeername(mysql_socket.sd, addr, len);
 #ifdef HAVE_PSI_INTERFACE
   if (likely(locker != NULL))
-    PSI_server->end_socket_wait(locker, socket);
+    PSI_server->end_socket_wait(locker);
 #endif
   return result;
 }
@@ -427,22 +469,22 @@ inline_mysql_socket_send
 #ifdef HAVE_PSI_INTERFACE
   const char *src_file, uint src_line,
 #endif
- MYSQL_SOCKET *sd, const void *buf, size_t n, int flags)
+ MYSQL_SOCKET mysql_socket, const void *buf, size_t n, int flags)
 {
   ssize_t result;
 #ifdef HAVE_PSI_INTERFACE
   struct PSI_socket_locker *locker= NULL;
   if (likely(PSI_server != NULL))
   {
-    locker= PSI_server->get_thread_socket_locker(sd->m_psi, PSI_SOCKET_SEND);
-	if (likely(locker !=NULL))
-	  PSI_server->start_socket_wait(locker, src_file, src_line);
+    locker= PSI_server->get_thread_socket_locker(mysql_socket.m_psi, PSI_SOCKET_SEND);
+    if (likely(locker !=NULL))
+      PSI_server->start_socket_wait(locker, src_file, src_line);
   }
 #endif
-  result= send(sd->sd, buf, n, flags);
+  result= send(mysql_socket.sd, buf, n, flags);
 #ifdef HAVE_PSI_INTERFACE
   if (likely(locker != NULL))
-    PSI_server->end_socket_wait(locker, socket);
+    PSI_server->end_socket_wait(locker);
 #endif
   return result;
 }
@@ -455,22 +497,22 @@ inline_mysql_socket_recv
 #ifdef HAVE_PSI_INTERFACE
   const char *src_file, uint src_line,
 #endif
- MYSQL_SOCKET *sd,  void *buf, size_t n, int flags)
+ MYSQL_SOCKET mysql_socket,  void *buf, size_t n, int flags)
 {
   ssize_t result;
 #ifdef HAVE_PSI_INTERFACE
   struct PSI_socket_locker *locker= NULL;
   if (likely(PSI_server != NULL))
   {
-    locker= PSI_server->get_thread_socket_locker(sd->m_psi, PSI_SOCKET_RECV);
-	if (likely(locker !=NULL))
-	  PSI_server->start_socket_wait(locker, src_file, src_line);
+    locker= PSI_server->get_thread_socket_locker(mysql_socket.m_psi, PSI_SOCKET_RECV);
+    if (likely(locker !=NULL))
+      PSI_server->start_socket_wait(locker, src_file, src_line);
   }
 #endif
-  result= recv(sd->sd, buf, n, flags);
+  result= recv(mysql_socket.sd, buf, n, flags);
 #ifdef HAVE_PSI_INTERFACE
   if (likely(locker != NULL))
-    PSI_server->end_socket_wait(locker, socket);
+    PSI_server->end_socket_wait(locker);
 #endif
   return result;
 }
@@ -483,22 +525,22 @@ inline_mysql_socket_sendto
 #ifdef HAVE_PSI_INTERFACE
   const char *src_file, uint src_line,
 #endif
- MYSQL_SOCKET *sd,  const void *buf, size_t n, int flags, CONST_SOCKADDR_ARG addr, socklen_t addr_len)
+ MYSQL_SOCKET mysql_socket, const void *buf, size_t n, int flags, __CONST_SOCKADDR_ARG addr, socklen_t addr_len)
 {
   ssize_t result;
 #ifdef HAVE_PSI_INTERFACE
   struct PSI_socket_locker *locker= NULL;
   if (likely(PSI_server != NULL))
   {
-    locker= PSI_server->get_thread_socket_locker(sd->m_psi, PSI_SOCKET_SEND);
-	if (likely(locker !=NULL))
-	  PSI_server->start_socket_wait(locker, src_file, src_line);
+    locker= PSI_server->get_thread_socket_locker(mysql_socket.m_psi, PSI_SOCKET_SEND);
+    if (likely(locker !=NULL))
+      PSI_server->start_socket_wait(locker, src_file, src_line);
   }
 #endif
-  result= sendto(sd->sd, buf, n, flags, addr, addr_len);
+  result= sendto(mysql_socket.sd, buf, n, flags, addr, addr_len);
 #ifdef HAVE_PSI_INTERFACE
   if (likely(locker != NULL))
-    PSI_server->end_socket_wait(locker, socket);
+    PSI_server->end_socket_wait(locker);
 #endif
   return result;
 }
@@ -511,22 +553,22 @@ inline_mysql_socket_recvfrom
 #ifdef HAVE_PSI_INTERFACE
   const char *src_file, uint src_line,
 #endif
- MYSQL_SOCKET *sd,  void *restrict buf, size_t n, int flags, SOCKADDR_ARG addr, socklen_t *restrict addr_len)
+ MYSQL_SOCKET mysql_socket, void *buf, size_t n, int flags, __SOCKADDR_ARG addr, socklen_t *addr_len)
 {
   ssize_t result;
 #ifdef HAVE_PSI_INTERFACE
   struct PSI_socket_locker *locker= NULL;
   if (likely(PSI_server != NULL))
   {
-    locker= PSI_server->get_thread_socket_locker(sd->m_psi, PSI_SOCKET_RECV);
-	if (likely(locker !=NULL))
-	  PSI_server->start_socket_wait(locker, src_file, src_line);
+    locker= PSI_server->get_thread_socket_locker(mysql_socket.m_psi, PSI_SOCKET_RECV);
+    if (likely(locker !=NULL))
+      PSI_server->start_socket_wait(locker, src_file, src_line);
   }
 #endif
-  result= recvfrom(sd->sd, buf, n, lags, addr, addr_len);
+  result= recvfrom(mysql_socket.sd, buf, n, flags, addr, addr_len);
 #ifdef HAVE_PSI_INTERFACE
   if (likely(locker != NULL))
-    PSI_server->end_socket_wait(locker, socket);
+    PSI_server->end_socket_wait(locker);
 #endif
   return result;
 }
@@ -539,22 +581,22 @@ inline_mysql_socket_sendmsg
 #ifdef HAVE_PSI_INTERFACE
   const char *src_file, uint src_line,
 #endif
- MYSQL_SOCKET *sd, const struct msghdr *message, int flags)
+ MYSQL_SOCKET mysql_socket, const struct msghdr *message, int flags)
 {
   ssize_t result;
 #ifdef HAVE_PSI_INTERFACE
   struct PSI_socket_locker *locker= NULL;
   if (likely(PSI_server != NULL))
   {
-    locker= PSI_server->get_thread_socket_locker(sd->m_psi, PSI_SOCKET_SEND);
-	if (likely(locker !=NULL))
-	  PSI_server->start_socket_wait(locker, src_file, src_line);
+    locker= PSI_server->get_thread_socket_locker(mysql_socket.m_psi, PSI_SOCKET_SEND);
+    if (likely(locker !=NULL))
+      PSI_server->start_socket_wait(locker, src_file, src_line);
   }
 #endif
-  result= sendmsg(sd->sd, message, flags);
+  result= sendmsg(mysql_socket.sd, message, flags);
 #ifdef HAVE_PSI_INTERFACE
   if (likely(locker != NULL))
-    PSI_server->end_socket_wait(locker, socket);
+    PSI_server->end_socket_wait(locker);
 #endif
   return result;
 }
@@ -567,22 +609,22 @@ inline_mysql_socket_recvmsg
 #ifdef HAVE_PSI_INTERFACE
   const char *src_file, uint src_line,
 #endif
- MYSQL_SOCKET *sd, struct msghdr *message, int flags)
+ MYSQL_SOCKET mysql_socket, struct msghdr *message, int flags)
 {
   ssize_t result;
 #ifdef HAVE_PSI_INTERFACE
   struct PSI_socket_locker *locker= NULL;
   if (likely(PSI_server != NULL))
   {
-    locker= PSI_server->get_thread_socket_locker(sd->m_psi, PSI_SOCKET_RECV);
-	if (likely(locker !=NULL))
-	  PSI_server->start_socket_wait(locker, src_file, src_line);
+    locker= PSI_server->get_thread_socket_locker(mysql_socket.m_psi, PSI_SOCKET_RECV);
+    if (likely(locker !=NULL))
+      PSI_server->start_socket_wait(locker, src_file, src_line);
   }
 #endif
-  result= recvmsg(sd->sd, message, flags);
+  result= recvmsg(mysql_socket.sd, message, flags);
 #ifdef HAVE_PSI_INTERFACE
   if (likely(locker != NULL))
-    PSI_server->end_socket_wait(locker, socket);
+    PSI_server->end_socket_wait(locker);
 #endif
   return result;
 }
@@ -595,22 +637,22 @@ inline_mysql_socket_getsockopt
 #ifdef HAVE_PSI_INTERFACE
   const char *src_file, uint src_line,
 #endif
- MYSQL_SOCKET *sd, int level, int optname, void *restrict optval, socklen_t *restrict optlen)
+ MYSQL_SOCKET mysql_socket, int level, int optname, void *optval, socklen_t *optlen)
 {
   int result;
 #ifdef HAVE_PSI_INTERFACE
   struct PSI_socket_locker *locker= NULL;
   if (likely(PSI_server != NULL))
   {
-    locker= PSI_server->get_thread_socket_locker(sd->m_psi, PSI_SOCKET_OPT);
-	if (likely(locker !=NULL))
-	  PSI_server->start_socket_wait(locker, src_file, src_line);
+    locker= PSI_server->get_thread_socket_locker(mysql_socket.m_psi, PSI_SOCKET_OPT);
+    if (likely(locker !=NULL))
+      PSI_server->start_socket_wait(locker, src_file, src_line);
   }
 #endif
-  result= getsockopt(sd->sd, level, optname, optval, optlen);
+  result= getsockopt(mysql_socket.sd, level, optname, optval, optlen);
 #ifdef HAVE_PSI_INTERFACE
   if (likely(locker != NULL))
-    PSI_server->end_socket_wait(locker, socket);
+    PSI_server->end_socket_wait(locker);
 #endif
   return result;
 }
@@ -623,22 +665,22 @@ inline_mysql_socket_setsockopt
 #ifdef HAVE_PSI_INTERFACE
   const char *src_file, uint src_line,
 #endif
- MYSQL_SOCKET *sd, int level, int optname, const void *optval, socklen_t optlen)
+ MYSQL_SOCKET mysql_socket, int level, int optname, const void *optval, socklen_t optlen)
 {
   int result;
 #ifdef HAVE_PSI_INTERFACE
   struct PSI_socket_locker *locker= NULL;
   if (likely(PSI_server != NULL))
   {
-    locker= PSI_server->get_thread_socket_locker(sd->m_psi, PSI_SOCKET_OPT);
-	if (likely(locker !=NULL))
-	  PSI_server->start_socket_wait(locker, src_file, src_line);
+    locker= PSI_server->get_thread_socket_locker(mysql_socket.m_psi, PSI_SOCKET_OPT);
+    if (likely(locker !=NULL))
+      PSI_server->start_socket_wait(locker, src_file, src_line);
   }
 #endif
-  result= setsockopt(sd->sd, level, optname, optval, optlen);
+  result= setsockopt(mysql_socket.sd, level, optname, optval, optlen);
 #ifdef HAVE_PSI_INTERFACE
   if (likely(locker != NULL))
-    PSI_server->end_socket_wait(locker, socket);
+    PSI_server->end_socket_wait(locker);
 #endif
   return result;
 }
@@ -651,78 +693,108 @@ inline_mysql_socket_listen
 #ifdef HAVE_PSI_INTERFACE
   const char *src_file, uint src_line,
 #endif
- MYSQL_SOCKET *sd, int n)
+ MYSQL_SOCKET mysql_socket, int n)
 {
   int result;
 #ifdef HAVE_PSI_INTERFACE
   struct PSI_socket_locker *locker= NULL;
   if (likely(PSI_server != NULL))
   {
-    locker= PSI_server->get_thread_socket_locker(sd->m_psi, PSI_SOCKET_CONNECT);
-	if (likely(locker !=NULL))
-	  PSI_server->start_socket_wait(locker, src_file, src_line);
+    locker= PSI_server->get_thread_socket_locker(mysql_socket.m_psi, PSI_SOCKET_CONNECT);
+    if (likely(locker !=NULL))
+      PSI_server->start_socket_wait(locker, src_file, src_line);
   }
 #endif
-  result= listen(sd->sd, n);
+  result= listen(mysql_socket.sd, n);
 #ifdef HAVE_PSI_INTERFACE
   if (likely(locker != NULL))
-    PSI_server->end_socket_wait(locker, socket);
+    PSI_server->end_socket_wait(locker);
 #endif
   return result;
 }
 
 /** mysql_socket_accept */
 
-static inline int
+static inline MYSQL_SOCKET
 inline_mysql_socket_accept
 (
 #ifdef HAVE_PSI_INTERFACE
   const char *src_file, uint src_line,
 #endif
- MYSQL_SOCKET *sd, SOCKADDR_ARG addr, socklen_t *restrict addr_len)
+ MYSQL_SOCKET mysql_socket, __SOCKADDR_ARG addr, socklen_t *addr_len)
 {
-  int result;
+  MYSQL_SOCKET result = mysql_socket;
+  result.sd = 0;
 #ifdef HAVE_PSI_INTERFACE
   struct PSI_socket_locker *locker= NULL;
   if (likely(PSI_server != NULL))
   {
-    locker= PSI_server->get_thread_socket_locker(sd->m_psi, PSI_SOCKET_CONNECT);
-	if (likely(locker !=NULL))
-	  PSI_server->start_socket_wait(locker, src_file, src_line);
+    locker= PSI_server->get_thread_socket_locker(mysql_socket.m_psi, PSI_SOCKET_CONNECT);
+    if (likely(locker !=NULL))
+      PSI_server->start_socket_wait(locker, src_file, src_line);
   }
 #endif
-  result= accept(sd->sd, addr, addr_len);
+  result.sd= accept(mysql_socket.sd, addr, addr_len);
 #ifdef HAVE_PSI_INTERFACE
   if (likely(locker != NULL))
-    PSI_server->end_socket_wait(locker, socket);
+    PSI_server->end_socket_wait(locker);
 #endif
   return result;
 }
 
 /** mysql_socket_accept4 */
 
-static inline int
+static inline MYSQL_SOCKET
 inline_mysql_socket_accept4
 (
 #ifdef HAVE_PSI_INTERFACE
   const char *src_file, uint src_line,
 #endif
- MYSQL_SOCKET *sd, SOCKADDR_ARG addr, socklen_t *restrict addr_len, int flags)
+ MYSQL_SOCKET mysql_socket, __SOCKADDR_ARG addr, socklen_t *addr_len, int flags)
+{
+  MYSQL_SOCKET result = mysql_socket;
+  result.sd = 0;
+#ifdef HAVE_PSI_INTERFACE
+  struct PSI_socket_locker *locker= NULL;
+  if (likely(PSI_server != NULL))
+  {
+    locker= PSI_server->get_thread_socket_locker(mysql_socket.m_psi, PSI_SOCKET_CONNECT);
+    if (likely(locker !=NULL))
+      PSI_server->start_socket_wait(locker, src_file, src_line);
+  }
+#endif
+  result.sd= accept4(mysql_socket.sd, addr, addr_len, flags);
+#ifdef HAVE_PSI_INTERFACE
+  if (likely(locker != NULL))
+    PSI_server->end_socket_wait(locker);
+#endif
+  return result;
+}
+
+/** mysql_socket_close */
+
+static inline int
+inline_mysql_socket_close
+(
+#ifdef HAVE_PSI_INTERFACE
+  const char *src_file, uint src_line,
+#endif
+  MYSQL_SOCKET mysql_socket)
 {
   int result;
 #ifdef HAVE_PSI_INTERFACE
   struct PSI_socket_locker *locker= NULL;
   if (likely(PSI_server != NULL))
   {
-    locker= PSI_server->get_thread_socket_locker(sd->m_psi, PSI_SOCKET_CONNECT);
-	if (likely(locker !=NULL))
-	  PSI_server->start_socket_wait(locker, src_file, src_line);
+    locker= PSI_server->get_thread_socket_locker(mysql_socket.m_psi, PSI_SOCKET_CLOSE);
+    if (likely(locker !=NULL))
+      PSI_server->start_socket_wait(locker, src_file, src_line);
   }
 #endif
-  result= accept4(sd->sd, addr, addr_len, flags);
+  result= closesocket(mysql_socket.sd);
 #ifdef HAVE_PSI_INTERFACE
   if (likely(locker != NULL))
-    PSI_server->end_socket_wait(locker, socket);
+    PSI_server->end_socket_wait(locker);
 #endif
   return result;
 }
@@ -735,22 +807,22 @@ inline_mysql_socket_shutdown
 #ifdef HAVE_PSI_INTERFACE
   const char *src_file, uint src_line,
 #endif
- MYSQL_SOCKET *sd, int how)
+  MYSQL_SOCKET mysql_socket, int how)
 {
   int result;
 #ifdef HAVE_PSI_INTERFACE
   struct PSI_socket_locker *locker= NULL;
   if (likely(PSI_server != NULL))
   {
-    locker= PSI_server->get_thread_socket_locker(sd->m_psi, PSI_SOCKET_CLOSE);
-	if (likely(locker !=NULL))
-	  PSI_server->start_socket_wait(locker, src_file, src_line);
+    locker= PSI_server->get_thread_socket_locker(mysql_socket.m_psi, PSI_SOCKET_SHUTDOWN);
+    if (likely(locker !=NULL))
+      PSI_server->start_socket_wait(locker, src_file, src_line);
   }
 #endif
-  result= shutdown(sd->sd, how);
+  result= shutdown(mysql_socket.sd, how);
 #ifdef HAVE_PSI_INTERFACE
   if (likely(locker != NULL))
-    PSI_server->end_socket_wait(locker, socket);
+    PSI_server->end_socket_wait(locker);
 #endif
   return result;
 }
@@ -763,22 +835,22 @@ inline_mysql_socket_sockatmark
 #ifdef HAVE_PSI_INTERFACE
   const char *src_file, uint src_line,
 #endif
-  MYSQL_SOCKET *sd)
+  MYSQL_SOCKET mysql_socket)
 {
   int result;
 #ifdef HAVE_PSI_INTERFACE
   struct PSI_socket_locker *locker= NULL;
   if (likely(PSI_server != NULL))
   {
-    locker= PSI_server->get_thread_socket_locker(sd->m_psi, PSI_SOCKET_STAT);
-	if (likely(locker !=NULL))
-	  PSI_server->start_socket_wait(locker, src_file, src_line);
+    locker= PSI_server->get_thread_socket_locker(mysql_socket.m_psi, PSI_SOCKET_STAT);
+    if (likely(locker !=NULL))
+      PSI_server->start_socket_wait(locker, src_file, src_line);
   }
 #endif
-  result= sockatmark(sd->sd);
+  result= sockatmark(mysql_socket.sd);
 #ifdef HAVE_PSI_INTERFACE
   if (likely(locker != NULL))
-    PSI_server->end_socket_wait(locker, socket);
+    PSI_server->end_socket_wait(locker);
 #endif
   return result;
 }
@@ -791,29 +863,28 @@ inline_mysql_socket_isfdtype
 #ifdef HAVE_PSI_INTERFACE
   const char *src_file, uint src_line,
 #endif
- MYSQL_SOCKET *sd,  int fdtype)
+ MYSQL_SOCKET mysql_socket, int fdtype)
 {
   int result;
 #ifdef HAVE_PSI_INTERFACE
   struct PSI_socket_locker *locker= NULL;
   if (likely(PSI_server != NULL))
   {
-    locker= PSI_server->get_thread_socket_locker(sd->m_psi, PSI_SOCKET_STAT);
-	if (likely(locker !=NULL))
-	  PSI_server->start_socket_wait(locker, src_file, src_line);
+    locker= PSI_server->get_thread_socket_locker(mysql_socket.m_psi, PSI_SOCKET_STAT);
+    if (likely(locker !=NULL))
+      PSI_server->start_socket_wait(locker, src_file, src_line);
   }
 #endif
-  result= isfdtype(sd->sd, fdtype);
+  result= isfdtype(mysql_socket.sd, fdtype);
 #ifdef HAVE_PSI_INTERFACE
   if (likely(locker != NULL))
-    PSI_server->end_socket_wait(locker, socket);
+    PSI_server->end_socket_wait(locker);
 #endif
   return result;
 }
 
 
-
-/** @} (end of group Network_instrumentation) */
+/** @} (end of group Socket_instrumentation) */
 
 #endif
 

=== modified file 'include/mysql/psi/psi.h'
--- a/include/mysql/psi/psi.h	2010-06-09 20:19:47 +0000
+++ b/include/mysql/psi/psi.h	2010-06-22 23:02:37 +0000
@@ -263,7 +263,10 @@ enum PSI_socket_operation
   PSI_SOCKET_OPT= 7,
 
   /** Socket status, as in @c sockatmark() and @c isfdtype(). */
-  PSI_SOCKET_STAT= 8
+  PSI_SOCKET_STAT= 8,
+
+  /** Socket shutdown, as in @c shutdown(). */
+  PSI_SOCKET_SHUTDOWN= 9
 };
 
 
@@ -591,6 +594,21 @@ typedef struct PSI_cond* (*init_cond_v1_
 typedef void (*destroy_cond_v1_t)(struct PSI_cond *cond);
 
 /**
+  Socket instrumentation initialisation API.
+  @param key the registered mutex key
+  @param identity the address of the socket itself
+  @return an instrumented socket
+*/
+typedef struct PSI_socket* (*init_socket_v1_t)
+  (PSI_socket_key key, const void *identity);
+
+/**
+  socket instrumentation destruction API.
+  @param socket the socket to destroy
+*/
+typedef void (*destroy_socket_v1_t)(struct PSI_socket *socket);
+
+/**
   Acquire a table info by name.
   @param schema_name name of the table schema
   @param schema_name_length length of schema_name
@@ -979,6 +997,10 @@ struct PSI_v1
   init_cond_v1_t init_cond;
   /** @sa destroy_cond_v1_t. */
   destroy_cond_v1_t destroy_cond;
+  /** @sa init_socket_v1_t. */
+  init_socket_v1_t init_socket;
+  /** @sa destroy_socket_v1_t. */
+  destroy_socket_v1_t destroy_socket;
   /** @sa get_table_share_v1_t. */
   get_table_share_v1_t get_table_share;
   /** @sa release_table_share_v1_t. */

=== modified file 'include/mysql/psi/psi_abi_v1.h.pp'
--- a/include/mysql/psi/psi_abi_v1.h.pp	2010-06-09 20:19:47 +0000
+++ b/include/mysql/psi/psi_abi_v1.h.pp	2010-06-22 23:02:37 +0000
@@ -63,7 +63,8 @@ enum PSI_socket_operation
   PSI_SOCKET_RECV= 5,
   PSI_SOCKET_SEEK= 6,
   PSI_SOCKET_OPT= 7,
-  PSI_SOCKET_STAT= 8
+  PSI_SOCKET_STAT= 8,
+  PSI_SOCKET_SHUTDOWN= 9
 };
 struct PSI_table_locker;
 typedef unsigned int PSI_mutex_key;
@@ -129,6 +130,9 @@ typedef void (*destroy_rwlock_v1_t)(stru
 typedef struct PSI_cond* (*init_cond_v1_t)
   (PSI_cond_key key, const void *identity);
 typedef void (*destroy_cond_v1_t)(struct PSI_cond *cond);
+typedef struct PSI_socket* (*init_socket_v1_t)
+  (PSI_socket_key key, const void *identity);
+typedef void (*destroy_socket_v1_t)(struct PSI_socket *socket);
 typedef struct PSI_table_share* (*get_table_share_v1_t)
   (const char *schema_name, int schema_name_length, const char *table_name,
    int table_name_length, const void *identity);
@@ -224,6 +228,8 @@ struct PSI_v1
   destroy_rwlock_v1_t destroy_rwlock;
   init_cond_v1_t init_cond;
   destroy_cond_v1_t destroy_cond;
+  init_socket_v1_t init_socket;
+  destroy_socket_v1_t destroy_socket;
   get_table_share_v1_t get_table_share;
   release_table_share_v1_t release_table_share;
   open_table_v1_t open_table;

=== modified file 'include/mysql/psi/psi_abi_v2.h.pp'
--- a/include/mysql/psi/psi_abi_v2.h.pp	2010-06-09 20:19:47 +0000
+++ b/include/mysql/psi/psi_abi_v2.h.pp	2010-06-22 23:02:37 +0000
@@ -63,7 +63,8 @@ enum PSI_socket_operation
   PSI_SOCKET_RECV= 5,
   PSI_SOCKET_SEEK= 6,
   PSI_SOCKET_OPT= 7,
-  PSI_SOCKET_STAT= 8
+  PSI_SOCKET_STAT= 8,
+  PSI_SOCKET_SHUTDOWN= 9
 };
 struct PSI_table_locker;
 typedef unsigned int PSI_mutex_key;

=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc	2010-05-12 07:09:20 +0000
+++ b/sql/mysqld.cc	2010-06-22 23:02:37 +0000
@@ -68,6 +68,7 @@
 
 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
 #include "../storage/perfschema/pfs_server.h"
+#include <mysql/psi/mysql_socket.h>
 #endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
 
 #include "keycaches.h"
@@ -874,7 +875,7 @@ void buffered_option_error_reporter(enum
 }
 #endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
 
-static my_socket unix_sock,ip_sock;
+static MYSQL_SOCKET unix_sock, ip_sock;
 struct rand_struct sql_rand; ///< used by sql_class.cc:THD::THD()
 
 #ifndef EMBEDDED_LIBRARY
@@ -1065,11 +1066,11 @@ static void close_connections(void)
   DBUG_PRINT("quit",("Closing sockets"));
   if (!opt_disable_networking )
   {
-    if (ip_sock != INVALID_SOCKET)
+    if (mysql_socket_getsd(ip_sock) != INVALID_SOCKET)
     {
-      (void) shutdown(ip_sock, SHUT_RDWR);
-      (void) closesocket(ip_sock);
-      ip_sock= INVALID_SOCKET;
+      (void) mysql_socket_shutdown(ip_sock, SHUT_RDWR);
+      (void) mysql_socket_close(ip_sock);
+      mysql_socket_getsd(ip_sock)= INVALID_SOCKET;
     }
   }
 #ifdef _WIN32
@@ -1097,12 +1098,12 @@ static void close_connections(void)
   }
 #endif
 #ifdef HAVE_SYS_UN_H
-  if (unix_sock != INVALID_SOCKET)
+  if (mysql_socket_getsd(unix_sock) != INVALID_SOCKET)
   {
-    (void) shutdown(unix_sock, SHUT_RDWR);
-    (void) closesocket(unix_sock);
+    (void) mysql_socket_shutdown(unix_sock, SHUT_RDWR);
+    (void) mysql_socket_close(unix_sock);
     (void) unlink(mysqld_unix_port);
-    unix_sock= INVALID_SOCKET;
+    mysql_socket_getsd(unix_sock)= INVALID_SOCKET;
   }
 #endif
   end_thr_alarm(0);			 // Abort old alarms.
@@ -1198,35 +1199,35 @@ static void close_server_sock()
 {
 #ifdef HAVE_CLOSE_SERVER_SOCK
   DBUG_ENTER("close_server_sock");
-  my_socket tmp_sock;
+  MYSQL_SOCKET tmp_sock;
   tmp_sock=ip_sock;
-  if (tmp_sock != INVALID_SOCKET)
+  if (mysql_socket_getsd(tmp_sock) != INVALID_SOCKET)
   {
-    ip_sock=INVALID_SOCKET;
+    mysql_socket_getsd(ip_sock)= INVALID_SOCKET;
     DBUG_PRINT("info",("calling shutdown on TCP/IP socket"));
-    (void) shutdown(tmp_sock, SHUT_RDWR);
+    (void) mysql_socket_shutdown(tmp_sock, SHUT_RDWR);
 #if defined(__NETWARE__)
     /*
       The following code is disabled for normal systems as it causes MySQL
       to hang on AIX 4.3 during shutdown
     */
     DBUG_PRINT("info",("calling closesocket on TCP/IP socket"));
-    (void) closesocket(tmp_sock);
+    (void) mysql_socket_close(tmp_sock);
 #endif
   }
   tmp_sock=unix_sock;
-  if (tmp_sock != INVALID_SOCKET)
+  if (mysql_socket_getsd(tmp_sock) != INVALID_SOCKET)
   {
-    unix_sock=INVALID_SOCKET;
+    mysql_socket_getsd(unix_sock)= INVALID_SOCKET;
     DBUG_PRINT("info",("calling shutdown on unix socket"));
-    (void) shutdown(tmp_sock, SHUT_RDWR);
+    (void) mysql_socket_shutdown(tmp_sock, SHUT_RDWR);
 #if defined(__NETWARE__)
     /*
       The following code is disabled for normal systems as it may cause MySQL
       to hang on AIX 4.3 during shutdown
     */
     DBUG_PRINT("info",("calling closesocket on unix/IP socket"));
-    (void) closesocket(tmp_sock);
+    (void) mysql_socket_close(tmp_sock);
 #endif
     (void) unlink(mysqld_unix_port);
   }
@@ -1852,12 +1853,12 @@ static void network_init(void)
 
     for (a= ai; a != NULL; a= a->ai_next)
     {
-      ip_sock= socket(a->ai_family, a->ai_socktype, a->ai_protocol);
-      if (ip_sock != INVALID_SOCKET)
+      ip_sock= mysql_socket_socket(key_socket_server, a->ai_family, a->ai_socktype, a->ai_protocol);
+      if (mysql_socket_getsd(ip_sock) != INVALID_SOCKET)
         break;
     }
 
-    if (ip_sock == INVALID_SOCKET)
+    if (mysql_socket_getsd(ip_sock) == INVALID_SOCKET)
     {
       DBUG_PRINT("error",("Got error: %d from socket()",socket_errno));
       sql_perror(ER_DEFAULT(ER_IPSOCK_ERROR));  /* purecov: tested */
@@ -1870,7 +1871,7 @@ static void network_init(void)
       user to open two mysqld servers with the same TCP/IP port.
     */
     arg= 1;
-    (void) setsockopt(ip_sock,SOL_SOCKET,SO_REUSEADDR,(char*)&arg,sizeof(arg));
+    (void) mysql_socket_setsockopt(ip_sock, SOL_SOCKET, SO_REUSEADDR, (char*)&arg,sizeof(arg));
 #endif /* __WIN__ */
 
 #ifdef IPV6_V6ONLY
@@ -1886,7 +1887,7 @@ static void network_init(void)
     if (a->ai_family == AF_INET6)
     {
       arg= 0;
-      (void) setsockopt(ip_sock, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&arg,
+      (void) mysql_socket_setsockopt(ip_sock, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&arg,
                 sizeof(arg));
     }
 #endif
@@ -1900,7 +1901,7 @@ static void network_init(void)
     */
     for (waited= 0, retry= 1; ; retry++, waited+= this_wait)
     {
-      if (((ret= bind(ip_sock, a->ai_addr, a->ai_addrlen)) >= 0 ) ||
+      if (((ret= mysql_socket_bind(ip_sock, a->ai_addr, a->ai_addrlen)) >= 0 ) ||
           (socket_errno != SOCKET_EADDRINUSE) ||
           (waited >= mysqld_port_timeout))
         break;
@@ -1916,7 +1917,7 @@ static void network_init(void)
       sql_print_error("Do you already have another mysqld server running on port: %d ?",mysqld_port);
       unireg_abort(1);
     }
-    if (listen(ip_sock,(int) back_log) < 0)
+    if (mysql_socket_listen(ip_sock, (int)back_log) < 0)
     {
       sql_perror("Can't start server: listen() on TCP/IP port");
       sql_print_error("listen() on TCP/IP failed with error %d",
@@ -1986,7 +1987,7 @@ static void network_init(void)
                       (uint) sizeof(UNIXaddr.sun_path) - 1, mysqld_unix_port);
       unireg_abort(1);
     }
-    if ((unix_sock= socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
+    if (mysql_socket_getsd((unix_sock= mysql_socket_socket(key_socket_server, AF_UNIX, SOCK_STREAM, 0))) < 0)
     {
       sql_perror("Can't start server : UNIX Socket "); /* purecov: inspected */
       unireg_abort(1);				/* purecov: inspected */
@@ -1996,10 +1997,10 @@ static void network_init(void)
     strmov(UNIXaddr.sun_path, mysqld_unix_port);
     (void) unlink(mysqld_unix_port);
     arg= 1;
-    (void) setsockopt(unix_sock,SOL_SOCKET,SO_REUSEADDR,(char*)&arg,
+    (void) mysql_socket_setsockopt(unix_sock, SOL_SOCKET, SO_REUSEADDR, (char*)&arg,
 		      sizeof(arg));
     umask(0);
-    if (bind(unix_sock, my_reinterpret_cast(struct sockaddr *) (&UNIXaddr),
+    if (bind(mysql_socket_getsd(unix_sock), my_reinterpret_cast(struct sockaddr *) (&UNIXaddr),
 	     sizeof(UNIXaddr)) < 0)
     {
       sql_perror("Can't start server : Bind on unix socket"); /* purecov: tested */
@@ -2010,7 +2011,7 @@ static void network_init(void)
 #if defined(S_IFSOCK) && defined(SECURE_SOCKETS)
     (void) chmod(mysqld_unix_port,S_IFSOCK);	/* Fix solaris 2.6 bug */
 #endif
-    if (listen(unix_sock,(int) back_log) < 0)
+    if (mysql_socket_listen(unix_sock, (int)back_log) < 0)
       sql_print_warning("listen() on Unix socket failed with error %d",
 		      socket_errno);
   }
@@ -4781,7 +4782,7 @@ int mysqld_main(int argc, char **argv)
     if (!opt_bootstrap)
       mysql_file_delete(key_file_pid, pidfile_name, MYF(MY_WME)); // Not needed anymore
 
-    if (unix_sock != INVALID_SOCKET)
+    if (mysql_socket_getsd(unix_sock) != INVALID_SOCKET)
       unlink(mysqld_unix_port);
     exit(1);
   }
@@ -4841,7 +4842,7 @@ int mysqld_main(int argc, char **argv)
   start_handle_manager();
 
   sql_print_information(ER_DEFAULT(ER_STARTUP),my_progname,server_version,
-                        ((unix_sock == INVALID_SOCKET) ? (char*) ""
+                        ((mysql_socket_getsd(unix_sock) == INVALID_SOCKET) ? (char*) ""
                                                        : mysqld_unix_port),
                          mysqld_port,
                          MYSQL_COMPILATION_COMMENT);
@@ -5324,9 +5325,9 @@ inline void kill_broken_server()
   /* hack to get around signals ignored in syscalls for problem OS's */
   if (
 #if !defined(__NETWARE__)
-      unix_sock == INVALID_SOCKET ||
+      mysql_socket_getsd(unix_sock) == INVALID_SOCKET ||
 #endif
-      (!opt_disable_networking && ip_sock == INVALID_SOCKET))
+      (!opt_disable_networking && mysql_socket_getsd(ip_sock) == INVALID_SOCKET))
   {
     select_thread_in_use = 0;
     /* The following call will never return */
@@ -5344,7 +5345,7 @@ inline void kill_broken_server()
 
 void handle_connections_sockets()
 {
-  my_socket sock,new_sock;
+  MYSQL_SOCKET sock, new_sock;
   uint error_count=0;
   THD *thd;
   struct sockaddr_storage cAddr;
@@ -5355,40 +5356,40 @@ void handle_connections_sockets()
   struct pollfd fds[2]; // for ip_sock and unix_sock
 #else
   fd_set readFDs,clientFDs;
-  uint max_used_connection= (uint) (max(ip_sock,unix_sock)+1);
+  uint max_used_connection= (uint)(max(mysql_socket_getsd(ip_sock), mysql_socket_getsd(unix_sock))+1);
 #endif
 
   DBUG_ENTER("handle_connections_sockets");
 
-  LINT_INIT(new_sock);
+  //TBD LINT_INIT(new_sock);
 
 #ifndef HAVE_POLL
   FD_ZERO(&clientFDs);
 #endif
 
-  if (ip_sock != INVALID_SOCKET)
+  if (mysql_socket_getsd(ip_sock) != INVALID_SOCKET)
   {
 #ifdef HAVE_POLL
-    fds[socket_count].fd= ip_sock;
+    fds[socket_count].fd= mysql_socket_getsd(ip_sock);
     fds[socket_count].events= POLLIN;
     socket_count++;
 #else
-    FD_SET(ip_sock,&clientFDs);
+    FD_SET(mysql_socket_getsd(ip_sock), &clientFDs);
 #endif    
 #ifdef HAVE_FCNTL
-    ip_flags = fcntl(ip_sock, F_GETFL, 0);
+    ip_flags = fcntl(mysql_socket_getsd(ip_sock), F_GETFL, 0);
 #endif
   }
 #ifdef HAVE_SYS_UN_H
 #ifdef HAVE_POLL
-  fds[socket_count].fd= unix_sock;
+  fds[socket_count].fd= mysql_socket_getsd(unix_sock);
   fds[socket_count].events= POLLIN;
   socket_count++;
 #else
-  FD_SET(unix_sock,&clientFDs);
+  FD_SET(mysql_socket_getsd(unix_sock), &clientFDs);
 #endif
 #ifdef HAVE_FCNTL
-  socket_flags=fcntl(unix_sock, F_GETFL, 0);
+  socket_flags=fcntl(mysql_socket_getsd(unix_sock), F_GETFL, 0);
 #endif
 #endif
 
@@ -5427,9 +5428,9 @@ void handle_connections_sockets()
     {
       if (fds[i].revents & POLLIN)
       {
-        sock= fds[i].fd;
+        mysql_socket_getsd(sock)= fds[i].fd;
 #ifdef HAVE_FCNTL
-        flags= fcntl(sock, F_GETFL, 0);
+        flags= fcntl(mysql_socket_getsd(sock), F_GETFL, 0);
 #else
         flags= 0;
 #endif // HAVE_FCNTL
@@ -5438,7 +5439,7 @@ void handle_connections_sockets()
     }
 #else  // HAVE_POLL
 #ifdef HAVE_SYS_UN_H
-    if (FD_ISSET(unix_sock,&readFDs))
+    if (FD_ISSET(mysql_socket_getsd(unix_sock), &readFDs))
     {
       sock = unix_sock;
       flags= socket_flags;
@@ -5455,25 +5456,24 @@ void handle_connections_sockets()
     if (!(test_flags & TEST_BLOCKING))
     {
 #if defined(O_NONBLOCK)
-      fcntl(sock, F_SETFL, flags | O_NONBLOCK);
+      fcntl(mysql_socket_getsd(sock), F_SETFL, flags | O_NONBLOCK);
 #elif defined(O_NDELAY)
-      fcntl(sock, F_SETFL, flags | O_NDELAY);
+      fcntl(mysql_socket_getsd(sock), F_SETFL, flags | O_NDELAY);
 #endif
     }
 #endif /* NO_FCNTL_NONBLOCK */
     for (uint retry=0; retry < MAX_ACCEPT_RETRY; retry++)
     {
       size_socket length= sizeof(struct sockaddr_storage);
-      new_sock= accept(sock, (struct sockaddr *)(&cAddr),
-                       &length);
+      new_sock= mysql_socket_accept(sock, (struct sockaddr *)(&cAddr), &length);
 #ifdef __NETWARE__ 
       // TODO: temporary fix, waiting for TCP/IP fix - DEFECT000303149
-      if ((new_sock == INVALID_SOCKET) && (socket_errno == EINVAL))
+      if ((mysql_socket_getsd(new_sock) == INVALID_SOCKET) && (socket_errno == EINVAL))
       {
         kill_server(SIGTERM);
       }
 #endif
-      if (new_sock != INVALID_SOCKET ||
+      if (mysql_socket_getsd(new_sock) != INVALID_SOCKET ||
 	  (socket_errno != SOCKET_EINTR && socket_errno != SOCKET_EAGAIN))
 	break;
       MAYBE_BROKEN_SYSCALL;
@@ -5481,15 +5481,15 @@ void handle_connections_sockets()
       if (!(test_flags & TEST_BLOCKING))
       {
 	if (retry == MAX_ACCEPT_RETRY - 1)
-	  fcntl(sock, F_SETFL, flags);		// Try without O_NONBLOCK
+	  fcntl(mysql_socket_getsd(sock), F_SETFL, flags);		// Try without O_NONBLOCK
       }
 #endif
     }
 #if !defined(NO_FCNTL_NONBLOCK)
     if (!(test_flags & TEST_BLOCKING))
-      fcntl(sock, F_SETFL, flags);
+      fcntl(mysql_socket_getsd(sock), F_SETFL, flags);
 #endif
-    if (new_sock == INVALID_SOCKET)
+    if (mysql_socket_getsd(new_sock) == INVALID_SOCKET)
     {
       if ((error_count++ & 255) == 0)		// This can happen often
 	sql_perror("Error in accept");
@@ -5501,11 +5501,11 @@ void handle_connections_sockets()
 
 #ifdef HAVE_LIBWRAP
     {
-      if (sock == ip_sock)
+      if (mysql_socket_getsd(sock) == mysql_socket_getsd(ip_sock))
       {
 	struct request_info req;
 	signal(SIGCHLD, SIG_DFL);
-	request_init(&req, RQ_DAEMON, libwrapName, RQ_FILE, new_sock, NULL);
+	request_init(&req, RQ_DAEMON, libwrapName, RQ_FILE, mysql_socket_getsd(new_sock), NULL); //TBD cwp
 	my_fromhost(&req);
 	if (!my_hosts_access(&req))
 	{
@@ -5526,8 +5526,8 @@ void handle_connections_sockets()
 	  if (req.sink)
 	    ((void (*)(int))req.sink)(req.fd);
 
-	  (void) shutdown(new_sock, SHUT_RDWR);
-	  (void) closesocket(new_sock);
+	  (void) mysql_socket_shutdown(new_sock, SHUT_RDWR);
+	  (void) mysql_socket_ closesocket(new_sock);
 	  continue;
 	}
       }
@@ -5538,12 +5538,12 @@ void handle_connections_sockets()
       size_socket dummyLen;
       struct sockaddr_storage dummy;
       dummyLen = sizeof(dummy);
-      if (  getsockname(new_sock,(struct sockaddr *)&dummy, 
+      if (  mysql_socket_getsockname(new_sock, (struct sockaddr *)&dummy,
                   (SOCKET_SIZE_TYPE *)&dummyLen) < 0  )
       {
 	sql_perror("Error on new connection socket");
-	(void) shutdown(new_sock, SHUT_RDWR);
-	(void) closesocket(new_sock);
+	(void) mysql_socket_shutdown(new_sock, SHUT_RDWR);
+	(void) mysql_socket_close(new_sock);
 	continue;
       }
     }
@@ -5554,14 +5554,14 @@ void handle_connections_sockets()
 
     if (!(thd= new THD))
     {
-      (void) shutdown(new_sock, SHUT_RDWR);
-      (void) closesocket(new_sock);
+      (void) mysql_socket_shutdown(new_sock, SHUT_RDWR);
+      (void) mysql_socket_close(new_sock);
       continue;
     }
-    if (!(vio_tmp=vio_new(new_sock,
-			  sock == unix_sock ? VIO_TYPE_SOCKET :
+    if (!(vio_tmp=vio_new(mysql_socket_getsd(new_sock), //TBD cwp
+			  mysql_socket_getsd(sock) == mysql_socket_getsd(unix_sock) ? VIO_TYPE_SOCKET :
 			  VIO_TYPE_TCPIP,
-			  sock == unix_sock ? VIO_LOCALHOST: 0)) ||
+			  mysql_socket_getsd(sock) == mysql_socket_getsd(unix_sock) ? VIO_LOCALHOST: 0)) ||
 	my_net_init(&thd->net,vio_tmp))
     {
       /*
@@ -5573,13 +5573,13 @@ void handle_connections_sockets()
         vio_delete(vio_tmp);
       else
       {
-	(void) shutdown(new_sock, SHUT_RDWR);
-	(void) closesocket(new_sock);
+	(void) mysql_socket_shutdown(new_sock, SHUT_RDWR);
+	(void) mysql_socket_close(new_sock);
       }
       delete thd;
       continue;
     }
-    if (sock == unix_sock)
+    if (mysql_socket_getsd(sock) == mysql_socket_getsd(unix_sock))
       thd->security_ctx->host=(char*) my_localhost;
 
     create_new_thread(thd);
@@ -7007,7 +7007,7 @@ static int mysql_init_variables(void)
   character_set_filesystem= &my_charset_bin;
 
   opt_specialflag= SPECIAL_ENGLISH;
-  unix_sock= ip_sock= INVALID_SOCKET;
+  mysql_socket_getsd(unix_sock)= mysql_socket_getsd(ip_sock)= INVALID_SOCKET;
   mysql_home_ptr= mysql_home;
   pidfile_name_ptr= pidfile_name;
   log_error_file_ptr= log_error_file;
@@ -8175,6 +8175,14 @@ static PSI_file_info all_server_files[]=
   { &key_file_init, "init", 0}
 };
 
+PSI_socket_key key_socket_server, key_socket_TBD;
+
+static PSI_socket_info all_server_sockets[]=
+{
+  { &key_socket_server, "server", 0},
+  { &key_socket_TBD, "TBD", 0}
+};
+
 /**
   Initialise all the performance schema instrumentation points
   used by the server.
@@ -8201,6 +8209,9 @@ void init_server_psi_keys(void)
 
   count= array_elements(all_server_files);
   PSI_server->register_file(category, all_server_files, count);
+
+  count= array_elements(all_server_sockets);
+  PSI_server->register_socket(category, all_server_sockets, count);
 }
 
 #endif /* HAVE_PSI_INTERFACE */

=== modified file 'sql/mysqld.h'
--- a/sql/mysqld.h	2010-05-07 16:17:55 +0000
+++ b/sql/mysqld.h	2010-06-22 23:02:37 +0000
@@ -280,6 +280,8 @@ extern PSI_file_key key_file_binlog, key
   key_file_pid, key_file_relay_log_info, key_file_send_file, key_file_tclog,
   key_file_trg, key_file_trn, key_file_init;
 
+extern PSI_socket_key key_socket_server, key_socket_TBD;
+
 void init_server_psi_keys();
 #endif /* HAVE_PSI_INTERFACE */
 

=== modified file 'storage/perfschema/pfs.cc'
--- a/storage/perfschema/pfs.cc	2010-06-09 20:19:47 +0000
+++ b/storage/perfschema/pfs.cc	2010-06-22 23:02:37 +0000
@@ -670,7 +670,7 @@ static inline int mysql_mutex_lock(...)
   @ingroup Performance_schema
 
   @defgroup Performance_schema_tables Performance Schema Tables
-  @ingroup Performance_schema_implementation
+  @ingroup Performance_schema_implementationf
 */
 
 pthread_key(PFS_thread*, THR_PFS);
@@ -735,7 +735,8 @@ static enum_operation_type socket_operat
   OPERATION_TYPE_SOCKETRECV,
   OPERATION_TYPE_SOCKETSEEK,
   OPERATION_TYPE_SOCKETOPT,
-  OPERATION_TYPE_SOCKETSTAT
+  OPERATION_TYPE_SOCKETSTAT,
+  OPERATION_TYPE_SOCKETSHUTDOWN
 };
 
 /**
@@ -930,6 +931,18 @@ static void destroy_cond_v1(PSI_cond* co
   destroy_cond(pfs);
 }
 
+static PSI_socket*
+init_socket_v1(PSI_socket_key key, const void *identity)
+{
+  INIT_BODY_V1(socket, key, identity);
+}
+
+static void destroy_socket_v1(PSI_socket* socket)
+{
+  PFS_socket *pfs= reinterpret_cast<PFS_socket*> (socket);
+  destroy_socket(pfs);
+}
+
 static PSI_table_share*
 get_table_share_v1(const char *schema_name, int schema_name_length,
                    const char *table_name, int table_name_length,
@@ -2033,21 +2046,90 @@ static void end_file_wait_v1(PSI_file_lo
 /** Socket operations */
 
 static void start_socket_wait_v1(PSI_socket_locker *locker,
-                                 const char *src_file,
-                                 uint src_line);
+                                     const char *src_file,
+                                     uint src_line);
 
 static void end_socket_wait_v1(PSI_socket_locker *locker);
 
 static void start_socket_wait_v1(PSI_socket_locker *locker,
-                                 const char *src_file,
-                                 uint src_line)
+                                     const char *src_file,
+                                     uint src_line)
 {
+	PFS_wait_locker *pfs_locker= reinterpret_cast<PFS_wait_locker*> (locker);
+	DBUG_ASSERT(pfs_locker != NULL);
+
+  PFS_events_waits *wait=&pfs_locker->m_waits_current;
+  if (wait->m_timer_state == TIMER_STATE_STARTING)
+  {
+    wait->m_timer_start= get_timer_value(pfs_locker->m_timer_name);
+    wait->m_timer_state= TIMER_STATE_STARTED;
+  }
+  wait->m_source_file= src_file;
+  wait->m_source_line= src_line;
 }
 
 static void end_socket_wait_v1(PSI_socket_locker *locker)
 {
+  PFS_wait_locker *pfs_locker= reinterpret_cast<PFS_wait_locker*> (locker);
+  DBUG_ASSERT(pfs_locker != NULL);
+  PFS_events_waits *wait= &pfs_locker->m_waits_current;
+
+  if (wait->m_timer_state == TIMER_STATE_STARTED)
+  {
+    wait->m_timer_end= get_timer_value(pfs_locker->m_timer_name);
+    wait->m_timer_state= TIMER_STATE_TIMED;
+  }
+  if (flag_events_waits_history)
+    insert_events_waits_history(wait->m_thread, wait);
+  if (flag_events_waits_history_long)
+    insert_events_waits_history_long(wait);
+
+  PFS_single_stat_chain *stat;
+  PFS_socket *socket= pfs_locker->m_target.m_socket;
+
+  ulonglong wait_time= wait->m_timer_end - wait->m_timer_start;
+  //aggregate_single_stat_chain(&socket->m_wait_stat, wait_time);
+  //stat= find_per_thread_socket_class_wait_stat(wait->m_thread,
+  //                                             socket->m_class);
+  //aggregate_single_stat_chain(stat, wait_time);
+
+  PFS_socket_class *klass= socket->m_class;
+
+  switch(wait->m_operation)
+  {
+  case OPERATION_TYPE_SOCKETCREATE:
+    socket->m_socket_stat.m_open_count++;
+    klass->m_socket_stat.m_open_count++;
+    break;
+  case OPERATION_TYPE_SOCKETSEND:
+    socket->m_socket_stat.m_count_send++;
+    //socket->m_socket_stat.m_send_bytes+= count; //TBD
+    //klass->m_socket_stat.m_send_bytes+= count; //TBD
+    break;
+  case OPERATION_TYPE_SOCKETRECV:
+    socket->m_socket_stat.m_count_recv++;
+    //socket->m_socket_stat.m_recv_bytes+= count; //TBD
+    //klass->m_socket_stat.m_recv_bytes+= count; //TBD
+    break;
+  case OPERATION_TYPE_SOCKETCLOSE:
+    release_socket(pfs_locker->m_target.m_socket);
+    destroy_socket(pfs_locker->m_target.m_socket); // TBD thread?
+    break;
+  case OPERATION_TYPE_SOCKETCONNECT:
+  case OPERATION_TYPE_SOCKETBIND:
+  case OPERATION_TYPE_SOCKETSTAT:
+  case OPERATION_TYPE_SOCKETOPT:
+  case OPERATION_TYPE_SOCKETSEEK:
+  case OPERATION_TYPE_SOCKETSHUTDOWN:
+    break;
+  default:
+    break;
+  }
+
+  wait->m_thread->m_wait_locker_count--;
 }
 
+
 PSI_v1 PFS_v1=
 {
   register_mutex_v1,
@@ -2062,6 +2144,8 @@ PSI_v1 PFS_v1=
   destroy_rwlock_v1,
   init_cond_v1,
   destroy_cond_v1,
+  init_socket_v1,
+  destroy_socket_v1,
   get_table_share_v1,
   release_table_share_v1,
   open_table_v1,

=== modified file 'storage/perfschema/pfs_column_types.h'
--- a/storage/perfschema/pfs_column_types.h	2010-06-09 20:19:47 +0000
+++ b/storage/perfschema/pfs_column_types.h	2010-06-22 23:02:37 +0000
@@ -119,7 +119,8 @@ enum enum_operation_type
   OPERATION_TYPE_SOCKETRECV = 31,
   OPERATION_TYPE_SOCKETSEEK = 32,
   OPERATION_TYPE_SOCKETOPT = 33,
-  OPERATION_TYPE_SOCKETSTAT = 34
+  OPERATION_TYPE_SOCKETSTAT = 34,
+  OPERATION_TYPE_SOCKETSHUTDOWN = 35
 };
 #define FIRST_OPERATION_TYPE (static_cast<int> (OPERATION_TYPE_LOCK))
 #define LAST_OPERATION_TYPE (static_cast<int> (OPERATION_TYPE_FILESYNC))

=== modified file 'storage/perfschema/pfs_events_waits.h'
--- a/storage/perfschema/pfs_events_waits.h	2010-04-19 12:26:29 +0000
+++ b/storage/perfschema/pfs_events_waits.h	2010-06-22 23:02:37 +0000
@@ -30,6 +30,7 @@ struct PFS_cond;
 struct PFS_table;
 struct PFS_file;
 struct PFS_thread;
+struct PFS_socket;
 struct PFS_instr_class;
 
 /** Class of a wait event. */
@@ -81,6 +82,8 @@ union events_waits_target
   PFS_table *m_table;
   /** File waited on. */
   PFS_file *m_file;
+  /** Socket waited on. */
+  PFS_socket *m_socket;
 };
 
 /** A wait event record. */

=== modified file 'storage/perfschema/pfs_instr.cc'
--- a/storage/perfschema/pfs_instr.cc	2010-05-03 15:41:32 +0000
+++ b/storage/perfschema/pfs_instr.cc	2010-06-22 23:02:37 +0000
@@ -63,6 +63,10 @@ ulong file_handle_lost;
 ulong table_max;
 /** Number of table instances lost. @sa table_array */
 ulong table_lost;
+/** Size of the socket instances array. @sa socket_array */
+ulong socket_max;
+/** Number of socket instances lost. @sa socket_array */
+ulong socket_lost;
 /** Number of EVENTS_WAITS_HISTORY records per thread. */
 ulong events_waits_history_per_thread;
 /** Number of instruments class per thread. */
@@ -120,6 +124,13 @@ PFS_file **file_handle_array= NULL;
 */
 PFS_table *table_array= NULL;
 
+/**
+  Socket instrumentation instances array.
+  @sa socket_max
+  @sa socket_lost
+*/
+PFS_socket *socket_array= NULL;
+
 static volatile uint32 thread_internal_id_counter= 0;
 
 static uint per_thread_rwlock_class_start;
@@ -1040,6 +1051,65 @@ void destroy_table(PFS_table *pfs)
 {
   DBUG_ASSERT(pfs != NULL);
   pfs->m_lock.allocated_to_free();
+}
+
+/**
+  Create instrumentation for a socket instance.
+  @param klass                        the socket class
+  @param identity                     the socket address
+  @return a socket instance, or NULL
+*/
+PFS_socket* create_socket(PFS_socket_class *klass, const void *identity) // TBD
+{
+  PFS_scan scan;
+  uint random= randomized_index(identity, socket_max);
+
+  for (scan.init(random, socket_max);
+       scan.has_pass();
+       scan.next_pass())
+  {
+    PFS_socket *pfs= socket_array + scan.first();
+    PFS_socket *pfs_last= socket_array + scan.last();
+    for ( ; pfs < pfs_last; pfs++)
+    {
+      if (pfs->m_lock.is_free())
+      {
+        if (pfs->m_lock.free_to_dirty())
+        {
+          pfs->m_identity= identity;
+          pfs->m_class= klass;
+          pfs->m_wait_stat.m_control_flag= &flag_events_waits_summary_by_instance;
+          pfs->m_wait_stat.m_parent= &klass->m_wait_stat;
+          reset_single_stat_link(&pfs->m_wait_stat);
+          pfs->m_lock.dirty_to_allocated();
+          return pfs;
+        }
+      }
+    }
+  }
+
+  socket_lost++;
+  return NULL;
+}
+
+/**
+  Release instrumentation for a socket instance.
+  @param pfs                          the socket to release
+*/
+void release_socket(PFS_socket *pfs) // TBD
+{
+  DBUG_ASSERT(pfs != NULL);
+  pfs->m_socket_stat.m_open_count--;
+}
+
+/**
+  Destroy instrumentation for a socket instance.
+  @param pfs                          the socket to destroy
+*/
+void destroy_socket(PFS_socket *pfs)
+{
+  DBUG_ASSERT(pfs != NULL);
+  pfs->m_lock.allocated_to_free();
 }
 
 static void reset_mutex_waits_by_instance(void)

=== modified file 'storage/perfschema/pfs_instr.h'
--- a/storage/perfschema/pfs_instr.h	2010-05-03 15:04:02 +0000
+++ b/storage/perfschema/pfs_instr.h	2010-06-22 23:02:37 +0000
@@ -129,6 +129,19 @@ struct PFS_table : public PFS_instr
   const void *m_identity;
 };
 
+/** Instrumented Socket and FILE implementation. @see PSI_socket. */
+struct PFS_socket : public PFS_instr
+{
+  /** Socket identity, typically int */
+  const void *m_identity;
+  /** Socket data. */   // TBD
+  char m_socketaddr[14];
+  /** Socket class. */
+  PFS_socket_class *m_class;
+  /** Socket usage statistics. */
+  PFS_socket_stat m_socket_stat;
+};
+
 /**
   @def LOCKER_STACK_SIZE
   Maximum number of nested waits.
@@ -248,26 +261,32 @@ int init_instruments(const PFS_global_pa
 void cleanup_instruments();
 int init_file_hash();
 void cleanup_file_hash();
+
 PFS_mutex* create_mutex(PFS_mutex_class *mutex_class, const void *identity);
 void destroy_mutex(PFS_mutex *pfs);
+
 PFS_rwlock* create_rwlock(PFS_rwlock_class *klass, const void *identity);
 void destroy_rwlock(PFS_rwlock *pfs);
+
 PFS_cond* create_cond(PFS_cond_class *klass, const void *identity);
 void destroy_cond(PFS_cond *pfs);
 
 PFS_thread* create_thread(PFS_thread_class *klass, const void *identity,
                           ulong thread_id);
-
 void destroy_thread(PFS_thread *pfs);
 
 PFS_file* find_or_create_file(PFS_thread *thread, PFS_file_class *klass,
                               const char *filename, uint len);
-
 void release_file(PFS_file *pfs);
 void destroy_file(PFS_thread *thread, PFS_file *pfs);
 PFS_table* create_table(PFS_table_share *share, const void *identity);
 void destroy_table(PFS_table *pfs);
 
+PFS_socket* create_socket(PFS_socket_class *socket_class, const void *identity);
+void release_socket(PFS_socket *pfs);
+void destroy_socket(PFS_socket *pfs);
+
+
 /* For iterators and show status. */
 
 extern ulong mutex_max;
@@ -284,6 +303,8 @@ extern long file_handle_max;
 extern ulong file_handle_lost;
 extern ulong table_max;
 extern ulong table_lost;
+extern ulong socket_max;
+extern ulong socket_lost;
 extern ulong events_waits_history_per_thread;
 extern ulong instr_class_per_thread;
 extern ulong locker_lost;
@@ -297,6 +318,7 @@ extern PFS_thread *thread_array;
 extern PFS_file *file_array;
 extern PFS_file **file_handle_array;
 extern PFS_table *table_array;
+extern PFS_socket *socket_array;
 
 void reset_events_waits_by_instance();
 void reset_per_thread_wait_stat();

=== modified file 'storage/perfschema/pfs_instr_class.cc'
--- a/storage/perfschema/pfs_instr_class.cc	2010-06-09 20:19:47 +0000
+++ b/storage/perfschema/pfs_instr_class.cc	2010-06-22 23:02:37 +0000
@@ -350,7 +350,7 @@ int init_socket_class(uint socket_class_
   if (socket_class_max > 0)
   {
     socket_class_array= PFS_MALLOC_ARRAY(socket_class_max, PFS_socket_class,
-                                       MYF(MY_ZEROFILL));
+                                         MYF(MY_ZEROFILL));
     if (unlikely(socket_class_array == NULL))
       return 1;
   }
@@ -369,7 +369,6 @@ void cleanup_socket_class(void)
   socket_class_max= 0;
 }
 
-
 static void init_instr_class(PFS_instr_class *klass,
                              const char *name,
                              uint name_length,
@@ -739,7 +738,7 @@ PFS_file_class *sanitize_file_class(PFS_
   @return a socket instrumentation key
 */
 PFS_socket_key register_socket_class(const char *name, uint name_length,
-                                 int flags)
+                                        int flags)
 {
   /* See comments in register_mutex_class */
   uint32 index;
@@ -754,8 +753,7 @@ PFS_socket_key register_socket_class(con
   {
     entry= &socket_class_array[index];
     init_instr_class(entry, name, name_length, flags);
-    entry->m_wait_stat.m_control_flag=
-      &flag_events_waits_summary_by_event_name;
+    entry->m_wait_stat.m_control_flag= &flag_events_waits_summary_by_event_name;
     entry->m_wait_stat.m_parent= NULL;
     reset_single_stat_link(&entry->m_wait_stat);
     entry->m_index= index;

=== modified file 'vio/viosocket.c'
--- a/vio/viosocket.c	2010-02-03 00:06:42 +0000
+++ b/vio/viosocket.c	2010-06-22 23:02:37 +0000
@@ -34,6 +34,8 @@ size_t vio_read(Vio * vio, uchar* buf, s
   DBUG_ENTER("vio_read");
   DBUG_PRINT("enter", ("sd: %d  buf: 0x%lx  size: %u", vio->sd, (long) buf,
                        (uint) size));
+  struct PSI_socket_locker *locker;
+  //locker= MYSQL_START_SOCKET_WAIT(m_psi, PSI_SOCKET_RECV, MAX_KEY, 0);
 
   /* Ensure nobody uses vio_read_buff and vio_read simultaneously */
   DBUG_ASSERT(vio->read_end == vio->read_pos);
@@ -49,6 +51,9 @@ size_t vio_read(Vio * vio, uchar* buf, s
     DBUG_PRINT("vio_error", ("Got error %d during read",errno));
   }
 #endif /* DBUG_OFF */
+
+  //MYSQL_END_SOCKET_WAIT(locker);
+
   DBUG_PRINT("exit", ("%ld", (long) r));
   DBUG_RETURN(r);
 }


Attachment: [text/bzr-bundle] bzr/chris.powers@oracle.com-20100622230237-o6q1wp9rv1ns0euj.bundle
Thread
bzr push into mysql-next-mr-wl4896 branch (chris.powers:3148 to 3149) WL#4896Christopher Powers23 Jun