* [PATCH v2 0/3] perf probe: Improve logs for long name string
@ 2024-10-12 15:44 Leo Yan
2024-10-12 15:44 ` [PATCH v2 1/3] perf probe: Use the MAX_EVENT_NAME_LEN macro Leo Yan
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Leo Yan @ 2024-10-12 15:44 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 group
and event strings.
[1] https://lore.kernel.org/linux-perf-users/20241010234818.ab279974ef597f02b61ab850@kernel.org/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(-)
--
2.25.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/3] perf probe: Use the MAX_EVENT_NAME_LEN macro
2024-10-12 15:44 [PATCH v2 0/3] perf probe: Improve logs for long name string Leo Yan
@ 2024-10-12 15:44 ` Leo Yan
2024-10-12 15:44 ` [PATCH v2 2/3] perf probe: Check group string length Leo Yan
2024-10-12 15:44 ` [PATCH v2 3/3] perf probe: Improve log for long event name failure Leo Yan
2 siblings, 0 replies; 5+ messages in thread
From: Leo Yan @ 2024-10-12 15:44 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] 5+ messages in thread
* [PATCH v2 2/3] perf probe: Check group string length
2024-10-12 15:44 [PATCH v2 0/3] perf probe: Improve logs for long name string Leo Yan
2024-10-12 15:44 ` [PATCH v2 1/3] perf probe: Use the MAX_EVENT_NAME_LEN macro Leo Yan
@ 2024-10-12 15:44 ` Leo Yan
2024-10-12 15:44 ` [PATCH v2 3/3] perf probe: Improve log for long event name failure Leo Yan
2 siblings, 0 replies; 5+ messages in thread
From: Leo Yan @ 2024-10-12 15:44 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] 5+ messages in thread
* [PATCH v2 3/3] perf probe: Improve log for long event name failure
2024-10-12 15:44 [PATCH v2 0/3] perf probe: Improve logs for long name string Leo Yan
2024-10-12 15:44 ` [PATCH v2 1/3] perf probe: Use the MAX_EVENT_NAME_LEN macro Leo Yan
2024-10-12 15:44 ` [PATCH v2 2/3] perf probe: Check group string length Leo Yan
@ 2024-10-12 15:44 ` Leo Yan
2024-10-12 20:52 ` Leo Yan
2 siblings, 1 reply; 5+ messages in thread
From: Leo Yan @ 2024-10-12 15:44 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 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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 3/3] perf probe: Improve log for long event name failure
2024-10-12 15:44 ` [PATCH v2 3/3] perf probe: Improve log for long event name failure Leo Yan
@ 2024-10-12 20:52 ` Leo Yan
0 siblings, 0 replies; 5+ messages in thread
From: Leo Yan @ 2024-10-12 20:52 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
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))
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-10-12 20:52 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-12 15:44 [PATCH v2 0/3] perf probe: Improve logs for long name string Leo Yan
2024-10-12 15:44 ` [PATCH v2 1/3] perf probe: Use the MAX_EVENT_NAME_LEN macro Leo Yan
2024-10-12 15:44 ` [PATCH v2 2/3] perf probe: Check group string length Leo Yan
2024-10-12 15:44 ` [PATCH v2 3/3] perf probe: Improve log for long event name failure Leo Yan
2024-10-12 20:52 ` Leo Yan
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).