Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1286206

[PATCH v2 06/14] perf: Split up cache.h

From Josh Poimboeuf <jpoimboe@redhat.com>
Newsgroups linux.kernel
Subject [PATCH v2 06/14] perf: Split up cache.h
Date 2015-12-08 05:30 +0100
Message-ID <qDi4y-5SE-29@gated-at.bofh.it> (permalink)
References <qDi4x-5SE-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


cache.h is a hodgepodge which consists of:

1) some macros
2) some includes
3) declarations for other .c files

Move the macros and declarations to more appropriate places.  This makes
the code more organized and makes it easier to separate out the
components later.  Some of the components will be moved out of perf into
a separate library.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 tools/perf/perf.h         | 12 ++++++++
 tools/perf/util/abspath.h | 11 ++++++++
 tools/perf/util/alias.h   |  7 +++++
 tools/perf/util/cache.h   | 72 ++++-------------------------------------------
 tools/perf/util/config.h  |  9 ++++++
 tools/perf/util/pager.h   |  7 +++++
 tools/perf/util/path.h    | 17 +++++++++++
 tools/perf/util/wrapper.h | 20 +++++++++++++
 8 files changed, 88 insertions(+), 67 deletions(-)
 create mode 100644 tools/perf/util/abspath.h
 create mode 100644 tools/perf/util/alias.h
 create mode 100644 tools/perf/util/pager.h
 create mode 100644 tools/perf/util/path.h

diff --git a/tools/perf/perf.h b/tools/perf/perf.h
index 90129ac..501acb4 100644
--- a/tools/perf/perf.h
+++ b/tools/perf/perf.h
@@ -6,6 +6,18 @@
 #include <linux/types.h>
 #include <linux/perf_event.h>
 
+#define CMD_EXEC_PATH "--exec-path"
+#define CMD_PERF_DIR "--perf-dir="
+#define CMD_WORK_TREE "--work-tree="
+#define CMD_DEBUGFS_DIR "--debugfs-dir="
+
+#define PERF_DIR_ENVIRONMENT "PERF_DIR"
+#define PERF_WORK_TREE_ENVIRONMENT "PERF_WORK_TREE"
+#define EXEC_PATH_ENVIRONMENT "PERF_EXEC_PATH"
+#define DEFAULT_PERF_DIR_ENVIRONMENT ".perf"
+#define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"
+#define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR"
+
 extern bool test_attr__enabled;
 void test_attr__init(void);
 void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu,
diff --git a/tools/perf/util/abspath.h b/tools/perf/util/abspath.h
new file mode 100644
index 0000000..13549fb
--- /dev/null
+++ b/tools/perf/util/abspath.h
@@ -0,0 +1,11 @@
+#ifndef __PERF_ABSPATH_H
+#define __PERF_ABSPATH_H
+
+static inline int is_absolute_path(const char *path)
+{
+	return path[0] == '/';
+}
+
+const char *make_nonrelative_path(const char *path);
+
+#endif /* __PERF_ABSPATH_H */
diff --git a/tools/perf/util/alias.h b/tools/perf/util/alias.h
new file mode 100644
index 0000000..23d4f84
--- /dev/null
+++ b/tools/perf/util/alias.h
@@ -0,0 +1,7 @@
+#ifndef __PERF_ALIAS_H
+#define __PERF_ALIAS_H
+
+char *alias_lookup(const char *alias);
+int split_cmdline(char *cmdline, const char ***argv);
+
+#endif /* __PERF_ALIAS_H */
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h
index 4c2b764..32e1f52 100644
--- a/tools/perf/util/cache.h
+++ b/tools/perf/util/cache.h
@@ -7,72 +7,10 @@
 #include "../perf.h"
 #include "../ui/ui.h"
 
