Skip to contentSkip to conversation

perf probe: Improve logs for long name string

PATCH Superseded Leo Yan 1 participant 5 messages Oct 12, 2024 perf events

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Leo Yan

author
#0 lore raw

v2 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 group and event strings.

[1] https://lore.kernel.org/linux-perf-users/[email protected]/T/

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 | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH v2 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
index a17c9b8a7a79..061a0412dec2 100644
@@ -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
author
#2 lore raw

PATCH v2 2/3 perf probe: Check group string length

In reply to Leo Yan

In 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
index 061a0412dec2..224ec6818803 100644
@@ -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
author
#3 lore raw

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

In reply to Leo Yan

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.
---
 tools/perf/util/probe-event.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/util/probe-event.c +3 -1
index 224ec6818803..441daf4fb321 100644
@@ -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))
Signature · 1 line
2.25.1
author
#4 lore raw

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

Quoted 11 lines · Leo Yan

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.

Quoted 8 lines

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

Quoted 21 lines
---
 tools/perf/util/probe-event.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/util/probe-event.c +3 -1
index 224ec6818803..441daf4fb321 100644
@@ -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))