Re: [PATCH 1/9] perf list: Use relative path for tracepoint scan

From: Arnaldo Carvalho de Melo
Date: Tue Apr 04 2023 - 10:10:53 EST


Em Mon, Apr 03, 2023 at 06:59:10PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Fri, Mar 31, 2023 at 01:29:41PM -0700, Namhyung Kim escreveu:
> > Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
> > ---
> > tools/perf/util/print-events.c | 26 ++++++++++++++++++++------
> > 1 file changed, 20 insertions(+), 6 deletions(-)
>
> Add to add this to fix on Alma Linux 8, and scandirat isn't being found
> on musl libc (Alpine Linux), probably we'll need some scaffolding...

About scandirat I'm adding the feature test below and this patch to the
patch that starts using scandirat():

diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c
index 28aa0b9300253d0a..386b1ab0b60e1d93 100644
--- a/tools/perf/util/print-events.c
+++ b/tools/perf/util/print-events.c
@@ -58,11 +58,9 @@ static const struct event_symbol event_symbols_tool[PERF_TOOL_MAX] = {
/*
* Print the events from <debugfs_mount_point>/tracing/events
*/
-void print_tracepoint_events(const struct print_callbacks *print_cb, void *print_state)
+void print_tracepoint_events(const struct print_callbacks *print_cb __maybe_unused, void *print_state __maybe_unused)
{
- struct dirent **sys_namelist = NULL;
char *events_path = get_tracing_file("events");
- int sys_items = tracing_events__scandir_alphasort(&sys_namelist);
int events_fd = open(events_path, O_PATH);

put_tracing_file(events_path);
@@ -71,6 +69,11 @@ void print_tracepoint_events(const struct print_callbacks *print_cb, void *print
return;
}

+#ifdef HAVE_SCANDIRAT_SUPPORT
+{
+ struct dirent **sys_namelist = NULL;
+ int sys_items = tracing_events__scandir_alphasort(&sys_namelist);
+
for (int i = 0; i < sys_items; i++) {
struct dirent *sys_dirent = sys_namelist[i];
struct dirent **evt_namelist = NULL;
@@ -120,7 +123,13 @@ void print_tracepoint_events(const struct print_callbacks *print_cb, void *print
close(dir_fd);
free(evt_namelist);
}
+
free(sys_namelist);
+}
+#else
+ printf("\nWARNING: Your libc doesn't have the scandir function, please ask its maintainers to implement it.\n"
+ " As a rough fallback, please do 'ls %s' to see the available tracepoint events.\n", events_path);
+#endif
close(events_fd);
}