List:Commits« Previous MessageNext Message »
From:Christopher Powers Date:June 7 2010 9:03pm
Subject:bzr commit into mysql-next-mr-wl4896 branch (chris.powers:3147) WL#4896
View as plain text  
#At file:///home/cpowers/work/dev/dev-wl4896/mysql/ based on revid:chris.powers@stripped

 3147 Christopher Powers	2010-06-07
      WL#4896 PERFORMANCE_SCHEMA Instrumenting Net IO
      
      Socket API wrappers, intermediate version

    added:
      include/mysql/psi/mysql_socket.h
    modified:
      include/mysql/psi/psi.h
=== added file 'include/mysql/psi/mysql_socket.h'
--- a/include/mysql/psi/mysql_socket.h	1970-01-01 00:00:00 +0000
+++ b/include/mysql/psi/mysql_socket.h	2010-06-07 21:03:19 +0000
@@ -0,0 +1,838 @@
+/* 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., 51 Franklin St, Fifth Floor, Boston, MA
+02110-1301  USA
+*/
+
+#ifndef MYSQL_SOCKET_H
+#define MYSQL_SOCKET_H
+
+/* For strlen() */
+#include <string.h>
+/* For MY_STAT */
+#include <my_dir.h>
+/* For my_chsize */
+#include <my_sys.h>
+
+/**
+  @file mysql/psi/mysql_socket.h
+[...]
+*/
+
+#include "mysql/psi/psi.h"
+
+/**
+  @defgroup Network_instrumentation Network Instrumentation
+  @ingroup Instrumentation_interface
+  @{
+*/
+
+#ifdef HAVE_PSI_INTERFACE
+  #define mysql_socket_socket(D, T, P) \
+    inline mysql_socket_socket(__FILE__, __LINE__, D, T, P)
+#else
+  #define mysql_socket_socket(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)
+#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)
+#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)
+#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)
+#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)
+#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)
+#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)
+#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)
+#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)
+#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)
+#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)
+#else
+  #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)
+#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)
+#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)
+#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)
+#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)
+#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_shutdown(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)
+#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)
+#else
+  #define mysql_socket_isfdtype(SD, FT) \
+    inline_mysql_socket_isfdtype(SD, FT)
+#endif
+		
+
+
+
+
+int mysql_socket_socket(D, T, P)
+int mysql_socket_socketpair(D, T, P, SDS)
+int mysql_socket_bind(SD, A, L)
+int mysql_socket_getsockname(SD, A, LP)
+int mysql_socket_connect(SD, A, L)
+int mysql_socket_getpeername(SD, A, LP)
+ssize_t mysql_socket_send(SD, B, N, FL)
+ssize_t mysql_socket_recv(SD, B, N, FL)
+ssize_t mysql_socket_sendto(SD, B, N, FL, A, L)
+ssize_t mysql_socket_recvfrom(SD, B, N, FL, A, LP)
+ssize_t mysql_socket_sendmsg(SD, M, FL)
+ssize_t mysql_socket_recvmsg(SD, M, FL)
+int mysql_socket_getsockopt(SD, LV, ON, OP, OL)
+int mysql_socket_setsockopt(SD, LV, ON, OP, OL)
+int mysql_socket_listen(SD, N)
+int mysql_socket_accept(SD, A, LP)
+int mysql_socket_accept4(SD, A, LP, FL)
+int mysql_socket_shutdown(SD, H)
+int mysql_socket_sockatmark(SD)
+int mysql_socket_isfdtype(SD, FT)
+
+
+
+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
+{
+  /** The real socket identifier. */
+  my_socket sd;
+  /**
+    The instrumentation hook.
+    Note that this hook is not conditionally defined,
+    for binary compatibility of the @c MYSQL_FILE interface.
+  */
+
+  struct PSI_socket *m_psi;
+};
+
+/**
+  Type of an instrumented socket.
+  @c MYSQL_SOCKET is a replacement for @c my_socket.
+  @sa mysql_file_open
+*/
+
+typedef struct st_mysql_socket_t MYSQL_SOCKET;
+
+
+/** mysql_socket_socket */
+
+static inline int
+inline_mysql_socket_socket
+(
+#ifdef HAVE_PSI_INTERFACE
+  const char *src_file, uint src_line,
+#endif
+  int domain, int type, int protocol)
+{
+  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_CREATE);
+	if (likely(locker !=NULL))
+	  PSI_server->start_socket_wait(locker, src_file, src_line);
+  }
+#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
+  return result;
+}
+
+/** mysql_socket_socketpair */
+
+static inline int
+inline_mysql_socket_socketpair
+(
+#ifdef HAVE_PSI_INTERFACE
+  const char *src_file, uint src_line,
+#endif
+  int domain, int type, int protocol, int fds[2])
+{
+  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_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);
+#endif
+  return result;
+}
+
+/** mysql_socket_bind */
+
+static inline int
+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)
+{
+  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);
+  }
+#endif
+  result= bind(sd->sd, addr, len);
+#ifdef HAVE_PSI_INTERFACE
+  if (likely(locker != NULL))
+    PSI_server->end_socket_wait(locker, socket);
+#endif
+  return result;
+}
+
+/** mysql_socket_getsockname */
+
+static inline int
+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)
+{
+  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);
+  }
+#endif
+  result= getsockname(sd->sd, addr, *restrict len);
+#ifdef HAVE_PSI_INTERFACE
+  if (likely(locker != NULL))
+    PSI_server->end_socket_wait(locker, socket);
+#endif
+  return result;
+}
+
+/** mysql_socket_connect */
+
+static inline int
+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)
+{
+  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);
+  }
+#endif
+  result= connect(sd->sd, addr, len);
+#ifdef HAVE_PSI_INTERFACE
+  if (likely(locker != NULL))
+    PSI_server->end_socket_wait(locker, socket);
+#endif
+  return result;
+}
+
+/** mysql_socket_getpeername */
+
+static inline int
+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)
+{
+  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);
+  }
+#endif
+  result= getpeername(sd->sd, addr, *restrict len);
+#ifdef HAVE_PSI_INTERFACE
+  if (likely(locker != NULL))
+    PSI_server->end_socket_wait(locker, socket);
+#endif
+  return result;
+}
+
+/** mysql_socket_send */
+
+static inline ssize_t
+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)
+{
+  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);
+  }
+#endif
+  result= send(sd->sd, buf, n, flags);
+#ifdef HAVE_PSI_INTERFACE
+  if (likely(locker != NULL))
+    PSI_server->end_socket_wait(locker, socket);
+#endif
+  return result;
+}
+
+/** mysql_socket_recv */
+
+static inline ssize_t
+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)
+{
+  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);
+  }
+#endif
+  result= recv(sd->sd, buf, n, flags);
+#ifdef HAVE_PSI_INTERFACE
+  if (likely(locker != NULL))
+    PSI_server->end_socket_wait(locker, socket);
+#endif
+  return result;
+}
+
+/** mysql_socket_sendto */
+
+static inline ssize_t
+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)
+{
+  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);
+  }
+#endif
+  result= sendto(sd->sd, buf, n, flags, addr, addr_len);
+#ifdef HAVE_PSI_INTERFACE
+  if (likely(locker != NULL))
+    PSI_server->end_socket_wait(locker, socket);
+#endif
+  return result;
+}
+
+/** mysql_socket_recvfrom */
+
+static inline ssize_t
+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)
+{
+  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);
+  }
+#endif
+  result= recvfrom(sd->sd, buf, n, lags, addr, addr_len);
+#ifdef HAVE_PSI_INTERFACE
+  if (likely(locker != NULL))
+    PSI_server->end_socket_wait(locker, socket);
+#endif
+  return result;
+}
+
+/** mysql_socket_sendmsg */
+
+static inline ssize_t
+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)
+{
+  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);
+  }
+#endif
+  result= sendmsg(sd->sd, message, flags);
+#ifdef HAVE_PSI_INTERFACE
+  if (likely(locker != NULL))
+    PSI_server->end_socket_wait(locker, socket);
+#endif
+  return result;
+}
+
+/** mysql_socket_recvmsg */
+
+static inline ssize_t
+inline_mysql_socket_recvmsg
+(
+#ifdef HAVE_PSI_INTERFACE
+  const char *src_file, uint src_line,
+#endif
+ MYSQL_SOCKET *sd, 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);
+  }
+#endif
+  result= recvmsg(sd->sd, message, flags);
+#ifdef HAVE_PSI_INTERFACE
+  if (likely(locker != NULL))
+    PSI_server->end_socket_wait(locker, socket);
+#endif
+  return result;
+}
+
+/** mysql_socket_getsockopt */
+
+static inline int
+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)
+{
+  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);
+  }
+#endif
+  result= getsockopt(sd->sd, level, optname, optval, optlen);
+#ifdef HAVE_PSI_INTERFACE
+  if (likely(locker != NULL))
+    PSI_server->end_socket_wait(locker, socket);
+#endif
+  return result;
+}
+
+/** mysql_socket_setsockopt */
+
+static inline int
+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)
+{
+  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);
+  }
+#endif
+  result= setsockopt(sd->sd, level, optname, optval, optlen);
+#ifdef HAVE_PSI_INTERFACE
+  if (likely(locker != NULL))
+    PSI_server->end_socket_wait(locker, socket);
+#endif
+  return result;
+}
+
+/** mysql_socket_listen */
+
+static inline int
+inline_mysql_socket_listen
+(
+#ifdef HAVE_PSI_INTERFACE
+  const char *src_file, uint src_line,
+#endif
+ MYSQL_SOCKET *sd, 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);
+  }
+#endif
+  result= listen(sd->sd, n);
+#ifdef HAVE_PSI_INTERFACE
+  if (likely(locker != NULL))
+    PSI_server->end_socket_wait(locker, socket);
+#endif
+  return result;
+}
+
+/** mysql_socket_accept */
+
+static inline int
+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)
+{
+  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);
+  }
+#endif
+  result= accept(sd->sd, addr, addr_len);
+#ifdef HAVE_PSI_INTERFACE
+  if (likely(locker != NULL))
+    PSI_server->end_socket_wait(locker, socket);
+#endif
+  return result;
+}
+
+/** mysql_socket_accept4 */
+
+static inline int
+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)
+{
+  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);
+  }
+#endif
+  result= accept4(sd->sd, addr, addr_len, flags);
+#ifdef HAVE_PSI_INTERFACE
+  if (likely(locker != NULL))
+    PSI_server->end_socket_wait(locker, socket);
+#endif
+  return result;
+}
+
+/** mysql_socket_shutdown */
+
+static inline int
+inline_mysql_socket_shutdown
+(
+#ifdef HAVE_PSI_INTERFACE
+  const char *src_file, uint src_line,
+#endif
+ MYSQL_SOCKET *sd, 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);
+  }
+#endif
+  result= shutdown(sd->sd, how);
+#ifdef HAVE_PSI_INTERFACE
+  if (likely(locker != NULL))
+    PSI_server->end_socket_wait(locker, socket);
+#endif
+  return result;
+}
+
+/** mysql_socket_sockatmark */
+
+static inline int
+inline_mysql_socket_sockatmark
+(
+#ifdef HAVE_PSI_INTERFACE
+  const char *src_file, uint src_line,
+#endif
+  MYSQL_SOCKET *sd)
+{
+  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);
+  }
+#endif
+  result= sockatmark(sd->sd);
+#ifdef HAVE_PSI_INTERFACE
+  if (likely(locker != NULL))
+    PSI_server->end_socket_wait(locker, socket);
+#endif
+  return result;
+}
+
+/** mysql_socket_isfdtype */
+
+static inline int
+inline_mysql_socket_isfdtype
+(
+#ifdef HAVE_PSI_INTERFACE
+  const char *src_file, uint src_line,
+#endif
+ MYSQL_SOCKET *sd,  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);
+  }
+#endif
+  result= isfdtype(sd->sd, fdtype);
+#ifdef HAVE_PSI_INTERFACE
+  if (likely(locker != NULL))
+    PSI_server->end_socket_wait(locker, socket);
+#endif
+  return result;
+}
+
+
+
+/** @} (end of group Network_instrumentation) */
+
+#endif
+

