List:Commits« Previous MessageNext Message »
From:Christopher Powers Date:June 9 2010 8:21pm
Subject:bzr push into mysql-next-mr-wl4896 branch (chris.powers:3147 to 3148) WL#4896
View as plain text  
 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
 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
=== modified file 'include/mysql/psi/mysql_socket.h'
--- a/include/mysql/psi/mysql_socket.h	2010-06-07 21:03:19 +0000
+++ b/include/mysql/psi/mysql_socket.h	2010-06-09 20:19:47 +0000
@@ -25,6 +25,8 @@ Foundation, Inc., 51 Franklin St, Fifth
 #include <my_dir.h>
 /* For my_chsize */
 #include <my_sys.h>
+/* For socket api */
+#include <sys/socket.h>
 
 /**
   @file mysql/psi/mysql_socket.h
@@ -199,33 +201,7 @@ Foundation, Inc., 51 Franklin St, Fifth
     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);
@@ -246,12 +222,13 @@ int accept4 (int fd, SOCKADDR_ARG addr,
 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,
@@ -280,7 +257,8 @@ inline_mysql_socket_socket
 #endif
   int domain, int type, int protocol)
 {
-  int result;
+  int result = 0;
+#if 0  
 #ifdef HAVE_PSI_INTERFACE
   struct PSI_socket_locker *locker= NULL;
   if (likely(PSI_server != NULL))
@@ -295,6 +273,7 @@ inline_mysql_socket_socket
   if (likely(locker != NULL))
     PSI_server->end_socket_wait(locker, socket);
 #endif
+#endif
   return result;
 }
 
@@ -308,7 +287,8 @@ inline_mysql_socket_socketpair
 #endif
   int domain, int type, int protocol, int fds[2])
 {
-  int result;
+  int result = 0;
+#if 0
 #ifdef HAVE_PSI_INTERFACE
   struct PSI_socket_locker *locker= NULL;
   if (likely(PSI_server != NULL))
@@ -323,6 +303,7 @@ inline_mysql_socket_socketpair
   if (likely(locker != NULL))
     PSI_server->end_socket_wait(locker, socket);
 #endif
+#endif
   return result;
 }
 
@@ -374,7 +355,7 @@ inline_mysql_socket_getsockname
 	  PSI_server->start_socket_wait(locker, src_file, src_line);
   }
 #endif
-  result= getsockname(sd->sd, addr, *restrict len);
+  result= getsockname(sd->sd, addr, len);
 #ifdef HAVE_PSI_INTERFACE
   if (likely(locker != NULL))
     PSI_server->end_socket_wait(locker, socket);

=== modified file 'include/mysql/psi/psi.h'
--- a/include/mysql/psi/psi.h	2010-06-07 21:03:19 +0000
+++ b/include/mysql/psi/psi.h	2010-06-09 20:19:47 +0000
@@ -312,6 +312,13 @@ typedef unsigned int PSI_thread_key;
 typedef unsigned int PSI_file_key;
 
 /**
+  Instrumented socket key.
+  To instrument a socket, a socket key must be obtained using @c register_socket.
+  Using a zero key always disable the instrumentation.
+*/
+typedef unsigned int PSI_socket_key;
+
+/**
   @def USE_PSI_1
   Define USE_PSI_1 to use the interface version 1.
 */
@@ -460,6 +467,28 @@ struct PSI_file_info_v1
   int m_flags;
 };
 
