List:Commits« Previous MessageNext Message »
From:Christopher Powers Date:February 16 2011 10:55pm
Subject:bzr push into mysql-trunk-wl5379 branch (chris.powers:3230 to 3231) WL#4896
View as plain text  
 3231 cpowers	2011-02-16
      WL#4896 "Performance Schema Net IO"
      
      - Renamed performance_schema_max_sockets to ..max_socket_instances
      - Fixed events_waits aggregation for timer waits
      - close_socket instrument now destroys PFS socket instance
      - Renamed PFS_single_stat.aggregate_timed() to aggregate_value()
      - Added status variable performance_schema_socket_classes_lost
      - Enabled socket_shutdown() and socket_close() instruments
      - Instrumented vio::fastsend()

    modified:
      include/mysql/psi/mysql_socket.h
      sql/sys_vars.cc
      storage/perfschema/ha_perfschema.cc
      storage/perfschema/pfs.cc
      storage/perfschema/pfs_instr_class.h
      storage/perfschema/pfs_stat.h
      vio/vio.c
      vio/viosocket.c
 3230 cpowers	2011-02-14
      WL#4896 "Performance Schema Net IO"
      
      - Added events_waits hooks
      - Added object_name info as ip:port

    modified:
      storage/perfschema/pfs.cc
      storage/perfschema/pfs_events_waits.h
      storage/perfschema/pfs_instr.h
      storage/perfschema/table_events_waits.cc
      storage/perfschema/table_events_waits.h
=== modified file 'include/mysql/psi/mysql_socket.h'
--- a/include/mysql/psi/mysql_socket.h	2011-02-12 00:22:15 +0000
+++ b/include/mysql/psi/mysql_socket.h	2011-02-16 22:53:35 +0000
@@ -242,17 +242,6 @@ inline_mysql_end_socket_wait(struct PSI_
     inline_mysql_socket_accept(FD, A, LP)
 #endif
 
-/** Not supported by P_S */
-#if 0
-  #ifdef HAVE_PSI_INTERFACE
-    #define mysql_socket_accept4(K, FD, A, LP, FL) \
-      inline_mysql_socket_accept4(K, __FILE__, __LINE__, FD, A, LP, FL)
-  #else
-    #define mysql_socket_accept4(FD, A, LP, FL) \
-      inline_mysql_socket_accept4(FD, A, LP, FL)
-  #endif
-#endif
-
 #ifdef HAVE_PSI_INTERFACE
   #define mysql_socket_close(FD) \
     inline_mysql_socket_close(__FILE__, __LINE__, FD)
@@ -269,6 +258,17 @@ inline_mysql_end_socket_wait(struct PSI_
     inline_mysql_socket_shutdown(FD, H)
 #endif
 
+/** Not supported by P_S */
+#if 0
+  #ifdef HAVE_PSI_INTERFACE
+    #define mysql_socket_accept4(K, FD, A, LP, FL) \
+      inline_mysql_socket_accept4(K, __FILE__, __LINE__, FD, A, LP, FL)
+  #else
+    #define mysql_socket_accept4(FD, A, LP, FL) \
+      inline_mysql_socket_accept4(FD, A, LP, FL)
+  #endif
+#endif
+
 /** Not supported by Winsock */
 #ifdef __WIN__
 
@@ -332,7 +332,6 @@ struct st_mysql_socket
     Note that this hook is not conditionally defined,
     for binary compatibility of the @c MYSQL_FILE interface.
   */
-
   struct PSI_socket *m_psi;
 };
 
@@ -754,45 +753,6 @@ inline_mysql_socket_accept
   return socket_accept;
 }
 
