Skip to contentSkip to conversation

tools/perf: Disable perf probe when libtraceevent is missing

PATCH In review Athira Rajeev 2 participants 3 messages Jan 20, 2023 – Jan 25, 2023 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/perf: Disable perf probe when libtraceevent is missing

While parsing the tracepoint events in parse_events_add_tracepoint() function, code checks for HAVE_LIBTRACEEVENT support. This is needed since libtraceevent is necessary for tracepoint. But while adding probe points, check for LIBTRACEEVENT is not done in case of perf probe. Hence, in environment with missing libtraceevent-devel, it is observed that adding a probe point works even though its not supported.

Example:
Adding probe point:
./perf probe 'vfs_getname=getname_flags:72 pathname=result->name:string' Added new event:
probe:vfs_getname (on getname_flags:72 with pathname=result->name:string)

You can now use it in all perf tools, such as:

perf record -e probe:vfs_getname -aR sleep 1

But trying perf record:
./perf record -e probe:vfs_getname -aR sleep 1 event syntax error: 'probe:vfs_getname'
\___ unsupported tracepoint
libtraceevent is necessary for tracepoint support Run 'perf list' for a list of valid events

Fix this by wrapping "builtin-probe" compilation and "perf probe" usage under "CONFIG_LIBTRACEEVENT" check.

---
 tools/perf/Build  | 4 +++-
 tools/perf/perf.c | 2 ++
 2 files changed, 5 insertions(+), 1 deletion(-)
tools/perf/Build +3 -1
index 6dd67e502295..a138a2304929 100644
@@ -33,7 +33,9 @@ ifeq ($(CONFIG_LIBTRACEEVENT),y)
   perf-$(CONFIG_TRACE) += trace/beauty/
 endif
 
-perf-$(CONFIG_LIBELF) += builtin-probe.o
+ifeq ($(CONFIG_LIBTRACEEVENT),y)
+  perf-$(CONFIG_LIBELF) += builtin-probe.o
+endif
 
 perf-y += bench/
 perf-y += tests/
