linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	linux-perf-users@vger.kernel.org,
	Kan Liang <kan.liang@linux.intel.com>,
	Leo Yan <leo.yan@linaro.org>
Subject: Re: [PATCH 1/9] perf list: Use relative path for tracepoint scan
Date: Mon, 3 Apr 2023 18:59:10 -0300	[thread overview]
Message-ID: <ZCtMLkNL80EkPvB1@kernel.org> (raw)
In-Reply-To: <20230331202949.810326-2-namhyung@kernel.org>

Em Fri, Mar 31, 2023 at 01:29:41PM -0700, Namhyung Kim escreveu:
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
>  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...

- Arnaldo


diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c
index 26a7e017c9284c01..28aa0b9300253d0a 100644
--- a/tools/perf/util/print-events.c
+++ b/tools/perf/util/print-events.c
@@ -6,6 +6,7 @@
 #include <string.h>
 #include <fcntl.h>
 #include <sys/param.h>
+#include <unistd.h>
 
 #include <api/fs/tracing_path.h>
 #include <linux/stddef.h>
 
> diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c
> index 62e9ea7dcf40..26a7e017c928 100644
> --- a/tools/perf/util/print-events.c
> +++ b/tools/perf/util/print-events.c
> @@ -4,6 +4,7 @@
>  #include <stdio.h>
>  #include <stdlib.h>
>  #include <string.h>
> +#include <fcntl.h>
>  #include <sys/param.h>
>  
>  #include <api/fs/tracing_path.h>
> @@ -59,12 +60,20 @@ static const struct event_symbol event_symbols_tool[PERF_TOOL_MAX] = {
>  void print_tracepoint_events(const struct print_callbacks *print_cb, void *print_state)
>  {
>  	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);
> +	if (events_fd < 0) {
> +		printf("Error: failed to open tracing events directory\n");
> +		return;
> +	}
>  
>  	for (int i = 0; i < sys_items; i++) {
>  		struct dirent *sys_dirent = sys_namelist[i];
>  		struct dirent **evt_namelist = NULL;
> -		char *dir_path;
> +		int dir_fd;
>  		int evt_items;
>  
>  		if (sys_dirent->d_type != DT_DIR ||
> @@ -72,22 +81,26 @@ void print_tracepoint_events(const struct print_callbacks *print_cb, void *print
>  		    !strcmp(sys_dirent->d_name, ".."))
>  			continue;
>  
> -		dir_path = get_events_file(sys_dirent->d_name);
> -		if (!dir_path)
> +		dir_fd = openat(events_fd, sys_dirent->d_name, O_PATH);
> +		if (dir_fd < 0)
>  			continue;
>  
> -		evt_items = scandir(dir_path, &evt_namelist, NULL, alphasort);
> +		evt_items = scandirat(events_fd, sys_dirent->d_name, &evt_namelist, NULL, alphasort);
>  		for (int j = 0; j < evt_items; j++) {
>  			struct dirent *evt_dirent = evt_namelist[j];
>  			char evt_path[MAXPATHLEN];
> +			int evt_fd;
>  
>  			if (evt_dirent->d_type != DT_DIR ||
>  			    !strcmp(evt_dirent->d_name, ".") ||
>  			    !strcmp(evt_dirent->d_name, ".."))
>  				continue;
>  
> -			if (tp_event_has_id(dir_path, evt_dirent) != 0)
> +			snprintf(evt_path, sizeof(evt_path), "%s/id", evt_dirent->d_name);
> +			evt_fd = openat(dir_fd, evt_path, O_RDONLY);
> +			if (evt_fd < 0)
>  				continue;
> +			close(evt_fd);
>  
>  			snprintf(evt_path, MAXPATHLEN, "%s:%s",
>  				 sys_dirent->d_name, evt_dirent->d_name);
> @@ -103,10 +116,11 @@ void print_tracepoint_events(const struct print_callbacks *print_cb, void *print
>  					/*long_desc=*/NULL,
>  					/*encoding_desc=*/NULL);
>  		}
> -		free(dir_path);
> +		close(dir_fd);
>  		free(evt_namelist);
>  	}
>  	free(sys_namelist);
> +	close(events_fd);
>  }
>  
>  void print_sdt_events(const struct print_callbacks *print_cb, void *print_state)
> -- 
> 2.40.0.348.gf938b09366-goog
> 

-- 

- Arnaldo

  reply	other threads:[~2023-04-03 21:59 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-31 20:29 [PATCHSET 0/9] perf tools: Update pmu scan using openat() (v1) Namhyung Kim
2023-03-31 20:29 ` [PATCH 1/9] perf list: Use relative path for tracepoint scan Namhyung Kim
2023-04-03 21:59   ` Arnaldo Carvalho de Melo [this message]
2023-04-03 22:00     ` Arnaldo Carvalho de Melo
2023-04-04 14:10     ` Arnaldo Carvalho de Melo
2023-04-04 22:08       ` Namhyung Kim
2023-04-04 22:19         ` Arnaldo Carvalho de Melo
2023-03-31 20:29 ` [PATCH 2/9] perf tools: Fix a asan issue in parse_events_multi_pmu_add() Namhyung Kim
2023-03-31 20:29 ` [PATCH 3/9] perf pmu: Add perf_pmu__destroy() function Namhyung Kim
2023-03-31 20:29 ` [PATCH 4/9] perf bench: Add pmu-scan benchmark Namhyung Kim
2023-03-31 20:29 ` [PATCH 5/9] perf pmu: Use relative path for sysfs scan Namhyung Kim
2023-04-03 17:23   ` Ian Rogers
2023-03-31 20:29 ` [PATCH 6/9] perf pmu: Use relative path in perf_pmu__caps_parse() Namhyung Kim
2023-03-31 20:29 ` [PATCH 7/9] perf pmu: Use relative path in setup_pmu_alias_list() Namhyung Kim
2023-03-31 20:29 ` [PATCH 8/9] perf pmu: Add perf_pmu__{open,scan}_file_at() Namhyung Kim
2023-03-31 20:29 ` [PATCH 9/9] perf intel-pt: Use perf_pmu__scan_file_at() if possible Namhyung Kim
2023-04-03  4:51   ` Adrian Hunter
2023-04-03 17:28 ` [PATCHSET 0/9] perf tools: Update pmu scan using openat() (v1) Ian Rogers
2023-04-03 20:25   ` Arnaldo Carvalho de Melo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZCtMLkNL80EkPvB1@kernel.org \
    --to=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --cc=leo.yan@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).