Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1389148
| From | Arnaldo Carvalho de Melo <acme@kernel.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 17/30] perf tools: Add lsdir() helper to read a directory |
| Date | 2016-04-27 16:40 +0200 |
| Message-ID | <rsyNe-2L2-63@gated-at.bofh.it> (permalink) |
| References | <rsyNc-2L2-15@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
From: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
As a utility function, add lsdir() which reads given directory and store
entry name into a strlist. lsdir accepts a filter function so that user
can filter out unneeded entries.
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>
Cc: Hemant Kumar <hemant@linux.vnet.ibm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20160426090242.11891.79014.stgit@devbox
[ Do not use the 'dirname' it is used in some distros ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/util.c | 34 ++++++++++++++++++++++++++++++++++
tools/perf/util/util.h | 3 +++
2 files changed, 37 insertions(+)
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index b7766c577b01..9473d46c00bb 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -117,6 +117,40 @@ int rm_rf(char *path)
return rmdir(path);
}
+/* A filter which removes dot files */
+bool lsdir_no_dot_filter(const char *name __maybe_unused, struct dirent *d)
+{
+ return d->d_name[0] != '.';
+}
+
+/* lsdir reads a directory and store it in strlist */
+struct strlist *lsdir(const char *name,
+ bool (*filter)(const char *, struct dirent *))
+{
+ struct strlist *list = NULL;
+ DIR *dir;
+ struct dirent *d;
+
+ dir = opendir(name);
+ if (!dir)
+ return NULL;
+
+ list = strlist__new(NULL, NULL);
+ if (!list) {
+ errno = -ENOMEM;
+ goto out;
+ }
+
+ while ((d = readdir(dir)) != NULL) {
+ if (!filter || filter(name, d))
+ strlist__add(list, d->d_name);
+ }
+
+out:
+ closedir(dir);
+ return list;
+}
+
static int slow_copyfile(const char *from, const char *to)
{
int err = -1;
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 3bf3de86d429..26a924651e7b 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -79,6 +79,7 @@
#include <termios.h>
#include <linux/bitops.h>
#include <termios.h>
+#include "strlist.h"
extern const char *graph_line;
extern const char *graph_dotted_line;
@@ -222,6 +223,8 @@ static inline int sane_case(int x, int high)
int mkdir_p(char *path, mode_t mode);
int rm_rf(char *path);
+struct strlist *lsdir(const char *name, bool (*filter)(const char *, struct dirent *));
+bool lsdir_no_dot_filter(const char *name, struct dirent *d);
int copyfile(const char *from, const char *to);
int copyfile_mode(const char *from, const char *to, mode_t mode);
int copyfile_offset(int fromfd, loff_t from_ofs, int tofd, loff_t to_ofs, u64 size);
--
2.5.5
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-27 16:40 +0200 [PATCH 15/30] perf evlist: Enforce ring buffer reading Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-27 16:40 +0200 [PATCH 30/30] perf tools: Set the maximum allowed stack from /proc/sys/kernel/perf_event_max_stack Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-27 16:40 +0200 [PATCH 03/30] perf trace: Make --pf maj/min/all use callchains too Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-27 16:40 +0200 [PATCH 05/30] perf trace: Make --event honour --min-stack too Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-27 16:40 +0200 [PATCH 17/30] perf tools: Add lsdir() helper to read a directory Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-27 16:40 +0200 [PATCH 13/30] perf intel-pt: Fix off-by-one comparison on maximum code Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-27 16:40 +0200 [PATCH 25/30] perf probe: Fix offline module name missmatch issue Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-27 16:40 +0200 [PATCH 21/30] perf trace: Do not beautify the 'pid' parameter as a simple integer Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-27 16:40 +0200 [PATCH 29/30] perf core: Allow setting up max frame stack depth via sysctl Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-27 16:40 +0200 [PATCH 26/30] perf probe: Fix module probe issue if no dwarf support Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-27 16:50 +0200 [PATCH 14/30] perf hists: Clear dummy entry accumulated period Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-27 16:50 +0200 [PATCH 16/30] perf probe: Close target file on error path Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-27 16:50 +0200 [PATCH 09/30] tools build: Fix perf_clean target Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-27 16:50 +0200 [PATCH 08/30] perf tools: Make the x86 clean quiet Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-27 16:50 +0200 [PATCH 12/30] perf bench futex: Simplify wrapper for LOCK_PI Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-27 16:50 +0200 [PATCH 20/30] perf trace: Move perf_flags beautifier to tools/perf/trace/beauty/ Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-27 16:50 +0200 [PATCH 27/30] perf tools: Update x86's syscall_64.tbl, adding preadv2 & pwritev2 Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-27 16:50 +0200 [PATCH 04/30] perf script: Fix segfault when printing callchains Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-27 16:50 +0200 [PATCH 19/30] perf probe: Set default kprobe group name if it is not given Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-27 16:50 +0200 [PATCH 10/30] perf tools: Remove duplicate const qualifier Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-27 16:50 +0200 [PATCH 18/30] perf probe: Let probe_file__add_event return 0 if succeeded Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-27 16:50 +0200 [PATCH 11/30] perf tests: Replace assignment with comparison on assert check Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-27 16:50 +0200 [PATCH 06/30] perf trace: Make --pf honour --min-stack too Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-27 16:50 +0200 [PATCH 02/30] perf trace: Extract evsel contructor from perf_evlist__add_pgfault Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-27 16:50 +0200 [PATCH 28/30] perf bench: Remove one more die() call Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-27 16:50 +0200 [PATCH 01/30] perf buildid: Fix off-by-one in write_buildid() Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-27 16:50 +0200 Re: [GIT PULL 00/30] perf/core improvements and fixes Ingo Molnar <mingo@kernel.org> - 2016-04-27 17:10 +0200
csiph-web