=== modified file 'include/mysql/psi/psi.h'
--- a/include/mysql/psi/psi.h	2010-01-26 23:42:54 +0000
+++ b/include/mysql/psi/psi.h	2010-06-07 21:03:19 +0000
@@ -80,6 +80,12 @@ struct PSI_thread;
 */
 struct PSI_file;
 
+/**
+  Interface for an instrumented socket descriptor.
+  This is an opaque structure.
+*/
+struct PSI_socket;
+
 /** Entry point for the performance schema interface. */
 struct PSI_bootstrap
 {
@@ -229,6 +235,38 @@ enum PSI_file_operation
   PSI_FILE_SYNC= 16
 };
 
+/** Operation performed on an instrumented socket. */
+enum PSI_socket_operation
+{
+  /** Socket creation, as in @c socket() or @c socketpair(). */
+  PSI_SOCKET_CREATE= 0,
+
+  /** Socket connection, as in @c connect(), @c listen() and @c accept(). */
+  PSI_SOCKET_CONNECT= 1,
+
+  /** Socket bind, as in @c bind(), @c getsockname() and @c getpeername(). */
+  PSI_SOCKET_BIND= 2,
+
+  /** Socket close, as in @c shutdown(). */
+  PSI_SOCKET_CLOSE= 3,
+  /**
+    Generic socket send, such as @c send(), @c sendto(), @c sendmsg(). */
+  PSI_SOCKET_SEND= 4,
+  /**
+    Generic socket receive, such as @c recv(), @c recvfrom), @c recvmsg(). */
+  PSI_SOCKET_RECV= 5,
+
+  /** Generic socket seek, such as @c fseek() or @c seek(). */
+  PSI_SOCKET_SEEK= 6,
+
+  /** Socket options, as in @c getsockopt() and @c setsockopt(). */
+  PSI_SOCKET_OPT= 7,
+
+  /** Socket status, as in @c sockatmark() and @c isfdtype(). */
+  PSI_SOCKET_STAT= 8
+};
+
+
 /**
   Interface for an instrumented table operation.
   This is an opaque structure.
@@ -682,6 +720,15 @@ typedef struct PSI_file_locker* (*get_th
   (File file, enum PSI_file_operation op);
 
 /**
+  Get a socket instrumentation locker.
+  @param socket the socket to access
+  @param op the operation to perform
+  @return a socket locker, or NULL
+*/
+typedef struct PSI_socket_locker* (*get_thread_socket_locker_v1_t)
+  (struct PSI_socket *socket, enum PSI_socket_operation op);
+
+/**
   Record a mutex instrumentation unlock event.
   @param thread the running thread instrumentation
   @param mutex the mutex instrumentation
@@ -844,6 +891,30 @@ typedef void (*end_file_wait_v1_t)
   (struct PSI_file_locker *locker, size_t count);
 
 /**
+  Record a socket instrumentation start event.
+  @param locker a socket locker for the running thread
+  @param op socket operation to be performed
+  @param count the number of bytes requested, or 0 if not applicable
+  @param src_file the source file name
+  @param src_line the source line number
+*/
+typedef void (*start_sockett_wait_v1_t)
+  (struct PSI_socket_locker *locker, size_t count, //TBD
+   const char *src_file, uint src_line);
+
+/**
+  Record a socket instrumentation end event.
+  Note that for socket close operations, the instrumented socket handle
+  associated with the socket (which was provided to obtain a locker)
+  is invalid after this call.
+  @param locker a socket locker for the running thread
+  @param count the number of bytes actually used in the operation,
+  or 0 if not applicable, or -1 if the operation failed
+  @sa get_thread_socket_locker
+*/
+typedef void (*end_socket_wait_v1_t)
+  (struct PSI_socket_locker *locker, size_t count); //TBD
+/**
   Performance Schema Interface, version 1.
   @since PSI_VERSION_1
 */
@@ -909,6 +980,8 @@ struct PSI_v1
   get_thread_file_stream_locker_v1_t get_thread_file_stream_locker;
   /** @sa get_thread_file_descriptor_locker_v1_t. */
   get_thread_file_descriptor_locker_v1_t get_thread_file_descriptor_locker;
+  /** @sa get_thread_socket_locker_v1_t. */
+  get_thread_socket_locker_v1_t get_thread_socket_locker;
   /** @sa unlock_mutex_v1_t. */
   unlock_mutex_v1_t unlock_mutex;
   /** @sa unlock_rwlock_v1_t. */


Attachment: [text/bzr-bundle] bzr/chris.powers@oracle.com-20100607210319-jacxcdjoc9ybaepj.bundle
Thread
bzr commit into mysql-next-mr-wl4896 branch (chris.powers:3147) WL#4896Christopher Powers7 Jun