#At file:///home/cpowers/work/dev/dev-wl4896/mysql/ based on revid:chris.powers@stripped
3155 Christopher Powers 2010-07-29
WL#4896 PERFORMANCE_SCHEMA Instrumenting Net IO
Track IP and port for each socket.
Added columns SOCKET_ID, IP, PORT, BYTES_READ, BYTES_WRITE to SOCKET_INSTANCES.
Added interface methods set_socket_descriptor(), set_socket_address() and set_socket_info().
modified:
include/mysql/psi/mysql_socket.h
include/mysql/psi/psi.h
include/mysql/psi/psi_abi_v1.h.pp
scripts/mysql_system_tables.sql
storage/perfschema/pfs.cc
storage/perfschema/pfs_instr.h
storage/perfschema/table_socket_instances.cc
storage/perfschema/table_socket_instances.h
=== modified file 'include/mysql/psi/mysql_socket.h'
--- a/include/mysql/psi/mysql_socket.h 2010-07-07 19:49:15 +0000
+++ b/include/mysql/psi/mysql_socket.h 2010-07-29 19:56:17 +0000
@@ -26,8 +26,8 @@ Foundation, Inc., 51 Franklin St, Fifth
/* For my_chsize */
#include <my_sys.h>
/* For socket api */
-#include <sys/socket.h>
-
+//#include <sys/socket.h>
+#include <netinet/in.h>
/**
@file mysql/psi/mysql_socket.h
[...]
@@ -320,6 +320,10 @@ inline_mysql_socket_socket
#endif
mysql_socket.fd= socket(domain, type, protocol);
+#ifdef HAVE_PSI_INTERFACE
+ if (likely(mysql_socket.m_psi != NULL))
+ PSI_server->set_socket_descriptor(mysql_socket.m_psi, mysql_socket.fd);
+#endif
return mysql_socket;
}
@@ -375,6 +379,9 @@ inline_mysql_socket_bind
#endif
result= bind(mysql_socket.fd, addr, len);
#ifdef HAVE_PSI_INTERFACE
+ if (likely(PSI_server != NULL && mysql_socket.m_psi != NULL))
+ PSI_server->set_socket_address(mysql_socket.m_psi, addr);
+
if (likely(locker != NULL))
PSI_server->end_socket_wait(locker);
#endif
@@ -740,7 +747,12 @@ inline_mysql_socket_accept
}
#endif
socket_accept.fd= accept(socket_listen.fd, addr, addr_len);
+
#ifdef HAVE_PSI_INTERFACE
+ /** Set socket address info */
+ if (likely(PSI_server != NULL && socket_accept.m_psi != NULL))
+ PSI_server->set_socket_info(socket_accept.m_psi, socket_accept.fd, addr);
+
if (likely(locker != NULL))
PSI_server->end_socket_wait(locker);
#endif
=== modified file 'include/mysql/psi/psi.h'
--- a/include/mysql/psi/psi.h 2010-06-22 23:02:37 +0000
+++ b/include/mysql/psi/psi.h 2010-07-29 19:56:17 +0000
@@ -967,6 +967,33 @@ typedef void (*start_socket_wait_v1_t)
*/
typedef void (*end_socket_wait_v1_t)
(struct PSI_socket_locker *locker);
+
+/**
+ Set the socket descriptor for an instrumented socket.
+ @param socket the instrumented socket
+ @param fd socket descriptor
+ */
+typedef void (*set_socket_descriptor_v1_t)(struct PSI_socket *socket,
+ uint fd);
+
+/**
+ Set the socket address for an instrumented socket.
+ @param socket the instrumented socket
+ @param addr socket address information
+ */
+typedef void (*set_socket_address_v1_t)(struct PSI_socket *socket,
+ const struct sockaddr * addr);
+
+/**
+ Set the socket info for an instrumented socket.
+ @param socket the instrumented socket
+ @param fd the socket descriptor
+ @param addr the socket ip address
+*/
+typedef void (*set_socket_info_v1_t)(struct PSI_socket *socket,
+ uint fd,
+ const struct sockaddr * addr);
+
/**
Performance Schema Interface, version 1.
@since PSI_VERSION_1
@@ -1084,6 +1111,12 @@ struct PSI_v1
start_socket_wait_v1_t start_socket_wait;
/** @sa end_file_wait_v1_t. */
end_socket_wait_v1_t end_socket_wait;
+ /** @sa set_socket_descriptor_v1_t. */
+ set_socket_descriptor_v1_t set_socket_descriptor;
+ /** @sa set_socket_address_v1_t. */
+ set_socket_address_v1_t set_socket_address;
+ /** @sa set_socket_info_v1_t. */
+ set_socket_info_v1_t set_socket_info;
};
/** @} (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 2010-06-22 23:02:37 +0000
+++ b/include/mysql/psi/psi_abi_v1.h.pp 2010-07-29 19:56:17 +0000
@@ -214,6 +214,13 @@ typedef void (*start_socket_wait_v1_t)
const char *src_file, uint src_line);
typedef void (*end_socket_wait_v1_t)
(struct PSI_socket_locker *locker);
+typedef void (*set_socket_descriptor_v1_t)(struct PSI_socket *socket,
+ uint fd);
+typedef void (*set_socket_address_v1_t)(struct PSI_socket *socket,
+ const struct sockaddr * addr);
+typedef void (*set_socket_info_v1_t)(struct PSI_socket *socket,
+ uint fd,
+ const struct sockaddr * addr);
struct PSI_v1
{
register_mutex_v1_t register_mutex;
@@ -272,6 +279,9 @@ struct PSI_v1
end_file_wait_v1_t end_file_wait;
start_socket_wait_v1_t start_socket_wait;
end_socket_wait_v1_t end_socket_wait;
+ set_socket_descriptor_v1_t set_socket_descriptor;
+ set_socket_address_v1_t set_socket_address;
+ set_socket_info_v1_t set_socket_info;
};
typedef struct PSI_v1 PSI;
typedef struct PSI_mutex_info_v1 PSI_mutex_info;
=== modified file 'scripts/mysql_system_tables.sql'
--- a/scripts/mysql_system_tables.sql 2010-07-09 02:23:31 +0000
+++ b/scripts/mysql_system_tables.sql 2010-07-29 19:56:17 +0000
@@ -364,12 +364,15 @@ DROP PREPARE stmt;
--
SET @l1="CREATE TABLE performance_schema.SOCKET_INSTANCES(";
-SET @l2="EVENT_NAME VARCHAR(128) not null,";
-SET @l3="OBJECT_INSTANCE_BEGIN BIGINT not null,";
-SET @l4="SOCKET_DESC VARCHAR(512) not null";
-SET @l5=")ENGINE=PERFORMANCE_SCHEMA;";
-
-SET @cmd=concat(@l1,@l2,@l3,@l4,@l5);
+SET @l2="EVENT_NAME varchar(128) not null,";
+SET @l3="OBJECT_INSTANCE_BEGIN bigint(20) not null,";
+SET @l4="SOCKET_ID int(11) not null,";
+SET @l5="IP varchar(128) not null,";
+SET @l6="PORT int(11) not null,";
+SET @l7="BYTES_READ bigint(20) not null,";
+SET @l8="BYTES_WRITE bigint(20) not null";
+SET @l9=")ENGINE=PERFORMANCE_SCHEMA;";
+SET @cmd=concat(@l1,@l2,@l3,@l4,@l5,@l6,@l7,@l8,@l9);
SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0');
PREPARE stmt FROM @str;
=== modified file 'storage/perfschema/pfs.cc'
--- a/storage/perfschema/pfs.cc 2010-07-09 02:23:31 +0000
+++ b/storage/perfschema/pfs.cc 2010-07-29 19:56:17 +0000
@@ -18,6 +18,7 @@
The performance schema implementation of all instruments.
*/
+#include <arpa/inet.h>
#include "my_global.h"
#include "pfs.h"
#include "pfs_instr_class.h"
@@ -1566,8 +1567,8 @@ get_thread_socket_locker_v1(PSI_socket *
pfs_locker->m_waits_current.m_timer_state= TIMER_STATE_UNTIMED;
pfs_locker->m_waits_current.m_object_instance_addr= pfs_socket;
- pfs_locker->m_waits_current.m_object_name= pfs_socket->m_socket_desc;
- pfs_locker->m_waits_current.m_object_name_length= pfs_socket->m_socket_desc_length;
+ pfs_locker->m_waits_current.m_object_name= pfs_socket->m_ip;
+ pfs_locker->m_waits_current.m_object_name_length= pfs_socket->m_ip_length;
pfs_locker->m_waits_current.m_event_id= pfs_thread->m_event_id++;
pfs_locker->m_waits_current.m_operation= socket_operation_map[static_cast<int>(op)];
pfs_locker->m_waits_current.m_wait_class= WAIT_CLASS_SOCKET;
@@ -2199,6 +2200,56 @@ static void end_socket_wait_v1(PSI_socke
wait->m_thread->m_wait_locker_count--;
}
+static void set_socket_descriptor_v1(PSI_socket *socket,
+ uint fd)
+{
+ DBUG_ASSERT(socket);
+ PFS_socket *pfs= reinterpret_cast<PFS_socket*>(socket);
+ pfs->m_fd= fd;
+}
+
+static void set_socket_address_v1(PSI_socket *socket,
+ const struct sockaddr * socket_addr)
+{
+ DBUG_ASSERT(socket);
+ PFS_socket *pfs= reinterpret_cast<PFS_socket*>(socket);
+
+ switch (socket_addr->sa_family)
+ {
+ case AF_INET:
+ {
+ struct sockaddr_in * sa4= (struct sockaddr_in *)(socket_addr);
+ pfs->m_ip_length= INET_ADDRSTRLEN;
+ inet_ntop(AF_INET, &(sa4->sin_addr), pfs->m_ip, pfs->m_ip_length);
+ pfs->m_port= ntohs(sa4->sin_port);
+ }
+ break;
+
+ case AF_INET6:
+ {
+ struct sockaddr_in6 * sa6= (struct sockaddr_in6 *)(socket_addr);
+ pfs->m_ip_length= INET6_ADDRSTRLEN;
+ inet_ntop(AF_INET6, &(sa6->sin6_addr), pfs->m_ip, pfs->m_ip_length);
+ pfs->m_port= ntohs(sa6->sin6_port);
+ }
+ break;
+
+ default:
+ break;
+ }
+}
+
+static void set_socket_info_v1(PSI_socket *socket,
+ uint fd,
+ const struct sockaddr * addr)
+{
+ DBUG_ASSERT(socket);
+ PFS_socket *pfs= reinterpret_cast<PFS_socket*>(socket);
+
+ pfs->m_fd= fd;
+ set_socket_address_v1(socket, addr);
+}
+
PSI_v1 PFS_v1=
{
@@ -2256,7 +2307,10 @@ PSI_v1 PFS_v1=
start_file_wait_v1,
end_file_wait_v1,
start_socket_wait_v1,
- end_socket_wait_v1
+ end_socket_wait_v1,
+ set_socket_descriptor_v1,
+ set_socket_address_v1,
+ set_socket_info_v1
};
static void* get_interface(int version)
=== modified file 'storage/perfschema/pfs_instr.h'
--- a/storage/perfschema/pfs_instr.h 2010-07-09 02:23:31 +0000
+++ b/storage/perfschema/pfs_instr.h 2010-07-29 19:56:17 +0000
@@ -20,7 +20,7 @@
@file storage/perfschema/pfs_instr.h
Performance schema instruments (declarations).
*/
-
+#include <netinet/in.h>
#include "pfs_lock.h"
#include "pfs_instr_class.h"
#include "pfs_events_waits.h"
@@ -129,15 +129,19 @@ struct PFS_table : public PFS_instr
const void *m_identity;
};
-/** Instrumented Socket and FILE implementation. @see PSI_socket. */
+/** Instrumented socket implementation. @see PSI_socket. */
struct PFS_socket : public PFS_instr
{
/** Socket identity, typically int */
const void *m_identity;
- /** Socket description. */
- char m_socket_desc[14]; // TBD
- /** Socket description length in bytes */
- uint m_socket_desc_length;
+ /** Socket file descriptor */
+ uint m_fd;
+ /** Socket ip address, IPV4 or IPV6 */
+ char m_ip[INET6_ADDRSTRLEN];
+ /** Socket ip address length in bytes */
+ uint m_ip_length;
+ /** Socket ip port */
+ uint m_port;
/** Socket class. */
PFS_socket_class *m_class;
/** Socket usage statistics. */
=== modified file 'storage/perfschema/table_socket_instances.cc'
--- a/storage/perfschema/table_socket_instances.cc 2010-07-09 02:23:31 +0000
+++ b/storage/perfschema/table_socket_instances.cc 2010-07-29 19:56:17 +0000
@@ -41,15 +41,36 @@ static const TABLE_FIELD_TYPE field_type
{ NULL, 0}
},
{
- { C_STRING_WITH_LEN("SOCKET_DESC") },
- { C_STRING_WITH_LEN("varchar(512)") },
+ { C_STRING_WITH_LEN("SOCKET_ID") },
+ { C_STRING_WITH_LEN("int(11)") },
+ { NULL, 0}
+ },
+ {
+ { C_STRING_WITH_LEN("IP") },
+ { C_STRING_WITH_LEN("varchar(128)") },
+ { NULL, 0}
+ },
+ {
+ { C_STRING_WITH_LEN("PORT") },
+ { C_STRING_WITH_LEN("int(11)") },
+ { NULL, 0}
+ },
+ {
+ { C_STRING_WITH_LEN("BYTES_READ") },
+ { C_STRING_WITH_LEN("bigint(20)") },
+ { NULL, 0}
+ },
+ {
+ { C_STRING_WITH_LEN("BYTES_WRITE") },
+ { C_STRING_WITH_LEN("bigint(20)") },
{ NULL, 0}
}
};
+
TABLE_FIELD_DEF
table_socket_instances::m_field_def=
-{ 3, field_types };
+{ 7, field_types };
PFS_engine_table_share
table_socket_instances::m_share=
@@ -134,8 +155,12 @@ 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_socket_desc= pfs->m_socket_desc;
- m_row.m_socket_desc_length= pfs->m_socket_desc_length;
+ m_row.m_fd= pfs->m_fd;
+ m_row.m_ip= pfs->m_ip;
+ m_row.m_ip_length= pfs->m_ip_length;
+ m_row.m_port= pfs->m_port;
+ m_row.m_bytes_read= pfs->m_socket_stat.m_recv_bytes;
+ m_row.m_bytes_write= pfs->m_socket_stat.m_send_bytes;
if (pfs->m_lock.end_optimistic_lock(&lock))
m_row_exists= true;
@@ -166,8 +191,20 @@ int table_socket_instances::read_row_val
case 1: /* OBJECT_INSTANCE_BEGIN */
set_field_ulonglong(f, (intptr)m_row.m_identity);
break;
- case 2: /* SOCKET_DESC */
- set_field_varchar_utf8(f, m_row.m_socket_desc, m_row.m_socket_desc_length);
+ case 2: /* SOCKET_ID */
+ set_field_ulong(f, m_row.m_fd);
+ break;
+ case 3: /* IP */
+ set_field_varchar_utf8(f, m_row.m_ip, m_row.m_ip_length);
+ break;
+ case 4: /* PORT */
+ set_field_ulong(f, m_row.m_port);
+ break;
+ case 5: /* BYTES_READ */
+ set_field_ulonglong(f, m_row.m_bytes_read);
+ break;
+ case 6: /* BYTES_WRITE */
+ set_field_ulonglong(f, m_row.m_bytes_write);
break;
default:
DBUG_ASSERT(false);
=== modified file 'storage/perfschema/table_socket_instances.h'
--- a/storage/perfschema/table_socket_instances.h 2010-07-09 02:23:31 +0000
+++ b/storage/perfschema/table_socket_instances.h 2010-07-29 19:56:17 +0000
@@ -38,10 +38,18 @@ struct row_socket_instances
uint m_event_name_length;
/** Column OBJECT_INSTANCE_BEGIN */
const void *m_identity;
- /** Column SOCKET_DESC. */
- const char *m_socket_desc;
- /** Length in bytes of @c m_socket_desc. */
- uint m_socket_desc_length;
+ /** Column SOCKET_ID */
+ uint m_fd;
+ /** Column IP. */
+ const char *m_ip;
+ /** Length in bytes of @c m_ip. */
+ uint m_ip_length;
+ /** Column PORT */
+ uint m_port;
+ /** Column BYTES_READ */
+ ulonglong m_bytes_read; // TBD
+ /** Column BYTES_WRITE */
+ ulonglong m_bytes_write;
};
/** Table PERFORMANCE_SCHEMA.SOCKET_INSTANCES. */
Attachment: [text/bzr-bundle] bzr/chris.powers@oracle.com-20100729195617-043jpyctutwrrss6.bundle
| Thread |
|---|
| • bzr commit into mysql-next-mr-wl4896 branch (chris.powers:3155) WL#4896 | Christopher Powers | 29 Jul |