Skip to contentSkip to conversation

perf tools: Move perf subcommand framework to a library

PATCH In review Josh Poimboeuf 3 participants 23 messages Dec 15, 2015 – Dec 18, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v4 cover perf tools: Move perf subcommand framework to a library

Ingo suggested that I factor out the perf subcommand functionality (originally copied from git) into tools/lib so that it can be used by stacktool[*] and possibly others.

All the subcommand option handling files have been moved into a new library named libsubcmd.a, including parse-options.c, run-command.c, exec_cmd.c, help.c, usage.c, and pager.c.

Patch 1 is a cleanup I discovered in the process of making the patch set. It's completely separate from the rest of the patches and can be merged independently.

Patches 2-7 are some cleanups and splitting up of the code related to the creation of the new library.

Patch 8 does the actual moving of the files and creation of the new libsubcmd.a library in tools/lib/subcmd.

Patch 9 updates the names of the ifdef include guards for the moved .h files.

Based on acme/perf/core.

These patches can also be found in the 'perf-subcmd-v4' branch in the following repo:

https://github.com/jpoimboe/linux

[*] https://lkml.kernel.org/r/[email protected]

v4:
- Rebase onto latest acme/perf/core
- Reuse FILES variable instead of creating OUTPUT_FILES in feature Makefile
- Make changelogs more verbose
- Move strlcpy() to tools/lib/string.c
- Create shared subcmd_config struct in subcmd-config.c

v3:
- Remove dependencies on util.h, cache.h, abspath, ctype, strbuf, term, usage, wrapper
- Move to a new 'libsubcmd' library in tools/lib/subcmd
- Rebase onto Namhyung's patches which remove the browser dependency from parse-options.c
- Get rid of the util_cfg struct in favor of file-specific init functions
- Split up the patches better
- Document the fact that parse_options*() can exit
- Convert parse-options.c internal functions to static
- Rename exec_cmd.* to exec-cmd.*
- Add new astrcat() and astrcatf() functions to replace strbuf
- Add some more fixes related to 'make O=' and 'make clean' (though a 'make clean' is no longer required and these patches are now unrelated to libsubcmd)

v2:
- Fix 'make clean' to remove tests/llvm-src-*.c and other leftover files
- Fix description for second-to-last patch

Josh Poimboeuf (9):
tools build: Fix feature Makefile issues with 'O=' perf tools: Move strlcpy() from perf to tools/lib/string.c
perf: Document the fact that parse_options*() may exit
perf: Provide subcmd configuration at runtime
perf: Remove subcmd dependencies on strbuf
perf: Remove 'perf' from subcmd function and variable names
perf: Finalize subcmd independence
perf subcmd: Create subcmd library
tools subcmd: Rename subcmd header include guards

 tools/build/Makefile.feature                    |   2 +-
 tools/build/feature/Makefile                    |  93 +++++------
 tools/include/linux/string.h                    |   4 +
 tools/lib/string.c                              |  27 +++
 tools/lib/subcmd/Build                          |   7 +
 tools/lib/subcmd/Makefile                       |  48 ++++++
 tools/lib/subcmd/exec-cmd.c                     | 209 ++++++++++++++++++++++++
 tools/lib/subcmd/exec-cmd.h                     |  16 ++
 tools/{perf/util => lib/subcmd}/help.c          |  63 +++++--
 tools/{perf/util => lib/subcmd}/help.h          |  10 +-
 tools/{perf/util => lib/subcmd}/pager.c         |  15 +-
 tools/lib/subcmd/pager.h                        |   9 +
 tools/{perf/util => lib/subcmd}/parse-options.c | 116 +++++++------
 tools/{perf/util => lib/subcmd}/parse-options.h |  12 +-
 tools/{perf/util => lib/subcmd}/run-command.c   |  24 ++-
 tools/{perf/util => lib/subcmd}/run-command.h   |  12 +-
 tools/{perf/util => lib/subcmd}/sigchain.c      |   3 +-
 tools/{perf/util => lib/subcmd}/sigchain.h      |   6 +-
 tools/lib/subcmd/subcmd-config.c                |  11 ++
 tools/lib/subcmd/subcmd-config.h                |  14 ++
 tools/lib/subcmd/subcmd-util.h                  |  91 +++++++++++
 tools/perf/Build                                |   5 +-
 tools/perf/MANIFEST                             |   1 +
 tools/perf/Makefile.perf                        |  20 ++-
 tools/perf/arch/x86/util/intel-pt.c             |   2 +-
 tools/perf/bench/futex-hash.c                   |   2 +-
 tools/perf/bench/futex-lock-pi.c                |   2 +-
 tools/perf/bench/futex-requeue.c                |   2 +-
 tools/perf/bench/futex-wake-parallel.c          |   2 +-
 tools/perf/bench/futex-wake.c                   |   2 +-
 tools/perf/bench/mem-functions.c                |   2 +-
 tools/perf/bench/numa.c                         |   2 +-
 tools/perf/bench/sched-messaging.c              |   2 +-
 tools/perf/bench/sched-pipe.c                   |   2 +-
 tools/perf/builtin-annotate.c                   |   2 +-
 tools/perf/builtin-bench.c                      |   2 +-
 tools/perf/builtin-buildid-cache.c              |   2 +-
 tools/perf/builtin-buildid-list.c               |   2 +-
 tools/perf/builtin-config.c                     |   2 +-
 tools/perf/builtin-data.c                       |   2 +-
 tools/perf/builtin-evlist.c                     |   2 +-
 tools/perf/builtin-help.c                       |  10 +-
 tools/perf/builtin-inject.c                     |   2 +-
 tools/perf/builtin-kmem.c                       |   2 +-
 tools/perf/builtin-kvm.c                        |   2 +-
 tools/perf/builtin-list.c                       |   2 +-
 tools/perf/builtin-lock.c                       |   2 +-
 tools/perf/builtin-mem.c                        |   2 +-
 tools/perf/builtin-probe.c                      |   2 +-
 tools/perf/builtin-record.c                     |   2 +-
 tools/perf/builtin-report.c                     |   2 +-
 tools/perf/builtin-sched.c                      |   2 +-
 tools/perf/builtin-script.c                     |  12 +-
 tools/perf/builtin-stat.c                       |   2 +-
 tools/perf/builtin-timechart.c                  |   2 +-
 tools/perf/builtin-top.c                        |   2 +-
 tools/perf/builtin-trace.c                      |   4 +-
 tools/perf/perf.c                               |  18 +-
 tools/perf/tests/attr.c                         |   4 +-
 tools/perf/tests/builtin-test.c                 |   2 +-
 tools/perf/util/Build                           |   7 -
 tools/perf/util/auxtrace.c                      |   2 +-
 tools/perf/util/cache.h                         |  10 +-
 tools/perf/util/cgroup.c                        |   2 +-
 tools/perf/util/config.c                        |   2 +-
 tools/perf/util/evlist.c                        |   2 +-
 tools/perf/util/exec_cmd.c                      | 149 -----------------
 tools/perf/util/exec_cmd.h                      |  13 --
 tools/perf/util/help-unknown-cmd.c              |   2 +-
 tools/perf/util/pager.h                         |   7 -
 tools/perf/util/parse-branch-options.c          |   2 +-
 tools/perf/util/parse-events.c                  |   4 +-
 tools/perf/util/parse-regs-options.c            |   2 +-
 tools/perf/util/path.c                          |  18 --
 tools/perf/util/sort.h                          |   2 +-
 tools/perf/util/util.h                          |  14 --
 76 files changed, 749 insertions(+), 417 deletions(-)
 create mode 100644 tools/lib/subcmd/Build
 create mode 100644 tools/lib/subcmd/Makefile
 create mode 100644 tools/lib/subcmd/exec-cmd.c
 create mode 100644 tools/lib/subcmd/exec-cmd.h
 rename tools/{perf/util => lib/subcmd}/help.c (81%)
 rename tools/{perf/util => lib/subcmd}/help.h (87%)
 rename tools/{perf/util => lib/subcmd}/pager.c (85%)
 create mode 100644 tools/lib/subcmd/pager.h
 rename tools/{perf/util => lib/subcmd}/parse-options.c (90%)
 rename tools/{perf/util => lib/subcmd}/parse-options.h (96%)
 rename tools/{perf/util => lib/subcmd}/run-command.c (90%)
 rename tools/{perf/util => lib/subcmd}/run-command.h (86%)
 rename tools/{perf/util => lib/subcmd}/sigchain.c (95%)
 rename tools/{perf/util => lib/subcmd}/sigchain.h (55%)
 create mode 100644 tools/lib/subcmd/subcmd-config.c
 create mode 100644 tools/lib/subcmd/subcmd-config.h
 create mode 100644 tools/lib/subcmd/subcmd-util.h
 delete mode 100644 tools/perf/util/exec_cmd.c
 delete mode 100644 tools/perf/util/exec_cmd.h
 delete mode 100644 tools/perf/util/pager.h
Signature · 1 line
2.4.3
#3 lore raw

PATCH v4 2/9 perf tools: Move strlcpy() from perf to tools/lib/string.c

strlcpy() will be needed by the subcmd library. Move it to the shared tools/lib/string.c file which can be used by other tools.

---
 tools/include/linux/string.h |  4 ++++
 tools/lib/string.c           | 27 +++++++++++++++++++++++++++
 tools/perf/util/cache.h      |  7 ++-----
 tools/perf/util/path.c       | 18 ------------------
 4 files changed, 33 insertions(+), 23 deletions(-)
tools/include/linux/string.h +4 -0
index 2e2f736..e26223f 100644
@@ -8,4 +8,8 @@ void *memdup(const void *src, size_t len);
 
 int strtobool(const char *s, bool *res);
 
+#ifndef __UCLIBC__
+extern size_t strlcpy(char *dest, const char *src, size_t size);
+#endif
+
 #endif /* _LINUX_STRING_H_ */
tools/lib/string.c +27 -0
index 065e54f..bd239bc 100644
@@ -16,6 +16,7 @@
 #include <string.h>
 #include <errno.h>
 #include <linux/string.h>
+#include <linux/compiler.h>
 
 /**
  * memdup - duplicate region of memory
@@ -60,3 +61,29 @@ int strtobool(const char *s, bool *res)
 	}
 	return 0;
 }
+
+/**
+ * strlcpy - Copy a C-string into a sized buffer
+ * @dest: Where to copy the string to
+ * @src: Where to copy the string from
+ * @size: size of destination buffer
+ *
+ * Compatible with *BSD: the result is always a valid
+ * NUL-terminated string that fits in the buffer (unless,
+ * of course, the buffer size is zero). It does not pad
+ * out the result like strncpy() does.
+ *
+ * If libc has strlcpy() then that version will override this
+ * implementation:
+ */
+size_t __weak strlcpy(char *dest, const char *src, size_t size)
+{
+	size_t ret = strlen(src);
+
+	if (size) {
+		size_t len = (ret >= size) ? size - 1 : ret;
+		memcpy(dest, src, len);
+		dest[len] = '\0';
+	}
+	return ret;
+}
tools/perf/util/cache.h +2 -5
index 9ca4a58..d723ecb 100644
@@ -8,6 +8,8 @@
 #include "../perf.h"
 #include "../ui/ui.h"
 
+#include <linux/string.h>
+
 #define CMD_EXEC_PATH "--exec-path"
 #define CMD_PERF_DIR "--perf-dir="
 #define CMD_WORK_TREE "--work-tree="
@@ -67,9 +69,4 @@ 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_CACHE_H */
tools/perf/util/path.c +0 -18
index 5d13cb4..3654d96 100644
@@ -22,24 +22,6 @@ static const char *get_perf_dir(void)
 	return ".";
 }
 
-/*
- * If libc has strlcpy() then that version will override this
- * implementation:
- */
-size_t __weak strlcpy(char *dest, const char *src, size_t size)
-{
-	size_t ret = strlen(src);
-
-	if (size) {
-		size_t len = (ret >= size) ? size - 1 : ret;
-
-		memcpy(dest, src, len);
-		dest[len] = '\0';
-	}
-
-	return ret;
-}
-
 static char *get_pathname(void)
 {
 	static char pathname_array[4][PATH_MAX];
Signature · 1 line
2.4.3
#11 lore raw

PATCH v4 6/9 perf: Remove 'perf' from subcmd function and variable names

In reply to Josh Poimboeuf

In preparation for moving exec_cmd.c and run-command.c out of perf and into a library, remove 'perf' from all the symbol names.

---
 tools/perf/builtin-help.c     |  2 +-
 tools/perf/builtin-script.c   |  8 ++++----
 tools/perf/perf.c             |  6 +++---
 tools/perf/tests/attr.c       |  2 +-
 tools/perf/util/exec_cmd.c    | 20 ++++++++++----------
 tools/perf/util/exec_cmd.h    | 12 ++++++------
 tools/perf/util/help.c        |  4 ++--
 tools/perf/util/run-command.c |  6 +++---
 tools/perf/util/run-command.h |  4 ++--
 9 files changed, 32 insertions(+), 32 deletions(-)
tools/perf/builtin-help.c +1 -1
index a7d588b..275aa64 100644
@@ -407,7 +407,7 @@ static int get_html_page_path(struct strbuf *page_path, const char *page)
 #ifndef open_html
 static void open_html(const char *path)
 {
-	execl_perf_cmd("web--browse", "-c", "help.browser", path, NULL);
+	execl_cmd("web--browse", "-c", "help.browser", path, NULL);
 }
 #endif
 
tools/perf/builtin-script.c +4 -4
index d259e9a..571016f 100644
@@ -1408,7 +1408,7 @@ static int list_available_scripts(const struct option *opt __maybe_unused,
 	char first_half[BUFSIZ];
 	char *script_root;
 
-	snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path());
+	snprintf(scripts_path, MAXPATHLEN, "%s/scripts", get_argv_exec_path());
 
 	scripts_dir = opendir(scripts_path);
 	if (!scripts_dir)
@@ -1529,7 +1529,7 @@ int find_scripts(char **scripts_array, char **scripts_path_array)
 	if (!session)
 		return -1;
 
-	snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path());
+	snprintf(scripts_path, MAXPATHLEN, "%s/scripts", get_argv_exec_path());
 
 	scripts_dir = opendir(scripts_path);
 	if (!scripts_dir) {
@@ -1587,7 +1587,7 @@ static char *get_script_path(const char *script_root, const char *suffix)
 	char lang_path[MAXPATHLEN];
 	char *__script_root;
 
-	snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path());
+	snprintf(scripts_path, MAXPATHLEN, "%s/scripts", get_argv_exec_path());
 
 	scripts_dir = opendir(scripts_path);
 	if (!scripts_dir)
@@ -1823,7 +1823,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 		scripting_max_stack = itrace_synth_opts.callchain_sz;
 
 	/* make sure PERF_EXEC_PATH is set for scripts */
