perf probe: Fix usage when libtraceevent is missing
authorAthira Rajeev <atrajeev@linux.vnet.ibm.com>
Tue, 31 Jan 2023 13:47:48 +0000 (19:17 +0530)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 2 Feb 2023 19:32:19 +0000 (16:32 -0300)
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 shows below message though it can't be used
via perf record.

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

The builtin tool like perf record needs libtraceevent to
parse tracefs. But still the probe can be used by enabling
via tracefs. Patch fixes the probe usage message to the user
based on presence of libtraceevent. With the fix,

 # ./perf probe 'pmu:myprobe=schedule'
 Added new event:
   pmu:myprobe          (on schedule)

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

cd /sys/kernel/tracing/
echo 1 > events/pmu/myprobe/enable
echo 1 > tracing_on
cat trace_pipe
Before removing the probe, echo 0 > events/pmu/myprobe/enable

Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Disha Goel <disgoel@linux.ibm.com>
Cc: Ian Rogers <irogers@google.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nageswara R Sastry <rnsastry@linux.ibm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linuxppc-dev@lists.ozlabs.org
Link: https://lore.kernel.org/r/20230131134748.54567-1-atrajeev@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-probe.c

index ed73d0b89ca2dae4b543b5ba1473a65f22d2a546..e72f6cea76f78a76986d52539a8ce543f8d28505 100644 (file)
@@ -383,9 +383,18 @@ 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");
+               pr_info("\tBefore removing the probe, echo 0 > events/%s/%s/enable\n", group, event);
+#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: