1 # name : innodb_show_lock_name.patch
2 # introduced : 11 or before
3 # maintainer : Yasufumi
6 # Any small change to this file in the main branch
7 # should be done or reviewed by the maintainer!
8 diff -ruN a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
9 --- a/storage/innobase/handler/ha_innodb.cc 2010-12-03 17:34:35.285040381 +0900
10 +++ b/storage/innobase/handler/ha_innodb.cc 2010-12-03 17:35:12.974975252 +0900
12 rw_lock_wait_time += mutex->lspent_time;
14 #else /* UNIV_DEBUG */
15 - buf1len= (uint) my_snprintf(buf1, sizeof(buf1), "%s:%lu",
16 - innobase_basename(mutex->cfile_name),
17 - (ulong) mutex->cline);
18 + buf1len= (uint) my_snprintf(buf1, sizeof(buf1), "%s",
19 + mutex->cmutex_name);
20 buf2len= (uint) my_snprintf(buf2, sizeof(buf2), "os_waits=%lu",
21 (ulong) mutex->count_os_wait);
23 @@ -9610,10 +9609,8 @@
26 buf1len = (uint) my_snprintf(buf1, sizeof buf1,
29 - block_mutex->cfile_name),
30 - (ulong) block_mutex->cline);
32 + block_mutex->cmutex_name);
33 buf2len = (uint) my_snprintf(buf2, sizeof buf2,
35 (ulong) block_mutex_oswait_count);
40 - buf1len = my_snprintf(buf1, sizeof buf1, "%s:%lu",
41 - innobase_basename(lock->cfile_name),
42 - (ulong) lock->cline);
43 + buf1len = my_snprintf(buf1, sizeof buf1, "%s",
45 buf2len = my_snprintf(buf2, sizeof buf2, "os_waits=%lu",
46 (ulong) lock->count_os_wait);
48 @@ -9658,10 +9654,8 @@
51 buf1len = (uint) my_snprintf(buf1, sizeof buf1,
54 - block_lock->cfile_name),
55 - (ulong) block_lock->cline);
57 + block_lock->lock_name);
58 buf2len = (uint) my_snprintf(buf2, sizeof buf2,
60 (ulong) block_lock_oswait_count);
61 diff -ruN a/storage/innobase/include/sync0rw.h b/storage/innobase/include/sync0rw.h
62 --- a/storage/innobase/include/sync0rw.h 2010-12-03 15:49:59.225953164 +0900
63 +++ b/storage/innobase/include/sync0rw.h 2010-12-03 17:35:12.978024458 +0900
66 # ifdef UNIV_SYNC_DEBUG
67 # define rw_lock_create(K, L, level) \
68 - rw_lock_create_func((L), (level), #L, __FILE__, __LINE__)
69 + rw_lock_create_func((L), (level), __FILE__, __LINE__, #L)
70 # else /* UNIV_SYNC_DEBUG */
71 # define rw_lock_create(K, L, level) \
72 - rw_lock_create_func((L), #L, __FILE__, __LINE__)
73 + rw_lock_create_func((L), __FILE__, __LINE__, #L)
74 # endif/* UNIV_SYNC_DEBUG */
75 # else /* UNIV_DEBUG */
76 # define rw_lock_create(K, L, level) \
77 - rw_lock_create_func((L), __FILE__, __LINE__)
78 + rw_lock_create_func((L), #L)
79 # endif /* UNIV_DEBUG */
81 /**************************************************************//**
84 # ifdef UNIV_SYNC_DEBUG
85 # define rw_lock_create(K, L, level) \
86 - pfs_rw_lock_create_func((K), (L), (level), #L, __FILE__, __LINE__)
87 + pfs_rw_lock_create_func((K), (L), (level), __FILE__, __LINE__, #L)
88 # else /* UNIV_SYNC_DEBUG */
89 # define rw_lock_create(K, L, level) \
90 - pfs_rw_lock_create_func((K), (L), #L, __FILE__, __LINE__)
91 + pfs_rw_lock_create_func((K), (L), __FILE__, __LINE__, #L)
92 # endif/* UNIV_SYNC_DEBUG */
93 # else /* UNIV_DEBUG */
94 # define rw_lock_create(K, L, level) \
95 - pfs_rw_lock_create_func((K), (L), __FILE__, __LINE__)
96 + pfs_rw_lock_create_func((K), (L), #L)
97 # endif /* UNIV_DEBUG */
99 /******************************************************************
100 @@ -256,10 +256,10 @@
101 # ifdef UNIV_SYNC_DEBUG
102 ulint level, /*!< in: level */
103 # endif /* UNIV_SYNC_DEBUG */
104 - const char* cmutex_name, /*!< in: mutex name */
105 -#endif /* UNIV_DEBUG */
106 const char* cfile_name, /*!< in: file name where created */
107 - ulint cline); /*!< in: file line where created */
108 + ulint cline, /*!< in: file line where created */
109 +#endif /* UNIV_DEBUG */
110 + const char* cmutex_name); /*!< in: mutex name */
111 /******************************************************************//**
112 Calling this function is obligatory only if the memory buffer containing
113 the rw-lock is freed. Removes an rw-lock object from the global list. The
115 struct PSI_rwlock *pfs_psi;/*!< The instrumentation hook */
117 ulint count_os_wait; /*!< Count of os_waits. May not be accurate */
118 - const char* cfile_name;/*!< File name where lock created */
119 + //const char* cfile_name;/*!< File name where lock created */
120 + const char* lock_name;/*!< lock name */
121 /* last s-lock file/line is not guaranteed to be correct */
122 const char* last_s_file_name;/*!< File name where last s-locked */
123 const char* last_x_file_name;/*!< File name where last x-locked */
125 are at the start of this struct, thus we can
126 peek this field without causing much memory
128 - unsigned cline:14; /*!< Line where created */
129 + //unsigned cline:14; /*!< Line where created */
130 unsigned last_s_line:14; /*!< Line number where last time s-locked */
131 unsigned last_x_line:14; /*!< Line number where last time x-locked */
133 @@ -692,10 +693,10 @@
134 # ifdef UNIV_SYNC_DEBUG
135 ulint level, /*!< in: level */
136 # endif /* UNIV_SYNC_DEBUG */
137 - const char* cmutex_name, /*!< in: mutex name */
138 -#endif /* UNIV_DEBUG */
139 const char* cfile_name, /*!< in: file name where created */
140 - ulint cline); /*!< in: file line where created */
141 + ulint cline, /*!< in: file line where created */
142 +#endif /* UNIV_DEBUG */
143 + const char* cmutex_name); /*!< in: mutex name */
145 /******************************************************************//**
146 Performance schema instrumented wrap function for rw_lock_x_lock_func()
147 diff -ruN a/storage/innobase/include/sync0rw.ic b/storage/innobase/include/sync0rw.ic
148 --- a/storage/innobase/include/sync0rw.ic 2010-11-03 07:01:13.000000000 +0900
149 +++ b/storage/innobase/include/sync0rw.ic 2010-12-03 17:35:12.980024605 +0900
150 @@ -640,10 +640,10 @@
151 # ifdef UNIV_SYNC_DEBUG
152 ulint level, /*!< in: level */
153 # endif /* UNIV_SYNC_DEBUG */
154 - const char* cmutex_name, /*!< in: mutex name */
155 -# endif /* UNIV_DEBUG */
156 const char* cfile_name, /*!< in: file name where created */
157 - ulint cline) /*!< in: file line where created */
158 + ulint cline, /*!< in: file line where created */
159 +# endif /* UNIV_DEBUG */
160 + const char* cmutex_name) /*!< in: mutex name */
162 /* Initialize the rwlock for performance schema */
163 lock->pfs_psi = (PSI_server && PFS_IS_INSTRUMENTED(key))
164 @@ -656,10 +656,10 @@
165 # ifdef UNIV_SYNC_DEBUG
167 # endif /* UNIV_SYNC_DEBUG */
169 -# endif /* UNIV_DEBUG */
173 +# endif /* UNIV_DEBUG */
176 /******************************************************************//**
177 Performance schema instrumented wrap function for rw_lock_x_lock_func()
178 diff -ruN a/storage/innobase/include/sync0sync.h b/storage/innobase/include/sync0sync.h
179 --- a/storage/innobase/include/sync0sync.h 2010-12-03 15:49:59.227955503 +0900
180 +++ b/storage/innobase/include/sync0sync.h 2010-12-03 17:35:12.982023946 +0900
181 @@ -158,14 +158,14 @@
183 # ifdef UNIV_SYNC_DEBUG
184 # define mutex_create(K, M, level) \
185 - pfs_mutex_create_func((K), (M), #M, (level), __FILE__, __LINE__)
186 + pfs_mutex_create_func((K), (M), (level), __FILE__, __LINE__, #M)
188 # define mutex_create(K, M, level) \
189 - pfs_mutex_create_func((K), (M), #M, __FILE__, __LINE__)
190 + pfs_mutex_create_func((K), (M), __FILE__, __LINE__, #M)
191 # endif/* UNIV_SYNC_DEBUG */
193 # define mutex_create(K, M, level) \
194 - pfs_mutex_create_func((K), (M), __FILE__, __LINE__)
195 + pfs_mutex_create_func((K), (M), #M)
196 # endif /* UNIV_DEBUG */
198 # define mutex_enter(M) \
199 @@ -185,14 +185,14 @@
201 # ifdef UNIV_SYNC_DEBUG
202 # define mutex_create(K, M, level) \
203 - mutex_create_func((M), #M, (level), __FILE__, __LINE__)
204 + mutex_create_func((M), (level), __FILE__, __LINE__, #M)
205 # else /* UNIV_SYNC_DEBUG */
206 # define mutex_create(K, M, level) \
207 - mutex_create_func((M), #M, __FILE__, __LINE__)
208 + mutex_create_func((M), __FILE__, __LINE__, #M)
209 # endif /* UNIV_SYNC_DEBUG */
210 # else /* UNIV_DEBUG */
211 # define mutex_create(K, M, level) \
212 - mutex_create_func((M), __FILE__, __LINE__)
213 + mutex_create_func((M), #M)
214 # endif /* UNIV_DEBUG */
216 # define mutex_enter(M) mutex_enter_func((M), __FILE__, __LINE__)
217 @@ -217,13 +217,13 @@
219 mutex_t* mutex, /*!< in: pointer to memory */
221 - const char* cmutex_name, /*!< in: mutex name */
222 # ifdef UNIV_SYNC_DEBUG
223 ulint level, /*!< in: level */
224 # endif /* UNIV_SYNC_DEBUG */
225 -#endif /* UNIV_DEBUG */
226 const char* cfile_name, /*!< in: file name where created */
227 - ulint cline); /*!< in: file line where created */
228 + ulint cline, /*!< in: file line where created */
229 +#endif /* UNIV_DEBUG */
230 + const char* cmutex_name); /*!< in: mutex name */
232 /******************************************************************//**
233 NOTE! Use the corresponding macro mutex_free(), not directly this function!
234 @@ -291,13 +291,13 @@
235 PSI_mutex_key key, /*!< in: Performance Schema key */
236 mutex_t* mutex, /*!< in: pointer to memory */
238 - const char* cmutex_name, /*!< in: mutex name */
239 # ifdef UNIV_SYNC_DEBUG
240 ulint level, /*!< in: level */
241 # endif /* UNIV_SYNC_DEBUG */
242 -# endif /* UNIV_DEBUG */
243 const char* cfile_name, /*!< in: file name where created */
244 - ulint cline); /*!< in: file line where created */
245 + ulint cline, /*!< in: file line where created */
246 +# endif /* UNIV_DEBUG */
247 + const char* cmutex_name);
248 /******************************************************************//**
249 NOTE! Please use the corresponding macro mutex_enter(), not directly
252 ulint line; /*!< Line where the mutex was locked */
253 ulint level; /*!< Level in the global latching order */
254 #endif /* UNIV_SYNC_DEBUG */
256 const char* cfile_name;/*!< File name where mutex created */
257 ulint cline; /*!< Line where created */
259 os_thread_id_t thread_id; /*!< The thread id of the thread
260 which locked the mutex. */
261 ulint magic_n; /*!< MUTEX_MAGIC_N */
263 ulong count_os_yield; /*!< count of os_wait */
264 ulonglong lspent_time; /*!< mutex os_wait timer msec */
265 ulonglong lmax_spent_time;/*!< mutex os_wait timer msec */
266 - const char* cmutex_name; /*!< mutex name */
267 ulint mutex_type; /*!< 0=usual mutex, 1=rw_lock mutex */
268 #endif /* UNIV_DEBUG */
269 + const char* cmutex_name; /*!< mutex name */
270 #ifdef UNIV_PFS_MUTEX
271 struct PSI_mutex* pfs_psi; /*!< The performance schema
272 instrumentation hook */
273 diff -ruN a/storage/innobase/include/sync0sync.ic b/storage/innobase/include/sync0sync.ic
274 --- a/storage/innobase/include/sync0sync.ic 2010-11-03 07:01:13.000000000 +0900
275 +++ b/storage/innobase/include/sync0sync.ic 2010-12-03 17:35:12.984024599 +0900
276 @@ -321,13 +321,13 @@
277 mysql_pfs_key_t key, /*!< in: Performance Schema key */
278 mutex_t* mutex, /*!< in: pointer to memory */
280 - const char* cmutex_name, /*!< in: mutex name */
281 # ifdef UNIV_SYNC_DEBUG
282 ulint level, /*!< in: level */
283 # endif /* UNIV_SYNC_DEBUG */
284 -# endif /* UNIV_DEBUG */
285 const char* cfile_name, /*!< in: file name where created */
286 - ulint cline) /*!< in: file line where created */
287 + ulint cline, /*!< in: file line where created */
288 +# endif /* UNIV_DEBUG */
289 + const char* cmutex_name) /*!< in: mutex name */
291 mutex->pfs_psi = (PSI_server && PFS_IS_INSTRUMENTED(key))
292 ? PSI_server->init_mutex(key, mutex)
293 @@ -335,13 +335,13 @@
295 mutex_create_func(mutex,
298 # ifdef UNIV_SYNC_DEBUG
300 # endif /* UNIV_SYNC_DEBUG */
301 -# endif /* UNIV_DEBUG */
305 +# endif /* UNIV_DEBUG */
308 /******************************************************************//**
309 NOTE! Please use the corresponding macro mutex_free(), not directly
310 diff -ruN a/storage/innobase/sync/sync0arr.c b/storage/innobase/sync/sync0arr.c
311 --- a/storage/innobase/sync/sync0arr.c 2010-12-03 15:09:51.304953409 +0900
312 +++ b/storage/innobase/sync/sync0arr.c 2010-12-03 17:35:12.985024561 +0900
313 @@ -489,13 +489,12 @@
314 mutex = cell->old_wait_mutex;
317 - "Mutex at %p created file %s line %lu, lock var %lu\n"
318 + "Mutex at %p '%s', lock var %lu\n"
319 #ifdef UNIV_SYNC_DEBUG
320 "Last time reserved in file %s line %lu, "
321 #endif /* UNIV_SYNC_DEBUG */
322 "waiters flag %lu\n",
323 - (void*) mutex, innobase_basename(mutex->cfile_name),
324 - (ulong) mutex->cline,
325 + (void*) mutex, mutex->cmutex_name,
326 (ulong) mutex->lock_word,
327 #ifdef UNIV_SYNC_DEBUG
328 mutex->file_name, (ulong) mutex->line,
330 rwlock = cell->old_wait_rw_lock;
333 - " RW-latch at %p created in file %s line %lu\n",
334 - (void*) rwlock, innobase_basename(rwlock->cfile_name),
335 - (ulong) rwlock->cline);
336 + " RW-latch at %p '%s'\n",
337 + (void*) rwlock, rwlock->lock_name);
338 writer = rw_lock_get_writer(rwlock);
339 if (writer != RW_LOCK_NOT_LOCKED) {
341 diff -ruN a/storage/innobase/sync/sync0rw.c b/storage/innobase/sync/sync0rw.c
342 --- a/storage/innobase/sync/sync0rw.c 2010-11-03 07:01:13.000000000 +0900
343 +++ b/storage/innobase/sync/sync0rw.c 2010-12-03 17:35:12.987029059 +0900
344 @@ -242,10 +242,10 @@
345 # ifdef UNIV_SYNC_DEBUG
346 ulint level, /*!< in: level */
347 # endif /* UNIV_SYNC_DEBUG */
348 - const char* cmutex_name, /*!< in: mutex name */
349 -#endif /* UNIV_DEBUG */
350 const char* cfile_name, /*!< in: file name where created */
351 - ulint cline) /*!< in: file line where created */
352 + ulint cline, /*!< in: file line where created */
353 +#endif /* UNIV_DEBUG */
354 + const char* cmutex_name) /*!< in: mutex name */
356 /* If this is the very first time a synchronization object is
357 created, then the following call initializes the sync system. */
358 @@ -254,14 +254,15 @@
359 mutex_create(rw_lock_mutex_key, rw_lock_get_mutex(lock),
360 SYNC_NO_ORDER_CHECK);
362 - lock->mutex.cfile_name = cfile_name;
363 - lock->mutex.cline = cline;
364 + ut_d(lock->mutex.cfile_name = cfile_name);
365 + ut_d(lock->mutex.cline = cline);
367 - ut_d(lock->mutex.cmutex_name = cmutex_name);
368 + lock->mutex.cmutex_name = cmutex_name;
369 ut_d(lock->mutex.mutex_type = 1);
370 #else /* INNODB_RW_LOCKS_USE_ATOMICS */
372 - UT_NOT_USED(cmutex_name);
373 + UT_NOT_USED(cfile_name);
374 + UT_NOT_USED(cline);
376 #endif /* INNODB_RW_LOCKS_USE_ATOMICS */
380 ut_d(lock->magic_n = RW_LOCK_MAGIC_N);
382 - lock->cfile_name = cfile_name;
383 - lock->cline = (unsigned int) cline;
384 + lock->lock_name = cmutex_name;
386 lock->count_os_wait = 0;
387 lock->last_s_file_name = "not yet reserved";
388 @@ -405,11 +405,10 @@
389 if (srv_print_latch_waits) {
391 "Thread %lu spin wait rw-s-lock at %p"
392 - " cfile %s cline %lu rnds %lu\n",
393 + " '%s' rnds %lu\n",
394 (ulong) os_thread_pf(os_thread_get_curr_id()),
396 - innobase_basename(lock->cfile_name),
397 - (ulong) lock->cline, (ulong) i);
398 + lock->lock_name, (ulong) i);
401 /* We try once again to obtain the lock */
403 if (srv_print_latch_waits) {
405 "Thread %lu OS wait rw-s-lock at %p"
406 - " cfile %s cline %lu\n",
408 os_thread_pf(os_thread_get_curr_id()),
410 - innobase_basename(lock->cfile_name),
411 - (ulong) lock->cline);
412 + (void*) lock, lock->lock_name);
415 /* these stats may not be accurate */
417 if (srv_print_latch_waits) {
419 "Thread %lu spin wait rw-x-lock at %p"
420 - " cfile %s cline %lu rnds %lu\n",
421 + " '%s' rnds %lu\n",
422 os_thread_pf(os_thread_get_curr_id()), (void*) lock,
423 - innobase_basename(lock->cfile_name),
424 - (ulong) lock->cline, (ulong) i);
425 + lock->lock_name, (ulong) i);
428 sync_array_reserve_cell(sync_primary_wait_array,
430 if (srv_print_latch_waits) {
432 "Thread %lu OS wait for rw-x-lock at %p"
433 - " cfile %s cline %lu\n",
435 os_thread_pf(os_thread_get_curr_id()), (void*) lock,
436 - innobase_basename(lock->cfile_name),
437 - (ulong) lock->cline);
441 /* these stats may not be accurate */
442 diff -ruN a/storage/innobase/sync/sync0sync.c b/storage/innobase/sync/sync0sync.c
443 --- a/storage/innobase/sync/sync0sync.c 2010-12-03 15:49:59.233955565 +0900
444 +++ b/storage/innobase/sync/sync0sync.c 2010-12-03 17:35:12.989024400 +0900
445 @@ -270,13 +270,13 @@
447 mutex_t* mutex, /*!< in: pointer to memory */
449 - const char* cmutex_name, /*!< in: mutex name */
450 # ifdef UNIV_SYNC_DEBUG
451 ulint level, /*!< in: level */
452 # endif /* UNIV_SYNC_DEBUG */
453 -#endif /* UNIV_DEBUG */
454 const char* cfile_name, /*!< in: file name where created */
455 - ulint cline) /*!< in: file line where created */
456 + ulint cline, /*!< in: file line where created */
457 +#endif /* UNIV_DEBUG */
458 + const char* cmutex_name) /*!< in: mutex name */
460 #if defined(HAVE_ATOMIC_BUILTINS)
461 mutex_reset_lock_word(mutex);
462 @@ -294,11 +294,13 @@
463 mutex->file_name = "not yet reserved";
464 mutex->level = level;
465 #endif /* UNIV_SYNC_DEBUG */
467 mutex->cfile_name = cfile_name;
468 mutex->cline = cline;
469 +#endif /* UNIV_DEBUG */
470 mutex->count_os_wait = 0;
472 mutex->cmutex_name= cmutex_name;
474 mutex->count_using= 0;
475 mutex->mutex_type= 0;
476 mutex->lspent_time= 0;
478 #ifdef UNIV_SRV_PRINT_LATCH_WAITS
480 "Thread %lu spin wait mutex at %p"
481 - " cfile %s cline %lu rnds %lu\n",
482 + " '%s' rnds %lu\n",
483 (ulong) os_thread_pf(os_thread_get_curr_id()), (void*) mutex,
484 - innobase_basename(mutex->cfile_name),
485 - (ulong) mutex->cline, (ulong) i);
486 + mutex->cmutex_name, (ulong) i);
489 mutex_spin_round_count += i;
492 #ifdef UNIV_SRV_PRINT_LATCH_WAITS
494 - "Thread %lu OS wait mutex at %p cfile %s cline %lu rnds %lu\n",
495 + "Thread %lu OS wait mutex at %p '%s' rnds %lu\n",
496 (ulong) os_thread_pf(os_thread_get_curr_id()), (void*) mutex,
497 - innobase_basename(mutex->cfile_name),
498 - (ulong) mutex->cline, (ulong) i);
499 + mutex->cmutex_name, (ulong) i);
502 mutex_os_wait_count++;
505 if (mutex->magic_n == MUTEX_MAGIC_N) {
507 - "Mutex created at %s %lu\n",
508 - innobase_basename(mutex->cfile_name),
509 - (ulong) mutex->cline);
511 + mutex->cmutex_name);
513 if (mutex_get_lock_word(mutex) != 0) {