Skip to content

Commit 7014e0e

Browse files
committed
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 <[email protected]> Cc: David Ahern <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Wang Nan <[email protected]> Link: https://lkml.kernel.org/n/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 25a7d91 commit 7014e0e

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

tools/lib/api/fs/tracing_path.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,19 @@ void put_events_file(char *file)
101101
free(file);
102102
}
103103

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+
104117
int tracing_path__strerror_open_tp(int err, char *buf, size_t size,
105118
const char *sys, const char *name)
106119
{

tools/lib/api/fs/tracing_path.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
#define __API_FS_TRACING_PATH_H
44

55
#include <linux/types.h>
6+
#include <dirent.h>
67

78
extern char tracing_events_path[];
89

10+
DIR *tracing_events__opendir(void);
11+
912
void tracing_path_set(const char *mountpoint);
1013
const char *tracing_path_mount(void);
1114

tools/perf/tests/parse-events.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,7 @@ static int count_tracepoints(void)
13231323
DIR *events_dir;
13241324
int cnt = 0;
13251325

1326-
events_dir = opendir(tracing_events_path);
1326+
events_dir = tracing_events__opendir();
13271327

13281328
TEST_ASSERT_VAL("Can't open events dir", events_dir);
13291329

tools/perf/util/parse-events.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
191191
char evt_path[MAXPATHLEN];
192192
char *dir_path;
193193

194-
sys_dir = opendir(tracing_events_path);
194+
sys_dir = tracing_events__opendir();
195195
if (!sys_dir)
196196
return NULL;
197197

@@ -578,7 +578,7 @@ static int add_tracepoint_multi_sys(struct list_head *list, int *idx,
578578
DIR *events_dir;
579579
int ret = 0;
580580

581-
events_dir = opendir(tracing_events_path);
581+
events_dir = tracing_events__opendir();
582582
if (!events_dir) {
583583
tracepoint_error(err, errno, sys_name, evt_name);
584584
return -1;
@@ -2106,7 +2106,7 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob,
21062106
bool evt_num_known = false;
21072107

21082108
restart:
2109-
sys_dir = opendir(tracing_events_path);
2109+
sys_dir = tracing_events__opendir();
21102110
if (!sys_dir)
21112111
return;
21122112

@@ -2200,7 +2200,7 @@ int is_valid_tracepoint(const char *event_string)
22002200
char evt_path[MAXPATHLEN];
22012201
char *dir_path;
22022202

2203-
sys_dir = opendir(tracing_events_path);
2203+
sys_dir = tracing_events__opendir();
22042204
if (!sys_dir)
22052205
return 0;
22062206

0 commit comments

Comments
 (0)