* [PATCH v3 0/3] perf probe: Improve logs for long name string
@ 2024-10-12 20:47 Leo Yan
2024-10-12 20:47 ` [PATCH v3 1/3] perf probe: Use the MAX_EVENT_NAME_LEN macro Leo Yan
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Leo Yan @ 2024-10-12 20:47 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo, Masami Hiramatsu, Namhyung Kim,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Ian Rogers,
Adrian Hunter, Liang, Kan, linux-perf-users, linux-kernel
Cc: 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.
[1] https://lore.kernel.org/linux-perf-users/20241010234818.ab279974ef597f02b61ab850@kernel.org/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(-)
--
2.25.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3 1/3] perf probe: Use the MAX_EVENT_NAME_LEN macro
2024-10-12 20:47 [PATCH v3 0/3] perf probe: Improve logs for long name string Leo Yan
@ 2024-10-12 20:47 ` Leo Yan
2024-10-14 0:46 ` Masami Hiramatsu
2024-10-12 20:47 ` [PATCH v3 2/3] perf probe: Check group string length Leo Yan
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Leo Yan @ 2024-10-12 20:47 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo, Masami Hiramatsu, Namhyung Kim,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Ian Rogers,
Adrian Hunter, Liang, Kan, linux-perf-users, linux-kernel
Cc: Leo Yan
The MAX_EVENT_NAME_LEN macro has been defined in the kernel. Use the
same definition in the tool for more readable.
Signed-off-by: Leo Yan <leo.yan@arm.com>
---
tools/perf/util/probe-event.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index a17c9b8a7a79..061a0412dec2 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -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 */
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v3 2/3] perf probe: Check group string length
2024-10-12 20:47 [PATCH v3 0/3] perf probe: Improve logs for long name string Leo Yan
2024-10-12 20:47 ` [PATCH v3 1/3] perf probe: Use the MAX_EVENT_NAME_LEN macro Leo Yan
@ 2024-10-12 20:47 ` Leo Yan
2024-10-12 20:47 ` [PATCH v3 3/3] perf probe: Improve log for long event name failure Leo Yan
2024-10-17 16:39 ` [PATCH v3 0/3] perf probe: Improve logs for long name string Namhyung Kim
3 siblings, 0 replies; 7+ messages in thread
From: Leo Yan @ 2024-10-12 20:47 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo, Masami Hiramatsu, Namhyung Kim,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Ian Rogers,
Adrian Hunter, Liang, Kan, linux-perf-users, linux-kernel
Cc: 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.
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Leo Yan <leo.yan@arm.com>
---
tools/perf/util/probe-event.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 061a0412dec2..224ec6818803 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -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);
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v3 3/3] perf probe: Improve log for long event name failure
2024-10-12 20:47 [PATCH v3 0/3] perf probe: Improve logs for long name string Leo Yan
2024-10-12 20:47 ` [PATCH v3 1/3] perf probe: Use the MAX_EVENT_NAME_LEN macro Leo Yan
2024-10-12 20:47 ` [PATCH v3 2/3] perf probe: Check group string length Leo Yan
@ 2024-10-12 20:47 ` Leo Yan
2024-10-14 2:24 ` Masami Hiramatsu
2024-10-17 16:39 ` [PATCH v3 0/3] perf probe: Improve logs for long name string Namhyung Kim
3 siblings, 1 reply; 7+ messages in thread
From: Leo Yan @ 2024-10-12 20:47 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo, Masami Hiramatsu, Namhyung Kim,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Ian Rogers,
Adrian Hunter, Liang, Kan, linux-perf-users, linux-kernel
Cc: 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 '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.
Signed-off-by: Leo Yan <leo.yan@arm.com>
---
tools/perf/util/probe-event.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 224ec6818803..2a2fc5e78c5c 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -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))
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v3 1/3] perf probe: Use the MAX_EVENT_NAME_LEN macro
2024-10-12 20:47 ` [PATCH v3 1/3] perf probe: Use the MAX_EVENT_NAME_LEN macro Leo Yan
@ 2024-10-14 0:46 ` Masami Hiramatsu
0 siblings, 0 replies; 7+ messages in thread
From: Masami Hiramatsu @ 2024-10-14 0:46 UTC (permalink / raw)
To: Leo Yan
Cc: Arnaldo Carvalho de Melo, Namhyung Kim, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
Liang, Kan, linux-perf-users, linux-kernel
On Sat, 12 Oct 2024 21:47:23 +0100
Leo Yan <leo.yan@arm.com> wrote:
> The MAX_EVENT_NAME_LEN macro has been defined in the kernel. Use the
> same definition in the tool for more readable.
>
Looks good to me. Thanks!
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> Signed-off-by: Leo Yan <leo.yan@arm.com>
> ---
> tools/perf/util/probe-event.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
> index a17c9b8a7a79..061a0412dec2 100644
> --- a/tools/perf/util/probe-event.c
> +++ b/tools/perf/util/probe-event.c
> @@ -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 */
> --
> 2.25.1
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3 3/3] perf probe: Improve log for long event name failure
2024-10-12 20:47 ` [PATCH v3 3/3] perf probe: Improve log for long event name failure Leo Yan
@ 2024-10-14 2:24 ` Masami Hiramatsu
0 siblings, 0 replies; 7+ messages in thread
From: Masami Hiramatsu @ 2024-10-14 2:24 UTC (permalink / raw)
To: Leo Yan
Cc: Arnaldo Carvalho de Melo, Namhyung Kim, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
Liang, Kan, linux-perf-users, linux-kernel
On Sat, 12 Oct 2024 21:47:25 +0100
Leo Yan <leo.yan@arm.com> 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 '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!
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Thank you,
> Signed-off-by: Leo Yan <leo.yan@arm.com>
> ---
> tools/perf/util/probe-event.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
> index 224ec6818803..2a2fc5e78c5c 100644
> --- a/tools/perf/util/probe-event.c
> +++ b/tools/perf/util/probe-event.c
> @@ -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))
> --
> 2.25.1
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3 0/3] perf probe: Improve logs for long name string
2024-10-12 20:47 [PATCH v3 0/3] perf probe: Improve logs for long name string Leo Yan
` (2 preceding siblings ...)
2024-10-12 20:47 ` [PATCH v3 3/3] perf probe: Improve log for long event name failure Leo Yan
@ 2024-10-17 16:39 ` Namhyung Kim
3 siblings, 0 replies; 7+ messages in thread
From: Namhyung Kim @ 2024-10-17 16:39 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo, Masami Hiramatsu, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
Liang, Kan, linux-perf-users, linux-kernel, Leo Yan
On Sat, 12 Oct 2024 21:47:22 +0100, Leo Yan wrote:
> 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
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-10-17 16:39 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-12 20:47 [PATCH v3 0/3] perf probe: Improve logs for long name string Leo Yan
2024-10-12 20:47 ` [PATCH v3 1/3] perf probe: Use the MAX_EVENT_NAME_LEN macro Leo Yan
2024-10-14 0:46 ` Masami Hiramatsu
2024-10-12 20:47 ` [PATCH v3 2/3] perf probe: Check group string length Leo Yan
2024-10-12 20:47 ` [PATCH v3 3/3] perf probe: Improve log for long event name failure Leo Yan
2024-10-14 2:24 ` Masami Hiramatsu
2024-10-17 16:39 ` [PATCH v3 0/3] perf probe: Improve logs for long name string Namhyung Kim
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).