+/**
+  Socket instrument information.
+  @since PSI_VERSION_1
+  This structure is used to register an instrumented socket.
+*/
+struct PSI_socket_info_v1
+{
+  /**
+    Pointer to the key assigned to the registered socket.
+  */
+  PSI_socket_key *m_key;
+  /**
+    The name of the socket instrument to register.
+  */
+  const char *m_name;
+  /**
+    The flags of the socket instrument to register.
+    @sa PSI_FLAG_GLOBAL
+  */
+  int m_flags;
+};
+
 /* Using typedef to make reuse between PSI_v1 and PSI_v2 easier later. */
 
 /**
@@ -508,6 +537,15 @@ typedef void (*register_file_v1_t)
   (const char *category, struct PSI_file_info_v1 *info, int count);
 
 /**
+  Socket registration API.
+  @param category a category name (typically a plugin name)
+  @param info an array of socket info to register
+  @param count the size of the info array
+*/
+typedef void (*register_socket_v1_t)
+  (const char *category, struct PSI_socket_info_v1 *info, int count);
+
+/**
   Mutex instrumentation initialisation API.
   @param key the registered mutex key
   @param identity the address of the mutex itself
@@ -894,12 +932,11 @@ typedef void (*end_file_wait_v1_t)
   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
+typedef void (*start_socket_wait_v1_t)
+  (struct PSI_socket_locker *locker,
    const char *src_file, uint src_line);
 
 /**
@@ -908,12 +945,10 @@ typedef void (*start_sockett_wait_v1_t)
   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
+  (struct PSI_socket_locker *locker);
 /**
   Performance Schema Interface, version 1.
   @since PSI_VERSION_1
@@ -930,6 +965,8 @@ struct PSI_v1
   register_thread_v1_t register_thread;
   /** @sa register_file_v1_t. */
   register_file_v1_t register_file;
+  /** @sa register_socket_v1_t. */
+  register_socket_v1_t register_socket;
   /** @sa init_mutex_v1_t. */
   init_mutex_v1_t init_mutex;
   /** @sa destroy_mutex_v1_t. */
@@ -1021,6 +1058,10 @@ struct PSI_v1
   start_file_wait_v1_t start_file_wait;
   /** @sa end_file_wait_v1_t. */
   end_file_wait_v1_t end_file_wait;
+  /** @sa start_file_wait_v1_t. */
+  start_socket_wait_v1_t start_socket_wait;
+  /** @sa end_file_wait_v1_t. */
+  end_socket_wait_v1_t end_socket_wait;
 };
 
 /** @} (end of group Group_PSI_v1) */
@@ -1129,6 +1170,7 @@ typedef struct PSI_rwlock_info_v1 PSI_rw
 typedef struct PSI_cond_info_v1 PSI_cond_info;
 typedef struct PSI_thread_info_v1 PSI_thread_info;
 typedef struct PSI_file_info_v1 PSI_file_info;
+typedef struct PSI_socket_info_v1 PSI_socket_info;
 #endif
 
 #ifdef USE_PSI_2
@@ -1138,6 +1180,7 @@ typedef struct PSI_rwlock_info_v2 PSI_rw
 typedef struct PSI_cond_info_v2 PSI_cond_info;
 typedef struct PSI_thread_info_v2 PSI_thread_info;
 typedef struct PSI_file_info_v2 PSI_file_info;
+typedef struct PSI_socket_info_v2 PSI_socket_info;
 #endif
 
 #else /* HAVE_PSI_INTERFACE */

=== modified file 'include/mysql/psi/psi_abi_v1.h.pp'
--- a/include/mysql/psi/psi_abi_v1.h.pp	2010-01-26 23:42:54 +0000
+++ b/include/mysql/psi/psi_abi_v1.h.pp	2010-06-09 20:19:47 +0000
@@ -7,6 +7,7 @@ struct PSI_table_share;
 struct PSI_table;
 struct PSI_thread;
 struct PSI_file;
+struct PSI_socket;
 struct PSI_bootstrap
 {
   void* (*get_interface)(int version);
@@ -52,12 +53,25 @@ enum PSI_file_operation
   PSI_FILE_RENAME= 15,
   PSI_FILE_SYNC= 16
 };