-/** mysql_socket_accept4 */
-
-#if 0
-  static inline MYSQL_SOCKET
-  inline_mysql_socket_accept4
-  (
-  #ifdef HAVE_PSI_INTERFACE
-    PSI_socket_key key, const char *src_file, uint src_line,
-  #endif
-   MYSQL_SOCKET socket_listen,  addr, socklen_t *addr_len, int flags)
-  {
-    MYSQL_SOCKET socket_accept = {0, NULL};
-  #ifdef HAVE_PSI_INTERFACE
-    struct PSI_socket_locker *locker= NULL;
-    PSI_socket_locker_state state;
-
-    socket_accept.m_psi = PSI_server ? PSI_server->init_socket(key, NULL)// &socket_accept.fd) // TBD: check this
-                                     : NULL;
-    if (likely(PSI_server != NULL && socket_accept.m_psi != NULL))
-    {
-      locker= PSI_server->get_thread_socket_locker(socket_accept.m_psi, PSI_SOCKET_CONNECT);
-      if (likely(locker !=NULL))
-        PSI_server->start_socket_wait(locker, (size_t)0, src_file, src_line);
-    }
-  #endif
-    socket_accept.fd= accept4(socket_listen.fd, addr, addr_len, flags);
-  #ifdef HAVE_PSI_INTERFACE
-    /** Set socket address info */
-    if (likely(PSI_server != NULL && socket_accept.m_psi != NULL
-        && socket_accept.fd != -1))
-      PSI_server->set_socket_info(socket_accept.m_psi, socket_accept.fd, addr);
-
-    if (likely(locker != NULL))
-      PSI_server->end_socket_wait(locker, (size_t)0);
-  #endif
-    return socket_accept;
-  }
-#endif
-
 /** mysql_socket_close */
 
 static inline int
@@ -818,7 +778,11 @@ inline_mysql_socket_close
   result= closesocket(mysql_socket.fd);
 #ifdef HAVE_PSI_INTERFACE
   if (likely(locker != NULL))
+  {
     PSI_server->end_socket_wait(locker, (size_t)0);
+    /* This socket will no longer be used by the server */
+    PSI_server->destroy_socket(mysql_socket.m_psi);
+  }
 #endif
   return result;
 }
@@ -853,6 +817,50 @@ inline_mysql_socket_shutdown
   return result;
 }
 
+/** Not supported by P_S */
+
+#if 0
+
+/** mysql_socket_accept4 */
+
+  static inline MYSQL_SOCKET
+  inline_mysql_socket_accept4
+  (
+  #ifdef HAVE_PSI_INTERFACE
+    PSI_socket_key key, const char *src_file, uint src_line,
+  #endif
+   MYSQL_SOCKET socket_listen,  addr, socklen_t *addr_len, int flags)
+  {
+    MYSQL_SOCKET socket_accept = {0, NULL};
+  #ifdef HAVE_PSI_INTERFACE
+    struct PSI_socket_locker *locker= NULL;
+    PSI_socket_locker_state state;
+
+    socket_accept.m_psi = PSI_server ? PSI_server->init_socket(key, NULL)// &socket_accept.fd) // TBD: check this
+                                     : NULL;
+    if (likely(PSI_server != NULL && socket_accept.m_psi != NULL))
+    {
+      locker= PSI_server->get_thread_socket_locker(socket_accept.m_psi, PSI_SOCKET_CONNECT);
+      if (likely(locker !=NULL))
+        PSI_server->start_socket_wait(locker, (size_t)0, src_file, src_line);
+    }
+  #endif
+    socket_accept.fd= accept4(socket_listen.fd, addr, addr_len, flags);
+  #ifdef HAVE_PSI_INTERFACE
+    /** Set socket address info */
+    if (likely(PSI_server != NULL && socket_accept.m_psi != NULL
+        && socket_accept.fd != -1))
+      PSI_server->set_socket_info(socket_accept.m_psi, socket_accept.fd, addr);
+
+    if (likely(locker != NULL))
+      PSI_server->end_socket_wait(locker, (size_t)0);
+  #endif
+    return socket_accept;
+  }
+
+#endif // unsupported
+
+
 /** Not supported by Winsock */
 
 #ifndef __WIN__

=== modified file 'sql/sys_vars.cc'
--- a/sql/sys_vars.cc	2011-01-14 19:33:04 +0000
+++ b/sql/sys_vars.cc	2011-02-16 22:53:35 +0000
@@ -135,7 +135,7 @@ static Sys_var_ulong Sys_pfs_max_file_in
        BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
 
 static Sys_var_ulong Sys_pfs_max_sockets(
-       "performance_schema_max_sockets",
+       "performance_schema_max_socket_instances",
        "Maximum number of opened instrumented sockets.",
        READ_ONLY GLOBAL_VAR(pfs_param.m_socket_sizing),
        CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 1024*1024),

=== modified file 'storage/perfschema/ha_perfschema.cc'
--- a/storage/perfschema/ha_perfschema.cc	2010-12-08 03:24:30 +0000
+++ b/storage/perfschema/ha_perfschema.cc	2011-02-16 22:53:35 +0000
@@ -126,6 +126,8 @@ static struct st_mysql_show_var pfs_stat
     (char*) &thread_class_lost, SHOW_LONG_NOFLUSH},
   {"Performance_schema_file_classes_lost",
     (char*) &file_class_lost, SHOW_LONG_NOFLUSH},