-	perf_set_argv_exec_path(perf_exec_path());
+	set_argv_exec_path(get_argv_exec_path());
 
 	if (argc && !script_name && !rec_script_path && !rep_script_path) {
 		int live_pipe[2];
tools/perf/perf.c +3 -3
index 783a331..6894325 100644
@@ -183,9 +183,9 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
 		if (!prefixcmp(cmd, CMD_EXEC_PATH)) {
 			cmd += strlen(CMD_EXEC_PATH);
 			if (*cmd == '=')
-				perf_set_argv_exec_path(cmd + 1);
+				set_argv_exec_path(cmd + 1);
 			else {
-				puts(perf_exec_path());
+				puts(get_argv_exec_path());
 				exit(0);
 			}
 		} else if (!strcmp(cmd, "--html-path")) {
@@ -538,7 +538,7 @@ int main(int argc, const char **argv)
 	page_size = sysconf(_SC_PAGE_SIZE);
 	cacheline_size = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
 
-	cmd = perf_extract_argv0_path(argv[0]);
+	cmd = extract_argv0_path(argv[0]);
 	if (!cmd)
 		cmd = "perf-help";
 
tools/perf/tests/attr.c +1 -1
index b66730e..6337f1c 100644
@@ -164,7 +164,7 @@ int test__attr(int subtest __maybe_unused)
 		return run_dir("./tests", "./perf");
 
 	/* Then installed path. */
-	snprintf(path_dir,  PATH_MAX, "%s/tests", perf_exec_path());
+	snprintf(path_dir,  PATH_MAX, "%s/tests", get_argv_exec_path());
 	snprintf(path_perf, PATH_MAX, "%s/perf", BINDIR);
 
 	if (!lstat(path_dir, &st) &&
tools/perf/util/exec_cmd.c +10 -10
index 65d86dc..701111a 100644
@@ -32,7 +32,7 @@ char *system_path(const char *path)
 	return buf;
 }
 
-const char *perf_extract_argv0_path(const char *argv0)
+const char *extract_argv0_path(const char *argv0)
 {
 	const char *slash;
 
@@ -51,7 +51,7 @@ const char *perf_extract_argv0_path(const char *argv0)
 	return argv0;
 }
 
-void perf_set_argv_exec_path(const char *exec_path)
+void set_argv_exec_path(const char *exec_path)
 {
 	argv_exec_path = exec_path;
 	/*
@@ -61,8 +61,8 @@ void perf_set_argv_exec_path(const char *exec_path)
 }
 
 
-/* Returns the highest-priority, location to look for perf programs. */
-char *perf_exec_path(void)
+/* Returns the highest-priority location to look for subprograms. */
+char *get_argv_exec_path(void)
 {
 	char *env;
 
@@ -92,7 +92,7 @@ void setup_path(void)
 {
 	const char *old_path = getenv("PATH");
 	char *new_path = NULL;
-	char *tmp = perf_exec_path();
+	char *tmp = get_argv_exec_path();
 
 	add_path(&new_path, tmp);
 	add_path(&new_path, argv0_path);
@@ -108,7 +108,7 @@ void setup_path(void)
 	free(new_path);
 }
 
-static const char **prepare_perf_cmd(const char **argv)
+static const char **prepare_exec_cmd(const char **argv)
 {
 	int argc;
 	const char **nargv;
@@ -124,8 +124,8 @@ static const char **prepare_perf_cmd(const char **argv)
 	return nargv;
 }
 
-int execv_perf_cmd(const char **argv) {
-	const char **nargv = prepare_perf_cmd(argv);
+int execv_cmd(const char **argv) {
+	const char **nargv = prepare_exec_cmd(argv);
 
 	/* execvp() can only ever return if it fails */
 	execvp(subcmd_config.exec_name, (char **)nargv);
@@ -135,7 +135,7 @@ int execv_perf_cmd(const char **argv) {
 }
 
 
-int execl_perf_cmd(const char *cmd,...)
+int execl_cmd(const char *cmd,...)
 {
 	int argc;
 	const char *argv[MAX_ARGS + 1];
@@ -155,5 +155,5 @@ int execl_perf_cmd(const char *cmd,...)
 		return error("too many args to run %s", cmd);
 
 	argv[argc] = NULL;
-	return execv_perf_cmd(argv);
+	return execv_cmd(argv);
 }
tools/perf/util/exec_cmd.h +6 -6
index fd4434e..f1bd343 100644
@@ -4,13 +4,13 @@
 extern void exec_cmd_init(const char *exec_name, const char *prefix,
 			  const char *exec_path, const char *exec_path_env);
 
-extern void perf_set_argv_exec_path(const char *exec_path);
-extern const char *perf_extract_argv0_path(const char *path);
+extern void set_argv_exec_path(const char *exec_path);
+extern const char *extract_argv0_path(const char *path);
 extern void setup_path(void);
-extern int execv_perf_cmd(const char **argv); /* NULL terminated */
-extern int execl_perf_cmd(const char *cmd, ...);
-/* perf_exec_path and system_path return malloc'd string, caller must free it */
-extern char *perf_exec_path(void);
+extern int execv_cmd(const char **argv); /* NULL terminated */
+extern int execl_cmd(const char *cmd, ...);
+/* get_argv_exec_path and system_path return malloc'd string, caller must free it */
+extern char *get_argv_exec_path(void);
 extern char *system_path(const char *path);
 
 #endif /* __PERF_EXEC_CMD_H */
tools/perf/util/help.c +2 -2
index 8e5e0ce..303a347 100644
@@ -155,7 +155,7 @@ void load_command_list(const char *prefix,
 		struct cmdnames *other_cmds)
 {
 	const char *env_path = getenv("PATH");
-	char *exec_path = perf_exec_path();
+	char *exec_path = get_argv_exec_path();
 
 	if (exec_path) {
 		list_commands_in_dir(main_cmds, exec_path, prefix);
@@ -200,7 +200,7 @@ void list_commands(const char *title, struct cmdnames *main_cmds,
 			longest = other_cmds->names[i]->len;
 
 	if (main_cmds->cnt) {
-		char *exec_path = perf_exec_path();
+		char *exec_path = get_argv_exec_path();
 		printf("available %s in '%s'\n", title, exec_path);
 		printf("----------------");
 		mput_char('-', strlen(title) + strlen(exec_path));
tools/perf/util/run-command.c +3 -3
index 34622b5..910c0f6 100644
@@ -112,8 +112,8 @@ int start_command(struct child_process *cmd)
 		}
 		if (cmd->preexec_cb)
 			cmd->preexec_cb();
-		if (cmd->perf_cmd) {
-			execv_perf_cmd(cmd->argv);
+		if (cmd->exec_cmd) {
+			execv_cmd(cmd->argv);
 		} else {
 			execvp(cmd->argv[0], (char *const*) cmd->argv);
 		}
@@ -207,7 +207,7 @@ static void prepare_run_command_v_opt(struct child_process *cmd,
 	memset(cmd, 0, sizeof(*cmd));
 	cmd->argv = argv;
 	cmd->no_stdin = opt & RUN_COMMAND_NO_STDIN ? 1 : 0;
-	cmd->perf_cmd = opt & RUN_PERF_CMD ? 1 : 0;
+	cmd->exec_cmd = opt & RUN_EXEC_CMD ? 1 : 0;
 	cmd->stdout_to_stderr = opt & RUN_COMMAND_STDOUT_TO_STDERR ? 1 : 0;
 }
 
tools/perf/util/run-command.h +2 -2
index 1ef264d..cf7d655 100644
@@ -41,7 +41,7 @@ struct child_process {
 	unsigned no_stdin:1;
 	unsigned no_stdout:1;
 	unsigned no_stderr:1;
-	unsigned perf_cmd:1; /* if this is to be perf sub-command */
+	unsigned exec_cmd:1; /* if this is to be external sub-command */
 	unsigned stdout_to_stderr:1;
 	void (*preexec_cb)(void);
 };
@@ -51,7 +51,7 @@ int finish_command(struct child_process *);
 int run_command(struct child_process *);
 
 #define RUN_COMMAND_NO_STDIN 1
-#define RUN_PERF_CMD	     2	/*If this is to be perf sub-command */
+#define RUN_EXEC_CMD	     2	/*If this is to be external sub-command */
 #define RUN_COMMAND_STDOUT_TO_STDERR 4
 int run_command_v_opt(const char **argv, int opt);
 
Signature · 1 line
2.4.3
#9 lore raw

PATCH v4 5/9 perf: Remove subcmd dependencies on strbuf

In reply to Josh Poimboeuf

Introduce and use new astrcat() and astrcatf() functions which replace the strbuf functionality for subcmd.

For now they duplicate strbuf's die-on-allocation-error policy.

---
 tools/perf/util/exec_cmd.c      | 27 +++++++++++++-------------
 tools/perf/util/help.c          | 14 ++++++--------
 tools/perf/util/parse-options.c | 42 +++++++++++++++++++++--------------------
 tools/perf/util/subcmd-util.h   | 24 +++++++++++++++++++++++
 4 files changed, 66 insertions(+), 41 deletions(-)
 create mode 100644 tools/perf/util/subcmd-util.h
tools/perf/util/exec_cmd.c +14 -13
index b935e4c..65d86dc 100644
@@ -4,6 +4,7 @@
 #include "subcmd-config.h"
 
 #include <string.h>
+#include "subcmd-util.h"
 
 #define MAX_ARGS	32
 
@@ -21,14 +22,14 @@ void exec_cmd_init(const char *exec_name, const char *prefix,
 
 char *system_path(const char *path)
 {
-	struct strbuf d = STRBUF_INIT;
+	char *buf = NULL;
 
 	if (is_absolute_path(path))
 		return strdup(path);
 
-	strbuf_addf(&d, "%s/%s", subcmd_config.prefix, path);
-	path = strbuf_detach(&d, NULL);
-	return (char *)path;
+	astrcatf(&buf, "%s/%s", subcmd_config.prefix, path);
+
+	return buf;
 }
 
 const char *perf_extract_argv0_path(const char *argv0)
@@ -75,22 +76,22 @@ char *perf_exec_path(void)
 	return system_path(subcmd_config.exec_path);
 }
 
-static void add_path(struct strbuf *out, const char *path)
+static void add_path(char **out, const char *path)
 {
 	if (path && *path) {
 		if (is_absolute_path(path))
-			strbuf_addstr(out, path);
+			astrcat(out, path);
 		else
-			strbuf_addstr(out, make_nonrelative_path(path));
+			astrcat(out, make_nonrelative_path(path));
 
-		strbuf_addch(out, PATH_SEP);
+		astrcat(out, ":");
 	}
 }
 
 void setup_path(void)
 {
 	const char *old_path = getenv("PATH");
-	struct strbuf new_path = STRBUF_INIT;
+	char *new_path = NULL;
 	char *tmp = perf_exec_path();
 
 	add_path(&new_path, tmp);
@@ -98,13 +99,13 @@ void setup_path(void)
 	free(tmp);
 
 	if (old_path)
-		strbuf_addstr(&new_path, old_path);
+		astrcat(&new_path, old_path);
 	else
-		strbuf_addstr(&new_path, "/usr/local/bin:/usr/bin:/bin");
+		astrcat(&new_path, "/usr/local/bin:/usr/bin:/bin");
 
-	setenv("PATH", new_path.buf, 1);
+	setenv("PATH", new_path, 1);
 
-	strbuf_release(&new_path);
+	free(new_path);
 }
 
 static const char **prepare_perf_cmd(const char **argv)
tools/perf/util/help.c +6 -8
index 8d74f7d..8e5e0ce 100644
@@ -2,6 +2,7 @@
 #include "../builtin.h"
 #include "exec_cmd.h"
 #include "help.h"
+#include "subcmd-util.h"
 
 void add_cmdname(struct cmdnames *cmds, const char *name, size_t len)
 {
@@ -119,8 +120,7 @@ static void list_commands_in_dir(struct cmdnames *cmds,
 	int prefix_len;
 	DIR *dir = opendir(path);
 	struct dirent *de;
-	struct strbuf buf = STRBUF_INIT;
-	int len;
+	char *buf = NULL;
 
 	if (!dir)
 		return;
@@ -128,8 +128,7 @@ static void list_commands_in_dir(struct cmdnames *cmds,
 		prefix = "perf-";
 	prefix_len = strlen(prefix);
 
-	strbuf_addf(&buf, "%s/", path);
-	len = buf.len;
+	astrcatf(&buf, "%s/", path);
 
 	while ((de = readdir(dir)) != NULL) {
 		int entlen;
@@ -137,9 +136,8 @@ static void list_commands_in_dir(struct cmdnames *cmds,
 		if (prefixcmp(de->d_name, prefix))
 			continue;
 
-		strbuf_setlen(&buf, len);
-		strbuf_addstr(&buf, de->d_name);
-		if (!is_executable(buf.buf))
+		astrcat(&buf, de->d_name);
+		if (!is_executable(buf))
 			continue;
 
 		entlen = strlen(de->d_name) - prefix_len;
@@ -149,7 +147,7 @@ static void list_commands_in_dir(struct cmdnames *cmds,
 		add_cmdname(cmds, de->d_name + prefix_len, entlen);
 	}
 	closedir(dir);
-	strbuf_release(&buf);
+	free(buf);
 }
 
 void load_command_list(const char *prefix,
tools/perf/util/parse-options.c +22 -20

85 lines not on this page · raw message

tools/perf/util/subcmd-util.h new file +24 -0
new file mode 100644
index 0000000..98fb9f9
@@ -0,0 +1,24 @@
+#ifndef __PERF_SUBCMD_UTIL_H
+#define __PERF_SUBCMD_UTIL_H
+
+#include <stdio.h>
+
+#define astrcatf(out, fmt, ...)						\
+({									\
+	char *tmp = *(out);						\
+	if (asprintf((out), "%s" fmt, tmp ?: "", ## __VA_ARGS__) == -1)	\
+		die("asprintf failed");					\
+	free(tmp);							\
+})
+
+static inline void astrcat(char **out, const char *add)
+{
+	char *tmp = *out;
+
+	if (asprintf(out, "%s%s", tmp ?: "", add) == -1)
+		die("asprintf failed");
+
+	free(tmp);
+}
+
+#endif /* __PERF_SUBCMD_UTIL_H */
Signature · 1 line
2.4.3
#21 lore raw

PATCH v4 9/9 tools subcmd: Rename subcmd header include guards

In reply to Josh Poimboeuf
---
 tools/lib/subcmd/exec-cmd.h      | 6 +++---
 tools/lib/subcmd/help.h          | 6 +++---
 tools/lib/subcmd/pager.h         | 6 +++---
 tools/lib/subcmd/parse-options.h | 7 ++++---
 tools/lib/subcmd/run-command.h   | 6 +++---
 tools/lib/subcmd/sigchain.h      | 6 +++---
 tools/lib/subcmd/subcmd-util.h   | 6 +++---
 7 files changed, 22 insertions(+), 21 deletions(-)
tools/lib/subcmd/exec-cmd.h +3 -3
index f1bd343..5d08bda 100644
@@ -1,5 +1,5 @@
-#ifndef __PERF_EXEC_CMD_H
-#define __PERF_EXEC_CMD_H
+#ifndef __SUBCMD_EXEC_CMD_H
+#define __SUBCMD_EXEC_CMD_H
 
 extern void exec_cmd_init(const char *exec_name, const char *prefix,
 			  const char *exec_path, const char *exec_path_env);
@@ -13,4 +13,4 @@ extern int execl_cmd(const char *cmd, ...);
 extern char *get_argv_exec_path(void);
 extern char *system_path(const char *path);
 
-#endif /* __PERF_EXEC_CMD_H */
+#endif /* __SUBCMD_EXEC_CMD_H */
tools/lib/subcmd/help.h +3 -3
index 096c8bc..e145a02 100644
@@ -1,5 +1,5 @@
-#ifndef __PERF_HELP_H
-#define __PERF_HELP_H
+#ifndef __SUBCMD_HELP_H
+#define __SUBCMD_HELP_H
 
 #include <sys/types.h>
 
@@ -31,4 +31,4 @@ int is_in_cmdlist(struct cmdnames *c, const char *s);
 void list_commands(const char *title, struct cmdnames *main_cmds,
 		   struct cmdnames *other_cmds);
 
-#endif /* __PERF_HELP_H */
+#endif /* __SUBCMD_HELP_H */
tools/lib/subcmd/pager.h +3 -3
index d6a591a..8b83714 100644
@@ -1,9 +1,9 @@
-#ifndef __PERF_PAGER_H
-#define __PERF_PAGER_H
+#ifndef __SUBCMD_PAGER_H
+#define __SUBCMD_PAGER_H
 
 extern void pager_init(const char *pager_env);
 
 extern void setup_pager(void);
 extern int pager_in_use(void);
 
-#endif /* __PERF_PAGER_H */
+#endif /* __SUBCMD_PAGER_H */
tools/lib/subcmd/parse-options.h +4 -3
index dec893f..13a2cc1 100644
@@ -1,5 +1,5 @@
-#ifndef __PERF_PARSE_OPTIONS_H
-#define __PERF_PARSE_OPTIONS_H
+#ifndef __SUBCMD_PARSE_OPTIONS_H
+#define __SUBCMD_PARSE_OPTIONS_H
 
 #include <stdbool.h>
 #include <stdint.h>
@@ -225,4 +225,5 @@ extern const char *parse_options_fix_filename(const char *prefix, const char *fi
 void set_option_flag(struct option *opts, int sopt, const char *lopt, int flag);
 void set_option_nobuild(struct option *opts, int shortopt, const char *longopt,
 			const char *build_opt, bool can_skip);
-#endif /* __PERF_PARSE_OPTIONS_H */
+
+#endif /* __SUBCMD_PARSE_OPTIONS_H */
tools/lib/subcmd/run-command.h +3 -3
index 4a55393..fe2befe 100644
@@ -1,5 +1,5 @@
-#ifndef __PERF_RUN_COMMAND_H
-#define __PERF_RUN_COMMAND_H
+#ifndef __SUBCMD_RUN_COMMAND_H
+#define __SUBCMD_RUN_COMMAND_H
 
 #include <unistd.h>
 
@@ -57,4 +57,4 @@ int run_command(struct child_process *);
 #define RUN_COMMAND_STDOUT_TO_STDERR 4
 int run_command_v_opt(const char **argv, int opt);
 
-#endif /* __PERF_RUN_COMMAND_H */
+#endif /* __SUBCMD_RUN_COMMAND_H */
tools/lib/subcmd/sigchain.h +3 -3
index 959d64e..0c919f2 100644
@@ -1,5 +1,5 @@
-#ifndef __PERF_SIGCHAIN_H
-#define __PERF_SIGCHAIN_H
+#ifndef __SUBCMD_SIGCHAIN_H
+#define __SUBCMD_SIGCHAIN_H
 
 typedef void (*sigchain_fun)(int);
 
@@ -7,4 +7,4 @@ int sigchain_pop(int sig);
 
 void sigchain_push_common(sigchain_fun f);
 
-#endif /* __PERF_SIGCHAIN_H */
+#endif /* __SUBCMD_SIGCHAIN_H */
tools/lib/subcmd/subcmd-util.h +3 -3
index 321aeb1..fc2e45d 100644
@@ -1,5 +1,5 @@
-#ifndef __PERF_SUBCMD_UTIL_H
-#define __PERF_SUBCMD_UTIL_H
+#ifndef __SUBCMD_UTIL_H
+#define __SUBCMD_UTIL_H
 
 #include <stdarg.h>
 #include <stdlib.h>
@@ -88,4 +88,4 @@ static inline int prefixcmp(const char *str, const char *prefix)
 			return (unsigned char)*prefix - (unsigned char)*str;
 }
 
-#endif /* __PERF_SUBCMD_UTIL_H */
+#endif /* __SUBCMD_UTIL_H */
Signature · 1 line
2.4.3
#19 lore raw

PATCH v4 8/9 perf subcmd: Create subcmd library

In reply to Josh Poimboeuf

Move the subcommand-related files from perf to a new library named libsubcmd.a.

Since we're moving files anyway, go ahead and rename 'exec_cmd.*' to 'exec-cmd.*' to be consistent with the naming of all the other files.

---
 tools/lib/subcmd/Build                             |  7 ++++
 tools/lib/subcmd/Makefile                          | 48 ++++++++++++++++++++++
 .../util/exec_cmd.c => lib/subcmd/exec-cmd.c}      |  2 +-
 .../util/exec_cmd.h => lib/subcmd/exec-cmd.h}      |  0
 tools/{perf/util => lib/subcmd}/help.c             |  2 +-
 tools/{perf/util => lib/subcmd}/help.h             |  0
 tools/{perf/util => lib/subcmd}/pager.c            |  0
 tools/{perf/util => lib/subcmd}/pager.h            |  0
 tools/{perf/util => lib/subcmd}/parse-options.c    |  0
 tools/{perf/util => lib/subcmd}/parse-options.h    |  0
 tools/{perf/util => lib/subcmd}/run-command.c      |  2 +-
 tools/{perf/util => lib/subcmd}/run-command.h      |  0
 tools/{perf/util => lib/subcmd}/sigchain.c         |  0
 tools/{perf/util => lib/subcmd}/sigchain.h         |  0
 tools/{perf/util => lib/subcmd}/subcmd-config.c    |  0
 tools/{perf/util => lib/subcmd}/subcmd-config.h    |  0
 tools/{perf/util => lib/subcmd}/subcmd-util.h      |  0
 tools/perf/MANIFEST                                |  1 +
 tools/perf/Makefile.perf                           | 20 +++++++--
 tools/perf/arch/x86/util/intel-pt.c                |  2 +-
 tools/perf/bench/futex-hash.c                      |  2 +-
 tools/perf/bench/futex-lock-pi.c                   |  2 +-
 tools/perf/bench/futex-requeue.c                   |  2 +-
 tools/perf/bench/futex-wake-parallel.c             |  2 +-
 tools/perf/bench/futex-wake.c                      |  2 +-
 tools/perf/bench/mem-functions.c                   |  2 +-
 tools/perf/bench/numa.c                            |  2 +-
 tools/perf/bench/sched-messaging.c                 |  2 +-
 tools/perf/bench/sched-pipe.c                      |  2 +-
 tools/perf/builtin-annotate.c                      |  2 +-
 tools/perf/builtin-bench.c                         |  2 +-
 tools/perf/builtin-buildid-cache.c                 |  2 +-
 tools/perf/builtin-buildid-list.c                  |  2 +-
 tools/perf/builtin-config.c                        |  2 +-
 tools/perf/builtin-data.c                          |  2 +-
 tools/perf/builtin-evlist.c                        |  2 +-
 tools/perf/builtin-help.c                          |  8 ++--
 tools/perf/builtin-inject.c                        |  2 +-
 tools/perf/builtin-kmem.c                          |  2 +-
 tools/perf/builtin-kvm.c                           |  2 +-
 tools/perf/builtin-list.c                          |  2 +-
 tools/perf/builtin-lock.c                          |  2 +-
 tools/perf/builtin-mem.c                           |  2 +-
 tools/perf/builtin-probe.c                         |  2 +-
 tools/perf/builtin-record.c                        |  2 +-
 tools/perf/builtin-report.c                        |  2 +-
 tools/perf/builtin-sched.c                         |  2 +-
 tools/perf/builtin-script.c                        |  4 +-
 tools/perf/builtin-stat.c                          |  2 +-
 tools/perf/builtin-timechart.c                     |  2 +-
 tools/perf/builtin-top.c                           |  2 +-
 tools/perf/builtin-trace.c                         |  4 +-
 tools/perf/perf.c                                  |  6 +--
 tools/perf/tests/attr.c                            |  2 +-
 tools/perf/tests/builtin-test.c                    |  2 +-
 tools/perf/util/Build                              |  7 ----
 tools/perf/util/auxtrace.c                         |  2 +-
 tools/perf/util/cache.h                            |  2 +-
 tools/perf/util/cgroup.c                           |  2 +-
 tools/perf/util/config.c                           |  2 +-
 tools/perf/util/evlist.c                           |  2 +-
 tools/perf/util/help-unknown-cmd.c                 |  2 +-
 tools/perf/util/parse-branch-options.c             |  2 +-
 tools/perf/util/parse-events.c                     |  4 +-
 tools/perf/util/parse-regs-options.c               |  2 +-
 tools/perf/util/sort.h                             |  2 +-
 66 files changed, 129 insertions(+), 68 deletions(-)
 create mode 100644 tools/lib/subcmd/Build
 create mode 100644 tools/lib/subcmd/Makefile
 rename tools/{perf/util/exec_cmd.c => lib/subcmd/exec-cmd.c} (99%)
 rename tools/{perf/util/exec_cmd.h => lib/subcmd/exec-cmd.h} (100%)
 rename tools/{perf/util => lib/subcmd}/help.c (99%)
 rename tools/{perf/util => lib/subcmd}/help.h (100%)
 rename tools/{perf/util => lib/subcmd}/pager.c (100%)
 rename tools/{perf/util => lib/subcmd}/pager.h (100%)
 rename tools/{perf/util => lib/subcmd}/parse-options.c (100%)
 rename tools/{perf/util => lib/subcmd}/parse-options.h (100%)
 rename tools/{perf/util => lib/subcmd}/run-command.c (99%)
 rename tools/{perf/util => lib/subcmd}/run-command.h (100%)
 rename tools/{perf/util => lib/subcmd}/sigchain.c (100%)
 rename tools/{perf/util => lib/subcmd}/sigchain.h (100%)
 rename tools/{perf/util => lib/subcmd}/subcmd-config.c (100%)
 rename tools/{perf/util => lib/subcmd}/subcmd-config.h (100%)
 rename tools/{perf/util => lib/subcmd}/subcmd-util.h (100%)
tools/lib/subcmd/Build new file +7 -0
new file mode 100644
index 0000000..ee31288
@@ -0,0 +1,7 @@
+libsubcmd-y += exec-cmd.o
+libsubcmd-y += help.o
+libsubcmd-y += pager.o
+libsubcmd-y += parse-options.o
+libsubcmd-y += run-command.o
+libsubcmd-y += sigchain.o
+libsubcmd-y += subcmd-config.o
tools/lib/subcmd/Makefile new file +48 -0

48 lines not on this page · raw message

tools/lib/subcmd/exec-cmd.c renamed from tools/perf/util/exec_cmd.c +1 -1
similarity index 99%
rename from tools/perf/util/exec_cmd.c
rename to tools/lib/subcmd/exec-cmd.c
index e7f9ed79..1ae833a 100644
@@ -7,7 +7,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include "subcmd-util.h"
-#include "exec_cmd.h"
+#include "exec-cmd.h"
 #include "subcmd-config.h"
 
 #define MAX_ARGS	32
tools/lib/subcmd/exec-cmd.h renamed from tools/perf/util/exec_cmd.h +0 -0
similarity index 100%
rename from tools/perf/util/exec_cmd.h
rename to tools/lib/subcmd/exec-cmd.h
tools/lib/subcmd/help.c renamed from tools/perf/util/help.c +1 -1
similarity index 99%
rename from tools/perf/util/help.c
rename to tools/lib/subcmd/help.c
index 8169480..e228c3c 100644
@@ -9,7 +9,7 @@
 #include <dirent.h>
 #include "subcmd-util.h"
 #include "help.h"
-#include "exec_cmd.h"
+#include "exec-cmd.h"
 
 void add_cmdname(struct cmdnames *cmds, const char *name, size_t len)
 {
tools/lib/subcmd/help.h renamed from tools/perf/util/help.h +0 -0
similarity index 100%
rename from tools/perf/util/help.h
rename to tools/lib/subcmd/help.h
tools/lib/subcmd/pager.c renamed from tools/perf/util/pager.c +0 -0
similarity index 100%
rename from tools/perf/util/pager.c
rename to tools/lib/subcmd/pager.c
tools/lib/subcmd/pager.h renamed from tools/perf/util/pager.h +0 -0
similarity index 100%
rename from tools/perf/util/pager.h
rename to tools/lib/subcmd/pager.h
tools/lib/subcmd/parse-options.c renamed from tools/perf/util/parse-options.c +0 -0
similarity index 100%
rename from tools/perf/util/parse-options.c
rename to tools/lib/subcmd/parse-options.c
tools/lib/subcmd/parse-options.h renamed from tools/perf/util/parse-options.h +0 -0
similarity index 100%
rename from tools/perf/util/parse-options.h
rename to tools/lib/subcmd/parse-options.h
tools/lib/subcmd/run-command.c renamed from tools/perf/util/run-command.c +1 -1
similarity index 99%
rename from tools/perf/util/run-command.c
rename to tools/lib/subcmd/run-command.c
index fed37d6..f4f6c9e 100644
@@ -7,7 +7,7 @@
 #include <sys/wait.h>
 #include "subcmd-util.h"
 #include "run-command.h"
-#include "exec_cmd.h"
+#include "exec-cmd.h"
 
 #define STRERR_BUFSIZE 128
 
tools/lib/subcmd/run-command.h renamed from tools/perf/util/run-command.h +0 -0
similarity index 100%
rename from tools/perf/util/run-command.h
rename to tools/lib/subcmd/run-command.h
tools/lib/subcmd/sigchain.c renamed from tools/perf/util/sigchain.c +0 -0
similarity index 100%
rename from tools/perf/util/sigchain.c
rename to tools/lib/subcmd/sigchain.c
tools/lib/subcmd/sigchain.h renamed from tools/perf/util/sigchain.h +0 -0
similarity index 100%
rename from tools/perf/util/sigchain.h
rename to tools/lib/subcmd/sigchain.h
tools/lib/subcmd/subcmd-config.c renamed from tools/perf/util/subcmd-config.c +0 -0
similarity index 100%
rename from tools/perf/util/subcmd-config.c
rename to tools/lib/subcmd/subcmd-config.c
tools/lib/subcmd/subcmd-config.h renamed from tools/perf/util/subcmd-config.h +0 -0
similarity index 100%
rename from tools/perf/util/subcmd-config.h
rename to tools/lib/subcmd/subcmd-config.h
tools/lib/subcmd/subcmd-util.h renamed from tools/perf/util/subcmd-util.h +0 -0
similarity index 100%
rename from tools/perf/util/subcmd-util.h
rename to tools/lib/subcmd/subcmd-util.h
tools/perf/MANIFEST +1 -0
index 2562eac..ce3932e 100644
@@ -20,6 +20,7 @@ tools/lib/traceevent
 tools/lib/bpf
 tools/lib/api
 tools/lib/bpf
+tools/lib/subcmd
 tools/lib/hweight.c
 tools/lib/rbtree.c
 tools/lib/string.c
tools/perf/Makefile.perf +16 -4
index 388ec64..569fcf0 100644
@@ -145,9 +145,10 @@ BISON   = bison
 STRIP   = strip
 AWK     = awk
 
-LIB_DIR          = $(srctree)/tools/lib/api/
+LIB_DIR		= $(srctree)/tools/lib/api/
 TRACE_EVENT_DIR = $(srctree)/tools/lib/traceevent/
-BPF_DIR = $(srctree)/tools/lib/bpf/
+BPF_DIR		= $(srctree)/tools/lib/bpf/
+SUBCMD_DIR	= $(srctree)/tools/lib/subcmd/
 
 # include config/Makefile by default and rule out
 # non-config cases
@@ -184,6 +185,7 @@ strip-libs = $(filter-out -l%,$(1))
 ifneq ($(OUTPUT),)
   TE_PATH=$(OUTPUT)
   BPF_PATH=$(OUTPUT)
+  SUBCMD_PATH=$(OUTPUT)
 ifneq ($(subdir),)
   API_PATH=$(OUTPUT)/../lib/api/
 else
@@ -193,6 +195,7 @@ else
   TE_PATH=$(TRACE_EVENT_DIR)
   API_PATH=$(LIB_DIR)
   BPF_PATH=$(BPF_DIR)
+  SUBCMD_PATH=$(SUBCMD_DIR)
 endif
 
 LIBTRACEEVENT = $(TE_PATH)libtraceevent.a
@@ -206,6 +209,8 @@ export LIBAPI
 
 LIBBPF = $(BPF_PATH)libbpf.a
 
+LIBSUBCMD = $(SUBCMD_PATH)libsubcmd.a
+
 # python extension build directories
 PYTHON_EXTBUILD     := $(OUTPUT)python_ext_build/
 PYTHON_EXTBUILD_LIB := $(PYTHON_EXTBUILD)lib/
@@ -257,7 +262,7 @@ export PERL_PATH
 
 LIB_FILE=$(OUTPUT)libperf.a
 
-PERFLIBS = $(LIB_FILE) $(LIBAPI) $(LIBTRACEEVENT)
+PERFLIBS = $(LIB_FILE) $(LIBAPI) $(LIBTRACEEVENT) $(LIBSUBCMD)
 ifndef NO_LIBBPF
   PERFLIBS += $(LIBBPF)
 endif
@@ -437,6 +442,13 @@ $(LIBBPF)-clean:
 	$(call QUIET_CLEAN, libbpf)
 	$(Q)$(MAKE) -C $(BPF_DIR) O=$(OUTPUT) clean >/dev/null
 
+$(LIBSUBCMD): fixdep FORCE
+	$(Q)$(MAKE) -C $(SUBCMD_DIR) O=$(OUTPUT) $(OUTPUT)libsubcmd.a
+
+$(LIBSUBCMD)-clean:
+	$(call QUIET_CLEAN, libsubcmd)
+	$(Q)$(MAKE) -C $(SUBCMD_DIR) O=$(OUTPUT) clean
+
 help:
 	@echo 'Perf make targets:'
 	@echo '  doc		- make *all* documentation (see below)'
@@ -584,7 +596,7 @@ config-clean:
 	$(call QUIET_CLEAN, config)
 	$(Q)$(MAKE) -C $(srctree)/tools/build/feature/ $(if $(OUTPUT),OUTPUT=$(OUTPUT)feature/,) clean >/dev/null
 
-clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean config-clean
+clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean config-clean
 	$(call QUIET_CLEAN, core-objs)  $(RM) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(LANG_BINDINGS)
 	$(Q)find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
 	$(Q)$(RM) $(OUTPUT).config-detected
tools/perf/arch/x86/util/intel-pt.c +1 -1
index b02af06..b64d462 100644
@@ -26,7 +26,7 @@
 #include "../../util/evlist.h"
 #include "../../util/evsel.h"
 #include "../../util/cpumap.h"
-#include "../../util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "../../util/parse-events.h"
 #include "../../util/pmu.h"
 #include "../../util/debug.h"
tools/perf/bench/futex-hash.c +1 -1
index fc9bebd..0999ac5 100644
@@ -11,7 +11,7 @@
 #include "../perf.h"
 #include "../util/util.h"
 #include "../util/stat.h"
-#include "../util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "../util/header.h"
 #include "bench.h"
 #include "futex.h"
tools/perf/bench/futex-lock-pi.c +1 -1
index bc6a16a..6a18ce2 100644
@@ -5,7 +5,7 @@
 #include "../perf.h"
 #include "../util/util.h"
 #include "../util/stat.h"
-#include "../util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "../util/header.h"
 #include "bench.h"
 #include "futex.h"
tools/perf/bench/futex-requeue.c +1 -1
index ad0d9b5..7182386 100644
@@ -11,7 +11,7 @@
 #include "../perf.h"
 #include "../util/util.h"
 #include "../util/stat.h"
-#include "../util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "../util/header.h"
 #include "bench.h"
 #include "futex.h"
tools/perf/bench/futex-wake-parallel.c +1 -1
index 6d8c9fa..91aaf2a 100644
@@ -10,7 +10,7 @@
 #include "../perf.h"
 #include "../util/util.h"
 #include "../util/stat.h"
-#include "../util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "../util/header.h"
 #include "bench.h"
 #include "futex.h"
tools/perf/bench/futex-wake.c +1 -1
index e5e41d3..f416bd7 100644
@@ -11,7 +11,7 @@
 #include "../perf.h"
 #include "../util/util.h"
 #include "../util/stat.h"
-#include "../util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "../util/header.h"
 #include "bench.h"
 #include "futex.h"
tools/perf/bench/mem-functions.c +1 -1
index 9419b94..a91aa85 100644
@@ -8,7 +8,7 @@
 
 #include "../perf.h"
 #include "../util/util.h"
-#include "../util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "../util/header.h"
 #include "../util/cloexec.h"
 #include "bench.h"
tools/perf/bench/numa.c +1 -1
index 492df27..5049d63 100644
@@ -7,7 +7,7 @@
 #include "../perf.h"
 #include "../builtin.h"
 #include "../util/util.h"
-#include "../util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "../util/cloexec.h"
 
 #include "bench.h"
tools/perf/bench/sched-messaging.c +1 -1
index d4ff1b5..bfaf950 100644
@@ -11,7 +11,7 @@
 
 #include "../perf.h"
 #include "../util/util.h"
-#include "../util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "../builtin.h"
 #include "bench.h"
 
tools/perf/bench/sched-pipe.c +1 -1
index 005cc28..1dc2d13 100644
@@ -10,7 +10,7 @@
  */
 #include "../perf.h"
 #include "../util/util.h"
-#include "../util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "../builtin.h"
 #include "bench.h"
 
tools/perf/builtin-annotate.c +1 -1
index 1f00dc7..e18f1b9 100644
@@ -21,7 +21,7 @@
 #include "util/evsel.h"
 #include "util/annotate.h"
 #include "util/event.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/parse-events.h"
 #include "util/thread.h"
 #include "util/sort.h"
tools/perf/builtin-bench.c +1 -1
index b17aed3..a1cddc6 100644
@@ -16,7 +16,7 @@
  */
 #include "perf.h"
 #include "util/util.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "builtin.h"
 #include "bench/bench.h"
 
tools/perf/builtin-buildid-cache.c +1 -1
index 7b8450c..d93bff7 100644
@@ -16,7 +16,7 @@
 #include "util/cache.h"
 #include "util/debug.h"
 #include "util/header.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/strlist.h"
 #include "util/build-id.h"
 #include "util/session.h"
tools/perf/builtin-buildid-list.c +1 -1
index 6419f57..5e914ee 100644
@@ -12,7 +12,7 @@
 #include "util/build-id.h"
 #include "util/cache.h"
 #include "util/debug.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/session.h"
 #include "util/symbol.h"
 #include "util/data.h"
tools/perf/builtin-config.c +1 -1
index 427ea7a..f04e804 100644
@@ -9,7 +9,7 @@
 #include "perf.h"
 
 #include "util/cache.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/util.h"
 #include "util/debug.h"
 
tools/perf/builtin-data.c +1 -1
index d6525bc..b97bc15 100644
@@ -2,7 +2,7 @@
 #include "builtin.h"
 #include "perf.h"
 #include "debug.h"
-#include "parse-options.h"
+#include <subcmd/parse-options.h>
 #include "data-convert-bt.h"
 
 typedef int (*data_cmd_fn_t)(int argc, const char **argv, const char *prefix);
tools/perf/builtin-evlist.c +1 -1
index f4d6251..08a7d36 100644
@@ -12,7 +12,7 @@
 #include "util/evlist.h"
 #include "util/evsel.h"
 #include "util/parse-events.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/session.h"
 #include "util/data.h"
 #include "util/debug.h"
tools/perf/builtin-help.c +4 -4
index 275aa64..96c1a4c 100644
@@ -6,11 +6,11 @@
 #include "perf.h"
 #include "util/cache.h"
 #include "builtin.h"
-#include "util/exec_cmd.h"
+#include <subcmd/exec-cmd.h>
 #include "common-cmds.h"
-#include "util/parse-options.h"
-#include "util/run-command.h"
-#include "util/help.h"
+#include <subcmd/parse-options.h>
+#include <subcmd/run-command.h>
+#include <subcmd/help.h>
 #include "util/debug.h"
 
 static struct man_viewer_list {
tools/perf/builtin-inject.c +1 -1
index 99d127f..0022e02 100644
@@ -18,7 +18,7 @@
 #include "util/data.h"
 #include "util/auxtrace.h"
 
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 
 #include <linux/list.h>
 
tools/perf/builtin-kmem.c +1 -1
index 93ce665..1180105 100644
@@ -12,7 +12,7 @@
 #include "util/tool.h"
 #include "util/callchain.h"
 
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/trace-event.h"
 #include "util/data.h"
 #include "util/cpumap.h"
tools/perf/builtin-kvm.c +1 -1
index 031f9f5..4418d92 100644
@@ -10,7 +10,7 @@
 #include "util/header.h"
 #include "util/session.h"
 #include "util/intlist.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/trace-event.h"
 #include "util/debug.h"
 #include "util/tool.h"
tools/perf/builtin-list.c +1 -1
index bf679e2..5e22db4 100644
@@ -14,7 +14,7 @@
 #include "util/parse-events.h"
 #include "util/cache.h"
 #include "util/pmu.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 
 int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
 {
tools/perf/builtin-lock.c +1 -1
index de16aae..ce3bfb4 100644
@@ -9,7 +9,7 @@
 #include "util/thread.h"
 #include "util/header.h"
 
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/trace-event.h"
 
 #include "util/debug.h"
tools/perf/builtin-mem.c +1 -1
index 80170aa..3901700 100644
@@ -1,7 +1,7 @@
 #include "builtin.h"
 #include "perf.h"
 
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/trace-event.h"
 #include "util/tool.h"
 #include "util/session.h"
tools/perf/builtin-probe.c +1 -1
index dbe2ea5..9af859b 100644
@@ -37,7 +37,7 @@
 #include "util/strfilter.h"
 #include "util/symbol.h"
 #include "util/debug.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/probe-finder.h"
 #include "util/probe-event.h"
 #include "util/probe-file.h"
tools/perf/builtin-record.c +1 -1
index 3ef3c79..da28252 100644
@@ -11,7 +11,7 @@
 
 #include "util/build-id.h"
 #include "util/util.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/parse-events.h"
 
 #include "util/callchain.h"
tools/perf/builtin-report.c +1 -1
index 5a45466..2a7330b 100644
@@ -27,7 +27,7 @@
 #include "util/session.h"
 #include "util/tool.h"
 
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/parse-events.h"
 
 #include "util/thread.h"
tools/perf/builtin-sched.c +1 -1
index e3d3e32..871b55ae 100644
@@ -12,7 +12,7 @@
 #include "util/tool.h"
 #include "util/cloexec.h"
 
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/trace-event.h"
 
 #include "util/debug.h"
tools/perf/builtin-script.c +2 -2
index 571016f..bcc3542 100644
@@ -3,9 +3,9 @@
 #include "perf.h"
 #include "util/cache.h"
 #include "util/debug.h"
-#include "util/exec_cmd.h"
+#include <subcmd/exec-cmd.h>
 #include "util/header.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/perf_regs.h"
 #include "util/session.h"
 #include "util/tool.h"
tools/perf/builtin-stat.c +1 -1
index 25a95f4..bbf42ee 100644
@@ -45,7 +45,7 @@
 #include "builtin.h"
 #include "util/cgroup.h"
 #include "util/util.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/parse-events.h"
 #include "util/pmu.h"
 #include "util/event.h"
tools/perf/builtin-timechart.c +1 -1
index 30e5962..bd7a775 100644
@@ -30,7 +30,7 @@
 
 #include "perf.h"
 #include "util/header.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/parse-events.h"
 #include "util/event.h"
 #include "util/session.h"
tools/perf/builtin-top.c +1 -1
index 92fe963..9ebd67a 100644
@@ -34,7 +34,7 @@
 #include "util/top.h"
 #include "util/util.h"
 #include <linux/rbtree.h>
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/parse-events.h"
 #include "util/cpumap.h"
 #include "util/xyarray.h"
tools/perf/builtin-trace.c +2 -2
index c783d8f..20916dd 100644
@@ -22,11 +22,11 @@
 #include "util/color.h"
 #include "util/debug.h"
 #include "util/evlist.h"
-#include "util/exec_cmd.h"
+#include <subcmd/exec-cmd.h>
 #include "util/machine.h"
 #include "util/session.h"
 #include "util/thread.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/strlist.h"
 #include "util/intlist.h"
 #include "util/thread_map.h"
tools/perf/perf.c +3 -3
index 6894325..cb1d249 100644
@@ -9,12 +9,12 @@
 #include "builtin.h"
 
 #include "util/env.h"
-#include "util/exec_cmd.h"
+#include <subcmd/exec-cmd.h>
 #include "util/cache.h"
 #include "util/quote.h"
-#include "util/run-command.h"
+#include <subcmd/run-command.h>
 #include "util/parse-events.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/bpf-loader.h"
 #include "util/debug.h"
 #include <api/fs/tracing_path.h>
tools/perf/tests/attr.c +1 -1
index 6337f1c..28d1605 100644
@@ -24,7 +24,7 @@
 #include <linux/kernel.h>
 #include "../perf.h"
 #include "util.h"
-#include "exec_cmd.h"
+#include <subcmd/exec-cmd.h>
 #include "tests.h"
 
 #define ENV "PERF_TEST_ATTR"
tools/perf/tests/builtin-test.c +1 -1
index fa98406..0372d59 100644
@@ -11,7 +11,7 @@
 #include "tests.h"
 #include "debug.h"
 #include "color.h"
-#include "parse-options.h"
+#include <subcmd/parse-options.h>
 #include "symbol.h"
 
 struct test __weak arch_tests[] = {
tools/perf/util/Build +0 -7
index 196beef..94b1099 100644
@@ -9,13 +9,10 @@ libperf-y += env.o
 libperf-y += event.o
 libperf-y += evlist.o
 libperf-y += evsel.o
-libperf-y += exec_cmd.o
 libperf-y += find_next_bit.o
-libperf-y += help.o
 libperf-y += kallsyms.o
 libperf-y += levenshtein.o
 libperf-y += llvm-utils.o
-libperf-y += parse-options.o
 libperf-y += parse-events.o
 libperf-y += perf_regs.o
 libperf-y += path.o
@@ -23,7 +20,6 @@ libperf-y += rbtree.o
 libperf-y += libstring.o
 libperf-y += bitmap.o
 libperf-y += hweight.o
-libperf-y += run-command.o
 libperf-y += quote.o
 libperf-y += strbuf.o
 libperf-y += string.o
@@ -32,11 +28,9 @@ libperf-y += strfilter.o
 libperf-y += top.o
 libperf-y += usage.o
 libperf-y += wrapper.o
-libperf-y += sigchain.o
 libperf-y += dso.o
 libperf-y += symbol.o
 libperf-y += color.o
-libperf-y += pager.o
 libperf-y += header.o
 libperf-y += callchain.o
 libperf-y += values.o
@@ -88,7 +82,6 @@ libperf-y += parse-branch-options.o
 libperf-y += parse-regs-options.o
 libperf-y += term.o
 libperf-y += help-unknown-cmd.o
-libperf-y += subcmd-config.o
 
 libperf-$(CONFIG_LIBBPF) += bpf-loader.o
 libperf-$(CONFIG_BPF_PROLOGUE) += bpf-prologue.o
tools/perf/util/auxtrace.c +1 -1
index 7f10430..360fda0 100644
@@ -45,7 +45,7 @@
 #include "event.h"
 #include "session.h"
 #include "debug.h"
-#include "parse-options.h"
+#include <subcmd/parse-options.h>
 
 #include "intel-pt.h"
 #include "intel-bts.h"
tools/perf/util/cache.h +1 -1
index fc6a745..07b5d63 100644
@@ -4,7 +4,7 @@
 #include <stdbool.h>
 #include "util.h"
 #include "strbuf.h"
-#include "pager.h"
+#include <subcmd/pager.h>
 #include "../perf.h"
 #include "../ui/ui.h"
 
tools/perf/util/cgroup.c +1 -1
index 32e12ec..90aa1b4 100644
@@ -1,6 +1,6 @@
 #include "util.h"
 #include "../perf.h"
-#include "parse-options.h"
+#include <subcmd/parse-options.h>
 #include "evsel.h"
 #include "cgroup.h"
 #include "evlist.h"
tools/perf/util/config.c +1 -1
index 2e452ac..d3e12e3 100644
@@ -10,7 +10,7 @@
  */
 #include "util.h"
 #include "cache.h"
-#include "exec_cmd.h"
+#include <subcmd/exec-cmd.h>
 #include "util/hist.h"  /* perf_hist_config */
 #include "util/llvm-utils.h"   /* perf_llvm_config */
 
tools/perf/util/evlist.c +1 -1
index d1b6c20..8c44aad 100644
@@ -18,7 +18,7 @@
 #include <unistd.h>
 
 #include "parse-events.h"
-#include "parse-options.h"
+#include <subcmd/parse-options.h>
 
 #include <sys/mman.h>
 
tools/perf/util/help-unknown-cmd.c +1 -1
index a0820f1..dc1e41c 100644
@@ -1,5 +1,5 @@
 #include "cache.h"
-#include "help.h"
+#include <subcmd/help.h>
 #include "../builtin.h"
 #include "levenshtein.h"
 
tools/perf/util/parse-branch-options.c +1 -1
index 355eecf..afc088d 100644
@@ -1,7 +1,7 @@
 #include "perf.h"
 #include "util/util.h"
 #include "util/debug.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/parse-branch-options.h"
 
 #define BRANCH_OPT(n, m) \
tools/perf/util/parse-events.c +2 -2
index 6fc8cd7..4f7b0ef 100644
@@ -4,9 +4,9 @@
 #include "../perf.h"
 #include "evlist.h"
 #include "evsel.h"
-#include "parse-options.h"
+#include <subcmd/parse-options.h>
 #include "parse-events.h"
-#include "exec_cmd.h"
+#include <subcmd/exec-cmd.h>
 #include "string.h"
 #include "symbol.h"
 #include "cache.h"
tools/perf/util/parse-regs-options.c +1 -1
index 4f2c1c2..646ecf7 100644
@@ -1,7 +1,7 @@
 #include "perf.h"
 #include "util/util.h"
 #include "util/debug.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/parse-regs-options.h"
 
 int
tools/perf/util/sort.h +1 -1
index 3122885..86f05e7 100644
@@ -18,7 +18,7 @@
 #include "debug.h"
 #include "header.h"
 
-#include "parse-options.h"
+#include <subcmd/parse-options.h>
 #include "parse-events.h"
 #include "hist.h"
 #include "thread.h"
Signature · 1 line
2.4.3
#13 lore raw

PATCH v4 7/9 perf: Finalize subcmd independence

In reply to Josh Poimboeuf

For the files that will be moved to the subcmd library, remove all their perf-specific includes and duplicate any needed functionality.

---
 tools/perf/util/exec_cmd.c      | 64 +++++++++++++++++++++++++++++++----
 tools/perf/util/help.c          | 47 +++++++++++++++++++++++---
 tools/perf/util/help.h          |  4 ++-
 tools/perf/util/pager.c         |  7 +++-
 tools/perf/util/parse-options.c | 74 +++++++++++++++++++++++++----------------
 tools/perf/util/parse-options.h |  2 +-
 tools/perf/util/run-command.c   | 16 ++++++---
 tools/perf/util/run-command.h   |  2 ++
 tools/perf/util/sigchain.c      |  3 +-
 tools/perf/util/subcmd-util.h   | 67 +++++++++++++++++++++++++++++++++++++
 tools/perf/util/util.h          | 14 --------
 11 files changed, 238 insertions(+), 62 deletions(-)
tools/perf/util/exec_cmd.c +57 -7
index 701111a..e7f9ed79 100644
@@ -1,12 +1,17 @@
-#include "cache.h"
-#include "exec_cmd.h"
-#include "quote.h"
-#include "subcmd-config.h"
-
+#include <linux/compiler.h>
+#include <linux/string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
 #include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
 #include "subcmd-util.h"
+#include "exec_cmd.h"
+#include "subcmd-config.h"
 
 #define MAX_ARGS	32
+#define PATH_MAX	4096
 
 static const char *argv_exec_path;
 static const char *argv0_path;
@@ -20,6 +25,49 @@ void exec_cmd_init(const char *exec_name, const char *prefix,
 	subcmd_config.exec_path_env	= exec_path_env;
 }
 
+#define is_dir_sep(c) ((c) == '/')
+
+static int is_absolute_path(const char *path)
+{
+	return path[0] == '/';
+}
+
+static const char *get_pwd_cwd(void)
+{
+	static char cwd[PATH_MAX + 1];
+	char *pwd;
+	struct stat cwd_stat, pwd_stat;
+	if (getcwd(cwd, PATH_MAX) == NULL)
+		return NULL;
+	pwd = getenv("PWD");
+	if (pwd && strcmp(pwd, cwd)) {
+		stat(cwd, &cwd_stat);
+		if (!stat(pwd, &pwd_stat) &&
+		    pwd_stat.st_dev == cwd_stat.st_dev &&
+		    pwd_stat.st_ino == cwd_stat.st_ino) {
+			strlcpy(cwd, pwd, PATH_MAX);
+		}
+	}
+	return cwd;
+}
+
+static const char *make_nonrelative_path(const char *path)
+{
+	static char buf[PATH_MAX + 1];
+
+	if (is_absolute_path(path)) {
+		if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX)
+			die("Too long path: %.*s", 60, path);
+	} else {
+		const char *cwd = get_pwd_cwd();
+		if (!cwd)
+			die("Cannot determine the current working directory");
+		if (snprintf(buf, PATH_MAX, "%s/%s", cwd, path) >= PATH_MAX)
+			die("Too long path: %.*s", 60, path);
+	}
+	return buf;
+}
+
 char *system_path(const char *path)
 {
 	char *buf = NULL;
@@ -151,8 +199,10 @@ int execl_cmd(const char *cmd,...)
 			break;
 	}
 	va_end(param);
-	if (MAX_ARGS <= argc)
-		return error("too many args to run %s", cmd);
+	if (MAX_ARGS <= argc) {
+		fprintf(stderr, " Error: too many args to run %s\n", cmd);
+		return -1;
+	}
 
 	argv[argc] = NULL;
 	return execv_cmd(argv);
tools/perf/util/help.c +42 -5

69 lines not on this page · raw message

tools/perf/util/help.h +3 -1
index 14851b0..096c8bc 100644
@@ -1,12 +1,14 @@
 #ifndef __PERF_HELP_H
 #define __PERF_HELP_H
 
+#include <sys/types.h>
+
 struct cmdnames {
 	size_t alloc;
 	size_t cnt;
 	struct cmdname {
 		size_t len; /* also used for similarity index in help.c */
-		char name[FLEX_ARRAY];
+		char name[];
 	} **names;
 };
 
tools/perf/util/pager.c +6 -1
index d5ef62e..d50f3b5 100644
@@ -1,4 +1,9 @@
-#include "cache.h"
+#include <sys/select.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+#include "pager.h"
 #include "run-command.h"
 #include "sigchain.h"
 #include "subcmd-config.h"
tools/perf/util/parse-options.c +46 -28

134 lines not on this page · raw message

tools/perf/util/parse-options.h +1 -1
index d1544069..dec893f 100644
@@ -1,8 +1,8 @@
 #ifndef __PERF_PARSE_OPTIONS_H
 #define __PERF_PARSE_OPTIONS_H
 
-#include <linux/kernel.h>
 #include <stdbool.h>
+#include <stdint.h>
 
 enum parse_opt_type {
 	/* special types */
tools/perf/util/run-command.c +12 -4
index 910c0f6..fed37d6 100644
@@ -1,7 +1,15 @@
-#include "cache.h"
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/wait.h>
+#include "subcmd-util.h"
 #include "run-command.h"
 #include "exec_cmd.h"
-#include "debug.h"
+
+#define STRERR_BUFSIZE 128
 
 static inline void close_pair(int fd[2])
 {
@@ -164,8 +172,8 @@ static int wait_or_whine(pid_t pid)
 		if (waiting < 0) {
 			if (errno == EINTR)
 				continue;
-			error("waitpid failed (%s)",
-			      strerror_r(errno, sbuf, sizeof(sbuf)));
+			fprintf(stderr, " Error: waitpid failed (%s)",
+				strerror_r(errno, sbuf, sizeof(sbuf)));
 			return -ERR_RUN_COMMAND_WAITPID;
 		}
 		if (waiting != pid)
tools/perf/util/run-command.h +2 -0
index cf7d655..4a55393 100644
@@ -1,6 +1,8 @@
 #ifndef __PERF_RUN_COMMAND_H
 #define __PERF_RUN_COMMAND_H
 
+#include <unistd.h>
+
 enum {
 	ERR_RUN_COMMAND_FORK = 10000,
 	ERR_RUN_COMMAND_EXEC,
tools/perf/util/sigchain.c +2 -1
index ba785e9..3537c34 100644
@@ -1,5 +1,6 @@
+#include <signal.h>
+#include "subcmd-util.h"
 #include "sigchain.h"
-#include "cache.h"
 
 #define SIGCHAIN_MAX_SIGNALS 32
 
tools/perf/util/subcmd-util.h +67 -0

79 lines not on this page · raw message

tools/perf/util/util.h +0 -14
index 150858f..4b519c5 100644
@@ -151,12 +151,6 @@ extern void set_warning_routine(void (*routine)(const char *err, va_list params)
 extern int prefixcmp(const char *str, const char *prefix);
 extern void set_buildid_dir(const char *dir);
 
-static inline const char *skip_prefix(const char *str, const char *prefix)
-{
-	size_t len = strlen(prefix);
-	return strncmp(str, prefix, len) ? NULL : str + len;
-}
-
 #ifdef __GLIBC_PREREQ
 #if __GLIBC_PREREQ(2, 1)
 #define HAVE_STRCHRNUL
@@ -187,14 +181,6 @@ static inline void *zalloc(size_t size)
 
 #define zfree(ptr) ({ free(*ptr); *ptr = NULL; })
 
-static inline int has_extension(const char *filename, const char *ext)
-{
-	size_t len = strlen(filename);
-	size_t extlen = strlen(ext);
-
-	return len > extlen && !memcmp(filename + len - extlen, ext, extlen);
-}
-
 /* Sane ctype - no locale, and works with signed chars */
 #undef isascii
 #undef isspace
Signature · 1 line
2.4.3
#7 lore raw

PATCH v4 4/9 perf: Provide subcmd configuration at runtime

In reply to Josh Poimboeuf

Create init functions for exec_cmd.c and pager.c. This allows their configuration to be specified at runtime so they can be split out into a separate library which can be used by other programs. Their configuration is stored in a shared subcmd_config struct.

---
 tools/perf/Build                |  5 ++++-
 tools/perf/perf.c               |  6 +++++-
 tools/perf/util/Build           |  2 +-
 tools/perf/util/cache.h         |  1 +
 tools/perf/util/exec_cmd.c      | 23 ++++++++++++++++-------
 tools/perf/util/exec_cmd.h      |  3 +++
 tools/perf/util/pager.c         |  8 +++++++-
 tools/perf/util/pager.h         |  2 ++
 tools/perf/util/parse-options.c |  4 +++-
 tools/perf/util/subcmd-config.c | 11 +++++++++++
 tools/perf/util/subcmd-config.h | 14 ++++++++++++++
 11 files changed, 67 insertions(+), 12 deletions(-)
 create mode 100644 tools/perf/util/subcmd-config.c
 create mode 100644 tools/perf/util/subcmd-config.h
tools/perf/Build +4 -1
index 2a41217..00c4b8c 100644
@@ -36,7 +36,10 @@ paths += -DPERF_MAN_PATH="BUILD_STR($(mandir_SQ))"
 
 CFLAGS_builtin-help.o      += $(paths)
 CFLAGS_builtin-timechart.o += $(paths)
-CFLAGS_perf.o              += -DPERF_HTML_PATH="BUILD_STR($(htmldir_SQ))" -include $(OUTPUT)PERF-VERSION-FILE
+CFLAGS_perf.o              += -DPERF_HTML_PATH="BUILD_STR($(htmldir_SQ))"	\
+			      -DPERF_EXEC_PATH="BUILD_STR($(perfexecdir_SQ))"	\
+			      -DPREFIX="BUILD_STR($(prefix_SQ))"		\
+			      -include $(OUTPUT)PERF-VERSION-FILE
 CFLAGS_builtin-trace.o	   += -DSTRACE_GROUPS_DIR="BUILD_STR($(STRACE_GROUPS_DIR_SQ))"
 
 libperf-y += util/
tools/perf/perf.c +5 -1
index 59ea48c..783a331 100644
@@ -119,7 +119,7 @@ static void commit_pager_choice(void)
 {
 	switch (use_pager) {
 	case 0:
-		setenv("PERF_PAGER", "cat", 1);
+		setenv(PERF_PAGER_ENVIRONMENT, "cat", 1);
 		break;
 	case 1:
 		/* setup_pager(); */
@@ -530,6 +530,10 @@ int main(int argc, const char **argv)
 	const char *cmd;
 	char sbuf[STRERR_BUFSIZE];
 
+	/* libsubcmd init */
+	exec_cmd_init("perf", PREFIX, PERF_EXEC_PATH, EXEC_PATH_ENVIRONMENT);
+	pager_init(PERF_PAGER_ENVIRONMENT);
+
 	/* The page_size is placed in util object. */
 	page_size = sysconf(_SC_PAGE_SIZE);
 	cacheline_size = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
tools/perf/util/Build +1 -1
index 99b3dae..196beef 100644
@@ -88,6 +88,7 @@ libperf-y += parse-branch-options.o
 libperf-y += parse-regs-options.o
 libperf-y += term.o
 libperf-y += help-unknown-cmd.o
+libperf-y += subcmd-config.o
 
 libperf-$(CONFIG_LIBBPF) += bpf-loader.o
 libperf-$(CONFIG_BPF_PROLOGUE) += bpf-prologue.o
@@ -113,7 +114,6 @@ libperf-$(CONFIG_ZLIB) += zlib.o
 libperf-$(CONFIG_LZMA) += lzma.o
 
 CFLAGS_config.o   += -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
-CFLAGS_exec_cmd.o += -DPERF_EXEC_PATH="BUILD_STR($(perfexecdir_SQ))" -DPREFIX="BUILD_STR($(prefix_SQ))"
 
 $(OUTPUT)util/parse-events-flex.c: util/parse-events.l $(OUTPUT)util/parse-events-bison.c
 	$(call rule_mkdir)
tools/perf/util/cache.h +1 -0
index d723ecb..fc6a745 100644
@@ -21,6 +21,7 @@
 #define DEFAULT_PERF_DIR_ENVIRONMENT ".perf"
 #define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"
 #define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR"
+#define PERF_PAGER_ENVIRONMENT "PERF_PAGER"
 
 typedef int (*config_fn_t)(const char *, const char *, void *);
 extern int perf_default_config(const char *, const char *, void *);
tools/perf/util/exec_cmd.c +16 -7
index 1099e92..b935e4c 100644
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "exec_cmd.h"
 #include "quote.h"
+#include "subcmd-config.h"
 
 #include <string.h>
 
@@ -9,15 +10,23 @@
 static const char *argv_exec_path;
 static const char *argv0_path;
 
+void exec_cmd_init(const char *exec_name, const char *prefix,
+		   const char *exec_path, const char *exec_path_env)
+{
+	subcmd_config.exec_name		= exec_name;
+	subcmd_config.prefix		= prefix;
+	subcmd_config.exec_path		= exec_path;
+	subcmd_config.exec_path_env	= exec_path_env;
+}
+
 char *system_path(const char *path)
 {
-	static const char *prefix = PREFIX;
 	struct strbuf d = STRBUF_INIT;
 
 	if (is_absolute_path(path))
 		return strdup(path);
 
-	strbuf_addf(&d, "%s/%s", prefix, path);
+	strbuf_addf(&d, "%s/%s", subcmd_config.prefix, path);
 	path = strbuf_detach(&d, NULL);
 	return (char *)path;
 }
@@ -47,7 +56,7 @@ void perf_set_argv_exec_path(const char *exec_path)
 	/*
 	 * Propagate this setting to external programs.
 	 */
-	setenv(EXEC_PATH_ENVIRONMENT, exec_path, 1);
+	setenv(subcmd_config.exec_path_env, exec_path, 1);
 }
 
 
@@ -59,11 +68,11 @@ char *perf_exec_path(void)
 	if (argv_exec_path)
 		return strdup(argv_exec_path);
 
-	env = getenv(EXEC_PATH_ENVIRONMENT);
+	env = getenv(subcmd_config.exec_path_env);
 	if (env && *env)
 		return strdup(env);
 
-	return system_path(PERF_EXEC_PATH);
+	return system_path(subcmd_config.exec_path);
 }
 
 static void add_path(struct strbuf *out, const char *path)
@@ -107,7 +116,7 @@ static const char **prepare_perf_cmd(const char **argv)
 		; /* just counting */
 	nargv = malloc(sizeof(*nargv) * (argc + 2));
 
-	nargv[0] = "perf";
+	nargv[0] = subcmd_config.exec_name;
 	for (argc = 0; argv[argc]; argc++)
 		nargv[argc + 1] = argv[argc];
 	nargv[argc + 1] = NULL;
@@ -118,7 +127,7 @@ int execv_perf_cmd(const char **argv) {
 	const char **nargv = prepare_perf_cmd(argv);
 
 	/* execvp() can only ever return if it fails */
-	execvp("perf", (char **)nargv);
+	execvp(subcmd_config.exec_name, (char **)nargv);
 
 	free(nargv);
 	return -1;
tools/perf/util/exec_cmd.h +3 -0
index 48b4175..fd4434e 100644
@@ -1,6 +1,9 @@
 #ifndef __PERF_EXEC_CMD_H
 #define __PERF_EXEC_CMD_H
 
+extern void exec_cmd_init(const char *exec_name, const char *prefix,
+			  const char *exec_path, const char *exec_path_env);
+
 extern void perf_set_argv_exec_path(const char *exec_path);
 extern const char *perf_extract_argv0_path(const char *path);
 extern void setup_path(void);
tools/perf/util/pager.c +7 -1
index 7dcbef6..d5ef62e 100644
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "run-command.h"
 #include "sigchain.h"
+#include "subcmd-config.h"
 
 /*
  * This is split up from the rest of git so that we can do
@@ -9,6 +10,11 @@
 
 static int spawned_pager;
 
+void pager_init(const char *pager_env)
+{
+	subcmd_config.pager_env = pager_env;
+}
+
 static void pager_preexec(void)
 {
 	/*
@@ -46,7 +52,7 @@ static void wait_for_pager_signal(int signo)
 
 void setup_pager(void)
 {
-	const char *pager = getenv("PERF_PAGER");
+	const char *pager = getenv(subcmd_config.pager_env);
 
 	if (!isatty(1))
 		return;
tools/perf/util/pager.h +2 -0
index 2794a83..d6a591a 100644
@@ -1,6 +1,8 @@
 #ifndef __PERF_PAGER_H
 #define __PERF_PAGER_H
 
+extern void pager_init(const char *pager_env);
+
 extern void setup_pager(void);
 extern int pager_in_use(void);
 
tools/perf/util/parse-options.c +3 -1
index 0ad1384..da4ba21 100644
@@ -2,6 +2,7 @@
 #include "parse-options.h"
 #include "cache.h"
 #include "header.h"
+#include "subcmd-config.h"
 #include <linux/string.h>
 
 #define OPT_SHORT 1
@@ -577,7 +578,8 @@ int parse_options_subcommand(int argc, const char **argv, const struct option *o
 	if (subcommands && !usagestr[0]) {
 		struct strbuf buf = STRBUF_INIT;
 
-		strbuf_addf(&buf, "perf %s [<options>] {", argv[0]);
+		strbuf_addf(&buf, "%s %s [<options>] {",
+			    subcmd_config.exec_name, argv[0]);
 		for (int i = 0; subcommands[i]; i++) {
 			if (i)
 				strbuf_addstr(&buf, "|");
tools/perf/util/subcmd-config.c new file +11 -0
new file mode 100644
index 0000000..d017c72
@@ -0,0 +1,11 @@
+#include "subcmd-config.h"
+
+#define UNDEFINED "SUBCMD_HAS_NOT_BEEN_INITIALIZED"
+
+struct subcmd_config subcmd_config = {
+	.exec_name	= UNDEFINED,
+	.prefix		= UNDEFINED,
+	.exec_path	= UNDEFINED,
+	.exec_path_env	= UNDEFINED,
+	.pager_env	= UNDEFINED,
+};
tools/perf/util/subcmd-config.h new file +14 -0
new file mode 100644
index 0000000..cc85140
@@ -0,0 +1,14 @@
+#ifndef __PERF_SUBCMD_CONFIG_H
+#define __PERF_SUBCMD_CONFIG_H
+
+struct subcmd_config {
+	const char *exec_name;
+	const char *prefix;
+	const char *exec_path;
+	const char *exec_path_env;
+	const char *pager_env;
+};
+
+extern struct subcmd_config subcmd_config;
+
+#endif /* __PERF_SUBCMD_CONFIG_H */
Signature · 1 line
2.4.3
#5 lore raw

PATCH v4 3/9 perf: Document the fact that parse_options*() may exit

In reply to Josh Poimboeuf

Generally, calling exit() from a library is bad practice. Eventually these functions might be redesigned so that they don't exit. For now, just document the fact that they do.

---
 tools/perf/util/parse-options.h | 3 +++
 1 file changed, 3 insertions(+)
tools/perf/util/parse-options.h +3 -0
index 1231960..d1544069 100644
@@ -152,6 +152,9 @@ struct option {
 /* parse_options() will filter out the processed options and leave the
  * non-option argments in argv[].
  * Returns the number of arguments left in argv[].
+ *
+ * NOTE: parse_options() and parse_options_subcommand() may call exit() in the
+ * case of an error (or for 'special' options like --list-cmds or --list-opts).
  */
 extern int parse_options(int argc, const char **argv,
                          const struct option *options,
Signature · 1 line
2.4.3
#1 lore raw

PATCH v4 1/9 tools build: Fix feature Makefile issues with 'O='

In reply to Josh Poimboeuf

When building perf binaries outside the source tree with 'make O=<dir>', the auto-detected features get re-tested for every build, which is unnecessary and inconsistent with the behavior seen when building directly in the source tree.

Another issue is that 'make O=<dir> clean' doesn't remove the feature files from the object tree.

Fix these problems by looking for the binaries in the $(OUTPUT) directory.

---
 tools/build/Makefile.feature |  2 +-
 tools/build/feature/Makefile | 93 ++++++++++++++++++++++----------------------
 2 files changed, 48 insertions(+), 47 deletions(-)
tools/build/Makefile.feature +1 -1
index b8c31ec..6c0519d 100644
@@ -7,7 +7,7 @@ endif
 
 feature_check = $(eval $(feature_check_code))
 define feature_check_code
-  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C $(feature_dir) test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0)
+  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C $(feature_dir) $(OUTPUT_FEATURES)test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0)
 endef
 
 feature_set = $(eval $(feature_set_code))
tools/build/feature/Makefile +47 -46

189 lines not on this page · raw message

Signature · 1 line
2.4.3
#14 lore raw

Re: [PATCH v4 7/9] perf: Finalize subcmd independence

In reply to Josh Poimboeuf

Em Tue, Dec 15, 2015 at 09:39:38AM -0600, Josh Poimboeuf escreveu:

Quoted 2 lines

For the files that will be moved to the subcmd library, remove all their perf-specific includes and duplicate any needed functionality.

Breaks rhel6.7 building:

Quoted 18 lines

#include "run-command.h"
#include "sigchain.h"
#include "subcmd-config.h"

tools/perf/util/parse-options.c +6 -2
index c1da2a5..f424027 100644
@@ -1,33 +1,47 @@
-#include "util.h"
+#include <linux/compiler.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <ctype.h>
 #include "subcmd-util.h"
 #include "parse-options.h"
-#include "cache.h"

tools/perf/util/parse-options.c line 16

Quoted 10 lines
tools/perf/util/parse-options.c +3 -2
-#include "header.h"
 #include "subcmd-config.h"
-#include <linux/string.h>
+#include "pager.h"
 
 #define OPT_SHORT 1
 #define OPT_UNSET 2
 
+typedef uint64_t u64;
+

[acme@sandy linux]$ cat /etc/redhat-release Red Hat Enterprise Linux Server release 6.7 (Santiago)

CC /tmp/build/perf/parse-options.o
parse-options.c:15: error: redefinition of typedef ‘u64’ /home/acme/git/linux/tools/include/linux/types.h:28: note: previous declaration of ‘u64’ was here
mv: cannot stat `/tmp/build/perf/.parse-options.o.tmp': No such file or directory
make[3]: *** [/tmp/build/perf/parse-options.o] Error 1 make[2]: *** [/tmp/build/perf/libsubcmd-in.o] Error 2 make[1]: *** [/tmp/build/perf/libsubcmd.a] Error 2
make[1]: *** Waiting for unfinished jobs....
MKDIR /tmp/build/perf/util/

Quoted 310 lines
tools/perf/util/parse-options.c +37 -24
 char *error_buf;
 
 static int opterror(const struct option *opt, const char *reason, int flags)
 {
 	if (flags & OPT_SHORT)
-		return error("switch `%c' %s", opt->short_name, reason);
-	if (flags & OPT_UNSET)
-		return error("option `no-%s' %s", opt->long_name, reason);
-	return error("option `%s' %s", opt->long_name, reason);
+		fprintf(stderr, " Error: switch `%c' %s", opt->short_name, reason);
+	else if (flags & OPT_UNSET)
+		fprintf(stderr, " Error: option `no-%s' %s", opt->long_name, reason);
+	else
+		fprintf(stderr, " Error: option `%s' %s", opt->long_name, reason);
+
+	return -1;
+}
+
+static const char *skip_prefix(const char *str, const char *prefix)
+{
+	size_t len = strlen(prefix);
+	return strncmp(str, prefix, len) ? NULL : str + len;
 }
 
 static void optwarning(const struct option *opt, const char *reason, int flags)
 {
 	if (flags & OPT_SHORT)
-		warning("switch `%c' %s", opt->short_name, reason);
+		fprintf(stderr, " Warning: switch `%c' %s", opt->short_name, reason);
 	else if (flags & OPT_UNSET)
-		warning("option `no-%s' %s", opt->long_name, reason);
+		fprintf(stderr, " Warning: option `no-%s' %s", opt->long_name, reason);
 	else
-		warning("option `%s' %s", opt->long_name, reason);
+		fprintf(stderr, " Warning: option `%s' %s", opt->long_name, reason);
 }
 
 static int get_arg(struct parse_opt_ctx_t *p, const struct option *opt,
@@ -71,11 +85,11 @@ static int get_value(struct parse_opt_ctx_t *p,
 
 			if (((flags & OPT_SHORT) && p->excl_opt->short_name) ||
 			    p->excl_opt->long_name == NULL) {
-				scnprintf(msg, sizeof(msg), "cannot be used with switch `%c'",
-					  p->excl_opt->short_name);
+				snprintf(msg, sizeof(msg), "cannot be used with switch `%c'",
+					 p->excl_opt->short_name);
 			} else {
-				scnprintf(msg, sizeof(msg), "cannot be used with %s",
-					  p->excl_opt->long_name);
+				snprintf(msg, sizeof(msg), "cannot be used with %s",
+					 p->excl_opt->long_name);
 			}
 			opterror(opt, msg, flags);
 			return -3;
@@ -401,14 +415,16 @@ match:
 		return get_value(p, options, flags);
 	}
 
-	if (ambiguous_option)
-		return error("Ambiguous option: %s "
-			"(could be --%s%s or --%s%s)",
-			arg,
-			(ambiguous_flags & OPT_UNSET) ?  "no-" : "",
-			ambiguous_option->long_name,
-			(abbrev_flags & OPT_UNSET) ?  "no-" : "",
-			abbrev_option->long_name);
+	if (ambiguous_option) {
+		 fprintf(stderr,
+			 " Error: Ambiguous option: %s (could be --%s%s or --%s%s)",
+			 arg,
+			 (ambiguous_flags & OPT_UNSET) ?  "no-" : "",
+			 ambiguous_option->long_name,
+			 (abbrev_flags & OPT_UNSET) ?  "no-" : "",
+			 abbrev_option->long_name);
+		 return -1;
+	}
 	if (abbrev_option)
 		return get_value(p, abbrev_option, abbrev_flags);
 	return -2;
@@ -420,7 +436,7 @@ static void check_typos(const char *arg, const struct option *options)
 		return;
 
 	if (!prefixcmp(arg, "no-")) {
-		error ("did you mean `--%s` (with two dashes ?)", arg);
+		fprintf(stderr, " Error: did you mean `--%s` (with two dashes ?)", arg);
 		exit(129);
 	}
 
@@ -428,7 +444,7 @@ static void check_typos(const char *arg, const struct option *options)
 		if (!options->long_name)
 			continue;
 		if (!prefixcmp(options->long_name, arg)) {
-			error ("did you mean `--%s` (with two dashes ?)", arg);
+			fprintf(stderr, " Error: did you mean `--%s` (with two dashes ?)", arg);
 			exit(129);
 		}
 	}
@@ -746,16 +762,18 @@ static int option__cmp(const void *va, const void *vb)
 
 static struct option *options__order(const struct option *opts)
 {
-	int nr_opts = 0;
+	int nr_opts = 0, len;
 	const struct option *o = opts;
 	struct option *ordered;
 
 	for (o = opts; o->type != OPTION_END; o++)
 		++nr_opts;
 
-	ordered = memdup(opts, sizeof(*o) * (nr_opts + 1));
-	if (ordered == NULL)
+	len = sizeof(*o) * (nr_opts + 1);
+	ordered = malloc(len);
+	if (!ordered)
 		goto out;
+	memcpy(ordered, opts, len);
 
 	qsort(ordered, nr_opts, sizeof(*o), option__cmp);
 out:
tools/perf/util/parse-options.h +1 -1
index d1544069..dec893f 100644
@@ -1,8 +1,8 @@
 #ifndef __PERF_PARSE_OPTIONS_H
 #define __PERF_PARSE_OPTIONS_H
 
-#include <linux/kernel.h>
 #include <stdbool.h>
+#include <stdint.h>
 
 enum parse_opt_type {
 	/* special types */
tools/perf/util/run-command.c +12 -4
index 910c0f6..fed37d6 100644
@@ -1,7 +1,15 @@
-#include "cache.h"
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/wait.h>
+#include "subcmd-util.h"
 #include "run-command.h"
 #include "exec_cmd.h"
-#include "debug.h"
+
+#define STRERR_BUFSIZE 128
 
 static inline void close_pair(int fd[2])
 {
@@ -164,8 +172,8 @@ static int wait_or_whine(pid_t pid)
 		if (waiting < 0) {
 			if (errno == EINTR)
 				continue;
-			error("waitpid failed (%s)",
-			      strerror_r(errno, sbuf, sizeof(sbuf)));
+			fprintf(stderr, " Error: waitpid failed (%s)",
+				strerror_r(errno, sbuf, sizeof(sbuf)));
 			return -ERR_RUN_COMMAND_WAITPID;
 		}
 		if (waiting != pid)
tools/perf/util/run-command.h +2 -0
index cf7d655..4a55393 100644
@@ -1,6 +1,8 @@
 #ifndef __PERF_RUN_COMMAND_H
 #define __PERF_RUN_COMMAND_H
 
+#include <unistd.h>
+
 enum {
 	ERR_RUN_COMMAND_FORK = 10000,
 	ERR_RUN_COMMAND_EXEC,
tools/perf/util/sigchain.c +2 -1
index ba785e9..3537c34 100644
@@ -1,5 +1,6 @@
+#include <signal.h>
+#include "subcmd-util.h"
 #include "sigchain.h"
-#include "cache.h"
 
 #define SIGCHAIN_MAX_SIGNALS 32
 
tools/perf/util/subcmd-util.h +67 -0
index 98fb9f9..321aeb1 100644
@@ -1,8 +1,66 @@
 #ifndef __PERF_SUBCMD_UTIL_H
 #define __PERF_SUBCMD_UTIL_H
 
+#include <stdarg.h>
+#include <stdlib.h>
 #include <stdio.h>
 
+#define NORETURN __attribute__((__noreturn__))
+
+static inline void report(const char *prefix, const char *err, va_list params)
+{
+	char msg[1024];
+	vsnprintf(msg, sizeof(msg), err, params);
+	fprintf(stderr, " %s%s\n", prefix, msg);
+}
+
+static NORETURN inline void die(const char *err, ...)
+{
+	va_list params;
+
+	va_start(params, err);
+	report(" Fatal: ", err, params);
+	exit(128);
+	va_end(params);
+}
+
+#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)
+
+static inline void *xrealloc(void *ptr, size_t size)
+{
+	void *ret = realloc(ptr, size);
+	if (!ret && !size)
+		ret = realloc(ptr, 1);
+	if (!ret) {
+		ret = realloc(ptr, size);
+		if (!ret && !size)
+			ret = realloc(ptr, 1);
+		if (!ret)
+			die("Out of memory, realloc failed");
+	}
+	return ret;
+}
+
 #define astrcatf(out, fmt, ...)						\
 ({									\
 	char *tmp = *(out);						\
@@ -21,4 +79,13 @@ static inline void astrcat(char **out, const char *add)
 	free(tmp);
 }
 
+static inline int prefixcmp(const char *str, const char *prefix)
+{
+	for (; ; str++, prefix++)
+		if (!*prefix)
+			return 0;
+		else if (*str != *prefix)
+			return (unsigned char)*prefix - (unsigned char)*str;
+}
+
 #endif /* __PERF_SUBCMD_UTIL_H */
tools/perf/util/util.h +0 -14
index 150858f..4b519c5 100644
@@ -151,12 +151,6 @@ extern void set_warning_routine(void (*routine)(const char *err, va_list params)
 extern int prefixcmp(const char *str, const char *prefix);
 extern void set_buildid_dir(const char *dir);
 
-static inline const char *skip_prefix(const char *str, const char *prefix)
-{
-	size_t len = strlen(prefix);
-	return strncmp(str, prefix, len) ? NULL : str + len;
-}
-
 #ifdef __GLIBC_PREREQ
 #if __GLIBC_PREREQ(2, 1)
 #define HAVE_STRCHRNUL
@@ -187,14 +181,6 @@ static inline void *zalloc(size_t size)
 
 #define zfree(ptr) ({ free(*ptr); *ptr = NULL; })
 
-static inline int has_extension(const char *filename, const char *ext)
-{
-	size_t len = strlen(filename);
-	size_t extlen = strlen(ext);
-
-	return len > extlen && !memcmp(filename + len - extlen, ext, extlen);
-}
-
 /* Sane ctype - no locale, and works with signed chars */
 #undef isascii
 #undef isspace
Signature · 1 line
2.4.3
#15 lore raw

Re: [PATCH v4 7/9] perf: Finalize subcmd independence

Quoted 39 lines · Arnaldo Carvalho de Melo

Em Tue, Dec 15, 2015 at 09:39:38AM -0600, Josh Poimboeuf escreveu:

Quoted 2 lines

For the files that will be moved to the subcmd library, remove all their perf-specific includes and duplicate any needed functionality.

Breaks rhel6.7 building:

Quoted 18 lines

#include "run-command.h"
#include "sigchain.h"
#include "subcmd-config.h"

tools/perf/util/parse-options.c +6 -2
index c1da2a5..f424027 100644
@@ -1,33 +1,47 @@
-#include "util.h"
+#include <linux/compiler.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <ctype.h>
 #include "subcmd-util.h"
 #include "parse-options.h"
-#include "cache.h"

tools/perf/util/parse-options.c line 16

Quoted 10 lines
tools/perf/util/parse-options.c +3 -2
-#include "header.h"
 #include "subcmd-config.h"
-#include <linux/string.h>
+#include "pager.h"
 
 #define OPT_SHORT 1
 #define OPT_UNSET 2
 
+typedef uint64_t u64;
+

[acme@sandy linux]$ cat /etc/redhat-release Red Hat Enterprise Linux Server release 6.7 (Santiago)

Quoted 11 lines

CC /tmp/build/perf/parse-options.o
parse-options.c:15: error: redefinition of typedef ‘u64’ /home/acme/git/linux/tools/include/linux/types.h:28: note: previous declaration of ‘u64’ was here
mv: cannot stat `/tmp/build/perf/.parse-options.o.tmp': No such file or directory
make[3]: *** [/tmp/build/perf/parse-options.o] Error 1 make[2]: *** [/tmp/build/perf/libsubcmd-in.o] Error 2 make[1]: *** [/tmp/build/perf/libsubcmd.a] Error 2
make[1]: *** Waiting for unfinished jobs....
MKDIR /tmp/build/perf/util/

Does this fix it?

---8<---

tools/lib/subcmd/parse-options.c +1 -2
index f424027..981bb44 100644
@@ -1,4 +1,5 @@
 #include <linux/compiler.h>
+#include <linux/types.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
@@ -12,8 +13,6 @@
 #define OPT_SHORT 1
 #define OPT_UNSET 2
 
-typedef uint64_t u64;
-
 char *error_buf;
 
 static int opterror(const struct option *opt, const char *reason, int flags)
#16 lore raw

Re: [PATCH v4 7/9] perf: Finalize subcmd independence

Em Wed, Dec 16, 2015 at 07:09:53PM -0600, Josh Poimboeuf escreveu:

Quoted 27 lines · Arnaldo Carvalho de Melo
Quoted 14 lines

Em Tue, Dec 15, 2015 at 09:39:38AM -0600, Josh Poimboeuf escreveu:

Quoted 2 lines

For the files that will be moved to the subcmd library, remove all their perf-specific includes and duplicate any needed functionality.

Breaks rhel6.7 building:

Review

Quoted 3 lines
(quoted diff) +2 -0
+typedef uint64_t u64;
+

[acme@sandy linux]$ cat /etc/redhat-release Red Hat Enterprise Linux Server release 6.7 (Santiago)

Quoted 11 lines

CC /tmp/build/perf/parse-options.o
parse-options.c:15: error: redefinition of typedef ‘u64’ /home/acme/git/linux/tools/include/linux/types.h:28: note: previous declaration of ‘u64’ was here
mv: cannot stat `/tmp/build/perf/.parse-options.o.tmp': No such file or directory
make[3]: *** [/tmp/build/perf/parse-options.o] Error 1 make[2]: *** [/tmp/build/perf/libsubcmd-in.o] Error 2 make[1]: *** [/tmp/build/perf/libsubcmd.a] Error 2
make[1]: *** Waiting for unfinished jobs....
MKDIR /tmp/build/perf/util/

Quoted 1 line

Does this fix it?

Yes, and it continues to build on fedora 21.

- Arnaldo

Quoted 21 lines

---8<---

tools/lib/subcmd/parse-options.c +1 -2
index f424027..981bb44 100644
@@ -1,4 +1,5 @@
 #include <linux/compiler.h>
+#include <linux/types.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
@@ -12,8 +13,6 @@
 #define OPT_SHORT 1
 #define OPT_UNSET 2
 
-typedef uint64_t u64;
-
 char *error_buf;
 
 static int opterror(const struct option *opt, const char *reason, int flags)
#17 lore raw

Re: [PATCH v4 7/9] perf: Finalize subcmd independence

Quoted 50 lines · Arnaldo Carvalho de Melo

Em Wed, Dec 16, 2015 at 07:09:53PM -0600, Josh Poimboeuf escreveu:

Quoted 27 lines · Arnaldo Carvalho de Melo
Quoted 14 lines

Em Tue, Dec 15, 2015 at 09:39:38AM -0600, Josh Poimboeuf escreveu:

Quoted 2 lines

For the files that will be moved to the subcmd library, remove all their perf-specific includes and duplicate any needed functionality.

Breaks rhel6.7 building:

Review

Quoted 3 lines
(quoted diff) +2 -0
+typedef uint64_t u64;
+

[acme@sandy linux]$ cat /etc/redhat-release Red Hat Enterprise Linux Server release 6.7 (Santiago)

Quoted 11 lines

CC /tmp/build/perf/parse-options.o
parse-options.c:15: error: redefinition of typedef ‘u64’ /home/acme/git/linux/tools/include/linux/types.h:28: note: previous declaration of ‘u64’ was here
mv: cannot stat `/tmp/build/perf/.parse-options.o.tmp': No such file or directory
make[3]: *** [/tmp/build/perf/parse-options.o] Error 1 make[2]: *** [/tmp/build/perf/libsubcmd-in.o] Error 2 make[1]: *** [/tmp/build/perf/libsubcmd.a] Error 2
make[1]: *** Waiting for unfinished jobs....
MKDIR /tmp/build/perf/util/

Quoted 1 line

Does this fix it?

Yes, and it continues to build on fedora 21.

- Arnaldo

Quoted 16 lines

---8<---

tools/lib/subcmd/parse-options.c +1 -0
index f424027..981bb44 100644
@@ -1,4 +1,5 @@
 #include <linux/compiler.h>
+#include <linux/types.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
@@ -12,8 +13,6 @@
 #define OPT_SHORT 1
 #define OPT_UNSET 2
 
Quoted 5 lines

tools/lib/subcmd/parse-options.c line 18

Quoted 5 lines
tools/lib/subcmd/parse-options.c +0 -2
-typedef uint64_t u64;
-
 char *error_buf;
 
 static int opterror(const struct option *opt, const char *reason, int flags)

Here's the same patch but without the unnecessary addition of the <linux/types.h> include. Ideally it would be folded into

"perf tools: Finalize subcmd independence"

but in case it's too late for that, I added a changelog.

---8<---

Subject: [PATCH] tools subcmd: Fix 'u64' build error with older compilers

Arnaldo reported the following error when building perf on RHEL 6.7:

parse-options.c:15: error: redefinition of typedef ‘u64’ /home/acme/git/linux/tools/include/linux/types.h:28: note: previous declaration of ‘u64’ was here

The parse-options.c file includes <linux/compiler.h>, which includes <linux/types.h>, which has a u64 typedef. So the u64 typedef in parse-options.c is unnecessary (and seems to trigger the above error on compilers which don't allow duplicate typedefs).

---
 tools/lib/subcmd/parse-options.c | 2 --
 1 file changed, 2 deletions(-)
tools/lib/subcmd/parse-options.c +0 -2
index f424027..c0c911a 100644
@@ -12,8 +12,6 @@
 #define OPT_SHORT 1
 #define OPT_UNSET 2
 
-typedef uint64_t u64;
-
 char *error_buf;
 
 static int opterror(const struct option *opt, const char *reason, int flags)
Signature · 1 line
2.4.3
#2 lore raw

[tip:perf/core] tools build: Fix feature Makefile issues with 'O= '

In reply to Josh Poimboeuf
tools build: Fix feature Makefile issues with 'O='
Commit-ID:  1925459b4d92d92e62d67ddc763cda650d2aa79c
Gitweb:     http://git.kernel.org/tip/1925459b4d92d92e62d67ddc763cda650d2aa79c
Author:     Josh Poimboeuf <[email protected]>
AuthorDate: Tue, 15 Dec 2015 09:39:32 -0600
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 16 Dec 2015 15:31:33 -0300

tools build: Fix feature Makefile issues with 'O='

When building perf binaries outside the source tree with 'make O=<dir>', the auto-detected features get re-tested for every build, which is unnecessary and inconsistent with the behavior seen when building directly in the source tree.

Another issue is that 'make O=<dir> clean' doesn't remove the feature files from the object tree.

Fix these problems by looking for the binaries in the $(OUTPUT) directory.

---
 tools/build/Makefile.feature |  2 +-
 tools/build/feature/Makefile | 93 ++++++++++++++++++++++----------------------
 2 files changed, 48 insertions(+), 47 deletions(-)
tools/build/Makefile.feature +1 -1
index b8c31ec..6c0519d 100644
@@ -7,7 +7,7 @@ endif
 
 feature_check = $(eval $(feature_check_code))
 define feature_check_code
-  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C $(feature_dir) test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0)
+  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C $(feature_dir) $(OUTPUT_FEATURES)test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0)
 endef
 
 feature_set = $(eval $(feature_set_code))
tools/build/feature/Makefile +47 -46

189 lines not on this page · raw message

#4 lore raw

[tip:perf/core] perf tools: Move strlcpy() from perf to tools/lib /string.c

In reply to Josh Poimboeuf
perf tools: Move strlcpy() from perf to tools/lib/string.c
Commit-ID:  ce99091730c92bf560712baa0696ea5a461b1fe8
Gitweb:     http://git.kernel.org/tip/ce99091730c92bf560712baa0696ea5a461b1fe8
Author:     Josh Poimboeuf <[email protected]>
AuthorDate: Tue, 15 Dec 2015 09:39:33 -0600
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 16 Dec 2015 16:09:39 -0300

perf tools: Move strlcpy() from perf to tools/lib/string.c

strlcpy() will be needed by the subcmd library. Move it to the shared tools/lib/string.c file which can be used by other tools.

---
 tools/include/linux/string.h |  4 ++++
 tools/lib/string.c           | 27 +++++++++++++++++++++++++++
 tools/perf/util/cache.h      |  7 ++-----
 tools/perf/util/path.c       | 18 ------------------
 4 files changed, 33 insertions(+), 23 deletions(-)
tools/include/linux/string.h +4 -0
index 2e2f736..e26223f 100644
@@ -8,4 +8,8 @@ void *memdup(const void *src, size_t len);
 
 int strtobool(const char *s, bool *res);
 
+#ifndef __UCLIBC__
+extern size_t strlcpy(char *dest, const char *src, size_t size);
+#endif
+
 #endif /* _LINUX_STRING_H_ */
tools/lib/string.c +27 -0
index 065e54f..bd239bc 100644
@@ -16,6 +16,7 @@
 #include <string.h>
 #include <errno.h>
 #include <linux/string.h>
+#include <linux/compiler.h>
 
 /**
  * memdup - duplicate region of memory
@@ -60,3 +61,29 @@ int strtobool(const char *s, bool *res)
 	}
 	return 0;
 }
+
+/**
+ * strlcpy - Copy a C-string into a sized buffer
+ * @dest: Where to copy the string to
+ * @src: Where to copy the string from
+ * @size: size of destination buffer
+ *
+ * Compatible with *BSD: the result is always a valid
+ * NUL-terminated string that fits in the buffer (unless,
+ * of course, the buffer size is zero). It does not pad
+ * out the result like strncpy() does.
+ *
+ * If libc has strlcpy() then that version will override this
+ * implementation:
+ */
+size_t __weak strlcpy(char *dest, const char *src, size_t size)
+{
+	size_t ret = strlen(src);
+
+	if (size) {
+		size_t len = (ret >= size) ? size - 1 : ret;
+		memcpy(dest, src, len);
+		dest[len] = '\0';
+	}
+	return ret;
+}
tools/perf/util/cache.h +2 -5
index 9ca4a58..d723ecb 100644
@@ -8,6 +8,8 @@
 #include "../perf.h"
 #include "../ui/ui.h"
 
+#include <linux/string.h>
+
 #define CMD_EXEC_PATH "--exec-path"
 #define CMD_PERF_DIR "--perf-dir="
 #define CMD_WORK_TREE "--work-tree="
@@ -67,9 +69,4 @@ 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_CACHE_H */
tools/perf/util/path.c +0 -18
index 5d13cb4..3654d96 100644
@@ -22,24 +22,6 @@ static const char *get_perf_dir(void)
 	return ".";
 }
 
-/*
- * If libc has strlcpy() then that version will override this
- * implementation:
- */
-size_t __weak strlcpy(char *dest, const char *src, size_t size)
-{
-	size_t ret = strlen(src);
-
-	if (size) {
-		size_t len = (ret >= size) ? size - 1 : ret;
-
-		memcpy(dest, src, len);
-		dest[len] = '\0';
-	}
-
-	return ret;
-}
-
 static char *get_pathname(void)
 {
 	static char pathname_array[4][PATH_MAX];
#6 lore raw

[tip:perf/core] perf tools: Document the fact that parse_options* () may exit

In reply to Josh Poimboeuf
perf tools: Document the fact that parse_options*() may exit
Commit-ID:  24a88bdd05d5de32f3a56a4dcc5070c97d4a514f
Gitweb:     http://git.kernel.org/tip/24a88bdd05d5de32f3a56a4dcc5070c97d4a514f
Author:     Josh Poimboeuf <[email protected]>
AuthorDate: Tue, 15 Dec 2015 09:39:34 -0600
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 16 Dec 2015 16:16:49 -0300

perf tools: Document the fact that parse_options*() may exit

Generally, calling exit() from a library is bad practice. Eventually these functions might be redesigned so that they don't exit. For now, just document the fact that they do.

---
 tools/perf/util/parse-options.h | 3 +++
 1 file changed, 3 insertions(+)
tools/perf/util/parse-options.h +3 -0
index 1231960..d1544069 100644
@@ -152,6 +152,9 @@ struct option {
 /* parse_options() will filter out the processed options and leave the
  * non-option argments in argv[].
  * Returns the number of arguments left in argv[].
+ *
+ * NOTE: parse_options() and parse_options_subcommand() may call exit() in the
+ * case of an error (or for 'special' options like --list-cmds or --list-opts).
  */
 extern int parse_options(int argc, const char **argv,
                          const struct option *options,
#8 lore raw

[tip:perf/core] perf tools: Provide subcmd configuration at runtime

In reply to Josh Poimboeuf
perf tools: Provide subcmd configuration at runtime
Commit-ID:  096d35585b4fce7d3ee9b8b34314f39f49491ab1
Gitweb:     http://git.kernel.org/tip/096d35585b4fce7d3ee9b8b34314f39f49491ab1
Author:     Josh Poimboeuf <[email protected]>
AuthorDate: Tue, 15 Dec 2015 09:39:35 -0600
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 16 Dec 2015 16:18:16 -0300

perf tools: Provide subcmd configuration at runtime

Create init functions for exec_cmd.c and pager.c. This allows their configuration to be specified at runtime so they can be split out into a separate library which can be used by other programs. Their configuration is stored in a shared subcmd_config struct.

---
 tools/perf/Build                |  5 ++++-
 tools/perf/perf.c               |  6 +++++-
 tools/perf/util/Build           |  2 +-
 tools/perf/util/cache.h         |  1 +
 tools/perf/util/exec_cmd.c      | 23 ++++++++++++++++-------
 tools/perf/util/exec_cmd.h      |  3 +++
 tools/perf/util/pager.c         |  8 +++++++-
 tools/perf/util/pager.h         |  2 ++
 tools/perf/util/parse-options.c |  4 +++-
 tools/perf/util/subcmd-config.c | 11 +++++++++++
 tools/perf/util/subcmd-config.h | 14 ++++++++++++++
 11 files changed, 67 insertions(+), 12 deletions(-)
tools/perf/Build +4 -1
index 2a41217..00c4b8c 100644
@@ -36,7 +36,10 @@ paths += -DPERF_MAN_PATH="BUILD_STR($(mandir_SQ))"
 
 CFLAGS_builtin-help.o      += $(paths)
 CFLAGS_builtin-timechart.o += $(paths)
-CFLAGS_perf.o              += -DPERF_HTML_PATH="BUILD_STR($(htmldir_SQ))" -include $(OUTPUT)PERF-VERSION-FILE
+CFLAGS_perf.o              += -DPERF_HTML_PATH="BUILD_STR($(htmldir_SQ))"	\
+			      -DPERF_EXEC_PATH="BUILD_STR($(perfexecdir_SQ))"	\
+			      -DPREFIX="BUILD_STR($(prefix_SQ))"		\
+			      -include $(OUTPUT)PERF-VERSION-FILE
 CFLAGS_builtin-trace.o	   += -DSTRACE_GROUPS_DIR="BUILD_STR($(STRACE_GROUPS_DIR_SQ))"
 
 libperf-y += util/
tools/perf/perf.c +5 -1
index 59ea48c..783a331 100644
@@ -119,7 +119,7 @@ static void commit_pager_choice(void)
 {
 	switch (use_pager) {
 	case 0:
-		setenv("PERF_PAGER", "cat", 1);
+		setenv(PERF_PAGER_ENVIRONMENT, "cat", 1);
 		break;
 	case 1:
 		/* setup_pager(); */
@@ -530,6 +530,10 @@ int main(int argc, const char **argv)
 	const char *cmd;
 	char sbuf[STRERR_BUFSIZE];
 
+	/* libsubcmd init */
+	exec_cmd_init("perf", PREFIX, PERF_EXEC_PATH, EXEC_PATH_ENVIRONMENT);
+	pager_init(PERF_PAGER_ENVIRONMENT);
+
 	/* The page_size is placed in util object. */
 	page_size = sysconf(_SC_PAGE_SIZE);
 	cacheline_size = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
tools/perf/util/Build +1 -1
index 99b3dae..196beef 100644
@@ -88,6 +88,7 @@ libperf-y += parse-branch-options.o
 libperf-y += parse-regs-options.o
 libperf-y += term.o
 libperf-y += help-unknown-cmd.o
+libperf-y += subcmd-config.o
 
 libperf-$(CONFIG_LIBBPF) += bpf-loader.o
 libperf-$(CONFIG_BPF_PROLOGUE) += bpf-prologue.o
@@ -113,7 +114,6 @@ libperf-$(CONFIG_ZLIB) += zlib.o
 libperf-$(CONFIG_LZMA) += lzma.o
 
 CFLAGS_config.o   += -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
-CFLAGS_exec_cmd.o += -DPERF_EXEC_PATH="BUILD_STR($(perfexecdir_SQ))" -DPREFIX="BUILD_STR($(prefix_SQ))"
 
 $(OUTPUT)util/parse-events-flex.c: util/parse-events.l $(OUTPUT)util/parse-events-bison.c
 	$(call rule_mkdir)
tools/perf/util/cache.h +1 -0
index d723ecb..fc6a745 100644
@@ -21,6 +21,7 @@
 #define DEFAULT_PERF_DIR_ENVIRONMENT ".perf"
 #define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"
 #define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR"
+#define PERF_PAGER_ENVIRONMENT "PERF_PAGER"
 
 typedef int (*config_fn_t)(const char *, const char *, void *);
 extern int perf_default_config(const char *, const char *, void *);
tools/perf/util/exec_cmd.c +16 -7
index 1099e92..b935e4c 100644
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "exec_cmd.h"
 #include "quote.h"
+#include "subcmd-config.h"
 
 #include <string.h>
 
@@ -9,15 +10,23 @@
 static const char *argv_exec_path;
 static const char *argv0_path;
 
+void exec_cmd_init(const char *exec_name, const char *prefix,
+		   const char *exec_path, const char *exec_path_env)
+{
+	subcmd_config.exec_name		= exec_name;
+	subcmd_config.prefix		= prefix;
+	subcmd_config.exec_path		= exec_path;
+	subcmd_config.exec_path_env	= exec_path_env;
+}
+
 char *system_path(const char *path)
 {
-	static const char *prefix = PREFIX;
 	struct strbuf d = STRBUF_INIT;
 
 	if (is_absolute_path(path))
 		return strdup(path);
 
-	strbuf_addf(&d, "%s/%s", prefix, path);
+	strbuf_addf(&d, "%s/%s", subcmd_config.prefix, path);
 	path = strbuf_detach(&d, NULL);
 	return (char *)path;
 }
@@ -47,7 +56,7 @@ void perf_set_argv_exec_path(const char *exec_path)
 	/*
 	 * Propagate this setting to external programs.
 	 */
-	setenv(EXEC_PATH_ENVIRONMENT, exec_path, 1);
+	setenv(subcmd_config.exec_path_env, exec_path, 1);
 }
 
 
@@ -59,11 +68,11 @@ char *perf_exec_path(void)
 	if (argv_exec_path)
 		return strdup(argv_exec_path);
 
-	env = getenv(EXEC_PATH_ENVIRONMENT);
+	env = getenv(subcmd_config.exec_path_env);
 	if (env && *env)
 		return strdup(env);
 
-	return system_path(PERF_EXEC_PATH);
+	return system_path(subcmd_config.exec_path);
 }
 
 static void add_path(struct strbuf *out, const char *path)
@@ -107,7 +116,7 @@ static const char **prepare_perf_cmd(const char **argv)
 		; /* just counting */
 	nargv = malloc(sizeof(*nargv) * (argc + 2));
 
-	nargv[0] = "perf";
+	nargv[0] = subcmd_config.exec_name;
 	for (argc = 0; argv[argc]; argc++)
 		nargv[argc + 1] = argv[argc];
 	nargv[argc + 1] = NULL;
@@ -118,7 +127,7 @@ int execv_perf_cmd(const char **argv) {
 	const char **nargv = prepare_perf_cmd(argv);
 
 	/* execvp() can only ever return if it fails */
-	execvp("perf", (char **)nargv);
+	execvp(subcmd_config.exec_name, (char **)nargv);
 
 	free(nargv);
 	return -1;
tools/perf/util/exec_cmd.h +3 -0
index 48b4175..fd4434e 100644
@@ -1,6 +1,9 @@
 #ifndef __PERF_EXEC_CMD_H
 #define __PERF_EXEC_CMD_H
 
+extern void exec_cmd_init(const char *exec_name, const char *prefix,
+			  const char *exec_path, const char *exec_path_env);
+
 extern void perf_set_argv_exec_path(const char *exec_path);
 extern const char *perf_extract_argv0_path(const char *path);
 extern void setup_path(void);
tools/perf/util/pager.c +7 -1
index 7dcbef6..d5ef62e 100644
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "run-command.h"
 #include "sigchain.h"
+#include "subcmd-config.h"
 
 /*
  * This is split up from the rest of git so that we can do
@@ -9,6 +10,11 @@
 
 static int spawned_pager;
 
+void pager_init(const char *pager_env)
+{
+	subcmd_config.pager_env = pager_env;
+}
+
 static void pager_preexec(void)
 {
 	/*
@@ -46,7 +52,7 @@ static void wait_for_pager_signal(int signo)
 
 void setup_pager(void)
 {
-	const char *pager = getenv("PERF_PAGER");
+	const char *pager = getenv(subcmd_config.pager_env);
 
 	if (!isatty(1))
 		return;
tools/perf/util/pager.h +2 -0
index 2794a83..d6a591a 100644
@@ -1,6 +1,8 @@
 #ifndef __PERF_PAGER_H
 #define __PERF_PAGER_H
 
+extern void pager_init(const char *pager_env);
+
 extern void setup_pager(void);
 extern int pager_in_use(void);
 
tools/perf/util/parse-options.c +3 -1
index 0ad1384..da4ba21 100644
@@ -2,6 +2,7 @@
 #include "parse-options.h"
 #include "cache.h"
 #include "header.h"
+#include "subcmd-config.h"
 #include <linux/string.h>
 
 #define OPT_SHORT 1
@@ -577,7 +578,8 @@ int parse_options_subcommand(int argc, const char **argv, const struct option *o
 	if (subcommands && !usagestr[0]) {
 		struct strbuf buf = STRBUF_INIT;
 
-		strbuf_addf(&buf, "perf %s [<options>] {", argv[0]);
+		strbuf_addf(&buf, "%s %s [<options>] {",
+			    subcmd_config.exec_name, argv[0]);
 		for (int i = 0; subcommands[i]; i++) {
 			if (i)
 				strbuf_addstr(&buf, "|");
tools/perf/util/subcmd-config.c new file +11 -0
new file mode 100644
index 0000000..d017c72
@@ -0,0 +1,11 @@
+#include "subcmd-config.h"
+
+#define UNDEFINED "SUBCMD_HAS_NOT_BEEN_INITIALIZED"
+
+struct subcmd_config subcmd_config = {
+	.exec_name	= UNDEFINED,
+	.prefix		= UNDEFINED,
+	.exec_path	= UNDEFINED,
+	.exec_path_env	= UNDEFINED,
+	.pager_env	= UNDEFINED,
+};
tools/perf/util/subcmd-config.h new file +14 -0
new file mode 100644
index 0000000..cc85140
@@ -0,0 +1,14 @@
+#ifndef __PERF_SUBCMD_CONFIG_H
+#define __PERF_SUBCMD_CONFIG_H
+
+struct subcmd_config {
+	const char *exec_name;
+	const char *prefix;
+	const char *exec_path;
+	const char *exec_path_env;
+	const char *pager_env;
+};
+
+extern struct subcmd_config subcmd_config;
+
+#endif /* __PERF_SUBCMD_CONFIG_H */
#10 lore raw

[tip:perf/core] perf tools: Remove subcmd dependencies on strbuf

In reply to Josh Poimboeuf
perf tools: Remove subcmd dependencies on strbuf
Commit-ID:  901421a5bdf605d24c278825cdd032cd6038bcb8
Gitweb:     http://git.kernel.org/tip/901421a5bdf605d24c278825cdd032cd6038bcb8
Author:     Josh Poimboeuf <[email protected]>
AuthorDate: Tue, 15 Dec 2015 09:39:36 -0600
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 16 Dec 2015 21:33:13 -0300

perf tools: Remove subcmd dependencies on strbuf

Introduce and use new astrcat() and astrcatf() functions which replace the strbuf functionality for subcmd.

For now they duplicate strbuf's die-on-allocation-error policy.

---
 tools/perf/util/exec_cmd.c      | 27 +++++++++++++-------------
 tools/perf/util/help.c          | 14 ++++++--------
 tools/perf/util/parse-options.c | 42 +++++++++++++++++++++--------------------
 tools/perf/util/subcmd-util.h   | 24 +++++++++++++++++++++++
 4 files changed, 66 insertions(+), 41 deletions(-)
tools/perf/util/exec_cmd.c +14 -13
index b935e4c..65d86dc 100644
@@ -4,6 +4,7 @@
 #include "subcmd-config.h"
 
 #include <string.h>
+#include "subcmd-util.h"
 
 #define MAX_ARGS	32
 
@@ -21,14 +22,14 @@ void exec_cmd_init(const char *exec_name, const char *prefix,
 
 char *system_path(const char *path)
 {
-	struct strbuf d = STRBUF_INIT;
+	char *buf = NULL;
 
 	if (is_absolute_path(path))
 		return strdup(path);
 
-	strbuf_addf(&d, "%s/%s", subcmd_config.prefix, path);
-	path = strbuf_detach(&d, NULL);
-	return (char *)path;
+	astrcatf(&buf, "%s/%s", subcmd_config.prefix, path);
+
+	return buf;
 }
 
 const char *perf_extract_argv0_path(const char *argv0)
@@ -75,22 +76,22 @@ char *perf_exec_path(void)
 	return system_path(subcmd_config.exec_path);
 }
 
-static void add_path(struct strbuf *out, const char *path)
+static void add_path(char **out, const char *path)
 {
 	if (path && *path) {
 		if (is_absolute_path(path))
-			strbuf_addstr(out, path);
+			astrcat(out, path);
 		else
-			strbuf_addstr(out, make_nonrelative_path(path));
+			astrcat(out, make_nonrelative_path(path));
 
-		strbuf_addch(out, PATH_SEP);
+		astrcat(out, ":");
 	}
 }
 
 void setup_path(void)
 {
 	const char *old_path = getenv("PATH");
-	struct strbuf new_path = STRBUF_INIT;
+	char *new_path = NULL;
 	char *tmp = perf_exec_path();
 
 	add_path(&new_path, tmp);
@@ -98,13 +99,13 @@ void setup_path(void)
 	free(tmp);
 
 	if (old_path)
-		strbuf_addstr(&new_path, old_path);
+		astrcat(&new_path, old_path);
 	else
-		strbuf_addstr(&new_path, "/usr/local/bin:/usr/bin:/bin");
+		astrcat(&new_path, "/usr/local/bin:/usr/bin:/bin");
 
-	setenv("PATH", new_path.buf, 1);
+	setenv("PATH", new_path, 1);
 
-	strbuf_release(&new_path);
+	free(new_path);
 }
 
 static const char **prepare_perf_cmd(const char **argv)
tools/perf/util/help.c +6 -8
index 8d74f7d..8e5e0ce 100644
@@ -2,6 +2,7 @@
 #include "../builtin.h"
 #include "exec_cmd.h"
 #include "help.h"
+#include "subcmd-util.h"
 
 void add_cmdname(struct cmdnames *cmds, const char *name, size_t len)
 {
@@ -119,8 +120,7 @@ static void list_commands_in_dir(struct cmdnames *cmds,
 	int prefix_len;
 	DIR *dir = opendir(path);
 	struct dirent *de;
-	struct strbuf buf = STRBUF_INIT;
-	int len;
+	char *buf = NULL;
 
 	if (!dir)
 		return;
@@ -128,8 +128,7 @@ static void list_commands_in_dir(struct cmdnames *cmds,
 		prefix = "perf-";
 	prefix_len = strlen(prefix);
 
-	strbuf_addf(&buf, "%s/", path);
-	len = buf.len;
+	astrcatf(&buf, "%s/", path);
 
 	while ((de = readdir(dir)) != NULL) {
 		int entlen;
@@ -137,9 +136,8 @@ static void list_commands_in_dir(struct cmdnames *cmds,
 		if (prefixcmp(de->d_name, prefix))
 			continue;
 
-		strbuf_setlen(&buf, len);
-		strbuf_addstr(&buf, de->d_name);
-		if (!is_executable(buf.buf))
+		astrcat(&buf, de->d_name);
+		if (!is_executable(buf))
 			continue;
 
 		entlen = strlen(de->d_name) - prefix_len;
@@ -149,7 +147,7 @@ static void list_commands_in_dir(struct cmdnames *cmds,
 		add_cmdname(cmds, de->d_name + prefix_len, entlen);
 	}
 	closedir(dir);
-	strbuf_release(&buf);
+	free(buf);
 }
 
 void load_command_list(const char *prefix,
tools/perf/util/parse-options.c +22 -20

85 lines not on this page · raw message

tools/perf/util/subcmd-util.h new file +24 -0
new file mode 100644
index 0000000..98fb9f9
@@ -0,0 +1,24 @@
+#ifndef __PERF_SUBCMD_UTIL_H
+#define __PERF_SUBCMD_UTIL_H
+
+#include <stdio.h>
+
+#define astrcatf(out, fmt, ...)						\
+({									\
+	char *tmp = *(out);						\
+	if (asprintf((out), "%s" fmt, tmp ?: "", ## __VA_ARGS__) == -1)	\
+		die("asprintf failed");					\
+	free(tmp);							\
+})
+
+static inline void astrcat(char **out, const char *add)
+{
+	char *tmp = *out;
+
+	if (asprintf(out, "%s%s", tmp ?: "", add) == -1)
+		die("asprintf failed");
+
+	free(tmp);
+}
+
+#endif /* __PERF_SUBCMD_UTIL_H */
#12 lore raw

[tip:perf/core] perf tools: Remove 'perf' from subcmd function and variable names

In reply to Josh Poimboeuf
perf tools: Remove 'perf' from subcmd function and variable names
Commit-ID:  46113a54be53aea50a4f5926b87e86e2e66c4266
Gitweb:     http://git.kernel.org/tip/46113a54be53aea50a4f5926b87e86e2e66c4266
Author:     Josh Poimboeuf <[email protected]>
AuthorDate: Tue, 15 Dec 2015 09:39:37 -0600
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 16 Dec 2015 21:34:28 -0300

perf tools: Remove 'perf' from subcmd function and variable names

In preparation for moving exec_cmd.c and run-command.c out of perf and into a library, remove 'perf' from all the symbol names.

---
 tools/perf/builtin-help.c     |  2 +-
 tools/perf/builtin-script.c   |  8 ++++----
 tools/perf/perf.c             |  6 +++---
 tools/perf/tests/attr.c       |  2 +-
 tools/perf/util/exec_cmd.c    | 20 ++++++++++----------
 tools/perf/util/exec_cmd.h    | 12 ++++++------
 tools/perf/util/help.c        |  4 ++--
 tools/perf/util/run-command.c |  6 +++---
 tools/perf/util/run-command.h |  4 ++--
 9 files changed, 32 insertions(+), 32 deletions(-)
tools/perf/builtin-help.c +1 -1
index a7d588b..275aa64 100644
@@ -407,7 +407,7 @@ static int get_html_page_path(struct strbuf *page_path, const char *page)
 #ifndef open_html
 static void open_html(const char *path)
 {
-	execl_perf_cmd("web--browse", "-c", "help.browser", path, NULL);
+	execl_cmd("web--browse", "-c", "help.browser", path, NULL);
 }
 #endif
 
tools/perf/builtin-script.c +4 -4
index d259e9a..571016f 100644
@@ -1408,7 +1408,7 @@ static int list_available_scripts(const struct option *opt __maybe_unused,
 	char first_half[BUFSIZ];
 	char *script_root;
 
-	snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path());
+	snprintf(scripts_path, MAXPATHLEN, "%s/scripts", get_argv_exec_path());
 
 	scripts_dir = opendir(scripts_path);
 	if (!scripts_dir)
@@ -1529,7 +1529,7 @@ int find_scripts(char **scripts_array, char **scripts_path_array)
 	if (!session)
 		return -1;
 
-	snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path());
+	snprintf(scripts_path, MAXPATHLEN, "%s/scripts", get_argv_exec_path());
 
 	scripts_dir = opendir(scripts_path);
 	if (!scripts_dir) {
@@ -1587,7 +1587,7 @@ static char *get_script_path(const char *script_root, const char *suffix)
 	char lang_path[MAXPATHLEN];
 	char *__script_root;
 
-	snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path());
+	snprintf(scripts_path, MAXPATHLEN, "%s/scripts", get_argv_exec_path());
 
 	scripts_dir = opendir(scripts_path);
 	if (!scripts_dir)
@@ -1823,7 +1823,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 		scripting_max_stack = itrace_synth_opts.callchain_sz;
 
 	/* make sure PERF_EXEC_PATH is set for scripts */
-	perf_set_argv_exec_path(perf_exec_path());
+	set_argv_exec_path(get_argv_exec_path());
 
 	if (argc && !script_name && !rec_script_path && !rep_script_path) {
 		int live_pipe[2];
tools/perf/perf.c +3 -3
index 783a331..6894325 100644
@@ -183,9 +183,9 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
 		if (!prefixcmp(cmd, CMD_EXEC_PATH)) {
 			cmd += strlen(CMD_EXEC_PATH);
 			if (*cmd == '=')
-				perf_set_argv_exec_path(cmd + 1);
+				set_argv_exec_path(cmd + 1);
 			else {
-				puts(perf_exec_path());
+				puts(get_argv_exec_path());
 				exit(0);
 			}
 		} else if (!strcmp(cmd, "--html-path")) {
@@ -538,7 +538,7 @@ int main(int argc, const char **argv)
 	page_size = sysconf(_SC_PAGE_SIZE);
 	cacheline_size = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
 
-	cmd = perf_extract_argv0_path(argv[0]);
+	cmd = extract_argv0_path(argv[0]);
 	if (!cmd)
 		cmd = "perf-help";
 
tools/perf/tests/attr.c +1 -1
index b66730e..6337f1c 100644
@@ -164,7 +164,7 @@ int test__attr(int subtest __maybe_unused)
 		return run_dir("./tests", "./perf");
 
 	/* Then installed path. */
-	snprintf(path_dir,  PATH_MAX, "%s/tests", perf_exec_path());
+	snprintf(path_dir,  PATH_MAX, "%s/tests", get_argv_exec_path());
 	snprintf(path_perf, PATH_MAX, "%s/perf", BINDIR);
 
 	if (!lstat(path_dir, &st) &&
tools/perf/util/exec_cmd.c +10 -10
index 65d86dc..701111a 100644
@@ -32,7 +32,7 @@ char *system_path(const char *path)
 	return buf;
 }
 
-const char *perf_extract_argv0_path(const char *argv0)
+const char *extract_argv0_path(const char *argv0)
 {
 	const char *slash;
 
@@ -51,7 +51,7 @@ const char *perf_extract_argv0_path(const char *argv0)
 	return argv0;
 }
 
-void perf_set_argv_exec_path(const char *exec_path)
+void set_argv_exec_path(const char *exec_path)
 {
 	argv_exec_path = exec_path;
 	/*
@@ -61,8 +61,8 @@ void perf_set_argv_exec_path(const char *exec_path)
 }
 
 
-/* Returns the highest-priority, location to look for perf programs. */
-char *perf_exec_path(void)
+/* Returns the highest-priority location to look for subprograms. */
+char *get_argv_exec_path(void)
 {
 	char *env;
 
@@ -92,7 +92,7 @@ void setup_path(void)
 {
 	const char *old_path = getenv("PATH");
 	char *new_path = NULL;
-	char *tmp = perf_exec_path();
+	char *tmp = get_argv_exec_path();
 
 	add_path(&new_path, tmp);
 	add_path(&new_path, argv0_path);
@@ -108,7 +108,7 @@ void setup_path(void)
 	free(new_path);
 }
 
-static const char **prepare_perf_cmd(const char **argv)
+static const char **prepare_exec_cmd(const char **argv)
 {
 	int argc;
 	const char **nargv;
@@ -124,8 +124,8 @@ static const char **prepare_perf_cmd(const char **argv)
 	return nargv;
 }
 
-int execv_perf_cmd(const char **argv) {
-	const char **nargv = prepare_perf_cmd(argv);
+int execv_cmd(const char **argv) {
+	const char **nargv = prepare_exec_cmd(argv);
 
 	/* execvp() can only ever return if it fails */
 	execvp(subcmd_config.exec_name, (char **)nargv);
@@ -135,7 +135,7 @@ int execv_perf_cmd(const char **argv) {
 }
 
 
-int execl_perf_cmd(const char *cmd,...)
+int execl_cmd(const char *cmd,...)
 {
 	int argc;
 	const char *argv[MAX_ARGS + 1];
@@ -155,5 +155,5 @@ int execl_perf_cmd(const char *cmd,...)
 		return error("too many args to run %s", cmd);
 
 	argv[argc] = NULL;
-	return execv_perf_cmd(argv);
+	return execv_cmd(argv);
 }
tools/perf/util/exec_cmd.h +6 -6
index fd4434e..f1bd343 100644
@@ -4,13 +4,13 @@
 extern void exec_cmd_init(const char *exec_name, const char *prefix,
 			  const char *exec_path, const char *exec_path_env);
 
-extern void perf_set_argv_exec_path(const char *exec_path);
-extern const char *perf_extract_argv0_path(const char *path);
+extern void set_argv_exec_path(const char *exec_path);
+extern const char *extract_argv0_path(const char *path);
 extern void setup_path(void);
-extern int execv_perf_cmd(const char **argv); /* NULL terminated */
-extern int execl_perf_cmd(const char *cmd, ...);
-/* perf_exec_path and system_path return malloc'd string, caller must free it */
-extern char *perf_exec_path(void);
+extern int execv_cmd(const char **argv); /* NULL terminated */
+extern int execl_cmd(const char *cmd, ...);
+/* get_argv_exec_path and system_path return malloc'd string, caller must free it */
+extern char *get_argv_exec_path(void);
 extern char *system_path(const char *path);
 
 #endif /* __PERF_EXEC_CMD_H */
tools/perf/util/help.c +2 -2
index 8e5e0ce..303a347 100644
@@ -155,7 +155,7 @@ void load_command_list(const char *prefix,
 		struct cmdnames *other_cmds)
 {
 	const char *env_path = getenv("PATH");
-	char *exec_path = perf_exec_path();
+	char *exec_path = get_argv_exec_path();
 
 	if (exec_path) {
 		list_commands_in_dir(main_cmds, exec_path, prefix);
@@ -200,7 +200,7 @@ void list_commands(const char *title, struct cmdnames *main_cmds,
 			longest = other_cmds->names[i]->len;
 
 	if (main_cmds->cnt) {
-		char *exec_path = perf_exec_path();
+		char *exec_path = get_argv_exec_path();
 		printf("available %s in '%s'\n", title, exec_path);
 		printf("----------------");
 		mput_char('-', strlen(title) + strlen(exec_path));
tools/perf/util/run-command.c +3 -3
index 34622b5..910c0f6 100644
@@ -112,8 +112,8 @@ int start_command(struct child_process *cmd)
 		}
 		if (cmd->preexec_cb)
 			cmd->preexec_cb();
-		if (cmd->perf_cmd) {
-			execv_perf_cmd(cmd->argv);
+		if (cmd->exec_cmd) {
+			execv_cmd(cmd->argv);
 		} else {
 			execvp(cmd->argv[0], (char *const*) cmd->argv);
 		}
@@ -207,7 +207,7 @@ static void prepare_run_command_v_opt(struct child_process *cmd,
 	memset(cmd, 0, sizeof(*cmd));
 	cmd->argv = argv;
 	cmd->no_stdin = opt & RUN_COMMAND_NO_STDIN ? 1 : 0;
-	cmd->perf_cmd = opt & RUN_PERF_CMD ? 1 : 0;
+	cmd->exec_cmd = opt & RUN_EXEC_CMD ? 1 : 0;
 	cmd->stdout_to_stderr = opt & RUN_COMMAND_STDOUT_TO_STDERR ? 1 : 0;
 }
 
tools/perf/util/run-command.h +2 -2
index 1ef264d..cf7d655 100644
@@ -41,7 +41,7 @@ struct child_process {
 	unsigned no_stdin:1;
 	unsigned no_stdout:1;
 	unsigned no_stderr:1;
-	unsigned perf_cmd:1; /* if this is to be perf sub-command */
+	unsigned exec_cmd:1; /* if this is to be external sub-command */
 	unsigned stdout_to_stderr:1;
 	void (*preexec_cb)(void);
 };
@@ -51,7 +51,7 @@ int finish_command(struct child_process *);
 int run_command(struct child_process *);
 
 #define RUN_COMMAND_NO_STDIN 1
-#define RUN_PERF_CMD	     2	/*If this is to be perf sub-command */
+#define RUN_EXEC_CMD	     2	/*If this is to be external sub-command */
 #define RUN_COMMAND_STDOUT_TO_STDERR 4
 int run_command_v_opt(const char **argv, int opt);
 
#18 lore raw

[tip:perf/core] perf tools: Finalize subcmd independence

In reply to Josh Poimboeuf
perf tools: Finalize subcmd independence
Commit-ID:  2f4ce5ec1d447beb42143a9653716a2ab025161e
Gitweb:     http://git.kernel.org/tip/2f4ce5ec1d447beb42143a9653716a2ab025161e
Author:     Josh Poimboeuf <[email protected]>
AuthorDate: Tue, 15 Dec 2015 09:39:38 -0600
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 17 Dec 2015 14:27:10 -0300

perf tools: Finalize subcmd independence

For the files that will be moved to the subcmd library, remove all their perf-specific includes and duplicate any needed functionality.

---
 tools/perf/util/exec_cmd.c      | 64 ++++++++++++++++++++++++++++++++----
 tools/perf/util/help.c          | 47 +++++++++++++++++++++++---
 tools/perf/util/help.h          |  4 ++-
 tools/perf/util/pager.c         |  7 +++-
 tools/perf/util/parse-options.c | 73 +++++++++++++++++++++++++----------------
 tools/perf/util/parse-options.h |  2 +-
 tools/perf/util/run-command.c   | 16 ++++++---
 tools/perf/util/run-command.h   |  2 ++
 tools/perf/util/sigchain.c      |  3 +-
 tools/perf/util/subcmd-util.h   | 67 +++++++++++++++++++++++++++++++++++++
 tools/perf/util/util.h          | 14 --------
 11 files changed, 237 insertions(+), 62 deletions(-)
tools/perf/util/exec_cmd.c +57 -7
index 701111a..e7f9ed79 100644
@@ -1,12 +1,17 @@
-#include "cache.h"
-#include "exec_cmd.h"
-#include "quote.h"
-#include "subcmd-config.h"
-
+#include <linux/compiler.h>
+#include <linux/string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
 #include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
 #include "subcmd-util.h"
+#include "exec_cmd.h"
+#include "subcmd-config.h"
 
 #define MAX_ARGS	32
+#define PATH_MAX	4096
 
 static const char *argv_exec_path;
 static const char *argv0_path;
@@ -20,6 +25,49 @@ void exec_cmd_init(const char *exec_name, const char *prefix,
 	subcmd_config.exec_path_env	= exec_path_env;
 }
 
+#define is_dir_sep(c) ((c) == '/')
+
+static int is_absolute_path(const char *path)
+{
+	return path[0] == '/';
+}
+
+static const char *get_pwd_cwd(void)
+{
+	static char cwd[PATH_MAX + 1];
+	char *pwd;
+	struct stat cwd_stat, pwd_stat;
+	if (getcwd(cwd, PATH_MAX) == NULL)
+		return NULL;
+	pwd = getenv("PWD");
+	if (pwd && strcmp(pwd, cwd)) {
+		stat(cwd, &cwd_stat);
+		if (!stat(pwd, &pwd_stat) &&
+		    pwd_stat.st_dev == cwd_stat.st_dev &&
+		    pwd_stat.st_ino == cwd_stat.st_ino) {
+			strlcpy(cwd, pwd, PATH_MAX);
+		}
+	}
+	return cwd;
+}
+
+static const char *make_nonrelative_path(const char *path)
+{
+	static char buf[PATH_MAX + 1];
+
+	if (is_absolute_path(path)) {
+		if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX)
+			die("Too long path: %.*s", 60, path);
+	} else {
+		const char *cwd = get_pwd_cwd();
+		if (!cwd)
+			die("Cannot determine the current working directory");
+		if (snprintf(buf, PATH_MAX, "%s/%s", cwd, path) >= PATH_MAX)
+			die("Too long path: %.*s", 60, path);
+	}
+	return buf;
+}
+
 char *system_path(const char *path)
 {
 	char *buf = NULL;
@@ -151,8 +199,10 @@ int execl_cmd(const char *cmd,...)
 			break;
 	}
 	va_end(param);
-	if (MAX_ARGS <= argc)
-		return error("too many args to run %s", cmd);
+	if (MAX_ARGS <= argc) {
+		fprintf(stderr, " Error: too many args to run %s\n", cmd);
+		return -1;
+	}
 
 	argv[argc] = NULL;
 	return execv_cmd(argv);
tools/perf/util/help.c +42 -5

69 lines not on this page · raw message

tools/perf/util/help.h +3 -1
index 14851b0..096c8bc 100644
@@ -1,12 +1,14 @@
 #ifndef __PERF_HELP_H
 #define __PERF_HELP_H
 
+#include <sys/types.h>
+
 struct cmdnames {
 	size_t alloc;
 	size_t cnt;
 	struct cmdname {
 		size_t len; /* also used for similarity index in help.c */
-		char name[FLEX_ARRAY];
+		char name[];
 	} **names;
 };
 
tools/perf/util/pager.c +6 -1
index d5ef62e..d50f3b5 100644
@@ -1,4 +1,9 @@
-#include "cache.h"
+#include <sys/select.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+#include "pager.h"
 #include "run-command.h"
 #include "sigchain.h"
 #include "subcmd-config.h"
tools/perf/util/parse-options.c +45 -28

130 lines not on this page · raw message

tools/perf/util/parse-options.h +1 -1
index d1544069..dec893f 100644
@@ -1,8 +1,8 @@
 #ifndef __PERF_PARSE_OPTIONS_H
 #define __PERF_PARSE_OPTIONS_H
 
-#include <linux/kernel.h>
 #include <stdbool.h>
+#include <stdint.h>
 
 enum parse_opt_type {
 	/* special types */
tools/perf/util/run-command.c +12 -4
index 910c0f6..fed37d6 100644
@@ -1,7 +1,15 @@
-#include "cache.h"
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/wait.h>
+#include "subcmd-util.h"
 #include "run-command.h"
 #include "exec_cmd.h"
-#include "debug.h"
+
+#define STRERR_BUFSIZE 128
 
 static inline void close_pair(int fd[2])
 {
@@ -164,8 +172,8 @@ static int wait_or_whine(pid_t pid)
 		if (waiting < 0) {
 			if (errno == EINTR)
 				continue;
-			error("waitpid failed (%s)",
-			      strerror_r(errno, sbuf, sizeof(sbuf)));
+			fprintf(stderr, " Error: waitpid failed (%s)",
+				strerror_r(errno, sbuf, sizeof(sbuf)));
 			return -ERR_RUN_COMMAND_WAITPID;
 		}
 		if (waiting != pid)
tools/perf/util/run-command.h +2 -0
index cf7d655..4a55393 100644
@@ -1,6 +1,8 @@
 #ifndef __PERF_RUN_COMMAND_H
 #define __PERF_RUN_COMMAND_H
 
+#include <unistd.h>
+
 enum {
 	ERR_RUN_COMMAND_FORK = 10000,
 	ERR_RUN_COMMAND_EXEC,
tools/perf/util/sigchain.c +2 -1
index ba785e9..3537c34 100644
@@ -1,5 +1,6 @@
+#include <signal.h>
+#include "subcmd-util.h"
 #include "sigchain.h"
-#include "cache.h"
 
 #define SIGCHAIN_MAX_SIGNALS 32
 
tools/perf/util/subcmd-util.h +67 -0

79 lines not on this page · raw message

tools/perf/util/util.h +0 -14
index 150858f..4b519c5 100644
@@ -151,12 +151,6 @@ extern void set_warning_routine(void (*routine)(const char *err, va_list params)
 extern int prefixcmp(const char *str, const char *prefix);
 extern void set_buildid_dir(const char *dir);
 
-static inline const char *skip_prefix(const char *str, const char *prefix)
-{
-	size_t len = strlen(prefix);
-	return strncmp(str, prefix, len) ? NULL : str + len;
-}
-
 #ifdef __GLIBC_PREREQ
 #if __GLIBC_PREREQ(2, 1)
 #define HAVE_STRCHRNUL
@@ -187,14 +181,6 @@ static inline void *zalloc(size_t size)
 
 #define zfree(ptr) ({ free(*ptr); *ptr = NULL; })
 
-static inline int has_extension(const char *filename, const char *ext)
-{
-	size_t len = strlen(filename);
-	size_t extlen = strlen(ext);
-
-	return len > extlen && !memcmp(filename + len - extlen, ext, extlen);
-}
-
 /* Sane ctype - no locale, and works with signed chars */
 #undef isascii
 #undef isspace
#20 lore raw

[tip:perf/core] perf subcmd: Create subcmd library

In reply to Josh Poimboeuf
perf subcmd: Create subcmd library
Commit-ID:  4b6ab94eabe4f55371cff4569750bb3996c55db6
Gitweb:     http://git.kernel.org/tip/4b6ab94eabe4f55371cff4569750bb3996c55db6
Author:     Josh Poimboeuf <[email protected]>
AuthorDate: Tue, 15 Dec 2015 09:39:39 -0600
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 17 Dec 2015 14:27:14 -0300

perf subcmd: Create subcmd library

Move the subcommand-related files from perf to a new library named libsubcmd.a.

Since we're moving files anyway, go ahead and rename 'exec_cmd.*' to 'exec-cmd.*' to be consistent with the naming of all the other files.

---
 tools/lib/subcmd/Build                             |  7 ++++
 tools/lib/subcmd/Makefile                          | 48 ++++++++++++++++++++++
 .../util/exec_cmd.c => lib/subcmd/exec-cmd.c}      |  2 +-
 .../util/exec_cmd.h => lib/subcmd/exec-cmd.h}      |  0
 tools/{perf/util => lib/subcmd}/help.c             |  2 +-
 tools/{perf/util => lib/subcmd}/help.h             |  0
 tools/{perf/util => lib/subcmd}/pager.c            |  0
 tools/{perf/util => lib/subcmd}/pager.h            |  0
 tools/{perf/util => lib/subcmd}/parse-options.c    |  0
 tools/{perf/util => lib/subcmd}/parse-options.h    |  0
 tools/{perf/util => lib/subcmd}/run-command.c      |  2 +-
 tools/{perf/util => lib/subcmd}/run-command.h      |  0
 tools/{perf/util => lib/subcmd}/sigchain.c         |  0
 tools/{perf/util => lib/subcmd}/sigchain.h         |  0
 tools/{perf/util => lib/subcmd}/subcmd-config.c    |  0
 tools/{perf/util => lib/subcmd}/subcmd-config.h    |  0
 tools/{perf/util => lib/subcmd}/subcmd-util.h      |  0
 tools/perf/MANIFEST                                |  1 +
 tools/perf/Makefile.perf                           | 20 +++++++--
 tools/perf/arch/x86/util/intel-pt.c                |  2 +-
 tools/perf/bench/futex-hash.c                      |  2 +-
 tools/perf/bench/futex-lock-pi.c                   |  2 +-
 tools/perf/bench/futex-requeue.c                   |  2 +-
 tools/perf/bench/futex-wake-parallel.c             |  2 +-
 tools/perf/bench/futex-wake.c                      |  2 +-
 tools/perf/bench/mem-functions.c                   |  2 +-
 tools/perf/bench/numa.c                            |  2 +-
 tools/perf/bench/sched-messaging.c                 |  2 +-
 tools/perf/bench/sched-pipe.c                      |  2 +-
 tools/perf/builtin-annotate.c                      |  2 +-
 tools/perf/builtin-bench.c                         |  2 +-
 tools/perf/builtin-buildid-cache.c                 |  2 +-
 tools/perf/builtin-buildid-list.c                  |  2 +-
 tools/perf/builtin-config.c                        |  2 +-
 tools/perf/builtin-data.c                          |  2 +-
 tools/perf/builtin-evlist.c                        |  2 +-
 tools/perf/builtin-help.c                          |  8 ++--
 tools/perf/builtin-inject.c                        |  2 +-
 tools/perf/builtin-kmem.c                          |  2 +-
 tools/perf/builtin-kvm.c                           |  2 +-
 tools/perf/builtin-list.c                          |  2 +-
 tools/perf/builtin-lock.c                          |  2 +-
 tools/perf/builtin-mem.c                           |  2 +-
 tools/perf/builtin-probe.c                         |  2 +-
 tools/perf/builtin-record.c                        |  2 +-
 tools/perf/builtin-report.c                        |  2 +-
 tools/perf/builtin-sched.c                         |  2 +-
 tools/perf/builtin-script.c                        |  4 +-
 tools/perf/builtin-stat.c                          |  2 +-
 tools/perf/builtin-timechart.c                     |  2 +-
 tools/perf/builtin-top.c                           |  2 +-
 tools/perf/builtin-trace.c                         |  4 +-
 tools/perf/perf.c                                  |  6 +--
 tools/perf/tests/attr.c                            |  2 +-
 tools/perf/tests/builtin-test.c                    |  2 +-
 tools/perf/util/Build                              |  7 ----
 tools/perf/util/auxtrace.c                         |  2 +-
 tools/perf/util/cache.h                            |  2 +-
 tools/perf/util/cgroup.c                           |  2 +-
 tools/perf/util/config.c                           |  2 +-
 tools/perf/util/evlist.c                           |  2 +-
 tools/perf/util/help-unknown-cmd.c                 |  2 +-
 tools/perf/util/parse-branch-options.c             |  2 +-
 tools/perf/util/parse-events.c                     |  4 +-
 tools/perf/util/parse-regs-options.c               |  2 +-
 tools/perf/util/sort.h                             |  2 +-
 66 files changed, 129 insertions(+), 68 deletions(-)
tools/lib/subcmd/Build new file +7 -0
new file mode 100644
index 0000000..ee31288
@@ -0,0 +1,7 @@
+libsubcmd-y += exec-cmd.o
+libsubcmd-y += help.o
+libsubcmd-y += pager.o
+libsubcmd-y += parse-options.o
+libsubcmd-y += run-command.o
+libsubcmd-y += sigchain.o
+libsubcmd-y += subcmd-config.o
tools/lib/subcmd/Makefile new file +48 -0

48 lines not on this page · raw message

tools/lib/subcmd/exec-cmd.c renamed from tools/perf/util/exec_cmd.c +1 -1
similarity index 99%
rename from tools/perf/util/exec_cmd.c
rename to tools/lib/subcmd/exec-cmd.c
index e7f9ed79..1ae833a 100644
@@ -7,7 +7,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include "subcmd-util.h"
-#include "exec_cmd.h"
+#include "exec-cmd.h"
 #include "subcmd-config.h"
 
 #define MAX_ARGS	32
tools/lib/subcmd/exec-cmd.h renamed from tools/perf/util/exec_cmd.h +0 -0
similarity index 100%
rename from tools/perf/util/exec_cmd.h
rename to tools/lib/subcmd/exec-cmd.h
tools/lib/subcmd/help.c renamed from tools/perf/util/help.c +1 -1
similarity index 99%
rename from tools/perf/util/help.c
rename to tools/lib/subcmd/help.c
index 8169480..e228c3c 100644
@@ -9,7 +9,7 @@
 #include <dirent.h>
 #include "subcmd-util.h"
 #include "help.h"
-#include "exec_cmd.h"
+#include "exec-cmd.h"
 
 void add_cmdname(struct cmdnames *cmds, const char *name, size_t len)
 {
tools/lib/subcmd/help.h renamed from tools/perf/util/help.h +0 -0
similarity index 100%
rename from tools/perf/util/help.h
rename to tools/lib/subcmd/help.h
tools/lib/subcmd/pager.c renamed from tools/perf/util/pager.c +0 -0
similarity index 100%
rename from tools/perf/util/pager.c
rename to tools/lib/subcmd/pager.c
tools/lib/subcmd/pager.h renamed from tools/perf/util/pager.h +0 -0
similarity index 100%
rename from tools/perf/util/pager.h
rename to tools/lib/subcmd/pager.h
tools/lib/subcmd/parse-options.c renamed from tools/perf/util/parse-options.c +0 -0
similarity index 100%
rename from tools/perf/util/parse-options.c
rename to tools/lib/subcmd/parse-options.c
tools/lib/subcmd/parse-options.h renamed from tools/perf/util/parse-options.h +0 -0
similarity index 100%
rename from tools/perf/util/parse-options.h
rename to tools/lib/subcmd/parse-options.h
tools/lib/subcmd/run-command.c renamed from tools/perf/util/run-command.c +1 -1
similarity index 99%
rename from tools/perf/util/run-command.c
rename to tools/lib/subcmd/run-command.c
index fed37d6..f4f6c9e 100644
@@ -7,7 +7,7 @@
 #include <sys/wait.h>
 #include "subcmd-util.h"
 #include "run-command.h"
-#include "exec_cmd.h"
+#include "exec-cmd.h"
 
 #define STRERR_BUFSIZE 128
 
tools/lib/subcmd/run-command.h renamed from tools/perf/util/run-command.h +0 -0
similarity index 100%
rename from tools/perf/util/run-command.h
rename to tools/lib/subcmd/run-command.h
tools/lib/subcmd/sigchain.c renamed from tools/perf/util/sigchain.c +0 -0
similarity index 100%
rename from tools/perf/util/sigchain.c
rename to tools/lib/subcmd/sigchain.c
tools/lib/subcmd/sigchain.h renamed from tools/perf/util/sigchain.h +0 -0
similarity index 100%
rename from tools/perf/util/sigchain.h
rename to tools/lib/subcmd/sigchain.h
tools/lib/subcmd/subcmd-config.c renamed from tools/perf/util/subcmd-config.c +0 -0
similarity index 100%
rename from tools/perf/util/subcmd-config.c
rename to tools/lib/subcmd/subcmd-config.c
tools/lib/subcmd/subcmd-config.h renamed from tools/perf/util/subcmd-config.h +0 -0
similarity index 100%
rename from tools/perf/util/subcmd-config.h
rename to tools/lib/subcmd/subcmd-config.h
tools/lib/subcmd/subcmd-util.h renamed from tools/perf/util/subcmd-util.h +0 -0
similarity index 100%
rename from tools/perf/util/subcmd-util.h
rename to tools/lib/subcmd/subcmd-util.h
tools/perf/MANIFEST +1 -0
index 2562eac..ce3932e 100644
@@ -20,6 +20,7 @@ tools/lib/traceevent
 tools/lib/bpf
 tools/lib/api
 tools/lib/bpf
+tools/lib/subcmd
 tools/lib/hweight.c
 tools/lib/rbtree.c
 tools/lib/string.c
tools/perf/Makefile.perf +16 -4
index 388ec64..569fcf0 100644
@@ -145,9 +145,10 @@ BISON   = bison
 STRIP   = strip
 AWK     = awk
 
-LIB_DIR          = $(srctree)/tools/lib/api/
+LIB_DIR		= $(srctree)/tools/lib/api/
 TRACE_EVENT_DIR = $(srctree)/tools/lib/traceevent/
-BPF_DIR = $(srctree)/tools/lib/bpf/
+BPF_DIR		= $(srctree)/tools/lib/bpf/
+SUBCMD_DIR	= $(srctree)/tools/lib/subcmd/
 
 # include config/Makefile by default and rule out
 # non-config cases
@@ -184,6 +185,7 @@ strip-libs = $(filter-out -l%,$(1))
 ifneq ($(OUTPUT),)
   TE_PATH=$(OUTPUT)
   BPF_PATH=$(OUTPUT)
+  SUBCMD_PATH=$(OUTPUT)
 ifneq ($(subdir),)
   API_PATH=$(OUTPUT)/../lib/api/
 else
@@ -193,6 +195,7 @@ else
   TE_PATH=$(TRACE_EVENT_DIR)
   API_PATH=$(LIB_DIR)
   BPF_PATH=$(BPF_DIR)
+  SUBCMD_PATH=$(SUBCMD_DIR)
 endif
 
 LIBTRACEEVENT = $(TE_PATH)libtraceevent.a
@@ -206,6 +209,8 @@ export LIBAPI
 
 LIBBPF = $(BPF_PATH)libbpf.a
 
+LIBSUBCMD = $(SUBCMD_PATH)libsubcmd.a
+
 # python extension build directories
 PYTHON_EXTBUILD     := $(OUTPUT)python_ext_build/
 PYTHON_EXTBUILD_LIB := $(PYTHON_EXTBUILD)lib/
@@ -257,7 +262,7 @@ export PERL_PATH
 
 LIB_FILE=$(OUTPUT)libperf.a
 
-PERFLIBS = $(LIB_FILE) $(LIBAPI) $(LIBTRACEEVENT)
+PERFLIBS = $(LIB_FILE) $(LIBAPI) $(LIBTRACEEVENT) $(LIBSUBCMD)
 ifndef NO_LIBBPF
   PERFLIBS += $(LIBBPF)
 endif
@@ -437,6 +442,13 @@ $(LIBBPF)-clean:
 	$(call QUIET_CLEAN, libbpf)
 	$(Q)$(MAKE) -C $(BPF_DIR) O=$(OUTPUT) clean >/dev/null
 
+$(LIBSUBCMD): fixdep FORCE
+	$(Q)$(MAKE) -C $(SUBCMD_DIR) O=$(OUTPUT) $(OUTPUT)libsubcmd.a
+
+$(LIBSUBCMD)-clean:
+	$(call QUIET_CLEAN, libsubcmd)
+	$(Q)$(MAKE) -C $(SUBCMD_DIR) O=$(OUTPUT) clean
+
 help:
 	@echo 'Perf make targets:'
 	@echo '  doc		- make *all* documentation (see below)'
@@ -584,7 +596,7 @@ config-clean:
 	$(call QUIET_CLEAN, config)
 	$(Q)$(MAKE) -C $(srctree)/tools/build/feature/ $(if $(OUTPUT),OUTPUT=$(OUTPUT)feature/,) clean >/dev/null
 
-clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean config-clean
+clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean config-clean
 	$(call QUIET_CLEAN, core-objs)  $(RM) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(LANG_BINDINGS)
 	$(Q)find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
 	$(Q)$(RM) $(OUTPUT).config-detected
tools/perf/arch/x86/util/intel-pt.c +1 -1
index b02af06..b64d462 100644
@@ -26,7 +26,7 @@
 #include "../../util/evlist.h"
 #include "../../util/evsel.h"
 #include "../../util/cpumap.h"
-#include "../../util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "../../util/parse-events.h"
 #include "../../util/pmu.h"
 #include "../../util/debug.h"
tools/perf/bench/futex-hash.c +1 -1
index fc9bebd..0999ac5 100644
@@ -11,7 +11,7 @@
 #include "../perf.h"
 #include "../util/util.h"
 #include "../util/stat.h"
-#include "../util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "../util/header.h"
 #include "bench.h"
 #include "futex.h"
tools/perf/bench/futex-lock-pi.c +1 -1
index bc6a16a..6a18ce2 100644
@@ -5,7 +5,7 @@
 #include "../perf.h"
 #include "../util/util.h"
 #include "../util/stat.h"
-#include "../util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "../util/header.h"
 #include "bench.h"
 #include "futex.h"
tools/perf/bench/futex-requeue.c +1 -1
index ad0d9b5..7182386 100644
@@ -11,7 +11,7 @@
 #include "../perf.h"
 #include "../util/util.h"
 #include "../util/stat.h"
-#include "../util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "../util/header.h"
 #include "bench.h"
 #include "futex.h"
tools/perf/bench/futex-wake-parallel.c +1 -1
index 6d8c9fa..91aaf2a 100644
@@ -10,7 +10,7 @@
 #include "../perf.h"
 #include "../util/util.h"
 #include "../util/stat.h"
-#include "../util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "../util/header.h"
 #include "bench.h"
 #include "futex.h"
tools/perf/bench/futex-wake.c +1 -1
index e5e41d3..f416bd7 100644
@@ -11,7 +11,7 @@
 #include "../perf.h"
 #include "../util/util.h"
 #include "../util/stat.h"
-#include "../util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "../util/header.h"
 #include "bench.h"
 #include "futex.h"
tools/perf/bench/mem-functions.c +1 -1
index 9419b94..a91aa85 100644
@@ -8,7 +8,7 @@
 
 #include "../perf.h"
 #include "../util/util.h"
-#include "../util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "../util/header.h"
 #include "../util/cloexec.h"
 #include "bench.h"
tools/perf/bench/numa.c +1 -1
index 492df27..5049d63 100644
@@ -7,7 +7,7 @@
 #include "../perf.h"
 #include "../builtin.h"
 #include "../util/util.h"
-#include "../util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "../util/cloexec.h"
 
 #include "bench.h"
tools/perf/bench/sched-messaging.c +1 -1
index d4ff1b5..bfaf950 100644
@@ -11,7 +11,7 @@
 
 #include "../perf.h"
 #include "../util/util.h"
-#include "../util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "../builtin.h"
 #include "bench.h"
 
tools/perf/bench/sched-pipe.c +1 -1
index 005cc28..1dc2d13 100644
@@ -10,7 +10,7 @@
  */
 #include "../perf.h"
 #include "../util/util.h"
-#include "../util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "../builtin.h"
 #include "bench.h"
 
tools/perf/builtin-annotate.c +1 -1
index 1f00dc7..e18f1b9 100644
@@ -21,7 +21,7 @@
 #include "util/evsel.h"
 #include "util/annotate.h"
 #include "util/event.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/parse-events.h"
 #include "util/thread.h"
 #include "util/sort.h"
tools/perf/builtin-bench.c +1 -1
index b17aed3..a1cddc6 100644
@@ -16,7 +16,7 @@
  */
 #include "perf.h"
 #include "util/util.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "builtin.h"
 #include "bench/bench.h"
 
tools/perf/builtin-buildid-cache.c +1 -1
index 7b8450c..d93bff7 100644
@@ -16,7 +16,7 @@
 #include "util/cache.h"
 #include "util/debug.h"
 #include "util/header.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/strlist.h"
 #include "util/build-id.h"
 #include "util/session.h"
tools/perf/builtin-buildid-list.c +1 -1
index 6419f57..5e914ee 100644
@@ -12,7 +12,7 @@
 #include "util/build-id.h"
 #include "util/cache.h"
 #include "util/debug.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/session.h"
 #include "util/symbol.h"
 #include "util/data.h"
tools/perf/builtin-config.c +1 -1
index 427ea7a..f04e804 100644
@@ -9,7 +9,7 @@
 #include "perf.h"
 
 #include "util/cache.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/util.h"
 #include "util/debug.h"
 
tools/perf/builtin-data.c +1 -1
index d6525bc..b97bc15 100644
@@ -2,7 +2,7 @@
 #include "builtin.h"
 #include "perf.h"
 #include "debug.h"
-#include "parse-options.h"
+#include <subcmd/parse-options.h>
 #include "data-convert-bt.h"
 
 typedef int (*data_cmd_fn_t)(int argc, const char **argv, const char *prefix);
tools/perf/builtin-evlist.c +1 -1
index f4d6251..08a7d36 100644
@@ -12,7 +12,7 @@
 #include "util/evlist.h"
 #include "util/evsel.h"
 #include "util/parse-events.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/session.h"
 #include "util/data.h"
 #include "util/debug.h"
tools/perf/builtin-help.c +4 -4
index 275aa64..96c1a4c 100644
@@ -6,11 +6,11 @@
 #include "perf.h"
 #include "util/cache.h"
 #include "builtin.h"
-#include "util/exec_cmd.h"
+#include <subcmd/exec-cmd.h>
 #include "common-cmds.h"
-#include "util/parse-options.h"
-#include "util/run-command.h"
-#include "util/help.h"
+#include <subcmd/parse-options.h>
+#include <subcmd/run-command.h>
+#include <subcmd/help.h>
 #include "util/debug.h"
 
 static struct man_viewer_list {
tools/perf/builtin-inject.c +1 -1
index 99d127f..0022e02 100644
@@ -18,7 +18,7 @@
 #include "util/data.h"
 #include "util/auxtrace.h"
 
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 
 #include <linux/list.h>
 
tools/perf/builtin-kmem.c +1 -1
index 93ce665..1180105 100644
@@ -12,7 +12,7 @@
 #include "util/tool.h"
 #include "util/callchain.h"
 
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/trace-event.h"
 #include "util/data.h"
 #include "util/cpumap.h"
tools/perf/builtin-kvm.c +1 -1
index 031f9f5..4418d92 100644
@@ -10,7 +10,7 @@
 #include "util/header.h"
 #include "util/session.h"
 #include "util/intlist.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/trace-event.h"
 #include "util/debug.h"
 #include "util/tool.h"
tools/perf/builtin-list.c +1 -1
index bf679e2..5e22db4 100644
@@ -14,7 +14,7 @@
 #include "util/parse-events.h"
 #include "util/cache.h"
 #include "util/pmu.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 
 int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
 {
tools/perf/builtin-lock.c +1 -1
index de16aae..ce3bfb4 100644
@@ -9,7 +9,7 @@
 #include "util/thread.h"
 #include "util/header.h"
 
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/trace-event.h"
 
 #include "util/debug.h"
tools/perf/builtin-mem.c +1 -1
index 80170aa..3901700 100644
@@ -1,7 +1,7 @@
 #include "builtin.h"
 #include "perf.h"
 
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/trace-event.h"
 #include "util/tool.h"
 #include "util/session.h"
tools/perf/builtin-probe.c +1 -1
index dbe2ea5..9af859b 100644
@@ -37,7 +37,7 @@
 #include "util/strfilter.h"
 #include "util/symbol.h"
 #include "util/debug.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/probe-finder.h"
 #include "util/probe-event.h"
 #include "util/probe-file.h"
tools/perf/builtin-record.c +1 -1
index a3b4930..1435ef6 100644
@@ -11,7 +11,7 @@
 
 #include "util/build-id.h"
 #include "util/util.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/parse-events.h"
 
 #include "util/callchain.h"
tools/perf/builtin-report.c +1 -1
index 5a45466..2a7330b 100644
@@ -27,7 +27,7 @@
 #include "util/session.h"
 #include "util/tool.h"
 
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/parse-events.h"
 
 #include "util/thread.h"
tools/perf/builtin-sched.c +1 -1
index e3d3e32..871b55ae 100644
@@ -12,7 +12,7 @@
 #include "util/tool.h"
 #include "util/cloexec.h"
 
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/trace-event.h"
 
 #include "util/debug.h"
tools/perf/builtin-script.c +2 -2
index 571016f..bcc3542 100644
@@ -3,9 +3,9 @@
 #include "perf.h"
 #include "util/cache.h"
 #include "util/debug.h"
-#include "util/exec_cmd.h"
+#include <subcmd/exec-cmd.h>
 #include "util/header.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/perf_regs.h"
 #include "util/session.h"
 #include "util/tool.h"
tools/perf/builtin-stat.c +1 -1
index 25a95f4..bbf42ee 100644
@@ -45,7 +45,7 @@
 #include "builtin.h"
 #include "util/cgroup.h"
 #include "util/util.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/parse-events.h"
 #include "util/pmu.h"
 #include "util/event.h"
tools/perf/builtin-timechart.c +1 -1
index 30e5962..bd7a775 100644
@@ -30,7 +30,7 @@
 
 #include "perf.h"
 #include "util/header.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/parse-events.h"
 #include "util/event.h"
 #include "util/session.h"
tools/perf/builtin-top.c +1 -1
index 92fe963..9ebd67a 100644
@@ -34,7 +34,7 @@
 #include "util/top.h"
 #include "util/util.h"
 #include <linux/rbtree.h>
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/parse-events.h"
 #include "util/cpumap.h"
 #include "util/xyarray.h"
tools/perf/builtin-trace.c +2 -2
index c783d8f..20916dd 100644
@@ -22,11 +22,11 @@
 #include "util/color.h"
 #include "util/debug.h"
 #include "util/evlist.h"
-#include "util/exec_cmd.h"
+#include <subcmd/exec-cmd.h>
 #include "util/machine.h"
 #include "util/session.h"
 #include "util/thread.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/strlist.h"
 #include "util/intlist.h"
 #include "util/thread_map.h"
tools/perf/perf.c +3 -3
index 6894325..cb1d249 100644
@@ -9,12 +9,12 @@
 #include "builtin.h"
 
 #include "util/env.h"
-#include "util/exec_cmd.h"
+#include <subcmd/exec-cmd.h>
 #include "util/cache.h"
 #include "util/quote.h"
-#include "util/run-command.h"
+#include <subcmd/run-command.h>
 #include "util/parse-events.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/bpf-loader.h"
 #include "util/debug.h"
 #include <api/fs/tracing_path.h>
tools/perf/tests/attr.c +1 -1
index 6337f1c..28d1605 100644
@@ -24,7 +24,7 @@
 #include <linux/kernel.h>
 #include "../perf.h"
 #include "util.h"
-#include "exec_cmd.h"
+#include <subcmd/exec-cmd.h>
 #include "tests.h"
 
 #define ENV "PERF_TEST_ATTR"
tools/perf/tests/builtin-test.c +1 -1
index fa98406..0372d59 100644
@@ -11,7 +11,7 @@
 #include "tests.h"
 #include "debug.h"
 #include "color.h"
-#include "parse-options.h"
+#include <subcmd/parse-options.h>
 #include "symbol.h"
 
 struct test __weak arch_tests[] = {
tools/perf/util/Build +0 -7
index 196beef..94b1099 100644
@@ -9,13 +9,10 @@ libperf-y += env.o
 libperf-y += event.o
 libperf-y += evlist.o
 libperf-y += evsel.o
-libperf-y += exec_cmd.o
 libperf-y += find_next_bit.o
-libperf-y += help.o
 libperf-y += kallsyms.o
 libperf-y += levenshtein.o
 libperf-y += llvm-utils.o
-libperf-y += parse-options.o
 libperf-y += parse-events.o
 libperf-y += perf_regs.o
 libperf-y += path.o
@@ -23,7 +20,6 @@ libperf-y += rbtree.o
 libperf-y += libstring.o
 libperf-y += bitmap.o
 libperf-y += hweight.o
-libperf-y += run-command.o
 libperf-y += quote.o
 libperf-y += strbuf.o
 libperf-y += string.o
@@ -32,11 +28,9 @@ libperf-y += strfilter.o
 libperf-y += top.o
 libperf-y += usage.o
 libperf-y += wrapper.o
-libperf-y += sigchain.o
 libperf-y += dso.o
 libperf-y += symbol.o
 libperf-y += color.o
-libperf-y += pager.o
 libperf-y += header.o
 libperf-y += callchain.o
 libperf-y += values.o
@@ -88,7 +82,6 @@ libperf-y += parse-branch-options.o
 libperf-y += parse-regs-options.o
 libperf-y += term.o
 libperf-y += help-unknown-cmd.o
-libperf-y += subcmd-config.o
 
 libperf-$(CONFIG_LIBBPF) += bpf-loader.o
 libperf-$(CONFIG_BPF_PROLOGUE) += bpf-prologue.o
tools/perf/util/auxtrace.c +1 -1
index 7f10430..360fda0 100644
@@ -45,7 +45,7 @@
 #include "event.h"
 #include "session.h"
 #include "debug.h"
-#include "parse-options.h"
+#include <subcmd/parse-options.h>
 
 #include "intel-pt.h"
 #include "intel-bts.h"
tools/perf/util/cache.h +1 -1
index fc6a745..07b5d63 100644
@@ -4,7 +4,7 @@
 #include <stdbool.h>
 #include "util.h"
 #include "strbuf.h"
-#include "pager.h"
+#include <subcmd/pager.h>
 #include "../perf.h"
 #include "../ui/ui.h"
 
tools/perf/util/cgroup.c +1 -1
index 32e12ec..90aa1b4 100644
@@ -1,6 +1,6 @@
 #include "util.h"
 #include "../perf.h"
-#include "parse-options.h"
+#include <subcmd/parse-options.h>
 #include "evsel.h"
 #include "cgroup.h"
 #include "evlist.h"
tools/perf/util/config.c +1 -1
index 2e452ac..d3e12e3 100644
@@ -10,7 +10,7 @@
  */
 #include "util.h"
 #include "cache.h"
-#include "exec_cmd.h"
+#include <subcmd/exec-cmd.h>
 #include "util/hist.h"  /* perf_hist_config */
 #include "util/llvm-utils.h"   /* perf_llvm_config */
 
tools/perf/util/evlist.c +1 -1
index d1b6c20..8c44aad 100644
@@ -18,7 +18,7 @@
 #include <unistd.h>
 
 #include "parse-events.h"
-#include "parse-options.h"
+#include <subcmd/parse-options.h>
 
 #include <sys/mman.h>
 
tools/perf/util/help-unknown-cmd.c +1 -1
index a0820f1..dc1e41c 100644
@@ -1,5 +1,5 @@
 #include "cache.h"
-#include "help.h"
+#include <subcmd/help.h>
 #include "../builtin.h"
 #include "levenshtein.h"
 
tools/perf/util/parse-branch-options.c +1 -1
index 355eecf..afc088d 100644
@@ -1,7 +1,7 @@
 #include "perf.h"
 #include "util/util.h"
 #include "util/debug.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/parse-branch-options.h"
 
 #define BRANCH_OPT(n, m) \
tools/perf/util/parse-events.c +2 -2
index 6fc8cd7..4f7b0ef 100644
@@ -4,9 +4,9 @@
 #include "../perf.h"
 #include "evlist.h"
 #include "evsel.h"
-#include "parse-options.h"
+#include <subcmd/parse-options.h>
 #include "parse-events.h"
-#include "exec_cmd.h"
+#include <subcmd/exec-cmd.h>
 #include "string.h"
 #include "symbol.h"
 #include "cache.h"
tools/perf/util/parse-regs-options.c +1 -1
index 4f2c1c2..646ecf7 100644
@@ -1,7 +1,7 @@
 #include "perf.h"
 #include "util/util.h"
 #include "util/debug.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/parse-regs-options.h"
 
 int
tools/perf/util/sort.h +1 -1
index 3122885..86f05e7 100644
@@ -18,7 +18,7 @@
 #include "debug.h"
 #include "header.h"
 
-#include "parse-options.h"
+#include <subcmd/parse-options.h>
 #include "parse-events.h"
 #include "hist.h"
 #include "thread.h"
#22 lore raw

[tip:perf/core] tools subcmd: Rename subcmd header include guards

In reply to Josh Poimboeuf
tools subcmd: Rename subcmd header include guards
Commit-ID:  1843b4e057b7717db21a3ad96fa16d6b4ee8f6c4
Gitweb:     http://git.kernel.org/tip/1843b4e057b7717db21a3ad96fa16d6b4ee8f6c4
Author:     Josh Poimboeuf <[email protected]>
AuthorDate: Tue, 15 Dec 2015 09:39:40 -0600
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 17 Dec 2015 14:27:14 -0300

tools subcmd: Rename subcmd header include guards

---
 tools/lib/subcmd/exec-cmd.h      | 6 +++---
 tools/lib/subcmd/help.h          | 6 +++---
 tools/lib/subcmd/pager.h         | 6 +++---
 tools/lib/subcmd/parse-options.h | 7 ++++---
 tools/lib/subcmd/run-command.h   | 6 +++---
 tools/lib/subcmd/sigchain.h      | 6 +++---
 tools/lib/subcmd/subcmd-util.h   | 6 +++---
 7 files changed, 22 insertions(+), 21 deletions(-)
tools/lib/subcmd/exec-cmd.h +3 -3
index f1bd343..5d08bda 100644
@@ -1,5 +1,5 @@
-#ifndef __PERF_EXEC_CMD_H
-#define __PERF_EXEC_CMD_H
+#ifndef __SUBCMD_EXEC_CMD_H
+#define __SUBCMD_EXEC_CMD_H
 
 extern void exec_cmd_init(const char *exec_name, const char *prefix,
 			  const char *exec_path, const char *exec_path_env);
@@ -13,4 +13,4 @@ extern int execl_cmd(const char *cmd, ...);
 extern char *get_argv_exec_path(void);
 extern char *system_path(const char *path);
 
-#endif /* __PERF_EXEC_CMD_H */
+#endif /* __SUBCMD_EXEC_CMD_H */
tools/lib/subcmd/help.h +3 -3
index 096c8bc..e145a02 100644
@@ -1,5 +1,5 @@
-#ifndef __PERF_HELP_H
-#define __PERF_HELP_H
+#ifndef __SUBCMD_HELP_H
+#define __SUBCMD_HELP_H
 
 #include <sys/types.h>
 
@@ -31,4 +31,4 @@ int is_in_cmdlist(struct cmdnames *c, const char *s);
 void list_commands(const char *title, struct cmdnames *main_cmds,
 		   struct cmdnames *other_cmds);
 
-#endif /* __PERF_HELP_H */
+#endif /* __SUBCMD_HELP_H */
tools/lib/subcmd/pager.h +3 -3
index d6a591a..8b83714 100644
@@ -1,9 +1,9 @@
-#ifndef __PERF_PAGER_H
-#define __PERF_PAGER_H
+#ifndef __SUBCMD_PAGER_H
+#define __SUBCMD_PAGER_H
 
 extern void pager_init(const char *pager_env);
 
 extern void setup_pager(void);
 extern int pager_in_use(void);
 
-#endif /* __PERF_PAGER_H */
+#endif /* __SUBCMD_PAGER_H */
tools/lib/subcmd/parse-options.h +4 -3
index dec893f..13a2cc1 100644
@@ -1,5 +1,5 @@
-#ifndef __PERF_PARSE_OPTIONS_H
-#define __PERF_PARSE_OPTIONS_H
+#ifndef __SUBCMD_PARSE_OPTIONS_H
+#define __SUBCMD_PARSE_OPTIONS_H
 
 #include <stdbool.h>
 #include <stdint.h>
@@ -225,4 +225,5 @@ extern const char *parse_options_fix_filename(const char *prefix, const char *fi
 void set_option_flag(struct option *opts, int sopt, const char *lopt, int flag);
 void set_option_nobuild(struct option *opts, int shortopt, const char *longopt,
 			const char *build_opt, bool can_skip);
-#endif /* __PERF_PARSE_OPTIONS_H */
+
+#endif /* __SUBCMD_PARSE_OPTIONS_H */
tools/lib/subcmd/run-command.h +3 -3
index 4a55393..fe2befe 100644
@@ -1,5 +1,5 @@
-#ifndef __PERF_RUN_COMMAND_H
-#define __PERF_RUN_COMMAND_H
+#ifndef __SUBCMD_RUN_COMMAND_H
+#define __SUBCMD_RUN_COMMAND_H
 
 #include <unistd.h>
 
@@ -57,4 +57,4 @@ int run_command(struct child_process *);
 #define RUN_COMMAND_STDOUT_TO_STDERR 4
 int run_command_v_opt(const char **argv, int opt);
 
-#endif /* __PERF_RUN_COMMAND_H */
+#endif /* __SUBCMD_RUN_COMMAND_H */
tools/lib/subcmd/sigchain.h +3 -3
index 959d64e..0c919f2 100644
@@ -1,5 +1,5 @@
-#ifndef __PERF_SIGCHAIN_H
-#define __PERF_SIGCHAIN_H
+#ifndef __SUBCMD_SIGCHAIN_H
+#define __SUBCMD_SIGCHAIN_H
 
 typedef void (*sigchain_fun)(int);
 
@@ -7,4 +7,4 @@ int sigchain_pop(int sig);
 
 void sigchain_push_common(sigchain_fun f);
 
-#endif /* __PERF_SIGCHAIN_H */
+#endif /* __SUBCMD_SIGCHAIN_H */
tools/lib/subcmd/subcmd-util.h +3 -3
index 321aeb1..fc2e45d 100644
@@ -1,5 +1,5 @@
-#ifndef __PERF_SUBCMD_UTIL_H
-#define __PERF_SUBCMD_UTIL_H
+#ifndef __SUBCMD_UTIL_H
+#define __SUBCMD_UTIL_H
 
 #include <stdarg.h>
 #include <stdlib.h>
@@ -88,4 +88,4 @@ static inline int prefixcmp(const char *str, const char *prefix)
 			return (unsigned char)*prefix - (unsigned char)*str;
 }
 
-#endif /* __PERF_SUBCMD_UTIL_H */
+#endif /* __SUBCMD_UTIL_H */