OSDN Git Service

tools lib api fs tracing_path: Add scandir alphasort
authorIan Rogers <irogers@google.com>
Mon, 14 Nov 2022 21:07:16 +0000 (13:07 -0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 15 Nov 2022 13:24:09 +0000 (10:24 -0300)
tracing_events__opendir() allows iteration over files in
<debugfs>/tracing/events but with an arbitrary sort order.

Add a scandir alternative where the results are alphabetically sorted.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-4-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/lib/api/fs/tracing_path.c
tools/lib/api/fs/tracing_path.h

index 5afb11b..b8e457c 100644 (file)
@@ -113,6 +113,22 @@ DIR *tracing_events__opendir(void)
        return dir;
 }
 
+int tracing_events__scandir_alphasort(struct dirent ***namelist)
+{
+       char *path = get_tracing_file("events");
+       int ret;
+
+       if (!path) {
+               *namelist = NULL;
+               return 0;
+       }
+
+       ret = scandir(path, namelist, NULL, alphasort);
+       put_events_file(path);
+
+       return ret;
+}
+
 int tracing_path__strerror_open_tp(int err, char *buf, size_t size,
                                   const char *sys, const char *name)
 {
index a19136b..fc6347c 100644 (file)
@@ -6,6 +6,7 @@
 #include <dirent.h>
 
 DIR *tracing_events__opendir(void);
+int tracing_events__scandir_alphasort(struct dirent ***namelist);
 
 void tracing_path_set(const char *mountpoint);
 const char *tracing_path_mount(void);