20 #include "my_global.h"
24 #include "my_pthread.h"
40 #include "sql_error.h"
1122 OPERATION_TYPE_LOCK,
1123 OPERATION_TYPE_TRYLOCK
1132 OPERATION_TYPE_READLOCK,
1133 OPERATION_TYPE_WRITELOCK,
1134 OPERATION_TYPE_TRYREADLOCK,
1135 OPERATION_TYPE_TRYWRITELOCK
1144 OPERATION_TYPE_WAIT,
1145 OPERATION_TYPE_TIMEDWAIT
1154 OPERATION_TYPE_FILECREATE,
1155 OPERATION_TYPE_FILECREATETMP,
1156 OPERATION_TYPE_FILEOPEN,
1157 OPERATION_TYPE_FILESTREAMOPEN,
1158 OPERATION_TYPE_FILECLOSE,
1159 OPERATION_TYPE_FILESTREAMCLOSE,
1160 OPERATION_TYPE_FILEREAD,
1161 OPERATION_TYPE_FILEWRITE,
1162 OPERATION_TYPE_FILESEEK,
1163 OPERATION_TYPE_FILETELL,
1164 OPERATION_TYPE_FILEFLUSH,
1165 OPERATION_TYPE_FILESTAT,
1166 OPERATION_TYPE_FILEFSTAT,
1167 OPERATION_TYPE_FILECHSIZE,
1168 OPERATION_TYPE_FILEDELETE,
1169 OPERATION_TYPE_FILERENAME,
1170 OPERATION_TYPE_FILESYNC
1179 OPERATION_TYPE_TABLE_FETCH,
1180 OPERATION_TYPE_TABLE_WRITE_ROW,
1181 OPERATION_TYPE_TABLE_UPDATE_ROW,
1182 OPERATION_TYPE_TABLE_DELETE_ROW
1191 OPERATION_TYPE_TL_READ_NORMAL,
1192 OPERATION_TYPE_TL_READ_WITH_SHARED_LOCKS,
1193 OPERATION_TYPE_TL_READ_HIGH_PRIORITY,
1194 OPERATION_TYPE_TL_READ_NO_INSERTS,
1195 OPERATION_TYPE_TL_WRITE_ALLOW_WRITE,
1196 OPERATION_TYPE_TL_WRITE_CONCURRENT_INSERT,
1197 OPERATION_TYPE_TL_WRITE_DELAYED,
1198 OPERATION_TYPE_TL_WRITE_LOW_PRIORITY,
1199 OPERATION_TYPE_TL_WRITE_NORMAL,
1200 OPERATION_TYPE_TL_READ_EXTERNAL,
1201 OPERATION_TYPE_TL_WRITE_EXTERNAL
1210 OPERATION_TYPE_SOCKETCREATE,
1211 OPERATION_TYPE_SOCKETCONNECT,
1212 OPERATION_TYPE_SOCKETBIND,
1213 OPERATION_TYPE_SOCKETCLOSE,
1214 OPERATION_TYPE_SOCKETSEND,
1215 OPERATION_TYPE_SOCKETRECV,
1216 OPERATION_TYPE_SOCKETSENDTO,
1217 OPERATION_TYPE_SOCKETRECVFROM,
1218 OPERATION_TYPE_SOCKETSENDMSG,
1219 OPERATION_TYPE_SOCKETRECVMSG,
1220 OPERATION_TYPE_SOCKETSEEK,
1221 OPERATION_TYPE_SOCKETOPT,
1222 OPERATION_TYPE_SOCKETSTAT,
1223 OPERATION_TYPE_SOCKETSHUTDOWN,
1224 OPERATION_TYPE_SOCKETSELECT
1239 static int build_prefix(
const LEX_STRING *prefix,
const char *category,
1240 char *output,
int *output_length)
1242 int len= strlen(category);
1243 char *out_ptr= output;
1244 int prefix_length= prefix->length;
1246 if (unlikely((prefix_length + len + 1) >=
1249 pfs_print_error(
"build_prefix: prefix+category is too long <%s> <%s>\n",
1250 prefix->str, category);
1254 if (unlikely(strchr(category,
'/') != NULL))
1256 pfs_print_error(
"build_prefix: invalid category <%s>\n",
1262 memcpy(out_ptr, prefix->str, prefix_length);
1263 out_ptr+= prefix_length;
1264 memcpy(out_ptr, category, len);
1268 *output_length= out_ptr - output;
1273 #define REGISTER_BODY_V1(KEY_T, PREFIX, REGISTER_FUNC) \
1275 char formatted_name[PFS_MAX_INFO_NAME_LENGTH]; \
1276 int prefix_length; \
1280 DBUG_ASSERT(category != NULL); \
1281 DBUG_ASSERT(info != NULL); \
1282 if (unlikely(build_prefix(&PREFIX, category, \
1283 formatted_name, &prefix_length))) \
1285 for (; count>0; count--, info++) \
1286 *(info->m_key)= 0; \
1290 for (; count>0; count--, info++) \
1292 DBUG_ASSERT(info->m_key != NULL); \
1293 DBUG_ASSERT(info->m_name != NULL); \
1294 len= strlen(info->m_name); \
1295 full_length= prefix_length + len; \
1296 if (likely(full_length <= PFS_MAX_INFO_NAME_LENGTH)) \
1298 memcpy(formatted_name + prefix_length, info->m_name, len); \
1299 key= REGISTER_FUNC(formatted_name, full_length, info->m_flags); \
1303 pfs_print_error("REGISTER_BODY_V1: name too long <%s> <%s>\n", \
1304 category, info->m_name); \
1308 *(info->m_key)= key; \
1320 static void register_mutex_v1(
const char *category,
1321 PSI_mutex_info_v1 *info,
1324 REGISTER_BODY_V1(PSI_mutex_key,
1333 static void register_rwlock_v1(
const char *category,
1334 PSI_rwlock_info_v1 *info,
1337 REGISTER_BODY_V1(PSI_rwlock_key,
1346 static void register_cond_v1(
const char *category,
1347 PSI_cond_info_v1 *info,
1350 REGISTER_BODY_V1(PSI_cond_key,
1359 static void register_thread_v1(
const char *category,
1360 PSI_thread_info_v1 *info,
1363 REGISTER_BODY_V1(PSI_thread_key,
1372 static void register_file_v1(
const char *category,
1373 PSI_file_info_v1 *info,
1376 REGISTER_BODY_V1(PSI_file_key,
1381 static void register_stage_v1(
const char *category,
1382 PSI_stage_info_v1 **info_array,
1389 PSI_stage_info_v1 *info;
1391 DBUG_ASSERT(category != NULL);
1392 DBUG_ASSERT(info_array != NULL);
1394 formatted_name, &prefix_length)))
1396 for (; count>0; count--, info_array++)
1397 (*info_array)->m_key= 0;
1401 for (; count>0; count--, info_array++)
1404 DBUG_ASSERT(info != NULL);
1405 DBUG_ASSERT(info->m_name != NULL);
1406 len= strlen(info->m_name);
1407 full_length= prefix_length + len;
1410 memcpy(formatted_name + prefix_length, info->m_name, len);
1418 pfs_print_error(
"register_stage_v1: name too long <%s> <%s>\n",
1419 category, info->m_name);
1426 static void register_statement_v1(
const char *category,
1427 PSI_statement_info_v1 *info,
1435 DBUG_ASSERT(category != NULL);
1436 DBUG_ASSERT(info != NULL);
1438 category, formatted_name, &prefix_length)))
1440 for (; count>0; count--, info++)
1445 for (; count>0; count--, info++)
1447 DBUG_ASSERT(info->m_name != NULL);
1448 len= strlen(info->m_name);
1449 full_length= prefix_length + len;
1452 memcpy(formatted_name + prefix_length, info->m_name, len);
1457 pfs_print_error(
"register_statement_v1: name too long <%s>\n",
1465 static void register_socket_v1(
const char *category,
1466 PSI_socket_info_v1 *info,
1469 REGISTER_BODY_V1(PSI_socket_key,
1470 socket_instrument_prefix,
1474 #define INIT_BODY_V1(T, KEY, ID) \
1475 PFS_##T##_class *klass; \
1477 klass= find_##T##_class(KEY); \
1478 if (unlikely(klass == NULL)) \
1480 if (! klass->m_enabled) \
1482 pfs= create_##T(klass, ID); \
1483 return reinterpret_cast<PSI_##T *> (pfs)
1490 init_mutex_v1(PSI_mutex_key key,
const void *identity)
1492 INIT_BODY_V1(mutex, key, identity);
1499 static void destroy_mutex_v1(PSI_mutex* mutex)
1503 DBUG_ASSERT(pfs != NULL);
1513 init_rwlock_v1(PSI_rwlock_key key,
const void *identity)
1515 INIT_BODY_V1(rwlock, key, identity);
1522 static void destroy_rwlock_v1(PSI_rwlock* rwlock)
1526 DBUG_ASSERT(pfs != NULL);
1536 init_cond_v1(PSI_cond_key key,
const void *identity)
1538 INIT_BODY_V1(cond, key, identity);
1545 static void destroy_cond_v1(PSI_cond* cond)
1549 DBUG_ASSERT(pfs != NULL);
1558 static PSI_table_share*
1559 get_table_share_v1(my_bool temporary,
TABLE_SHARE *share)
1562 if (temporary || share->is_view)
1566 if (unlikely(pfs_thread == NULL))
1570 return reinterpret_cast<PSI_table_share*
> (pfs_share);
1577 static void release_table_share_v1(PSI_table_share* share)
1581 if (unlikely(pfs == NULL))
1592 drop_table_share_v1(my_bool temporary,
1593 const char *schema_name,
int schema_name_length,
1594 const char *
table_name,
int table_name_length)
1600 if (unlikely(pfs_thread == NULL))
1604 table_name, table_name_length);
1612 open_table_v1(PSI_table_share *share,
const void *identity)
1616 if (unlikely(pfs_table_share == NULL))
1636 if (unlikely(thread == NULL))
1640 return reinterpret_cast<PSI_table *
> (pfs_table);
1647 static void unbind_table_v1(PSI_table *
table)
1650 if (likely(pfs != NULL))
1661 rebind_table_v1(PSI_table_share *share,
const void *identity, PSI_table *table)
1664 if (likely(pfs != NULL))
1670 thread= my_pthread_getspecific_ptr(
PFS_thread*, THR_PFS);
1698 if (unlikely(pfs_table_share == NULL))
1713 return reinterpret_cast<PSI_table *
> (pfs_table);
1720 static void close_table_v1(PSI_table *table)
1723 if (unlikely(pfs == NULL))
1730 init_socket_v1(PSI_socket_key key,
const my_socket *fd,
1731 const struct sockaddr *addr, socklen_t addr_len)
1736 if (unlikely(klass == NULL))
1741 return reinterpret_cast<PSI_socket *
> (pfs);
1744 static void destroy_socket_v1(PSI_socket *socket)
1748 DBUG_ASSERT(pfs != NULL);
1757 static void create_file_v1(PSI_file_key key,
const char *
name, File
file)
1761 int index= (int) file;
1762 if (unlikely(index < 0))
1765 if (unlikely(klass == NULL))
1772 if (unlikely(pfs_thread == NULL))
1788 uint len= strlen(name);
1801 ulonglong m_thread_internal_id;
1802 char m_username[USERNAME_LENGTH];
1803 uint m_username_length;
1804 char m_hostname[HOSTNAME_LENGTH];
1805 uint m_hostname_length;
1807 PSI_thread_key m_child_key;
1808 const void *m_child_identity;
1809 void *(*m_user_start_routine)(
void*);
1813 void* pfs_spawn_thread(
void *arg)
1817 void *(*user_start_routine)(
void*);
1823 if (likely(klass != NULL))
1826 if (likely(pfs != NULL))
1828 clear_thread_account(pfs);
1830 pfs->m_parent_thread_internal_id= typed_arg->m_thread_internal_id;
1832 memcpy(pfs->m_username, typed_arg->m_username,
sizeof(pfs->m_username));
1833 pfs->m_username_length= typed_arg->m_username_length;
1835 memcpy(pfs->m_hostname, typed_arg->m_hostname,
sizeof(pfs->m_hostname));
1836 pfs->m_hostname_length= typed_arg->m_hostname_length;
1838 set_thread_account(pfs);
1845 my_pthread_setspecific_ptr(THR_PFS, pfs);
1853 user_start_routine= typed_arg->m_user_start_routine;
1854 user_arg= typed_arg->m_user_arg;
1858 (*user_start_routine)(user_arg);
1867 static int spawn_thread_v1(PSI_thread_key key,
1868 pthread_t *thread,
const pthread_attr_t *attr,
1869 void *(*start_routine)(
void*),
void *arg)
1877 if (unlikely(psi_arg == NULL))
1880 psi_arg->m_child_key= key;
1881 psi_arg->m_child_identity= (arg ? arg : thread);
1882 psi_arg->m_user_start_routine= start_routine;
1883 psi_arg->m_user_arg= arg;
1885 parent= my_pthread_getspecific_ptr(
PFS_thread*, THR_PFS);
1895 memcpy(psi_arg->m_username, parent->
m_username,
sizeof(psi_arg->m_username));
1898 memcpy(psi_arg->m_hostname, parent->
m_hostname,
sizeof(psi_arg->m_hostname));
1903 psi_arg->m_thread_internal_id= 0;
1904 psi_arg->m_username_length= 0;
1905 psi_arg->m_hostname_length= 0;
1908 int result= pthread_create(thread, attr, pfs_spawn_thread, psi_arg);
1909 if (unlikely(result != 0))
1919 new_thread_v1(PSI_thread_key key,
const void *identity, ulonglong processlist_id)
1924 if (likely(klass != NULL))
1929 return reinterpret_cast<PSI_thread*
> (pfs);
1936 static void set_thread_id_v1(PSI_thread *thread, ulonglong processlist_id)
1939 if (unlikely(pfs == NULL))
1952 return reinterpret_cast<PSI_thread*
> (pfs);
1959 static void set_thread_user_v1(
const char *user,
int user_len)
1963 DBUG_ASSERT((user != NULL) || (user_len == 0));
1964 DBUG_ASSERT(user_len >= 0);
1965 DBUG_ASSERT((uint) user_len <=
sizeof(pfs->
m_username));
1967 if (unlikely(pfs == NULL))
1970 aggregate_thread(pfs, pfs->m_account, pfs->m_user, pfs->m_host);
1974 clear_thread_account(pfs);
1980 set_thread_account(pfs);
1993 lookup_setup_actor(pfs,
2009 static void set_thread_account_v1(
const char *user,
int user_len,
2010 const char *host,
int host_len)
2014 DBUG_ASSERT((user != NULL) || (user_len == 0));
2015 DBUG_ASSERT(user_len >= 0);
2016 DBUG_ASSERT((uint) user_len <=
sizeof(pfs->
m_username));
2017 DBUG_ASSERT((host != NULL) || (host_len == 0));
2018 DBUG_ASSERT(host_len >= 0);
2019 DBUG_ASSERT((uint) host_len <=
sizeof(pfs->
m_hostname));
2021 if (unlikely(pfs == NULL))
2026 clear_thread_account(pfs);
2036 set_thread_account(pfs);
2049 lookup_setup_actor(pfs,
2064 static void set_thread_db_v1(
const char* db,
int db_len)
2068 DBUG_ASSERT((db != NULL) || (db_len == 0));
2069 DBUG_ASSERT(db_len >= 0);
2070 DBUG_ASSERT((uint) db_len <=
sizeof(pfs->
m_dbname));
2072 if (likely(pfs != NULL))
2086 static void set_thread_command_v1(
int command)
2090 DBUG_ASSERT(command >= 0);
2091 DBUG_ASSERT(command <= (
int) COM_END);
2093 if (likely(pfs != NULL))
2103 static void set_thread_start_time_v1(time_t start_time)
2107 if (likely(pfs != NULL))
2117 static void set_thread_state_v1(
const char* state)
2126 static void set_thread_info_v1(
const char* info, uint info_len)
2130 DBUG_ASSERT((info != NULL) || (info_len == 0));
2132 if (likely(pfs != NULL))
2134 if ((info != NULL) && (info_len > 0))
2157 static void set_thread_v1(PSI_thread* thread)
2160 my_pthread_setspecific_ptr(THR_PFS, pfs);
2167 static void delete_current_thread_v1(
void)
2172 aggregate_thread(thread, thread->m_account, thread->m_user, thread->m_host);
2173 my_pthread_setspecific_ptr(THR_PFS, NULL);
2182 static void delete_thread_v1(PSI_thread *thread)
2188 aggregate_thread(pfs, pfs->m_account, pfs->m_user, pfs->m_host);
2197 static PSI_mutex_locker*
2198 start_mutex_wait_v1(PSI_mutex_locker_state *state,
2199 PSI_mutex *mutex, PSI_mutex_operation op,
2200 const char *src_file, uint src_line)
2203 DBUG_ASSERT((
int) op >= 0);
2204 DBUG_ASSERT((uint) op < array_elements(mutex_operation_map));
2205 DBUG_ASSERT(state != NULL);
2207 DBUG_ASSERT(pfs_mutex != NULL);
2208 DBUG_ASSERT(pfs_mutex->
m_class != NULL);
2213 register uint
flags;
2214 ulonglong timer_start= 0;
2219 if (unlikely(pfs_thread == NULL))
2223 state->m_thread=
reinterpret_cast<PSI_thread *
> (pfs_thread);
2229 state->m_timer_start= timer_start;
2242 state->m_wait= wait;
2270 state->m_timer_start= timer_start;
2272 state->m_thread= NULL;
2285 state->m_flags=
flags;
2286 state->m_mutex= mutex;
2287 return reinterpret_cast<PSI_mutex_locker*
> (state);
2295 static PSI_rwlock_locker*
2296 start_rwlock_wait_v1(PSI_rwlock_locker_state *state,
2298 PSI_rwlock_operation op,
2299 const char *src_file, uint src_line)
2302 DBUG_ASSERT(static_cast<int> (op) >= 0);
2303 DBUG_ASSERT(static_cast<uint> (op) < array_elements(rwlock_operation_map));
2304 DBUG_ASSERT(state != NULL);
2305 DBUG_ASSERT(pfs_rwlock != NULL);
2306 DBUG_ASSERT(pfs_rwlock->
m_class != NULL);
2311 register uint
flags;
2312 ulonglong timer_start= 0;
2317 if (unlikely(pfs_thread == NULL))
2321 state->m_thread=
reinterpret_cast<PSI_thread *
> (pfs_thread);
2327 state->m_timer_start= timer_start;
2340 state->m_wait= wait;
2355 wait->
m_operation= rwlock_operation_map[
static_cast<int> (op)];
2368 state->m_timer_start= timer_start;
2370 state->m_thread= NULL;
2383 state->m_flags=
flags;
2384 state->m_rwlock= rwlock;
2385 return reinterpret_cast<PSI_rwlock_locker*
> (state);
2392 static PSI_cond_locker*
2393 start_cond_wait_v1(PSI_cond_locker_state *state,
2394 PSI_cond *cond, PSI_mutex *mutex,
2395 PSI_cond_operation op,
2396 const char *src_file, uint src_line)
2410 DBUG_ASSERT(static_cast<int> (op) >= 0);
2411 DBUG_ASSERT(static_cast<uint> (op) < array_elements(cond_operation_map));
2412 DBUG_ASSERT(state != NULL);
2413 DBUG_ASSERT(pfs_cond != NULL);
2414 DBUG_ASSERT(pfs_cond->
m_class != NULL);
2419 register uint
flags;
2420 ulonglong timer_start= 0;
2425 if (unlikely(pfs_thread == NULL))
2429 state->m_thread=
reinterpret_cast<PSI_thread *
> (pfs_thread);
2435 state->m_timer_start= timer_start;
2448 state->m_wait= wait;
2463 wait->
m_operation= cond_operation_map[
static_cast<int> (op)];
2476 state->m_timer_start= timer_start;
2490 state->m_flags=
flags;
2491 state->m_cond= cond;
2492 state->m_mutex= mutex;
2493 return reinterpret_cast<PSI_cond_locker*
> (state);
2496 static inline PFS_TL_LOCK_TYPE lock_flags_to_lock_type(uint flags)
2498 enum thr_lock_type value=
static_cast<enum thr_lock_type
> (
flags);
2504 case TL_READ_WITH_SHARED_LOCKS:
2505 return PFS_TL_READ_WITH_SHARED_LOCKS;
2506 case TL_READ_HIGH_PRIORITY:
2507 return PFS_TL_READ_HIGH_PRIORITY;
2508 case TL_READ_NO_INSERT:
2509 return PFS_TL_READ_NO_INSERT;
2510 case TL_WRITE_ALLOW_WRITE:
2511 return PFS_TL_WRITE_ALLOW_WRITE;
2512 case TL_WRITE_CONCURRENT_INSERT:
2513 return PFS_TL_WRITE_CONCURRENT_INSERT;
2514 case TL_WRITE_DELAYED:
2515 return PFS_TL_WRITE_DELAYED;
2516 case TL_WRITE_LOW_PRIORITY:
2517 return PFS_TL_WRITE_LOW_PRIORITY;
2519 return PFS_TL_WRITE;
2524 case TL_READ_DEFAULT:
2525 case TL_WRITE_DEFAULT:
2534 static inline PFS_TL_LOCK_TYPE external_lock_flags_to_lock_type(uint flags)
2536 DBUG_ASSERT(flags == F_RDLCK || flags == F_WRLCK);
2537 return (flags == F_RDLCK ? PFS_TL_READ_EXTERNAL : PFS_TL_WRITE_EXTERNAL);
2544 static PSI_table_locker*
2545 start_table_io_wait_v1(PSI_table_locker_state *state,
2547 PSI_table_io_operation op,
2549 const char *src_file, uint src_line)
2551 DBUG_ASSERT(static_cast<int> (op) >= 0);
2552 DBUG_ASSERT(static_cast<uint> (op) < array_elements(table_io_operation_map));
2553 DBUG_ASSERT(state != NULL);
2555 DBUG_ASSERT(pfs_table != NULL);
2556 DBUG_ASSERT(pfs_table->
m_share != NULL);
2563 DBUG_ASSERT(pfs_thread ==
2564 my_pthread_getspecific_ptr(
PFS_thread*, THR_PFS));
2566 register uint
flags;
2567 ulonglong timer_start= 0;
2571 if (pfs_thread == NULL)
2575 state->m_thread=
reinterpret_cast<PSI_thread *
> (pfs_thread);
2581 state->m_timer_start= timer_start;
2594 state->m_wait= wait;
2610 wait->
m_operation= table_io_operation_map[
static_cast<int> (op)];
2628 state->m_timer_start= timer_start;
2638 state->m_flags=
flags;
2639 state->m_table=
table;
2640 state->m_io_operation= op;
2641 state->m_index=
index;
2642 return reinterpret_cast<PSI_table_locker*
> (state);
2649 static PSI_table_locker*
2650 start_table_lock_wait_v1(PSI_table_locker_state *state,
2652 PSI_table_lock_operation op,
2654 const char *src_file, uint src_line)
2656 DBUG_ASSERT(state != NULL);
2657 DBUG_ASSERT((op == PSI_TABLE_LOCK) || (op == PSI_TABLE_EXTERNAL_LOCK));
2661 DBUG_ASSERT(pfs_table != NULL);
2662 DBUG_ASSERT(pfs_table->
m_share != NULL);
2669 PFS_TL_LOCK_TYPE lock_type;
2673 case PSI_TABLE_LOCK:
2674 lock_type= lock_flags_to_lock_type(op_flags);
2676 case PSI_TABLE_EXTERNAL_LOCK:
2681 if (op_flags == F_UNLCK)
2683 lock_type= external_lock_flags_to_lock_type(op_flags);
2686 lock_type= PFS_TL_READ;
2690 DBUG_ASSERT((uint) lock_type < array_elements(table_lock_operation_map));
2692 register uint
flags;
2693 ulonglong timer_start= 0;
2697 if (pfs_thread == NULL)
2701 state->m_thread=
reinterpret_cast<PSI_thread *
> (pfs_thread);
2707 state->m_timer_start= timer_start;
2720 state->m_wait= wait;
2736 wait->
m_operation= table_lock_operation_map[lock_type];
2754 state->m_timer_start= timer_start;
2764 state->m_flags=
flags;
2765 state->m_table=
table;
2766 state->m_index= lock_type;
2767 return reinterpret_cast<PSI_table_locker*
> (state);
2774 static PSI_file_locker*
2775 get_thread_file_name_locker_v1(PSI_file_locker_state *state,
2777 PSI_file_operation op,
2778 const char *name,
const void *identity)
2780 DBUG_ASSERT(static_cast<int> (op) >= 0);
2781 DBUG_ASSERT(static_cast<uint> (op) < array_elements(file_operation_map));
2782 DBUG_ASSERT(state != NULL);
2787 if (unlikely(klass == NULL))
2794 if (unlikely(pfs_thread == NULL))
2800 register uint
flags;
2802 state->m_thread=
reinterpret_cast<PSI_thread *
> (pfs_thread);
2817 state->m_wait= wait;
2834 wait->
m_operation= file_operation_map[
static_cast<int> (op)];
2841 state->m_file= NULL;
2842 state->m_name=
name;
2843 state->m_class= klass;
2844 state->m_operation= op;
2845 return reinterpret_cast<PSI_file_locker*
> (state);
2852 static PSI_file_locker*
2853 get_thread_file_stream_locker_v1(PSI_file_locker_state *state,
2854 PSI_file *file, PSI_file_operation op)
2857 DBUG_ASSERT(static_cast<int> (op) >= 0);
2858 DBUG_ASSERT(static_cast<uint> (op) < array_elements(file_operation_map));
2859 DBUG_ASSERT(state != NULL);
2861 if (unlikely(pfs_file == NULL))
2863 DBUG_ASSERT(pfs_file->
m_class != NULL);
2869 register uint
flags;
2874 if (unlikely(pfs_thread == NULL))
2878 state->m_thread=
reinterpret_cast<PSI_thread *
> (pfs_thread);
2893 state->m_wait= wait;
2910 wait->
m_operation= file_operation_map[
static_cast<int> (op)];
2930 state->m_flags=
flags;
2931 state->m_file=
reinterpret_cast<PSI_file*
> (pfs_file);
2932 state->m_operation= op;
2933 state->m_name= NULL;
2934 state->m_class= klass;
2935 return reinterpret_cast<PSI_file_locker*
> (state);
2942 static PSI_file_locker*
2943 get_thread_file_descriptor_locker_v1(PSI_file_locker_state *state,
2944 File file, PSI_file_operation op)
2946 int index=
static_cast<int> (
file);
2947 DBUG_ASSERT(static_cast<int> (op) >= 0);
2948 DBUG_ASSERT(static_cast<uint> (op) < array_elements(file_operation_map));
2949 DBUG_ASSERT(state != NULL);
2955 if (unlikely(pfs_file == NULL))
2966 if (op == PSI_FILE_CLOSE)
2972 DBUG_ASSERT(pfs_file->
m_class != NULL);
2975 register uint
flags;
2980 if (unlikely(pfs_thread == NULL))
2984 state->m_thread=
reinterpret_cast<PSI_thread *
> (pfs_thread);
2999 state->m_wait= wait;
3016 wait->
m_operation= file_operation_map[
static_cast<int> (op)];
3036 state->m_flags=
flags;
3037 state->m_file=
reinterpret_cast<PSI_file*
> (pfs_file);
3038 state->m_operation= op;
3039 state->m_name= NULL;
3040 state->m_class= klass;
3041 return reinterpret_cast<PSI_file_locker*
> (state);
3046 static PSI_socket_locker*
3047 start_socket_wait_v1(PSI_socket_locker_state *state,
3049 PSI_socket_operation op,
3051 const char *src_file, uint src_line)
3053 DBUG_ASSERT(static_cast<int> (op) >= 0);
3054 DBUG_ASSERT(static_cast<uint> (op) < array_elements(socket_operation_map));
3055 DBUG_ASSERT(state != NULL);
3058 DBUG_ASSERT(pfs_socket != NULL);
3059 DBUG_ASSERT(pfs_socket->
m_class != NULL);
3064 register uint flags= 0;
3065 ulonglong timer_start= 0;
3071 if (unlikely(pfs_thread == NULL))
3077 state->m_thread=
reinterpret_cast<PSI_thread *
> (pfs_thread);
3083 state->m_timer_start= timer_start;
3096 state->m_wait= wait;
3112 wait->
m_operation= socket_operation_map[
static_cast<int>(op)];
3126 state->m_timer_start= timer_start;
3139 case PSI_SOCKET_CONNECT:
3140 case PSI_SOCKET_CREATE:
3141 case PSI_SOCKET_BIND:
3142 case PSI_SOCKET_SEEK:
3143 case PSI_SOCKET_OPT:
3144 case PSI_SOCKET_STAT:
3145 case PSI_SOCKET_SHUTDOWN:
3146 case PSI_SOCKET_CLOSE:
3147 case PSI_SOCKET_SELECT:
3156 state->m_flags=
flags;
3157 state->m_socket= socket;
3158 state->m_operation= op;
3159 return reinterpret_cast<PSI_socket_locker*
> (state);
3166 static void unlock_mutex_v1(PSI_mutex *mutex)
3170 DBUG_ASSERT(pfs_mutex != NULL);
3193 ulonglong locked_time;
3203 static void unlock_rwlock_v1(PSI_rwlock *rwlock)
3206 DBUG_ASSERT(pfs_rwlock != NULL);
3207 DBUG_ASSERT(pfs_rwlock == sanitize_rwlock(pfs_rwlock));
3208 DBUG_ASSERT(pfs_rwlock->
m_class != NULL);
3211 bool last_writer=
false;
3212 bool last_reader=
false;
3231 else if (likely(pfs_rwlock->
m_readers > 0))
3260 ulonglong locked_time;
3266 else if (last_reader)
3281 static void signal_cond_v1(PSI_cond* cond)
3285 DBUG_ASSERT(pfs_cond != NULL);
3294 static void broadcast_cond_v1(PSI_cond* cond)
3298 DBUG_ASSERT(pfs_cond != NULL);
3307 static PSI_idle_locker*
3308 start_idle_wait_v1(PSI_idle_locker_state* state,
const char *src_file, uint src_line)
3310 DBUG_ASSERT(state != NULL);
3318 register uint flags= 0;
3319 ulonglong timer_start= 0;
3324 if (unlikely(pfs_thread == NULL))
3328 state->m_thread=
reinterpret_cast<PSI_thread *
> (pfs_thread);
3336 state->m_timer_start= timer_start;
3349 state->m_wait= wait;
3380 state->m_timer_start= timer_start;
3385 state->m_flags=
flags;
3386 return reinterpret_cast<PSI_idle_locker*
> (state);
3393 static void end_idle_wait_v1(PSI_idle_locker* locker)
3395 PSI_idle_locker_state *state=
reinterpret_cast<PSI_idle_locker_state*
> (locker);
3396 DBUG_ASSERT(state != NULL);
3397 ulonglong timer_end= 0;
3398 ulonglong wait_time= 0;
3400 register uint flags= state->m_flags;
3404 timer_end= state->m_timer();
3405 wait_time= timer_end - state->m_timer_start;
3414 if (flags & STATE_FLAG_TIMED)
3417 event_name_array[GLOBAL_IDLE_EVENT_INDEX].aggregate_value(wait_time);
3422 event_name_array[GLOBAL_IDLE_EVENT_INDEX].aggregate_counted();
3428 DBUG_ASSERT(wait != NULL);
3440 if (flags & STATE_FLAG_TIMED)
3456 static void end_mutex_wait_v1(PSI_mutex_locker* locker,
int rc)
3458 PSI_mutex_locker_state *state=
reinterpret_cast<PSI_mutex_locker_state*
> (locker);
3459 DBUG_ASSERT(state != NULL);
3461 ulonglong timer_end= 0;
3462 ulonglong wait_time= 0;
3465 DBUG_ASSERT(mutex != NULL);
3468 register uint flags= state->m_flags;
3470 if (flags & STATE_FLAG_TIMED)
3472 timer_end= state->m_timer();
3473 wait_time= timer_end - state->m_timer_start;
3483 if (likely(rc == 0))
3489 if (flags & STATE_FLAG_THREAD)
3495 if (flags & STATE_FLAG_TIMED)
3498 event_name_array[
index].aggregate_value(wait_time);
3503 event_name_array[
index].aggregate_counted();
3506 if (flags & STATE_FLAG_EVENT)
3509 DBUG_ASSERT(wait != NULL);
3526 static void end_rwlock_rdwait_v1(PSI_rwlock_locker* locker,
int rc)
3528 PSI_rwlock_locker_state *state=
reinterpret_cast<PSI_rwlock_locker_state*
> (locker);
3529 DBUG_ASSERT(state != NULL);
3531 ulonglong timer_end= 0;
3532 ulonglong wait_time= 0;
3535 DBUG_ASSERT(rwlock != NULL);
3537 if (state->m_flags & STATE_FLAG_TIMED)
3539 timer_end= state->m_timer();
3540 wait_time= timer_end - state->m_timer_start;
3565 if (state->m_flags & STATE_FLAG_THREAD)
3568 DBUG_ASSERT(thread != NULL);
3574 if (state->m_flags & STATE_FLAG_TIMED)
3577 event_name_array[
index].aggregate_value(wait_time);
3582 event_name_array[
index].aggregate_counted();
3585 if (state->m_flags & STATE_FLAG_EVENT)
3588 DBUG_ASSERT(wait != NULL);
3605 static void end_rwlock_wrwait_v1(PSI_rwlock_locker* locker,
int rc)
3607 PSI_rwlock_locker_state *state=
reinterpret_cast<PSI_rwlock_locker_state*
> (locker);
3608 DBUG_ASSERT(state != NULL);
3610 ulonglong timer_end= 0;
3611 ulonglong wait_time= 0;
3614 DBUG_ASSERT(rwlock != NULL);
3617 if (state->m_flags & STATE_FLAG_TIMED)
3619 timer_end= state->m_timer();
3620 wait_time= timer_end - state->m_timer_start;
3630 if (likely(rc == 0))
3640 if (state->m_flags & STATE_FLAG_THREAD)
3646 if (state->m_flags & STATE_FLAG_TIMED)
3649 event_name_array[
index].aggregate_value(wait_time);
3654 event_name_array[
index].aggregate_counted();
3657 if (state->m_flags & STATE_FLAG_EVENT)
3660 DBUG_ASSERT(wait != NULL);
3677 static void end_cond_wait_v1(PSI_cond_locker* locker,
int rc)
3679 PSI_cond_locker_state *state=
reinterpret_cast<PSI_cond_locker_state*
> (locker);
3680 DBUG_ASSERT(state != NULL);
3682 ulonglong timer_end= 0;
3683 ulonglong wait_time= 0;
3688 if (state->m_flags & STATE_FLAG_TIMED)
3690 timer_end= state->m_timer();
3691 wait_time= timer_end - state->m_timer_start;
3701 if (state->m_flags & STATE_FLAG_THREAD)
3704 DBUG_ASSERT(thread != NULL);
3710 if (state->m_flags & STATE_FLAG_TIMED)
3713 event_name_array[
index].aggregate_value(wait_time);
3718 event_name_array[
index].aggregate_counted();
3721 if (state->m_flags & STATE_FLAG_EVENT)
3724 DBUG_ASSERT(wait != NULL);
3741 static void end_table_io_wait_v1(PSI_table_locker* locker)
3743 PSI_table_locker_state *state=
reinterpret_cast<PSI_table_locker_state*
> (locker);
3744 DBUG_ASSERT(state != NULL);
3746 ulonglong timer_end= 0;
3747 ulonglong wait_time= 0;
3750 DBUG_ASSERT(table != NULL);
3756 (state->m_index == MAX_INDEXES));
3759 table_io_stat->m_has_data=
true;
3761 switch (state->m_io_operation)
3763 case PSI_TABLE_FETCH_ROW:
3764 stat= & table_io_stat->
m_fetch;
3766 case PSI_TABLE_WRITE_ROW:
3769 case PSI_TABLE_UPDATE_ROW:
3772 case PSI_TABLE_DELETE_ROW:
3781 register uint flags= state->m_flags;
3783 if (flags & STATE_FLAG_TIMED)
3785 timer_end= state->m_timer();
3786 wait_time= timer_end - state->m_timer_start;
3787 stat->aggregate_value(wait_time);
3791 stat->aggregate_counted();
3794 if (flags & STATE_FLAG_THREAD)
3797 DBUG_ASSERT(thread != NULL);
3806 if (flags & STATE_FLAG_TIMED)
3808 event_name_array[GLOBAL_TABLE_IO_EVENT_INDEX].aggregate_value(wait_time);
3812 event_name_array[GLOBAL_TABLE_IO_EVENT_INDEX].aggregate_counted();
3815 if (flags & STATE_FLAG_EVENT)
3818 DBUG_ASSERT(wait != NULL);
3837 static void end_table_lock_wait_v1(PSI_table_locker* locker)
3839 PSI_table_locker_state *state=
reinterpret_cast<PSI_table_locker_state*
> (locker);
3840 DBUG_ASSERT(state != NULL);
3842 ulonglong timer_end= 0;
3843 ulonglong wait_time= 0;
3846 DBUG_ASSERT(table != NULL);
3850 register uint flags= state->m_flags;
3852 if (flags & STATE_FLAG_TIMED)
3854 timer_end= state->m_timer();
3855 wait_time= timer_end - state->m_timer_start;
3856 stat->aggregate_value(wait_time);
3860 stat->aggregate_counted();
3863 if (flags & STATE_FLAG_THREAD)
3866 DBUG_ASSERT(thread != NULL);
3875 if (flags & STATE_FLAG_TIMED)
3877 event_name_array[GLOBAL_TABLE_LOCK_EVENT_INDEX].aggregate_value(wait_time);
3881 event_name_array[GLOBAL_TABLE_LOCK_EVENT_INDEX].aggregate_counted();
3884 if (flags & STATE_FLAG_EVENT)
3887 DBUG_ASSERT(wait != NULL);
3902 static void start_file_wait_v1(PSI_file_locker *locker,
3904 const char *src_file,
3907 static void end_file_wait_v1(PSI_file_locker *locker,
3914 static void start_file_open_wait_v1(PSI_file_locker *locker,
3915 const char *src_file,
3918 start_file_wait_v1(locker, 0, src_file, src_line);
3927 static PSI_file* end_file_open_wait_v1(PSI_file_locker *locker,
3930 PSI_file_locker_state *state=
reinterpret_cast<PSI_file_locker_state*
> (locker);
3931 DBUG_ASSERT(state != NULL);
3933 switch (state->m_operation)
3937 case PSI_FILE_STREAM_OPEN:
3938 case PSI_FILE_CREATE:
3943 const char *name= state->m_name;
3944 uint len= strlen(name);
3946 state->m_file=
reinterpret_cast<PSI_file*
> (pfs_file);
3955 end_file_wait_v1(locker, 0);
3957 return state->m_file;
3964 static void end_file_open_wait_and_bind_to_descriptor_v1
3965 (PSI_file_locker *locker, File file)
3968 int index= (int) file;
3969 PSI_file_locker_state *state=
reinterpret_cast<PSI_file_locker_state*
> (locker);
3970 DBUG_ASSERT(state != NULL);
3976 const char *name= state->m_name;
3977 uint len= strlen(name);
3979 state->m_file=
reinterpret_cast<PSI_file*
> (pfs_file);
3982 end_file_wait_v1(locker, 0);
3984 if (likely(index >= 0))
3990 if (pfs_file != NULL)
4001 static void start_file_wait_v1(PSI_file_locker *locker,
4003 const char *src_file,
4006 ulonglong timer_start= 0;
4007 PSI_file_locker_state *state=
reinterpret_cast<PSI_file_locker_state*
> (locker);
4008 DBUG_ASSERT(state != NULL);
4010 register uint flags= state->m_flags;
4012 if (flags & STATE_FLAG_TIMED)
4015 state->m_timer_start= timer_start;
4018 if (flags & STATE_FLAG_EVENT)
4021 DBUG_ASSERT(wait != NULL);
4034 static void end_file_wait_v1(PSI_file_locker *locker,
4037 PSI_file_locker_state *state=
reinterpret_cast<PSI_file_locker_state*
> (locker);
4038 DBUG_ASSERT(state != NULL);
4043 ulonglong timer_end= 0;
4044 ulonglong wait_time= 0;
4046 register uint flags= state->m_flags;
4047 size_t bytes= ((int)byte_count > -1 ? byte_count : 0);
4060 switch (state->m_operation)
4067 case PSI_FILE_WRITE:
4071 case PSI_FILE_CREATE:
4072 case PSI_FILE_CREATE_TMP:
4074 case PSI_FILE_STREAM_OPEN:
4075 case PSI_FILE_STREAM_CLOSE:
4078 case PSI_FILE_FLUSH:
4079 case PSI_FILE_FSTAT:
4080 case PSI_FILE_CHSIZE:
4081 case PSI_FILE_DELETE:
4082 case PSI_FILE_RENAME:
4085 case PSI_FILE_CLOSE:
4095 if (flags & STATE_FLAG_TIMED)
4097 timer_end= state->m_timer();
4098 wait_time= timer_end - state->m_timer_start;
4100 byte_stat->aggregate(wait_time, bytes);
4105 byte_stat->aggregate_counted(bytes);
4108 if (flags & STATE_FLAG_THREAD)
4110 DBUG_ASSERT(thread != NULL);
4116 if (flags & STATE_FLAG_TIMED)
4119 event_name_array[
index].aggregate_value(wait_time);
4124 event_name_array[
index].aggregate_counted();
4127 if (state->m_flags & STATE_FLAG_EVENT)
4130 DBUG_ASSERT(wait != NULL);
4152 static void start_file_close_wait_v1(PSI_file_locker *locker,
4153 const char *src_file,
4160 PSI_file_locker_state *state=
reinterpret_cast<PSI_file_locker_state*
> (locker);
4161 DBUG_ASSERT(state != NULL);
4163 switch (state->m_operation)
4165 case PSI_FILE_DELETE:
4166 thread=
reinterpret_cast<PFS_thread*
> (state->m_thread);
4167 name= state->m_name;
4170 state->m_file=
reinterpret_cast<PSI_file*
> (pfs_file);
4172 case PSI_FILE_STREAM_CLOSE:
4173 case PSI_FILE_CLOSE:
4180 start_file_wait_v1(locker, 0, src_file, src_line);
4189 static void end_file_close_wait_v1(PSI_file_locker *locker,
int rc)
4191 PSI_file_locker_state *state=
reinterpret_cast<PSI_file_locker_state*
> (locker);
4192 DBUG_ASSERT(state != NULL);
4194 end_file_wait_v1(locker, 0);
4202 switch(state->m_operation)
4204 case PSI_FILE_CLOSE:
4205 case PSI_FILE_STREAM_CLOSE:
4209 case PSI_FILE_DELETE:
4221 static void start_stage_v1(PSI_stage_key key,
const char *src_file,
int src_line)
4223 ulonglong timer_value= 0;
4226 if (unlikely(pfs_thread == NULL))
4243 if (old_class != NULL)
4257 event_name_array[
index].aggregate_value(stage_time);
4262 event_name_array[
index].aggregate_counted();
4286 if (unlikely(new_klass == NULL))
4299 if (timer_value == 0)
4322 static void end_stage_v1()
4324 ulonglong timer_value= 0;
4327 if (unlikely(pfs_thread == NULL))
4341 if (old_class != NULL)
4355 event_name_array[
index].aggregate_value(stage_time);
4360 event_name_array[
index].aggregate_counted();
4383 static PSI_statement_locker*
4384 get_thread_statement_locker_v1(PSI_statement_locker_state *state,
4385 PSI_statement_key key,
4386 const void *charset)
4388 DBUG_ASSERT(state != NULL);
4392 if (unlikely(klass == NULL))
4397 register uint
flags;
4402 if (unlikely(pfs_thread == NULL))
4406 state->m_thread=
reinterpret_cast<PSI_thread *
> (pfs_thread);
4414 ulonglong event_id= pfs_thread->
m_event_id++;
4467 state->m_statement= pfs;
4481 if (flag_statements_digest)
4485 state->m_digest_state.m_last_id_index= 0;
4486 digest_reset(& state->m_digest_state.m_digest_storage);
4487 state->m_digest_state.m_digest_storage.m_charset_number= cs->number;
4490 state->m_discarded=
false;
4491 state->m_class= klass;
4494 state->m_lock_time= 0;
4495 state->m_rows_sent= 0;
4496 state->m_rows_examined= 0;
4497 state->m_created_tmp_disk_tables= 0;
4498 state->m_created_tmp_tables= 0;
4499 state->m_select_full_join= 0;
4500 state->m_select_full_range_join= 0;
4501 state->m_select_range= 0;
4502 state->m_select_range_check= 0;
4503 state->m_select_scan= 0;
4504 state->m_sort_merge_passes= 0;
4505 state->m_sort_range= 0;
4506 state->m_sort_rows= 0;
4507 state->m_sort_scan= 0;
4508 state->m_no_index_used= 0;
4509 state->m_no_good_index_used= 0;
4511 state->m_schema_name_length= 0;
4513 return reinterpret_cast<PSI_statement_locker*
> (state);
4516 static PSI_statement_locker*
4517 refine_statement_v1(PSI_statement_locker *locker,
4518 PSI_statement_key key)
4520 PSI_statement_locker_state *state=
reinterpret_cast<PSI_statement_locker_state*
> (locker);
4523 DBUG_ASSERT(state->m_class != NULL);
4527 DBUG_ASSERT(klass->
m_flags & PSI_FLAG_MUTABLE);
4530 uint flags= state->m_flags;
4532 if (unlikely(klass == NULL) || !klass->
m_enabled)
4535 if (flags & STATE_FLAG_THREAD)
4538 DBUG_ASSERT(pfs_thread != NULL);
4543 state->m_discarded=
true;
4547 if ((flags & STATE_FLAG_TIMED) && ! klass->
m_timed)
4548 flags= flags & ~STATE_FLAG_TIMED;
4550 if (flags & STATE_FLAG_EVENT)
4553 DBUG_ASSERT(pfs != NULL);
4559 state->m_class= klass;
4561 return reinterpret_cast<PSI_statement_locker*
> (state);
4564 static void start_statement_v1(PSI_statement_locker *locker,
4565 const char *db, uint db_len,
4566 const char *src_file, uint src_line)
4568 PSI_statement_locker_state *state=
reinterpret_cast<PSI_statement_locker_state*
> (locker);
4569 DBUG_ASSERT(state != NULL);
4571 register uint flags= state->m_flags;
4572 ulonglong timer_start= 0;
4574 if (flags & STATE_FLAG_TIMED)
4577 state->m_timer_start= timer_start;
4580 compile_time_assert(PSI_SCHEMA_NAME_LEN == NAME_LEN);
4581 DBUG_ASSERT(db_len <=
sizeof(state->m_schema_name));
4584 memcpy(state->m_schema_name, db, db_len);
4585 state->m_schema_name_length= db_len;
4587 if (flags & STATE_FLAG_EVENT)
4590 DBUG_ASSERT(pfs != NULL);
4603 static void set_statement_text_v1(PSI_statement_locker *locker,
4604 const char *text, uint text_len)
4606 PSI_statement_locker_state *state=
reinterpret_cast<PSI_statement_locker_state*
> (locker);
4607 DBUG_ASSERT(state != NULL);
4609 if (state->m_discarded)
4612 if (state->m_flags & STATE_FLAG_EVENT)
4615 DBUG_ASSERT(pfs != NULL);
4626 #define SET_STATEMENT_ATTR_BODY(LOCKER, ATTR, VALUE) \
4627 PSI_statement_locker_state *state; \
4628 state= reinterpret_cast<PSI_statement_locker_state*> (LOCKER); \
4629 if (unlikely(state == NULL)) \
4631 if (state->m_discarded) \
4633 state->ATTR= VALUE; \
4634 if (state->m_flags & STATE_FLAG_EVENT) \
4636 PFS_events_statements *pfs; \
4637 pfs= reinterpret_cast<PFS_events_statements*> (state->m_statement); \
4638 DBUG_ASSERT(pfs != NULL); \
4643 #define INC_STATEMENT_ATTR_BODY(LOCKER, ATTR, VALUE) \
4644 PSI_statement_locker_state *state; \
4645 state= reinterpret_cast<PSI_statement_locker_state*> (LOCKER); \
4646 if (unlikely(state == NULL)) \
4648 if (state->m_discarded) \
4650 state->ATTR+= VALUE; \
4651 if (state->m_flags & STATE_FLAG_EVENT) \
4653 PFS_events_statements *pfs; \
4654 pfs= reinterpret_cast<PFS_events_statements*> (state->m_statement); \
4655 DBUG_ASSERT(pfs != NULL); \
4656 pfs->ATTR+= VALUE; \
4660 static void set_statement_lock_time_v1(PSI_statement_locker *locker,
4663 SET_STATEMENT_ATTR_BODY(locker, m_lock_time, count);
4666 static void set_statement_rows_sent_v1(PSI_statement_locker *locker,
4669 SET_STATEMENT_ATTR_BODY(locker, m_rows_sent, count);
4672 static void set_statement_rows_examined_v1(PSI_statement_locker *locker,
4675 SET_STATEMENT_ATTR_BODY(locker, m_rows_examined, count);
4678 static void inc_statement_created_tmp_disk_tables_v1(PSI_statement_locker *locker,
4681 INC_STATEMENT_ATTR_BODY(locker, m_created_tmp_disk_tables, count);
4684 static void inc_statement_created_tmp_tables_v1(PSI_statement_locker *locker,
4687 INC_STATEMENT_ATTR_BODY(locker, m_created_tmp_tables, count);
4690 static void inc_statement_select_full_join_v1(PSI_statement_locker *locker,
4693 INC_STATEMENT_ATTR_BODY(locker, m_select_full_join, count);
4696 static void inc_statement_select_full_range_join_v1(PSI_statement_locker *locker,
4699 INC_STATEMENT_ATTR_BODY(locker, m_select_full_range_join, count);
4702 static void inc_statement_select_range_v1(PSI_statement_locker *locker,
4705 INC_STATEMENT_ATTR_BODY(locker, m_select_range, count);
4708 static void inc_statement_select_range_check_v1(PSI_statement_locker *locker,
4711 INC_STATEMENT_ATTR_BODY(locker, m_select_range_check, count);
4714 static void inc_statement_select_scan_v1(PSI_statement_locker *locker,
4717 INC_STATEMENT_ATTR_BODY(locker, m_select_scan, count);
4720 static void inc_statement_sort_merge_passes_v1(PSI_statement_locker *locker,
4723 INC_STATEMENT_ATTR_BODY(locker, m_sort_merge_passes, count);
4726 static void inc_statement_sort_range_v1(PSI_statement_locker *locker,
4729 INC_STATEMENT_ATTR_BODY(locker, m_sort_range, count);
4732 static void inc_statement_sort_rows_v1(PSI_statement_locker *locker,
4735 INC_STATEMENT_ATTR_BODY(locker, m_sort_rows, count);
4738 static void inc_statement_sort_scan_v1(PSI_statement_locker *locker,
4741 INC_STATEMENT_ATTR_BODY(locker, m_sort_scan, count);
4744 static void set_statement_no_index_used_v1(PSI_statement_locker *locker)
4746 SET_STATEMENT_ATTR_BODY(locker, m_no_index_used, 1);
4749 static void set_statement_no_good_index_used_v1(PSI_statement_locker *locker)
4751 SET_STATEMENT_ATTR_BODY(locker, m_no_good_index_used, 1);
4754 static void end_statement_v1(PSI_statement_locker *locker,
void *stmt_da)
4756 PSI_statement_locker_state *state=
reinterpret_cast<PSI_statement_locker_state*
> (locker);
4758 DBUG_ASSERT(state != NULL);
4759 DBUG_ASSERT(da != NULL);
4761 if (state->m_discarded)
4765 DBUG_ASSERT(klass != NULL);
4767 ulonglong timer_end= 0;
4768 ulonglong wait_time= 0;
4769 register uint flags= state->m_flags;
4771 if (flags & STATE_FLAG_TIMED)
4773 timer_end= state->m_timer();
4774 wait_time= timer_end - state->m_timer_start;
4784 PSI_digest_storage *digest_storage= NULL;
4787 if (flags & STATE_FLAG_THREAD)
4790 DBUG_ASSERT(thread != NULL);
4793 stat= & event_name_array[
index];
4797 digest_storage= &state->m_digest_state.m_digest_storage;
4799 digest_stat= find_or_create_digest(thread, digest_storage,
4800 state->m_schema_name,
4801 state->m_schema_name_length);
4804 if (flags & STATE_FLAG_EVENT)
4807 DBUG_ASSERT(pfs != NULL);
4809 switch(da->status())
4818 memcpy(pfs->
m_sqlstate,
"00000", SQLSTATE_LENGTH);
4827 memcpy(pfs->
m_sqlstate, da->get_sqlstate(), SQLSTATE_LENGTH);
4836 if (flags & STATE_FLAG_DIGEST)
4858 if (flags & STATE_FLAG_DIGEST)
4866 digest_storage= &state->m_digest_state.m_digest_storage;
4868 digest_stat= find_or_create_digest(thread, digest_storage,
4869 state->m_schema_name,
4870 state->m_schema_name_length);
4874 event_name_array= global_instr_class_statements_array;
4876 stat= & event_name_array[
index];
4879 if (flags & STATE_FLAG_TIMED)
4882 stat->aggregate_value(wait_time);
4887 stat->aggregate_counted();
4890 stat->m_lock_time+= state->m_lock_time;
4891 stat->m_rows_sent+= state->m_rows_sent;
4892 stat->m_rows_examined+= state->m_rows_examined;
4893 stat->m_created_tmp_disk_tables+= state->m_created_tmp_disk_tables;
4894 stat->m_created_tmp_tables+= state->m_created_tmp_tables;
4895 stat->m_select_full_join+= state->m_select_full_join;
4896 stat->m_select_full_range_join+= state->m_select_full_range_join;
4897 stat->m_select_range+= state->m_select_range;
4898 stat->m_select_range_check+= state->m_select_range_check;
4899 stat->m_select_scan+= state->m_select_scan;
4900 stat->m_sort_merge_passes+= state->m_sort_merge_passes;
4901 stat->m_sort_range+= state->m_sort_range;
4902 stat->m_sort_rows+= state->m_sort_rows;
4903 stat->m_sort_scan+= state->m_sort_scan;
4904 stat->m_no_index_used+= state->m_no_index_used;
4905 stat->m_no_good_index_used+= state->m_no_good_index_used;
4907 if (digest_stat != NULL)
4909 if (flags & STATE_FLAG_TIMED)
4911 digest_stat->aggregate_value(wait_time);
4915 digest_stat->aggregate_counted();
4918 digest_stat->m_lock_time+= state->m_lock_time;
4919 digest_stat->m_rows_sent+= state->m_rows_sent;
4920 digest_stat->m_rows_examined+= state->m_rows_examined;
4921 digest_stat->m_created_tmp_disk_tables+= state->m_created_tmp_disk_tables;
4922 digest_stat->m_created_tmp_tables+= state->m_created_tmp_tables;
4923 digest_stat->m_select_full_join+= state->m_select_full_join;
4924 digest_stat->m_select_full_range_join+= state->m_select_full_range_join;
4925 digest_stat->m_select_range+= state->m_select_range;
4926 digest_stat->m_select_range_check+= state->m_select_range_check;
4927 digest_stat->m_select_scan+= state->m_select_scan;
4928 digest_stat->m_sort_merge_passes+= state->m_sort_merge_passes;
4929 digest_stat->m_sort_range+= state->m_sort_range;
4930 digest_stat->m_sort_rows+= state->m_sort_rows;
4931 digest_stat->m_sort_scan+= state->m_sort_scan;
4932 digest_stat->m_no_index_used+= state->m_no_index_used;
4933 digest_stat->m_no_good_index_used+= state->m_no_good_index_used;
4936 switch (da->status())
4941 stat->m_rows_affected+= da->affected_rows();
4942 stat->m_warning_count+= da->statement_warn_count();
4943 if (digest_stat != NULL)
4945 digest_stat->m_rows_affected+= da->affected_rows();
4946 digest_stat->m_warning_count+= da->statement_warn_count();
4950 stat->m_warning_count+= da->statement_warn_count();
4951 if (digest_stat != NULL)
4953 digest_stat->m_warning_count+= da->statement_warn_count();
4957 stat->m_error_count++;
4958 if (digest_stat != NULL)
4960 digest_stat->m_error_count++;
4972 static void end_socket_wait_v1(PSI_socket_locker *locker,
size_t byte_count)
4974 PSI_socket_locker_state *state=
reinterpret_cast<PSI_socket_locker_state*
> (locker);
4975 DBUG_ASSERT(state != NULL);
4978 DBUG_ASSERT(socket != NULL);
4980 ulonglong timer_end= 0;
4981 ulonglong wait_time= 0;
4983 register uint flags= state->m_flags;
4984 size_t bytes= ((int)byte_count > -1 ? byte_count : 0);
4986 switch (state->m_operation)
4989 case PSI_SOCKET_RECV:
4990 case PSI_SOCKET_RECVFROM:
4991 case PSI_SOCKET_RECVMSG:
4995 case PSI_SOCKET_SEND:
4996 case PSI_SOCKET_SENDTO:
4997 case PSI_SOCKET_SENDMSG:
5001 case PSI_SOCKET_CONNECT:
5002 case PSI_SOCKET_CREATE:
5003 case PSI_SOCKET_BIND:
5004 case PSI_SOCKET_SEEK:
5005 case PSI_SOCKET_OPT:
5006 case PSI_SOCKET_STAT:
5007 case PSI_SOCKET_SHUTDOWN:
5008 case PSI_SOCKET_SELECT:
5009 case PSI_SOCKET_CLOSE:
5019 if (flags & STATE_FLAG_TIMED)
5021 timer_end= state->m_timer();
5022 wait_time= timer_end - state->m_timer_start;
5025 byte_stat->aggregate(wait_time, bytes);
5030 byte_stat->aggregate_counted(bytes);
5034 if (flags & STATE_FLAG_EVENT)
5037 DBUG_ASSERT(thread != NULL);
5039 DBUG_ASSERT(wait != NULL);
5053 static void set_socket_state_v1(PSI_socket *socket, PSI_socket_state state)
5055 DBUG_ASSERT((state == PSI_SOCKET_STATE_IDLE) || (state == PSI_SOCKET_STATE_ACTIVE));
5057 DBUG_ASSERT(pfs != NULL);
5058 DBUG_ASSERT(pfs->
m_idle || (state == PSI_SOCKET_STATE_IDLE));
5059 DBUG_ASSERT(!pfs->
m_idle || (state == PSI_SOCKET_STATE_ACTIVE));
5060 pfs->
m_idle= (state == PSI_SOCKET_STATE_IDLE);
5066 static void set_socket_info_v1(PSI_socket *socket,
5067 const my_socket *fd,
5068 const struct sockaddr *addr,
5072 DBUG_ASSERT(pfs != NULL);
5079 if (likely(addr != NULL && addr_len > 0))
5084 if (unlikely(pfs->
m_addr_len >
sizeof(sockaddr_storage)))
5085 pfs->
m_addr_len=
sizeof(
struct sockaddr_storage);
5095 static void set_socket_thread_owner_v1(PSI_socket *socket)
5098 DBUG_ASSERT(pfs_socket != NULL);
5107 static int set_thread_connect_attrs_v1(
const char *buffer, uint length,
5108 const void *from_cs)
5113 DBUG_ASSERT(buffer != NULL);
5126 if (copy_size == length)
5148 register_statement_v1,
5159 release_table_share_v1,
5160 drop_table_share_v1,
5171 set_thread_account_v1,
5173 set_thread_command_v1,
5174 set_thread_start_time_v1,
5175 set_thread_state_v1,
5178 delete_current_thread_v1,
5180 get_thread_file_name_locker_v1,
5181 get_thread_file_stream_locker_v1,
5182 get_thread_file_descriptor_locker_v1,
5189 start_mutex_wait_v1,
5191 start_rwlock_wait_v1,
5192 end_rwlock_rdwait_v1,
5193 start_rwlock_wait_v1,
5194 end_rwlock_wrwait_v1,
5197 start_table_io_wait_v1,
5198 end_table_io_wait_v1,
5199 start_table_lock_wait_v1,
5200 end_table_lock_wait_v1,
5201 start_file_open_wait_v1,
5202 end_file_open_wait_v1,
5203 end_file_open_wait_and_bind_to_descriptor_v1,
5206 start_file_close_wait_v1,
5207 end_file_close_wait_v1,
5210 get_thread_statement_locker_v1,
5211 refine_statement_v1,
5213 set_statement_text_v1,
5214 set_statement_lock_time_v1,
5215 set_statement_rows_sent_v1,
5216 set_statement_rows_examined_v1,
5217 inc_statement_created_tmp_disk_tables_v1,
5218 inc_statement_created_tmp_tables_v1,
5219 inc_statement_select_full_join_v1,
5220 inc_statement_select_full_range_join_v1,
5221 inc_statement_select_range_v1,
5222 inc_statement_select_range_check_v1,
5223 inc_statement_select_scan_v1,
5224 inc_statement_sort_merge_passes_v1,
5225 inc_statement_sort_range_v1,
5226 inc_statement_sort_rows_v1,
5227 inc_statement_sort_scan_v1,
5228 set_statement_no_index_used_v1,
5229 set_statement_no_good_index_used_v1,
5231 start_socket_wait_v1,
5233 set_socket_state_v1,
5235 set_socket_thread_owner_v1,
5236 pfs_digest_start_v1,
5237 pfs_digest_add_token_v1,
5238 set_thread_connect_attrs_v1,
5241 static void* get_interface(
int version)