tools/perf/perf.c +2 -0
index 82bbe0ca858b..7b0d79284d5a 100644
@@ -80,9 +80,11 @@ static struct cmd_struct commands[] = {
 #ifdef HAVE_LIBTRACEEVENT
 	{ "sched",	cmd_sched,	0 },
 #endif
+#ifdef HAVE_LIBTRACEEVENT
 #ifdef HAVE_LIBELF_SUPPORT
 	{ "probe",	cmd_probe,	0 },
 #endif
+#endif
 #ifdef HAVE_LIBTRACEEVENT
 	{ "kmem",	cmd_kmem,	0 },
 	{ "lock",	cmd_lock,	0 },
Signature · 1 line
2.39.0
#1 lore raw

Em Fri, Jan 20, 2023 at 05:32:56PM +0530, Athira Rajeev escreveu:

Quoted 25 lines

While parsing the tracepoint events in parse_events_add_tracepoint() function, code checks for HAVE_LIBTRACEEVENT support. This is needed since libtraceevent is necessary for tracepoint. But while adding probe points, check for LIBTRACEEVENT is not done in case of perf probe. Hence, in environment with missing libtraceevent-devel, it is observed that adding a probe point works even though its not supported.

Example:
Adding probe point:
./perf probe 'vfs_getname=getname_flags:72 pathname=result->name:string' Added new event:
probe:vfs_getname (on getname_flags:72 with pathname=result->name:string)

You can now use it in all perf tools, such as:

perf record -e probe:vfs_getname -aR sleep 1

But trying perf record:
./perf record -e probe:vfs_getname -aR sleep 1 event syntax error: 'probe:vfs_getname'
\___ unsupported tracepoint
libtraceevent is necessary for tracepoint support Run 'perf list' for a list of valid events

Quoted 2 lines

Fix this by wrapping "builtin-probe" compilation and "perf probe" usage under "CONFIG_LIBTRACEEVENT" check.

Humm, but 'perf probe' continues to work, as uou demoed above, the problem is with the suggestion to use other perf tools that need to parse tracefs and without libtraceevent, currently can't do it:

[root@quaco ~]# perf probe 'vfs_getname=getname_flags:72 pathname=result->name:string' Added new event:
probe:vfs_getname (on getname_flags:72 with pathname=result->name:string)

You can now use it in all perf tools, such as:

perf record -e probe:vfs_getname -aR sleep 1

[root@quaco ~]# perf probe -l
probe:vfs_getname (on getname_flags:72@fs/namei.c with pathname)
[root@quaco ~]# perf trace -e probe:vfs_getname
perf: 'trace' is not a perf-command. See 'perf --help'. [root@quaco ~]# cd /sys/kernel/tracing/events/probe/vfs_getname/ [root@quaco vfs_getname]# ls
enable filter format hist id trigger
[root@quaco vfs_getname]# ls -la
total 0
drwxr-x---. 2 root root 0 Jan 20 11:18 .
drwxr-x---. 3 root root 0 Jan 20 11:18 ..
-rw-r-----. 1 root root 0 Jan 20 11:18 enable -rw-r-----. 1 root root 0 Jan 20 11:18 filter -r--r-----. 1 root root 0 Jan 20 11:18 format -r--r-----. 1 root root 0 Jan 20 11:18 hist -r--r-----. 1 root root 0 Jan 20 11:18 id
-rw-r-----. 1 root root 0 Jan 20 11:18 trigger [root@quaco vfs_getname]#

But we can go on from there:

[root@quaco tracing]# pwd
/sys/kernel/tracing
[root@quaco tracing]# echo 1 > /sys/kernel/tracing/events/probe/vfs_getname/enable [root@quaco tracing]# echo 1 > tracing_on
[root@quaco tracing]# head trace_pipe

    systemd-oomd-979     [003] ..... 96369.978971: vfs_getname: (getname_flags.part.0+0x6b/0x1c0) pathname="/sys/fs/cgroup/user.slice/user-1000.slice/[email protected]"
    systemd-oomd-979     [003] ..... 96369.979022: vfs_getname: (getname_flags.part.0+0x6b/0x1c0) pathname="/sys/fs/cgroup/user.slice/user-1000.slice/[email protected]/memory.current"
    systemd-oomd-979     [003] ..... 96369.979084: vfs_getname: (getname_flags.part.0+0x6b/0x1c0) pathname=""
    systemd-oomd-979     [003] ..... 96369.979162: vfs_getname: (getname_flags.part.0+0x6b/0x1c0) pathname="/sys/fs/cgroup/user.slice/user-1000.slice/[email protected]/memory.min"
    systemd-oomd-979     [003] ..... 96369.979197: vfs_getname: (getname_flags.part.0+0x6b/0x1c0) pathname=""
    systemd-oomd-979     [003] ..... 96369.979267: vfs_getname: (getname_flags.part.0+0x6b/0x1c0) pathname="/sys/fs/cgroup/user.slice/user-1000.slice/[email protected]/memory.low"
    systemd-oomd-979     [003] ..... 96369.979303: vfs_getname: (getname_flags.part.0+0x6b/0x1c0) pathname=""
    systemd-oomd-979     [003] ..... 96369.979372: vfs_getname: (getname_flags.part.0+0x6b/0x1c0) pathname="/sys/fs/cgroup/user.slice/user-1000.slice/[email protected]/memory.swap.current"
    systemd-oomd-979     [003] ..... 96369.979406: vfs_getname: (getname_flags.part.0+0x6b/0x1c0) pathname=""
    systemd-oomd-979     [003] ..... 96369.979475: vfs_getname: (getname_flags.part.0+0x6b/0x1c0) pathname="/sys/fs/cgroup/user.slice/user-1000.slice/[email protected]/memory.stat"

[root@quaco tracing]#

So you could instead replace the suggestion from:

"
You can now use it in all perf tools, such as:

perf record -e probe:vfs_getname -aR sleep 1
"

To:

"
perf is not linked with libtraceevent, to use the new probe you can use tracefs:

cd /sys/kernel/tracing/
echo 1 > events/probe/vfs_getname/enable echo 1 > tracing_on
cat trace_pipe
"

wdyt?

- Arnaldo

Quoted 39 lines
---
 tools/perf/Build  | 4 +++-
 tools/perf/perf.c | 2 ++
 2 files changed, 5 insertions(+), 1 deletion(-)
tools/perf/Build +3 -1
index 6dd67e502295..a138a2304929 100644
@@ -33,7 +33,9 @@ ifeq ($(CONFIG_LIBTRACEEVENT),y)
   perf-$(CONFIG_TRACE) += trace/beauty/
 endif
 
-perf-$(CONFIG_LIBELF) += builtin-probe.o
+ifeq ($(CONFIG_LIBTRACEEVENT),y)
+  perf-$(CONFIG_LIBELF) += builtin-probe.o
+endif
 
 perf-y += bench/
 perf-y += tests/
tools/perf/perf.c +2 -0
index 82bbe0ca858b..7b0d79284d5a 100644
@@ -80,9 +80,11 @@ static struct cmd_struct commands[] = {
 #ifdef HAVE_LIBTRACEEVENT
 	{ "sched",	cmd_sched,	0 },
 #endif
+#ifdef HAVE_LIBTRACEEVENT
 #ifdef HAVE_LIBELF_SUPPORT
 	{ "probe",	cmd_probe,	0 },
 #endif
+#endif
 #ifdef HAVE_LIBTRACEEVENT
 	{ "kmem",	cmd_kmem,	0 },
 	{ "lock",	cmd_lock,	0 },
Signature · 1 line
2.39.0
Signature · 1 line
- Arnaldo
#2 lore raw
Quoted 97 lines · Arnaldo Carvalho de Melo

Em Fri, Jan 20, 2023 at 05:32:56PM +0530, Athira Rajeev escreveu:

Quoted 25 lines

While parsing the tracepoint events in parse_events_add_tracepoint() function, code checks for HAVE_LIBTRACEEVENT support. This is needed since libtraceevent is necessary for tracepoint. But while adding probe points, check for LIBTRACEEVENT is not done in case of perf probe. Hence, in environment with missing libtraceevent-devel, it is observed that adding a probe point works even though its not supported.

Example:
Adding probe point:
./perf probe 'vfs_getname=getname_flags:72 pathname=result->name:string' Added new event:
probe:vfs_getname (on getname_flags:72 with pathname=result->name:string)

You can now use it in all perf tools, such as:

perf record -e probe:vfs_getname -aR sleep 1

But trying perf record:
./perf record -e probe:vfs_getname -aR sleep 1 event syntax error: 'probe:vfs_getname'
\___ unsupported tracepoint
libtraceevent is necessary for tracepoint support Run 'perf list' for a list of valid events

Quoted 2 lines

Fix this by wrapping "builtin-probe" compilation and "perf probe" usage under "CONFIG_LIBTRACEEVENT" check.

Humm, but 'perf probe' continues to work, as uou demoed above, the problem is with the suggestion to use other perf tools that need to parse tracefs and without libtraceevent, currently can't do it:

[root@quaco ~]# perf probe 'vfs_getname=getname_flags:72 pathname=result->name:string' Added new event:
probe:vfs_getname (on getname_flags:72 with pathname=result->name:string)

You can now use it in all perf tools, such as:

perf record -e probe:vfs_getname -aR sleep 1

[root@quaco ~]# perf probe -l
probe:vfs_getname (on getname_flags:72@fs/namei.c with pathname)
[root@quaco ~]# perf trace -e probe:vfs_getname
perf: 'trace' is not a perf-command. See 'perf --help'. [root@quaco ~]# cd /sys/kernel/tracing/events/probe/vfs_getname/ [root@quaco vfs_getname]# ls
enable filter format hist id trigger
[root@quaco vfs_getname]# ls -la
total 0
drwxr-x---. 2 root root 0 Jan 20 11:18 .
drwxr-x---. 3 root root 0 Jan 20 11:18 ..

(quoted diff) +0 -6
-rw-r-----. 1 root root 0 Jan 20 11:18 enable
-rw-r-----. 1 root root 0 Jan 20 11:18 filter
-r--r-----. 1 root root 0 Jan 20 11:18 format
-r--r-----. 1 root root 0 Jan 20 11:18 hist
-r--r-----. 1 root root 0 Jan 20 11:18 id
-rw-r-----. 1 root root 0 Jan 20 11:18 trigger

[root@quaco vfs_getname]#

But we can go on from there:

[root@quaco tracing]# pwd
/sys/kernel/tracing
[root@quaco tracing]# echo 1 > /sys/kernel/tracing/events/probe/vfs_getname/enable [root@quaco tracing]# echo 1 > tracing_on
[root@quaco tracing]# head trace_pipe

   systemd-oomd-979     [003] ..... 96369.978971: vfs_getname: (getname_flags.part.0+0x6b/0x1c0) pathname="/sys/fs/cgroup/user.slice/user-1000.slice/[email protected]"
   systemd-oomd-979     [003] ..... 96369.979022: vfs_getname: (getname_flags.part.0+0x6b/0x1c0) pathname="/sys/fs/cgroup/user.slice/user-1000.slice/[email protected]/memory.current"
   systemd-oomd-979     [003] ..... 96369.979084: vfs_getname: (getname_flags.part.0+0x6b/0x1c0) pathname=""
   systemd-oomd-979     [003] ..... 96369.979162: vfs_getname: (getname_flags.part.0+0x6b/0x1c0) pathname="/sys/fs/cgroup/user.slice/user-1000.slice/[email protected]/memory.min"
   systemd-oomd-979     [003] ..... 96369.979197: vfs_getname: (getname_flags.part.0+0x6b/0x1c0) pathname=""
   systemd-oomd-979     [003] ..... 96369.979267: vfs_getname: (getname_flags.part.0+0x6b/0x1c0) pathname="/sys/fs/cgroup/user.slice/user-1000.slice/[email protected]/memory.low"
   systemd-oomd-979     [003] ..... 96369.979303: vfs_getname: (getname_flags.part.0+0x6b/0x1c0) pathname=""
   systemd-oomd-979     [003] ..... 96369.979372: vfs_getname: (getname_flags.part.0+0x6b/0x1c0) pathname="/sys/fs/cgroup/user.slice/user-1000.slice/[email protected]/memory.swap.current"
   systemd-oomd-979     [003] ..... 96369.979406: vfs_getname: (getname_flags.part.0+0x6b/0x1c0) pathname=""
   systemd-oomd-979     [003] ..... 96369.979475: vfs_getname: (getname_flags.part.0+0x6b/0x1c0) pathname="/sys/fs/cgroup/user.slice/user-1000.slice/[email protected]/memory.stat"

[root@quaco tracing]#

So you could instead replace the suggestion from:

"
You can now use it in all perf tools, such as:

perf record -e probe:vfs_getname -aR sleep 1
"

To:

"
perf is not linked with libtraceevent, to use the new probe you can use tracefs:

Quoted 7 lines

cd /sys/kernel/tracing/
echo 1 > events/probe/vfs_getname/enable echo 1 > tracing_on
cat trace_pipe
"

wdyt?

Hi Arnaldo,

Thanks for the suggestion. The idea to change usage message based on presence of libtraceevent is good. I could try change with HAVE_LIBTRACEEVENT condition. Sample snippet below:

tools/perf/builtin-probe.c +8 -0
index ed73d0b89ca2..f010d0e43577 100644
@@ -383,9 +383,17 @@ static int perf_add_probe_events(struct perf_probe_event *pevs, int npevs)
 
        /* Note that it is possible to skip all events because of blacklist */
        if (event) {
+#ifndef HAVE_LIBTRACEEVENT
+               pr_info("\nperf is not linked with libtraceevent, to use the new probe you can use tracefs:\n\n");
+               pr_info("\tcd /sys/kernel/tracing/\n");
+               pr_info("\techo 1 > events/%s/%s/enable\n", group, event);
+               pr_info("\techo 1 > tracing_on\n");
+               pr_info("\tcat trace_pipe\n");
+#else
                /* Show how to use the event. */
                pr_info("\nYou can now use it in all perf tools, such as:\n\n");
                pr_info("\tperf record -e %s:%s -aR sleep 1\n\n", group, event);
+#endif
        }
 
 out_cleanup:

I will re-work on patch changes and also test for other options ( perf probe with different group “GROUP" values etc) to make sure this works via tracefs. Arnaldo, the above approach looks fine to proceed with ?

Thanks
Athira

Quoted 46 lines

- Arnaldo

Quoted 39 lines

---
tools/perf/Build | 4 +++-
tools/perf/perf.c | 2 ++

2 files changed, 5 insertions(+), 1 deletion(-)
tools/perf/Build +0 -0
index 6dd67e502295..a138a2304929 100644
@@ -33,7 +33,9 @@ ifeq ($(CONFIG_LIBTRACEEVENT),y)
  perf-$(CONFIG_TRACE) += trace/beauty/

endif

tools/perf/Build +3 -1
-perf-$(CONFIG_LIBELF) += builtin-probe.o
+ifeq ($(CONFIG_LIBTRACEEVENT),y)
+  perf-$(CONFIG_LIBELF) += builtin-probe.o
+endif

perf-y += bench/
perf-y += tests/

tools/perf/perf.c +2 -0
index 82bbe0ca858b..7b0d79284d5a 100644
@@ -80,9 +80,11 @@ static struct cmd_struct commands[] = {
 #ifdef HAVE_LIBTRACEEVENT
 	{ "sched",	cmd_sched,	0 },
 #endif
+#ifdef HAVE_LIBTRACEEVENT
 #ifdef HAVE_LIBELF_SUPPORT
 	{ "probe",	cmd_probe,	0 },
 #endif
+#endif
 #ifdef HAVE_LIBTRACEEVENT
 	{ "kmem",	cmd_kmem,	0 },
 	{ "lock",	cmd_lock,	0 },
Signature · 1 line
2.39.0
Signature · 1 line
- Arnaldo