linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: Clark Williams <williams@redhat.com>,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	David Ahern <dsahern@gmail.com>, Jiri Olsa <jolsa@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Wang Nan <wangnan0@huawei.com>
Subject: [PATCH 07/18] tools lib api fs tracing_path: Introduce opendir() method
Date: Sat, 19 May 2018 07:54:56 -0300	[thread overview]
Message-ID: <20180519105507.16450-8-acme@kernel.org> (raw)
In-Reply-To: <20180519105507.16450-1-acme@kernel.org>

From: Arnaldo Carvalho de Melo <acme@redhat.com>

That takes care of using the right call to get the tracing_path
directory, the one that will end up calling tracing_path_set() to figure
out where tracefs is mounted.

One more step in doing just lazy reading of system structures to reduce
the number of operations done unconditionaly at 'perf' start.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: https://lkml.kernel.org/n/tip-42zzi0f274909bg9mxzl81bu@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/lib/api/fs/tracing_path.c | 13 +++++++++++++
 tools/lib/api/fs/tracing_path.h |  3 +++
 tools/perf/tests/parse-events.c |  2 +-
 tools/perf/util/parse-events.c  |  8 ++++----
 4 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/tools/lib/api/fs/tracing_path.c b/tools/lib/api/fs/tracing_path.c
index 9cd282425929..9b451af0721c 100644
--- a/tools/lib/api/fs/tracing_path.c
+++ b/tools/lib/api/fs/tracing_path.c
@@ -101,6 +101,19 @@ void put_events_file(char *file)
 	free(file);
 }
 
+DIR *tracing_events__opendir(void)
+{
+	DIR *dir = NULL;
+	char *path = get_tracing_file("events");
+
+	if (path) {
+		dir = opendir(path);
+		put_events_file(path);
+	}
+
+	return dir;
+}
+
 int tracing_path__strerror_open_tp(int err, char *buf, size_t size,
 				   const char *sys, const char *name)
 {
diff --git a/tools/lib/api/fs/tracing_path.h b/tools/lib/api/fs/tracing_path.h
index 3b32fb439f12..904d085b2ae7 100644
--- a/tools/lib/api/fs/tracing_path.h
+++ b/tools/lib/api/fs/tracing_path.h
@@ -3,9 +3,12 @@
 #define __API_FS_TRACING_PATH_H
 
 #include <linux/types.h>
+#include <dirent.h>
 
 extern char tracing_events_path[];
 
+DIR *tracing_events__opendir(void);
+
 void tracing_path_set(const char *mountpoint);
 const char *tracing_path_mount(void);
 
diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
index 6d57d7082637..b9ebe15afb13 100644
--- a/tools/perf/tests/parse-events.c
+++ b/tools/perf/tests/parse-events.c
@@ -1323,7 +1323,7 @@ static int count_tracepoints(void)
 	DIR *events_dir;
 	int cnt = 0;
 
-	events_dir = opendir(tracing_events_path);
+	events_dir = tracing_events__opendir();
 
 	TEST_ASSERT_VAL("Can't open events dir", events_dir);
 
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 24668300b327..15eec49e71a1 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -191,7 +191,7 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
 	char evt_path[MAXPATHLEN];
 	char *dir_path;
 
-	sys_dir = opendir(tracing_events_path);
+	sys_dir = tracing_events__opendir();
 	if (!sys_dir)
 		return NULL;
 
@@ -578,7 +578,7 @@ static int add_tracepoint_multi_sys(struct list_head *list, int *idx,
 	DIR *events_dir;
 	int ret = 0;
 
-	events_dir = opendir(tracing_events_path);
+	events_dir = tracing_events__opendir();
 	if (!events_dir) {
 		tracepoint_error(err, errno, sys_name, evt_name);
 		return -1;
@@ -2106,7 +2106,7 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob,
 	bool evt_num_known = false;
 
 restart:
-	sys_dir = opendir(tracing_events_path);
+	sys_dir = tracing_events__opendir();
 	if (!sys_dir)
 		return;
 
@@ -2200,7 +2200,7 @@ int is_valid_tracepoint(const char *event_string)
 	char evt_path[MAXPATHLEN];
 	char *dir_path;
 
-	sys_dir = opendir(tracing_events_path);
+	sys_dir = tracing_events__opendir();
 	if (!sys_dir)
 		return 0;
 
-- 
2.14.3

  parent reply	other threads:[~2018-05-19 10:54 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-19 10:54 [GIT PULL 00/18] perf/core improvements and fixes Arnaldo Carvalho de Melo
2018-05-19 10:54 ` [PATCH 01/18] perf config: Call perf_config__init() lazily Arnaldo Carvalho de Melo
2018-05-19 10:54 ` [PATCH 02/18] tools lib api: The tracing_mnt variable doesn't need to be global Arnaldo Carvalho de Melo
2018-05-19 10:54 ` [PATCH 03/18] tools lib api: Unexport 'tracing_path' variable Arnaldo Carvalho de Melo
2018-05-19 10:54 ` [PATCH 04/18] tools lib api fs tracing_path: Introduce get/put_events_file() helpers Arnaldo Carvalho de Melo
2018-05-19 10:54 ` [PATCH 05/18] perf tools: Reuse the path to the tracepoint /events/ directory Arnaldo Carvalho de Melo
2018-05-19 10:54 ` [PATCH 06/18] perf parse-events: Use get/put_events_file() Arnaldo Carvalho de Melo
2018-05-19 10:54 ` Arnaldo Carvalho de Melo [this message]
2018-05-19 10:54 ` [PATCH 08/18] tools lib api fs tracing_path: Make tracing_events_path private Arnaldo Carvalho de Melo
2018-05-19 10:54 ` [PATCH 09/18] tools include compiler-gcc: Add __pure attribute helper Arnaldo Carvalho de Melo
2018-05-19 10:54 ` [PATCH 10/18] perf tools: Read the cache line size lazily Arnaldo Carvalho de Melo
2018-05-19 10:55 ` [PATCH 11/18] perf tools: No need to unconditionally read the max_stack sysctls Arnaldo Carvalho de Melo
2018-05-19 10:55 ` [PATCH 12/18] perf script: Show virtual addresses instead of offsets Arnaldo Carvalho de Melo
2018-05-19 10:55 ` [PATCH 13/18] perf script: Show symbol offsets by default Arnaldo Carvalho de Melo
2018-05-19 10:55 ` [PATCH 14/18] perf annotate: Record the min/max cycles Arnaldo Carvalho de Melo
2018-05-19 10:55 ` [PATCH 15/18] perf annotate: Create hotkey 'c' to show " Arnaldo Carvalho de Melo
2018-05-19 10:55 ` [PATCH 16/18] perf bpf: Fixup include and examples install messages Arnaldo Carvalho de Melo
2018-05-19 10:55 ` [PATCH 17/18] perf machine: Add machine__is() to identify machine arch Arnaldo Carvalho de Melo
2018-05-19 10:55 ` [PATCH 18/18] perf tools: Fix kernel_start for PTI on x86 Arnaldo Carvalho de Melo
2018-05-19 11:33 ` [GIT PULL 00/18] perf/core improvements and fixes Ingo Molnar

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=20180519105507.16450-8-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=dsahern@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=wangnan0@huawei.com \
    --cc=williams@redhat.com \
    /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).