+enum PSI_socket_operation
+{
+  PSI_SOCKET_CREATE= 0,
+  PSI_SOCKET_CONNECT= 1,
+  PSI_SOCKET_BIND= 2,
+  PSI_SOCKET_CLOSE= 3,
+  PSI_SOCKET_SEND= 4,
+  PSI_SOCKET_RECV= 5,
+  PSI_SOCKET_SEEK= 6,
+  PSI_SOCKET_OPT= 7,
+  PSI_SOCKET_STAT= 8
+};
 struct PSI_table_locker;
 typedef unsigned int PSI_mutex_key;
 typedef unsigned int PSI_rwlock_key;
 typedef unsigned int PSI_cond_key;
 typedef unsigned int PSI_thread_key;
 typedef unsigned int PSI_file_key;
+typedef unsigned int PSI_socket_key;
 struct PSI_mutex_info_v1
 {
   PSI_mutex_key *m_key;
@@ -88,6 +102,12 @@ struct PSI_file_info_v1
   const char *m_name;
   int m_flags;
 };
+struct PSI_socket_info_v1
+{
+  PSI_socket_key *m_key;
+  const char *m_name;
+  int m_flags;
+};
 typedef void (*register_mutex_v1_t)
   (const char *category, struct PSI_mutex_info_v1 *info, int count);
 typedef void (*register_rwlock_v1_t)
@@ -98,6 +118,8 @@ typedef void (*register_thread_v1_t)
   (const char *category, struct PSI_thread_info_v1 *info, int count);
 typedef void (*register_file_v1_t)
   (const char *category, struct PSI_file_info_v1 *info, int count);
+typedef void (*register_socket_v1_t)
+  (const char *category, struct PSI_socket_info_v1 *info, int count);
 typedef struct PSI_mutex* (*init_mutex_v1_t)
   (PSI_mutex_key key, const void *identity);
 typedef void (*destroy_mutex_v1_t)(struct PSI_mutex *mutex);
@@ -144,6 +166,8 @@ typedef struct PSI_file_locker* (*get_th
   (struct PSI_file *file, enum PSI_file_operation op);
 typedef struct PSI_file_locker* (*get_thread_file_descriptor_locker_v1_t)
   (File file, enum PSI_file_operation op);
+typedef struct PSI_socket_locker* (*get_thread_socket_locker_v1_t)
+  (struct PSI_socket *socket, enum PSI_socket_operation op);
 typedef void (*unlock_mutex_v1_t)
   (struct PSI_thread *thread, struct PSI_mutex *mutex);
 typedef void (*unlock_rwlock_v1_t)
@@ -181,6 +205,11 @@ typedef void (*start_file_wait_v1_t)
    const char *src_file, uint src_line);
 typedef void (*end_file_wait_v1_t)
   (struct PSI_file_locker *locker, size_t count);
+typedef void (*start_socket_wait_v1_t)
+  (struct PSI_socket_locker *locker,
+   const char *src_file, uint src_line);
+typedef void (*end_socket_wait_v1_t)
+  (struct PSI_socket_locker *locker);
 struct PSI_v1
 {
   register_mutex_v1_t register_mutex;
@@ -188,6 +217,7 @@ struct PSI_v1
   register_cond_v1_t register_cond;
   register_thread_v1_t register_thread;
   register_file_v1_t register_file;
+  register_socket_v1_t register_socket;
   init_mutex_v1_t init_mutex;
   destroy_mutex_v1_t destroy_mutex;
   init_rwlock_v1_t init_rwlock;
@@ -213,6 +243,7 @@ struct PSI_v1
   get_thread_file_name_locker_v1_t get_thread_file_name_locker;
   get_thread_file_stream_locker_v1_t get_thread_file_stream_locker;
   get_thread_file_descriptor_locker_v1_t get_thread_file_descriptor_locker;
+  get_thread_socket_locker_v1_t get_thread_socket_locker;
   unlock_mutex_v1_t unlock_mutex;
   unlock_rwlock_v1_t unlock_rwlock;
   signal_cond_v1_t signal_cond;
@@ -233,6 +264,8 @@ struct PSI_v1
     end_file_open_wait_and_bind_to_descriptor;
   start_file_wait_v1_t start_file_wait;
   end_file_wait_v1_t end_file_wait;
+  start_socket_wait_v1_t start_socket_wait;
+  end_socket_wait_v1_t end_socket_wait;
 };
 typedef struct PSI_v1 PSI;
 typedef struct PSI_mutex_info_v1 PSI_mutex_info;
