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 - mutex->cfile_name, (ulong) mutex->cline);
17 + buf1len= (uint) my_snprintf(buf1, sizeof(buf1), "%s",
18 + mutex->cmutex_name);
19 buf2len= (uint) my_snprintf(buf2, sizeof(buf2), "os_waits=%lu",
20 (ulong) mutex->count_os_wait);
25 buf1len = (uint) my_snprintf(buf1, sizeof buf1,
27 - block_mutex->cfile_name,
28 - (ulong) block_mutex->cline);
30 + block_mutex->cmutex_name);
31 buf2len = (uint) my_snprintf(buf2, sizeof buf2,
33 (ulong) block_mutex_oswait_count);
38 - buf1len = my_snprintf(buf1, sizeof buf1, "%s:%lu",
39 - lock->cfile_name, (ulong) lock->cline);
40 + buf1len = my_snprintf(buf1, sizeof buf1, "%s",
42 buf2len = my_snprintf(buf2, sizeof buf2, "os_waits=%lu",
43 (ulong) lock->count_os_wait);
48 buf1len = (uint) my_snprintf(buf1, sizeof buf1,
50 - block_lock->cfile_name,
51 - (ulong) block_lock->cline);
53 + block_lock->lock_name);
54 buf2len = (uint) my_snprintf(buf2, sizeof buf2,
56 (ulong) block_lock_oswait_count);
57 diff -ruN a/storage/innobase/include/sync0rw.h b/storage/innobase/include/sync0rw.h
58 --- a/storage/innobase/include/sync0rw.h 2010-12-03 15:49:59.225953164 +0900
59 +++ b/storage/innobase/include/sync0rw.h 2010-12-03 17:35:12.978024458 +0900
62 # ifdef UNIV_SYNC_DEBUG
63 # define rw_lock_create(K, L, level) \
64 - rw_lock_create_func((L), (level), #L, __FILE__, __LINE__)
65 + rw_lock_create_func((L), (level), __FILE__, __LINE__, #L)
66 # else /* UNIV_SYNC_DEBUG */
67 # define rw_lock_create(K, L, level) \
68 - rw_lock_create_func((L), #L, __FILE__, __LINE__)
69 + rw_lock_create_func((L), __FILE__, __LINE__, #L)
70 # endif/* UNIV_SYNC_DEBUG */
71 # else /* UNIV_DEBUG */
72 # define rw_lock_create(K, L, level) \
73 - rw_lock_create_func((L), __FILE__, __LINE__)
74 + rw_lock_create_func((L), #L)
75 # endif /* UNIV_DEBUG */
77 /**************************************************************//**
80 # ifdef UNIV_SYNC_DEBUG
81 # define rw_lock_create(K, L, level) \
82 - pfs_rw_lock_create_func((K), (L), (level), #L, __FILE__, __LINE__)
83 + pfs_rw_lock_create_func((K), (L), (level), __FILE__, __LINE__, #L)
84 # else /* UNIV_SYNC_DEBUG */
85 # define rw_lock_create(K, L, level) \
86 - pfs_rw_lock_create_func((K), (L), #L, __FILE__, __LINE__)
87 + pfs_rw_lock_create_func((K), (L), __FILE__, __LINE__, #L)
88 # endif/* UNIV_SYNC_DEBUG */
89 # else /* UNIV_DEBUG */
90 # define rw_lock_create(K, L, level) \
91 - pfs_rw_lock_create_func((K), (L), __FILE__, __LINE__)
92 + pfs_rw_lock_create_func((K), (L), #L)
93 # endif /* UNIV_DEBUG */
95 /******************************************************************
97 # ifdef UNIV_SYNC_DEBUG
98 ulint level, /*!< in: level */
99 # endif /* UNIV_SYNC_DEBUG */
100 - const char* cmutex_name, /*!< in: mutex name */
101 -#endif /* UNIV_DEBUG */
102 const char* cfile_name, /*!< in: file name where created */
103 - ulint cline); /*!< in: file line where created */
104 + ulint cline, /*!< in: file line where created */
105 +#endif /* UNIV_DEBUG */
106 + const char* cmutex_name); /*!< in: mutex name */
107 /******************************************************************//**
108 Calling this function is obligatory only if the memory buffer containing
109 the rw-lock is freed. Removes an rw-lock object from the global list. The
111 struct PSI_rwlock *pfs_psi;/*!< The instrumentation hook */
113 ulint count_os_wait; /*!< Count of os_waits. May not be accurate */
114 - const char* cfile_name;/*!< File name where lock created */
115 + //const char* cfile_name;/*!< File name where lock created */
116 + const char* lock_name;/*!< lock name */
117 /* last s-lock file/line is not guaranteed to be correct */
118 const char* last_s_file_name;/*!< File name where last s-locked */
119 const char* last_x_file_name;/*!< File name where last x-locked */
121 are at the start of this struct, thus we can
122 peek this field without causing much memory
124 - unsigned cline:14; /*!< Line where created */
125 + //unsigned cline:14; /*!< Line where created */
126 unsigned last_s_line:14; /*!< Line number where last time s-locked */
127 unsigned last_x_line:14; /*!< Line number where last time x-locked */
129 @@ -692,10 +693,10 @@
130 # ifdef UNIV_SYNC_DEBUG
131 ulint level, /*!< in: level */
132 # endif /* UNIV_SYNC_DEBUG */
133 - const char* cmutex_name, /*!< in: mutex name */
134 -#endif /* UNIV_DEBUG */
135 const char* cfile_name, /*!< in: file name where created */
136 - ulint cline); /*!< in: file line where created */
137 + ulint cline, /*!< in: file line where created */
138 +#endif /* UNIV_DEBUG */
139 + const char* cmutex_name); /*!< in: mutex name */
141 /******************************************************************//**
142 Performance schema instrumented wrap function for rw_lock_x_lock_func()
143 diff -ruN a/storage/innobase/include/sync0rw.ic b/storage/innobase/include/sync0rw.ic
144 --- a/storage/innobase/include/sync0rw.ic 2010-11-03 07:01:13.000000000 +0900
145 +++ b/storage/innobase/include/sync0rw.ic 2010-12-03 17:35:12.980024605 +0900
146 @@ -640,10 +640,10 @@
147 # ifdef UNIV_SYNC_DEBUG
148 ulint level, /*!< in: level */
149 # endif /* UNIV_SYNC_DEBUG */
150 - const char* cmutex_name, /*!< in: mutex name */
151 -# endif /* UNIV_DEBUG */
152 const char* cfile_name, /*!< in: file name where created */
153 - ulint cline) /*!< in: file line where created */
154 + ulint cline, /*!< in: file line where created */
155 +# endif /* UNIV_DEBUG */
156 + const char* cmutex_name) /*!< in: mutex name */
158 /* Initialize the rwlock for performance schema */
159 lock->pfs_psi = (PSI_server && PFS_IS_INSTRUMENTED(key))
160 @@ -656,10 +656,10 @@
161 # ifdef UNIV_SYNC_DEBUG
163 # endif /* UNIV_SYNC_DEBUG */
165 -# endif /* UNIV_DEBUG */
169 +# endif /* UNIV_DEBUG */
172 /******************************************************************//**
173 Performance schema instrumented wrap function for rw_lock_x_lock_func()
174 diff -ruN a/storage/innobase/include/sync0sync.h b/storage/innobase/include/sync0sync.h
175 --- a/storage/innobase/include/sync0sync.h 2010-12-03 15:49:59.227955503 +0900
176 +++ b/storage/innobase/include/sync0sync.h 2010-12-03 17:35:12.982023946 +0900
177 @@ -159,14 +159,14 @@
179 # ifdef UNIV_SYNC_DEBUG
180 # define mutex_create(K, M, level) \
181 - pfs_mutex_create_func((K), (M), #M, (level), __FILE__, __LINE__)
182 + pfs_mutex_create_func((K), (M), (level), __FILE__, __LINE__, #M)
184 # define mutex_create(K, M, level) \
185 - pfs_mutex_create_func((K), (M), #M, __FILE__, __LINE__)
186 + pfs_mutex_create_func((K), (M), __FILE__, __LINE__, #M)
187 # endif/* UNIV_SYNC_DEBUG */
189 # define mutex_create(K, M, level) \
190 - pfs_mutex_create_func((K), (M), __FILE__, __LINE__)
191 + pfs_mutex_create_func((K), (M), #M)
192 # endif /* UNIV_DEBUG */
194 # define mutex_enter(M) \
195 @@ -186,14 +186,14 @@
197 # ifdef UNIV_SYNC_DEBUG
198 # define mutex_create(K, M, level) \
199 - mutex_create_func((M), #M, (level), __FILE__, __LINE__)
200 + mutex_create_func((M), (level), __FILE__, __LINE__, #M)
201 # else /* UNIV_SYNC_DEBUG */
202 # define mutex_create(K, M, level) \
203 - mutex_create_func((M), #M, __FILE__, __LINE__)
204 + mutex_create_func((M), __FILE__, __LINE__, #M)
205 # endif /* UNIV_SYNC_DEBUG */
206 # else /* UNIV_DEBUG */
207 # define mutex_create(K, M, level) \
208 - mutex_create_func((M), __FILE__, __LINE__)
209 + mutex_create_func((M), #M)
210 # endif /* UNIV_DEBUG */
212 # define mutex_enter(M) mutex_enter_func((M), __FILE__, __LINE__)
213 @@ -218,13 +218,13 @@
215 mutex_t* mutex, /*!< in: pointer to memory */
217 - const char* cmutex_name, /*!< in: mutex name */
218 # ifdef UNIV_SYNC_DEBUG
219 ulint level, /*!< in: level */
220 # endif /* UNIV_SYNC_DEBUG */
221 -#endif /* UNIV_DEBUG */
222 const char* cfile_name, /*!< in: file name where created */
223 - ulint cline); /*!< in: file line where created */
224 + ulint cline, /*!< in: file line where created */
225 +#endif /* UNIV_DEBUG */
226 + const char* cmutex_name); /*!< in: mutex name */
228 /******************************************************************//**
229 NOTE! Use the corresponding macro mutex_free(), not directly this function!
230 @@ -292,13 +292,13 @@
231 PSI_mutex_key key, /*!< in: Performance Schema key */
232 mutex_t* mutex, /*!< in: pointer to memory */
234 - const char* cmutex_name, /*!< in: mutex name */
235 # ifdef UNIV_SYNC_DEBUG
236 ulint level, /*!< in: level */
237 # endif /* UNIV_SYNC_DEBUG */
238 -# endif /* UNIV_DEBUG */
239 const char* cfile_name, /*!< in: file name where created */
240 - ulint cline); /*!< in: file line where created */
241 + ulint cline, /*!< in: file line where created */
242 +# endif /* UNIV_DEBUG */
243 + const char* cmutex_name);
244 /******************************************************************//**
245 NOTE! Please use the corresponding macro mutex_enter(), not directly
248 ulint line; /*!< Line where the mutex was locked */
249 ulint level; /*!< Level in the global latching order */
250 #endif /* UNIV_SYNC_DEBUG */
252 const char* cfile_name;/*!< File name where mutex created */
253 ulint cline; /*!< Line where created */
255 os_thread_id_t thread_id; /*!< The thread id of the thread
256 which locked the mutex. */
257 ulint magic_n; /*!< MUTEX_MAGIC_N */
259 ulong count_os_yield; /*!< count of os_wait */
260 ulonglong lspent_time; /*!< mutex os_wait timer msec */
261 ulonglong lmax_spent_time;/*!< mutex os_wait timer msec */
262 - const char* cmutex_name; /*!< mutex name */
263 ulint mutex_type; /*!< 0=usual mutex, 1=rw_lock mutex */
264 #endif /* UNIV_DEBUG */
265 + const char* cmutex_name; /*!< mutex name */
266 #ifdef UNIV_PFS_MUTEX
267 struct PSI_mutex* pfs_psi; /*!< The performance schema
268 instrumentation hook */
269 diff -ruN a/storage/innobase/include/sync0sync.ic b/storage/innobase/include/sync0sync.ic
270 --- a/storage/innobase/include/sync0sync.ic 2010-11-03 07:01:13.000000000 +0900
271 +++ b/storage/innobase/include/sync0sync.ic 2010-12-03 17:35:12.984024599 +0900
272 @@ -321,13 +321,13 @@
273 mysql_pfs_key_t key, /*!< in: Performance Schema key */
274 mutex_t* mutex, /*!< in: pointer to memory */
276 - const char* cmutex_name, /*!< in: mutex name */
277 # ifdef UNIV_SYNC_DEBUG
278 ulint level, /*!< in: level */
279 # endif /* UNIV_SYNC_DEBUG */
280 -# endif /* UNIV_DEBUG */
281 const char* cfile_name, /*!< in: file name where created */
282 - ulint cline) /*!< in: file line where created */
283 + ulint cline, /*!< in: file line where created */
284 +# endif /* UNIV_DEBUG */
285 + const char* cmutex_name) /*!< in: mutex name */
287 mutex->pfs_psi = (PSI_server && PFS_IS_INSTRUMENTED(key))
288 ? PSI_server->init_mutex(key, mutex)
289 @@ -335,13 +335,13 @@
291 mutex_create_func(mutex,
294 # ifdef UNIV_SYNC_DEBUG
296 # endif /* UNIV_SYNC_DEBUG */
297 -# endif /* UNIV_DEBUG */
301 +# endif /* UNIV_DEBUG */
304 /******************************************************************//**
305 NOTE! Please use the corresponding macro mutex_free(), not directly
306 diff -ruN a/storage/innobase/sync/sync0arr.c b/storage/innobase/sync/sync0arr.c
307 --- a/storage/innobase/sync/sync0arr.c 2010-12-03 15:09:51.304953409 +0900
308 +++ b/storage/innobase/sync/sync0arr.c 2010-12-03 17:35:12.985024561 +0900
309 @@ -488,12 +488,12 @@
310 mutex = cell->old_wait_mutex;
313 - "Mutex at %p created file %s line %lu, lock var %lu\n"
314 + "Mutex at %p '%s', lock var %lu\n"
315 #ifdef UNIV_SYNC_DEBUG
316 "Last time reserved in file %s line %lu, "
317 #endif /* UNIV_SYNC_DEBUG */
318 "waiters flag %lu\n",
319 - (void*) mutex, mutex->cfile_name, (ulong) mutex->cline,
320 + (void*) mutex, mutex->cmutex_name,
321 (ulong) mutex->lock_word,
322 #ifdef UNIV_SYNC_DEBUG
323 mutex->file_name, (ulong) mutex->line,
325 rwlock = cell->old_wait_rw_lock;
328 - " RW-latch at %p created in file %s line %lu\n",
329 - (void*) rwlock, rwlock->cfile_name,
330 - (ulong) rwlock->cline);
331 + " RW-latch at %p '%s'\n",
332 + (void*) rwlock, rwlock->lock_name);
333 writer = rw_lock_get_writer(rwlock);
334 if (writer != RW_LOCK_NOT_LOCKED) {
336 diff -ruN a/storage/innobase/sync/sync0rw.c b/storage/innobase/sync/sync0rw.c
337 --- a/storage/innobase/sync/sync0rw.c 2010-11-03 07:01:13.000000000 +0900
338 +++ b/storage/innobase/sync/sync0rw.c 2010-12-03 17:35:12.987029059 +0900
339 @@ -241,10 +241,10 @@
340 # ifdef UNIV_SYNC_DEBUG
341 ulint level, /*!< in: level */
342 # endif /* UNIV_SYNC_DEBUG */
343 - const char* cmutex_name, /*!< in: mutex name */
344 -#endif /* UNIV_DEBUG */
345 const char* cfile_name, /*!< in: file name where created */
346 - ulint cline) /*!< in: file line where created */
347 + ulint cline, /*!< in: file line where created */
348 +#endif /* UNIV_DEBUG */
349 + const char* cmutex_name) /*!< in: mutex name */
351 /* If this is the very first time a synchronization object is
352 created, then the following call initializes the sync system. */
353 @@ -253,14 +253,15 @@
354 mutex_create(rw_lock_mutex_key, rw_lock_get_mutex(lock),
355 SYNC_NO_ORDER_CHECK);
357 - lock->mutex.cfile_name = cfile_name;
358 - lock->mutex.cline = cline;
359 + ut_d(lock->mutex.cfile_name = cfile_name);
360 + ut_d(lock->mutex.cline = cline);
362 - ut_d(lock->mutex.cmutex_name = cmutex_name);
363 + lock->mutex.cmutex_name = cmutex_name;
364 ut_d(lock->mutex.mutex_type = 1);
365 #else /* INNODB_RW_LOCKS_USE_ATOMICS */
367 - UT_NOT_USED(cmutex_name);
368 + UT_NOT_USED(cfile_name);
369 + UT_NOT_USED(cline);
371 #endif /* INNODB_RW_LOCKS_USE_ATOMICS */
375 ut_d(lock->magic_n = RW_LOCK_MAGIC_N);
377 - lock->cfile_name = cfile_name;
378 - lock->cline = (unsigned int) cline;
379 + lock->lock_name = cmutex_name;
381 lock->count_os_wait = 0;
382 lock->last_s_file_name = "not yet reserved";
383 @@ -401,10 +401,10 @@
384 if (srv_print_latch_waits) {
386 "Thread %lu spin wait rw-s-lock at %p"
387 - " cfile %s cline %lu rnds %lu\n",
388 + " '%s' rnds %lu\n",
389 (ulong) os_thread_pf(os_thread_get_curr_id()),
391 - lock->cfile_name, (ulong) lock->cline, (ulong) i);
392 + lock->lock_name, (ulong) i);
395 /* We try once again to obtain the lock */
397 if (srv_print_latch_waits) {
399 "Thread %lu OS wait rw-s-lock at %p"
400 - " cfile %s cline %lu\n",
402 os_thread_pf(os_thread_get_curr_id()),
403 - (void*) lock, lock->cfile_name,
404 - (ulong) lock->cline);
405 + (void*) lock, lock->lock_name);
408 /* these stats may not be accurate */
410 if (srv_print_latch_waits) {
412 "Thread %lu spin wait rw-x-lock at %p"
413 - " cfile %s cline %lu rnds %lu\n",
414 + " '%s' rnds %lu\n",
415 os_thread_pf(os_thread_get_curr_id()), (void*) lock,
416 - lock->cfile_name, (ulong) lock->cline, (ulong) i);
417 + lock->lock_name, (ulong) i);
420 sync_array_reserve_cell(sync_primary_wait_array,
422 if (srv_print_latch_waits) {
424 "Thread %lu OS wait for rw-x-lock at %p"
425 - " cfile %s cline %lu\n",
427 os_thread_pf(os_thread_get_curr_id()), (void*) lock,
428 - lock->cfile_name, (ulong) lock->cline);
432 /* these stats may not be accurate */
433 diff -ruN a/storage/innobase/sync/sync0sync.c b/storage/innobase/sync/sync0sync.c
434 --- a/storage/innobase/sync/sync0sync.c 2010-12-03 15:49:59.233955565 +0900
435 +++ b/storage/innobase/sync/sync0sync.c 2010-12-03 17:35:12.989024400 +0900
436 @@ -269,13 +269,13 @@
438 mutex_t* mutex, /*!< in: pointer to memory */
440 - const char* cmutex_name, /*!< in: mutex name */
441 # ifdef UNIV_SYNC_DEBUG
442 ulint level, /*!< in: level */
443 # endif /* UNIV_SYNC_DEBUG */
444 -#endif /* UNIV_DEBUG */
445 const char* cfile_name, /*!< in: file name where created */
446 - ulint cline) /*!< in: file line where created */
447 + ulint cline, /*!< in: file line where created */
448 +#endif /* UNIV_DEBUG */
449 + const char* cmutex_name) /*!< in: mutex name */
451 #if defined(HAVE_ATOMIC_BUILTINS)
452 mutex_reset_lock_word(mutex);
453 @@ -293,11 +293,13 @@
454 mutex->file_name = "not yet reserved";
455 mutex->level = level;
456 #endif /* UNIV_SYNC_DEBUG */
458 mutex->cfile_name = cfile_name;
459 mutex->cline = cline;
460 +#endif /* UNIV_DEBUG */
461 mutex->count_os_wait = 0;
463 mutex->cmutex_name= cmutex_name;
465 mutex->count_using= 0;
466 mutex->mutex_type= 0;
467 mutex->lspent_time= 0;
469 #ifdef UNIV_SRV_PRINT_LATCH_WAITS
471 "Thread %lu spin wait mutex at %p"
472 - " cfile %s cline %lu rnds %lu\n",
473 + " '%s' rnds %lu\n",
474 (ulong) os_thread_pf(os_thread_get_curr_id()), (void*) mutex,
475 - mutex->cfile_name, (ulong) mutex->cline, (ulong) i);
476 + mutex->cmutex_name, (ulong) i);
479 mutex_spin_round_count += i;
482 #ifdef UNIV_SRV_PRINT_LATCH_WAITS
484 - "Thread %lu OS wait mutex at %p cfile %s cline %lu rnds %lu\n",
485 + "Thread %lu OS wait mutex at %p '%s' rnds %lu\n",
486 (ulong) os_thread_pf(os_thread_get_curr_id()), (void*) mutex,
487 - mutex->cfile_name, (ulong) mutex->cline, (ulong) i);
488 + mutex->cmutex_name, (ulong) i);
491 mutex_os_wait_count++;
494 if (mutex->magic_n == MUTEX_MAGIC_N) {
496 - "Mutex created at %s %lu\n",
497 - mutex->cfile_name, (ulong) mutex->cline);
499 + mutex->cmutex_name);
501 if (mutex_get_lock_word(mutex) != 0) {