List:Commits« Previous MessageNext Message »
From:Marc Alff Date:August 18 2011 12:28pm
Subject:bzr push into mysql-trunk branch (marc.alff:3379 to 3380) WL#4896
View as plain text  
 3380 Marc Alff	2011-08-18
      WL#4896 PERFORMANCE_SCHEMA NET IO
      
      Code cleanup for destroy_socket

    modified:
      include/mysql/psi/mysql_socket.h
      storage/perfschema/pfs.cc
      storage/perfschema/pfs_instr.cc
      storage/perfschema/pfs_instr.h
      storage/perfschema/table_socket_summary_by_instance.cc
 3379 Christopher Powers	2011-08-18
      WL#4896 "Performance Schema Net IO"
      
      Disable socket_instances check in mtr_check.sql until 
      incomplete test case cleanup can be ruled out as a source
      of failures, particularly with RPL.

    modified:
      mysql-test/include/mtr_check.sql
=== modified file 'include/mysql/psi/mysql_socket.h'
--- a/include/mysql/psi/mysql_socket.h	2011-08-11 16:07:45 +0000
+++ b/include/mysql/psi/mysql_socket.h	2011-08-18 12:27:21 +0000
@@ -540,6 +540,8 @@ inline_mysql_socket_socket
 
   if (likely(mysql_socket.fd != INVALID_SOCKET && mysql_socket.m_psi != NULL))
     PSI_CALL(set_socket_info)(mysql_socket.m_psi, &mysql_socket.fd, NULL, 0);
+#else
+  mysql_socket.m_psi= NULL;
 #endif
   return mysql_socket;
 }
@@ -925,10 +927,16 @@ inline_mysql_socket_close
     PSI_CALL(start_socket_wait)(locker, (size_t)0, src_file, src_line);
     result= closesocket(mysql_socket.fd);
     PSI_CALL(end_socket_wait)(locker, (size_t)0);
+    /* Remove the instrumentation for this socket. */
+    PSI_CALL(destroy_socket)(mysql_socket.m_psi);
     return result;
   }
 #endif
   result= closesocket(mysql_socket.fd);
+#ifdef HAVE_PSI_SOCKET_INTERFACE
+  /* Remove the instrumentation for this socket. */
+  PSI_CALL(destroy_socket)(mysql_socket.m_psi);
+#endif
   return result;
 }
 

=== modified file 'storage/perfschema/pfs.cc'
--- a/storage/perfschema/pfs.cc	2011-08-18 05:58:49 +0000
+++ b/storage/perfschema/pfs.cc	2011-08-18 12:27:21 +0000
@@ -2836,93 +2836,75 @@ get_thread_socket_locker_v1(PSI_socket_l
 
   DBUG_ASSERT(pfs_socket->m_class != NULL);
 
-  my_bool socket_close= false;
+  if (!pfs_socket->m_enabled || pfs_socket->m_idle)
+    return NULL;
+
   register uint flags= 0;
 
-  if (!pfs_socket->m_enabled || pfs_socket->m_idle)
+  if (flag_thread_instrumentation)
   {
-    if (op == PSI_SOCKET_CLOSE)
-      socket_close= true;
-    else
+    PFS_thread *pfs_thread= pfs_socket->m_thread_owner;
+
+    if (unlikely(pfs_thread == NULL))
       return NULL;
-  }
 
-  PFS_thread *pfs_thread= pfs_socket->m_thread_owner;
+    DBUG_ASSERT(pfs_thread ==
+                my_pthread_getspecific_ptr(PFS_thread*, THR_PFS));
 
-  if (flag_thread_instrumentation && likely(pfs_thread != NULL) &&
-      likely(!socket_close))
-  {
-    //PFS_thread *pfs_thread= pfs_socket->m_thread_owner;
+    if (!pfs_thread->m_enabled)
+      return NULL;
 
-    //if (unlikely(pfs_thread == NULL))
-    //  return NULL;
+    state->m_thread= reinterpret_cast<PSI_thread *> (pfs_thread);
+    flags= STATE_FLAG_THREAD;
 
-    /*
-      If instrumentation for this thread has been disabled, then return a null
-      locker *unless* this is a socket close, in which case end_socket_wait()
-      will later call destroy_socket().
-    */
-    if (!pfs_thread->m_enabled)
+    if (pfs_socket->m_timed && !pfs_socket->m_idle)
+      flags|= STATE_FLAG_TIMED;
+
+    if (flag_events_waits_current)
     {
-      if (op != PSI_SOCKET_CLOSE)
+      if (unlikely(pfs_thread->m_events_waits_count >= WAIT_STACK_SIZE))
+      {
+        locker_lost++;
         return NULL;
-    }
-    else
-    {
-      state->m_thread= reinterpret_cast<PSI_thread *> (pfs_thread);
-      flags= STATE_FLAG_THREAD;
-
-      if (pfs_socket->m_timed & !pfs_socket->m_idle)
-        flags|= STATE_FLAG_TIMED;
+      }
+      PFS_events_waits *wait= &pfs_thread->m_events_waits_stack[pfs_thread->m_events_waits_count];
+      state->m_wait= wait;
+      flags|= STATE_FLAG_EVENT;
 
-      if (flag_events_waits_current)
-      {
-        if (unlikely(pfs_thread->m_events_waits_count >= WAIT_STACK_SIZE))
-        {
-          locker_lost++;
-          return NULL;
-        }
-        PFS_events_waits *wait= &pfs_thread->m_events_waits_stack[pfs_thread->m_events_waits_count];
-        state->m_wait= wait;
-        flags|= STATE_FLAG_EVENT;
-
-        PFS_events_waits *parent_event= wait - 1;
-        wait->m_event_type= EVENT_TYPE_WAIT;
-        wait->m_nesting_event_id=   parent_event->m_event_id;
-        wait->m_nesting_event_type= parent_event->m_event_type;
-        wait->m_thread=       pfs_thread;
-        wait->m_class=        pfs_socket->m_class;
-        wait->m_timer_start=  0;
-        wait->m_timer_end=    0;
-        wait->m_object_instance_addr= pfs_socket->m_identity;
-        wait->m_weak_socket=  pfs_socket;
-        wait->m_weak_version= pfs_socket->get_version();
-        wait->m_event_id=     pfs_thread->m_event_id++;
-        wait->m_operation=    socket_operation_map[static_cast<int>(op)];
-        wait->m_wait_class=   WAIT_CLASS_SOCKET;
+      PFS_events_waits *parent_event= wait - 1;
+      wait->m_event_type= EVENT_TYPE_WAIT;
+      wait->m_nesting_event_id=   parent_event->m_event_id;
+      wait->m_nesting_event_type= parent_event->m_event_type;
+      wait->m_thread=       pfs_thread;
+      wait->m_class=        pfs_socket->m_class;
+      wait->m_timer_start=  0;
+      wait->m_timer_end=    0;
+      wait->m_object_instance_addr= pfs_socket->m_identity;
+      wait->m_weak_socket=  pfs_socket;
+      wait->m_weak_version= pfs_socket->get_version();
+      wait->m_event_id=     pfs_thread->m_event_id++;
+      wait->m_operation=    socket_operation_map[static_cast<int>(op)];
+      wait->m_wait_class=   WAIT_CLASS_SOCKET;
 
-        pfs_thread->m_events_waits_count++;
-      }
+      pfs_thread->m_events_waits_count++;
     }
   }
   else
   {
-    if (!socket_close)
+    if (pfs_socket->m_timed)
     {
-      if (pfs_socket->m_timed)
-      {
-        flags= STATE_FLAG_TIMED;
-      }
-      else
+      flags= STATE_FLAG_TIMED;
+    }
+    else
+    {
+      /*
+        Even if timing is disabled, end_socket_wait() still needs a locker to
+        capture the number of bytes sent or received by the socket operation.
+        For operations that do not have a byte count, then just increment the
+        event counter and return a NULL locker.
+      */
+      switch (op)
       {
-        /*
-          Even if timing is disabled, end_socket_wait() still needs a locker to
-          capture the number of bytes sent or received by the socket operation.
-          For operations that do not have a byte count, then just increment the
-          event counter and return a NULL locker.
-        */
-        switch (op)
-        {
         case PSI_SOCKET_CONNECT:
         case PSI_SOCKET_CREATE:
         case PSI_SOCKET_BIND:
@@ -2932,14 +2914,10 @@ get_thread_socket_locker_v1(PSI_socket_l
         case PSI_SOCKET_SHUTDOWN:
         case PSI_SOCKET_CLOSE:
         case PSI_SOCKET_SELECT:
-          {
           pfs_socket->m_socket_stat.m_io_stat.m_misc.aggregate_counted();
           return NULL;
-          }
-          break;
         default:
           break;
-        }
       }
     }
   }
@@ -4668,26 +4646,25 @@ static void end_socket_wait_v1(PSI_socke
 
   ulonglong timer_end= 0;
   ulonglong wait_time= 0;
-  bool socket_closed= false;
   PFS_byte_stat *byte_stat;
   register uint flags= state->m_flags;
   size_t bytes= ((int)byte_count > -1 ? byte_count : 0);
-  
+
   switch (state->m_operation)
   {
-    /** Group read operations */
+    /* Group read operations */
     case PSI_SOCKET_RECV:
     case PSI_SOCKET_RECVFROM:
     case PSI_SOCKET_RECVMSG:
       byte_stat= &socket->m_socket_stat.m_io_stat.m_read;
       break;
-    /** Group write operations */
+    /* Group write operations */
     case PSI_SOCKET_SEND:
     case PSI_SOCKET_SENDTO:
     case PSI_SOCKET_SENDMSG:
       byte_stat= &socket->m_socket_stat.m_io_stat.m_write;
       break;
-    /** Group remainging operations as miscellaneous */
+    /* Group remaining operations as miscellaneous */
     case PSI_SOCKET_CONNECT:
     case PSI_SOCKET_CREATE:
     case PSI_SOCKET_BIND:
@@ -4700,17 +4677,14 @@ static void end_socket_wait_v1(PSI_socke
       break;
     case PSI_SOCKET_CLOSE:
       byte_stat= &socket->m_socket_stat.m_io_stat.m_misc;
-      /* This socket will no longer be used by the server */
-      socket_closed= true;
       break;
-
     default:
       DBUG_ASSERT(false);
       byte_stat= NULL;
       break;
   }
 
-  /** Aggregation for EVENTS_WAITS_SUMMARY_BY_INSTANCE */
+  /* Aggregation for EVENTS_WAITS_SUMMARY_BY_INSTANCE */
   if (flags & STATE_FLAG_TIMED)
   {
     timer_end= state->m_timer();
@@ -4725,47 +4699,23 @@ static void end_socket_wait_v1(PSI_socke
     byte_stat->aggregate_counted(bytes);
   }
 
-  /** Global thread aggregation */
-  if (flags & STATE_FLAG_THREAD)
+  /* Aggregate to EVENTS_WAITS_HISTORY and EVENTS_WAITS_HISTORY_LONG */
+  if (flags & STATE_FLAG_EVENT)
   {
     PFS_thread *thread= reinterpret_cast<PFS_thread *>(state->m_thread);
     DBUG_ASSERT(thread != NULL);
+    PFS_events_waits *wait= reinterpret_cast<PFS_events_waits*> (state->m_wait);
+    DBUG_ASSERT(wait != NULL);
 
-    PFS_single_stat *event_name_array;
-    event_name_array= thread->m_instr_class_waits_stats;
-    uint index= socket->m_class->m_event_name_index;
-
-    /* Reduce overhead by aggregating after the socket has been closed. */
-    if (socket_closed)
-    {
-      /* Combine stats for all operations */
-      PFS_single_stat stat;
-      socket->m_socket_stat.m_io_stat.sum_waits(&stat);
-
-      /* Aggregate to EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME (timed) */
-      event_name_array[index].aggregate(&stat);
-    }
-
-    /* Aggregate to EVENTS_WAITS_CURRENT and EVENTS_WAITS_HISTORY */
-    if (flags & STATE_FLAG_EVENT)
-    {
-      PFS_events_waits *wait= reinterpret_cast<PFS_events_waits*> (state->m_wait);
-      DBUG_ASSERT(wait != NULL);
-
-      wait->m_timer_end= timer_end;
-      wait->m_number_of_bytes= bytes;
+    wait->m_timer_end= timer_end;
+    wait->m_number_of_bytes= bytes;
 
-      if (flag_events_waits_history)
-        insert_events_waits_history(thread, wait);
-      if (flag_events_waits_history_long)
-        insert_events_waits_history_long(wait);
-      thread->m_events_waits_count--;
-    }
+    if (flag_events_waits_history)
+      insert_events_waits_history(thread, wait);
+    if (flag_events_waits_history_long)
+      insert_events_waits_history_long(wait);
+    thread->m_events_waits_count--;
   }
-
-  /* This socket will no longer be used */
-  if (socket_closed)
-    destroy_socket(socket);
 }
 
 static void set_socket_state_v1(PSI_socket *socket, PSI_socket_state state)
@@ -4774,11 +4724,13 @@ static void set_socket_state_v1(PSI_sock
   if (unlikely(socket == NULL))
     return;
   PFS_socket *pfs= reinterpret_cast<PFS_socket*>(socket);
+  DBUG_ASSERT(pfs->m_idle || (state == PSI_SOCKET_STATE_IDLE));
+  DBUG_ASSERT(!pfs->m_idle || (state == PSI_SOCKET_STATE_ACTIVE));
   pfs->m_idle= (state == PSI_SOCKET_STATE_IDLE);
 }
 
 /**
-  Set socket descriptor and addres info.
+  Set socket descriptor and address info.
 */
 static void set_socket_info_v1(PSI_socket *socket,
                                const my_socket *fd,

=== modified file 'storage/perfschema/pfs_instr.cc'
--- a/storage/perfschema/pfs_instr.cc	2011-08-11 03:11:58 +0000
+++ b/storage/perfschema/pfs_instr.cc	2011-08-18 12:27:21 +0000
@@ -1469,8 +1469,8 @@ PFS_socket* create_socket(PFS_socket_cla
           pfs->m_fd= fd;
           pfs->m_identity= pfs;
           pfs->m_class= klass;
-		      pfs->m_enabled= klass->m_enabled && flag_global_instrumentation;
-		      pfs->m_timed= klass->m_timed;
+          pfs->m_enabled= klass->m_enabled && flag_global_instrumentation;
+          pfs->m_timed= klass->m_timed;
           pfs->m_idle= false;
           pfs->m_socket_stat.reset();
           pfs->m_lock.dirty_to_allocated();
@@ -1488,15 +1488,6 @@ PFS_socket* create_socket(PFS_socket_cla
 }
 
 /**
-  Release instrumentation for a socket instance.
-  @param pfs                          the socket to release
-*/
-void release_socket(PFS_socket *pfs)
-{
-  DBUG_ASSERT(pfs != NULL);
-}
-
-/**
   Destroy instrumentation for a socket instance.
   @param pfs                          the socket to destroy
 */
@@ -1507,11 +1498,25 @@ void destroy_socket(PFS_socket *pfs)
 
   /* Aggregate to SOCKET_SUMMARY_BY_EVENT_NAME */
   klass->m_socket_stat.m_io_stat.aggregate(&pfs->m_socket_stat.m_io_stat);
-  pfs->m_socket_stat.reset();
 
   if (klass->is_singleton())
     klass->m_singleton= NULL;
 
+  /* Aggregate to EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME */
+  PFS_thread *thread= pfs->m_thread_owner;
+  if (thread != NULL)
+  {
+    PFS_single_stat *event_name_array;
+    event_name_array= thread->m_instr_class_waits_stats;
+    uint index= pfs->m_class->m_event_name_index;
+
+    /* Combine stats for all operations */
+    PFS_single_stat stat;
+    pfs->m_socket_stat.m_io_stat.sum_waits(&stat);
+    event_name_array[index].aggregate(&stat);
+  }
+
+  pfs->m_socket_stat.reset();
   pfs->m_thread_owner= NULL;
   pfs->m_fd= 0;
   pfs->m_addr_len= 0;

=== modified file 'storage/perfschema/pfs_instr.h'
--- a/storage/perfschema/pfs_instr.h	2011-08-11 03:11:58 +0000
+++ b/storage/perfschema/pfs_instr.h	2011-08-18 12:27:21 +0000
@@ -513,7 +513,6 @@ PFS_table* create_table(PFS_table_share
 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. */

=== modified file 'storage/perfschema/table_socket_summary_by_instance.cc'
--- a/storage/perfschema/table_socket_summary_by_instance.cc	2011-04-27 23:24:59 +0000
+++ b/storage/perfschema/table_socket_summary_by_instance.cc	2011-08-18 12:27:21 +0000
@@ -252,15 +252,15 @@ void table_socket_summary_by_instance::m
   m_row.m_event_name.make_row(safe_class);
   m_row.m_identity= pfs->m_identity;
 
+  time_normalizer *normalizer= time_normalizer::get(wait_timer);
+
+  /* Collect timer and byte count stats */
+  m_row.m_io_stat.set(normalizer, &pfs->m_socket_stat.m_io_stat);
+
   if (!pfs->m_lock.end_optimistic_lock(&lock))
     return;
 
   m_row_exists= true;
-
-  time_normalizer *normalizer= time_normalizer::get(wait_timer);
-  
-  /* Collect timer and byte count stats */
-  m_row.m_io_stat.set(normalizer, &pfs->m_socket_stat.m_io_stat);
 }
 
 int table_socket_summary_by_instance::read_row_values(TABLE *table,

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-trunk branch (marc.alff:3379 to 3380) WL#4896Marc Alff22 Aug