@@ -240,5 +273,6 @@ typedef struct PSI_rwlock_info_v1 PSI_rw
 typedef struct PSI_cond_info_v1 PSI_cond_info;
 typedef struct PSI_thread_info_v1 PSI_thread_info;
 typedef struct PSI_file_info_v1 PSI_file_info;
+typedef struct PSI_socket_info_v1 PSI_socket_info;
 extern MYSQL_PLUGIN_IMPORT PSI *PSI_server;
 C_MODE_END

=== modified file 'include/mysql/psi/psi_abi_v2.h.pp'
--- a/include/mysql/psi/psi_abi_v2.h.pp	2009-12-01 00:49:15 +0000
+++ b/include/mysql/psi/psi_abi_v2.h.pp	2010-06-09 20:19:47 +0000
@@ -7,6 +7,7 @@ struct PSI_table_share;
 struct PSI_table;
 struct PSI_thread;
 struct PSI_file;
+struct PSI_socket;
 struct PSI_bootstrap
 {
   void* (*get_interface)(int version);
@@ -52,12 +53,25 @@ enum PSI_file_operation
   PSI_FILE_RENAME= 15,
   PSI_FILE_SYNC= 16
 };
+enum PSI_socket_operation
+{
+  PSI_SOCKET_CREATE= 0,
+  PSI_SOCKET_CONNECT= 1,
+  PSI_SOCKET_BIND= 2,
+  PSI_SOCKET_CLOSE= 3,
+  PSI_SOCKET_SEND= 4,
+  PSI_SOCKET_RECV= 5,
+  PSI_SOCKET_SEEK= 6,
+  PSI_SOCKET_OPT= 7,
+  PSI_SOCKET_STAT= 8
+};
 struct PSI_table_locker;
 typedef unsigned int PSI_mutex_key;
 typedef unsigned int PSI_rwlock_key;
 typedef unsigned int PSI_cond_key;
 typedef unsigned int PSI_thread_key;
 typedef unsigned int PSI_file_key;
