MDEV-36676 Add debug function to print MEM_ROOT name#4703
MDEV-36676 Add debug function to print MEM_ROOT name#4703longjinvan wants to merge 1 commit intoMariaDB:mainfrom
Conversation
Add dbug_print_memroot_name function that retrieves and prints the name of a MEM_ROOT from Performance Schema. All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc.
|
|
gkodinov
left a comment
There was a problem hiding this comment.
Thank you for your contribution. This is a preliminary review.
Several things to fix in addition to the actual comments below:
- remove the license reference from the commit message
- make the commit message compliant with CODING_STANDARDS.md
- click on the CLA bot button on the PR github page, pick your license and say "accept". This should clear the CLA bot.
| #ifndef DBUG_OFF | ||
| extern void dbug_print_memroot_name(MEM_ROOT *root); | ||
| #else | ||
| #define dbug_print_memroot_name(A) do {} while(0) |
There was a problem hiding this comment.
Why can't it just be an empty define, similar to e.g. DBUG_ENTER?
|
|
||
| if (!root) | ||
| { | ||
| DBUG_PRINT("info", ("MEM_ROOT: NULL")); |
There was a problem hiding this comment.
I would print to the standard output. The primary use of this is when you're on a debugger console and trying to get the name of the memroot quickly without tweaking the P_S functions. So I'd expect this to print to standard output and not via (the possibly turned off) DBUG_PRINT functions.
Ditto for all the rest of the DBUG_PRINTs in this function.
| @@ -0,0 +1,142 @@ | |||
| /* Copyright (c) 2025, MariaDB Corporation. | |||
There was a problem hiding this comment.
Please convert that to a proper unit test and move it into unittest/. If you go with my advice to move it into PFS, you might need to create a subdirectory of unittest/ for pfs.
| @@ -715,3 +715,42 @@ LEX_STRING lex_string_casedn_root(MEM_ROOT *root, CHARSET_INFO *cs, | |||
| res.str[res.length]= '\0'; | |||
| return res; | |||
| } | |||
|
|
|||
There was a problem hiding this comment.
By defining the function here you're making mysys depend on pfs and thus creating a circular dependency since pfs already depends on mysys.
I'd move the whole function out of mysys to pfs.
Description
MEM_ROOTs used to have names stored inside the structure. Now these names are stored in Performance Schema, making it difficult to retrieve them during debugging.
Add dbug_print_memroot_name() function that retrieves and prints the name of a MEM_ROOT from Performance Schema. The function uses DBUG_PRINT to output the MEM_ROOT name, address, and PSI key. The function is debug-only (wrapped in #ifndef DBUG_OFF) with zero production overhead.
How can this PR be tested?
A new test file
test_memroot_name.chas been added to validate the function. The test is automatically built in Debug mode and verifies that dbug_print_memroot_name() correctly handles NULL pointers, registered PSI keys, PSI_NOT_INSTRUMENTED, and invalid keys.Standalone unit test:
Note: In standalone mode, Performance Schema is not initialized, so PSI name resolution is unavailable and keys will show as 0. The test validates edge case handling and crash safety.
End-to-end test within a running server (verifies full PSI name resolution):
Expected output: MEM_ROOT 'memory/sql/thd::main_mem_root' (0x...) [key=7]
Standalone test output
Trace file (test_memroot_name.trace):
End-to-end server test (grep "MEM_ROOT" /tmp/mysqld.trace):
Basing the PR against the correct MariaDB version
✅ This is a new feature and the PR is based against the latest MariaDB development branch
PR quality check
✅ I have checked the
CODING_STANDARDS.mdfile and my PR conforms to this where appropriate.✅ For any trivial modifications to the PR, I am ok with the reviewer making the changes themselves.
Copyright
All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc.