Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools lib api fs tracing_path: Add scandir alphasort

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>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
1504b6f9 fe13d43d

+17
+16
tools/lib/api/fs/tracing_path.c
··· 113 113 return dir; 114 114 } 115 115 116 + int tracing_events__scandir_alphasort(struct dirent ***namelist) 117 + { 118 + char *path = get_tracing_file("events"); 119 + int ret; 120 + 121 + if (!path) { 122 + *namelist = NULL; 123 + return 0; 124 + } 125 + 126 + ret = scandir(path, namelist, NULL, alphasort); 127 + put_events_file(path); 128 + 129 + return ret; 130 + } 131 + 116 132 int tracing_path__strerror_open_tp(int err, char *buf, size_t size, 117 133 const char *sys, const char *name) 118 134 {
+1
tools/lib/api/fs/tracing_path.h
··· 6 6 #include <dirent.h> 7 7 8 8 DIR *tracing_events__opendir(void); 9 + int tracing_events__scandir_alphasort(struct dirent ***namelist); 9 10 10 11 void tracing_path_set(const char *mountpoint); 11 12 const char *tracing_path_mount(void);