]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
tools lib api fs tracing_path: Introduce opendir() method
authorArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 17 May 2018 17:42:39 +0000 (14:42 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 17 May 2018 17:50:38 +0000 (14:50 -0300)
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
tools/lib/api/fs/tracing_path.h
tools/perf/tests/parse-events.c
tools/perf/util/parse-events.c

index 9cd28242592983b4b63f91e9b3f8d0bf7086718a..9b451af0721ccc59383ec6656298e14f13b5182e 100644 (file)
@@ -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)
 {
index 3b32fb439f12526aaaaae6c058eba08e00471468..904d085b2ae74ac7aaa006fa222b276b9ee1a4d3 100644 (file)
@@ -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);
 
index 6d57d708263763e3a9d86471fe6db3a6b266936e..b9ebe15afb1384e5a034f486cf145f2dd8f0773b 100644 (file)
@@ -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);
 
index 24668300b327760a434e478c5f36fac3e9ab34ae..15eec49e71a12ad89596f928e39874522c4a65df 100644 (file)
@@ -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;