-#define CMD_EXEC_PATH "--exec-path"
-#define CMD_PERF_DIR "--perf-dir="
-#define CMD_WORK_TREE "--work-tree="
-#define CMD_DEBUGFS_DIR "--debugfs-dir="
-
-#define PERF_DIR_ENVIRONMENT "PERF_DIR"
-#define PERF_WORK_TREE_ENVIRONMENT "PERF_WORK_TREE"
-#define EXEC_PATH_ENVIRONMENT "PERF_EXEC_PATH"
-#define DEFAULT_PERF_DIR_ENVIRONMENT ".perf"
-#define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"
-#define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR"
-
-typedef int (*config_fn_t)(const char *, const char *, void *);
-extern int perf_default_config(const char *, const char *, void *);
-extern int perf_config(config_fn_t fn, void *);
-extern int perf_config_int(const char *, const char *);
-extern u64 perf_config_u64(const char *, const char *);
-extern int perf_config_bool(const char *, const char *);
-extern int config_error_nonbool(const char *);
-extern const char *perf_config_dirname(const char *, const char *);
-
-/* pager.c */
-extern void setup_pager(void);
-extern int pager_in_use(void);
-
-char *alias_lookup(const char *alias);
-int split_cmdline(char *cmdline, const char ***argv);
-
-#define alloc_nr(x) (((x)+16)*3/2)
-
-/*
- * Realloc the buffer pointed at by variable 'x' so that it can hold
- * at least 'nr' entries; the number of entries currently allocated
- * is 'alloc', using the standard growing factor alloc_nr() macro.
- *
- * DO NOT USE any expression with side-effect for 'x' or 'alloc'.
- */
-#define ALLOC_GROW(x, nr, alloc) \
-	do { \
-		if ((nr) > alloc) { \
-			if (alloc_nr(alloc) < (nr)) \
-				alloc = (nr); \
-			else \
-				alloc = alloc_nr(alloc); \
-			x = xrealloc((x), alloc * sizeof(*(x))); \
-		} \
-	} while(0)
-
-
-static inline int is_absolute_path(const char *path)
-{
-	return path[0] == '/';
-}
-
-const char *make_nonrelative_path(const char *path);
-char *strip_path_suffix(const char *path, const char *suffix);
-
-extern char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
-extern char *perf_path(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
-
-extern char *perf_pathdup(const char *fmt, ...)
-	__attribute__((format (printf, 1, 2)));
-
-#ifndef __UCLIBC__
-/* Matches the libc/libbsd function attribute so we declare this unconditionally: */
-extern size_t strlcpy(char *dest, const char *src, size_t size);
-#endif
+#include "abspath.h"
+#include "alias.h"
+#include "config.h"
+#include "pager.h"
+#include "path.h"
 
 #endif /* __PERF_CACHE_H */
diff --git a/tools/perf/util/config.h b/tools/perf/util/config.h
index d48c647..8e53f6f 100644
--- a/tools/perf/util/config.h
+++ b/tools/perf/util/config.h
@@ -6,4 +6,13 @@
 extern char buildid_dir[];
 extern void set_buildid_dir(const char *dir);
 
+typedef int (*config_fn_t)(const char *, const char *, void *);
+extern int perf_default_config(const char *, const char *, void *);
+extern int perf_config(config_fn_t fn, void *);
+extern int perf_config_int(const char *, const char *);
+extern u64 perf_config_u64(const char *, const char *);
+extern int perf_config_bool(const char *, const char *);
+extern int config_error_nonbool(const char *);
+extern const char *perf_config_dirname(const char *, const char *);
+
 #endif /* __PERF_CONFIG_H */
diff --git a/tools/perf/util/pager.h b/tools/perf/util/pager.h
new file mode 100644
index 0000000..2794a83
--- /dev/null
+++ b/tools/perf/util/pager.h
@@ -0,0 +1,7 @@
+#ifndef __PERF_PAGER_H
+#define __PERF_PAGER_H
+
+extern void setup_pager(void);
+extern int pager_in_use(void);
+
+#endif /* __PERF_PAGER_H */
diff --git a/tools/perf/util/path.h b/tools/perf/util/path.h
new file mode 100644
index 0000000..3604e82f
--- /dev/null
+++ b/tools/perf/util/path.h
@@ -0,0 +1,17 @@
+#ifndef __PERF_PATH_H
+#define __PERF_PATH_H
+
+char *strip_path_suffix(const char *path, const char *suffix);
+
+extern char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
+extern char *perf_path(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
+
+extern char *perf_pathdup(const char *fmt, ...)
+	__attribute__((format (printf, 1, 2)));
+
+#ifndef __UCLIBC__
+/* Matches the libc/libbsd function attribute so we declare this unconditionally: */
+extern size_t strlcpy(char *dest, const char *src, size_t size);
+#endif
+
+#endif /* __PERF_PATH_H */
diff --git a/tools/perf/util/wrapper.h b/tools/perf/util/wrapper.h
index 510781b..e2fa014 100644
--- a/tools/perf/util/wrapper.h
+++ b/tools/perf/util/wrapper.h
@@ -11,4 +11,24 @@ static inline void *zalloc(size_t size)
 
 #define zfree(ptr) ({ free(*ptr); *ptr = NULL; })
 
+#define alloc_nr(x) (((x)+16)*3/2)
+
+/*
+ * Realloc the buffer pointed at by variable 'x' so that it can hold
+ * at least 'nr' entries; the number of entries currently allocated
+ * is 'alloc', using the standard growing factor alloc_nr() macro.
+ *
+ * DO NOT USE any expression with side-effect for 'x' or 'alloc'.
+ */
+#define ALLOC_GROW(x, nr, alloc) \
+	do { \
+		if ((nr) > alloc) { \
+			if (alloc_nr(alloc) < (nr)) \
+				alloc = (nr); \
+			else \
+				alloc = alloc_nr(alloc); \
+			x = xrealloc((x), alloc * sizeof(*(x))); \
+		} \
+	} while(0)
+
 #endif /* __PERF_WRAPPER_H */
-- 
2.4.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v2 00/14] perf tools: Move perf subcommand framework into lib/tools Josh Poimboeuf <jpoimboe@redhat.com> - 2015-12-08 05:30 +0100
  [PATCH v2 02/14] perf: Use -iquote for local include paths Josh Poimboeuf <jpoimboe@redhat.com> - 2015-12-08 05:30 +0100
  [PATCH v2 10/14] perf: Move cmd_version() to builtin-version.c Josh Poimboeuf <jpoimboe@redhat.com> - 2015-12-08 05:30 +0100
    [tip:perf/core] perf tools: Move cmd_version()   to builtin-version.c tip-bot for Josh Poimboeuf <tipbot@zytor.com> - 2015-12-10 09:20 +0100
  [PATCH v2 11/14] perf: Move help_unknown_cmd() to its own file Josh Poimboeuf <jpoimboe@redhat.com> - 2015-12-08 05:30 +0100
  [PATCH v2 09/14] perf: Remove check for unused PERF_PAGER_IN_USE Josh Poimboeuf <jpoimboe@redhat.com> - 2015-12-08 05:30 +0100
  [PATCH v2 06/14] perf: Split up cache.h Josh Poimboeuf <jpoimboe@redhat.com> - 2015-12-08 05:30 +0100
  [PATCH v2 04/14] perf: Move term functions out of util.c Josh Poimboeuf <jpoimboe@redhat.com> - 2015-12-08 05:30 +0100
    Re: [PATCH v2 04/14] perf: Move term functions out of util.c Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-12-09 17:00 +0100
    [tip:perf/core] perf tools: Move term functions out of util.c tip-bot for Josh Poimboeuf <tipbot@zytor.com> - 2015-12-10 09:20 +0100
  [PATCH v2 08/14] perf: Save cmdline arguments earlier Josh Poimboeuf <jpoimboe@redhat.com> - 2015-12-08 05:30 +0100
    [tip:perf/core] perf tools: Save cmdline arguments earlier tip-bot for Josh Poimboeuf <tipbot@zytor.com> - 2015-12-10 09:20 +0100
  [PATCH v2 07/14] perf: Remove cache.h Josh Poimboeuf <jpoimboe@redhat.com> - 2015-12-08 05:30 +0100
  [PATCH v2 13/14] perf tools: Move tools/lib/string.c to libapi Josh Poimboeuf <jpoimboe@redhat.com> - 2015-12-08 05:30 +0100
  Re: [PATCH v2 14/14] perf tools: Move subcommand framework and  related utils to libapi Josh Poimboeuf <jpoimboe@redhat.com> - 2015-12-08 20:20 +0100
    Re: [PATCH v2 14/14] perf tools: Move subcommand framework and  related utils to libapi Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-12-08 20:50 +0100
      Re: [PATCH v2 14/14] perf tools: Move subcommand framework and  related utils to libapi Josh Poimboeuf <jpoimboe@redhat.com> - 2015-12-08 22:50 +0100
        Re: [PATCH v2 14/14] perf tools: Move subcommand framework and  related utils to libapi Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-12-08 23:30 +0100
          Re: [PATCH v2 14/14] perf tools: Move subcommand framework and  related utils to libapi Josh Poimboeuf <jpoimboe@redhat.com> - 2015-12-09 00:10 +0100
            Re: [PATCH v2 14/14] perf tools: Move subcommand framework and  related utils to libapi Ingo Molnar <mingo@kernel.org> - 2015-12-09 09:10 +0100
              Re: [PATCH v2 14/14] perf tools: Move subcommand framework and  related utils to libapi Josh Poimboeuf <jpoimboe@redhat.com> - 2015-12-09 13:40 +0100
                Re: [PATCH v2 14/14] perf tools: Move subcommand framework and  related utils to libapi Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-12-09 17:00 +0100
                Re: [PATCH v2 14/14] perf tools: Move subcommand framework and  related utils to libapi Josh Poimboeuf <jpoimboe@redhat.com> - 2015-12-09 20:00 +0100
                Re: [PATCH v2 14/14] perf tools: Move subcommand framework and  related utils to libapi Namhyung Kim <namhyung@kernel.org> - 2015-12-10 04:00 +0100
                Re: [PATCH v2 14/14] perf tools: Move subcommand framework and  related utils to libapi Josh Poimboeuf <jpoimboe@redhat.com> - 2015-12-10 16:00 +0100
                Re: [PATCH v2 14/14] perf tools: Move subcommand framework and  related utils to libapi Josh Poimboeuf <jpoimboe@redhat.com> - 2015-12-10 22:40 +0100
                Re: [PATCH v2 14/14] perf tools: Move subcommand framework and  related utils to libapi Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-12-11 12:30 +0100
                Re: [PATCH v2 14/14] perf tools: Move subcommand framework and  related utils to libapi Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-12-10 14:00 +0100
                Re: [PATCH v2 14/14] perf tools: Move subcommand framework and  related utils to libapi Josh Poimboeuf <jpoimboe@redhat.com> - 2015-12-10 16:20 +0100
  Re: [PATCH v2 00/14] perf tools: Move perf subcommand framework into  lib/tools Namhyung Kim <namhyung@kernel.org> - 2015-12-10 05:10 +0100
    Re: [PATCH v2 00/14] perf tools: Move perf subcommand framework into  lib/tools Josh Poimboeuf <jpoimboe@redhat.com> - 2015-12-10 16:20 +0100

csiph-web