List:Commits« Previous MessageNext Message »
From:Christopher Powers Date:March 14 2011 4:30pm
Subject:bzr push into mysql-trunk branch (chris.powers:3254 to 3256) WL#4896
View as plain text  
 3256 Christopher Powers	2011-03-14
      WL#4896 "Performance Schema Net IO"
      
      - API change: Updated ps_abi_v1.h.pp

    modified:
      include/mysql/psi/psi_abi_v1.h.pp
 3255 cpowers	2011-03-14
      WL#4896 "Performance Schema Net IO"
      
      - Replaced get_thread_id() API with set_socket_owner()
      - Replaced PFS_socket.m_thread_id with m_thread_owner
      - SOCKET_INSTANCES.THREAD_ID displays owning thread id if availble, else NULL  

    modified:
      include/mysql/psi/mysql_socket.h
      include/mysql/psi/psi.h
      storage/perfschema/pfs.cc
      storage/perfschema/pfs_instr.h
      storage/perfschema/table_socket_instances.cc
 3254 cpowers	2011-03-11
      WL#4896 "Performance Schema Net IO"
      
      - Added get_thread_id API
      - Set corresponding thread_id during socket create

    modified:
      include/mysql/psi/mysql_socket.h
      include/mysql/psi/psi.h
      storage/perfschema/pfs.cc
=== modified file 'include/mysql/psi/mysql_socket.h'
--- a/include/mysql/psi/mysql_socket.h	2011-03-12 00:00:13 +0000
+++ b/include/mysql/psi/mysql_socket.h	2011-03-14 16:11:25 +0000
@@ -400,22 +400,16 @@ inline_mysql_socket_socket
   int domain, int type, int protocol)
 {
   MYSQL_SOCKET mysql_socket;
-  ulong thread_id;
 
   mysql_socket.fd= socket(domain, type, protocol);
 
 #ifdef HAVE_PSI_INTERFACE
-  mysql_socket.m_psi = PSI_server ? PSI_server->init_socket(key, &mysql_socket.fd)
-                                  : NULL;
+  mysql_socket.m_psi = PSI_server ?
+                       PSI_server->init_socket(key, &mysql_socket.fd) : NULL;
 
   if (likely(PSI_server != NULL && mysql_socket.m_psi != NULL
              && mysql_socket.fd != -1))
-    {
-      thread_id= PSI_server->get_thread_id();
-      PSI_server->set_socket_info(mysql_socket.m_psi, &mysql_socket.fd,
-                                  NULL, 0, thread_id);
-    }
-
+    PSI_server->set_socket_info(mysql_socket.m_psi, &mysql_socket.fd, NULL, 0);
 #endif
   return mysql_socket;
 }
@@ -800,22 +794,18 @@ inline_mysql_socket_accept
   MYSQL_SOCKET socket_listen, struct sockaddr *addr, socklen_t *addr_len)
 {
   MYSQL_SOCKET socket_accept = MYSQL_INVALID_SOCKET;
-  ulong thread_id;
 
   socket_accept.fd= accept(socket_listen.fd, addr, addr_len);
 
   /** Initialize the instrument with the new socket descriptor and address */
   #ifdef HAVE_PSI_INTERFACE
   socket_accept.m_psi = PSI_server ?
-          PSI_server->init_socket(key, (const void *)&socket_accept.fd) : NULL;
+          PSI_server->init_socket(key, (const my_socket*)&socket_accept.fd) : NULL;
 
   if (likely(PSI_server != NULL && socket_accept.m_psi != NULL
              && socket_accept.fd != -1))
-    {
-      thread_id= PSI_server->get_thread_id();
-      PSI_server->set_socket_info(socket_accept.m_psi, &socket_accept.fd,
-                                  addr, addr_len, thread_id);
-    }
+    PSI_server->set_socket_info(socket_accept.m_psi, &socket_accept.fd,
+                                addr, addr_len);
 #endif
   return socket_accept;
 }

