On Mon, 7 Oct 2024 15:11:16 +0100
Leo Yan <leo.yan@xxxxxxx> wrote:
If a symbol name is longer than the maximum event length (64 bytes),
generate an new event name with below combination:
TruncatedSymbol + '_' + HashString + '__return' + '\0'
`> 46B + 1B + 8B + 8B + 1B = 64 Bytes.
With this change, a probe can be injected for long symbol.
Before:
# nm test_cpp_mangle | grep -E "print_data|Point"
0000000000000cac t _GLOBAL__sub_I__Z62this_is_a_very_very_long_print_data_abcdefghijklmnopqrstuvwxyzi
0000000000000b50 T _Z62this_is_a_very_very_long_print_data_abcdefghijklmnopqrstuvwxyzR5Point
0000000000000b14 T _Z62this_is_a_very_very_long_print_data_abcdefghijklmnopqrstuvwxyzi
# perf probe -x test_cpp_mangle --add \
"_Z62this_is_a_very_very_long_print_data_abcdefghijklmnopqrstuvwxyzi"
snprintf() failed: -7; the event name nbase='_Z62this_is_a_very_very_long_print_data_abcdefghijklmnopqrstuvwxyzi' is too long
Error: Failed to add events.
After:
# perf probe -x test_cpp_mangle --add \
"_Z62this_is_a_very_very_long_print_data_abcdefghijklmnopqrstuvwxyzi"
Probe event='_Z62this_is_a_very_very_long_print_data_abcdefghijklmnopqrstuvwxyzi' is too long (>= 64 bytes).
Generate hashed event name='_Z62this_is_a_very_very_long_print_data_abcdef_91f40679'
Added new event:
probe_test_cpp_mangle: _Z62this_is_a_very_very_long_print_data_abcdef_91f40679
(on _Z62this_is_a_very_very_long_print_data_abcdefghijklmnopqrstuvwxyzi in /mnt/test_cpp_mangle)
You can now use it in all perf tools, such as:
perf record -e probe_test_cpp_mangle: _Z62this_is_a_very_very_long_print_data_abcdef_91f40679 -aR sleep 1
OK, personally, I recommend you to specify event name instead of generating
long event name in this case. But I understand sometimes this kind of feature
is good for someone.
BTW, I would like to confirm. Can't we demangle the symbol name and parse it?