+  {"Performance_schema_socket_classes_lost",
+    (char*) &socket_class_lost, SHOW_LONG_NOFLUSH},
   {"Performance_schema_mutex_instances_lost",
     (char*) &mutex_lost, SHOW_LONG},
   {"Performance_schema_rwlock_instances_lost",

=== modified file 'storage/perfschema/pfs.cc'
--- a/storage/perfschema/pfs.cc	2011-02-14 23:26:08 +0000
+++ b/storage/perfschema/pfs.cc	2011-02-16 22:53:35 +0000
@@ -2794,7 +2794,7 @@ static void end_mutex_wait_v1(PSI_mutex_
     timer_end= state->m_timer();
     wait_time= timer_end - state->m_timer_start;
     /* Aggregate to EVENTS_WAITS_SUMMARY_BY_INSTANCE (timed) */
-    mutex->m_wait_stat.aggregate_timed(wait_time);
+    mutex->m_wait_stat.aggregate_value(wait_time);
   }
   else
   {
@@ -2817,7 +2817,7 @@ static void end_mutex_wait_v1(PSI_mutex_
     if (flags & STATE_FLAG_TIMED)
     {
       /* Aggregate to EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME (timed) */
-      event_name_array[index].aggregate_timed(wait_time);
+      event_name_array[index].aggregate_value(wait_time);
     }
     else
     {
@@ -2886,7 +2886,7 @@ static void end_rwlock_rdwait_v1(PSI_rwl
     timer_end= state->m_timer();
     wait_time= timer_end - state->m_timer_start;
     /* Aggregate to EVENTS_WAITS_SUMMARY_BY_INSTANCE (timed) */
-    rwlock->m_wait_stat.aggregate_timed(wait_time);
+    rwlock->m_wait_stat.aggregate_value(wait_time);
   }
   else
   {
@@ -2921,7 +2921,7 @@ static void end_rwlock_rdwait_v1(PSI_rwl
     if (state->m_flags & STATE_FLAG_TIMED)
     {
       /* Aggregate to EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME (timed) */
-      event_name_array[index].aggregate_timed(wait_time);
+      event_name_array[index].aggregate_value(wait_time);
     }
     else
     {
@@ -2991,7 +2991,7 @@ static void end_rwlock_wrwait_v1(PSI_rwl
     timer_end= state->m_timer();
     wait_time= timer_end - state->m_timer_start;
     /* Aggregate to EVENTS_WAITS_SUMMARY_BY_INSTANCE (timed) */
-    rwlock->m_wait_stat.aggregate_timed(wait_time);
+    rwlock->m_wait_stat.aggregate_value(wait_time);
   }
   else
   {
@@ -3018,7 +3018,7 @@ static void end_rwlock_wrwait_v1(PSI_rwl
     if (state->m_flags & STATE_FLAG_TIMED)
     {
       /* Aggregate to EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME (timed) */
-      event_name_array[index].aggregate_timed(wait_time);
+      event_name_array[index].aggregate_value(wait_time);
     }
     else
     {
@@ -3088,7 +3088,7 @@ static void end_cond_wait_v1(PSI_cond_lo
     timer_end= state->m_timer();
     wait_time= timer_end - state->m_timer_start;
     /* Aggregate to EVENTS_WAITS_SUMMARY_BY_INSTANCE (timed) */
-    cond->m_wait_stat.aggregate_timed(wait_time);
+    cond->m_wait_stat.aggregate_value(wait_time);
   }
   else
   {
@@ -3108,7 +3108,7 @@ static void end_cond_wait_v1(PSI_cond_lo
     if (state->m_flags & STATE_FLAG_TIMED)
     {
       /* Aggregate to EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME (timed) */
-      event_name_array[index].aggregate_timed(wait_time);
+      event_name_array[index].aggregate_value(wait_time);
     }
     else
     {
@@ -3206,7 +3206,7 @@ static void end_table_io_wait_v1(PSI_tab
   {
     timer_end= state->m_timer();
     wait_time= timer_end - state->m_timer_start;
-    stat->aggregate_timed(wait_time);
+    stat->aggregate_value(wait_time);
   }
   else
   {
@@ -3283,7 +3283,7 @@ static void end_table_lock_wait_v1(PSI_t
   {
     timer_end= state->m_timer();
     wait_time= timer_end - state->m_timer_start;
-    stat->aggregate_timed(wait_time);
+    stat->aggregate_value(wait_time);
   }
   else
   {
@@ -3426,7 +3426,7 @@ static void end_file_wait_v1(PSI_file_lo
     timer_end= state->m_timer();
     wait_time= timer_end - state->m_timer_start;
     /* Aggregate to EVENTS_WAITS_SUMMARY_BY_INSTANCE (timed) */
-    file->m_wait_stat.aggregate_timed(wait_time);
+    file->m_wait_stat.aggregate_value(wait_time);
   }
   else
   {
@@ -3445,7 +3445,7 @@ static void end_file_wait_v1(PSI_file_lo
     if (flags & STATE_FLAG_TIMED)
     {
       /* Aggregate to EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME (timed) */
-      event_name_array[index].aggregate_timed(wait_time);
+      event_name_array[index].aggregate_value(wait_time);
     }
     else
     {
@@ -3545,9 +3545,9 @@ static void end_socket_wait_v1(PSI_socke
 
   PFS_socket *socket= reinterpret_cast<PFS_socket *> (state->m_socket);
   DBUG_ASSERT(socket != NULL);
+  PFS_thread *thread= reinterpret_cast<PFS_thread *> (state->m_thread);
 
-  PFS_single_stat *time_stat;
-  PFS_single_stat *io_stat;
+  PFS_single_stat *time_stat, *io_stat;
 
   switch (state->m_operation)
   {
@@ -3604,33 +3604,57 @@ static void end_socket_wait_v1(PSI_socke
   {
     timer_end= state->m_timer();
     wait_time= timer_end - state->m_timer_start;
-    time_stat->aggregate_timed(wait_time);
+    /* Aggregate to EVENTS_WAITS_SUMMARY_BY_INSTANCE (timed) */
+    socket->m_wait_stat.aggregate_value(wait_time);
+    /* Aggregate to current operation (timed) */
+    time_stat->aggregate_value(wait_time);
   }
   else
   {
+    /* Aggregate to EVENTS_WAITS_SUMMARY_BY_INSTANCE (counted) */
+    socket->m_wait_stat.aggregate_counted();
+    /* Aggregate to current operation (counted) */
     time_stat->aggregate_counted();
   }
 
-  if (flags & STATE_FLAG_WAIT)
+  if (flags & STATE_FLAG_THREAD)
   {
-    DBUG_ASSERT(flags & STATE_FLAG_THREAD);
-    PFS_thread *thread= reinterpret_cast<PFS_thread *> (state->m_thread);
-    DBUG_ASSERT(thread != NULL);
+    PFS_single_stat *event_name_array;
+    event_name_array= thread->m_instr_class_wait_stats;
+    uint index= socket->m_class->m_event_name_index;
 
-    PFS_events_waits *wait= reinterpret_cast<PFS_events_waits*> (state->m_wait);
-    DBUG_ASSERT(wait != NULL);
+    if (flags & STATE_FLAG_TIMED)
+    {
+      /* Aggregate to EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME (timed) */
+      event_name_array[index].aggregate_value(wait_time);
+    }
+    else
+    {
+      /* Aggregate to EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME (counted) */
+      event_name_array[index].aggregate_counted();
+    }
 
-    wait->m_timer_end= timer_end;
-    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 (flags & STATE_FLAG_WAIT)
+    {
+      DBUG_ASSERT(flags & STATE_FLAG_THREAD);
+      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);
+
+      wait->m_timer_end= timer_end;
+      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--;
+    }
   }
 
-  /** Aggregate the number of bytes for the operation */
+  /** Aggregate number of bytes for the operation */
   if ((int)byte_count > -1)
-    io_stat->aggregate_timed(byte_count);
+    io_stat->aggregate_value(byte_count);
 }
 
 static void set_socket_descriptor_v1(PSI_socket *socket, uint fd)

=== modified file 'storage/perfschema/pfs_instr_class.h'
--- a/storage/perfschema/pfs_instr_class.h	2011-02-07 21:34:45 +0000
+++ b/storage/perfschema/pfs_instr_class.h	2011-02-16 22:53:35 +0000
@@ -373,6 +373,7 @@ 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	2011-02-07 21:34:45 +0000
+++ b/storage/perfschema/pfs_stat.h	2011-02-16 22:53:35 +0000
@@ -71,7 +71,7 @@ struct PFS_single_stat
     m_count++;
   }
 
-  inline void aggregate_timed(ulonglong value)
+  inline void aggregate_value(ulonglong value)
   {
     m_count++;
     m_sum+= value;
@@ -82,7 +82,7 @@ struct PFS_single_stat
   }
 };
 
-/** Single statistic. */
+/** Combined statistic. */
 struct PFS_multi_stat
 {
   /** Timer statistics */

=== modified file 'vio/vio.c'
--- a/vio/vio.c	2010-12-07 18:55:54 +0000
+++ b/vio/vio.c	2011-02-16 22:53:35 +0000
@@ -166,8 +166,8 @@ static void vio_init(Vio* vio, enum enum
   vio->has_data=        (flags & VIO_BUFFERED_READ) ?
                             vio_buff_has_data : has_no_data;
 #ifdef HAVE_PSI_INTERFACE
-  vio->mysql_socket.fd= sd; // TBDs
-  vio->mysql_socket.m_psi= NULL;
+  mysql_socket_getfd(vio->mysql_socket)= sd;
+  vio->mysql_socket.m_psi= NULL; // TBD
 #endif
   DBUG_VOID_RETURN;
 }

=== modified file 'vio/viosocket.c'
--- a/vio/viosocket.c	2010-12-07 18:55:54 +0000
+++ b/vio/viosocket.c	2011-02-16 22:53:35 +0000
@@ -215,7 +215,9 @@ vio_is_blocking(Vio * vio)
 int vio_fastsend(Vio* vio __attribute__((unused)))
 {
   int r=0;
+  MYSQL_SOCKET_WAIT_VARIABLES(locker, state) /* no ';' */
   DBUG_ENTER("vio_fastsend");
+  MYSQL_START_SOCKET_WAIT(locker, &state, vio->mysql_socket.m_psi, PSI_SOCKET_OPT, 0);
 
 #if defined(IPTOS_THROUGHPUT)
   {
@@ -234,8 +236,10 @@ int vio_fastsend(Vio* vio __attribute__(
     r= setsockopt(vio->sd, IPPROTO_TCP, TCP_NODELAY,
                   IF_WIN((const char*), (void*)) &nodelay,
                   sizeof(nodelay));
-
   }
+
+  MYSQL_END_SOCKET_WAIT(locker, 0);
+
   if (r)
   {
     DBUG_PRINT("warning", ("Couldn't set socket option for fast send"));
@@ -249,9 +253,12 @@ int vio_keepalive(Vio* vio, my_bool set_
 {
   int r=0;
   uint opt = 0;
+  MYSQL_SOCKET_WAIT_VARIABLES(locker, state) /* no ';' */
   DBUG_ENTER("vio_keepalive");
   DBUG_PRINT("enter", ("sd: %d  set_keep_alive: %d", vio->sd, (int)
 		       set_keep_alive));
+  MYSQL_START_SOCKET_WAIT(locker, &state, vio->mysql_socket.m_psi, PSI_SOCKET_OPT, 0);
+
   if (vio->type != VIO_TYPE_NAMEDPIPE)
   {
     if (set_keep_alive)
@@ -259,6 +266,8 @@ int vio_keepalive(Vio* vio, my_bool set_
     r = setsockopt(vio->sd, SOL_SOCKET, SO_KEEPALIVE, (char *) &opt,
 		   sizeof(opt));
   }
+
+  MYSQL_END_SOCKET_WAIT(locker, 0);
   DBUG_RETURN(r);
 }
 
@@ -300,11 +309,11 @@ int vio_close(Vio * vio)
     DBUG_ASSERT(vio->type ==  VIO_TYPE_TCPIP ||
       vio->type == VIO_TYPE_SOCKET ||
       vio->type == VIO_TYPE_SSL);
-
     DBUG_ASSERT(vio->sd >= 0);
-    if (shutdown(vio->sd, SHUT_RDWR))
+
+    if (mysql_socket_shutdown(vio->mysql_socket, SHUT_RDWR))
       r= -1;
-    if (closesocket(vio->sd))
+    if (mysql_socket_close(vio->mysql_socket))
       r= -1;
   }
   if (r)
@@ -314,6 +323,7 @@ int vio_close(Vio * vio)
   }
   vio->type= VIO_CLOSED;
   vio->sd=   -1;
+  mysql_socket_getfd(vio->mysql_socket)= vio->sd;
   DBUG_RETURN(r);
 }
 


Attachment: [text/bzr-bundle] bzr/cpowers@tma-1-20110216225335-t5qts3qnz02rw60a.bundle
Thread
bzr push into mysql-trunk-wl5379 branch (chris.powers:3230 to 3231) WL#4896Christopher Powers16 Feb