=== modified file 'include/mysql/psi/psi.h'
--- a/include/mysql/psi/psi.h	2011-03-12 00:00:13 +0000
+++ b/include/mysql/psi/psi.h	2011-03-14 16:11:25 +0000
@@ -826,7 +826,7 @@ typedef void (*destroy_cond_v1_t)(struct
   @return an instrumented socket
 */
 typedef struct PSI_socket* (*init_socket_v1_t)
-  (PSI_socket_key key, const void *identity);
+  (PSI_socket_key key, const my_socket *fd);
 
 /**
   socket instrumentation destruction API.
@@ -928,15 +928,6 @@ typedef void (*set_thread_id_v1_t)(struc
 typedef struct PSI_thread* (*get_thread_v1_t)(void);
 
 /**
-  Get the thread id of the running thread.
-  For this function to return a result,
-  the thread instrumentation must have been attached to the
-  running thread using @c set_thread()
-  @return the thread id of the running thread
-*/
-typedef ulong (*get_thread_id_v1_t)(void);
-
-/**
   Assign a user name to the instrumented thread.
   @param user the user name
   @param user_len the user name length
@@ -1333,8 +1324,15 @@ typedef void (*set_socket_address_v1_t)(
 typedef void (*set_socket_info_v1_t)(struct PSI_socket *socket,
                                      my_socket *fd,
                                      const struct sockaddr *addr,
-                                     socklen_t *addr_len,
-                                     ulong thread_id);
+                                     socklen_t *addr_len);
+
+/**
+  Set the id of the thread owning the socket.
+  @param socket instrumented socket
+  @param thread instrumented thread
+*/
+typedef void (*set_socket_thread_owner_v1_t)(struct PSI_socket *socket,
+                                             struct PSI_thread *thread);
 
 /**
   Performance Schema Interface, version 1.
@@ -1390,8 +1388,6 @@ struct PSI_v1
   set_thread_id_v1_t set_thread_id;
   /** @sa get_thread_v1_t. */
   get_thread_v1_t get_thread;
-  /** @sa get_thread_id_v1_t. */
-  get_thread_id_v1_t get_thread_id;
   /** @sa set_thread_user_v1_t. */
   set_thread_user_v1_t set_thread_user;
   /** @sa set_thread_user_host_v1_t. */
@@ -1483,6 +1479,8 @@ struct PSI_v1
   set_socket_address_v1_t set_socket_address;
   /** @sa set_socket_info_v1_t. */
   set_socket_info_v1_t set_socket_info;
+  /** @sa set_socket_thread_owner_v1_t. */
+  set_socket_thread_owner_v1_t set_socket_thread_owner;
 };
 
 /** @} (end of group Group_PSI_v1) */

