[PATCH v2 3/3] perf probe: Improve log for long event name failure

Leo Yan posted 3 patches 1 month, 2 weeks ago
There is a newer version of this series
[PATCH v2 3/3] perf probe: Improve log for long event name failure
Posted by Leo Yan 1 month, 2 weeks ago
If a symbol name is longer than the maximum event length (64 bytes), the
perf tool reports error:

  # perf probe -x test_cpp_mangle --add "this_is_a_very_very_long_print_data_abcdefghijklmnopqrstuvwxyz(int)"
    snprintf() failed: -7; the event name nbase='this_is_a_very_very_long_print_data_abcdefghijklmnopqrstuvwxyz(int)' is too long
    Error: Failed to add events.

An information is missed in the log that the symbol name and the event
name can be set separately. Especially, this is recommended for adding
probe for a long symbol.

This commit refines the log for reminding event syntax.

After:

  # perf probe -x test_cpp_mangle --add "this_is_a_very_very_long_print_data_abcdefghijklmnopqrstuvwxyz(int)"
    snprintf() failed: -7; the event name is too long (>= 64 bytes)
      Try to set event with syntax "[GROUP:]EVENT=this_is_a_very_very_long_print_data_abcdefghijklmnopqrstuvwxyz(int)"
      Error: Failed to add events.

Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 tools/perf/util/probe-event.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 224ec6818803..441daf4fb321 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -2760,7 +2760,9 @@ static int get_new_event_name(char *buf, size_t len, const char *base,
 	/* Try no suffix number */
 	ret = e_snprintf(buf, len, "%s%s", nbase, ret_event ? "__return" : "");
 	if (ret < 0) {
-		pr_warning("snprintf() failed: %d; the event name nbase='%s' is too long\n", ret, nbase);
+		pr_warning("snprintf() failed: %d; the event name is too long (>= %d bytes)\n"
+			   "  Try to set event with syntax \"[GROUP:]EVENT=%s\"\n",
+			   ret, MAX_EVENT_NAME_LEN, nbase);
 		goto out;
 	}
 	if (!strlist__has_entry(namelist, buf))
-- 
2.25.1
Re: [PATCH v2 3/3] perf probe: Improve log for long event name failure
Posted by Leo Yan 1 month, 2 weeks ago
On 10/12/2024 4:44 PM, Leo Yan wrote:
> If a symbol name is longer than the maximum event length (64 bytes), the
> perf tool reports error:
> 
>   # perf probe -x test_cpp_mangle --add "this_is_a_very_very_long_print_data_abcdefghijklmnopqrstuvwxyz(int)"
>     snprintf() failed: -7; the event name nbase='this_is_a_very_very_long_print_data_abcdefghijklmnopqrstuvwxyz(int)' is too long
>     Error: Failed to add events.
> 
> An information is missed in the log that the symbol name and the event
> name can be set separately. Especially, this is recommended for adding
> probe for a long symbol.
> 
> This commit refines the log for reminding event syntax.
> 
> After:
> 
>   # perf probe -x test_cpp_mangle --add "this_is_a_very_very_long_print_data_abcdefghijklmnopqrstuvwxyz(int)"
>     snprintf() failed: -7; the event name is too long (>= 64 bytes)
>       Try to set event with syntax "[GROUP:]EVENT=this_is_a_very_very_long_print_data_abcdefghijklmnopqrstuvwxyz(int)"
>       Error: Failed to add events.

As the printed log is not suitable for all cases in this patch, please
ignore this patch and directly review version 3 for a updated log.

Thanks,
Leo

> 
> Signed-off-by: Leo Yan <leo.yan@arm.com>
> ---
>  tools/perf/util/probe-event.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
> index 224ec6818803..441daf4fb321 100644
> --- a/tools/perf/util/probe-event.c
> +++ b/tools/perf/util/probe-event.c
> @@ -2760,7 +2760,9 @@ static int get_new_event_name(char *buf, size_t len, const char *base,
>  	/* Try no suffix number */
>  	ret = e_snprintf(buf, len, "%s%s", nbase, ret_event ? "__return" : "");
>  	if (ret < 0) {
> -		pr_warning("snprintf() failed: %d; the event name nbase='%s' is too long\n", ret, nbase);
> +		pr_warning("snprintf() failed: %d; the event name is too long (>= %d bytes)\n"
> +			   "  Try to set event with syntax \"[GROUP:]EVENT=%s\"\n",
> +			   ret, MAX_EVENT_NAME_LEN, nbase);
>  		goto out;
>  	}
>  	if (!strlist__has_entry(namelist, buf))