summaryrefslogtreecommitdiff
path: root/storage/perfschema/pfs.cc
diff options
context:
space:
mode:
Diffstat (limited to 'storage/perfschema/pfs.cc')
-rw-r--r--storage/perfschema/pfs.cc102
1 files changed, 91 insertions, 11 deletions
diff --git a/storage/perfschema/pfs.cc b/storage/perfschema/pfs.cc
index 3d3ce83b01b..584d6b017a8 100644
--- a/storage/perfschema/pfs.cc
+++ b/storage/perfschema/pfs.cc
@@ -1,13 +1,20 @@
-/* Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; version 2 of the License.
+ it under the terms of the GNU General Public License, version 2.0,
+ as published by the Free Software Foundation.
+
+ This program is also distributed with certain software (including
+ but not limited to OpenSSL) that is licensed under separate terms,
+ as designated in a particular file or component or in included license
+ documentation. The authors of MySQL hereby grant you an additional
+ permission to link the program and your derivative works with the
+ separately licensed software that they have included with MySQL.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
+ GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
@@ -58,6 +65,8 @@
#include "pfs_program.h"
#include "pfs_prepared_stmt.h"
+using std::min;
+
/*
This is a development tool to investigate memory statistics,
do not use in production.
@@ -2379,8 +2388,8 @@ void pfs_set_thread_account_v1(const char *user, int user_len,
DBUG_ASSERT((uint) user_len <= sizeof(pfs->m_username));
DBUG_ASSERT((host != NULL) || (host_len == 0));
DBUG_ASSERT(host_len >= 0);
- DBUG_ASSERT((uint) host_len <= sizeof(pfs->m_hostname));
+ host_len= min<size_t>(host_len, sizeof(pfs->m_hostname));
if (unlikely(pfs == NULL))
return;
@@ -2998,9 +3007,7 @@ pfs_start_table_io_wait_v1(PSI_table_locker_state *state,
if (! pfs_table->m_io_enabled)
return NULL;
- PFS_thread *pfs_thread= pfs_table->m_thread_owner;
-
- DBUG_ASSERT(pfs_thread == my_thread_get_THR_PFS());
+ PFS_thread *pfs_thread= my_thread_get_THR_PFS();
uint flags;
ulonglong timer_start= 0;
@@ -3103,7 +3110,7 @@ pfs_start_table_lock_wait_v1(PSI_table_locker_state *state,
if (! pfs_table->m_lock_enabled)
return NULL;
- PFS_thread *pfs_thread= pfs_table->m_thread_owner;
+ PFS_thread *pfs_thread= my_thread_get_THR_PFS();
PFS_TL_LOCK_TYPE lock_type;
@@ -3516,7 +3523,12 @@ pfs_start_socket_wait_v1(PSI_socket_locker_state *state,
if (flag_thread_instrumentation)
{
- PFS_thread *pfs_thread= pfs_socket->m_thread_owner;
+ /*
+ Do not use pfs_socket->m_thread_owner here,
+ as different threads may use concurrently the same socket,
+ for example during a KILL.
+ */
+ PFS_thread *pfs_thread= my_thread_get_THR_PFS();
if (unlikely(pfs_thread == NULL))
return NULL;
@@ -3888,6 +3900,8 @@ void pfs_end_idle_wait_v1(PSI_idle_locker* locker)
if (thread->m_flag_events_waits_history_long)
insert_events_waits_history_long(wait);
thread->m_events_waits_current--;
+
+ DBUG_ASSERT(wait == thread->m_events_waits_current);
}
}
@@ -3972,6 +3986,8 @@ void pfs_end_mutex_wait_v1(PSI_mutex_locker* locker, int rc)
if (thread->m_flag_events_waits_history_long)
insert_events_waits_history_long(wait);
thread->m_events_waits_current--;
+
+ DBUG_ASSERT(wait == thread->m_events_waits_current);
}
}
}
@@ -4051,6 +4067,8 @@ void pfs_end_rwlock_rdwait_v1(PSI_rwlock_locker* locker, int rc)
if (thread->m_flag_events_waits_history_long)
insert_events_waits_history_long(wait);
thread->m_events_waits_current--;
+
+ DBUG_ASSERT(wait == thread->m_events_waits_current);
}
}
}
@@ -4128,6 +4146,8 @@ void pfs_end_rwlock_wrwait_v1(PSI_rwlock_locker* locker, int rc)
if (thread->m_flag_events_waits_history_long)
insert_events_waits_history_long(wait);
thread->m_events_waits_current--;
+
+ DBUG_ASSERT(wait == thread->m_events_waits_current);
}
}
}
@@ -4192,6 +4212,8 @@ void pfs_end_cond_wait_v1(PSI_cond_locker* locker, int rc)
if (thread->m_flag_events_waits_history_long)
insert_events_waits_history_long(wait);
thread->m_events_waits_current--;
+
+ DBUG_ASSERT(wait == thread->m_events_waits_current);
}
}
}
@@ -4287,6 +4309,8 @@ void pfs_end_table_io_wait_v1(PSI_table_locker* locker, ulonglong numrows)
if (thread->m_flag_events_waits_history_long)
insert_events_waits_history_long(wait);
thread->m_events_waits_current--;
+
+ DBUG_ASSERT(wait == thread->m_events_waits_current);
}
}
@@ -4356,6 +4380,8 @@ void pfs_end_table_lock_wait_v1(PSI_table_locker* locker)
if (thread->m_flag_events_waits_history_long)
insert_events_waits_history_long(wait);
thread->m_events_waits_current--;
+
+ DBUG_ASSERT(wait == thread->m_events_waits_current);
}
}
@@ -4397,9 +4423,11 @@ pfs_end_file_open_wait_v1(PSI_file_locker *locker,
switch (state->m_operation)
{
case PSI_FILE_STAT:
+ case PSI_FILE_RENAME:
break;
case PSI_FILE_STREAM_OPEN:
case PSI_FILE_CREATE:
+ case PSI_FILE_OPEN:
if (result != NULL)
{
PFS_file_class *klass= reinterpret_cast<PFS_file_class*> (state->m_class);
@@ -4410,7 +4438,6 @@ pfs_end_file_open_wait_v1(PSI_file_locker *locker,
state->m_file= reinterpret_cast<PSI_file*> (pfs_file);
}
break;
- case PSI_FILE_OPEN:
default:
DBUG_ASSERT(false);
break;
@@ -4628,6 +4655,8 @@ void pfs_end_file_wait_v1(PSI_file_locker *locker,
if (thread->m_flag_events_waits_history_long)
insert_events_waits_history_long(wait);
thread->m_events_waits_current--;
+
+ DBUG_ASSERT(wait == thread->m_events_waits_current);
}
}
}
@@ -4716,6 +4745,31 @@ void pfs_end_file_close_wait_v1(PSI_file_locker *locker, int rc)
return;
}
+/**
+ Implementation of the file instrumentation interface.
+ @sa PSI_v1::end_file_rename_wait.
+*/
+void pfs_end_file_rename_wait_v1(PSI_file_locker *locker, const char *old_name,
+ const char *new_name, int rc)
+{
+ PSI_file_locker_state *state= reinterpret_cast<PSI_file_locker_state*> (locker);
+ DBUG_ASSERT(state != NULL);
+ DBUG_ASSERT(state->m_operation == PSI_FILE_RENAME);
+
+ if (rc == 0)
+ {
+ PFS_thread *thread= reinterpret_cast<PFS_thread *> (state->m_thread);
+
+ uint old_len= (uint)strlen(old_name);
+ uint new_len= (uint)strlen(new_name);
+
+ find_and_rename_file(thread, old_name, old_len, new_name, new_len);
+ }
+
+ pfs_end_file_wait_v1(locker, 0);
+ return;
+}
+
PSI_stage_progress*
pfs_start_stage_v1(PSI_stage_key key, const char *src_file, int src_line)
{
@@ -6223,6 +6277,8 @@ void pfs_end_socket_wait_v1(PSI_socket_locker *locker, size_t byte_count)
if (thread->m_flag_events_waits_history_long)
insert_events_waits_history_long(wait);
thread->m_events_waits_current--;
+
+ DBUG_ASSERT(wait == thread->m_events_waits_current);
}
}
@@ -6365,6 +6421,26 @@ void pfs_reprepare_prepared_stmt_v1(PSI_prepared_stmt* prepared_stmt)
return;
}
+void pfs_set_prepared_stmt_text_v1(PSI_prepared_stmt *prepared_stmt,
+ const char *text,
+ uint text_len)
+{
+ PFS_prepared_stmt *pfs_prepared_stmt =
+ reinterpret_cast<PFS_prepared_stmt *>(prepared_stmt);
+ DBUG_ASSERT(pfs_prepared_stmt != NULL);
+
+ uint max_len = COL_INFO_SIZE;
+ if (text_len > max_len)
+ {
+ text_len = max_len;
+ }
+
+ memcpy(pfs_prepared_stmt->m_sqltext, text, text_len);
+ pfs_prepared_stmt->m_sqltext_length = text_len;
+
+ return;
+}
+
/**
Implementation of the thread attribute connection interface
@sa PSI_v1::set_thread_connect_attr.
@@ -6887,6 +6963,8 @@ pfs_end_metadata_wait_v1(PSI_metadata_locker *locker,
if (thread->m_flag_events_waits_history_long)
insert_events_waits_history_long(wait);
thread->m_events_waits_current--;
+
+ DBUG_ASSERT(wait == thread->m_events_waits_current);
}
}
else
@@ -6980,6 +7058,7 @@ PSI_v1 PFS_v1=
pfs_end_file_wait_v1,
pfs_start_file_close_wait_v1,
pfs_end_file_close_wait_v1,
+ pfs_end_file_rename_wait_v1,
pfs_start_stage_v1,
pfs_get_current_stage_progress_v1,
pfs_end_stage_v1,
@@ -7023,6 +7102,7 @@ PSI_v1 PFS_v1=
pfs_destroy_prepared_stmt_v1,
pfs_reprepare_prepared_stmt_v1,
pfs_execute_prepared_stmt_v1,
+ pfs_set_prepared_stmt_text_v1,
pfs_digest_start_v1,
pfs_digest_end_v1,
pfs_set_thread_connect_attrs_v1,