diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-05-17 13:42:39 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-05-17 13:50:38 -0400 |
commit | 7014e0e3bf9b0d0b6221eb7d2f8a1f690423dd73 (patch) | |
tree | 37da2c3997d4b2c03a4e1698481e8608925b11cd /tools | |
parent | 25a7d914274de38637c5199342eb90a297361386 (diff) |
tools lib api fs tracing_path: Introduce opendir() method
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>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/lib/api/fs/tracing_path.c | 13 | ||||
-rw-r--r-- | tools/lib/api/fs/tracing_path.h | 3 | ||||
-rw-r--r-- | tools/perf/tests/parse-events.c | 2 | ||||
-rw-r--r-- | 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) | |||
101 | free(file); | 101 | free(file); |
102 | } | 102 | } |
103 | 103 | ||
104 | DIR *tracing_events__opendir(void) | ||
105 | { | ||
106 | DIR *dir = NULL; | ||
107 | char *path = get_tracing_file("events"); | ||
108 | |||
109 | if (path) { | ||
110 | dir = opendir(path); | ||
111 | put_events_file(path); | ||
112 | } | ||
113 | |||
114 | return dir; | ||
115 | } | ||
116 | |||
104 | int tracing_path__strerror_open_tp(int err, char *buf, size_t size, | 117 | int tracing_path__strerror_open_tp(int err, char *buf, size_t size, |
105 | const char *sys, const char *name) | 118 | const char *sys, const char *name) |
106 | { | 119 | { |
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 @@ | |||
3 | #define __API_FS_TRACING_PATH_H | 3 | #define __API_FS_TRACING_PATH_H |
4 | 4 | ||
5 | #include <linux/types.h> | 5 | #include <linux/types.h> |
6 | #include <dirent.h> | ||
6 | 7 | ||
7 | extern char tracing_events_path[]; | 8 | extern char tracing_events_path[]; |
8 | 9 | ||
10 | DIR *tracing_events__opendir(void); | ||
11 | |||
9 | void tracing_path_set(const char *mountpoint); | 12 | void tracing_path_set(const char *mountpoint); |
10 | const char *tracing_path_mount(void); | 13 | const char *tracing_path_mount(void); |
11 | 14 | ||
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) | |||
1323 | DIR *events_dir; | 1323 | DIR *events_dir; |
1324 | int cnt = 0; | 1324 | int cnt = 0; |
1325 | 1325 | ||
1326 | events_dir = opendir(tracing_events_path); | 1326 | events_dir = tracing_events__opendir(); |
1327 | 1327 | ||
1328 | TEST_ASSERT_VAL("Can't open events dir", events_dir); | 1328 | TEST_ASSERT_VAL("Can't open events dir", events_dir); |
1329 | 1329 | ||
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) | |||
191 | char evt_path[MAXPATHLEN]; | 191 | char evt_path[MAXPATHLEN]; |
192 | char *dir_path; | 192 | char *dir_path; |
193 | 193 | ||
194 | sys_dir = opendir(tracing_events_path); | 194 | sys_dir = tracing_events__opendir(); |
195 | if (!sys_dir) | 195 | if (!sys_dir) |
196 | return NULL; | 196 | return NULL; |
197 | 197 | ||
@@ -578,7 +578,7 @@ static int add_tracepoint_multi_sys(struct list_head *list, int *idx, | |||
578 | DIR *events_dir; | 578 | DIR *events_dir; |
579 | int ret = 0; | 579 | int ret = 0; |
580 | 580 | ||
581 | events_dir = opendir(tracing_events_path); | 581 | events_dir = tracing_events__opendir(); |
582 | if (!events_dir) { | 582 | if (!events_dir) { |
583 | tracepoint_error(err, errno, sys_name, evt_name); | 583 | tracepoint_error(err, errno, sys_name, evt_name); |
584 | return -1; | 584 | return -1; |
@@ -2106,7 +2106,7 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob, | |||
2106 | bool evt_num_known = false; | 2106 | bool evt_num_known = false; |
2107 | 2107 | ||
2108 | restart: | 2108 | restart: |
2109 | sys_dir = opendir(tracing_events_path); | 2109 | sys_dir = tracing_events__opendir(); |
2110 | if (!sys_dir) | 2110 | if (!sys_dir) |
2111 | return; | 2111 | return; |
2112 | 2112 | ||
@@ -2200,7 +2200,7 @@ int is_valid_tracepoint(const char *event_string) | |||
2200 | char evt_path[MAXPATHLEN]; | 2200 | char evt_path[MAXPATHLEN]; |
2201 | char *dir_path; | 2201 | char *dir_path; |
2202 | 2202 | ||
2203 | sys_dir = opendir(tracing_events_path); | 2203 | sys_dir = tracing_events__opendir(); |
2204 | if (!sys_dir) | 2204 | if (!sys_dir) |
2205 | return 0; | 2205 | return 0; |
2206 | 2206 | ||