define print_all_rec_locks set $ht=lock_sys->rec_hash set $i=0 while ($i < $ht->n_cells) set $lck=(struct lock_struct*)$ht->array[$i]->node while ($lck != 0) printf "%p: ", $lck print_lock $lck set $lck=(struct lock_struct*)$lck->hash end set $i=$i+1 end end document print_all_rec_locks Print all the record locks in lock_sys->rec_hash end define print_trx_lock_heap_total set $trx=trx_sys->mysql_trx_list.start set $total=0 while ($trx != 0) set $total=$total+$trx->lock_heap->total_size set $trx=$trx->mysql_trx_list.next end printf "Total memory in all trx lock heaps: %ldM\n", $total/(1024 * 1024) end document print_trx_lock_heap_total Print the total memory used by a transaction's locks end define print_trx_lock_heap_size set $trx=trx_sys->mysql_trx_list.start while ($trx != 0) printf "0x%016lx %8ld\n", $trx, $trx->lock.heap->total_size set $trx=$trx->mysql_trx_list.next end end document print_trx_lock_heap_size Print the memory used by a transaction lock heap end define print_mem_heap set $heap=$arg0 set $base=&$heap->base set $node=$base->start print *$heap while ($node != 0) printf "block: 0x%p len: %lu free: %lu\n", $node->buf_block, $node->len, $node->len - $node->free set $node=$node->list.next end end document print_mem_heap Print the heap base node and length of the heap blocks end define ut_align set $ret=($arg0 + 7) & ~7 end define print_rec_locks_in_block set $ptr=(char*)((buf_block_t*) $arg0)->frame set $memblk=(mem_block_t*) $ptr set $lck=(struct lock_struct*)($ptr+$memblk->start) printf "block: %p\n", $ptr while ($lck < ($ptr + $memblk->free)) printf "%p: ", $lck print_lock $lck set $nbytes=$lck->un_member.rec_lock.n_bits / 8 set $nbytes=$nbytes+sizeof(*$lck) ut_align $nbytes set $lck=(struct lock_struct*) ((char*) $lck+$ret) end end document print_rec_locks_in_block Print all the locks in a heap block. Useful for looking at old locks. end define print_rec_locks_from_heap set $trx=(trx_t*) $arg0 set $heap=$trx->lock_heap set $base=&$heap->base set $node=$base->start while ($node != 0) if ($node->buf_block != 0) print_rec_locks_in_block $node->buf_block end set $node=$node->list.next end end document print_rec_locks_from_heap Work backwards from the heap and print locks. Helpful in printing defunct locks. end