perf probe: Improve logs for long name string
v3 cover perf probe: Improve logs for long name string
The series [1] tries to use hashed symbol names for event names. This can avoid failures due to long symbol names. Somehow, it is preferred to specify a distinct event name when adding a probe.
This series follows up on the comment to improve the logs for long event strings.
[1] https://lore.kernel.org/linux-perf-users/[email protected]/T/
Changes from v2:
- Printed a more abstract syntax "EVENT=PROBEDEF" in log.
- Amended warning for adding suffix failure.
Changes from v1:
- Used a patch to add MAX_EVENT_NAME_LEN macro.
- Refined log for long event name failure to replace hashed event name (Masami).
Leo Yan (3):
perf probe: Use the MAX_EVENT_NAME_LEN macro perf probe: Check group string length
perf probe: Improve log for long event name failure
tools/perf/util/probe-event.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
Signature · 1 line
2.25.1
PATCH v3 1/3 perf probe: Use the MAX_EVENT_NAME_LEN macro
The MAX_EVENT_NAME_LEN macro has been defined in the kernel. Use the same definition in the tool for more readable.
--- tools/perf/util/probe-event.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/util/probe-event.c +4 -1
@@ -51,6 +51,9 @@#define PERFPROBE_GROUP "probe" +/* Defined in kernel/trace/trace.h */ +#define MAX_EVENT_NAME_LEN 64 +bool probe_event_dry_run;/* Dry run flag */ struct probe_conf probe_conf = { .magic_num =DEFAULT_PROBE_MAGIC_NUM };
@@ -2841,7 +2844,7 @@ static int probe_trace_event__set_name(struct probe_trace_event *tev, bool allow_suffix) {const char *event, *group; -char buf[64 ]; +char buf[MAX_EVENT_NAME_LEN ];int ret;/* If probe_event or trace_event already have the name, reuse it */
Signature · 1 line
2.25.1
Re: [PATCH v3 1/3] perf probe: Use the MAX_EVENT_NAME_LEN macro
Quoted 3 lines · On Sat, 12 Oct 2024 21:47:23 +0100 Leo Yan <[email protected]> wrote:
The
MAX_EVENT_NAME_LENmacro has been defined in the kernel. Use the same definition in the tool for more readable.
Looks good to me. Thanks!
Quoted 31 lines
Signed-off-by Leo Yan <[email protected]>--- tools/perf/util/probe-event.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)tools/perf/util/probe-event.c +4
-1@@ -51,6 +51,9 @@#define PERFPROBE_GROUP "probe" +/* Defined in kernel/trace/trace.h */ +#define MAX_EVENT_NAME_LEN 64 +bool probe_event_dry_run;/* Dry run flag */ struct probe_conf probe_conf = { .magic_num =DEFAULT_PROBE_MAGIC_NUM };@@ -2841,7 +2844,7 @@ static int probe_trace_event__set_name(struct probe_trace_event *tev, bool allow_suffix) {const char *event, *group; -char buf[64 ]; +char buf[MAX_EVENT_NAME_LEN ];int ret;/* If probe_event or trace_event already have the name, reuse it */ Signature · 1 line
2.25.1
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
PATCH v3 2/3 perf probe: Check group string length
In reply to Leo YanIn the kernel, the probe group string length is limited up to MAX_EVENT_NAME_LEN (including the NULL terminator).
Check for this limitation and report an error if it is exceeded.
--- tools/perf/util/probe-event.c | 6 ++++++ 1 file changed, 6 insertions(+)
tools/perf/util/probe-event.c +6 -0
@@ -2868,6 +2868,12 @@ static int probe_trace_event__set_name(struct probe_trace_event *tev,else group =PERFPROBE_GROUP ; +if (strlen (group) >=MAX_EVENT_NAME_LEN ) { +pr_err ("Probe group string='%s' is too long (>= %d bytes)\n" , + group,MAX_EVENT_NAME_LEN ); +return -ENOMEM ; + } +/* Get an unused new event name */ ret =get_new_event_name (buf,sizeof (buf), event, namelist, tev->point.retprobe, allow_suffix);
Signature · 1 line
2.25.1
PATCH v3 3/3 perf probe: Improve log for long event name failure
In reply to Leo YanIf 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 'this_is_a_very_very_long_print_data_abcdefghijklmnopqrstuvwxyz(int)' is too long
Hint: Set a shorter event with syntax "EVENT=PROBEDEF"
EVENT: Event name (max length: 64 bytes).
Error: Failed to add events.--- tools/perf/util/probe-event.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
tools/perf/util/probe-event.c +8 -2
@@ -2760,7 +2760,10 @@ 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 '%s' is too long\n" +" Hint: Set a shorter event with syntax \"EVENT=PROBEDEF\"\n" +" EVENT: Event name (max length: %d bytes).\n" , + ret, nbase,MAX_EVENT_NAME_LEN ); goto out; }if (!strlist__has_entry (namelist, buf))
@@ -2780,7 +2783,10 @@ static int get_new_event_name(char *buf, size_t len, const char *base,for (i =1 ; i <MAX_EVENT_INDEX ; i++) { ret =e_snprintf (buf, len,"%s_%d" , nbase, i);if (ret <0 ) { -pr_debug ("snprintf() failed: %d\n" , ret); +pr_warning ("Add suffix failed: %d; the event name '%s' is too long\n" +" Hint: Set a shorter event with syntax \"EVENT=PROBEDEF\"\n" +" EVENT: Event name (max length: %d bytes).\n" , + ret, nbase,MAX_EVENT_NAME_LEN ); goto out; }if (!strlist__has_entry (namelist, buf))
Signature · 1 line
2.25.1
Re: [PATCH v3 3/3] perf probe: Improve log for long event name failure
Quoted 13 lines · On Sat, 12 Oct 2024 21:47:25 +0100 Leo Yan <[email protected]> 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.
Quoted 8 lines
After:
# perf probe -x test_cpp_mangle --add "this_is_a_very_very_long_print_data_abcdefghijklmnopqrstuvwxyz(int)" snprintf() failed: -7; the event name 'this_is_a_very_very_long_print_data_abcdefghijklmnopqrstuvwxyz(int)' is too long Hint: Set a shorter event with syntax "EVENT=PROBEDEF" EVENT: Event name (max length: 64 bytes). Error: Failed to add events.
Nice!
Thank you,
Quoted 36 lines
Signed-off-by Leo Yan <[email protected]>--- tools/perf/util/probe-event.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)tools/perf/util/probe-event.c +8
-2@@ -2760,7 +2760,10 @@ 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 '%s' is too long\n" +" Hint: Set a shorter event with syntax \"EVENT=PROBEDEF\"\n" +" EVENT: Event name (max length: %d bytes).\n" , + ret, nbase,MAX_EVENT_NAME_LEN ); goto out; }if (!strlist__has_entry (namelist, buf))@@ -2780,7 +2783,10 @@ static int get_new_event_name(char *buf, size_t len, const char *base,for (i =1 ; i <MAX_EVENT_INDEX ; i++) { ret =e_snprintf (buf, len,"%s_%d" , nbase, i);if (ret <0 ) { -pr_debug ("snprintf() failed: %d\n" , ret); +pr_warning ("Add suffix failed: %d; the event name '%s' is too long\n" +" Hint: Set a shorter event with syntax \"EVENT=PROBEDEF\"\n" +" EVENT: Event name (max length: %d bytes).\n" , + ret, nbase,MAX_EVENT_NAME_LEN ); goto out; }if (!strlist__has_entry (namelist, buf))Signature · 1 line
2.25.1
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
Quoted 8 lines · Leo Yan
The series [1] tries to use hashed symbol names for event names. This can avoid failures due to long symbol names. Somehow, it is preferred to specify a distinct event name when adding a probe.
This series follows up on the comment to improve the logs for long event strings.
[...]
Applied to perf-tools-next, thanks!
Best regards,
Namhyung