# name : innodb_show_lock_name.patch # introduced : 11 or before # maintainer : Yasufumi # #!!! notice !!! # Any small change to this file in the main branch # should be done or reviewed by the maintainer! --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -9709,9 +9709,8 @@ rw_lock_wait_time += mutex->lspent_time; } #else /* UNIV_DEBUG */ - buf1len= (uint) my_snprintf(buf1, sizeof(buf1), "%s:%lu", - innobase_basename(mutex->cfile_name), - (ulong) mutex->cline); + buf1len= (uint) my_snprintf(buf1, sizeof(buf1), "%s", + mutex->cmutex_name); buf2len= (uint) my_snprintf(buf2, sizeof(buf2), "os_waits=%lu", (ulong) mutex->count_os_wait); @@ -9726,10 +9725,8 @@ if (block_mutex) { buf1len = (uint) my_snprintf(buf1, sizeof buf1, - "combined %s:%lu", - innobase_basename( - block_mutex->cfile_name), - (ulong) block_mutex->cline); + "combined %s", + block_mutex->cmutex_name); buf2len = (uint) my_snprintf(buf2, sizeof buf2, "os_waits=%lu", (ulong) block_mutex_oswait_count); @@ -9758,9 +9755,8 @@ continue; } - buf1len = my_snprintf(buf1, sizeof buf1, "%s:%lu", - innobase_basename(lock->cfile_name), - (ulong) lock->cline); + buf1len = my_snprintf(buf1, sizeof buf1, "%s", + lock->lock_name); buf2len = my_snprintf(buf2, sizeof buf2, "os_waits=%lu", (ulong) lock->count_os_wait); @@ -9774,10 +9770,8 @@ if (block_lock) { buf1len = (uint) my_snprintf(buf1, sizeof buf1, - "combined %s:%lu", - innobase_basename( - block_lock->cfile_name), - (ulong) block_lock->cline); + "combined %s", + block_lock->lock_name); buf2len = (uint) my_snprintf(buf2, sizeof buf2, "os_waits=%lu", (ulong) block_lock_oswait_count); --- a/storage/innobase/include/sync0rw.h +++ b/storage/innobase/include/sync0rw.h @@ -138,14 +138,14 @@ # ifdef UNIV_DEBUG # ifdef UNIV_SYNC_DEBUG # define rw_lock_create(K, L, level) \ - rw_lock_create_func((L), (level), #L, __FILE__, __LINE__) + rw_lock_create_func((L), (level), __FILE__, __LINE__, #L) # else /* UNIV_SYNC_DEBUG */ # define rw_lock_create(K, L, level) \ - rw_lock_create_func((L), #L, __FILE__, __LINE__) + rw_lock_create_func((L), __FILE__, __LINE__, #L) # endif/* UNIV_SYNC_DEBUG */ # else /* UNIV_DEBUG */ # define rw_lock_create(K, L, level) \ - rw_lock_create_func((L), __FILE__, __LINE__) + rw_lock_create_func((L), #L) # endif /* UNIV_DEBUG */ /**************************************************************//** @@ -191,14 +191,14 @@ # ifdef UNIV_DEBUG # ifdef UNIV_SYNC_DEBUG # define rw_lock_create(K, L, level) \ - pfs_rw_lock_create_func((K), (L), (level), #L, __FILE__, __LINE__) + pfs_rw_lock_create_func((K), (L), (level), __FILE__, __LINE__, #L) # else /* UNIV_SYNC_DEBUG */ # define rw_lock_create(K, L, level) \ - pfs_rw_lock_create_func((K), (L), #L, __FILE__, __LINE__) + pfs_rw_lock_create_func((K), (L), __FILE__, __LINE__, #L) # endif/* UNIV_SYNC_DEBUG */ # else /* UNIV_DEBUG */ # define rw_lock_create(K, L, level) \ - pfs_rw_lock_create_func((K), (L), __FILE__, __LINE__) + pfs_rw_lock_create_func((K), (L), #L) # endif /* UNIV_DEBUG */ /****************************************************************** @@ -256,10 +256,10 @@ # ifdef UNIV_SYNC_DEBUG ulint level, /*!< in: level */ # endif /* UNIV_SYNC_DEBUG */ - const char* cmutex_name, /*!< in: mutex name */ -#endif /* UNIV_DEBUG */ const char* cfile_name, /*!< in: file name where created */ - ulint cline); /*!< in: file line where created */ + ulint cline, /*!< in: file line where created */ +#endif /* UNIV_DEBUG */ + const char* cmutex_name); /*!< in: mutex name */ /******************************************************************//** Calling this function is obligatory only if the memory buffer containing the rw-lock is freed. Removes an rw-lock object from the global list. The @@ -611,7 +611,8 @@ struct PSI_rwlock *pfs_psi;/*!< The instrumentation hook */ #endif ulint count_os_wait; /*!< Count of os_waits. May not be accurate */ - const char* cfile_name;/*!< File name where lock created */ + //const char* cfile_name;/*!< File name where lock created */ + const char* lock_name;/*!< lock name */ /* last s-lock file/line is not guaranteed to be correct */ const char* last_s_file_name;/*!< File name where last s-locked */ const char* last_x_file_name;/*!< File name where last x-locked */ @@ -622,7 +623,7 @@ are at the start of this struct, thus we can peek this field without causing much memory bus traffic */ - unsigned cline:14; /*!< Line where created */ + //unsigned cline:14; /*!< Line where created */ unsigned last_s_line:14; /*!< Line number where last time s-locked */ unsigned last_x_line:14; /*!< Line number where last time x-locked */ #ifdef UNIV_DEBUG @@ -693,10 +694,10 @@ # ifdef UNIV_SYNC_DEBUG ulint level, /*!< in: level */ # endif /* UNIV_SYNC_DEBUG */ - const char* cmutex_name, /*!< in: mutex name */ -#endif /* UNIV_DEBUG */ const char* cfile_name, /*!< in: file name where created */ - ulint cline); /*!< in: file line where created */ + ulint cline, /*!< in: file line where created */ +#endif /* UNIV_DEBUG */ + const char* cmutex_name); /*!< in: mutex name */ /******************************************************************//** Performance schema instrumented wrap function for rw_lock_x_lock_func() --- a/storage/innobase/include/sync0rw.ic +++ b/storage/innobase/include/sync0rw.ic @@ -641,10 +641,10 @@ # ifdef UNIV_SYNC_DEBUG ulint level, /*!< in: level */ # endif /* UNIV_SYNC_DEBUG */ - const char* cmutex_name, /*!< in: mutex name */ -# endif /* UNIV_DEBUG */ const char* cfile_name, /*!< in: file name where created */ - ulint cline) /*!< in: file line where created */ + ulint cline, /*!< in: file line where created */ +# endif /* UNIV_DEBUG */ + const char* cmutex_name) /*!< in: mutex name */ { /* Initialize the rwlock for performance schema */ lock->pfs_psi = (PSI_server && PFS_IS_INSTRUMENTED(key)) @@ -657,10 +657,10 @@ # ifdef UNIV_SYNC_DEBUG level, # endif /* UNIV_SYNC_DEBUG */ - cmutex_name, -# endif /* UNIV_DEBUG */ cfile_name, - cline); + cline, +# endif /* UNIV_DEBUG */ + cmutex_name); } /******************************************************************//** Performance schema instrumented wrap function for rw_lock_x_lock_func() --- a/storage/innobase/include/sync0sync.h +++ b/storage/innobase/include/sync0sync.h @@ -158,14 +158,14 @@ # ifdef UNIV_DEBUG # ifdef UNIV_SYNC_DEBUG # define mutex_create(K, M, level) \ - pfs_mutex_create_func((K), (M), #M, (level), __FILE__, __LINE__) + pfs_mutex_create_func((K), (M), (level), __FILE__, __LINE__, #M) # else # define mutex_create(K, M, level) \ - pfs_mutex_create_func((K), (M), #M, __FILE__, __LINE__) + pfs_mutex_create_func((K), (M), __FILE__, __LINE__, #M) # endif/* UNIV_SYNC_DEBUG */ # else # define mutex_create(K, M, level) \ - pfs_mutex_create_func((K), (M), __FILE__, __LINE__) + pfs_mutex_create_func((K), (M), #M) # endif /* UNIV_DEBUG */ # define mutex_enter(M) \ @@ -185,14 +185,14 @@ # ifdef UNIV_DEBUG # ifdef UNIV_SYNC_DEBUG # define mutex_create(K, M, level) \ - mutex_create_func((M), #M, (level), __FILE__, __LINE__) + mutex_create_func((M), (level), __FILE__, __LINE__, #M) # else /* UNIV_SYNC_DEBUG */ # define mutex_create(K, M, level) \ - mutex_create_func((M), #M, __FILE__, __LINE__) + mutex_create_func((M), __FILE__, __LINE__, #M) # endif /* UNIV_SYNC_DEBUG */ # else /* UNIV_DEBUG */ # define mutex_create(K, M, level) \ - mutex_create_func((M), __FILE__, __LINE__) + mutex_create_func((M), #M) # endif /* UNIV_DEBUG */ # define mutex_enter(M) mutex_enter_func((M), __FILE__, __LINE__) @@ -217,13 +217,13 @@ /*==============*/ mutex_t* mutex, /*!< in: pointer to memory */ #ifdef UNIV_DEBUG - const char* cmutex_name, /*!< in: mutex name */ # ifdef UNIV_SYNC_DEBUG ulint level, /*!< in: level */ # endif /* UNIV_SYNC_DEBUG */ -#endif /* UNIV_DEBUG */ const char* cfile_name, /*!< in: file name where created */ - ulint cline); /*!< in: file line where created */ + ulint cline, /*!< in: file line where created */ +#endif /* UNIV_DEBUG */ + const char* cmutex_name); /*!< in: mutex name */ /******************************************************************//** NOTE! Use the corresponding macro mutex_free(), not directly this function! @@ -291,13 +291,13 @@ PSI_mutex_key key, /*!< in: Performance Schema key */ mutex_t* mutex, /*!< in: pointer to memory */ # ifdef UNIV_DEBUG - const char* cmutex_name, /*!< in: mutex name */ # ifdef UNIV_SYNC_DEBUG ulint level, /*!< in: level */ # endif /* UNIV_SYNC_DEBUG */ -# endif /* UNIV_DEBUG */ const char* cfile_name, /*!< in: file name where created */ - ulint cline); /*!< in: file line where created */ + ulint cline, /*!< in: file line where created */ +# endif /* UNIV_DEBUG */ + const char* cmutex_name); /******************************************************************//** NOTE! Please use the corresponding macro mutex_enter(), not directly this function! @@ -728,9 +728,9 @@ ulint line; /*!< Line where the mutex was locked */ ulint level; /*!< Level in the global latching order */ #endif /* UNIV_SYNC_DEBUG */ +#ifdef UNIV_DEBUG const char* cfile_name;/*!< File name where mutex created */ ulint cline; /*!< Line where created */ -#ifdef UNIV_DEBUG os_thread_id_t thread_id; /*!< The thread id of the thread which locked the mutex. */ ulint magic_n; /*!< MUTEX_MAGIC_N */ @@ -745,9 +745,9 @@ ulong count_os_yield; /*!< count of os_wait */ ulonglong lspent_time; /*!< mutex os_wait timer msec */ ulonglong lmax_spent_time;/*!< mutex os_wait timer msec */ - const char* cmutex_name; /*!< mutex name */ ulint mutex_type; /*!< 0=usual mutex, 1=rw_lock mutex */ #endif /* UNIV_DEBUG */ + const char* cmutex_name; /*!< mutex name */ #ifdef UNIV_PFS_MUTEX struct PSI_mutex* pfs_psi; /*!< The performance schema instrumentation hook */ --- a/storage/innobase/include/sync0sync.ic +++ b/storage/innobase/include/sync0sync.ic @@ -320,13 +320,13 @@ mysql_pfs_key_t key, /*!< in: Performance Schema key */ mutex_t* mutex, /*!< in: pointer to memory */ # ifdef UNIV_DEBUG - const char* cmutex_name, /*!< in: mutex name */ # ifdef UNIV_SYNC_DEBUG ulint level, /*!< in: level */ # endif /* UNIV_SYNC_DEBUG */ -# endif /* UNIV_DEBUG */ const char* cfile_name, /*!< in: file name where created */ - ulint cline) /*!< in: file line where created */ + ulint cline, /*!< in: file line where created */ +# endif /* UNIV_DEBUG */ + const char* cmutex_name) /*!< in: mutex name */ { mutex->pfs_psi = (PSI_server && PFS_IS_INSTRUMENTED(key)) ? PSI_server->init_mutex(key, mutex) @@ -334,13 +334,13 @@ mutex_create_func(mutex, # ifdef UNIV_DEBUG - cmutex_name, # ifdef UNIV_SYNC_DEBUG level, # endif /* UNIV_SYNC_DEBUG */ -# endif /* UNIV_DEBUG */ cfile_name, - cline); + cline, +# endif /* UNIV_DEBUG */ + cmutex_name); } /******************************************************************//** NOTE! Please use the corresponding macro mutex_free(), not directly --- a/storage/innobase/sync/sync0arr.c +++ b/storage/innobase/sync/sync0arr.c @@ -489,13 +489,12 @@ mutex = cell->old_wait_mutex; fprintf(file, - "Mutex at %p created file %s line %lu, lock var %lu\n" + "Mutex at %p '%s', lock var %lu\n" #ifdef UNIV_SYNC_DEBUG "Last time reserved in file %s line %lu, " #endif /* UNIV_SYNC_DEBUG */ "waiters flag %lu\n", - (void*) mutex, innobase_basename(mutex->cfile_name), - (ulong) mutex->cline, + (void*) mutex, mutex->cmutex_name, (ulong) mutex->lock_word, #ifdef UNIV_SYNC_DEBUG mutex->file_name, (ulong) mutex->line, @@ -513,9 +512,8 @@ rwlock = cell->old_wait_rw_lock; fprintf(file, - " RW-latch at %p created in file %s line %lu\n", - (void*) rwlock, innobase_basename(rwlock->cfile_name), - (ulong) rwlock->cline); + " RW-latch at %p '%s'\n", + (void*) rwlock, rwlock->lock_name); writer = rw_lock_get_writer(rwlock); if (writer != RW_LOCK_NOT_LOCKED) { fprintf(file, --- a/storage/innobase/sync/sync0rw.c +++ b/storage/innobase/sync/sync0rw.c @@ -242,10 +242,10 @@ # ifdef UNIV_SYNC_DEBUG ulint level, /*!< in: level */ # endif /* UNIV_SYNC_DEBUG */ - const char* cmutex_name, /*!< in: mutex name */ -#endif /* UNIV_DEBUG */ const char* cfile_name, /*!< in: file name where created */ - ulint cline) /*!< in: file line where created */ + ulint cline, /*!< in: file line where created */ +#endif /* UNIV_DEBUG */ + const char* cmutex_name) /*!< in: mutex name */ { /* If this is the very first time a synchronization object is created, then the following call initializes the sync system. */ @@ -254,14 +254,15 @@ mutex_create(rw_lock_mutex_key, rw_lock_get_mutex(lock), SYNC_NO_ORDER_CHECK); - lock->mutex.cfile_name = cfile_name; - lock->mutex.cline = cline; + ut_d(lock->mutex.cfile_name = cfile_name); + ut_d(lock->mutex.cline = cline); - ut_d(lock->mutex.cmutex_name = cmutex_name); + lock->mutex.cmutex_name = cmutex_name; ut_d(lock->mutex.mutex_type = 1); #else /* INNODB_RW_LOCKS_USE_ATOMICS */ # ifdef UNIV_DEBUG - UT_NOT_USED(cmutex_name); + UT_NOT_USED(cfile_name); + UT_NOT_USED(cline); # endif #endif /* INNODB_RW_LOCKS_USE_ATOMICS */ @@ -284,8 +285,7 @@ ut_d(lock->magic_n = RW_LOCK_MAGIC_N); - lock->cfile_name = cfile_name; - lock->cline = (unsigned int) cline; + lock->lock_name = cmutex_name; lock->count_os_wait = 0; lock->last_s_file_name = "not yet reserved"; @@ -405,11 +405,10 @@ if (srv_print_latch_waits) { fprintf(stderr, "Thread %lu spin wait rw-s-lock at %p" - " cfile %s cline %lu rnds %lu\n", + " '%s' rnds %lu\n", (ulong) os_thread_pf(os_thread_get_curr_id()), (void*) lock, - innobase_basename(lock->cfile_name), - (ulong) lock->cline, (ulong) i); + lock->lock_name, (ulong) i); } /* We try once again to obtain the lock */ @@ -442,11 +441,9 @@ if (srv_print_latch_waits) { fprintf(stderr, "Thread %lu OS wait rw-s-lock at %p" - " cfile %s cline %lu\n", + " '%s'\n", os_thread_pf(os_thread_get_curr_id()), - (void*) lock, - innobase_basename(lock->cfile_name), - (ulong) lock->cline); + (void*) lock, lock->lock_name); } /* these stats may not be accurate */ @@ -668,10 +665,9 @@ if (srv_print_latch_waits) { fprintf(stderr, "Thread %lu spin wait rw-x-lock at %p" - " cfile %s cline %lu rnds %lu\n", + " '%s' rnds %lu\n", os_thread_pf(os_thread_get_curr_id()), (void*) lock, - innobase_basename(lock->cfile_name), - (ulong) lock->cline, (ulong) i); + lock->lock_name, (ulong) i); } sync_array_reserve_cell(sync_primary_wait_array, @@ -692,10 +688,9 @@ if (srv_print_latch_waits) { fprintf(stderr, "Thread %lu OS wait for rw-x-lock at %p" - " cfile %s cline %lu\n", + " '%s'\n", os_thread_pf(os_thread_get_curr_id()), (void*) lock, - innobase_basename(lock->cfile_name), - (ulong) lock->cline); + lock->lock_name); } /* these stats may not be accurate */ --- a/storage/innobase/sync/sync0sync.c +++ b/storage/innobase/sync/sync0sync.c @@ -270,13 +270,13 @@ /*==============*/ mutex_t* mutex, /*!< in: pointer to memory */ #ifdef UNIV_DEBUG - const char* cmutex_name, /*!< in: mutex name */ # ifdef UNIV_SYNC_DEBUG ulint level, /*!< in: level */ # endif /* UNIV_SYNC_DEBUG */ -#endif /* UNIV_DEBUG */ const char* cfile_name, /*!< in: file name where created */ - ulint cline) /*!< in: file line where created */ + ulint cline, /*!< in: file line where created */ +#endif /* UNIV_DEBUG */ + const char* cmutex_name) /*!< in: mutex name */ { #if defined(HAVE_ATOMIC_BUILTINS) mutex_reset_lock_word(mutex); @@ -294,11 +294,13 @@ mutex->file_name = "not yet reserved"; mutex->level = level; #endif /* UNIV_SYNC_DEBUG */ +#ifdef UNIV_DEBUG mutex->cfile_name = cfile_name; mutex->cline = cline; +#endif /* UNIV_DEBUG */ mutex->count_os_wait = 0; -#ifdef UNIV_DEBUG mutex->cmutex_name= cmutex_name; +#ifdef UNIV_DEBUG mutex->count_using= 0; mutex->mutex_type= 0; mutex->lspent_time= 0; @@ -552,10 +554,9 @@ #ifdef UNIV_SRV_PRINT_LATCH_WAITS fprintf(stderr, "Thread %lu spin wait mutex at %p" - " cfile %s cline %lu rnds %lu\n", + " '%s' rnds %lu\n", (ulong) os_thread_pf(os_thread_get_curr_id()), (void*) mutex, - innobase_basename(mutex->cfile_name), - (ulong) mutex->cline, (ulong) i); + mutex->cmutex_name, (ulong) i); #endif mutex_spin_round_count += i; @@ -630,10 +631,9 @@ #ifdef UNIV_SRV_PRINT_LATCH_WAITS fprintf(stderr, - "Thread %lu OS wait mutex at %p cfile %s cline %lu rnds %lu\n", + "Thread %lu OS wait mutex at %p '%s' rnds %lu\n", (ulong) os_thread_pf(os_thread_get_curr_id()), (void*) mutex, - innobase_basename(mutex->cfile_name), - (ulong) mutex->cline, (ulong) i); + mutex->cmutex_name, (ulong) i); #endif mutex_os_wait_count++; @@ -881,9 +881,8 @@ if (mutex->magic_n == MUTEX_MAGIC_N) { fprintf(stderr, - "Mutex created at %s %lu\n", - innobase_basename(mutex->cfile_name), - (ulong) mutex->cline); + "Mutex '%s'\n", + mutex->cmutex_name); if (mutex_get_lock_word(mutex) != 0) { ulint line;