On Mon, Dec 07, 2015 at 10:21:52PM -0600, Josh Poimboeuf wrote: > The perf subcommand framework is needed for other tools. Move > parse-options.c and its dependencies over to libapi. > > Any function names with 'perf' have been renamed to something more > generic. > > Also created a util_cfg struct for passing perf-specific configuration > to the library. Specifying the configuration at runtime allows the same > binary to be shared by multiple tools without having to recompile it.
this patch is too big.. IMO it needs to be split into 3 parts as described in above 3 paragraphs thanks, jirka > > Signed-off-by: Josh Poimboeuf <jpoim...@redhat.com> > --- > tools/include/asm-generic/bitops/__fls.h | 2 +- > tools/include/asm-generic/bitops/fls.h | 2 +- > tools/include/asm-generic/bitops/fls64.h | 2 +- > tools/lib/api/Build | 1 + > tools/lib/api/Makefile | 6 +++- > tools/lib/api/util/Build | 13 +++++++++ > tools/{perf => lib/api}/util/abspath.c | 6 +++- > tools/{perf => lib/api}/util/abspath.h | 6 ++-- > tools/lib/api/util/cfg.c | 12 ++++++++ > tools/lib/api/util/cfg.h | 15 ++++++++++ > tools/{perf => lib/api}/util/compat-util.h | 7 ++--- > tools/{perf => lib/api}/util/ctype.c | 3 +- > tools/{perf => lib/api}/util/ctype.h | 6 ++-- > tools/{perf => lib/api}/util/exec_cmd.c | 42 > ++++++++++++++-------------- > tools/{perf => lib/api}/util/exec_cmd.h | 18 ++++++------ > tools/{perf => lib/api}/util/help.c | 11 +++++--- > tools/{perf => lib/api}/util/help.h | 0 > tools/{perf => lib/api}/util/pager.c | 6 ++-- > tools/{perf => lib/api}/util/pager.h | 6 ++-- > tools/{perf => lib/api}/util/parse-options.c | 21 ++++++++++---- > tools/{perf => lib/api}/util/parse-options.h | 10 +++---- > tools/{perf => lib/api}/util/run-command.c | 12 ++++---- > tools/{perf => lib/api}/util/run-command.h | 10 +++---- > tools/{perf => lib/api}/util/sigchain.c | 4 ++- > tools/{perf => lib/api}/util/sigchain.h | 6 ++-- > tools/{perf => lib/api}/util/strbuf.c | 6 +++- > tools/{perf => lib/api}/util/strbuf.h | 6 ++-- > tools/{perf => lib/api}/util/term.c | 3 +- > tools/{perf => lib/api}/util/term.h | 0 > tools/{perf => lib/api}/util/usage.c | 4 +-- > tools/{perf => lib/api}/util/usage.h | 8 +++--- > tools/{perf => lib/api}/util/wrapper.c | 4 ++- > tools/{perf => lib/api}/util/wrapper.h | 6 ++-- > tools/perf/Build | 2 +- > 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 | 9 +++--- > 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/builtin.h | 2 +- > tools/perf/perf.c | 27 +++++++++++++----- > tools/perf/perf.h | 1 + > tools/perf/tests/attr.c | 4 +-- > tools/perf/tests/builtin-test.c | 2 +- > tools/perf/ui/setup.c | 5 ++++ > tools/perf/ui/ui.h | 1 + > tools/perf/util/Build | 13 --------- > tools/perf/util/auxtrace.c | 2 +- > tools/perf/util/cgroup.c | 2 +- > tools/perf/util/config.c | 2 +- > tools/perf/util/evlist.c | 2 +- > tools/perf/util/header.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/python-ext-sources | 1 - > tools/perf/util/sort.h | 2 +- > tools/perf/util/util.h | 19 +++++++------ > 87 files changed, 265 insertions(+), 183 deletions(-) > create mode 100644 tools/lib/api/util/Build > rename tools/{perf => lib/api}/util/abspath.c (90%) > rename tools/{perf => lib/api}/util/abspath.h (59%) > create mode 100644 tools/lib/api/util/cfg.c > create mode 100644 tools/lib/api/util/cfg.h > rename tools/{perf => lib/api}/util/compat-util.h (95%) > rename tools/{perf => lib/api}/util/ctype.c (97%) > rename tools/{perf => lib/api}/util/ctype.h (93%) > rename tools/{perf => lib/api}/util/exec_cmd.c (72%) > rename tools/{perf => lib/api}/util/exec_cmd.h (14%) > rename tools/{perf => lib/api}/util/help.c (96%) > rename tools/{perf => lib/api}/util/help.h (100%) > rename tools/{perf => lib/api}/util/pager.c (93%) > rename tools/{perf => lib/api}/util/pager.h (42%) > rename tools/{perf => lib/api}/util/parse-options.c (98%) > rename tools/{perf => lib/api}/util/parse-options.h (98%) > rename tools/{perf => lib/api}/util/run-command.c (96%) > rename tools/{perf => lib/api}/util/run-command.h (87%) > rename tools/{perf => lib/api}/util/sigchain.c (93%) > rename tools/{perf => lib/api}/util/sigchain.h (53%) > rename tools/{perf => lib/api}/util/strbuf.c (97%) > rename tools/{perf => lib/api}/util/strbuf.h (97%) > rename tools/{perf => lib/api}/util/term.c (93%) > rename tools/{perf => lib/api}/util/term.h (100%) > rename tools/{perf => lib/api}/util/usage.c (97%) > rename tools/{perf => lib/api}/util/usage.h (84%) > rename tools/{perf => lib/api}/util/wrapper.c (92%) > rename tools/{perf => lib/api}/util/wrapper.h (89%) > > diff --git a/tools/include/asm-generic/bitops/__fls.h > b/tools/include/asm-generic/bitops/__fls.h > index 2218b9a..494c9c6 100644 > --- a/tools/include/asm-generic/bitops/__fls.h > +++ b/tools/include/asm-generic/bitops/__fls.h > @@ -1 +1 @@ > -#include <../../../../include/asm-generic/bitops/__fls.h> > +#include "../../../../include/asm-generic/bitops/__fls.h" > diff --git a/tools/include/asm-generic/bitops/fls.h > b/tools/include/asm-generic/bitops/fls.h > index dbf711a..0e4995f 100644 > --- a/tools/include/asm-generic/bitops/fls.h > +++ b/tools/include/asm-generic/bitops/fls.h > @@ -1 +1 @@ > -#include <../../../../include/asm-generic/bitops/fls.h> > +#include "../../../../include/asm-generic/bitops/fls.h" > diff --git a/tools/include/asm-generic/bitops/fls64.h > b/tools/include/asm-generic/bitops/fls64.h > index 980b1f6..35bee00 100644 > --- a/tools/include/asm-generic/bitops/fls64.h > +++ b/tools/include/asm-generic/bitops/fls64.h > @@ -1 +1 @@ > -#include <../../../../include/asm-generic/bitops/fls64.h> > +#include "../../../../include/asm-generic/bitops/fls64.h" > diff --git a/tools/lib/api/Build b/tools/lib/api/Build > index 9e3967e..6ad3ac2 100644 > --- a/tools/lib/api/Build > +++ b/tools/lib/api/Build > @@ -2,3 +2,4 @@ libapi-y += fd/ > libapi-y += fs/ > libapi-y += cpu.o > libapi-y += string/ > +libapi-y += util/ > diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile > index d85904d..ad896c2 100644 > --- a/tools/lib/api/Makefile > +++ b/tools/lib/api/Makefile > @@ -17,7 +17,11 @@ LIBFILE = $(OUTPUT)libapi.a > > CFLAGS := $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) > CFLAGS += -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE > -D_FORTIFY_SOURCE=2 -fPIC > -CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 > +CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE > + > +CFLAGS += -I$(srctree)/tools/include/ > +CFLAGS += -I$(srctree)/include/uapi > +CFLAGS += -I$(srctree)/include > > RM = rm -f > > diff --git a/tools/lib/api/util/Build b/tools/lib/api/util/Build > new file mode 100644 > index 0000000..6f95278 > --- /dev/null > +++ b/tools/lib/api/util/Build > @@ -0,0 +1,13 @@ > +libapi-y += abspath.o > +libapi-y += cfg.o > +libapi-y += ctype.o > +libapi-y += exec_cmd.o > +libapi-y += help.o > +libapi-y += pager.o > +libapi-y += parse-options.o > +libapi-y += run-command.o > +libapi-y += sigchain.o > +libapi-y += strbuf.o > +libapi-y += term.o > +libapi-y += usage.o > +libapi-y += wrapper.o > diff --git a/tools/perf/util/abspath.c b/tools/lib/api/util/abspath.c > similarity index 90% > rename from tools/perf/util/abspath.c > rename to tools/lib/api/util/abspath.c > index eab5d85..9827a3f 100644 > --- a/tools/perf/util/abspath.c > +++ b/tools/lib/api/util/abspath.c > @@ -1,4 +1,8 @@ > -#include "util.h" > +#include "compat-util.h" > + > +#include "../string/string.h" > +#include "abspath.h" > +#include "usage.h" > > static const char *get_pwd_cwd(void) > { > diff --git a/tools/perf/util/abspath.h b/tools/lib/api/util/abspath.h > similarity index 59% > rename from tools/perf/util/abspath.h > rename to tools/lib/api/util/abspath.h > index 13549fb..fa5d82a 100644 > --- a/tools/perf/util/abspath.h > +++ b/tools/lib/api/util/abspath.h > @@ -1,5 +1,5 @@ > -#ifndef __PERF_ABSPATH_H > -#define __PERF_ABSPATH_H > +#ifndef __API_UTIL_ABSPATH_H > +#define __API_UTIL_ABSPATH_H > > static inline int is_absolute_path(const char *path) > { > @@ -8,4 +8,4 @@ static inline int is_absolute_path(const char *path) > > const char *make_nonrelative_path(const char *path); > > -#endif /* __PERF_ABSPATH_H */ > +#endif /* __API_UTIL_ABSPATH_H */ > diff --git a/tools/lib/api/util/cfg.c b/tools/lib/api/util/cfg.c > new file mode 100644 > index 0000000..40653dc > --- /dev/null > +++ b/tools/lib/api/util/cfg.c > @@ -0,0 +1,12 @@ > +#include "compat-util.h" > +#include "cfg.h" > + > +#define UNDEFINED "UNDEFINED" > + > +struct util_cfg util_cfg = { > + .prefix = UNDEFINED, > + .exec_name = UNDEFINED, > + .exec_path = UNDEFINED, > + .exec_path_env = UNDEFINED, > + .pager_env = UNDEFINED, > +}; > diff --git a/tools/lib/api/util/cfg.h b/tools/lib/api/util/cfg.h > new file mode 100644 > index 0000000..f271732 > --- /dev/null > +++ b/tools/lib/api/util/cfg.h > @@ -0,0 +1,15 @@ > +#ifndef __API_UTIL_CONFIG_H > +#define __API_UTIL_CONFIG_H > + > +struct util_cfg { > + const char *prefix; > + const char *exec_name; > + const char *exec_path; > + const char *exec_path_env; > + const char *pager_env; > + void (*exit_browser)(void); > +}; > + > +extern struct util_cfg util_cfg; > + > +#endif /* #define __API_UTIL_CONFIG_H */ > diff --git a/tools/perf/util/compat-util.h b/tools/lib/api/util/compat-util.h > similarity index 95% > rename from tools/perf/util/compat-util.h > rename to tools/lib/api/util/compat-util.h > index f472a98..ab2b257 100644 > --- a/tools/perf/util/compat-util.h > +++ b/tools/lib/api/util/compat-util.h > @@ -1,5 +1,5 @@ > -#ifndef __PERF_COMPAT_UTIL_H > -#define __PERF_COMPAT_UTIL_H > +#ifndef __API_UTIL_COMPAT_UTIL_H > +#define __API_UTIL_COMPAT_UTIL_H > > #ifndef FLEX_ARRAY > /* > @@ -74,7 +74,6 @@ > #include <linux/magic.h> > #include <linux/types.h> > #include <sys/ttydefaults.h> > -#include <api/fs/tracing_path.h> > #include <termios.h> > #include <linux/bitops.h> > #include <termios.h> > @@ -127,4 +126,4 @@ > #define NSEC_PER_MSEC 1000000L > #endif > > -#endif /* __PERF_COMPAT_UTIL_H */ > +#endif /* __API_UTIL_COMPAT_UTIL_H */ > diff --git a/tools/perf/util/ctype.c b/tools/lib/api/util/ctype.c > similarity index 97% > rename from tools/perf/util/ctype.c > rename to tools/lib/api/util/ctype.c > index aada3ac..a7b2d33 100644 > --- a/tools/perf/util/ctype.c > +++ b/tools/lib/api/util/ctype.c > @@ -3,7 +3,8 @@ > * > * No surprises, and works with signed and unsigned chars. > */ > -#include "util.h" > +#include "compat-util.h" > +#include "ctype.h" > > enum { > S = GIT_SPACE, > diff --git a/tools/perf/util/ctype.h b/tools/lib/api/util/ctype.h > similarity index 93% > rename from tools/perf/util/ctype.h > rename to tools/lib/api/util/ctype.h > index b66bfeb..1be5f8d 100644 > --- a/tools/perf/util/ctype.h > +++ b/tools/lib/api/util/ctype.h > @@ -1,5 +1,5 @@ > -#ifndef __PERF_CTYPE_H > -#define __PERF_CTYPE_H > +#ifndef __API_UTIL_CTYPE_H > +#define __API_UTIL_CTYPE_H > > /* Sane ctype - no locale, and works with signed chars */ > #undef isascii > @@ -49,4 +49,4 @@ static inline int sane_case(int x, int high) > return x; > } > > -#endif /* __PERF_CTYPE_H */ > +#endif /* __API_UTIL_CTYPE_H */ > diff --git a/tools/perf/util/exec_cmd.c b/tools/lib/api/util/exec_cmd.c > similarity index 72% > rename from tools/perf/util/exec_cmd.c > rename to tools/lib/api/util/exec_cmd.c > index 8d5661e..7466924 100644 > --- a/tools/perf/util/exec_cmd.c > +++ b/tools/lib/api/util/exec_cmd.c > @@ -1,8 +1,9 @@ > -#include "util.h" > +#include "compat-util.h" > #include "exec_cmd.h" > -#include "quote.h" > - > -#include <string.h> > +#include "strbuf.h" > +#include "abspath.h" > +#include "usage.h" > +#include "cfg.h" > > #define MAX_ARGS 32 > > @@ -11,18 +12,17 @@ static const char *argv0_path; > > 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", util_cfg.prefix, path); > path = strbuf_detach(&d, NULL); > return (char *)path; > } > > -const char *perf_extract_argv0_path(const char *argv0) > +const char *extract_argv0_path(const char *argv0) > { > const char *slash; > > @@ -41,29 +41,29 @@ 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; > /* > * Propagate this setting to external programs. > */ > - setenv(EXEC_PATH_ENVIRONMENT, exec_path, 1); > + setenv(util_cfg.exec_path_env, exec_path, 1); > } > > > -/* 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; > > if (argv_exec_path) > return strdup(argv_exec_path); > > - env = getenv(EXEC_PATH_ENVIRONMENT); > + env = getenv(util_cfg.exec_path_env); > if (env && *env) > return strdup(env); > > - return system_path(PERF_EXEC_PATH); > + return system_path(util_cfg.exec_path); > } > > static void add_path(struct strbuf *out, const char *path) > @@ -82,7 +82,7 @@ void setup_path(void) > { > const char *old_path = getenv("PATH"); > struct strbuf new_path = STRBUF_INIT; > - char *tmp = perf_exec_path(); > + char *tmp = get_argv_exec_path(); > > add_path(&new_path, tmp); > add_path(&new_path, argv0_path); > @@ -98,7 +98,7 @@ void setup_path(void) > strbuf_release(&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; > @@ -107,25 +107,25 @@ static const char **prepare_perf_cmd(const char **argv) > ; /* just counting */ > nargv = malloc(sizeof(*nargv) * (argc + 2)); > > - nargv[0] = "perf"; > + nargv[0] = util_cfg.exec_name; > for (argc = 0; argv[argc]; argc++) > nargv[argc + 1] = argv[argc]; > nargv[argc + 1] = NULL; > 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("perf", (char **)nargv); > + execvp(util_cfg.exec_name, (char **)nargv); > > free(nargv); > return -1; > } > > > -int execl_perf_cmd(const char *cmd,...) > +int execl_cmd(const char *cmd,...) > { > int argc; > const char *argv[MAX_ARGS + 1]; > @@ -145,5 +145,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); > } > diff --git a/tools/perf/util/exec_cmd.h b/tools/lib/api/util/exec_cmd.h > similarity index 14% > rename from tools/perf/util/exec_cmd.h > rename to tools/lib/api/util/exec_cmd.h > index 48b4175..c826713 100644 > --- a/tools/perf/util/exec_cmd.h > +++ b/tools/lib/api/util/exec_cmd.h > @@ -1,13 +1,13 @@ > -#ifndef __PERF_EXEC_CMD_H > -#define __PERF_EXEC_CMD_H > +#ifndef __API_UTIL_EXEC_CMD_H > +#define __API_UTIL_EXEC_CMD_H > > -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 */ > +#endif /* __API_UTIL_EXEC_CMD_H */ > diff --git a/tools/perf/util/help.c b/tools/lib/api/util/help.c > similarity index 96% > rename from tools/perf/util/help.c > rename to tools/lib/api/util/help.c > index dfe9c5f..36b3e60 100644 > --- a/tools/perf/util/help.c > +++ b/tools/lib/api/util/help.c > @@ -1,6 +1,9 @@ > -#include "util.h" > -#include "exec_cmd.h" > +#include "compat-util.h" > #include "help.h" > +#include "exec_cmd.h" > +#include "strbuf.h" > +#include "wrapper.h" > +#include "term.h" > > void add_cmdname(struct cmdnames *cmds, const char *name, size_t len) > { > @@ -164,7 +167,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); > @@ -209,7 +212,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)); > diff --git a/tools/perf/util/help.h b/tools/lib/api/util/help.h > similarity index 100% > rename from tools/perf/util/help.h > rename to tools/lib/api/util/help.h > diff --git a/tools/perf/util/pager.c b/tools/lib/api/util/pager.c > similarity index 93% > rename from tools/perf/util/pager.c > rename to tools/lib/api/util/pager.c > index 6cff2ac..97a59ed 100644 > --- a/tools/perf/util/pager.c > +++ b/tools/lib/api/util/pager.c > @@ -1,6 +1,8 @@ > -#include "util.h" > +#include "compat-util.h" > +#include "pager.h" > #include "run-command.h" > #include "sigchain.h" > +#include "cfg.h" > > /* > * This is split up from the rest of git so that we can do > @@ -46,7 +48,7 @@ static void wait_for_pager_signal(int signo) > > void setup_pager(void) > { > - const char *pager = getenv("PERF_PAGER"); > + const char *pager = getenv(util_cfg.pager_env); > > if (!isatty(1)) > return; > diff --git a/tools/perf/util/pager.h b/tools/lib/api/util/pager.h > similarity index 42% > rename from tools/perf/util/pager.h > rename to tools/lib/api/util/pager.h > index 2794a83..3c13659 100644 > --- a/tools/perf/util/pager.h > +++ b/tools/lib/api/util/pager.h > @@ -1,7 +1,7 @@ > -#ifndef __PERF_PAGER_H > -#define __PERF_PAGER_H > +#ifndef __API_UTIL_PAGER_H > +#define __API_UTIL_PAGER_H > > extern void setup_pager(void); > extern int pager_in_use(void); > > -#endif /* __PERF_PAGER_H */ > +#endif /* __API_UTIL_PAGER_H */ > diff --git a/tools/perf/util/parse-options.c > b/tools/lib/api/util/parse-options.c > similarity index 98% > rename from tools/perf/util/parse-options.c > rename to tools/lib/api/util/parse-options.c > index 8d70c1b..9e334a9 100644 > --- a/tools/perf/util/parse-options.c > +++ b/tools/lib/api/util/parse-options.c > @@ -1,7 +1,12 @@ > -#include "util.h" > +#include "compat-util.h" > + > +#include "../string/string.h" > #include "parse-options.h" > -#include "header.h" > -#include <api/string/string.h> > +#include "strbuf.h" > +#include "usage.h" > +#include "ctype.h" > +#include "pager.h" > +#include "cfg.h" > > #define OPT_SHORT 1 > #define OPT_UNSET 2 > @@ -510,7 +515,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>] {", > + util_cfg.exec_name, argv[0]); > for (int i = 0; subcommands[i]; i++) { > if (i) > strbuf_addstr(&buf, "|"); > @@ -771,7 +777,9 @@ int usage_with_options_internal(const char * const > *usagestr, > void usage_with_options(const char * const *usagestr, > const struct option *opts) > { > - exit_browser(false); > + if (util_cfg.exit_browser) > + util_cfg.exit_browser(); > + > usage_with_options_internal(usagestr, opts, 0, NULL); > exit(129); > } > @@ -781,7 +789,8 @@ void usage_with_options_msg(const char * const *usagestr, > { > va_list ap; > > - exit_browser(false); > + if (util_cfg.exit_browser) > + util_cfg.exit_browser(); > > va_start(ap, fmt); > strbuf_addv(&error_buf, fmt, ap); > diff --git a/tools/perf/util/parse-options.h > b/tools/lib/api/util/parse-options.h > similarity index 98% > rename from tools/perf/util/parse-options.h > rename to tools/lib/api/util/parse-options.h > index a8e407b..4b97cba 100644 > --- a/tools/perf/util/parse-options.h > +++ b/tools/lib/api/util/parse-options.h > @@ -1,8 +1,7 @@ > -#ifndef __PERF_PARSE_OPTIONS_H > -#define __PERF_PARSE_OPTIONS_H > +#ifndef __API_UTIL_PARSE_OPTIONS_H > +#define __API_UTIL_PARSE_OPTIONS_H > > -#include <linux/kernel.h> > -#include <stdbool.h> > +#include "compat-util.h" > > enum parse_opt_type { > /* special types */ > @@ -226,4 +225,5 @@ extern int parse_opt_verbosity_cb(const struct option *, > const char *, int); > extern const char *parse_options_fix_filename(const char *prefix, const char > *file); > > void set_option_flag(struct option *opts, int sopt, const char *lopt, int > flag); > -#endif /* __PERF_PARSE_OPTIONS_H */ > + > +#endif /* __API_UTIL_PARSE_OPTIONS_H */ > diff --git a/tools/perf/util/run-command.c b/tools/lib/api/util/run-command.c > similarity index 96% > rename from tools/perf/util/run-command.c > rename to tools/lib/api/util/run-command.c > index 38d2cc6..d5f2daa 100644 > --- a/tools/perf/util/run-command.c > +++ b/tools/lib/api/util/run-command.c > @@ -1,7 +1,9 @@ > -#include "util.h" > +#include "compat-util.h" > #include "run-command.h" > #include "exec_cmd.h" > -#include "debug.h" > +#include "usage.h" > + > +#define STRERR_BUFSIZE 128 > > static inline void close_pair(int fd[2]) > { > @@ -112,8 +114,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 +209,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; > } > > diff --git a/tools/perf/util/run-command.h b/tools/lib/api/util/run-command.h > similarity index 87% > rename from tools/perf/util/run-command.h > rename to tools/lib/api/util/run-command.h > index 1ef264d..6876b14 100644 > --- a/tools/perf/util/run-command.h > +++ b/tools/lib/api/util/run-command.h > @@ -1,5 +1,5 @@ > -#ifndef __PERF_RUN_COMMAND_H > -#define __PERF_RUN_COMMAND_H > +#ifndef __API_UTIL_RUN_COMMAND_H > +#define __API_UTIL_RUN_COMMAND_H > > enum { > ERR_RUN_COMMAND_FORK = 10000, > @@ -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,8 +51,8 @@ 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); > > -#endif /* __PERF_RUN_COMMAND_H */ > +#endif /* __API_UTIL_RUN_COMMAND_H */ > diff --git a/tools/perf/util/sigchain.c b/tools/lib/api/util/sigchain.c > similarity index 93% > rename from tools/perf/util/sigchain.c > rename to tools/lib/api/util/sigchain.c > index 5eebf88..d7ed474 100644 > --- a/tools/perf/util/sigchain.c > +++ b/tools/lib/api/util/sigchain.c > @@ -1,5 +1,7 @@ > -#include "util.h" > +#include "compat-util.h" > #include "sigchain.h" > +#include "usage.h" > +#include "wrapper.h" > > #define SIGCHAIN_MAX_SIGNALS 32 > > diff --git a/tools/perf/util/sigchain.h b/tools/lib/api/util/sigchain.h > similarity index 53% > rename from tools/perf/util/sigchain.h > rename to tools/lib/api/util/sigchain.h > index 959d64e..6038d7b 100644 > --- a/tools/perf/util/sigchain.h > +++ b/tools/lib/api/util/sigchain.h > @@ -1,5 +1,5 @@ > -#ifndef __PERF_SIGCHAIN_H > -#define __PERF_SIGCHAIN_H > +#ifndef __API_UTIL_SIGCHAIN_H > +#define __API_UTIL_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 /* __API_UTIL_SIGCHAIN_H */ > diff --git a/tools/perf/util/strbuf.c b/tools/lib/api/util/strbuf.c > similarity index 97% > rename from tools/perf/util/strbuf.c > rename to tools/lib/api/util/strbuf.c > index 0e53793..6f0ae90 100644 > --- a/tools/perf/util/strbuf.c > +++ b/tools/lib/api/util/strbuf.c > @@ -1,5 +1,9 @@ > -#include "util.h" > +#include "compat-util.h" > + > #include <linux/kernel.h> > +#include "strbuf.h" > +#include "wrapper.h" > +#include "usage.h" > > int prefixcmp(const char *str, const char *prefix) > { > diff --git a/tools/perf/util/strbuf.h b/tools/lib/api/util/strbuf.h > similarity index 97% > rename from tools/perf/util/strbuf.h > rename to tools/lib/api/util/strbuf.h > index 39a1481..cc284a6 100644 > --- a/tools/perf/util/strbuf.h > +++ b/tools/lib/api/util/strbuf.h > @@ -1,5 +1,5 @@ > -#ifndef __PERF_STRBUF_H > -#define __PERF_STRBUF_H > +#ifndef __API_UTIL_STRBUF_H > +#define __API_UTIL_STRBUF_H > > /* > * Strbuf's can be use in many ways: as a byte array, or to store arbitrary > @@ -93,4 +93,4 @@ extern void strbuf_addv(struct strbuf *sb, const char *fmt, > va_list ap); > /* XXX: if read fails, any partial read is undone */ > extern ssize_t strbuf_read(struct strbuf *, int fd, ssize_t hint); > > -#endif /* __PERF_STRBUF_H */ > +#endif /* __API_UTIL_STRBUF_H */ > diff --git a/tools/perf/util/term.c b/tools/lib/api/util/term.c > similarity index 93% > rename from tools/perf/util/term.c > rename to tools/lib/api/util/term.c > index 90b47d8..e246994 100644 > --- a/tools/perf/util/term.c > +++ b/tools/lib/api/util/term.c > @@ -1,4 +1,5 @@ > -#include "util.h" > +#include "compat-util.h" > +#include "term.h" > > void get_term_dimensions(struct winsize *ws) > { > diff --git a/tools/perf/util/term.h b/tools/lib/api/util/term.h > similarity index 100% > rename from tools/perf/util/term.h > rename to tools/lib/api/util/term.h > diff --git a/tools/perf/util/usage.c b/tools/lib/api/util/usage.c > similarity index 97% > rename from tools/perf/util/usage.c > rename to tools/lib/api/util/usage.c > index 6adfa18..69ec872 100644 > --- a/tools/perf/util/usage.c > +++ b/tools/lib/api/util/usage.c > @@ -6,8 +6,8 @@ > * > * Copyright (C) Linus Torvalds, 2005 > */ > -#include "util.h" > -#include "debug.h" > +#include "compat-util.h" > +#include "usage.h" > > static void report(const char *prefix, const char *err, va_list params) > { > diff --git a/tools/perf/util/usage.h b/tools/lib/api/util/usage.h > similarity index 84% > rename from tools/perf/util/usage.h > rename to tools/lib/api/util/usage.h > index e3f1bd0..05a6e43 100644 > --- a/tools/perf/util/usage.h > +++ b/tools/lib/api/util/usage.h > @@ -1,5 +1,5 @@ > -#ifndef __PERF_USAGE_H > -#define __PERF_USAGE_H > +#ifndef __API_UTIL_USAGE_H > +#define __API_UTIL_USAGE_H > > #include "compat-util.h" > > @@ -8,7 +8,7 @@ extern void die(const char *err, ...) NORETURN > __attribute__((format (printf, 1, > extern int error(const char *err, ...) __attribute__((format (printf, 1, > 2))); > extern void warning(const char *err, ...) __attribute__((format (printf, 1, > 2))); > > -#include "../../../include/linux/stringify.h" > +#include <linux/stringify.h> > > #define DIE_IF(cnd) \ > do { if (cnd) \ > @@ -20,4 +20,4 @@ extern void warning(const char *err, ...) > __attribute__((format (printf, 1, 2))) > extern void set_die_routine(void (*routine)(const char *err, va_list params) > NORETURN); > extern void set_warning_routine(void (*routine)(const char *err, va_list > params)); > > -#endif /* __PERF_USAGE_H */ > +#endif /* __API_UTIL_USAGE_H */ > diff --git a/tools/perf/util/wrapper.c b/tools/lib/api/util/wrapper.c > similarity index 92% > rename from tools/perf/util/wrapper.c > rename to tools/lib/api/util/wrapper.c > index 861ecfa..de59145 100644 > --- a/tools/perf/util/wrapper.c > +++ b/tools/lib/api/util/wrapper.c > @@ -1,7 +1,9 @@ > /* > * Various trivial helper wrappers around standard functions > */ > -#include "util.h" > +#include "compat-util.h" > +#include "wrapper.h" > +#include "usage.h" > > /* > * There's no pack memory to release - but stay close to the Git > diff --git a/tools/perf/util/wrapper.h b/tools/lib/api/util/wrapper.h > similarity index 89% > rename from tools/perf/util/wrapper.h > rename to tools/lib/api/util/wrapper.h > index e2fa014..b8adda7 100644 > --- a/tools/perf/util/wrapper.h > +++ b/tools/lib/api/util/wrapper.h > @@ -1,5 +1,5 @@ > -#ifndef __PERF_WRAPPER_H > -#define __PERF_WRAPPER_H > +#ifndef __API_UTIL_WRAPPER_H > +#define __API_UTIL_WRAPPER_H > > extern char *xstrdup(const char *str); > extern void *xrealloc(void *ptr, size_t size) __attribute__((weak)); > @@ -31,4 +31,4 @@ static inline void *zalloc(size_t size) > } \ > } while(0) > > -#endif /* __PERF_WRAPPER_H */ > +#endif /* __API_UTIL_WRAPPER_H */ > diff --git a/tools/perf/Build b/tools/perf/Build > index 2a41217..050f3ad 100644 > --- a/tools/perf/Build > +++ b/tools/perf/Build > @@ -36,7 +36,7 @@ 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/ > diff --git a/tools/perf/arch/x86/util/intel-pt.c > b/tools/perf/arch/x86/util/intel-pt.c > index b02af06..bcc432a 100644 > --- a/tools/perf/arch/x86/util/intel-pt.c > +++ b/tools/perf/arch/x86/util/intel-pt.c > @@ -26,7 +26,7 @@ > #include "../../util/evlist.h" > #include "../../util/evsel.h" > #include "../../util/cpumap.h" > -#include "../../util/parse-options.h" > +#include <api/util/parse-options.h> > #include "../../util/parse-events.h" > #include "../../util/pmu.h" > #include "../../util/debug.h" > diff --git a/tools/perf/bench/futex-hash.c b/tools/perf/bench/futex-hash.c > index fc9bebd..07115cf 100644 > --- a/tools/perf/bench/futex-hash.c > +++ b/tools/perf/bench/futex-hash.c > @@ -11,7 +11,7 @@ > #include "../perf.h" > #include "../util/util.h" > #include "../util/stat.h" > -#include "../util/parse-options.h" > +#include <api/util/parse-options.h> > #include "../util/header.h" > #include "bench.h" > #include "futex.h" > diff --git a/tools/perf/bench/futex-lock-pi.c > b/tools/perf/bench/futex-lock-pi.c > index bc6a16a..487c3d3 100644 > --- a/tools/perf/bench/futex-lock-pi.c > +++ b/tools/perf/bench/futex-lock-pi.c > @@ -5,7 +5,7 @@ > #include "../perf.h" > #include "../util/util.h" > #include "../util/stat.h" > -#include "../util/parse-options.h" > +#include <api/util/parse-options.h> > #include "../util/header.h" > #include "bench.h" > #include "futex.h" > diff --git a/tools/perf/bench/futex-requeue.c > b/tools/perf/bench/futex-requeue.c > index ad0d9b5..eb56ddf 100644 > --- a/tools/perf/bench/futex-requeue.c > +++ b/tools/perf/bench/futex-requeue.c > @@ -11,7 +11,7 @@ > #include "../perf.h" > #include "../util/util.h" > #include "../util/stat.h" > -#include "../util/parse-options.h" > +#include <api/util/parse-options.h> > #include "../util/header.h" > #include "bench.h" > #include "futex.h" > diff --git a/tools/perf/bench/futex-wake-parallel.c > b/tools/perf/bench/futex-wake-parallel.c > index 6d8c9fa..1bab7b0 100644 > --- a/tools/perf/bench/futex-wake-parallel.c > +++ b/tools/perf/bench/futex-wake-parallel.c > @@ -10,7 +10,7 @@ > #include "../perf.h" > #include "../util/util.h" > #include "../util/stat.h" > -#include "../util/parse-options.h" > +#include <api/util/parse-options.h> > #include "../util/header.h" > #include "bench.h" > #include "futex.h" > diff --git a/tools/perf/bench/futex-wake.c b/tools/perf/bench/futex-wake.c > index e5e41d3..d23e978 100644 > --- a/tools/perf/bench/futex-wake.c > +++ b/tools/perf/bench/futex-wake.c > @@ -11,7 +11,7 @@ > #include "../perf.h" > #include "../util/util.h" > #include "../util/stat.h" > -#include "../util/parse-options.h" > +#include <api/util/parse-options.h> > #include "../util/header.h" > #include "bench.h" > #include "futex.h" > diff --git a/tools/perf/bench/mem-functions.c > b/tools/perf/bench/mem-functions.c > index 9419b94..ad11f26 100644 > --- a/tools/perf/bench/mem-functions.c > +++ b/tools/perf/bench/mem-functions.c > @@ -8,7 +8,7 @@ > > #include "../perf.h" > #include "../util/util.h" > -#include "../util/parse-options.h" > +#include <api/util/parse-options.h> > #include "../util/header.h" > #include "../util/cloexec.h" > #include "bench.h" > diff --git a/tools/perf/bench/numa.c b/tools/perf/bench/numa.c > index 492df27..8a42d13 100644 > --- a/tools/perf/bench/numa.c > +++ b/tools/perf/bench/numa.c > @@ -7,7 +7,7 @@ > #include "../perf.h" > #include "../builtin.h" > #include "../util/util.h" > -#include "../util/parse-options.h" > +#include <api/util/parse-options.h> > #include "../util/cloexec.h" > > #include "bench.h" > diff --git a/tools/perf/bench/sched-messaging.c > b/tools/perf/bench/sched-messaging.c > index d4ff1b5..77e36e9 100644 > --- a/tools/perf/bench/sched-messaging.c > +++ b/tools/perf/bench/sched-messaging.c > @@ -11,7 +11,7 @@ > > #include "../perf.h" > #include "../util/util.h" > -#include "../util/parse-options.h" > +#include <api/util/parse-options.h> > #include "../builtin.h" > #include "bench.h" > > diff --git a/tools/perf/bench/sched-pipe.c b/tools/perf/bench/sched-pipe.c > index 005cc28..b1e84c8 100644 > --- a/tools/perf/bench/sched-pipe.c > +++ b/tools/perf/bench/sched-pipe.c > @@ -10,7 +10,7 @@ > */ > #include "../perf.h" > #include "../util/util.h" > -#include "../util/parse-options.h" > +#include <api/util/parse-options.h> > #include "../builtin.h" > #include "bench.h" > > diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c > index 50695c7..bba340b 100644 > --- a/tools/perf/builtin-annotate.c > +++ b/tools/perf/builtin-annotate.c > @@ -20,7 +20,7 @@ > #include "util/evsel.h" > #include "util/annotate.h" > #include "util/event.h" > -#include "util/parse-options.h" > +#include <api/util/parse-options.h> > #include "util/parse-events.h" > #include "util/thread.h" > #include "util/sort.h" > diff --git a/tools/perf/builtin-bench.c b/tools/perf/builtin-bench.c > index b17aed3..48b4054 100644 > --- a/tools/perf/builtin-bench.c > +++ b/tools/perf/builtin-bench.c > @@ -16,7 +16,7 @@ > */ > #include "perf.h" > #include "util/util.h" > -#include "util/parse-options.h" > +#include <api/util/parse-options.h> > #include "builtin.h" > #include "bench/bench.h" > > diff --git a/tools/perf/builtin-buildid-cache.c > b/tools/perf/builtin-buildid-cache.c > index bed484f..1dc9eb0 100644 > --- a/tools/perf/builtin-buildid-cache.c > +++ b/tools/perf/builtin-buildid-cache.c > @@ -16,7 +16,7 @@ > #include "util/util.h" > #include "util/debug.h" > #include "util/header.h" > -#include "util/parse-options.h" > +#include <api/util/parse-options.h> > #include "util/strlist.h" > #include "util/build-id.h" > #include "util/session.h" > diff --git a/tools/perf/builtin-buildid-list.c > b/tools/perf/builtin-buildid-list.c > index bd7558e..4ff4f6c 100644 > --- a/tools/perf/builtin-buildid-list.c > +++ b/tools/perf/builtin-buildid-list.c > @@ -12,7 +12,7 @@ > #include "util/build-id.h" > #include "util/util.h" > #include "util/debug.h" > -#include "util/parse-options.h" > +#include <api/util/parse-options.h> > #include "util/session.h" > #include "util/symbol.h" > #include "util/data.h" > diff --git a/tools/perf/builtin-config.c b/tools/perf/builtin-config.c > index 03117c8..a2a087c 100644 > --- a/tools/perf/builtin-config.c > +++ b/tools/perf/builtin-config.c > @@ -9,7 +9,7 @@ > #include "perf.h" > > #include "util/util.h" > -#include "util/parse-options.h" > +#include <api/util/parse-options.h> > #include "util/debug.h" > > static const char * const config_usage[] = { > diff --git a/tools/perf/builtin-data.c b/tools/perf/builtin-data.c > index d6525bc..b27861f 100644 > --- a/tools/perf/builtin-data.c > +++ b/tools/perf/builtin-data.c > @@ -2,7 +2,7 @@ > #include "builtin.h" > #include "perf.h" > #include "debug.h" > -#include "parse-options.h" > +#include <api/util/parse-options.h> > #include "data-convert-bt.h" > > typedef int (*data_cmd_fn_t)(int argc, const char **argv, const char > *prefix); > diff --git a/tools/perf/builtin-evlist.c b/tools/perf/builtin-evlist.c > index f4d6251..7f673a0 100644 > --- a/tools/perf/builtin-evlist.c > +++ b/tools/perf/builtin-evlist.c > @@ -12,7 +12,7 @@ > #include "util/evlist.h" > #include "util/evsel.h" > #include "util/parse-events.h" > -#include "util/parse-options.h" > +#include <api/util/parse-options.h> > #include "util/session.h" > #include "util/data.h" > #include "util/debug.h" > diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c > index 23c3fdb..6ddbffc 100644 > --- a/tools/perf/builtin-help.c > +++ b/tools/perf/builtin-help.c > @@ -6,11 +6,10 @@ > #include "perf.h" > #include "util/util.h" > #include "builtin.h" > -#include "util/exec_cmd.h" > +#include <api/util/exec_cmd.h> > #include "common-cmds.h" > -#include "util/parse-options.h" > -#include "util/run-command.h" > -#include "util/help.h" > +#include <api/util/parse-options.h> > +#include <api/util/run-command.h> > #include "util/debug.h" > > static struct man_viewer_list { > @@ -407,7 +406,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 > > diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c > index 99d127f..a85ecba 100644 > --- a/tools/perf/builtin-inject.c > +++ b/tools/perf/builtin-inject.c > @@ -18,7 +18,7 @@ > #include "util/data.h" > #include "util/auxtrace.h" > > -#include "util/parse-options.h" > +#include <api/util/parse-options.h> > > #include <linux/list.h> > > diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c > index cdf487b..e0c5b44 100644 > --- a/tools/perf/builtin-kmem.c > +++ b/tools/perf/builtin-kmem.c > @@ -11,7 +11,7 @@ > #include "util/tool.h" > #include "util/callchain.h" > > -#include "util/parse-options.h" > +#include <api/util/parse-options.h> > #include "util/trace-event.h" > #include "util/data.h" > #include "util/cpumap.h" > diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c > index a9ad326..2202f54 100644 > --- a/tools/perf/builtin-kvm.c > +++ b/tools/perf/builtin-kvm.c > @@ -9,7 +9,7 @@ > #include "util/header.h" > #include "util/session.h" > #include "util/intlist.h" > -#include "util/parse-options.h" > +#include <api/util/parse-options.h> > #include "util/trace-event.h" > #include "util/debug.h" > #include "util/tool.h" > diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c > index 70856ac..0b080cd 100644 > --- a/tools/perf/builtin-list.c > +++ b/tools/perf/builtin-list.c > @@ -14,7 +14,7 @@ > #include "util/parse-events.h" > #include "util/util.h" > #include "util/pmu.h" > -#include "util/parse-options.h" > +#include <api/util/parse-options.h> > > int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused) > { > diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c > index 191d32f..2e14528 100644 > --- a/tools/perf/builtin-lock.c > +++ b/tools/perf/builtin-lock.c > @@ -8,7 +8,7 @@ > #include "util/thread.h" > #include "util/header.h" > > -#include "util/parse-options.h" > +#include <api/util/parse-options.h> > #include "util/trace-event.h" > > #include "util/debug.h" > diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c > index 80170aa..fd2adeb 100644 > --- a/tools/perf/builtin-mem.c > +++ b/tools/perf/builtin-mem.c > @@ -1,7 +1,7 @@ > #include "builtin.h" > #include "perf.h" > > -#include "util/parse-options.h" > +#include <api/util/parse-options.h> > #include "util/trace-event.h" > #include "util/tool.h" > #include "util/session.h" > diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c > index 132afc9..d4a7885 100644 > --- a/tools/perf/builtin-probe.c > +++ b/tools/perf/builtin-probe.c > @@ -37,7 +37,7 @@ > #include "util/strfilter.h" > #include "util/symbol.h" > #include "util/debug.h" > -#include "util/parse-options.h" > +#include <api/util/parse-options.h> > #include "util/probe-finder.h" > #include "util/probe-event.h" > #include "util/probe-file.h" > diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c > index 199fc31..9c0d1bd 100644 > --- a/tools/perf/builtin-record.c > +++ b/tools/perf/builtin-record.c > @@ -11,7 +11,7 @@ > > #include "util/build-id.h" > #include "util/util.h" > -#include "util/parse-options.h" > +#include <api/util/parse-options.h> > #include "util/parse-events.h" > > #include "util/callchain.h" > diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c > index 61ed8f2..b998e26 100644 > --- a/tools/perf/builtin-report.c > +++ b/tools/perf/builtin-report.c > @@ -26,7 +26,7 @@ > #include "util/session.h" > #include "util/tool.h" > > -#include "util/parse-options.h" > +#include <api/util/parse-options.h> > #include "util/parse-events.h" > > #include "util/thread.h" > diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c > index 43dedd4..37ab946 100644 > --- a/tools/perf/builtin-sched.c > +++ b/tools/perf/builtin-sched.c > @@ -11,7 +11,7 @@ > #include "util/tool.h" > #include "util/cloexec.h" > > -#include "util/parse-options.h" > +#include <api/util/parse-options.h> > #include "util/trace-event.h" > > #include "util/debug.h" > diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c > index 8873021..ba344c0 100644 > --- a/tools/perf/builtin-script.c > +++ b/tools/perf/builtin-script.c > @@ -2,9 +2,9 @@ > > #include "perf.h" > #include "util/debug.h" > -#include "util/exec_cmd.h" > +#include <api/util/exec_cmd.h> > #include "util/header.h" > -#include "util/parse-options.h" > +#include <api/util/parse-options.h> > #include "util/perf_regs.h" > #include "util/session.h" > #include "util/tool.h" > @@ -1393,7 +1393,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) > @@ -1514,7 +1514,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) { > @@ -1572,7 +1572,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) > @@ -1808,7 +1808,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]; > diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c > index df2fbf0..a1460b2 100644 > --- a/tools/perf/builtin-stat.c > +++ b/tools/perf/builtin-stat.c > @@ -45,7 +45,7 @@ > #include "builtin.h" > #include "util/cgroup.h" > #include "util/util.h" > -#include "util/parse-options.h" > +#include <api/util/parse-options.h> > #include "util/parse-events.h" > #include "util/pmu.h" > #include "util/event.h" > diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c > index ab75e5b..89d6ca1 100644 > --- a/tools/perf/builtin-timechart.c > +++ b/tools/perf/builtin-timechart.c > @@ -29,7 +29,7 @@ > > #include "perf.h" > #include "util/header.h" > -#include "util/parse-options.h" > +#include <api/util/parse-options.h> > #include "util/parse-events.h" > #include "util/event.h" > #include "util/session.h" > diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c > index c8dd628..ee1a733 100644 > --- a/tools/perf/builtin-top.c > +++ b/tools/perf/builtin-top.c > @@ -33,7 +33,7 @@ > #include "util/top.h" > #include "util/util.h" > #include <linux/rbtree.h> > -#include "util/parse-options.h" > +#include <api/util/parse-options.h> > #include "util/parse-events.h" > #include "util/cpumap.h" > #include "util/xyarray.h" > diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c > index c783d8f..63b180a 100644 > --- a/tools/perf/builtin-trace.c > +++ b/tools/perf/builtin-trace.c > @@ -22,11 +22,11 @@ > #include "util/color.h" > #include "util/debug.h" > #include "util/evlist.h" > -#include "util/exec_cmd.h" > +#include <api/util/exec_cmd.h> > #include "util/machine.h" > #include "util/session.h" > #include "util/thread.h" > -#include "util/parse-options.h" > +#include <api/util/parse-options.h> > #include "util/strlist.h" > #include "util/intlist.h" > #include "util/thread_map.h" > diff --git a/tools/perf/builtin.h b/tools/perf/builtin.h > index 3f871b5..123e66a 100644 > --- a/tools/perf/builtin.h > +++ b/tools/perf/builtin.h > @@ -2,7 +2,7 @@ > #define BUILTIN_H > > #include "util/util.h" > -#include "util/strbuf.h" > +#include <api/util/strbuf.h> > > extern const char perf_usage_string[]; > extern const char perf_more_info_string[]; > diff --git a/tools/perf/perf.c b/tools/perf/perf.c > index c57e447..1312c50 100644 > --- a/tools/perf/perf.c > +++ b/tools/perf/perf.c > @@ -9,16 +9,17 @@ > #include "builtin.h" > > #include "util/env.h" > -#include "util/exec_cmd.h" > +#include <api/util/exec_cmd.h> > #include "util/util.h" > #include "util/quote.h" > -#include "util/run-command.h" > +#include <api/util/run-command.h> > #include "util/parse-events.h" > -#include "util/parse-options.h" > +#include <api/util/parse-options.h> > #include "util/bpf-loader.h" > #include "util/debug.h" > #include <api/fs/tracing_path.h> > #include <pthread.h> > +#include <api/util/cfg.h> > > const char perf_usage_string[] = > "perf [--version] [--help] [OPTIONS] COMMAND [ARGS]"; > @@ -119,7 +120,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(); */ > @@ -129,6 +130,16 @@ static void commit_pager_choice(void) > } > } > > +static void setup_util(void) > +{ > + util_cfg.prefix = PREFIX; > + util_cfg.exec_name = "perf"; > + util_cfg.exec_path = PERF_EXEC_PATH; > + util_cfg.exec_path_env = EXEC_PATH_ENVIRONMENT; > + util_cfg.pager_env = PERF_PAGER_ENVIRONMENT; > + util_cfg.exit_browser = exit_browser_no_wait; > +} > + > struct option options[] = { > OPT_ARGUMENT("help", "help"), > OPT_ARGUMENT("version", "version"), > @@ -183,9 +194,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")) { > @@ -530,11 +541,13 @@ int main(int argc, const char **argv) > const char *cmd; > char sbuf[STRERR_BUFSIZE]; > > + setup_util(); > + > /* The page_size is placed in util object. */ > 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"; > > diff --git a/tools/perf/perf.h b/tools/perf/perf.h > index 501acb4..8f314b5 100644 > --- a/tools/perf/perf.h > +++ b/tools/perf/perf.h > @@ -17,6 +17,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" > > extern bool test_attr__enabled; > void test_attr__init(void); > diff --git a/tools/perf/tests/attr.c b/tools/perf/tests/attr.c > index b66730e..bdc4a3b 100644 > --- a/tools/perf/tests/attr.c > +++ b/tools/perf/tests/attr.c > @@ -24,7 +24,7 @@ > #include <linux/kernel.h> > #include "../perf.h" > #include "util.h" > -#include "exec_cmd.h" > +#include <api/util/exec_cmd.h> > #include "tests.h" > > #define ENV "PERF_TEST_ATTR" > @@ -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) && > diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c > index 2b1ade1..1b8af76 100644 > --- a/tools/perf/tests/builtin-test.c > +++ b/tools/perf/tests/builtin-test.c > @@ -11,7 +11,7 @@ > #include "tests.h" > #include "debug.h" > #include "color.h" > -#include "parse-options.h" > +#include <api/util/parse-options.h> > #include "symbol.h" > > struct test __weak arch_tests[] = { > diff --git a/tools/perf/ui/setup.c b/tools/perf/ui/setup.c > index df4bd94..f6eaee1 100644 > --- a/tools/perf/ui/setup.c > +++ b/tools/perf/ui/setup.c > @@ -105,3 +105,8 @@ void exit_browser(bool wait_for_ok) > break; > } > } > + > +void exit_browser_no_wait(void) > +{ > + exit_browser(false); > +} > diff --git a/tools/perf/ui/ui.h b/tools/perf/ui/ui.h > index ab88383..91ba964 100644 > --- a/tools/perf/ui/ui.h > +++ b/tools/perf/ui/ui.h > @@ -12,6 +12,7 @@ extern int use_browser; > > void setup_browser(bool fallback_to_pager); > void exit_browser(bool wait_for_ok); > +void exit_browser_no_wait(void); > > #ifdef HAVE_SLANG_SUPPORT > int ui__init(void); > diff --git a/tools/perf/util/Build b/tools/perf/util/Build > index 02d3a54..6732b3e 100644 > --- a/tools/perf/util/Build > +++ b/tools/perf/util/Build > @@ -1,41 +1,30 @@ > -libperf-y += abspath.o > libperf-y += alias.o > libperf-y += annotate.o > libperf-y += build-id.o > libperf-y += config.o > -libperf-y += ctype.o > libperf-y += db-export.o > 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 > libperf-y += rbtree.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 > libperf-y += strlist.o > 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 > @@ -85,7 +74,6 @@ libperf-$(CONFIG_AUXTRACE) += intel-pt.o > libperf-$(CONFIG_AUXTRACE) += intel-bts.o > libperf-y += parse-branch-options.o > libperf-y += parse-regs-options.o > -libperf-y += term.o > libperf-y += help-unknown-cmd.o > > libperf-$(CONFIG_LIBBPF) += bpf-loader.o > @@ -112,7 +100,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) > diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c > index cc83262..07f25ec 100644 > --- a/tools/perf/util/auxtrace.c > +++ b/tools/perf/util/auxtrace.c > @@ -45,7 +45,7 @@ > #include "event.h" > #include "session.h" > #include "debug.h" > -#include "parse-options.h" > +#include <api/util/parse-options.h> > > #include "intel-pt.h" > #include "intel-bts.h" > diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c > index 32e12ec..4543e72 100644 > --- a/tools/perf/util/cgroup.c > +++ b/tools/perf/util/cgroup.c > @@ -1,6 +1,6 @@ > #include "util.h" > #include "../perf.h" > -#include "parse-options.h" > +#include <api/util/parse-options.h> > #include "evsel.h" > #include "cgroup.h" > #include "evlist.h" > diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c > index 6b9e91f..8bdc5c6 100644 > --- a/tools/perf/util/config.c > +++ b/tools/perf/util/config.c > @@ -9,7 +9,7 @@ > * > */ > #include "util.h" > -#include "exec_cmd.h" > +#include <api/util/exec_cmd.h> > #include "util/hist.h" /* perf_hist_config */ > #include "util/llvm-utils.h" /* perf_llvm_config */ > > diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c > index d139219..79eef69 100644 > --- a/tools/perf/util/evlist.c > +++ b/tools/perf/util/evlist.c > @@ -18,7 +18,7 @@ > #include <unistd.h> > > #include "parse-events.h" > -#include "parse-options.h" > +#include <api/util/parse-options.h> > > #include <sys/mman.h> > > diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c > index 4383800..ec7b508 100644 > --- a/tools/perf/util/header.c > +++ b/tools/perf/util/header.c > @@ -20,7 +20,7 @@ > #include "cpumap.h" > #include "pmu.h" > #include "vdso.h" > -#include "strbuf.h" > +#include <api/util/strbuf.h> > #include "build-id.h" > #include "data.h" > > diff --git a/tools/perf/util/help-unknown-cmd.c > b/tools/perf/util/help-unknown-cmd.c > index c30ae78..e658c22 100644 > --- a/tools/perf/util/help-unknown-cmd.c > +++ b/tools/perf/util/help-unknown-cmd.c > @@ -1,5 +1,5 @@ > #include "util.h" > -#include "help.h" > +#include <api/util/help.h> > #include "../builtin.h" > #include "levenshtein.h" > > diff --git a/tools/perf/util/parse-branch-options.c > b/tools/perf/util/parse-branch-options.c > index 355eecf..611f0f2 100644 > --- a/tools/perf/util/parse-branch-options.c > +++ b/tools/perf/util/parse-branch-options.c > @@ -1,7 +1,7 @@ > #include "perf.h" > #include "util/util.h" > #include "util/debug.h" > -#include "util/parse-options.h" > +#include <api/util/parse-options.h> > #include "util/parse-branch-options.h" > > #define BRANCH_OPT(n, m) \ > diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c > index d2ec59d..5263f87 100644 > --- a/tools/perf/util/parse-events.c > +++ b/tools/perf/util/parse-events.c > @@ -4,9 +4,9 @@ > #include "../perf.h" > #include "evlist.h" > #include "evsel.h" > -#include "parse-options.h" > +#include <api/util/parse-options.h> > #include "parse-events.h" > -#include "exec_cmd.h" > +#include <api/util/exec_cmd.h> > #include "string.h" > #include "symbol.h" > #include "header.h" > diff --git a/tools/perf/util/parse-regs-options.c > b/tools/perf/util/parse-regs-options.c > index 4f2c1c2..893d2ca 100644 > --- a/tools/perf/util/parse-regs-options.c > +++ b/tools/perf/util/parse-regs-options.c > @@ -1,7 +1,7 @@ > #include "perf.h" > #include "util/util.h" > #include "util/debug.h" > -#include "util/parse-options.h" > +#include <api/util/parse-options.h> > #include "util/parse-regs-options.h" > > int > diff --git a/tools/perf/util/python-ext-sources > b/tools/perf/util/python-ext-sources > index 51be28b..2f5a2d0 100644 > --- a/tools/perf/util/python-ext-sources > +++ b/tools/perf/util/python-ext-sources > @@ -6,7 +6,6 @@ > # > > util/python.c > -util/ctype.c > util/evlist.c > util/evsel.c > util/cpumap.c > diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h > index 139a566..3459ae1 100644 > --- a/tools/perf/util/sort.h > +++ b/tools/perf/util/sort.h > @@ -17,7 +17,7 @@ > #include "debug.h" > #include "header.h" > > -#include "parse-options.h" > +#include <api/util/parse-options.h> > #include "parse-events.h" > #include "hist.h" > #include "thread.h" > diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h > index f1c07f6..6459f59 100644 > --- a/tools/perf/util/util.h > +++ b/tools/perf/util/util.h > @@ -1,24 +1,27 @@ > #ifndef __PERF_UTIL_H > #define __PERF_UTIL_H > > -#include "compat-util.h" > +#include <api/util/compat-util.h> > > +#include <api/fs/tracing_path.h> > #include <api/string/string.h> > +#include <api/util/abspath.h> > +#include <api/util/ctype.h> > +#include <api/util/help.h> > +#include <api/util/pager.h> > +#include <api/util/strbuf.h> > +#include <api/util/term.h> > +#include <api/util/usage.h> > +#include <api/util/wrapper.h> > + > #include "../perf.h" > -#include "abspath.h" > #include "alias.h" > #include "config.h" > -#include "ctype.h" > #include "lzma.h" > -#include "pager.h" > #include "path.h" > #include "srcline.h" > -#include "strbuf.h" > #include "string.h" > -#include "term.h" > #include "../ui/ui.h" > -#include "usage.h" > -#include "wrapper.h" > #include "zlib.h" > > int parse_nsec_time(const char *str, u64 *ptime); > -- > 2.4.3 > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/