diff options
author | Michael Widenius <monty@mariadb.org> | 2018-04-17 00:08:03 +0300 |
---|---|---|
committer | Monty <monty@mariadb.org> | 2018-05-07 00:07:33 +0300 |
commit | 70c1110a29a430b26990861cb753843bb00198dc (patch) | |
tree | d50bf894a520c2086ddd8bd2713432622000f247 | |
parent | 9d6dc39ad9a6c1b0a9dd373607fa1a2f9a24c335 (diff) | |
download | mariadb-git-70c1110a29a430b26990861cb753843bb00198dc.tar.gz |
Optimize performance schema likely/unlikely
Performance schema likely/unlikely assume that performance schema
is enabled by default, which causes a performance degradation for
default installations that doesn't have performance schema enabled.
Fixed by changing the likely/unlikely in PS to assume it's
not enabled. This can be changed by compiling with
-DPSI_ON_BY_DEFAULT
Other changes:
- Added psi_likely/psi_unlikely that is depending on
PSI_ON_BY_DEFAULT. psi_likely() is assumed to be true
if PS is enabled.
- Added likely/unlikely to some PS interface code.
- Moved pfs_enabled to mysys (was initialized but not used before)
- Added "if (pfs_likely(pfs_enabled))" around calls to PS to avoid
an extra call if PS is not enabled.
- Moved checking flag_global_instrumention before other flags
to speed up the case when PS is not enabled.
-rw-r--r-- | include/mysql/psi/mysql_file.h | 707 | ||||
-rw-r--r-- | include/mysql/psi/mysql_idle.h | 2 | ||||
-rw-r--r-- | include/mysql/psi/mysql_socket.h | 30 | ||||
-rw-r--r-- | include/mysql/psi/mysql_statement.h | 18 | ||||
-rw-r--r-- | include/mysql/psi/mysql_table.h | 8 | ||||
-rw-r--r-- | include/mysql/psi/mysql_thread.h | 38 | ||||
-rw-r--r-- | include/mysql/psi/psi.h | 16 | ||||
-rw-r--r-- | include/mysql/psi/psi_abi_v1.h.pp | 1 | ||||
-rw-r--r-- | include/mysql/psi/psi_abi_v2.h.pp | 1 | ||||
-rw-r--r-- | mysys/file_logger.c | 2 | ||||
-rw-r--r-- | mysys/my_likely.c | 4 | ||||
-rw-r--r-- | mysys/psi_noop.c | 7 | ||||
-rw-r--r-- | storage/perfschema/pfs.cc | 46 | ||||
-rw-r--r-- | storage/perfschema/pfs_instr_class.cc | 7 |
14 files changed, 486 insertions, 401 deletions
diff --git a/include/mysql/psi/mysql_file.h b/include/mysql/psi/mysql_file.h index 801c26086f5..f793aa6237c 100644 --- a/include/mysql/psi/mysql_file.h +++ b/include/mysql/psi/mysql_file.h @@ -529,16 +529,18 @@ inline_mysql_file_fgets( { char *result; #ifdef HAVE_PSI_FILE_INTERFACE - struct PSI_file_locker *locker; - PSI_file_locker_state state; - locker= PSI_FILE_CALL(get_thread_file_stream_locker) - (&state, file->m_psi, PSI_FILE_READ); - if (likely(locker != NULL)) + if (psi_likely(pfs_enabled)) { - PSI_FILE_CALL(start_file_wait)(locker, (size_t) size, src_file, src_line); - result= fgets(str, size, file->m_file); - PSI_FILE_CALL(end_file_wait)(locker, result ? strlen(result) : 0); - return result; + struct PSI_file_locker *locker; + PSI_file_locker_state state; + locker= PSI_FILE_CALL(get_thread_file_stream_locker) (&state, file->m_psi, PSI_FILE_READ); + if (likely(locker != NULL)) + { + PSI_FILE_CALL(start_file_wait)(locker, (size_t) size, src_file, src_line); + result= fgets(str, size, file->m_file); + PSI_FILE_CALL(end_file_wait)(locker, result ? strlen(result) : 0); + return result; + } } #endif @@ -555,16 +557,18 @@ inline_mysql_file_fgetc( { int result; #ifdef HAVE_PSI_FILE_INTERFACE - struct PSI_file_locker *locker; - PSI_file_locker_state state; - locker= PSI_FILE_CALL(get_thread_file_stream_locker) - (&state, file->m_psi, PSI_FILE_READ); - if (likely(locker != NULL)) + if (psi_likely(pfs_enabled)) { - PSI_FILE_CALL(start_file_wait)(locker, (size_t) 1, src_file, src_line); - result= fgetc(file->m_file); - PSI_FILE_CALL(end_file_wait)(locker, (size_t) 1); - return result; + struct PSI_file_locker *locker; + PSI_file_locker_state state; + locker= PSI_FILE_CALL(get_thread_file_stream_locker)(&state, file->m_psi, PSI_FILE_READ); + if (likely(locker != NULL)) + { + PSI_FILE_CALL(start_file_wait)(locker, (size_t) 1, src_file, src_line); + result= fgetc(file->m_file); + PSI_FILE_CALL(end_file_wait)(locker, (size_t) 1); + return result; + } } #endif @@ -581,18 +585,20 @@ inline_mysql_file_fputs( { int result; #ifdef HAVE_PSI_FILE_INTERFACE - struct PSI_file_locker *locker; - PSI_file_locker_state state; - size_t bytes; - locker= PSI_FILE_CALL(get_thread_file_stream_locker) - (&state, file->m_psi, PSI_FILE_WRITE); - if (likely(locker != NULL)) + if (psi_likely(pfs_enabled)) { - bytes= str ? strlen(str) : 0; - PSI_FILE_CALL(start_file_wait)(locker, bytes, src_file, src_line); - result= fputs(str, file->m_file); - PSI_FILE_CALL(end_file_wait)(locker, bytes); - return result; + struct PSI_file_locker *locker; + PSI_file_locker_state state; + size_t bytes; + locker= PSI_FILE_CALL(get_thread_file_stream_locker) (&state, file->m_psi, PSI_FILE_WRITE); + if (likely(locker != NULL)) + { + bytes= str ? strlen(str) : 0; + PSI_FILE_CALL(start_file_wait)(locker, bytes, src_file, src_line); + result= fputs(str, file->m_file); + PSI_FILE_CALL(end_file_wait)(locker, bytes); + return result; + } } #endif @@ -609,16 +615,18 @@ inline_mysql_file_fputc( { int result; #ifdef HAVE_PSI_FILE_INTERFACE - struct PSI_file_locker *locker; - PSI_file_locker_state state; - locker= PSI_FILE_CALL(get_thread_file_stream_locker) - (&state, file->m_psi, PSI_FILE_WRITE); - if (likely(locker != NULL)) + if (psi_likely(pfs_enabled)) { - PSI_FILE_CALL(start_file_wait)(locker, (size_t) 1, src_file, src_line); - result= fputc(c, file->m_file); - PSI_FILE_CALL(end_file_wait)(locker, (size_t) 1); - return result; + struct PSI_file_locker *locker; + PSI_file_locker_state state; + locker= PSI_FILE_CALL(get_thread_file_stream_locker) (&state, file->m_psi, PSI_FILE_WRITE); + if (likely(locker != NULL)) + { + PSI_FILE_CALL(start_file_wait)(locker, (size_t) 1, src_file, src_line); + result= fputc(c, file->m_file); + PSI_FILE_CALL(end_file_wait)(locker, (size_t) 1); + return result; + } } #endif @@ -635,18 +643,20 @@ inline_mysql_file_fprintf(MYSQL_FILE *file, const char *format, ...) int result; va_list args; #ifdef HAVE_PSI_FILE_INTERFACE - struct PSI_file_locker *locker; - PSI_file_locker_state state; - locker= PSI_FILE_CALL(get_thread_file_stream_locker) - (&state, file->m_psi, PSI_FILE_WRITE); - if (likely(locker != NULL)) + if (psi_likely(pfs_enabled)) { - PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, __FILE__, __LINE__); - va_start(args, format); - result= vfprintf(file->m_file, format, args); - va_end(args); - PSI_FILE_CALL(end_file_wait)(locker, (size_t) result); - return result; + struct PSI_file_locker *locker; + PSI_file_locker_state state; + locker= PSI_FILE_CALL(get_thread_file_stream_locker) (&state, file->m_psi, PSI_FILE_WRITE); + if (likely(locker != NULL)) + { + PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, __FILE__, __LINE__); + va_start(args, format); + result= vfprintf(file->m_file, format, args); + va_end(args); + PSI_FILE_CALL(end_file_wait)(locker, (size_t) result); + return result; + } } #endif @@ -665,16 +675,18 @@ inline_mysql_file_vfprintf( { int result; #ifdef HAVE_PSI_FILE_INTERFACE - struct PSI_file_locker *locker; - PSI_file_locker_state state; - locker= PSI_FILE_CALL(get_thread_file_stream_locker) - (&state, file->m_psi, PSI_FILE_WRITE); - if (likely(locker != NULL)) + if (psi_likely(pfs_enabled)) { - PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line); - result= vfprintf(file->m_file, format, args); - PSI_FILE_CALL(end_file_wait)(locker, (size_t) result); - return result; + struct PSI_file_locker *locker; + PSI_file_locker_state state; + locker= PSI_FILE_CALL(get_thread_file_stream_locker) (&state, file->m_psi, PSI_FILE_WRITE); + if (likely(locker != NULL)) + { + PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line); + result= vfprintf(file->m_file, format, args); + PSI_FILE_CALL(end_file_wait)(locker, (size_t) result); + return result; + } } #endif @@ -691,16 +703,18 @@ inline_mysql_file_fflush( { int result; #ifdef HAVE_PSI_FILE_INTERFACE - struct PSI_file_locker *locker; - PSI_file_locker_state state; - locker= PSI_FILE_CALL(get_thread_file_stream_locker) - (&state, file->m_psi, PSI_FILE_FLUSH); - if (likely(locker != NULL)) + if (psi_likely(pfs_enabled)) { - PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line); - result= fflush(file->m_file); - PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0); - return result; + struct PSI_file_locker *locker; + PSI_file_locker_state state; + locker= PSI_FILE_CALL(get_thread_file_stream_locker)(&state, file->m_psi, PSI_FILE_FLUSH); + if (likely(locker != NULL)) + { + PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line); + result= fflush(file->m_file); + PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0); + return result; + } } #endif @@ -723,16 +737,18 @@ inline_mysql_file_fstat( { int result; #ifdef HAVE_PSI_FILE_INTERFACE - struct PSI_file_locker *locker; - PSI_file_locker_state state; - locker= PSI_FILE_CALL(get_thread_file_descriptor_locker) - (&state, filenr, PSI_FILE_FSTAT); - if (likely(locker != NULL)) + if (psi_likely(pfs_enabled)) { - PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line); - result= my_fstat(filenr, stat_area, flags); - PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0); - return result; + struct PSI_file_locker *locker; + PSI_file_locker_state state; + locker= PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, filenr, PSI_FILE_FSTAT); + if (likely(locker != NULL)) + { + PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line); + result= my_fstat(filenr, stat_area, flags); + PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0); + return result; + } } #endif @@ -749,16 +765,18 @@ inline_mysql_file_stat( { MY_STAT *result; #ifdef HAVE_PSI_FILE_INTERFACE - struct PSI_file_locker *locker; - PSI_file_locker_state state; - locker= PSI_FILE_CALL(get_thread_file_name_locker) - (&state, key, PSI_FILE_STAT, path, &locker); - if (likely(locker != NULL)) + if (psi_likely(pfs_enabled)) { - PSI_FILE_CALL(start_file_open_wait)(locker, src_file, src_line); - result= my_stat(path, stat_area, flags); - PSI_FILE_CALL(end_file_open_wait)(locker, result); - return result; + struct PSI_file_locker *locker; + PSI_file_locker_state state; + locker= PSI_FILE_CALL(get_thread_file_name_locker)(&state, key, PSI_FILE_STAT, path, &locker); + if (likely(locker != NULL)) + { + PSI_FILE_CALL(start_file_open_wait)(locker, src_file, src_line); + result= my_stat(path, stat_area, flags); + PSI_FILE_CALL(end_file_open_wait)(locker, result); + return result; + } } #endif @@ -775,17 +793,19 @@ inline_mysql_file_chsize( { int result; #ifdef HAVE_PSI_FILE_INTERFACE - struct PSI_file_locker *locker; - PSI_file_locker_state state; - locker= PSI_FILE_CALL(get_thread_file_descriptor_locker) - (&state, file, PSI_FILE_CHSIZE); - if (likely(locker != NULL)) + if (psi_likely(pfs_enabled)) { - PSI_FILE_CALL(start_file_wait)(locker, (size_t) newlength, src_file, - src_line); - result= my_chsize(file, newlength, filler, flags); - PSI_FILE_CALL(end_file_wait)(locker, (size_t) newlength); - return result; + struct PSI_file_locker *locker; + PSI_file_locker_state state; + locker= PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, file, PSI_FILE_CHSIZE); + if (likely(locker != NULL)) + { + PSI_FILE_CALL(start_file_wait)(locker, (size_t) newlength, src_file, + src_line); + result= my_chsize(file, newlength, filler, flags); + PSI_FILE_CALL(end_file_wait)(locker, (size_t) newlength); + return result; + } } #endif @@ -805,22 +825,24 @@ inline_mysql_file_fopen( if (likely(that != NULL)) { #ifdef HAVE_PSI_FILE_INTERFACE - struct PSI_file_locker *locker; - PSI_file_locker_state state; - locker= PSI_FILE_CALL(get_thread_file_name_locker) - (&state, key, PSI_FILE_STREAM_OPEN, filename, that); - if (likely(locker != NULL)) + if (psi_likely(pfs_enabled)) { - PSI_FILE_CALL(start_file_open_wait) - (locker, src_file, src_line); - that->m_file= my_fopen(filename, flags, myFlags); - that->m_psi= PSI_FILE_CALL(end_file_open_wait)(locker, that->m_file); - if (unlikely(that->m_file == NULL)) + struct PSI_file_locker *locker; + PSI_file_locker_state state; + locker= PSI_FILE_CALL(get_thread_file_name_locker)(&state, key, PSI_FILE_STREAM_OPEN, + filename, that); + if (likely(locker != NULL)) { - my_free(that); - return NULL; + PSI_FILE_CALL(start_file_open_wait)(locker, src_file, src_line); + that->m_file= my_fopen(filename, flags, myFlags); + that->m_psi= PSI_FILE_CALL(end_file_open_wait)(locker, that->m_file); + if (unlikely(that->m_file == NULL)) + { + my_free(that); + return NULL; + } + return that; } - return that; } #endif @@ -846,17 +868,20 @@ inline_mysql_file_fclose( if (likely(file != NULL)) { #ifdef HAVE_PSI_FILE_INTERFACE - struct PSI_file_locker *locker; - PSI_file_locker_state state; - locker= PSI_FILE_CALL(get_thread_file_stream_locker) - (&state, file->m_psi, PSI_FILE_STREAM_CLOSE); - if (likely(locker != NULL)) + if (psi_likely(pfs_enabled)) { - PSI_FILE_CALL(start_file_close_wait)(locker, src_file, src_line); - result= my_fclose(file->m_file, flags); - PSI_FILE_CALL(end_file_close_wait)(locker, result); - my_free(file); - return result; + struct PSI_file_locker *locker; + PSI_file_locker_state state; + locker= PSI_FILE_CALL(get_thread_file_stream_locker)(&state, file->m_psi, + PSI_FILE_STREAM_CLOSE); + if (likely(locker != NULL)) + { + PSI_FILE_CALL(start_file_close_wait)(locker, src_file, src_line); + result= my_fclose(file->m_file, flags); + PSI_FILE_CALL(end_file_close_wait)(locker, result); + my_free(file); + return result; + } } #endif @@ -875,21 +900,23 @@ inline_mysql_file_fread( { size_t result; #ifdef HAVE_PSI_FILE_INTERFACE - struct PSI_file_locker *locker; - PSI_file_locker_state state; - size_t bytes_read; - locker= PSI_FILE_CALL(get_thread_file_stream_locker) - (&state, file->m_psi, PSI_FILE_READ); - if (likely(locker != NULL)) + if (psi_likely(pfs_enabled)) { - PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line); - result= my_fread(file->m_file, buffer, count, flags); - if (flags & (MY_NABP | MY_FNABP)) - bytes_read= (result == 0) ? count : 0; - else - bytes_read= (result != MY_FILE_ERROR) ? result : 0; - PSI_FILE_CALL(end_file_wait)(locker, bytes_read); - return result; + struct PSI_file_locker *locker; + PSI_file_locker_state state; + size_t bytes_read; + locker= PSI_FILE_CALL(get_thread_file_stream_locker)(&state, file->m_psi, PSI_FILE_READ); + if (likely(locker != NULL)) + { + PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line); + result= my_fread(file->m_file, buffer, count, flags); + if (flags & (MY_NABP | MY_FNABP)) + bytes_read= (result == 0) ? count : 0; + else + bytes_read= (result != MY_FILE_ERROR) ? result : 0; + PSI_FILE_CALL(end_file_wait)(locker, bytes_read); + return result; + } } #endif @@ -906,21 +933,23 @@ inline_mysql_file_fwrite( { size_t result; #ifdef HAVE_PSI_FILE_INTERFACE - struct PSI_file_locker *locker; - PSI_file_locker_state state; - size_t bytes_written; - locker= PSI_FILE_CALL(get_thread_file_stream_locker) - (&state, file->m_psi, PSI_FILE_WRITE); - if (likely(locker != NULL)) + if (psi_likely(pfs_enabled)) { - PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line); - result= my_fwrite(file->m_file, buffer, count, flags); - if (flags & (MY_NABP | MY_FNABP)) - bytes_written= (result == 0) ? count : 0; - else - bytes_written= (result != MY_FILE_ERROR) ? result : 0; - PSI_FILE_CALL(end_file_wait)(locker, bytes_written); - return result; + struct PSI_file_locker *locker; + PSI_file_locker_state state; + size_t bytes_written; + locker= PSI_FILE_CALL(get_thread_file_stream_locker)(&state, file->m_psi, PSI_FILE_WRITE); + if (likely(locker != NULL)) + { + PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line); + result= my_fwrite(file->m_file, buffer, count, flags); + if (flags & (MY_NABP | MY_FNABP)) + bytes_written= (result == 0) ? count : 0; + else + bytes_written= (result != MY_FILE_ERROR) ? result : 0; + PSI_FILE_CALL(end_file_wait)(locker, bytes_written); + return result; + } } #endif @@ -937,16 +966,18 @@ inline_mysql_file_fseek( { my_off_t result; #ifdef HAVE_PSI_FILE_INTERFACE - struct PSI_file_locker *locker; - PSI_file_locker_state state; - locker= PSI_FILE_CALL(get_thread_file_stream_locker) - (&state, file->m_psi, PSI_FILE_SEEK); - if (likely(locker != NULL)) + if (psi_likely(pfs_enabled)) { - PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line); - result= my_fseek(file->m_file, pos, whence, flags); - PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0); - return result; + struct PSI_file_locker *locker; + PSI_file_locker_state state; + locker= PSI_FILE_CALL(get_thread_file_stream_locker)(&state, file->m_psi, PSI_FILE_SEEK); + if (likely(locker != NULL)) + { + PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line); + result= my_fseek(file->m_file, pos, whence, flags); + PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0); + return result; + } } #endif @@ -963,16 +994,18 @@ inline_mysql_file_ftell( { my_off_t result; #ifdef HAVE_PSI_FILE_INTERFACE - struct PSI_file_locker *locker; - PSI_file_locker_state state; - locker= PSI_FILE_CALL(get_thread_file_stream_locker) - (&state, file->m_psi, PSI_FILE_TELL); - if (likely(locker != NULL)) + if (psi_likely(pfs_enabled)) { - PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line); - result= my_ftell(file->m_file, flags); - PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0); - return result; + struct PSI_file_locker *locker; + PSI_file_locker_state state; + locker= PSI_FILE_CALL(get_thread_file_stream_locker)(&state, file->m_psi, PSI_FILE_TELL); + if (likely(locker != NULL)) + { + PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line); + result= my_ftell(file->m_file, flags); + PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0); + return result; + } } #endif @@ -989,16 +1022,19 @@ inline_mysql_file_create( { File file; #ifdef HAVE_PSI_FILE_INTERFACE - struct PSI_file_locker *locker; - PSI_file_locker_state state; - locker= PSI_FILE_CALL(get_thread_file_name_locker) - (&state, key, PSI_FILE_CREATE, filename, &locker); - if (likely(locker != NULL)) + if (psi_likely(pfs_enabled)) { - PSI_FILE_CALL(start_file_open_wait)(locker, src_file, src_line); - file= my_create(filename, create_flags, access_flags, myFlags); - PSI_FILE_CALL(end_file_open_wait_and_bind_to_descriptor)(locker, file); - return file; + struct PSI_file_locker *locker; + PSI_file_locker_state state; + locker= PSI_FILE_CALL(get_thread_file_name_locker)(&state, key, PSI_FILE_CREATE, filename, + &locker); + if (likely(locker != NULL)) + { + PSI_FILE_CALL(start_file_open_wait)(locker, src_file, src_line); + file= my_create(filename, create_flags, access_flags, myFlags); + PSI_FILE_CALL(end_file_open_wait_and_bind_to_descriptor)(locker, file); + return file; + } } #endif @@ -1035,16 +1071,19 @@ inline_mysql_file_open( { File file; #ifdef HAVE_PSI_FILE_INTERFACE - struct PSI_file_locker *locker; - PSI_file_locker_state state; - locker= PSI_FILE_CALL(get_thread_file_name_locker) - (&state, key, PSI_FILE_OPEN, filename, &locker); - if (likely(locker != NULL)) + if (psi_likely(pfs_enabled)) { - PSI_FILE_CALL(start_file_open_wait)(locker, src_file, src_line); - file= my_open(filename, flags, myFlags); - PSI_FILE_CALL(end_file_open_wait_and_bind_to_descriptor)(locker, file); - return file; + struct PSI_file_locker *locker; + PSI_file_locker_state state; + locker= PSI_FILE_CALL(get_thread_file_name_locker)(&state, key, PSI_FILE_OPEN, filename, + &locker); + if (likely(locker != NULL)) + { + PSI_FILE_CALL(start_file_open_wait)(locker, src_file, src_line); + file= my_open(filename, flags, myFlags); + PSI_FILE_CALL(end_file_open_wait_and_bind_to_descriptor)(locker, file); + return file; + } } #endif @@ -1061,16 +1100,18 @@ inline_mysql_file_close( { int result; #ifdef HAVE_PSI_FILE_INTERFACE - struct PSI_file_locker *locker; - PSI_file_locker_state state; - locker= PSI_FILE_CALL(get_thread_file_descriptor_locker) - (&state, file, PSI_FILE_CLOSE); - if (likely(locker != NULL)) + if (psi_likely(pfs_enabled)) { - PSI_FILE_CALL(start_file_close_wait)(locker, src_file, src_line); - result= my_close(file, flags); - PSI_FILE_CALL(end_file_close_wait)(locker, result); - return result; + struct PSI_file_locker *locker; + PSI_file_locker_state state; + locker= PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, file, PSI_FILE_CLOSE); + if (likely(locker != NULL)) + { + PSI_FILE_CALL(start_file_close_wait)(locker, src_file, src_line); + result= my_close(file, flags); + PSI_FILE_CALL(end_file_close_wait)(locker, result); + return result; + } } #endif @@ -1087,21 +1128,23 @@ inline_mysql_file_read( { size_t result; #ifdef HAVE_PSI_FILE_INTERFACE - struct PSI_file_locker *locker; - PSI_file_locker_state state; - size_t bytes_read; - locker= PSI_FILE_CALL(get_thread_file_descriptor_locker) - (&state, file, PSI_FILE_READ); - if (likely(locker != NULL)) + if (psi_likely(pfs_enabled)) { - PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line); - result= my_read(file, buffer, count, flags); - if (flags & (MY_NABP | MY_FNABP)) - bytes_read= (result == 0) ? count : 0; - else - bytes_read= (result != MY_FILE_ERROR) ? result : 0; - PSI_FILE_CALL(end_file_wait)(locker, bytes_read); - return result; + struct PSI_file_locker *locker; + PSI_file_locker_state state; + size_t bytes_read; + locker= PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, file, PSI_FILE_READ); + if (likely(locker != NULL)) + { + PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line); + result= my_read(file, buffer, count, flags); + if (flags & (MY_NABP | MY_FNABP)) + bytes_read= (result == 0) ? count : 0; + else + bytes_read= (result != MY_FILE_ERROR) ? result : 0; + PSI_FILE_CALL(end_file_wait)(locker, bytes_read); + return result; + } } #endif @@ -1118,21 +1161,23 @@ inline_mysql_file_write( { size_t result; #ifdef HAVE_PSI_FILE_INTERFACE - struct PSI_file_locker *locker; - PSI_file_locker_state state; - size_t bytes_written; - locker= PSI_FILE_CALL(get_thread_file_descriptor_locker) - (&state, file, PSI_FILE_WRITE); - if (likely(locker != NULL)) + if (psi_likely(pfs_enabled)) { - PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line); - result= my_write(file, buffer, count, flags); - if (flags & (MY_NABP | MY_FNABP)) - bytes_written= (result == 0) ? count : 0; - else - bytes_written= (result != MY_FILE_ERROR) ? result : 0; - PSI_FILE_CALL(end_file_wait)(locker, bytes_written); - return result; + struct PSI_file_locker *locker; + PSI_file_locker_state state; + size_t bytes_written; + locker= PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, file, PSI_FILE_WRITE); + if (likely(locker != NULL)) + { + PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line); + result= my_write(file, buffer, count, flags); + if (flags & (MY_NABP | MY_FNABP)) + bytes_written= (result == 0) ? count : 0; + else + bytes_written= (result != MY_FILE_ERROR) ? result : 0; + PSI_FILE_CALL(end_file_wait)(locker, bytes_written); + return result; + } } #endif @@ -1149,21 +1194,23 @@ inline_mysql_file_pread( { size_t result; #ifdef HAVE_PSI_FILE_INTERFACE - struct PSI_file_locker *locker; - PSI_file_locker_state state; - size_t bytes_read; - locker= PSI_FILE_CALL(get_thread_file_descriptor_locker) - (&state, file, PSI_FILE_READ); - if (likely(locker != NULL)) + if (psi_likely(pfs_enabled)) { - PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line); - result= my_pread(file, buffer, count, offset, flags); - if (flags & (MY_NABP | MY_FNABP)) - bytes_read= (result == 0) ? count : 0; - else - bytes_read= (result != MY_FILE_ERROR) ? result : 0; - PSI_FILE_CALL(end_file_wait)(locker, bytes_read); - return result; + struct PSI_file_locker *locker; + PSI_file_locker_state state; + size_t bytes_read; + locker= PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, file, PSI_FILE_READ); + if (likely(locker != NULL)) + { + PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line); + result= my_pread(file, buffer, count, offset, flags); + if (flags & (MY_NABP | MY_FNABP)) + bytes_read= (result == 0) ? count : 0; + else + bytes_read= (result != MY_FILE_ERROR) ? result : 0; + PSI_FILE_CALL(end_file_wait)(locker, bytes_read); + return result; + } } #endif @@ -1180,21 +1227,23 @@ inline_mysql_file_pwrite( { size_t result; #ifdef HAVE_PSI_FILE_INTERFACE - struct PSI_file_locker *locker; - PSI_file_locker_state state; - size_t bytes_written; - locker= PSI_FILE_CALL(get_thread_file_descriptor_locker) - (&state, file, PSI_FILE_WRITE); - if (likely(locker != NULL)) + if (psi_likely(pfs_enabled)) { - PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line); - result= my_pwrite(file, buffer, count, offset, flags); - if (flags & (MY_NABP | MY_FNABP)) - bytes_written= (result == 0) ? count : 0; - else - bytes_written= (result != MY_FILE_ERROR) ? result : 0; - PSI_FILE_CALL(end_file_wait)(locker, bytes_written); - return result; + struct PSI_file_locker *locker; + PSI_file_locker_state state; + size_t bytes_written; + locker= PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, file, PSI_FILE_WRITE); + if (likely(locker != NULL)) + { + PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line); + result= my_pwrite(file, buffer, count, offset, flags); + if (flags & (MY_NABP | MY_FNABP)) + bytes_written= (result == 0) ? count : 0; + else + bytes_written= (result != MY_FILE_ERROR) ? result : 0; + PSI_FILE_CALL(end_file_wait)(locker, bytes_written); + return result; + } } #endif @@ -1211,16 +1260,18 @@ inline_mysql_file_seek( { my_off_t result; #ifdef HAVE_PSI_FILE_INTERFACE - struct PSI_file_locker *locker; - PSI_file_locker_state state; - locker= PSI_FILE_CALL(get_thread_file_descriptor_locker) - (&state, file, PSI_FILE_SEEK); - if (likely(locker != NULL)) + if (psi_likely(pfs_enabled)) { - PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line); - result= my_seek(file, pos, whence, flags); - PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0); - return result; + struct PSI_file_locker *locker; + PSI_file_locker_state state; + locker= PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, file, PSI_FILE_SEEK); + if (likely(locker != NULL)) + { + PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line); + result= my_seek(file, pos, whence, flags); + PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0); + return result; + } } #endif @@ -1237,16 +1288,18 @@ inline_mysql_file_tell( { my_off_t result; #ifdef HAVE_PSI_FILE_INTERFACE - struct PSI_file_locker *locker; - PSI_file_locker_state state; - locker= PSI_FILE_CALL(get_thread_file_descriptor_locker) - (&state, file, PSI_FILE_TELL); - if (likely(locker != NULL)) + if (psi_likely(pfs_enabled)) { - PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line); - result= my_tell(file, flags); - PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0); - return result; + struct PSI_file_locker *locker; + PSI_file_locker_state state; + locker= PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, file, PSI_FILE_TELL); + if (likely(locker != NULL)) + { + PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line); + result= my_tell(file, flags); + PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0); + return result; + } } #endif @@ -1263,16 +1316,18 @@ inline_mysql_file_delete( { int result; #ifdef HAVE_PSI_FILE_INTERFACE - struct PSI_file_locker *locker; - PSI_file_locker_state state; - locker= PSI_FILE_CALL(get_thread_file_name_locker) - (&state, key, PSI_FILE_DELETE, name, &locker); - if (likely(locker != NULL)) + if (psi_likely(pfs_enabled)) { - PSI_FILE_CALL(start_file_close_wait)(locker, src_file, src_line); - result= my_delete(name, flags); - PSI_FILE_CALL(end_file_close_wait)(locker, result); - return result; + struct PSI_file_locker *locker; + PSI_file_locker_state state; + locker= PSI_FILE_CALL(get_thread_file_name_locker)(&state, key, PSI_FILE_DELETE, name, &locker); + if (likely(locker != NULL)) + { + PSI_FILE_CALL(start_file_close_wait)(locker, src_file, src_line); + result= my_delete(name, flags); + PSI_FILE_CALL(end_file_close_wait)(locker, result); + return result; + } } #endif @@ -1289,16 +1344,18 @@ inline_mysql_file_rename( { int result; #ifdef HAVE_PSI_FILE_INTERFACE - struct PSI_file_locker *locker; - PSI_file_locker_state state; - locker= PSI_FILE_CALL(get_thread_file_name_locker) - (&state, key, PSI_FILE_RENAME, to, &locker); - if (likely(locker != NULL)) + if (psi_likely(pfs_enabled)) { - PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line); - result= my_rename(from, to, flags); - PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0); - return result; + struct PSI_file_locker *locker; + PSI_file_locker_state state; + locker= PSI_FILE_CALL(get_thread_file_name_locker)(&state, key, PSI_FILE_RENAME, to, &locker); + if (likely(locker != NULL)) + { + PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line); + result= my_rename(from, to, flags); + PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0); + return result; + } } #endif @@ -1317,17 +1374,20 @@ inline_mysql_file_create_with_symlink( { File file; #ifdef HAVE_PSI_FILE_INTERFACE - struct PSI_file_locker *locker; - PSI_file_locker_state state; - locker= PSI_FILE_CALL(get_thread_file_name_locker) - (&state, key, PSI_FILE_CREATE, filename, &locker); - if (likely(locker != NULL)) + if (psi_likely(pfs_enabled)) { - PSI_FILE_CALL(start_file_open_wait)(locker, src_file, src_line); - file= my_create_with_symlink(linkname, filename, create_flags, access_flags, - flags); - PSI_FILE_CALL(end_file_open_wait_and_bind_to_descriptor)(locker, file); - return file; + struct PSI_file_locker *locker; + PSI_file_locker_state state; + locker= PSI_FILE_CALL(get_thread_file_name_locker)(&state, key, PSI_FILE_CREATE, filename, + &locker); + if (likely(locker != NULL)) + { + PSI_FILE_CALL(start_file_open_wait)(locker, src_file, src_line); + file= my_create_with_symlink(linkname, filename, create_flags, access_flags, + flags); + PSI_FILE_CALL(end_file_open_wait_and_bind_to_descriptor)(locker, file); + return file; + } } #endif @@ -1348,16 +1408,19 @@ inline_mysql_file_delete_with_symlink( char buf[FN_REFLEN]; char *fullname= fn_format(buf, name, "", ext, MY_UNPACK_FILENAME | MY_APPEND_EXT); #ifdef HAVE_PSI_FILE_INTERFACE - struct PSI_file_locker *locker; - PSI_file_locker_state state; - locker= PSI_FILE_CALL(get_thread_file_name_locker) - (&state, key, PSI_FILE_DELETE, fullname, &locker); - if (likely(locker != NULL)) + if (psi_likely(pfs_enabled)) { - PSI_FILE_CALL(start_file_close_wait)(locker, src_file, src_line); - result= my_handler_delete_with_symlink(fullname, flags); - PSI_FILE_CALL(end_file_close_wait)(locker, result); - return result; + struct PSI_file_locker *locker; + PSI_file_locker_state state; + locker= PSI_FILE_CALL(get_thread_file_name_locker)(&state, key, PSI_FILE_DELETE, fullname, + &locker); + if (likely(locker != NULL)) + { + PSI_FILE_CALL(start_file_close_wait)(locker, src_file, src_line); + result= my_handler_delete_with_symlink(fullname, flags); + PSI_FILE_CALL(end_file_close_wait)(locker, result); + return result; + } } #endif @@ -1375,16 +1438,18 @@ inline_mysql_file_rename_with_symlink( { int result; #ifdef HAVE_PSI_FILE_INTERFACE - struct PSI_file_locker *locker; - PSI_file_locker_state state; - locker= PSI_FILE_CALL(get_thread_file_name_locker) - (&state, key, PSI_FILE_RENAME, to, &locker); - if (likely(locker != NULL)) + if (psi_likely(pfs_enabled)) { - PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line); - result= my_rename_with_symlink(from, to, flags); - PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0); - return result; + struct PSI_file_locker *locker; + PSI_file_locker_state state; + locker= PSI_FILE_CALL(get_thread_file_name_locker)(&state, key, PSI_FILE_RENAME, to, &locker); + if (likely(locker != NULL)) + { + PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line); + result= my_rename_with_symlink(from, to, flags); + PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0); + return result; + } } #endif @@ -1401,16 +1466,18 @@ inline_mysql_file_sync( { int result= 0; #ifdef HAVE_PSI_FILE_INTERFACE - struct PSI_file_locker *locker; - PSI_file_locker_state state; - locker= PSI_FILE_CALL(get_thread_file_descriptor_locker) - (&state, fd, PSI_FILE_SYNC); - if (likely(locker != NULL)) + if (psi_likely(pfs_enabled)) { - PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line); - result= my_sync(fd, flags); - PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0); - return result; + struct PSI_file_locker *locker; + PSI_file_locker_state state; + locker= PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, fd, PSI_FILE_SYNC); + if (likely(locker != NULL)) + { + PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line); + result= my_sync(fd, flags); + PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0); + return result; + } } #endif diff --git a/include/mysql/psi/mysql_idle.h b/include/mysql/psi/mysql_idle.h index b623edce108..16c9de7ff55 100644 --- a/include/mysql/psi/mysql_idle.h +++ b/include/mysql/psi/mysql_idle.h @@ -82,7 +82,7 @@ inline_mysql_start_idle_wait(PSI_idle_locker_state *state, static inline void inline_mysql_end_idle_wait(struct PSI_idle_locker *locker) { - if (likely(locker != NULL)) + if (psi_likely(locker != NULL)) PSI_IDLE_CALL(end_idle_wait)(locker); } #endif diff --git a/include/mysql/psi/mysql_socket.h b/include/mysql/psi/mysql_socket.h index 2bbe4c39849..3baabb6e57d 100644 --- a/include/mysql/psi/mysql_socket.h +++ b/include/mysql/psi/mysql_socket.h @@ -245,7 +245,7 @@ inline_mysql_start_socket_wait(PSI_socket_locker_state *state, const char *src_file, uint src_line) { struct PSI_socket_locker *locker; - if (mysql_socket.m_psi != NULL) + if (psi_likely(mysql_socket.m_psi != NULL)) { locker= PSI_SOCKET_CALL(start_socket_wait) (state, mysql_socket.m_psi, op, byte_count, src_file, src_line); @@ -262,7 +262,7 @@ inline_mysql_start_socket_wait(PSI_socket_locker_state *state, static inline void inline_mysql_end_socket_wait(struct PSI_socket_locker *locker, size_t byte_count) { - if (locker != NULL) + if (psi_likely(locker != NULL)) PSI_SOCKET_CALL(end_socket_wait)(locker, byte_count); } @@ -577,7 +577,7 @@ inline_mysql_socket_bind int result; #ifdef HAVE_PSI_SOCKET_INTERFACE - if (mysql_socket.m_psi != NULL) + if (psi_likely(mysql_socket.m_psi != NULL)) { /* Instrumentation start */ PSI_socket_locker_state state; @@ -617,7 +617,7 @@ inline_mysql_socket_getsockname int result; #ifdef HAVE_PSI_SOCKET_INTERFACE - if (mysql_socket.m_psi != NULL) + if (psi_likely(mysql_socket.m_psi != NULL)) { /* Instrumentation start */ PSI_socket_locker *locker; @@ -655,7 +655,7 @@ inline_mysql_socket_connect int result; #ifdef HAVE_PSI_SOCKET_INTERFACE - if (mysql_socket.m_psi != NULL) + if (psi_likely(mysql_socket.m_psi != NULL)) { /* Instrumentation start */ PSI_socket_locker *locker; @@ -693,7 +693,7 @@ inline_mysql_socket_getpeername int result; #ifdef HAVE_PSI_SOCKET_INTERFACE - if (mysql_socket.m_psi != NULL) + if (psi_likely(mysql_socket.m_psi != NULL)) { /* Instrumentation start */ PSI_socket_locker *locker; @@ -731,7 +731,7 @@ inline_mysql_socket_send ssize_t result; #ifdef HAVE_PSI_SOCKET_INTERFACE - if (mysql_socket.m_psi != NULL) + if (psi_likely(mysql_socket.m_psi != NULL)) { /* Instrumentation start */ PSI_socket_locker *locker; @@ -772,7 +772,7 @@ inline_mysql_socket_recv ssize_t result; #ifdef HAVE_PSI_SOCKET_INTERFACE - if (mysql_socket.m_psi != NULL) + if (psi_likely(mysql_socket.m_psi != NULL)) { /* Instrumentation start */ PSI_socket_locker *locker; @@ -813,7 +813,7 @@ inline_mysql_socket_sendto ssize_t result; #ifdef HAVE_PSI_SOCKET_INTERFACE - if (mysql_socket.m_psi != NULL) + if (psi_likely(mysql_socket.m_psi != NULL)) { /* Instrumentation start */ PSI_socket_locker *locker; @@ -855,7 +855,7 @@ inline_mysql_socket_recvfrom ssize_t result; #ifdef HAVE_PSI_SOCKET_INTERFACE - if (mysql_socket.m_psi != NULL) + if (psi_likely(mysql_socket.m_psi != NULL)) { /* Instrumentation start */ PSI_socket_locker *locker; @@ -896,7 +896,7 @@ inline_mysql_socket_getsockopt int result; #ifdef HAVE_PSI_SOCKET_INTERFACE - if (mysql_socket.m_psi != NULL) + if (psi_likely(mysql_socket.m_psi != NULL)) { /* Instrumentation start */ PSI_socket_locker *locker; @@ -935,7 +935,7 @@ inline_mysql_socket_setsockopt int result; #ifdef HAVE_PSI_SOCKET_INTERFACE - if (mysql_socket.m_psi) + if (psi_likely(mysql_socket.m_psi)) { /* Instrumentation start */ PSI_socket_locker *locker; @@ -973,7 +973,7 @@ inline_mysql_socket_listen int result; #ifdef HAVE_PSI_SOCKET_INTERFACE - if (mysql_socket.m_psi != NULL) + if (psi_likely(mysql_socket.m_psi != NULL)) { /* Instrumentation start */ PSI_socket_locker *locker; @@ -1087,7 +1087,7 @@ inline_mysql_socket_close int result; #ifdef HAVE_PSI_SOCKET_INTERFACE - if (mysql_socket.m_psi != NULL) + if (psi_likely(mysql_socket.m_psi != NULL)) { /* Instrumentation start */ PSI_socket_locker *locker; @@ -1142,7 +1142,7 @@ inline_mysql_socket_shutdown /* Instrumentation start */ #ifdef HAVE_PSI_SOCKET_INTERFACE - if (mysql_socket.m_psi != NULL) + if (psi_likely(mysql_socket.m_psi != NULL)) { PSI_socket_locker *locker; PSI_socket_locker_state state; diff --git a/include/mysql/psi/mysql_statement.h b/include/mysql/psi/mysql_statement.h index 2c59b50aa63..44d27ef1ea6 100644 --- a/include/mysql/psi/mysql_statement.h +++ b/include/mysql/psi/mysql_statement.h @@ -127,7 +127,7 @@ inline_mysql_digest_start(PSI_statement_locker *locker) { PSI_digest_locker* digest_locker= NULL; - if (likely(locker != NULL)) + if (psi_likely(locker != NULL)) digest_locker= PSI_DIGEST_CALL(digest_start)(locker); return digest_locker; } @@ -137,7 +137,7 @@ inline_mysql_digest_start(PSI_statement_locker *locker) static inline void inline_mysql_digest_end(PSI_digest_locker *locker, const sql_digest_storage *digest) { - if (likely(locker != NULL)) + if (psi_likely(locker != NULL)) PSI_DIGEST_CALL(digest_end)(locker, digest); } #endif @@ -151,7 +151,7 @@ inline_mysql_start_statement(PSI_statement_locker_state *state, { PSI_statement_locker *locker; locker= PSI_STATEMENT_CALL(get_thread_statement_locker)(state, key, charset); - if (likely(locker != NULL)) + if (psi_likely(locker != NULL)) PSI_STATEMENT_CALL(start_statement)(locker, db, (uint)db_len, src_file, src_line); return locker; } @@ -160,7 +160,7 @@ static inline struct PSI_statement_locker * inline_mysql_refine_statement(PSI_statement_locker *locker, PSI_statement_key key) { - if (likely(locker != NULL)) + if (psi_likely(locker != NULL)) { locker= PSI_STATEMENT_CALL(refine_statement)(locker, key); } @@ -171,7 +171,7 @@ static inline void inline_mysql_set_statement_text(PSI_statement_locker *locker, const char *text, uint text_len) { - if (likely(locker != NULL)) + if (psi_likely(locker != NULL)) { PSI_STATEMENT_CALL(set_statement_text)(locker, text, text_len); } @@ -181,7 +181,7 @@ static inline void inline_mysql_set_statement_lock_time(PSI_statement_locker *locker, ulonglong count) { - if (likely(locker != NULL)) + if (psi_likely(locker != NULL)) { PSI_STATEMENT_CALL(set_statement_lock_time)(locker, count); } @@ -191,7 +191,7 @@ static inline void inline_mysql_set_statement_rows_sent(PSI_statement_locker *locker, ulonglong count) { - if (likely(locker != NULL)) + if (psi_likely(locker != NULL)) { PSI_STATEMENT_CALL(set_statement_rows_sent)(locker, count); } @@ -201,7 +201,7 @@ static inline void inline_mysql_set_statement_rows_examined(PSI_statement_locker *locker, ulonglong count) { - if (likely(locker != NULL)) + if (psi_likely(locker != NULL)) { PSI_STATEMENT_CALL(set_statement_rows_examined)(locker, count); } @@ -212,7 +212,7 @@ inline_mysql_end_statement(struct PSI_statement_locker *locker, Diagnostics_area *stmt_da) { PSI_STAGE_CALL(end_stage)(); - if (likely(locker != NULL)) + if (psi_likely(locker != NULL)) PSI_STATEMENT_CALL(end_statement)(locker, stmt_da); } #endif diff --git a/include/mysql/psi/mysql_table.h b/include/mysql/psi/mysql_table.h index 5b4b64a8e48..e420f9a099e 100644 --- a/include/mysql/psi/mysql_table.h +++ b/include/mysql/psi/mysql_table.h @@ -87,7 +87,7 @@ #ifdef HAVE_PSI_TABLE_INTERFACE #define MYSQL_TABLE_IO_WAIT(PSI, OP, INDEX, FLAGS, PAYLOAD) \ { \ - if (PSI != NULL) \ + if (psi_likely(PSI != NULL)) \ { \ PSI_table_locker *locker; \ PSI_table_locker_state state; \ @@ -120,7 +120,7 @@ #ifdef HAVE_PSI_TABLE_INTERFACE #define MYSQL_TABLE_LOCK_WAIT(PSI, OP, FLAGS, PAYLOAD) \ { \ - if (PSI != NULL) \ + if (psi_likely(PSI != NULL)) \ { \ PSI_table_locker *locker; \ PSI_table_locker_state state; \ @@ -186,7 +186,7 @@ inline_mysql_start_table_lock_wait(PSI_table_locker_state *state, enum PSI_table_lock_operation op, ulong flags, const char *src_file, uint src_line) { - if (psi != NULL) + if (psi_likely(psi != NULL)) { struct PSI_table_locker *locker; locker= PSI_TABLE_CALL(start_table_lock_wait) @@ -203,7 +203,7 @@ inline_mysql_start_table_lock_wait(PSI_table_locker_state *state, static inline void inline_mysql_end_table_lock_wait(struct PSI_table_locker *locker) { - if (locker != NULL) + if (psi_likely(locker != NULL)) PSI_TABLE_CALL(end_table_lock_wait)(locker); } #endif diff --git a/include/mysql/psi/mysql_thread.h b/include/mysql/psi/mysql_thread.h index 08715513f8c..6350467c3bc 100644 --- a/include/mysql/psi/mysql_thread.h +++ b/include/mysql/psi/mysql_thread.h @@ -682,7 +682,7 @@ static inline int inline_mysql_mutex_lock( int result; #ifdef HAVE_PSI_MUTEX_INTERFACE - if (that->m_psi != NULL) + if (psi_likely(that->m_psi != NULL)) { /* Instrumentation start */ PSI_mutex_locker *locker; @@ -725,7 +725,7 @@ static inline int inline_mysql_mutex_trylock( int result; #ifdef HAVE_PSI_MUTEX_INTERFACE - if (that->m_psi != NULL) + if (psi_likely(that->m_psi != NULL)) { /* Instrumentation start */ PSI_mutex_locker *locker; @@ -768,7 +768,7 @@ static inline int inline_mysql_mutex_unlock( int result; #ifdef HAVE_PSI_MUTEX_INTERFACE - if (that->m_psi != NULL) + if (psi_likely(that->m_psi != NULL)) PSI_MUTEX_CALL(unlock_mutex)(that->m_psi); #endif @@ -835,7 +835,7 @@ static inline int inline_mysql_rwlock_destroy( mysql_rwlock_t *that) { #ifdef HAVE_PSI_RWLOCK_INTERFACE - if (that->m_psi != NULL) + if (psi_likely(that->m_psi != NULL)) { PSI_RWLOCK_CALL(destroy_rwlock)(that->m_psi); that->m_psi= NULL; @@ -849,7 +849,7 @@ static inline int inline_mysql_prlock_destroy( mysql_prlock_t *that) { #ifdef HAVE_PSI_RWLOCK_INTERFACE - if (that->m_psi != NULL) + if (psi_likely(that->m_psi != NULL)) { PSI_RWLOCK_CALL(destroy_rwlock)(that->m_psi); that->m_psi= NULL; @@ -869,7 +869,7 @@ static inline int inline_mysql_rwlock_rdlock( int result; #ifdef HAVE_PSI_RWLOCK_INTERFACE - if (that->m_psi != NULL) + if (psi_likely(that->m_psi != NULL)) { /* Instrumentation start */ PSI_rwlock_locker *locker; @@ -905,7 +905,7 @@ static inline int inline_mysql_prlock_rdlock( int result; #ifdef HAVE_PSI_RWLOCK_INTERFACE - if (that->m_psi != NULL) + if (psi_likely(that->m_psi != NULL)) { /* Instrumentation start */ PSI_rwlock_locker *locker; @@ -941,7 +941,7 @@ static inline int inline_mysql_rwlock_wrlock( int result; #ifdef HAVE_PSI_RWLOCK_INTERFACE - if (that->m_psi != NULL) + if (psi_likely(that->m_psi != NULL)) { /* Instrumentation start */ PSI_rwlock_locker *locker; @@ -977,7 +977,7 @@ static inline int inline_mysql_prlock_wrlock( int result; #ifdef HAVE_PSI_RWLOCK_INTERFACE - if (that->m_psi != NULL) + if (psi_likely(that->m_psi != NULL)) { /* Instrumentation start */ PSI_rwlock_locker *locker; @@ -1013,7 +1013,7 @@ static inline int inline_mysql_rwlock_tryrdlock( int result; #ifdef HAVE_PSI_RWLOCK_INTERFACE - if (that->m_psi != NULL) + if (psi_likely(that->m_psi != NULL)) { /* Instrumentation start */ PSI_rwlock_locker *locker; @@ -1048,7 +1048,7 @@ static inline int inline_mysql_rwlock_trywrlock( int result; #ifdef HAVE_PSI_RWLOCK_INTERFACE - if (that->m_psi != NULL) + if (psi_likely(that->m_psi != NULL)) { /* Instrumentation start */ PSI_rwlock_locker *locker; @@ -1078,7 +1078,7 @@ static inline int inline_mysql_rwlock_unlock( { int result; #ifdef HAVE_PSI_RWLOCK_INTERFACE - if (that->m_psi != NULL) + if (psi_likely(that->m_psi != NULL)) PSI_RWLOCK_CALL(unlock_rwlock)(that->m_psi); #endif result= rw_unlock(&that->m_rwlock); @@ -1091,7 +1091,7 @@ static inline int inline_mysql_prlock_unlock( { int result; #ifdef HAVE_PSI_RWLOCK_INTERFACE - if (that->m_psi != NULL) + if (psi_likely(that->m_psi != NULL)) PSI_RWLOCK_CALL(unlock_rwlock)(that->m_psi); #endif result= rw_pr_unlock(&that->m_prlock); @@ -1135,7 +1135,7 @@ static inline int inline_mysql_cond_destroy( mysql_cond_t *that) { #ifdef HAVE_PSI_COND_INTERFACE - if (that->m_psi != NULL) + if (psi_likely(that->m_psi != NULL)) { PSI_COND_CALL(destroy_cond)(that->m_psi); that->m_psi= NULL; @@ -1155,7 +1155,7 @@ static inline int inline_mysql_cond_wait( int result; #ifdef HAVE_PSI_COND_INTERFACE - if (that->m_psi != NULL) + if (psi_likely(that->m_psi != NULL)) { /* Instrumentation start */ PSI_cond_locker *locker; @@ -1192,7 +1192,7 @@ static inline int inline_mysql_cond_timedwait( int result; #ifdef HAVE_PSI_COND_INTERFACE - if (that->m_psi != NULL) + if (psi_likely(that->m_psi != NULL)) { /* Instrumentation start */ PSI_cond_locker *locker; @@ -1204,7 +1204,7 @@ static inline int inline_mysql_cond_timedwait( result= my_cond_timedwait(&that->m_cond, &mutex->m_mutex, abstime); /* Instrumentation end */ - if (locker != NULL) + if (psi_likely(locker != NULL)) PSI_COND_CALL(end_cond_wait)(locker, result); return result; @@ -1222,7 +1222,7 @@ static inline int inline_mysql_cond_signal( { int result; #ifdef HAVE_PSI_COND_INTERFACE - if (that->m_psi != NULL) + if (psi_likely(that->m_psi != NULL)) PSI_COND_CALL(signal_cond)(that->m_psi); #endif result= pthread_cond_signal(&that->m_cond); @@ -1234,7 +1234,7 @@ static inline int inline_mysql_cond_broadcast( { int result; #ifdef HAVE_PSI_COND_INTERFACE - if (that->m_psi != NULL) + if (psi_likely(that->m_psi != NULL)) PSI_COND_CALL(broadcast_cond)(that->m_psi); #endif result= pthread_cond_broadcast(&that->m_cond); diff --git a/include/mysql/psi/psi.h b/include/mysql/psi/psi.h index 3f43445e08a..394dd1b30b4 100644 --- a/include/mysql/psi/psi.h +++ b/include/mysql/psi/psi.h @@ -40,6 +40,21 @@ #error "You must include my_global.h in the code for the build to be correct." #endif +/* + If PSI_ON_BY_DFAULT is defined, assume PSI will be enabled by default and + optimize jumps testing for PSI this case. If not, optimize the binary for + that PSI is not enabled +*/ + +#ifdef PSI_ON_BY_DEFAULT +#define psi_likely(A) likely(A) +#define psi_unlikely(A) unlikely(A) +#else +#define psi_likely(A) unlikely(A) +#define psi_unlikely(A) likely(A) +#endif + + C_MODE_START struct TABLE_SHARE; @@ -2346,6 +2361,7 @@ typedef struct PSI_stage_info_none PSI_stage_info; #endif /* HAVE_PSI_INTERFACE */ +extern MYSQL_PLUGIN_IMPORT my_bool pfs_enabled; extern MYSQL_PLUGIN_IMPORT PSI *PSI_server; /* diff --git a/include/mysql/psi/psi_abi_v1.h.pp b/include/mysql/psi/psi_abi_v1.h.pp index 17ac0271da2..ef18f59e4a9 100644 --- a/include/mysql/psi/psi_abi_v1.h.pp +++ b/include/mysql/psi/psi_abi_v1.h.pp @@ -616,5 +616,6 @@ typedef struct PSI_file_locker_state_v1 PSI_file_locker_state; typedef struct PSI_table_locker_state_v1 PSI_table_locker_state; typedef struct PSI_statement_locker_state_v1 PSI_statement_locker_state; typedef struct PSI_socket_locker_state_v1 PSI_socket_locker_state; +extern MYSQL_PLUGIN_IMPORT my_bool pfs_enabled; extern MYSQL_PLUGIN_IMPORT PSI *PSI_server; C_MODE_END diff --git a/include/mysql/psi/psi_abi_v2.h.pp b/include/mysql/psi/psi_abi_v2.h.pp index 4e81fd66ca4..adf1af7cfae 100644 --- a/include/mysql/psi/psi_abi_v2.h.pp +++ b/include/mysql/psi/psi_abi_v2.h.pp @@ -209,5 +209,6 @@ typedef struct PSI_file_locker_state_v2 PSI_file_locker_state; typedef struct PSI_table_locker_state_v2 PSI_table_locker_state; typedef struct PSI_statement_locker_state_v2 PSI_statement_locker_state; typedef struct PSI_socket_locker_state_v2 PSI_socket_locker_state; +extern MYSQL_PLUGIN_IMPORT my_bool pfs_enabled; extern MYSQL_PLUGIN_IMPORT PSI *PSI_server; C_MODE_END diff --git a/mysys/file_logger.c b/mysys/file_logger.c index 35a077c4391..3565397c79a 100644 --- a/mysys/file_logger.c +++ b/mysys/file_logger.c @@ -227,7 +227,7 @@ int logger_printf(LOGGER_HANDLE *log, const char *fmt, ...) void logger_init_mutexes() { #ifdef HAVE_PSI_INTERFACE - if (PSI_server) + if (unlikely(PSI_server)) PSI_server->register_mutex("sql_logger", mutex_list, 1); #endif } diff --git a/mysys/my_likely.c b/mysys/my_likely.c index 9b32c65d6a0..c6fca5b7146 100644 --- a/mysys/my_likely.c +++ b/mysys/my_likely.c @@ -121,14 +121,14 @@ static LIKELY_ENTRY *my_likely_find(const char *file_name, uint line) { char key[80], *pos; LIKELY_ENTRY *entry; - uint length; + size_t length; if (!likely_inited) return 0; pos= strnmov(key, file_name, sizeof(key)-4); int3store(pos+1, line); - length= (pos-key)+4; + length= (size_t) (pos-key)+4; pthread_mutex_lock(&likely_mutex); if (!(entry= (LIKELY_ENTRY*) my_hash_search(&likely_hash, (uchar*) key, diff --git a/mysys/psi_noop.c b/mysys/psi_noop.c index 6eecf56f797..f8fa2c92f63 100644 --- a/mysys/psi_noop.c +++ b/mysys/psi_noop.c @@ -763,6 +763,13 @@ struct PSI_bootstrap *PSI_hook= NULL; PSI *PSI_server= & PSI_noop; +/** + Global performance schema flag. + Indicate if the performance schema is enabled. + This flag is set at startup, and never changes. +*/ +my_bool pfs_enabled= FALSE; + void set_psi_server(PSI *psi) { PSI_server= psi; diff --git a/storage/perfschema/pfs.cc b/storage/perfschema/pfs.cc index bca4da4a31a..5bdc973341f 100644 --- a/storage/perfschema/pfs.cc +++ b/storage/perfschema/pfs.cc @@ -1615,6 +1615,14 @@ open_table_v1(PSI_table_share *share, const void *identity) { PFS_table_share *pfs_table_share= reinterpret_cast<PFS_table_share*> (share); + /* + When the performance schema is off, do not instrument anything. + Table handles have short life cycle, instrumentation will happen + again if needed during the next open(). + */ + if (psi_unlikely(! flag_global_instrumentation)) + return NULL; + if (unlikely(pfs_table_share == NULL)) return NULL; @@ -1626,14 +1634,6 @@ open_table_v1(PSI_table_share *share, const void *identity) if (! global_table_io_class.m_enabled && ! global_table_lock_class.m_enabled) return NULL; - /* - When the performance schema is off, do not instrument anything. - Table handles have short life cycle, instrumentation will happen - again if needed during the next open(). - */ - if (! flag_global_instrumentation) - return NULL; - PFS_thread *thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); if (unlikely(thread == NULL)) return NULL; @@ -1668,22 +1668,22 @@ rebind_table_v1(PSI_table_share *share, const void *identity, PSI_table *table) PFS_thread *thread; DBUG_ASSERT(pfs->m_thread_owner == NULL); - /* The table handle was already instrumented, reuse it for this thread. */ - thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); - - if (unlikely(! pfs->m_share->m_enabled)) + if (psi_unlikely(! flag_global_instrumentation)) { destroy_table(pfs); return NULL; } - if (unlikely(! global_table_io_class.m_enabled && ! global_table_lock_class.m_enabled)) + /* The table handle was already instrumented, reuse it for this thread. */ + thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); + + if (unlikely(! pfs->m_share->m_enabled)) { destroy_table(pfs); return NULL; } - if (unlikely(! flag_global_instrumentation)) + if (unlikely(! global_table_io_class.m_enabled && ! global_table_lock_class.m_enabled)) { destroy_table(pfs); return NULL; @@ -1693,6 +1693,9 @@ rebind_table_v1(PSI_table_share *share, const void *identity, PSI_table *table) return table; } + if (psi_unlikely(! flag_global_instrumentation)) + return NULL; + /* See open_table_v1() */ PFS_table_share *pfs_table_share= reinterpret_cast<PFS_table_share*> (share); @@ -1706,9 +1709,6 @@ rebind_table_v1(PSI_table_share *share, const void *identity, PSI_table *table) if (! global_table_io_class.m_enabled && ! global_table_lock_class.m_enabled) return NULL; - if (! flag_global_instrumentation) - return NULL; - PFS_thread *thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); if (unlikely(thread == NULL)) return NULL; @@ -1760,7 +1760,7 @@ static void destroy_socket_v1(PSI_socket *socket) */ static void create_file_v1(PSI_file_key key, const char *name, File file) { - if (! flag_global_instrumentation) + if (psi_unlikely(! flag_global_instrumentation)) return; int index= (int) file; if (unlikely(index < 0)) @@ -2783,7 +2783,7 @@ get_thread_file_name_locker_v1(PSI_file_locker_state *state, DBUG_ASSERT(static_cast<uint> (op) < array_elements(file_operation_map)); DBUG_ASSERT(state != NULL); - if (! flag_global_instrumentation) + if (psi_unlikely(! flag_global_instrumentation)) return NULL; PFS_file_class *klass= find_file_class(key); if (unlikely(klass == NULL)) @@ -3316,7 +3316,7 @@ start_idle_wait_v1(PSI_idle_locker_state* state, const char *src_file, uint src_ { DBUG_ASSERT(state != NULL); - if (!flag_global_instrumentation) + if (psi_unlikely(! flag_global_instrumentation)) return NULL; if (!global_idle_class.m_enabled) @@ -4253,7 +4253,7 @@ static void start_stage_v1(PSI_stage_key key, const char *src_file, int src_line /* Always update column threads.processlist_state. */ pfs_thread->m_stage= key; - if (! flag_global_instrumentation) + if (psi_unlikely(! flag_global_instrumentation)) return; if (flag_thread_instrumentation && ! pfs_thread->m_enabled) @@ -4353,7 +4353,7 @@ static void end_stage_v1() pfs_thread->m_stage= 0; - if (! flag_global_instrumentation) + if (psi_unlikely(! flag_global_instrumentation)) return; if (flag_thread_instrumentation && ! pfs_thread->m_enabled) @@ -4412,7 +4412,7 @@ get_thread_statement_locker_v1(PSI_statement_locker_state *state, DBUG_ASSERT(state != NULL); DBUG_ASSERT(charset != NULL); - if (! flag_global_instrumentation) + if (psi_unlikely(! flag_global_instrumentation)) return NULL; PFS_statement_class *klass= find_statement_class(key); if (unlikely(klass == NULL)) diff --git a/storage/perfschema/pfs_instr_class.cc b/storage/perfschema/pfs_instr_class.cc index 3f5fce9e7a2..d2202190461 100644 --- a/storage/perfschema/pfs_instr_class.cc +++ b/storage/perfschema/pfs_instr_class.cc @@ -41,13 +41,6 @@ */ /** - Global performance schema flag. - Indicate if the performance schema is enabled. - This flag is set at startup, and never changes. -*/ -my_bool pfs_enabled= TRUE; - -/** PFS_INSTRUMENT option settings array and associated state variable to serialize access during shutdown. */ |