=== modified file 'include/mysql/psi/psi_abi_v1.h.pp'
--- a/include/mysql/psi/psi_abi_v1.h.pp	2011-03-09 23:28:32 +0000
+++ b/include/mysql/psi/psi_abi_v1.h.pp	2011-03-14 16:29:27 +0000
@@ -225,7 +225,7 @@ typedef struct PSI_cond* (*init_cond_v1_
   (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);
+  (PSI_socket_key key, const my_socket *fd);
 typedef void (*destroy_socket_v1_t)(struct PSI_socket *socket);
 typedef struct PSI_table_share* (*get_table_share_v1_t)
   (my_bool temporary, struct TABLE_SHARE *share);
@@ -343,6 +343,8 @@ typedef void (*set_socket_info_v1_t)(str
                                      my_socket *fd,
                                      const struct sockaddr *addr,
                                      socklen_t *addr_len);
+typedef void (*set_socket_thread_owner_v1_t)(struct PSI_socket *socket,
+                                             struct PSI_thread *thread);
 struct PSI_v1
 {
   register_mutex_v1_t register_mutex;
@@ -415,6 +417,7 @@ struct PSI_v1
   set_socket_descriptor_v1_t set_socket_descriptor;
   set_socket_address_v1_t set_socket_address;
   set_socket_info_v1_t set_socket_info;
+  set_socket_thread_owner_v1_t set_socket_thread_owner;
 };
 typedef struct PSI_v1 PSI;
 typedef struct PSI_mutex_info_v1 PSI_mutex_info;

=== modified file 'storage/perfschema/pfs.cc'
--- a/storage/perfschema/pfs.cc	2011-03-12 00:00:13 +0000
+++ b/storage/perfschema/pfs.cc	2011-03-14 16:11:25 +0000
@@ -1370,12 +1370,12 @@ static void close_table_v1(PSI_table *ta
 }
 
 static PSI_socket*
-init_socket_v1(PSI_socket_key key, const void *identity)
+init_socket_v1(PSI_socket_key key, const my_socket *fd)
 {
-  INIT_BODY_V1(socket, key, identity);
+  INIT_BODY_V1(socket, key, fd);
 }
 
-static void destroy_socket_v1(PSI_socket* socket)
+static void destroy_socket_v1(PSI_socket *socket)
 {
   PFS_socket *pfs= reinterpret_cast<PFS_socket*> (socket);
   destroy_socket(pfs);
@@ -1554,17 +1554,6 @@ get_thread_v1(void)
 
 /**
   Implementation of the thread instrumentation interface.
-  @sa PSI_v1::get_thread.
-*/
-static ulong
-get_thread_id_v1(void)
-{
-  PFS_thread *pfs= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
-  return (likely(pfs != NULL) ? pfs->m_thread_id : 0);
-}
-
-/**
-  Implementation of the thread instrumentation interface.
   @sa PSI_v1::set_thread_user.
 */
 static void set_thread_user_v1(const char *user, int user_len)
@@ -3816,8 +3805,7 @@ static void set_socket_address_v1(PSI_so
 static void set_socket_info_v1(PSI_socket *socket,
                                my_socket *fd,
                                const struct sockaddr *addr,
-                               socklen_t *addr_len,
-                               ulong thread_id)
+                               socklen_t *addr_len)
 {
   DBUG_ASSERT(socket);
   PFS_socket *pfs= reinterpret_cast<PFS_socket*>(socket);
@@ -3838,9 +3826,19 @@ static void set_socket_info_v1(PSI_socke
     if (likely(pfs->m_sock_len > 0))
       memcpy(&pfs->m_sock_addr, addr, pfs->m_sock_len);
   }
+}
 
-  /** Set thread id associated with this socket */
-  pfs->m_thread_id= thread_id;
+/**
+  Implementation of the socket instrumentation interface.
+  @sa PSI_v1::set_socket_info.
+*/
+static void set_socket_thread_owner_v1(PSI_socket *socket, PSI_thread *thread)
+{
+  if (likely(socket != NULL && thread != NULL))
+  {
+    PFS_socket *pfs_socket= reinterpret_cast<PFS_socket*>(socket);
+    pfs_socket->m_thread_owner= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
+  }
 }
 
 /**
@@ -3873,7 +3871,6 @@ PSI_v1 PFS_v1=
   new_thread_v1,
   set_thread_id_v1,
   get_thread_v1,
-  get_thread_id_v1,
   set_thread_user_v1,
   set_thread_user_host_v1,
   set_thread_db_v1,
@@ -3918,7 +3915,8 @@ PSI_v1 PFS_v1=
   end_socket_wait_v1,
   set_socket_descriptor_v1,
   set_socket_address_v1,
-  set_socket_info_v1
+  set_socket_info_v1,
+  set_socket_thread_owner_v1
 };
 
 static void* get_interface(int version)

=== modified file 'storage/perfschema/pfs_instr.h'
--- a/storage/perfschema/pfs_instr.h	2011-03-09 21:28:05 +0000
+++ b/storage/perfschema/pfs_instr.h	2011-03-14 16:11:25 +0000
@@ -202,8 +202,8 @@ struct PFS_socket : public PFS_instr
 
   /** Socket identity, typically int */
   const void *m_identity;
-  /** Thread identifier */
-  uint m_thread_id;
+  /** Owning thread, if applicable */
+  PFS_thread *m_thread_owner;
   /** Socket file descriptor */
   uint m_fd;
   /** Raw socket address */

=== modified file 'storage/perfschema/table_socket_instances.cc'
--- a/storage/perfschema/table_socket_instances.cc	2011-03-09 21:28:05 +0000
+++ b/storage/perfschema/table_socket_instances.cc	2011-03-14 16:11:25 +0000
@@ -154,9 +154,13 @@ void table_socket_instances::make_row(PF
   m_row.m_event_name=         safe_class->m_name;
   m_row.m_event_name_length=  safe_class->m_name_length;
   m_row.m_identity=           pfs->m_identity;
-  m_row.m_thread_id=          pfs->m_thread_id;
   m_row.m_fd=                 pfs->m_fd;
 
+  PFS_thread *safe_thread= sanitize_thread(pfs->m_thread_owner);
+
+  if (safe_thread != NULL)
+    m_row.m_thread_id= safe_thread->m_thread_id;
+
   if (pfs->m_lock.end_optimistic_lock(&lock))
     m_row_exists= true;
 }
@@ -187,7 +191,10 @@ int table_socket_instances::read_row_val
         set_field_ulonglong(f, (intptr)m_row.m_identity);
         break;
       case 2: /* THREAD_ID */
-        set_field_ulong(f, m_row.m_thread_id);
+        if (m_row.m_thread_id != 0) // TBD: use flag to indicate valid thread id?
+          set_field_ulong(f, m_row.m_thread_id);
+        else
+          f->set_null();
         break;
       case 3: /* SOCKET_ID */
         set_field_ulong(f, m_row.m_fd);


Attachment: [text/bzr-bundle] bzr/chris.powers@oracle.com-20110314162927-qs4b586w8sr422vi.bundle
Thread
bzr push into mysql-trunk branch (chris.powers:3254 to 3256) WL#4896Christopher Powers14 Mar