+typedef unsigned int PSI_socket_key;
 struct PSI_v2
 {
   int placeholder;
@@ -88,5 +102,6 @@ typedef struct PSI_rwlock_info_v2 PSI_rw
 typedef struct PSI_cond_info_v2 PSI_cond_info;
 typedef struct PSI_thread_info_v2 PSI_thread_info;
 typedef struct PSI_file_info_v2 PSI_file_info;
+typedef struct PSI_socket_info_v2 PSI_socket_info;
 extern MYSQL_PLUGIN_IMPORT PSI *PSI_server;
 C_MODE_END

=== modified file 'storage/perfschema/pfs.cc'
--- a/storage/perfschema/pfs.cc	2010-04-19 12:26:29 +0000
+++ b/storage/perfschema/pfs.cc	2010-06-09 20:19:47 +0000
@@ -722,6 +722,23 @@ static enum_operation_type file_operatio
 };
 
 /**
+  Conversion map from PSI_socket_operation to enum_operation_type.
+  Indexed by enum PSI_socket_operation.
+*/
+static enum_operation_type socket_operation_map[]=
+{
+  OPERATION_TYPE_SOCKETCREATE,
+  OPERATION_TYPE_SOCKETCONNECT,
+  OPERATION_TYPE_SOCKETBIND,
+  OPERATION_TYPE_SOCKETCLOSE,
+  OPERATION_TYPE_SOCKETSEND,
+  OPERATION_TYPE_SOCKETRECV,
+  OPERATION_TYPE_SOCKETSEEK,
+  OPERATION_TYPE_SOCKETOPT,
+  OPERATION_TYPE_SOCKETSTAT
+};
+
+/**
   Build the prefix name of a class of instruments in a category.
   For example, this function builds the string 'wait/sync/mutex/sql/' from
   a prefix 'wait/sync/mutex' and a category 'sql'.
@@ -851,6 +868,16 @@ static void register_file_v1(const char
                    register_file_class)
 }
 
+static void register_socket_v1(const char *category,
+                             PSI_socket_info_v1 *info,
+                             int count)
+{
+  REGISTER_BODY_V1(PSI_socket_key,
+                   socket_instrument_prefix,
+                   register_socket_class)
+}
+
+
 #define INIT_BODY_V1(T, KEY, ID)                                            \
   PFS_##T##_class *klass;                                                   \
   PFS_##T *pfs;                                                             \
@@ -1458,6 +1485,14 @@ get_thread_file_descriptor_locker_v1(Fil
   return NULL;
 }
 
+/** Socket locker */
+
+static PSI_socket_locker*
+get_thread_socket_locker_v1(PSI_socket *socket, PSI_socket_operation op)
+{
+  return NULL;
+}
+
 static void unlock_mutex_v1(PSI_thread * thread, PSI_mutex *mutex)
 {
   PFS_mutex *pfs_mutex= reinterpret_cast<PFS_mutex*> (mutex);
@@ -1808,6 +1843,8 @@ static void end_cond_wait_v1(PSI_cond_lo
   wait->m_thread->m_wait_locker_count--;
 }
 
+/** Table operations */
+
 static void start_table_wait_v1(PSI_table_locker* locker,
                                 const char *src_file, uint src_line)
 {
@@ -1864,6 +1901,8 @@ static void end_table_wait_v1(PSI_table_
   wait->m_thread->m_wait_locker_count--;
 }
 
+/** File operations */
+
 static void start_file_wait_v1(PSI_file_locker *locker,
                                size_t count,
                                const char *src_file,
@@ -1872,6 +1911,7 @@ static void start_file_wait_v1(PSI_file_
 static void end_file_wait_v1(PSI_file_locker *locker,
                              size_t count);
 
+
 static PSI_file* start_file_open_wait_v1(PSI_file_locker *locker,
                                          const char *src_file,
                                          uint src_line)
@@ -1990,6 +2030,24 @@ static void end_file_wait_v1(PSI_file_lo
   wait->m_thread->m_wait_locker_count--;
 }
 
+/** Socket operations */
+
+static void start_socket_wait_v1(PSI_socket_locker *locker,
+                                 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)
+{
+}
+
+static void end_socket_wait_v1(PSI_socket_locker *locker)
+{
+}
+
 PSI_v1 PFS_v1=
 {
   register_mutex_v1,
@@ -1997,6 +2055,7 @@ PSI_v1 PFS_v1=
   register_cond_v1,
   register_thread_v1,
   register_file_v1,
+  register_socket_v1,
   init_mutex_v1,
   destroy_mutex_v1,
   init_rwlock_v1,
@@ -2022,6 +2081,7 @@ PSI_v1 PFS_v1=
   get_thread_file_name_locker_v1,
   get_thread_file_stream_locker_v1,
   get_thread_file_descriptor_locker_v1,
+  get_thread_socket_locker_v1,
   unlock_mutex_v1,
   unlock_rwlock_v1,
   signal_cond_v1,
@@ -2040,7 +2100,9 @@ PSI_v1 PFS_v1=
   end_file_open_wait_v1,
   end_file_open_wait_and_bind_to_descriptor_v1,
   start_file_wait_v1,
-  end_file_wait_v1
+  end_file_wait_v1,
+  start_socket_wait_v1,
+  end_socket_wait_v1
 };
 
 static void* get_interface(int version)

=== modified file 'storage/perfschema/pfs_column_types.h'
--- a/storage/perfschema/pfs_column_types.h	2010-04-19 12:26:29 +0000
+++ b/storage/perfschema/pfs_column_types.h	2010-06-09 20:19:47 +0000
@@ -109,7 +109,17 @@ enum enum_operation_type
   OPERATION_TYPE_FILECHSIZE= 22,
   OPERATION_TYPE_FILEDELETE= 23,
   OPERATION_TYPE_FILERENAME= 24,
-  OPERATION_TYPE_FILESYNC= 25
+  OPERATION_TYPE_FILESYNC= 25,
+
+  OPERATION_TYPE_SOCKETCREATE = 26,
+  OPERATION_TYPE_SOCKETCONNECT = 27,
+  OPERATION_TYPE_SOCKETBIND = 28,
+  OPERATION_TYPE_SOCKETCLOSE = 29,
+  OPERATION_TYPE_SOCKETSEND = 30,
+  OPERATION_TYPE_SOCKETRECV = 31,
+  OPERATION_TYPE_SOCKETSEEK = 32,
+  OPERATION_TYPE_SOCKETOPT = 33,
+  OPERATION_TYPE_SOCKETSTAT = 34
 };
 #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_column_values.cc'
--- a/storage/perfschema/pfs_column_values.cc	2010-05-03 15:04:02 +0000
+++ b/storage/perfschema/pfs_column_values.cc	2010-06-09 20:19:47 +0000
@@ -39,3 +39,5 @@ LEX_STRING thread_instrument_prefix=
 LEX_STRING file_instrument_prefix=
 { C_STRING_WITH_LEN("wait/io/file/") };
 
+LEX_STRING socket_instrument_prefix=
+{ C_STRING_WITH_LEN("wait/io/socket/") };

=== modified file 'storage/perfschema/pfs_column_values.h'
--- a/storage/perfschema/pfs_column_values.h	2010-04-19 12:26:29 +0000
+++ b/storage/perfschema/pfs_column_values.h	2010-06-09 20:19:47 +0000
@@ -31,6 +31,7 @@ extern LEX_STRING rwlock_instrument_pref
 extern LEX_STRING cond_instrument_prefix;
 extern LEX_STRING thread_instrument_prefix;
 extern LEX_STRING file_instrument_prefix;
+extern LEX_STRING socket_instrument_prefix;
 
 #endif
 

=== modified file 'storage/perfschema/pfs_instr_class.cc'
--- a/storage/perfschema/pfs_instr_class.cc	2010-04-19 12:26:29 +0000
+++ b/storage/perfschema/pfs_instr_class.cc	2010-06-09 20:19:47 +0000
@@ -76,6 +76,10 @@ ulong thread_class_lost= 0;
 ulong file_class_max= 0;
 /** Number of file class lost. @sa file_class_array */
 ulong file_class_lost= 0;
+/** Size of the socket class array. @sa socket_class_array */
+ulong socket_class_max= 0;
+/** Number of socket class lost. @sa socket_class_array */
+ulong socket_class_lost= 0;
 /** Size of the table share array. @sa table_share_array */
 ulong table_share_max= 0;
 /** Number of table share lost. @sa table_share_array */
@@ -124,6 +128,12 @@ static volatile uint32 file_class_alloca
 
 static PFS_file_class *file_class_array= NULL;
 
+
+static volatile uint32 socket_class_dirty_count= 0;
+static volatile uint32 socket_class_allocated_count= 0;
+
+static PFS_socket_class *socket_class_array= NULL;
+
 /**
   Initialize the instrument synch class buffers.
   @param mutex_class_sizing           max number of mutex class
@@ -325,6 +335,41 @@ void cleanup_file_class(void)
   file_class_max= 0;
 }
 
+/**
+  Initialize the socket class buffer.
+  @param socket_class_sizing            max number of socket class
+  @return 0 on success
+*/
+int init_socket_class(uint socket_class_sizing)
+{
+  int result= 0;
+  socket_class_dirty_count= socket_class_allocated_count= 0;
+  socket_class_max= socket_class_sizing;
+  socket_class_lost= 0;
+
+  if (socket_class_max > 0)
+  {
+    socket_class_array= PFS_MALLOC_ARRAY(socket_class_max, PFS_socket_class,
+                                       MYF(MY_ZEROFILL));
+    if (unlikely(socket_class_array == NULL))
+      return 1;
+  }
+  else
+    socket_class_array= NULL;
+
+  return result;
+}
+
+/** Cleanup the socket class buffers. */
+void cleanup_socket_class(void)
+{
+  pfs_free(socket_class_array);
+  socket_class_array= NULL;
+  socket_class_dirty_count= socket_class_allocated_count= 0;
+  socket_class_max= 0;
+}
+
+
 static void init_instr_class(PFS_instr_class *klass,
                              const char *name,
                              uint name_length,
@@ -687,6 +732,57 @@ PFS_file_class *sanitize_file_class(PFS_
 }
 
 /**
+  Register a socket instrumentation metadata.
+  @param name                         the instrumented name
+  @param name_length                  length in bytes of name
+  @param flags                        the instrumentation flags
+  @return a socket instrumentation key
+*/
+PFS_socket_key register_socket_class(const char *name, uint name_length,
+                                 int flags)
+{
+  /* See comments in register_mutex_class */
+  uint32 index;
+  PFS_socket_class *entry;
+
+  REGISTER_CLASS_BODY_PART(index, socket_class_array, socket_class_max,
+                           name, name_length)
+
+  index= PFS_atomic::add_u32(&socket_class_dirty_count, 1);
+
+  if (index < socket_class_max)
+  {
+    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_parent= NULL;
+    reset_single_stat_link(&entry->m_wait_stat);
+    entry->m_index= index;
+    PFS_atomic::add_u32(&socket_class_allocated_count, 1);
+    return (index + 1);
+  }
+
+  socket_class_lost++;
+  return 0;
+}
+
+/**
+  Find a socket instrumentation class by key.
+  @param key                          the instrument key
+  @return the instrument class, or NULL
+*/
+PFS_socket_class *find_socket_class(PFS_socket_key key)
+{
+  FIND_CLASS_BODY(key, socket_class_allocated_count, socket_class_array);
+}
+
+PFS_socket_class *sanitize_socket_class(PFS_socket_class *unsafe)
+{
+  SANITIZE_ARRAY_BODY(socket_class_array, socket_class_max, unsafe);
+}
+
+/**
   Find or create a table instance by name.
   @param thread                       the executing instrumented thread
   @param schema_name                  the table schema name
@@ -855,6 +951,15 @@ static void reset_file_class_waits(void)
     reset_single_stat_link(&pfs->m_wait_stat);
 }
 
+static void reset_socket_class_waits(void)
+{
+  PFS_socket_class *pfs= socket_class_array;
+  PFS_socket_class *pfs_last= socket_class_array + socket_class_max;
+
+  for ( ; pfs < pfs_last; pfs++)
+    reset_single_stat_link(&pfs->m_wait_stat);
+}
+
 /** Reset the wait statistics for every instrument class. */
 void reset_instrument_class_waits(void)
 {
@@ -862,6 +967,7 @@ void reset_instrument_class_waits(void)
   reset_rwlock_class_waits();
   reset_cond_class_waits();
   reset_file_class_waits();
+  reset_socket_class_waits();
 }
 
 /** Reset the io statistics per file class. */

=== modified file 'storage/perfschema/pfs_instr_class.h'
--- a/storage/perfschema/pfs_instr_class.h	2010-05-03 15:04:02 +0000
+++ b/storage/perfschema/pfs_instr_class.h	2010-06-09 20:19:47 +0000
@@ -56,6 +56,8 @@ typedef unsigned int PFS_sync_key;
 typedef unsigned int PFS_thread_key;
 /** Key, naming a file instrument. */
 typedef unsigned int PFS_file_key;
+/** Key, naming a socket instrument. */
+typedef unsigned int PFS_socket_key;
 
 struct PFS_thread;
 
@@ -183,6 +185,15 @@ struct PFS_file_class : public PFS_instr
   uint m_index;
 };
 
+/** Instrumentation metadata for a socket. */
+struct PFS_socket_class : public PFS_instr_class
+{
+  /** Socket usage statistics. */
+  PFS_socket_stat m_socket_stat;
+  /** Self index in @c socket_class_array. */
+  uint m_index;
+};
+
 int init_sync_class(uint mutex_class_sizing,
                     uint rwlock_class_sizing,
                     uint cond_class_sizing);
@@ -196,6 +207,8 @@ int init_table_share_hash();
 void cleanup_table_share_hash();
 int init_file_class(uint file_class_sizing);
 void cleanup_file_class();
+int init_socket_class(uint socket_class_sizing);
+void cleanup_socket_class();
 
 PFS_sync_key register_mutex_class(const char *name, uint name_length,
                                   int flags);
@@ -211,6 +224,8 @@ PFS_thread_key register_thread_class(con
 
 PFS_file_key register_file_class(const char *name, uint name_length,
                                  int flags);
+PFS_socket_key register_socket_class(const char *name, uint name_length,
+                                 int flags);
 
 PFS_mutex_class *find_mutex_class(PSI_mutex_key key);
 PFS_mutex_class *sanitize_mutex_class(PFS_mutex_class *unsafe);
@@ -222,6 +237,8 @@ PFS_thread_class *find_thread_class(PSI_
 PFS_thread_class *sanitize_thread_class(PFS_thread_class *unsafe);
 PFS_file_class *find_file_class(PSI_file_key key);
 PFS_file_class *sanitize_file_class(PFS_file_class *unsafe);
+PFS_socket_class *find_socket_class(PSI_socket_key key);
+PFS_socket_class *sanitize_socket_class(PFS_socket_class *unsafe);
 
 PFS_table_share *find_or_create_table_share(PFS_thread *thread,
                                             const char *schema_name,
@@ -241,6 +258,8 @@ extern ulong thread_class_max;
 extern ulong thread_class_lost;
 extern ulong file_class_max;
 extern ulong file_class_lost;
+extern ulong socket_class_max;
+extern ulong socket_class_lost;
 extern ulong table_share_max;
 extern ulong table_share_lost;
 extern PFS_table_share *table_share_array;

=== modified file 'storage/perfschema/pfs_stat.h'
--- a/storage/perfschema/pfs_stat.h	2010-04-19 12:26:29 +0000
+++ b/storage/perfschema/pfs_stat.h	2010-06-09 20:19:47 +0000
@@ -120,6 +120,34 @@ inline void reset_file_stat(PFS_file_sta
   stat->m_write_bytes= 0;
 }
 
+/** Statistics for SOCKET usage. */
+struct PFS_socket_stat
+{
+  /** Number of current open sockets. */
+  ulong m_open_count;
+  /** Count of RECV operations. */
+  ulonglong m_count_recv;
+  /** Count of SEND operations. */
+  ulonglong m_count_send;
+  /** Number of bytes received. */
+  ulonglong m_recv_bytes;
+  /** Number of bytes sent. */
+  ulonglong m_send_bytes;
+};
+
+/**
+  Reset socket statistic.
+  @param stat                         the statistics to reset
+*/
+inline void reset_socket_stat(PFS_socket_stat *stat)
+{
+  stat->m_open_count= 0;
+  stat->m_count_recv= 0;
+  stat->m_count_send= 0;
+  stat->m_recv_bytes= 0;
+  stat->m_send_bytes= 0;
+}
+
 /** @} */
 #endif
 


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