Skip to contentSkip to conversation

perf tools: Move perf subcommand framework into lib/tools

PATCH Superseded Josh Poimboeuf 4 participants 25 messages Dec 4, 2015 – Dec 8, 2015

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover perf tools: Move perf subcommand framework into lib/tools

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 libapi, including parse-options.c, run-command.c, exec_cmd.c, help.c, usage.c, and their dependencies. Since several of the dependencies are more general-purpose "utilities" which aren't directly related to subcommands, I put everything in 'tools/lib/api/util'. They're linked into perf as part of the libapi.a library.

Patches 1-10 do some cleanups and splitting up of the code in preparation for the move.

Patch 11 does the actual moving of the files into tools/lib/api/util.

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

Josh Poimboeuf (13):
perf: Use -iquote for local include paths
perf: Split up util.h
perf: Move term functions out of util.c
perf: Remove unused pager_use_color variable
perf: Split up cache.h
perf: Remove cache.h
perf: Save cmdline arguments earlier
perf: Remove check for unused PERF_PAGER_IN_USE
perf: Move cmd_version() to builtin-version.c
perf: Move help_unknown_cmd() to its own file
perf tools: Move strlcpy() to tools/lib/string.c
perf tools: Move perf subcommand framework into a library perf tools: Move subcommand framework and related utils to libapi

 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                                |   2 +
 tools/lib/api/Makefile                             |   6 +-
 tools/lib/api/string/Build                         |   1 +
 tools/lib/{ => api/string}/string.c                |  24 +-
 tools/{include/linux => lib/api/string}/string.h   |  15 +-
 tools/lib/api/util/Build                           |  13 +
 tools/{perf => lib/api}/util/abspath.c             |   6 +-
 tools/lib/api/util/abspath.h                       |  11 +
 tools/lib/api/util/cfg.c                           |  12 +
 tools/lib/api/util/cfg.h                           |  15 +
 tools/lib/api/util/compat-util.h                   | 129 +++++++++
 tools/{perf => lib/api}/util/ctype.c               |   3 +-
 tools/lib/api/util/ctype.h                         |  52 ++++
 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                | 134 ++-------
 tools/{perf => lib/api}/util/help.h                |   3 +
 tools/{perf => lib/api}/util/pager.c               |  14 +-
 tools/lib/api/util/pager.h                         |   7 +
 tools/{perf => lib/api}/util/parse-options.c       |  30 +-
 tools/{perf => lib/api}/util/parse-options.h       |   7 +-
 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              |   8 +-
 tools/lib/api/util/term.c                          |  36 +++
 tools/lib/api/util/term.h                          |   7 +
 tools/{perf => lib/api}/util/usage.c               |   4 +-
 tools/lib/api/util/usage.h                         |  23 ++
 tools/{perf => lib/api}/util/wrapper.c             |   4 +-
 .../{perf/util/cache.h => lib/api/util/wrapper.h}  |  65 +----
 tools/perf/Build                                   |   3 +-
 tools/perf/MANIFEST                                |   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                      |   3 +-
 tools/perf/builtin-bench.c                         |   2 +-
 tools/perf/builtin-buildid-cache.c                 |   4 +-
 tools/perf/builtin-buildid-list.c                  |   4 +-
 tools/perf/builtin-config.c                        |   3 +-
 tools/perf/builtin-data.c                          |   2 +-
 tools/perf/builtin-evlist.c                        |   2 +-
 tools/perf/builtin-help.c                          |  11 +-
 tools/perf/builtin-inject.c                        |   2 +-
 tools/perf/builtin-kmem.c                          |   5 +-
 tools/perf/builtin-kvm.c                           |   3 +-
 tools/perf/builtin-list.c                          |   4 +-
 tools/perf/builtin-lock.c                          |   3 +-
 tools/perf/builtin-mem.c                           |   2 +-
 tools/perf/builtin-probe.c                         |   2 +-
 tools/perf/builtin-record.c                        |   2 +-
 tools/perf/builtin-report.c                        |   3 +-
 tools/perf/builtin-sched.c                         |   3 +-
 tools/perf/builtin-script.c                        |  13 +-
 tools/perf/builtin-stat.c                          |   2 +-
 tools/perf/builtin-timechart.c                     |   3 +-
 tools/perf/builtin-top.c                           |   3 +-
 tools/perf/builtin-trace.c                         |   4 +-
 tools/perf/builtin-version.c                       |   9 +
 tools/perf/builtin.h                               |   2 +-
 tools/perf/config/Makefile                         |   4 +-
 tools/perf/perf.c                                  |  30 +-
 tools/perf/perf.h                                  |  13 +
 tools/perf/tests/Build                             |   6 +-
 tools/perf/tests/attr.c                            |   4 +-
 tools/perf/tests/bpf.c                             |   4 +-
 tools/perf/tests/builtin-test.c                    |   2 +-
 tools/perf/tests/llvm.c                            |   4 +-
 tools/perf/ui/browser.c                            |   1 -
 tools/perf/ui/browsers/header.c                    |   2 +-
 tools/perf/ui/gtk/browser.c                        |   2 +-
 tools/perf/ui/gtk/hists.c                          |   2 +-
 tools/perf/ui/gtk/setup.c                          |   2 +-
 tools/perf/ui/helpline.h                           |   2 +-
 tools/perf/ui/progress.c                           |   2 +-
 tools/perf/ui/setup.c                              |   7 +-
 tools/perf/ui/tui/progress.c                       |   2 +-
 tools/perf/ui/tui/setup.c                          |   1 -
 tools/perf/ui/tui/util.c                           |   1 -
 tools/perf/ui/ui.h                                 |   1 +
 tools/perf/util/Build                              |  20 +-
 tools/perf/util/alias.c                            |   2 +-
 tools/perf/util/alias.h                            |   7 +
 tools/perf/util/annotate.c                         |   1 -
 tools/perf/util/auxtrace.c                         |   4 +-
 tools/perf/util/bpf-loader.c                       |   2 +-
 tools/perf/util/cgroup.c                           |   2 +-
 tools/perf/util/color.c                            |   4 +-
 tools/perf/util/config.c                           |   3 +-
 tools/perf/util/config.h                           |  18 ++
 tools/perf/util/debug.c                            |   1 -
 tools/perf/util/env.c                              |   9 -
 tools/perf/util/environment.c                      |   8 -
 tools/perf/util/evlist.c                           |   2 +-
 tools/perf/util/header.c                           |   2 +-
 tools/perf/util/help-unknown-cmd.c                 | 103 +++++++
 tools/perf/util/help-unknown-cmd.h                 |   0
 tools/perf/util/intel-pt-decoder/insn.c            |   2 +-
 .../perf/util/intel-pt-decoder/intel-pt-decoder.c  |   1 -
 tools/perf/util/levenshtein.c                      |   2 +-
 tools/perf/util/llvm-utils.c                       |   1 -
 tools/perf/util/lzma.h                             |   8 +
 tools/perf/util/map.c                              |   2 +-
 tools/perf/util/ordered-events.c                   |   2 +-
 tools/perf/util/parse-branch-options.c             |   2 +-
 tools/perf/util/parse-events.c                     |   5 +-
 tools/perf/util/parse-regs-options.c               |   2 +-
 tools/perf/util/path.c                             |  20 +-
 tools/perf/util/path.h                             |  12 +
 tools/perf/util/probe-event.c                      |   1 -
 tools/perf/util/probe-file.c                       |   1 -
 tools/perf/util/python-ext-sources                 |   1 -
 tools/perf/util/quote.c                            |   2 +-
 tools/perf/util/sort.h                             |   3 +-
 tools/perf/util/srcline.h                          |  16 ++
 tools/perf/util/string.h                           |  34 +++
 tools/perf/util/thread.h                           |   4 +-
 tools/perf/util/util.c                             |  34 ---
 tools/perf/util/util.h                             | 314 ++-------------------
 tools/perf/util/zlib.h                             |   8 +
 133 files changed, 852 insertions(+), 761 deletions(-)
 create mode 100644 tools/lib/api/string/Build
 rename tools/lib/{ => api/string}/string.c (73%)
 rename tools/{include/linux => lib/api/string}/string.h (23%)
 create mode 100644 tools/lib/api/util/Build
 rename tools/{perf => lib/api}/util/abspath.c (90%)
 create mode 100644 tools/lib/api/util/abspath.h
 create mode 100644 tools/lib/api/util/cfg.c
 create mode 100644 tools/lib/api/util/cfg.h
 create mode 100644 tools/lib/api/util/compat-util.h
 rename tools/{perf => lib/api}/util/ctype.c (97%)
 create mode 100644 tools/lib/api/util/ctype.h
 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 (59%)
 rename tools/{perf => lib/api}/util/help.h (85%)
 rename tools/{perf => lib/api}/util/pager.c (88%)
 create mode 100644 tools/lib/api/util/pager.h
 rename tools/{perf => lib/api}/util/parse-options.c (97%)
 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 (95%)
 create mode 100644 tools/lib/api/util/term.c
 create mode 100644 tools/lib/api/util/term.h
 rename tools/{perf => lib/api}/util/usage.c (97%)
 create mode 100644 tools/lib/api/util/usage.h
 rename tools/{perf => lib/api}/util/wrapper.c (92%)
 rename tools/{perf/util/cache.h => lib/api/util/wrapper.h} (22%)
 create mode 100644 tools/perf/builtin-version.c
 create mode 100644 tools/perf/util/alias.h
 create mode 100644 tools/perf/util/config.h
 delete mode 100644 tools/perf/util/environment.c
 create mode 100644 tools/perf/util/help-unknown-cmd.c
 create mode 100644 tools/perf/util/help-unknown-cmd.h
 create mode 100644 tools/perf/util/lzma.h
 create mode 100644 tools/perf/util/path.h
 create mode 100644 tools/perf/util/srcline.h
 create mode 100644 tools/perf/util/string.h
 create mode 100644 tools/perf/util/zlib.h
Signature · 1 line
2.4.3
#1 lore raw

PATCH 1/13 perf: Use -iquote for local include paths

If there's a local header file which has the same name as a system header file, '#include <header.h>' will mistakenly include the local file instead of the system file.

With the next patch we'll have a string.h file. Use the '-iquote' option to prepare for it so that '#include "string.h"' picks up the local version.

---
 tools/perf/config/Makefile | 4 ++--
 tools/perf/tests/Build     | 6 +++---
 tools/perf/tests/bpf.c     | 4 ++--
 tools/perf/tests/llvm.c    | 4 ++--
 tools/perf/util/thread.h   | 4 ++--
 5 files changed, 11 insertions(+), 11 deletions(-)
tools/perf/config/Makefile +2 -2
index 6eb9a95..4f96ca3 100644
@@ -210,8 +210,8 @@ CFLAGS += -I$(obj-perf)/util
 CFLAGS += -I$(obj-perf)
 endif
 
-CFLAGS += -I$(src-perf)/util
-CFLAGS += -I$(src-perf)
+CFLAGS += -iquote $(src-perf)/util
+CFLAGS += -iquote $(src-perf)
 CFLAGS += -I$(srctree)/tools/lib/
 
 CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
tools/perf/tests/Build +3 -3
index 0ff8a97..f8888e8 100644
@@ -37,21 +37,21 @@ perf-y += topology.o
 
 $(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c
 	$(call rule_mkdir)
-	$(Q)echo '#include <tests/llvm.h>' > $@
+	$(Q)echo '#include "tests/llvm.h"' > $@
 	$(Q)echo 'const char test_llvm__bpf_base_prog[] =' >> $@
 	$(Q)sed -e 's/"/\\"/g' -e 's/\(.*\)/"\1\\n"/g' $< >> $@
 	$(Q)echo ';' >> $@
 
 $(OUTPUT)tests/llvm-src-kbuild.c: tests/bpf-script-test-kbuild.c
 	$(call rule_mkdir)
-	$(Q)echo '#include <tests/llvm.h>' > $@
+	$(Q)echo '#include "tests/llvm.h"' > $@
 	$(Q)echo 'const char test_llvm__bpf_test_kbuild_prog[] =' >> $@
 	$(Q)sed -e 's/"/\\"/g' -e 's/\(.*\)/"\1\\n"/g' $< >> $@
 	$(Q)echo ';' >> $@
 
 $(OUTPUT)tests/llvm-src-prologue.c: tests/bpf-script-test-prologue.c
 	$(call rule_mkdir)
-	$(Q)echo '#include <tests/llvm.h>' > $@
+	$(Q)echo '#include "tests/llvm.h"' > $@
 	$(Q)echo 'const char test_llvm__bpf_test_prologue_prog[] =' >> $@
 	$(Q)sed -e 's/"/\\"/g' -e 's/\(.*\)/"\1\\n"/g' $< >> $@
 	$(Q)echo ';' >> $@
tools/perf/tests/bpf.c +2 -2
index 33689a0..044a119 100644
@@ -1,7 +1,7 @@
 #include <stdio.h>
 #include <sys/epoll.h>
-#include <util/bpf-loader.h>
-#include <util/evlist.h>
+#include "util/bpf-loader.h"
+#include "util/evlist.h"
 #include "tests.h"
 #include "llvm.h"
 #include "debug.h"
tools/perf/tests/llvm.c +2 -2
index 06f45c1..dc90cea 100644
@@ -1,7 +1,7 @@
 #include <stdio.h>
 #include <bpf/libbpf.h>
-#include <util/llvm-utils.h>
-#include <util/cache.h>
+#include "util/llvm-utils.h"
+#include "util/cache.h"
 #include "llvm.h"
 #include "tests.h"
 #include "debug.h"
tools/perf/util/thread.h +2 -2
index a0ac031..f0d1035 100644
@@ -7,8 +7,8 @@
 #include <unistd.h>
 #include <sys/types.h>
 #include "symbol.h"
-#include <strlist.h>
-#include <intlist.h>
+#include "strlist.h"
+#include "intlist.h"
 
 struct thread_stack;
 
Signature · 1 line
2.4.3
#2 lore raw

PATCH 2/13 perf: Split up util.h

In reply to Josh Poimboeuf

util.h is a hodgepodge which consists of:

1) some compatibility macros and system includes
2) declarations for util.c
3) declarations for other .c files

Move the compatibility macros and system includes to compat-util.h. Move the declarations for other .c files to their respective proper locations, creating new header files where needed.

This makes the code better organized and will make it easier to untangle these pieces into separate components later.

---
 tools/perf/util/compat-util.h   | 130 +++++++++++++++++
 tools/perf/util/config.h        |   9 ++
 tools/perf/util/ctype.h         |  52 +++++++
 tools/perf/util/help.c          |   8 ++
 tools/perf/util/lzma.h          |   8 ++
 tools/perf/util/parse-options.c |   6 +
 tools/perf/util/srcline.h       |  16 +++
 tools/perf/util/strbuf.h        |   2 +
 tools/perf/util/string.h        |  34 +++++
 tools/perf/util/usage.h         |  23 +++
 tools/perf/util/util.h          | 302 ++--------------------------------------
 tools/perf/util/wrapper.h       |  14 ++
 tools/perf/util/zlib.h          |   8 ++
 13 files changed, 323 insertions(+), 289 deletions(-)
 create mode 100644 tools/perf/util/compat-util.h
 create mode 100644 tools/perf/util/config.h
 create mode 100644 tools/perf/util/ctype.h
 create mode 100644 tools/perf/util/lzma.h
 create mode 100644 tools/perf/util/srcline.h
 create mode 100644 tools/perf/util/string.h
 create mode 100644 tools/perf/util/usage.h
 create mode 100644 tools/perf/util/wrapper.h
 create mode 100644 tools/perf/util/zlib.h
tools/perf/util/compat-util.h new file +130 -0
new file mode 100644
index 0000000..f472a98
@@ -0,0 +1,130 @@
+#ifndef __PERF_COMPAT_UTIL_H
+#define __PERF_COMPAT_UTIL_H
+
+#ifndef FLEX_ARRAY
+/*
+ * See if our compiler is known to support flexible array members.
+ */
+#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
+# define FLEX_ARRAY /* empty */
+#elif defined(__GNUC__)
+# if (__GNUC__ >= 3)
+#  define FLEX_ARRAY /* empty */
+# else
+#  define FLEX_ARRAY 0 /* older GNU extension */
+# endif
+#endif
+
+/*
+ * Otherwise, default to safer but a bit wasteful traditional style
+ */
+#ifndef FLEX_ARRAY
+# define FLEX_ARRAY 1
+#endif
+#endif
+
+#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
+
+#ifdef __GNUC__
+#define TYPEOF(x) (__typeof__(x))
+#else
+#define TYPEOF(x)
+#endif
+
+#define MSB(x, bits) ((x) & TYPEOF(x)(~0ULL << (sizeof(x) * 8 - (bits))))
+#define HAS_MULTI_BITS(i)  ((i) & ((i) - 1))  /* checks if an integer has more than 1 bit set */
+
+/* Approximation of the length of the decimal representation of this type. */
+#define decimal_length(x)	((int)(sizeof(x) * 2.56 + 0.5) + 1)
+
+#define _ALL_SOURCE 1
+#define _BSD_SOURCE 1
+/* glibc 2.20 deprecates _BSD_SOURCE in favour of _DEFAULT_SOURCE */
+#define _DEFAULT_SOURCE 1
+#define HAS_BOOL
+
+#include <unistd.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <sys/statfs.h>
+#include <fcntl.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <errno.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/time.h>
+#include <time.h>
+#include <signal.h>
+#include <fnmatch.h>
+#include <assert.h>
+#include <regex.h>
+#include <utime.h>
+#include <sys/wait.h>
+#include <poll.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <inttypes.h>
+#include <linux/kernel.h>
+#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>
+
+/* On most systems <limits.h> would have given us this, but
+ * not on some systems (e.g. GNU/Hurd).
+ */
+#ifndef PATH_MAX
+#define PATH_MAX 4096
+#endif
+
+#ifndef PRIuMAX
+#define PRIuMAX "llu"
+#endif
+
+#ifndef PRIu32
+#define PRIu32 "u"
+#endif
+
+#ifndef PRIx32
+#define PRIx32 "x"
+#endif
+
+#ifndef PATH_SEP
+#define PATH_SEP ':'
+#endif
+
+#ifndef STRIP_EXTENSION
+#define STRIP_EXTENSION ""
+#endif
+
+#ifndef has_dos_drive_prefix
+#define has_dos_drive_prefix(path) 0
+#endif
+
+#ifndef is_dir_sep
+#define is_dir_sep(c) ((c) == '/')
+#endif
+
+#ifdef __GNUC__
+#define NORETURN __attribute__((__noreturn__))
+#else
+#define NORETURN
+#ifndef __attribute__
+#define __attribute__(x)
+#endif
+#endif
+
+#ifndef NSEC_PER_MSEC
+#define NSEC_PER_MSEC	1000000L
+#endif
+
+#endif /* __PERF_COMPAT_UTIL_H */
tools/perf/util/config.h new file +9 -0
new file mode 100644
index 0000000..d48c647
@@ -0,0 +1,9 @@
+#ifndef __PERF_CONFIG_H
+#define __PERF_CONFIG_H
+
+#define PERF_GTK_DSO  "libperf-gtk.so"
+
+extern char buildid_dir[];
+extern void set_buildid_dir(const char *dir);
+
+#endif /* __PERF_CONFIG_H */
tools/perf/util/ctype.h new file +52 -0

52 lines not on this page · raw message

tools/perf/util/help.c +8 -0
index fa1fc4a..29efb03 100644
@@ -114,6 +114,14 @@ static int is_executable(const char *name)
 	return st.st_mode & S_IXUSR;
 }
 
+static 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);
+}
+
 static void list_commands_in_dir(struct cmdnames *cmds,
 					 const char *path,
 					 const char *prefix)
tools/perf/util/lzma.h new file +8 -0
new file mode 100644
index 0000000..ef286e9
@@ -0,0 +1,8 @@
+#ifndef __PERF_LZMA_H
+#define __PERF_LZMA_H
+
+#ifdef HAVE_LZMA_SUPPORT
+int lzma_decompress_to_file(const char *input, int output_fd);
+#endif
+
+#endif /* __PERF_LZMA_H */
tools/perf/util/parse-options.c +6 -0
index 9fca092..29366ae 100644
@@ -9,6 +9,12 @@
 
 static struct strbuf error_buf = STRBUF_INIT;
 
+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 int opterror(const struct option *opt, const char *reason, int flags)
 {
 	if (flags & OPT_SHORT)
tools/perf/util/srcline.h new file +16 -0
new file mode 100644
index 0000000..ef57dc5
@@ -0,0 +1,16 @@
+#ifndef __PERF_SRCLINE_H
+#define __PERF_SRCLINE_H
+
+#define SRCLINE_UNKNOWN  ((char *) "??:0")
+
+struct dso;
+struct symbol;
+
+extern bool srcline_full_filename;
+char *get_srcline(struct dso *dso, u64 addr, struct symbol *sym,
+		  bool show_sym);
+char *__get_srcline(struct dso *dso, u64 addr, struct symbol *sym,
+		  bool show_sym, bool unwind_inlines);
+void free_srcline(char *srcline);
+
+#endif /* __PERF_SRCLINE_H */
tools/perf/util/strbuf.h +2 -0
index 529f2f0..39a1481 100644
@@ -50,6 +50,8 @@ struct strbuf {
 
 #define STRBUF_INIT  { 0, 0, strbuf_slopbuf }
 
+extern int prefixcmp(const char *str, const char *prefix);
+
 /*----- strbuf life cycle -----*/
 extern void strbuf_init(struct strbuf *buf, ssize_t hint);
 extern void strbuf_release(struct strbuf *);
tools/perf/util/string.h new file +34 -0
new file mode 100644
index 0000000..d124268
@@ -0,0 +1,34 @@
+#ifndef __PERF_STRING_H
+#define __PERF_STRING_H
+
+s64 perf_atoll(const char *str);
+char **argv_split(const char *str, int *argcp);
+void argv_free(char **argv);
+bool strglobmatch(const char *str, const char *pat);
+bool strlazymatch(const char *str, const char *pat);
+static inline bool strisglob(const char *str)
+{
+	return strpbrk(str, "*?[") != NULL;
+}
+int strtailcmp(const char *s1, const char *s2);
+char *strxfrchar(char *s, char from, char to);
+
+#define _STR(x) #x
+#define STR(x) _STR(x)
+
+char *ltrim(char *s);
+char *rtrim(char *s);
+
+char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints);
+
+static inline char *asprintf_expr_in_ints(const char *var, size_t nints, int *ints)
+{
+	return asprintf_expr_inout_ints(var, true, nints, ints);
+}
+
+static inline char *asprintf_expr_not_in_ints(const char *var, size_t nints, int *ints)
+{
+	return asprintf_expr_inout_ints(var, false, nints, ints);
+}
+
+#endif /* __PERF_STRING_H */
tools/perf/util/usage.h new file +23 -0
new file mode 100644
index 0000000..e3f1bd0
@@ -0,0 +1,23 @@
+#ifndef __PERF_USAGE_H
+#define __PERF_USAGE_H
+
+#include "compat-util.h"
+
+extern void usage(const char *err) NORETURN;
+extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));
+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"
+
+#define DIE_IF(cnd)	\
+	do { if (cnd)	\
+		die(" at (" __FILE__ ":" __stringify(__LINE__) "): "	\
+		    __stringify(cnd) "\n");				\
+	} while (0)
+
+
+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 */
tools/perf/util/util.h +13 -289

346 lines not on this page · raw message

tools/perf/util/wrapper.h new file +14 -0
new file mode 100644
index 0000000..510781b
@@ -0,0 +1,14 @@
+#ifndef __PERF_WRAPPER_H
+#define __PERF_WRAPPER_H
+
+extern char *xstrdup(const char *str);
+extern void *xrealloc(void *ptr, size_t size) __attribute__((weak));
+
+static inline void *zalloc(size_t size)
+{
+	return calloc(1, size);
+}
+
+#define zfree(ptr) ({ free(*ptr); *ptr = NULL; })
+
+#endif /* __PERF_WRAPPER_H */
tools/perf/util/zlib.h new file +8 -0
new file mode 100644
index 0000000..40ee6d8
@@ -0,0 +1,8 @@
+#ifndef __PERF_ZLIB_H
+#define __PERF_ZLIB_H
+
+#ifdef HAVE_ZLIB_SUPPORT
+int gzip_decompress_to_file(const char *input, int output_fd);
+#endif
+
+#endif /* __PERF_ZLIB_H */
Signature · 1 line
2.4.3
#3 lore raw

PATCH 3/13 perf: Move term functions out of util.c

In reply to Josh Poimboeuf

The term functions are needed by help.c which is going to be moved into a separate library. Move them out of util.c and into their own file.

---
 tools/perf/util/Build  |  1 +
 tools/perf/util/term.c | 35 +++++++++++++++++++++++++++++++++++
 tools/perf/util/term.h |  7 +++++++
 tools/perf/util/util.c | 34 ----------------------------------
 tools/perf/util/util.h |  4 +---
 5 files changed, 44 insertions(+), 37 deletions(-)
 create mode 100644 tools/perf/util/term.c
 create mode 100644 tools/perf/util/term.h
tools/perf/util/Build +1 -0
index 0513dd5..6c3bbd5 100644
@@ -87,6 +87,7 @@ 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-$(CONFIG_LIBBPF) += bpf-loader.o
 libperf-$(CONFIG_BPF_PROLOGUE) += bpf-prologue.o
tools/perf/util/term.c new file +35 -0
new file mode 100644
index 0000000..90b47d8
@@ -0,0 +1,35 @@
+#include "util.h"
+
+void get_term_dimensions(struct winsize *ws)
+{
+	char *s = getenv("LINES");
+
+	if (s != NULL) {
+		ws->ws_row = atoi(s);
+		s = getenv("COLUMNS");
+		if (s != NULL) {
+			ws->ws_col = atoi(s);
+			if (ws->ws_row && ws->ws_col)
+				return;
+		}
+	}
+#ifdef TIOCGWINSZ
+	if (ioctl(1, TIOCGWINSZ, ws) == 0 &&
+	    ws->ws_row && ws->ws_col)
+		return;
+#endif
+	ws->ws_row = 25;
+	ws->ws_col = 80;
+}
+
+void set_term_quiet_input(struct termios *old)
+{
+	struct termios tc;
+
+	tcgetattr(0, old);
+	tc = *old;
+	tc.c_lflag &= ~(ICANON | ECHO);
+	tc.c_cc[VMIN] = 0;
+	tc.c_cc[VTIME] = 0;
+	tcsetattr(0, TCSANOW, &tc);
+}
tools/perf/util/term.h new file +7 -0
new file mode 100644
index 0000000..7b13f46
@@ -0,0 +1,7 @@
+#ifndef __PERF_TERM_H
+#define __PERF_TERM_H
+
+void get_term_dimensions(struct winsize *ws);
+void set_term_quiet_input(struct termios *old);
+
+#endif /* __PERF_TERM_H */
tools/perf/util/util.c +0 -34
index 75759ae..07da970 100644
@@ -355,40 +355,6 @@ void sighandler_dump_stack(int sig)
 	exit(sig);
 }
 
-void get_term_dimensions(struct winsize *ws)
-{
-	char *s = getenv("LINES");
-
-	if (s != NULL) {
-		ws->ws_row = atoi(s);
-		s = getenv("COLUMNS");
-		if (s != NULL) {
-			ws->ws_col = atoi(s);
-			if (ws->ws_row && ws->ws_col)
-				return;
-		}
-	}
-#ifdef TIOCGWINSZ
-	if (ioctl(1, TIOCGWINSZ, ws) == 0 &&
-	    ws->ws_row && ws->ws_col)
-		return;
-#endif
-	ws->ws_row = 25;
-	ws->ws_col = 80;
-}
-
-void set_term_quiet_input(struct termios *old)
-{
-	struct termios tc;
-
-	tcgetattr(0, old);
-	tc = *old;
-	tc.c_lflag &= ~(ICANON | ECHO);
-	tc.c_cc[VMIN] = 0;
-	tc.c_cc[VTIME] = 0;
-	tcsetattr(0, TCSANOW, &tc);
-}
-
 int parse_nsec_time(const char *str, u64 *ptime)
 {
 	u64 time_sec, time_nsec;
tools/perf/util/util.h +1 -3
index cd0d9b0..d8e3d8d 100644
@@ -9,6 +9,7 @@
 #include "srcline.h"
 #include "strbuf.h"
 #include "string.h"
+#include "term.h"
 #include "usage.h"
 #include "wrapper.h"
 #include "zlib.h"
@@ -38,9 +39,6 @@ void sighandler_dump_stack(int sig);
 extern unsigned int page_size;
 extern int cacheline_size;
 
-void get_term_dimensions(struct winsize *ws);
-void set_term_quiet_input(struct termios *old);
-
 struct parse_tag {
 	char tag;
 	int mult;
Signature · 1 line
2.4.3
#4 lore raw

PATCH 4/13 perf: Remove unused pager_use_color variable

In reply to Josh Poimboeuf
---
 tools/perf/util/Build         | 1 -
 tools/perf/util/cache.h       | 1 -
 tools/perf/util/color.c       | 2 +-
 tools/perf/util/environment.c | 8 --------
 4 files changed, 1 insertion(+), 11 deletions(-)
 delete mode 100644 tools/perf/util/environment.c
tools/perf/util/Build +0 -1
index 6c3bbd5..65fef59 100644
@@ -6,7 +6,6 @@ libperf-y += config.o
 libperf-y += ctype.o
 libperf-y += db-export.o
 libperf-y += env.o
-libperf-y += environment.o
 libperf-y += event.o
 libperf-y += evlist.o
 libperf-y += evsel.o
tools/perf/util/cache.h +0 -1
index c861373..4c2b764 100644
@@ -31,7 +31,6 @@ extern const char *perf_config_dirname(const char *, const char *);
 /* pager.c */
 extern void setup_pager(void);
 extern int pager_in_use(void);
-extern int pager_use_color;
 
 char *alias_lookup(const char *alias);
 int split_cmdline(char *cmdline, const char ***argv);
tools/perf/util/color.c +1 -1
index 9b95654..e5fb88b 100644
@@ -24,7 +24,7 @@ int perf_config_colorbool(const char *var, const char *value, int stdout_is_tty)
  auto_color:
 	if (stdout_is_tty < 0)
 		stdout_is_tty = isatty(1);
-	if (stdout_is_tty || (pager_in_use() && pager_use_color)) {
+	if (stdout_is_tty || pager_in_use()) {
 		char *term = getenv("TERM");
 		if (term && strcmp(term, "dumb"))
 			return 1;
tools/perf/util/environment.c deleted +0 -8
deleted file mode 100644
index 7405123..0000000
@@ -1,8 +0,0 @@
-/*
- * We put all the perf config variables in this same object
- * file, so that programs can link against the config parser
- * without having to link against all the rest of perf.
- */
-#include "cache.h"
-
-int pager_use_color = 1;
Signature · 1 line
2.4.3
#5 lore raw

PATCH 5/13 perf: Split up cache.h

In reply to Josh Poimboeuf

cache.h is a hodgepodge which consists of:

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

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

---
 tools/perf/perf.h         | 12 ++++++++
 tools/perf/util/abspath.h | 11 ++++++++
 tools/perf/util/alias.h   |  7 +++++
 tools/perf/util/cache.h   | 72 ++++-------------------------------------------
 tools/perf/util/config.h  |  9 ++++++
 tools/perf/util/pager.h   |  7 +++++
 tools/perf/util/path.h    | 17 +++++++++++
 tools/perf/util/wrapper.h | 20 +++++++++++++
 8 files changed, 88 insertions(+), 67 deletions(-)
 create mode 100644 tools/perf/util/abspath.h
 create mode 100644 tools/perf/util/alias.h
 create mode 100644 tools/perf/util/pager.h
 create mode 100644 tools/perf/util/path.h
tools/perf/perf.h +12 -0
index 90129ac..501acb4 100644
@@ -6,6 +6,18 @@
 #include <linux/types.h>
 #include <linux/perf_event.h>
 
+#define CMD_EXEC_PATH "--exec-path"
+#define CMD_PERF_DIR "--perf-dir="
+#define CMD_WORK_TREE "--work-tree="
+#define CMD_DEBUGFS_DIR "--debugfs-dir="
+
+#define PERF_DIR_ENVIRONMENT "PERF_DIR"
+#define PERF_WORK_TREE_ENVIRONMENT "PERF_WORK_TREE"
+#define EXEC_PATH_ENVIRONMENT "PERF_EXEC_PATH"
+#define DEFAULT_PERF_DIR_ENVIRONMENT ".perf"
+#define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"
+#define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR"
+
 extern bool test_attr__enabled;
 void test_attr__init(void);
 void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu,
tools/perf/util/abspath.h new file +11 -0
new file mode 100644
index 0000000..13549fb
@@ -0,0 +1,11 @@
+#ifndef __PERF_ABSPATH_H
+#define __PERF_ABSPATH_H
+
+static inline int is_absolute_path(const char *path)
+{
+	return path[0] == '/';
+}
+
+const char *make_nonrelative_path(const char *path);
+
+#endif /* __PERF_ABSPATH_H */
tools/perf/util/alias.h new file +7 -0
new file mode 100644
index 0000000..23d4f84
@@ -0,0 +1,7 @@
+#ifndef __PERF_ALIAS_H
+#define __PERF_ALIAS_H
+
+char *alias_lookup(const char *alias);
+int split_cmdline(char *cmdline, const char ***argv);
+
+#endif /* __PERF_ALIAS_H */
tools/perf/util/cache.h +5 -67

77 lines not on this page · raw message

tools/perf/util/config.h +9 -0
index d48c647..8e53f6f 100644
@@ -6,4 +6,13 @@
 extern char buildid_dir[];
 extern void set_buildid_dir(const char *dir);
 
+typedef int (*config_fn_t)(const char *, const char *, void *);
+extern int perf_default_config(const char *, const char *, void *);
+extern int perf_config(config_fn_t fn, void *);
+extern int perf_config_int(const char *, const char *);
+extern u64 perf_config_u64(const char *, const char *);
+extern int perf_config_bool(const char *, const char *);
+extern int config_error_nonbool(const char *);
+extern const char *perf_config_dirname(const char *, const char *);
+
 #endif /* __PERF_CONFIG_H */
tools/perf/util/pager.h new file +7 -0
new file mode 100644
index 0000000..2794a83
@@ -0,0 +1,7 @@
+#ifndef __PERF_PAGER_H
+#define __PERF_PAGER_H
+
+extern void setup_pager(void);
+extern int pager_in_use(void);
+
+#endif /* __PERF_PAGER_H */
tools/perf/util/path.h new file +17 -0
new file mode 100644
index 0000000..3604e82f
@@ -0,0 +1,17 @@
+#ifndef __PERF_PATH_H
+#define __PERF_PATH_H
+
+char *strip_path_suffix(const char *path, const char *suffix);
+
+extern char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
+extern char *perf_path(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
+
+extern char *perf_pathdup(const char *fmt, ...)
+	__attribute__((format (printf, 1, 2)));
+
+#ifndef __UCLIBC__
+/* Matches the libc/libbsd function attribute so we declare this unconditionally: */
+extern size_t strlcpy(char *dest, const char *src, size_t size);
+#endif
+
+#endif /* __PERF_PATH_H */
tools/perf/util/wrapper.h +20 -0
index 510781b..e2fa014 100644
@@ -11,4 +11,24 @@ static inline void *zalloc(size_t size)
 
 #define zfree(ptr) ({ free(*ptr); *ptr = NULL; })
 
+#define alloc_nr(x) (((x)+16)*3/2)
+
+/*
+ * Realloc the buffer pointed at by variable 'x' so that it can hold
+ * at least 'nr' entries; the number of entries currently allocated
+ * is 'alloc', using the standard growing factor alloc_nr() macro.
+ *
+ * DO NOT USE any expression with side-effect for 'x' or 'alloc'.
+ */
+#define ALLOC_GROW(x, nr, alloc) \
+	do { \
+		if ((nr) > alloc) { \
+			if (alloc_nr(alloc) < (nr)) \
+				alloc = (nr); \
+			else \
+				alloc = alloc_nr(alloc); \
+			x = xrealloc((x), alloc * sizeof(*(x))); \
+		} \
+	} while(0)
+
 #endif /* __PERF_WRAPPER_H */
Signature · 1 line
2.4.3
#6 lore raw

PATCH 6/13 perf: Remove cache.h

In reply to Josh Poimboeuf

cache.h is now just a collection of some commonly used includes. Move the includes to util.h, which has a similar collection.

---
 tools/perf/builtin-annotate.c                       |  1 -
 tools/perf/builtin-buildid-cache.c                  |  2 +-
 tools/perf/builtin-buildid-list.c                   |  2 +-
 tools/perf/builtin-config.c                         |  3 +--
 tools/perf/builtin-help.c                           |  2 +-
 tools/perf/builtin-kmem.c                           |  1 -
 tools/perf/builtin-kvm.c                            |  1 -
 tools/perf/builtin-list.c                           |  2 +-
 tools/perf/builtin-lock.c                           |  1 -
 tools/perf/builtin-report.c                         |  1 -
 tools/perf/builtin-sched.c                          |  1 -
 tools/perf/builtin-script.c                         |  1 -
 tools/perf/builtin-timechart.c                      |  1 -
 tools/perf/builtin-top.c                            |  1 -
 tools/perf/perf.c                                   |  2 +-
 tools/perf/tests/llvm.c                             |  2 +-
 tools/perf/ui/browser.c                             |  1 -
 tools/perf/ui/browsers/header.c                     |  2 +-
 tools/perf/ui/gtk/browser.c                         |  2 +-
 tools/perf/ui/gtk/hists.c                           |  2 +-
 tools/perf/ui/gtk/setup.c                           |  2 +-
 tools/perf/ui/helpline.h                            |  2 +-
 tools/perf/ui/progress.c                            |  2 +-
 tools/perf/ui/setup.c                               |  2 +-
 tools/perf/ui/tui/progress.c                        |  2 +-
 tools/perf/ui/tui/setup.c                           |  1 -
 tools/perf/ui/tui/util.c                            |  1 -
 tools/perf/util/abspath.c                           |  2 +-
 tools/perf/util/alias.c                             |  2 +-
 tools/perf/util/annotate.c                          |  1 -
 tools/perf/util/cache.h                             | 16 ----------------
 tools/perf/util/color.c                             |  2 +-
 tools/perf/util/config.c                            |  1 -
 tools/perf/util/debug.c                             |  1 -
 tools/perf/util/exec_cmd.c                          |  2 +-
 tools/perf/util/help.c                              |  2 +-
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c |  1 -
 tools/perf/util/levenshtein.c                       |  2 +-
 tools/perf/util/llvm-utils.c                        |  1 -
 tools/perf/util/pager.c                             |  2 +-
 tools/perf/util/parse-events.c                      |  1 -
 tools/perf/util/parse-options.c                     |  1 -
 tools/perf/util/path.c                              |  2 +-
 tools/perf/util/probe-event.c                       |  1 -
 tools/perf/util/probe-file.c                        |  1 -
 tools/perf/util/quote.c                             |  2 +-
 tools/perf/util/run-command.c                       |  2 +-
 tools/perf/util/sigchain.c                          |  2 +-
 tools/perf/util/sort.h                              |  1 -
 tools/perf/util/strbuf.c                            |  2 +-
 tools/perf/util/util.h                              |  6 ++++++
 tools/perf/util/wrapper.c                           |  2 +-
 52 files changed, 34 insertions(+), 67 deletions(-)
 delete mode 100644 tools/perf/util/cache.h
tools/perf/builtin-annotate.c +0 -1
index 2bf9b3f..50695c7 100644
@@ -10,7 +10,6 @@
 #include "util/util.h"
 #include "util/color.h"
 #include <linux/list.h>
-#include "util/cache.h"
 #include <linux/rbtree.h>
 #include "util/symbol.h"
 
tools/perf/builtin-buildid-cache.c +1 -1
index 7b8450c..bed484f 100644
@@ -13,7 +13,7 @@
 #include <unistd.h>
 #include "builtin.h"
 #include "perf.h"
-#include "util/cache.h"
+#include "util/util.h"
 #include "util/debug.h"
 #include "util/header.h"
 #include "util/parse-options.h"
tools/perf/builtin-buildid-list.c +1 -1
index 918b4de..bd7558e 100644
@@ -10,7 +10,7 @@
 #include "builtin.h"
 #include "perf.h"
 #include "util/build-id.h"
-#include "util/cache.h"
+#include "util/util.h"
 #include "util/debug.h"
 #include "util/parse-options.h"
 #include "util/session.h"
tools/perf/builtin-config.c +1 -2
index 427ea7a..03117c8 100644
@@ -8,9 +8,8 @@
 
 #include "perf.h"
 
-#include "util/cache.h"
-#include "util/parse-options.h"
 #include "util/util.h"
+#include "util/parse-options.h"
 #include "util/debug.h"
 
 static const char * const config_usage[] = {
tools/perf/builtin-help.c +1 -1
index a7d588b..23c3fdb 100644
@@ -4,7 +4,7 @@
  * Builtin help command
  */
 #include "perf.h"
-#include "util/cache.h"
+#include "util/util.h"
 #include "builtin.h"
 #include "util/exec_cmd.h"
 #include "common-cmds.h"
tools/perf/builtin-kmem.c +0 -1
index 93ce665..1c3d3d9 100644
@@ -4,7 +4,6 @@
 #include "util/evlist.h"
 #include "util/evsel.h"
 #include "util/util.h"
-#include "util/cache.h"
 #include "util/symbol.h"
 #include "util/thread.h"
 #include "util/header.h"
tools/perf/builtin-kvm.c +0 -1
index dd94b4c..a9ad326 100644
@@ -4,7 +4,6 @@
 #include "util/evsel.h"
 #include "util/evlist.h"
 #include "util/util.h"
-#include "util/cache.h"
 #include "util/symbol.h"
 #include "util/thread.h"
 #include "util/header.h"
tools/perf/builtin-list.c +1 -1
index bf679e2..70856ac 100644
@@ -12,7 +12,7 @@
 #include "perf.h"
 
 #include "util/parse-events.h"
-#include "util/cache.h"
+#include "util/util.h"
 #include "util/pmu.h"
 #include "util/parse-options.h"
 
tools/perf/builtin-lock.c +0 -1
index de16aae..191d32f 100644
@@ -4,7 +4,6 @@
 #include "util/evlist.h"
 #include "util/evsel.h"
 #include "util/util.h"
-#include "util/cache.h"
 #include "util/symbol.h"
 #include "util/thread.h"
 #include "util/header.h"
tools/perf/builtin-report.c +0 -1
index af5db88..61ed8f2 100644
@@ -8,7 +8,6 @@
 #include "builtin.h"
 
 #include "util/util.h"
-#include "util/cache.h"
 
 #include "util/annotate.h"
 #include "util/color.h"
tools/perf/builtin-sched.c +0 -1
index e3d3e32..43dedd4 100644
@@ -3,7 +3,6 @@
 
 #include "util/util.h"
 #include "util/evlist.h"
-#include "util/cache.h"
 #include "util/evsel.h"
 #include "util/symbol.h"
 #include "util/thread.h"
tools/perf/builtin-script.c +0 -1
index 3c3f8d0..8873021 100644
@@ -1,7 +1,6 @@
 #include "builtin.h"
 
 #include "perf.h"
-#include "util/cache.h"
 #include "util/debug.h"
 #include "util/exec_cmd.h"
 #include "util/header.h"
tools/perf/builtin-timechart.c +0 -1
index 30e5962..ab75e5b 100644
@@ -20,7 +20,6 @@
 
 #include "util/color.h"
 #include <linux/list.h>
-#include "util/cache.h"
 #include "util/evlist.h"
 #include "util/evsel.h"
 #include <linux/rbtree.h>
tools/perf/builtin-top.c +0 -1
index 7e2e72e..c8dd628 100644
@@ -22,7 +22,6 @@
 #include "perf.h"
 
 #include "util/annotate.h"
-#include "util/cache.h"
 #include "util/color.h"
 #include "util/evlist.h"
 #include "util/evsel.h"
tools/perf/perf.c +1 -1
index 4bee53c..bcf4fab 100644
@@ -10,7 +10,7 @@
 
 #include "util/env.h"
 #include "util/exec_cmd.h"
-#include "util/cache.h"
+#include "util/util.h"
 #include "util/quote.h"
 #include "util/run-command.h"
 #include "util/parse-events.h"
tools/perf/tests/llvm.c +1 -1
index dc90cea..fdb7e84 100644
@@ -1,7 +1,7 @@
 #include <stdio.h>
 #include <bpf/libbpf.h>
 #include "util/llvm-utils.h"
-#include "util/cache.h"
+#include "util/util.h"
 #include "llvm.h"
 #include "tests.h"
 #include "debug.h"
tools/perf/ui/browser.c +0 -1
index e9703c0..97b570d 100644
@@ -1,5 +1,4 @@
 #include "../util.h"
-#include "../cache.h"
 #include "../../perf.h"
 #include "libslang.h"
 #include "ui.h"
tools/perf/ui/browsers/header.c +1 -1
index edbeaaf..d4c9fac 100644
@@ -1,4 +1,4 @@
-#include "util/cache.h"
+#include "util/util.h"
 #include "util/debug.h"
 #include "ui/browser.h"
 #include "ui/keysyms.h"
tools/perf/ui/gtk/browser.c +1 -1
index c24d912..4305b1b 100644
@@ -1,5 +1,5 @@
 #include "../evlist.h"
-#include "../cache.h"
+#include "../util.h"
 #include "../evsel.h"
 #include "../sort.h"
 #include "../hist.h"
tools/perf/ui/gtk/hists.c +1 -1
index 4677172..9f3db1f 100644
@@ -1,5 +1,5 @@
 #include "../evlist.h"
-#include "../cache.h"
+#include "../util.h"
 #include "../evsel.h"
 #include "../sort.h"
 #include "../hist.h"
tools/perf/ui/gtk/setup.c +1 -1
index 1d57676..562a800 100644
@@ -1,5 +1,5 @@
 #include "gtk.h"
-#include "../../util/cache.h"
+#include "../../util/util.h"
 #include "../../util/debug.h"
 
 extern struct perf_error_ops perf_gtk_eops;
tools/perf/ui/helpline.h +1 -1
index 46181f4..66901b2 100644
@@ -4,7 +4,7 @@
 #include <stdio.h>
 #include <stdarg.h>
 
-#include "../util/cache.h"
+#include "../util/util.h"
 
 struct ui_helpline {
 	void (*pop)(void);
tools/perf/ui/progress.c +1 -1
index a0f24c7..8857f99 100644
@@ -1,4 +1,4 @@
-#include "../cache.h"
+#include "../util.h"
 #include "progress.h"
 
 static void null_progress__update(struct ui_progress *p __maybe_unused)
tools/perf/ui/setup.c +1 -1
index ba51fa8..df4bd94 100644
@@ -1,7 +1,7 @@
 #include <pthread.h>
 #include <dlfcn.h>
 
-#include "../util/cache.h"
+#include "../util/util.h"
 #include "../util/debug.h"
 #include "../util/hist.h"
 
tools/perf/ui/tui/progress.c +1 -1
index c4b9900..89df2eb 100644
@@ -1,4 +1,4 @@
-#include "../cache.h"
+#include "../util.h"
 #include "../progress.h"
 #include "../libslang.h"
 #include "../ui.h"
tools/perf/ui/tui/setup.c +0 -1
index 7dfeba0..b498733 100644
@@ -4,7 +4,6 @@
 #include <execinfo.h>
 #endif
 
-#include "../../util/cache.h"
 #include "../../util/debug.h"
 #include "../browser.h"
 #include "../helpline.h"
tools/perf/ui/tui/util.c +0 -1
index d96ad7c..c2de719 100644
@@ -4,7 +4,6 @@
 #include <string.h>
 #include <sys/ttydefaults.h>
 
-#include "../../util/cache.h"
 #include "../../util/debug.h"
 #include "../browser.h"
 #include "../keysyms.h"
tools/perf/util/abspath.c +1 -1
index 0e76aff..eab5d85 100644
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "util.h"
 
 static const char *get_pwd_cwd(void)
 {
tools/perf/util/alias.c +1 -1
index c0b43ee..f905664 100644
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "util.h"
 
 static const char *alias_key;
 static char *alias_val;
tools/perf/util/annotate.c +0 -1
index 1dd1949..2ab2407 100644
@@ -12,7 +12,6 @@
 #include "sort.h"
 #include "build-id.h"
 #include "color.h"
-#include "cache.h"
 #include "symbol.h"
 #include "debug.h"
 #include "annotate.h"
tools/perf/util/cache.h deleted +0 -16
deleted file mode 100644
index 32e1f52..0000000
@@ -1,16 +0,0 @@
-#ifndef __PERF_CACHE_H
-#define __PERF_CACHE_H
-
-#include <stdbool.h>
-#include "util.h"
-#include "strbuf.h"
-#include "../perf.h"
-#include "../ui/ui.h"
-
-#include "abspath.h"
-#include "alias.h"
-#include "config.h"
-#include "pager.h"
-#include "path.h"
-
-#endif /* __PERF_CACHE_H */
tools/perf/util/color.c +1 -1
index e5fb88b..f436c12 100644
@@ -1,5 +1,5 @@
 #include <linux/kernel.h>
-#include "cache.h"
+#include "util.h"
 #include "color.h"
 #include <math.h>
 
tools/perf/util/config.c +0 -1
index 2e452ac..6b9e91f 100644
@@ -9,7 +9,6 @@
  *
  */
 #include "util.h"
-#include "cache.h"
 #include "exec_cmd.h"
 #include "util/hist.h"  /* perf_hist_config */
 #include "util/llvm-utils.h"   /* perf_llvm_config */
tools/perf/util/debug.c +0 -1
index 86d9c73..8931f4e 100644
@@ -6,7 +6,6 @@
 #include <stdarg.h>
 #include <stdio.h>
 
-#include "cache.h"
 #include "color.h"
 #include "event.h"
 #include "debug.h"
tools/perf/util/exec_cmd.c +1 -1
index 1099e92..8d5661e 100644
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "util.h"
 #include "exec_cmd.h"
 #include "quote.h"
 
tools/perf/util/help.c +1 -1
index 29efb03..2d5e304 100644
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "util.h"
 #include "../builtin.h"
 #include "exec_cmd.h"
 #include "levenshtein.h"
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +0 -1
index 9409d01..697ed0a 100644
@@ -23,7 +23,6 @@
 #include <stdint.h>
 #include <inttypes.h>
 
-#include "../cache.h"
 #include "../util.h"
 
 #include "intel-pt-insn-decoder.h"
tools/perf/util/levenshtein.c +1 -1
index e521d15..61bb371 100644
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "util.h"
 #include "levenshtein.h"
 
 /*
tools/perf/util/llvm-utils.c +0 -1
index 00724d4..5f02deb 100644
@@ -7,7 +7,6 @@
 #include "util.h"
 #include "debug.h"
 #include "llvm-utils.h"
-#include "cache.h"
 
 #define CLANG_BPF_CMD_DEFAULT_TEMPLATE				\
 		"$CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS "\
tools/perf/util/pager.c +1 -1
index 53ef006..bb19546 100644
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "util.h"
 #include "run-command.h"
 #include "sigchain.h"
 
tools/perf/util/parse-events.c +0 -1
index 6fc8cd7..d2ec59d 100644
@@ -9,7 +9,6 @@
 #include "exec_cmd.h"
 #include "string.h"
 #include "symbol.h"
-#include "cache.h"
 #include "header.h"
 #include "bpf-loader.h"
 #include "debug.h"
tools/perf/util/parse-options.c +0 -1
index 29366ae..9937e91 100644
@@ -1,6 +1,5 @@
 #include "util.h"
 #include "parse-options.h"
-#include "cache.h"
 #include "header.h"
 #include <linux/string.h>
 
tools/perf/util/path.c +1 -1
index 5d13cb4..1e22ac0 100644
@@ -10,7 +10,7 @@
  *
  * which is what it's designed for.
  */
-#include "cache.h"
+#include "util.h"
 
 static char bad_path[] = "/bad-path/";
 /*
tools/perf/util/probe-event.c +0 -1
index 93996ec..388fec5 100644
@@ -36,7 +36,6 @@
 #include "event.h"
 #include "strlist.h"
 #include "debug.h"
-#include "cache.h"
 #include "color.h"
 #include "symbol.h"
 #include "thread.h"
tools/perf/util/probe-file.c +0 -1
index e3b3b92..724a6ce 100644
@@ -18,7 +18,6 @@
 #include "event.h"
 #include "strlist.h"
 #include "debug.h"
-#include "cache.h"
 #include "color.h"
 #include "symbol.h"
 #include "thread.h"
tools/perf/util/quote.c +1 -1
index 01f0324..57ed644 100644
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "util.h"
 #include "quote.h"
 
 /* Help to copy the thing properly quoted for the shell safety.
tools/perf/util/run-command.c +1 -1
index 34622b5..38d2cc6 100644
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "util.h"
 #include "run-command.h"
 #include "exec_cmd.h"
 #include "debug.h"
tools/perf/util/sigchain.c +1 -1
index ba785e9..5eebf88 100644
@@ -1,5 +1,5 @@
+#include "util.h"
 #include "sigchain.h"
-#include "cache.h"
 
 #define SIGCHAIN_MAX_SIGNALS 32
 
tools/perf/util/sort.h +0 -1
index 3122885..139a566 100644
@@ -6,7 +6,6 @@
 
 #include "color.h"
 #include <linux/list.h>
-#include "cache.h"
 #include <linux/rbtree.h>
 #include "symbol.h"
 #include "string.h"
tools/perf/util/strbuf.c +1 -1
index 25671fa..0e53793 100644
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "util.h"
 #include <linux/kernel.h>
 
 int prefixcmp(const char *str, const char *prefix)
tools/perf/util/util.h +6 -0
index d8e3d8d..c7b50d5 100644
@@ -3,13 +3,19 @@
 
 #include "compat-util.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"
tools/perf/util/wrapper.c +1 -1
index 19f15b6..861ecfa 100644
@@ -1,7 +1,7 @@
 /*
  * Various trivial helper wrappers around standard functions
  */
-#include "cache.h"
+#include "util.h"
 
 /*
  * There's no pack memory to release - but stay close to the Git
Signature · 1 line
2.4.3
#7 lore raw

PATCH 7/13 perf: Save cmdline arguments earlier

In reply to Josh Poimboeuf

perf_env__set_cmdline() only saves the arguments the first time it's called. It doesn't need to be called every time the options and suboptions are parsed. Instead it can just be called once.

This also has the advantage of making the option parsing code less perf-specific so it can be moved out to a library.

---
 tools/perf/perf.c               | 1 +
 tools/perf/util/env.c           | 9 ---------
 tools/perf/util/parse-options.c | 2 --
 3 files changed, 1 insertion(+), 11 deletions(-)
tools/perf/perf.c +1 -0
index bcf4fab..c57e447 100644
@@ -384,6 +384,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
 		use_pager = 1;
 	commit_pager_choice();
 
+	perf_env__set_cmdline(&perf_env, argc, argv);
 	status = p->fn(argc, argv, prefix);
 	exit_browser(status);
 	perf_env__exit(&perf_env);
tools/perf/util/env.c +0 -9
index 6af4f7c..7dd5939 100644
@@ -25,15 +25,6 @@ int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[])
 {
 	int i;
 
-	/*
-	 * If env->cmdline_argv has already been set, do not override it.  This allows
-	 * a command to set the cmdline, parse args and then call another
-	 * builtin function that implements a command -- e.g, cmd_kvm calling
-	 * cmd_record.
-	 */
-	if (env->cmdline_argv != NULL)
-		return 0;
-
 	/* do not include NULL termination */
 	env->cmdline_argv = calloc(argc, sizeof(char *));
 	if (env->cmdline_argv == NULL)
tools/perf/util/parse-options.c +0 -2
index 9937e91..735c8c8 100644
@@ -506,8 +506,6 @@ int parse_options_subcommand(int argc, const char **argv, const struct option *o
 {
 	struct parse_opt_ctx_t ctx;
 
-	perf_env__set_cmdline(&perf_env, argc, argv);
-
 	/* build usage string if it's not provided */
 	if (subcommands && !usagestr[0]) {
 		struct strbuf buf = STRBUF_INIT;
Signature · 1 line
2.4.3
#8 lore raw

PATCH 8/13 perf: Remove check for unused PERF_PAGER_IN_USE

In reply to Josh Poimboeuf

PERF_PAGER_IN_USE doesn't seem to be used anywhere, so let's remove it.

This will also make it easier to move pager.c into a separate library.

---
 tools/perf/util/pager.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
tools/perf/util/pager.c +1 -7
index bb19546..6cff2ac 100644
@@ -85,11 +85,5 @@ void setup_pager(void)
 
 int pager_in_use(void)
 {
-	const char *env;
-
-	if (spawned_pager)
-		return 1;
-
-	env = getenv("PERF_PAGER_IN_USE");
-	return env ? perf_config_bool("PERF_PAGER_IN_USE", env) : 0;
+	return spawned_pager;
 }
Signature · 1 line
2.4.3
#9 lore raw

PATCH 9/13 perf: Move cmd_version() to builtin-version.c

In reply to Josh Poimboeuf

Move cmd_version() to its own file so that help.c can be moved to a library.

---
 tools/perf/Build             | 1 +
 tools/perf/builtin-version.c | 9 +++++++++
 tools/perf/util/help.c       | 7 -------
 3 files changed, 10 insertions(+), 7 deletions(-)
 create mode 100644 tools/perf/builtin-version.c
tools/perf/Build +1 -0
index 2c7aaf2..2a41217 100644
@@ -20,6 +20,7 @@ perf-y += builtin-kvm.o
 perf-y += builtin-inject.o
 perf-y += builtin-mem.o
 perf-y += builtin-data.o
+perf-y += builtin-version.o
 
 perf-$(CONFIG_AUDIT) += builtin-trace.o
 perf-$(CONFIG_LIBELF) += builtin-probe.o
tools/perf/builtin-version.c new file +9 -0
new file mode 100644
index 0000000..0587ec6
@@ -0,0 +1,9 @@
+#include "util/util.h"
+#include "builtin.h"
+
+int cmd_version(int argc __maybe_unused, const char **argv __maybe_unused,
+		const char *prefix __maybe_unused)
+{
+	printf("perf version %s\n", perf_version_string);
+	return 0;
+}
tools/perf/util/help.c +0 -7
index 2d5e304..573ce05 100644
@@ -340,10 +340,3 @@ const char *help_unknown_cmd(const char *cmd)
 
 	exit(1);
 }
-
-int cmd_version(int argc __maybe_unused, const char **argv __maybe_unused,
-		const char *prefix __maybe_unused)
-{
-	printf("perf version %s\n", perf_version_string);
-	return 0;
-}
Signature · 1 line
2.4.3
#10 lore raw

PATCH 10/13 perf: Move help_unknown_cmd() to its own file

In reply to Josh Poimboeuf

help_unknown_cmd() is quite perf-specific because it relies on some perf_config*() functions. Move it and its supporting functions out into a separate file so that help.c can be moved to a library.

---
 tools/perf/util/Build              |   1 +
 tools/perf/util/help-unknown-cmd.c | 103 +++++++++++++++++++++++++++++++++++
 tools/perf/util/help-unknown-cmd.h |   0
 tools/perf/util/help.c             | 108 ++-----------------------------------
 tools/perf/util/help.h             |   3 ++
 5 files changed, 110 insertions(+), 105 deletions(-)
 create mode 100644 tools/perf/util/help-unknown-cmd.c
 create mode 100644 tools/perf/util/help-unknown-cmd.h
tools/perf/util/Build +1 -0
index 65fef59..99b3dae 100644
@@ -87,6 +87,7 @@ 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
 libperf-$(CONFIG_BPF_PROLOGUE) += bpf-prologue.o
tools/perf/util/help-unknown-cmd.c new file +103 -0

103 lines not on this page · raw message

tools/perf/util/help-unknown-cmd.h new file +0 -0
new file mode 100644
index 0000000..e69de29
tools/perf/util/help.c +3 -105

135 lines not on this page · raw message

tools/perf/util/help.h +3 -0
index 7f5c6de..14851b0 100644
@@ -20,6 +20,9 @@ void load_command_list(const char *prefix,
 		struct cmdnames *main_cmds,
 		struct cmdnames *other_cmds);
 void add_cmdname(struct cmdnames *cmds, const char *name, size_t len);
+void clean_cmdnames(struct cmdnames *cmds);
+int cmdname_compare(const void *a, const void *b);
+void uniq(struct cmdnames *cmds);
 /* Here we require that excludes is a sorted list. */
 void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes);
 int is_in_cmdlist(struct cmdnames *c, const char *s);
Signature · 1 line
2.4.3
#11 lore raw

PATCH 11/13 perf tools: Move strlcpy() to tools/lib/string.c

In reply to Josh Poimboeuf

Move strlcpy() to tools/lib/string.c so it can be used by other tools, namely abspath.c which is getting moved to a library.

---
 tools/include/linux/string.h |  5 +++++
 tools/lib/string.c           | 19 +++++++++++++++++++
 tools/perf/util/path.c       | 18 ------------------
 tools/perf/util/path.h       |  5 -----
 tools/perf/util/util.h       |  1 +
 5 files changed, 25 insertions(+), 23 deletions(-)
tools/include/linux/string.h +5 -0
index 2e2f736..eae1d87 100644
@@ -8,4 +8,9 @@ void *memdup(const void *src, size_t len);
 
 int strtobool(const char *s, bool *res);
 
+#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 /* _LINUX_STRING_H_ */
tools/lib/string.c +19 -0
index 065e54f..3366582 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,21 @@ int strtobool(const char *s, bool *res)
 	}
 	return 0;
 }
+
+/*
+ * 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/path.c +0 -18
index 1e22ac0..416fe7d 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];
tools/perf/util/path.h +0 -5
index 3604e82f..1df12e7 100644
@@ -9,9 +9,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_PATH_H */
tools/perf/util/util.h +1 -0
index c7b50d5..2c6db35 100644
@@ -3,6 +3,7 @@
 
 #include "compat-util.h"
 
+#include <linux/string.h>
 #include "../perf.h"
 #include "abspath.h"
 #include "alias.h"
Signature · 1 line
2.4.3
#12 lore raw

PATCH 12/13 perf tools: Move perf subcommand framework into a library

In reply to Josh Poimboeuf

The perf subcommand framework will soon be needed by stacktool. Move parse-options.c, run-command.c, exec_cmd.c, help.c, usage.c, and their dependencies over to libapi in 'tools/lib/api/util'.

Functions with 'perf' in their name have been given more generic names.

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.

---
 tools/lib/api/Build                              |  1 +
 tools/lib/api/string/Build                       |  1 +
 tools/lib/{ => api/string}/string.c              |  7 ++++---
 tools/{include/linux => lib/api/string}/string.h | 10 +++++-----
 tools/perf/MANIFEST                              |  2 --
 tools/perf/builtin-kmem.c                        |  2 +-
 tools/perf/util/Build                            |  6 ------
 tools/perf/util/auxtrace.c                       |  2 +-
 tools/perf/util/bpf-loader.c                     |  2 +-
 tools/perf/util/intel-pt-decoder/insn.c          |  2 +-
 tools/perf/util/map.c                            |  2 +-
 tools/perf/util/ordered-events.c                 |  2 +-
 tools/perf/util/parse-options.c                  |  2 +-
 tools/perf/util/util.h                           |  2 +-
 14 files changed, 19 insertions(+), 24 deletions(-)
 create mode 100644 tools/lib/api/string/Build
 rename tools/lib/{ => api/string}/string.c (93%)
 rename tools/{include/linux => lib/api/string}/string.h (66%)
tools/lib/api/Build +1 -0
index e8b8a23..9e3967e 100644
@@ -1,3 +1,4 @@
 libapi-y += fd/
 libapi-y += fs/
 libapi-y += cpu.o
+libapi-y += string/
tools/lib/api/string/Build new file +1 -0
new file mode 100644
index 0000000..7707d3d
@@ -0,0 +1 @@
+libapi-y += string.o
tools/lib/api/string/string.c renamed from tools/lib/string.c +4 -3
similarity index 93%
rename from tools/lib/string.c
rename to tools/lib/api/string/string.c
index 3366582..3140ba3 100644
@@ -1,5 +1,5 @@
 /*
- *  linux/tools/lib/string.c
+ *  linux/tools/lib/api/string/string.c
  *
  *  Copied from linux/lib/string.c, where it is:
  *
@@ -15,8 +15,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
-#include <linux/string.h>
-#include <linux/compiler.h>
+#include "string.h"
+
+#define __weak __attribute__((weak))
 
 /**
  * memdup - duplicate region of memory
tools/lib/api/string/string.h renamed from tools/include/linux/string.h +5 -5
similarity index 66%
rename from tools/include/linux/string.h
rename to tools/lib/api/string/string.h
index eae1d87..74bd4fd 100644
@@ -1,8 +1,8 @@
-#ifndef _TOOLS_LINUX_STRING_H_
-#define _TOOLS_LINUX_STRING_H_
+#ifndef _API_STRING_H
+#define _API_STRING_H
 
-
-#include <linux/types.h>	/* for size_t */
+#include <stddef.h>
+#include <stdbool.h>
 
 void *memdup(const void *src, size_t len);
 
@@ -13,4 +13,4 @@ int strtobool(const char *s, bool *res);
 extern size_t strlcpy(char *dest, const char *src, size_t size);
 #endif
 
-#endif /* _LINUX_STRING_H_ */
+#endif /* _API_STRING_H */
tools/perf/MANIFEST +0 -2
index 2562eac..39c38cb 100644
@@ -22,7 +22,6 @@ tools/lib/api
 tools/lib/bpf
 tools/lib/hweight.c
 tools/lib/rbtree.c
-tools/lib/string.c
 tools/lib/symbol/kallsyms.c
 tools/lib/symbol/kallsyms.h
 tools/lib/util/find_next_bit.c
@@ -51,7 +50,6 @@ tools/include/linux/log2.h
 tools/include/linux/poison.h
 tools/include/linux/rbtree.h
 tools/include/linux/rbtree_augmented.h
-tools/include/linux/string.h
 tools/include/linux/types.h
 tools/include/linux/err.h
 include/asm-generic/bitops/arch_hweight.h
tools/perf/builtin-kmem.c +1 -1
index 1c3d3d9..cdf487b 100644
@@ -19,7 +19,7 @@
 #include "util/debug.h"
 
 #include <linux/rbtree.h>
-#include <linux/string.h>
+#include <api/string/string.h>
 #include <locale.h>
 #include <regex.h>
 
tools/perf/util/Build +0 -6
index 99b3dae..02d3a54 100644
@@ -20,7 +20,6 @@ libperf-y += parse-events.o
 libperf-y += perf_regs.o
 libperf-y += path.o
 libperf-y += rbtree.o
-libperf-y += libstring.o
 libperf-y += bitmap.o
 libperf-y += hweight.o
 libperf-y += run-command.o
@@ -141,7 +140,6 @@ $(OUTPUT)util/pmu.o: $(OUTPUT)util/pmu-flex.c $(OUTPUT)util/pmu-bison.c
 
 CFLAGS_find_next_bit.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
 CFLAGS_rbtree.o        += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
-CFLAGS_libstring.o     += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
 CFLAGS_hweight.o       += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
 CFLAGS_parse-events.o  += -Wno-redundant-decls
 
@@ -157,10 +155,6 @@ $(OUTPUT)util/rbtree.o: ../lib/rbtree.c FORCE
 	$(call rule_mkdir)
 	$(call if_changed_dep,cc_o_c)
 
-$(OUTPUT)util/libstring.o: ../lib/string.c FORCE
-	$(call rule_mkdir)
-	$(call if_changed_dep,cc_o_c)
-
 $(OUTPUT)util/hweight.o: ../lib/hweight.c FORCE
 	$(call rule_mkdir)
 	$(call if_changed_dep,cc_o_c)
tools/perf/util/auxtrace.c +1 -1
index 7f10430..cc83262 100644
@@ -22,7 +22,7 @@
 #include <linux/types.h>
 #include <linux/bitops.h>
 #include <linux/log2.h>
-#include <linux/string.h>
+#include <api/string/string.h>
 
 #include <sys/param.h>
 #include <stdlib.h>
tools/perf/util/bpf-loader.c +1 -1
index 540a7ef..5a99b6a 100644
@@ -8,7 +8,7 @@
 #include <linux/bpf.h>
 #include <bpf/libbpf.h>
 #include <linux/err.h>
-#include <linux/string.h>
+#include <api/string/string.h>
 #include "perf.h"
 #include "debug.h"
 #include "bpf-loader.h"
tools/perf/util/intel-pt-decoder/insn.c +1 -1
index 47314a6..bcf3a8e 100644
@@ -19,7 +19,7 @@
  */
 
 #ifdef __KERNEL__
-#include <linux/string.h>
+#include <api/string/string.h>
 #else
 #include <string.h>
 #endif
tools/perf/util/map.c +1 -1
index 93d9f1c..c9f716d 100644
@@ -14,7 +14,7 @@
 #include "util.h"
 #include "debug.h"
 #include "machine.h"
-#include <linux/string.h>
+#include <api/string/string.h>
 
 static void __maps__insert(struct maps *maps, struct map *map);
 
tools/perf/util/ordered-events.c +1 -1
index b1b9e23..867ae98 100644
@@ -1,6 +1,6 @@
 #include <linux/list.h>
 #include <linux/compiler.h>
-#include <linux/string.h>
+#include <api/string/string.h>
 #include "ordered-events.h"
 #include "session.h"
 #include "asm/bug.h"
tools/perf/util/parse-options.c +1 -1
index 735c8c8..8d70c1b 100644
@@ -1,7 +1,7 @@
 #include "util.h"
 #include "parse-options.h"
 #include "header.h"
-#include <linux/string.h>
+#include <api/string/string.h>
 
 #define OPT_SHORT 1
 #define OPT_UNSET 2
tools/perf/util/util.h +1 -1
index 2c6db35..f1c07f6 100644
@@ -3,7 +3,7 @@
 
 #include "compat-util.h"
 
-#include <linux/string.h>
+#include <api/string/string.h>
 #include "../perf.h"
 #include "abspath.h"
 #include "alias.h"
Signature · 1 line
2.4.3
#13 lore raw

PATCH 12/13 perf tools: Move tools/lib/string.c to libapi

Quoted 11 lines · Josh Poimboeuf

The perf subcommand framework will soon be needed by stacktool. Move parse-options.c, run-command.c, exec_cmd.c, help.c, usage.c, and their dependencies over to libapi in 'tools/lib/api/util'.

Functions with 'perf' in their name have been given more generic names.

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.

Oops! Right patch, wrong description. Not sure how I borked that one up. Should be:

----8<----

Subject: [PATCH] perf tools: Move tools/lib/string.c to libapi

Get rid of libstring and move tools/lib/string.c to libapi where it can more easily be used by other tools.

---
 tools/lib/api/Build                              |  1 +
 tools/lib/api/string/Build                       |  1 +
 tools/lib/{ => api/string}/string.c              |  7 ++++---
 tools/{include/linux => lib/api/string}/string.h | 10 +++++-----
 tools/perf/MANIFEST                              |  2 --
 tools/perf/builtin-kmem.c                        |  2 +-
 tools/perf/util/Build                            |  6 ------
 tools/perf/util/auxtrace.c                       |  2 +-
 tools/perf/util/bpf-loader.c                     |  2 +-
 tools/perf/util/intel-pt-decoder/insn.c          |  2 +-
 tools/perf/util/map.c                            |  2 +-
 tools/perf/util/ordered-events.c                 |  2 +-
 tools/perf/util/parse-options.c                  |  2 +-
 tools/perf/util/util.h                           |  2 +-
 14 files changed, 19 insertions(+), 24 deletions(-)
 create mode 100644 tools/lib/api/string/Build
 rename tools/lib/{ => api/string}/string.c (93%)
 rename tools/{include/linux => lib/api/string}/string.h (66%)
tools/lib/api/Build +1 -0
index e8b8a23..9e3967e 100644
@@ -1,3 +1,4 @@
 libapi-y += fd/
 libapi-y += fs/
 libapi-y += cpu.o
+libapi-y += string/
tools/lib/api/string/Build new file +1 -0
new file mode 100644
index 0000000..7707d3d
@@ -0,0 +1 @@
+libapi-y += string.o
tools/lib/api/string/string.c renamed from tools/lib/string.c +4 -3
similarity index 93%
rename from tools/lib/string.c
rename to tools/lib/api/string/string.c
index 3366582..3140ba3 100644
@@ -1,5 +1,5 @@
 /*
- *  linux/tools/lib/string.c
+ *  linux/tools/lib/api/string/string.c
  *
  *  Copied from linux/lib/string.c, where it is:
  *
@@ -15,8 +15,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
-#include <linux/string.h>
-#include <linux/compiler.h>
+#include "string.h"
+
+#define __weak __attribute__((weak))
 
 /**
  * memdup - duplicate region of memory
tools/lib/api/string/string.h renamed from tools/include/linux/string.h +5 -5
similarity index 66%
rename from tools/include/linux/string.h
rename to tools/lib/api/string/string.h
index eae1d87..74bd4fd 100644
@@ -1,8 +1,8 @@
-#ifndef _TOOLS_LINUX_STRING_H_
-#define _TOOLS_LINUX_STRING_H_
+#ifndef _API_STRING_H
+#define _API_STRING_H
 
-
-#include <linux/types.h>	/* for size_t */
+#include <stddef.h>
+#include <stdbool.h>
 
 void *memdup(const void *src, size_t len);
 
@@ -13,4 +13,4 @@ int strtobool(const char *s, bool *res);
 extern size_t strlcpy(char *dest, const char *src, size_t size);
 #endif
 
-#endif /* _LINUX_STRING_H_ */
+#endif /* _API_STRING_H */
tools/perf/MANIFEST +0 -2
index 2562eac..39c38cb 100644
@@ -22,7 +22,6 @@ tools/lib/api
 tools/lib/bpf
 tools/lib/hweight.c
 tools/lib/rbtree.c
-tools/lib/string.c
 tools/lib/symbol/kallsyms.c
 tools/lib/symbol/kallsyms.h
 tools/lib/util/find_next_bit.c
@@ -51,7 +50,6 @@ tools/include/linux/log2.h
 tools/include/linux/poison.h
 tools/include/linux/rbtree.h
 tools/include/linux/rbtree_augmented.h
-tools/include/linux/string.h
 tools/include/linux/types.h
 tools/include/linux/err.h
 include/asm-generic/bitops/arch_hweight.h
tools/perf/builtin-kmem.c +1 -1
index 1c3d3d9..cdf487b 100644
@@ -19,7 +19,7 @@
 #include "util/debug.h"
 
 #include <linux/rbtree.h>
-#include <linux/string.h>
+#include <api/string/string.h>
 #include <locale.h>
 #include <regex.h>
 
tools/perf/util/Build +0 -6
index 99b3dae..02d3a54 100644
@@ -20,7 +20,6 @@ libperf-y += parse-events.o
 libperf-y += perf_regs.o
 libperf-y += path.o
 libperf-y += rbtree.o
-libperf-y += libstring.o
 libperf-y += bitmap.o
 libperf-y += hweight.o
 libperf-y += run-command.o
@@ -141,7 +140,6 @@ $(OUTPUT)util/pmu.o: $(OUTPUT)util/pmu-flex.c $(OUTPUT)util/pmu-bison.c
 
 CFLAGS_find_next_bit.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
 CFLAGS_rbtree.o        += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
-CFLAGS_libstring.o     += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
 CFLAGS_hweight.o       += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
 CFLAGS_parse-events.o  += -Wno-redundant-decls
 
@@ -157,10 +155,6 @@ $(OUTPUT)util/rbtree.o: ../lib/rbtree.c FORCE
 	$(call rule_mkdir)
 	$(call if_changed_dep,cc_o_c)
 
-$(OUTPUT)util/libstring.o: ../lib/string.c FORCE
-	$(call rule_mkdir)
-	$(call if_changed_dep,cc_o_c)
-
 $(OUTPUT)util/hweight.o: ../lib/hweight.c FORCE
 	$(call rule_mkdir)
 	$(call if_changed_dep,cc_o_c)
tools/perf/util/auxtrace.c +1 -1
index 7f10430..cc83262 100644
@@ -22,7 +22,7 @@
 #include <linux/types.h>
 #include <linux/bitops.h>
 #include <linux/log2.h>
-#include <linux/string.h>
+#include <api/string/string.h>
 
 #include <sys/param.h>
 #include <stdlib.h>
tools/perf/util/bpf-loader.c +1 -1
index 540a7ef..5a99b6a 100644
@@ -8,7 +8,7 @@
 #include <linux/bpf.h>
 #include <bpf/libbpf.h>
 #include <linux/err.h>
-#include <linux/string.h>
+#include <api/string/string.h>
 #include "perf.h"
 #include "debug.h"
 #include "bpf-loader.h"
tools/perf/util/intel-pt-decoder/insn.c +1 -1
index 47314a6..bcf3a8e 100644
@@ -19,7 +19,7 @@
  */
 
 #ifdef __KERNEL__
-#include <linux/string.h>
+#include <api/string/string.h>
 #else
 #include <string.h>
 #endif
tools/perf/util/map.c +1 -1
index 93d9f1c..c9f716d 100644
@@ -14,7 +14,7 @@
 #include "util.h"
 #include "debug.h"
 #include "machine.h"
-#include <linux/string.h>
+#include <api/string/string.h>
 
 static void __maps__insert(struct maps *maps, struct map *map);
 
tools/perf/util/ordered-events.c +1 -1
index b1b9e23..867ae98 100644
@@ -1,6 +1,6 @@
 #include <linux/list.h>
 #include <linux/compiler.h>
-#include <linux/string.h>
+#include <api/string/string.h>
 #include "ordered-events.h"
 #include "session.h"
 #include "asm/bug.h"
tools/perf/util/parse-options.c +1 -1
index 735c8c8..8d70c1b 100644
@@ -1,7 +1,7 @@
 #include "util.h"
 #include "parse-options.h"
 #include "header.h"
-#include <linux/string.h>
+#include <api/string/string.h>
 
 #define OPT_SHORT 1
 #define OPT_UNSET 2
tools/perf/util/util.h +1 -1
index 2c6db35..f1c07f6 100644
@@ -3,7 +3,7 @@
 
 #include "compat-util.h"
 
-#include <linux/string.h>
+#include <api/string/string.h>
 #include "../perf.h"
 #include "abspath.h"
 #include "alias.h"
Signature · 1 line
2.4.3
#14 lore raw

PATCH 13/13 perf tools: Move subcommand framework and related utils to libapi

In reply to Josh Poimboeuf

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.

---
 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 |  7 +++--
 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, 264 insertions(+), 181 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%)
tools/include/asm-generic/bitops/__fls.h +1 -1
index 2218b9a..494c9c6 100644
@@ -1 +1 @@
-#include <../../../../include/asm-generic/bitops/__fls.h>
+#include "../../../../include/asm-generic/bitops/__fls.h"
tools/include/asm-generic/bitops/fls.h +1 -1
index dbf711a..0e4995f 100644
@@ -1 +1 @@
-#include <../../../../include/asm-generic/bitops/fls.h>
+#include "../../../../include/asm-generic/bitops/fls.h"
tools/include/asm-generic/bitops/fls64.h +1 -1
index 980b1f6..35bee00 100644
@@ -1 +1 @@
-#include <../../../../include/asm-generic/bitops/fls64.h>
+#include "../../../../include/asm-generic/bitops/fls64.h"
tools/lib/api/Build +1 -0
index 9e3967e..6ad3ac2 100644
@@ -2,3 +2,4 @@ libapi-y += fd/
 libapi-y += fs/
 libapi-y += cpu.o
 libapi-y += string/
+libapi-y += util/
tools/lib/api/Makefile +5 -1
index d85904d..ad896c2 100644
@@ -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
 
tools/lib/api/util/Build new file +13 -0
new file mode 100644
index 0000000..6f95278
@@ -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
tools/lib/api/util/abspath.c renamed from tools/perf/util/abspath.c +5 -1
similarity index 90%
rename from tools/perf/util/abspath.c
rename to tools/lib/api/util/abspath.c
index eab5d85..9827a3f 100644
@@ -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)
 {
tools/lib/api/util/abspath.h renamed from tools/perf/util/abspath.h +3 -3
similarity index 59%
rename from tools/perf/util/abspath.h
rename to tools/lib/api/util/abspath.h
index 13549fb..fa5d82a 100644
@@ -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 */
tools/lib/api/util/cfg.c new file +12 -0
new file mode 100644
index 0000000..40653dc
@@ -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,
+};
tools/lib/api/util/cfg.h new file +15 -0
new file mode 100644
index 0000000..f271732
@@ -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 */
tools/lib/api/util/compat-util.h renamed from tools/perf/util/compat-util.h +3 -4
similarity index 95%
rename from tools/perf/util/compat-util.h
rename to tools/lib/api/util/compat-util.h
index f472a98..ab2b257 100644
@@ -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 */
tools/lib/api/util/ctype.c renamed from tools/perf/util/ctype.c +2 -1
similarity index 97%
rename from tools/perf/util/ctype.c
rename to tools/lib/api/util/ctype.c
index aada3ac..a7b2d33 100644
@@ -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,
tools/lib/api/util/ctype.h renamed from tools/perf/util/ctype.h +3 -3
similarity index 93%
rename from tools/perf/util/ctype.h
rename to tools/lib/api/util/ctype.h
index b66bfeb..1be5f8d 100644
@@ -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 */
tools/lib/api/util/exec_cmd.c renamed from tools/perf/util/exec_cmd.c +21 -21

120 lines not on this page · raw message

tools/lib/api/util/exec_cmd.h renamed from tools/perf/util/exec_cmd.h +9 -9
similarity index 14%
rename from tools/perf/util/exec_cmd.h
rename to tools/lib/api/util/exec_cmd.h
index 48b4175..c826713 100644
@@ -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 */
tools/lib/api/util/help.c renamed from tools/perf/util/help.c +7 -4
similarity index 96%
rename from tools/perf/util/help.c
rename to tools/lib/api/util/help.c
index dfe9c5f..36b3e60 100644
@@ -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));
tools/lib/api/util/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/api/util/help.h
tools/lib/api/util/pager.c renamed from tools/perf/util/pager.c +4 -2
similarity index 93%
rename from tools/perf/util/pager.c
rename to tools/lib/api/util/pager.c
index 6cff2ac..97a59ed 100644
@@ -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;
tools/lib/api/util/pager.h renamed from tools/perf/util/pager.h +3 -3
similarity index 42%
rename from tools/perf/util/pager.h
rename to tools/lib/api/util/pager.h
index 2794a83..3c13659 100644
@@ -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 */
tools/lib/api/util/parse-options.c renamed from tools/perf/util/parse-options.c +15 -6
similarity index 98%
rename from tools/perf/util/parse-options.c
rename to tools/lib/api/util/parse-options.c
index 8d70c1b..9e334a9 100644
@@ -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);
tools/lib/api/util/parse-options.h renamed from tools/perf/util/parse-options.h +4 -3
similarity index 98%
rename from tools/perf/util/parse-options.h
rename to tools/lib/api/util/parse-options.h
index a8e407b..f880488 100644
@@ -1,5 +1,5 @@
-#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>
@@ -226,4 +226,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 */
tools/lib/api/util/run-command.c renamed from tools/perf/util/run-command.c +7 -5
similarity index 96%
rename from tools/perf/util/run-command.c
rename to tools/lib/api/util/run-command.c
index 38d2cc6..d5f2daa 100644
@@ -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;
 }
 
tools/lib/api/util/run-command.h renamed from tools/perf/util/run-command.h +5 -5
similarity index 87%
rename from tools/perf/util/run-command.h
rename to tools/lib/api/util/run-command.h
index 1ef264d..6876b14 100644
@@ -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 */
tools/lib/api/util/sigchain.c renamed from tools/perf/util/sigchain.c +3 -1
similarity index 93%
rename from tools/perf/util/sigchain.c
rename to tools/lib/api/util/sigchain.c
index 5eebf88..d7ed474 100644
@@ -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
 
tools/lib/api/util/sigchain.h renamed from tools/perf/util/sigchain.h +3 -3
similarity index 53%
rename from tools/perf/util/sigchain.h
rename to tools/lib/api/util/sigchain.h
index 959d64e..6038d7b 100644
@@ -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 */
tools/lib/api/util/strbuf.c renamed from tools/perf/util/strbuf.c +5 -1
similarity index 97%
rename from tools/perf/util/strbuf.c
rename to tools/lib/api/util/strbuf.c
index 0e53793..6f0ae90 100644
@@ -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)
 {
tools/lib/api/util/strbuf.h renamed from tools/perf/util/strbuf.h +3 -3
similarity index 97%
rename from tools/perf/util/strbuf.h
rename to tools/lib/api/util/strbuf.h
index 39a1481..cc284a6 100644
@@ -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 */
tools/lib/api/util/term.c renamed from tools/perf/util/term.c +2 -1
similarity index 93%
rename from tools/perf/util/term.c
rename to tools/lib/api/util/term.c
index 90b47d8..e246994 100644
@@ -1,4 +1,5 @@
-#include "util.h"
+#include "compat-util.h"
+#include "term.h"
 
 void get_term_dimensions(struct winsize *ws)
 {
tools/lib/api/util/term.h renamed from tools/perf/util/term.h +0 -0
similarity index 100%
rename from tools/perf/util/term.h
rename to tools/lib/api/util/term.h
tools/lib/api/util/usage.c renamed from tools/perf/util/usage.c +2 -2
similarity index 97%
rename from tools/perf/util/usage.c
rename to tools/lib/api/util/usage.c
index 6adfa18..69ec872 100644
@@ -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)
 {
tools/lib/api/util/usage.h renamed from tools/perf/util/usage.h +4 -4
similarity index 84%
rename from tools/perf/util/usage.h
rename to tools/lib/api/util/usage.h
index e3f1bd0..05a6e43 100644
@@ -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 */
tools/lib/api/util/wrapper.c renamed from tools/perf/util/wrapper.c +3 -1
similarity index 92%
rename from tools/perf/util/wrapper.c
rename to tools/lib/api/util/wrapper.c
index 861ecfa..de59145 100644
@@ -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
tools/lib/api/util/wrapper.h renamed from tools/perf/util/wrapper.h +3 -3
similarity index 89%
rename from tools/perf/util/wrapper.h
rename to tools/lib/api/util/wrapper.h
index e2fa014..b8adda7 100644
@@ -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 */
tools/perf/Build +1 -1
index 2a41217..050f3ad 100644
@@ -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/
tools/perf/arch/x86/util/intel-pt.c +1 -1
index b02af06..bcc432a 100644
@@ -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"
tools/perf/bench/futex-hash.c +1 -1
index fc9bebd..07115cf 100644
@@ -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"
tools/perf/bench/futex-lock-pi.c +1 -1
index bc6a16a..487c3d3 100644
@@ -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"
tools/perf/bench/futex-requeue.c +1 -1
index ad0d9b5..eb56ddf 100644
@@ -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"
tools/perf/bench/futex-wake-parallel.c +1 -1
index 6d8c9fa..1bab7b0 100644
@@ -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"
tools/perf/bench/futex-wake.c +1 -1
index e5e41d3..d23e978 100644
@@ -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"
tools/perf/bench/mem-functions.c +1 -1
index 9419b94..ad11f26 100644
@@ -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"
tools/perf/bench/numa.c +1 -1
index 492df27..8a42d13 100644
@@ -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"
tools/perf/bench/sched-messaging.c +1 -1
index d4ff1b5..77e36e9 100644
@@ -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"
 
tools/perf/bench/sched-pipe.c +1 -1
index 005cc28..b1e84c8 100644
@@ -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"
 
tools/perf/builtin-annotate.c +1 -1
index 50695c7..bba340b 100644
@@ -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"
tools/perf/builtin-bench.c +1 -1
index b17aed3..48b4054 100644
@@ -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"
 
tools/perf/builtin-buildid-cache.c +1 -1
index bed484f..1dc9eb0 100644
@@ -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"
tools/perf/builtin-buildid-list.c +1 -1
index bd7558e..4ff4f6c 100644
@@ -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"
tools/perf/builtin-config.c +1 -1
index 03117c8..a2a087c 100644
@@ -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[] = {
tools/perf/builtin-data.c +1 -1
index d6525bc..b27861f 100644
@@ -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);
tools/perf/builtin-evlist.c +1 -1
index f4d6251..7f673a0 100644
@@ -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"
tools/perf/builtin-help.c +4 -5
index 23c3fdb..6ddbffc 100644
@@ -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
 
tools/perf/builtin-inject.c +1 -1
index 99d127f..a85ecba 100644
@@ -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>
 
tools/perf/builtin-kmem.c +1 -1
index cdf487b..e0c5b44 100644
@@ -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"
tools/perf/builtin-kvm.c +1 -1
index a9ad326..2202f54 100644
@@ -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"
tools/perf/builtin-list.c +1 -1
index 70856ac..0b080cd 100644
@@ -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)
 {
tools/perf/builtin-lock.c +1 -1
index 191d32f..2e14528 100644
@@ -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"
tools/perf/builtin-mem.c +1 -1
index 80170aa..fd2adeb 100644
@@ -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"
tools/perf/builtin-probe.c +1 -1
index 132afc9..d4a7885 100644
@@ -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"
tools/perf/builtin-record.c +1 -1
index 199fc31..9c0d1bd 100644
@@ -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"
tools/perf/builtin-report.c +1 -1
index 61ed8f2..b998e26 100644
@@ -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"
tools/perf/builtin-sched.c +1 -1
index 43dedd4..37ab946 100644
@@ -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"
tools/perf/builtin-script.c +6 -6
index 8873021..ba344c0 100644
@@ -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];
tools/perf/builtin-stat.c +1 -1
index df2fbf0..a1460b2 100644
@@ -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"
tools/perf/builtin-timechart.c +1 -1
index ab75e5b..89d6ca1 100644
@@ -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"
tools/perf/builtin-top.c +1 -1
index c8dd628..ee1a733 100644
@@ -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"
tools/perf/builtin-trace.c +2 -2
index c783d8f..63b180a 100644
@@ -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"
tools/perf/builtin.h +1 -1
index 3f871b5..123e66a 100644
@@ -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[];
tools/perf/perf.c +20 -7
index c57e447..1312c50 100644
@@ -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";
 
tools/perf/perf.h +1 -0
index 501acb4..8f314b5 100644
@@ -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);
tools/perf/tests/attr.c +2 -2
index b66730e..bdc4a3b 100644
@@ -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) &&
tools/perf/tests/builtin-test.c +1 -1
index 2b1ade1..1b8af76 100644
@@ -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[] = {
tools/perf/ui/setup.c +5 -0
index df4bd94..f6eaee1 100644
@@ -105,3 +105,8 @@ void exit_browser(bool wait_for_ok)
 		break;
 	}
 }
+
+void exit_browser_no_wait(void)
+{
+	exit_browser(false);
+}
tools/perf/ui/ui.h +1 -0
index ab88383..91ba964 100644
@@ -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);
tools/perf/util/Build +0 -13
index 02d3a54..6732b3e 100644
@@ -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)
tools/perf/util/auxtrace.c +1 -1
index cc83262..07f25ec 100644
@@ -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"
tools/perf/util/cgroup.c +1 -1
index 32e12ec..4543e72 100644
@@ -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"
tools/perf/util/config.c +1 -1
index 6b9e91f..8bdc5c6 100644
@@ -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 */
 
tools/perf/util/evlist.c +1 -1
index d139219..79eef69 100644
@@ -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>
 
tools/perf/util/header.c +1 -1
index 4383800..ec7b508 100644
@@ -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"
 
tools/perf/util/help-unknown-cmd.c +1 -1
index c30ae78..e658c22 100644
@@ -1,5 +1,5 @@
 #include "util.h"
-#include "help.h"
+#include <api/util/help.h>
 #include "../builtin.h"
 #include "levenshtein.h"
 
tools/perf/util/parse-branch-options.c +1 -1
index 355eecf..611f0f2 100644
@@ -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) \
tools/perf/util/parse-events.c +2 -2
index d2ec59d..5263f87 100644
@@ -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"
tools/perf/util/parse-regs-options.c +1 -1
index 4f2c1c2..893d2ca 100644
@@ -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
tools/perf/util/python-ext-sources +0 -1
index 51be28b..2f5a2d0 100644
@@ -6,7 +6,6 @@
 #
 
 util/python.c
-util/ctype.c
 util/evlist.c
 util/evsel.c
 util/cpumap.c
tools/perf/util/sort.h +1 -1
index 139a566..3459ae1 100644
@@ -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"
tools/perf/util/util.h +11 -8
index f1c07f6..6459f59 100644
@@ -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);
Signature · 1 line
2.4.3
#15 lore raw
In reply to Josh Poimboeuf
Quoted 33 lines · Josh Poimboeuf

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 libapi, including parse-options.c, run-command.c, exec_cmd.c, help.c, usage.c, and their dependencies. Since several of the dependencies are more general-purpose "utilities" which aren't directly related to subcommands, I put everything in 'tools/lib/api/util'. They're linked into perf as part of the libapi.a library.

Patches 1-10 do some cleanups and splitting up of the code in preparation for the move.

Patch 11 does the actual moving of the files into tools/lib/api/util.

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

Josh Poimboeuf (13):
perf: Use -iquote for local include paths
perf: Split up util.h
perf: Move term functions out of util.c
perf: Remove unused pager_use_color variable
perf: Split up cache.h
perf: Remove cache.h
perf: Save cmdline arguments earlier
perf: Remove check for unused PERF_PAGER_IN_USE
perf: Move cmd_version() to builtin-version.c
perf: Move help_unknown_cmd() to its own file
perf tools: Move strlcpy() to tools/lib/string.c
perf tools: Move perf subcommand framework into a library perf tools: Move subcommand framework and related utils to libapi

Quoted 1 line
 133 files changed, 852 insertions(+), 761 deletions(-)

So this split-out looks great to me!

A bit of a background: this series is a necessary precondition of me being able to merge 'stacktool' and the frame pointer handling enhancements Josh is working on - but it would be nice if this could all be done via Arnaldo's perf tree to minimize any impact on pending perf work.

I've Cc:-ed Namhyung and Jiri as well, who've done a lot of work in perf/util/.

Thanks,

Ingo

#16 lore raw
Quoted 38 lines · Ingo Molnar
Quoted 33 lines · Josh Poimboeuf

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 libapi, including parse-options.c, run-command.c, exec_cmd.c, help.c, usage.c, and their dependencies. Since several of the dependencies are more general-purpose "utilities" which aren't directly related to subcommands, I put everything in 'tools/lib/api/util'. They're linked into perf as part of the libapi.a library.

Patches 1-10 do some cleanups and splitting up of the code in preparation for the move.

Patch 11 does the actual moving of the files into tools/lib/api/util.

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

Josh Poimboeuf (13):
perf: Use -iquote for local include paths
perf: Split up util.h
perf: Move term functions out of util.c
perf: Remove unused pager_use_color variable
perf: Split up cache.h
perf: Remove cache.h
perf: Save cmdline arguments earlier
perf: Remove check for unused PERF_PAGER_IN_USE
perf: Move cmd_version() to builtin-version.c
perf: Move help_unknown_cmd() to its own file
perf tools: Move strlcpy() to tools/lib/string.c
perf tools: Move perf subcommand framework into a library perf tools: Move subcommand framework and related utils to libapi

Quoted 1 line
 133 files changed, 852 insertions(+), 761 deletions(-)
Quoted 9 lines

So this split-out looks great to me!

A bit of a background: this series is a necessary precondition of me being able to merge 'stacktool' and the frame pointer handling enhancements Josh is working on - but it would be nice if this could all be done via Arnaldo's perf tree to minimize any impact on pending perf work.

I've Cc:-ed Namhyung and Jiri as well, who've done a lot of work in perf/util/.

heya,
got compilation error over this patchset:

[jolsa@krava perf]$ make clean && make JOBS=1

...

CC tests/llvm-src-base.o
tests/llvm-src-base.c:1:24: fatal error: tests/llvm.h: No such file or directory compilation terminated.
mv: cannot stat ‘tests/.llvm-src-base.o.tmp’: No such file or directory /home/jolsa/kernel/linux-perf/tools/build/Makefile.build:77: recipe for target 'tests/llvm-src-base.o' failed make[3]: *** [tests/llvm-src-base.o] Error 1 /home/jolsa/kernel/linux-perf/tools/build/Makefile.build:116: recipe for target 'tests' failed make[2]: *** [tests] Error 2
Makefile.perf:313: recipe for target 'perf-in.o' failed
make[1]: *** [perf-in.o] Error 2
Makefile:68: recipe for target 'all' failed
make: *** [all] Error 2

jirka

#17 lore raw
Quoted 56 lines · Jiri Olsa
Quoted 38 lines · Ingo Molnar
Quoted 33 lines · Josh Poimboeuf

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 libapi, including parse-options.c, run-command.c, exec_cmd.c, help.c, usage.c, and their dependencies. Since several of the dependencies are more general-purpose "utilities" which aren't directly related to subcommands, I put everything in 'tools/lib/api/util'. They're linked into perf as part of the libapi.a library.

Patches 1-10 do some cleanups and splitting up of the code in preparation for the move.

Patch 11 does the actual moving of the files into tools/lib/api/util.

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

Josh Poimboeuf (13):
perf: Use -iquote for local include paths
perf: Split up util.h
perf: Move term functions out of util.c
perf: Remove unused pager_use_color variable
perf: Split up cache.h
perf: Remove cache.h
perf: Save cmdline arguments earlier
perf: Remove check for unused PERF_PAGER_IN_USE
perf: Move cmd_version() to builtin-version.c
perf: Move help_unknown_cmd() to its own file
perf tools: Move strlcpy() to tools/lib/string.c
perf tools: Move perf subcommand framework into a library perf tools: Move subcommand framework and related utils to libapi

Quoted 1 line
 133 files changed, 852 insertions(+), 761 deletions(-)
Quoted 9 lines

So this split-out looks great to me!

A bit of a background: this series is a necessary precondition of me being able to merge 'stacktool' and the frame pointer handling enhancements Josh is working on - but it would be nice if this could all be done via Arnaldo's perf tree to minimize any impact on pending perf work.

I've Cc:-ed Namhyung and Jiri as well, who've done a lot of work in perf/util/.

heya,
got compilation error over this patchset:

[jolsa@krava perf]$ make clean && make JOBS=1

...

Quoted 12 lines

CC tests/llvm-src-base.o
tests/llvm-src-base.c:1:24: fatal error: tests/llvm.h: No such file or directory compilation terminated.
mv: cannot stat ‘tests/.llvm-src-base.o.tmp’: No such file or directory /home/jolsa/kernel/linux-perf/tools/build/Makefile.build:77: recipe for target 'tests/llvm-src-base.o' failed make[3]: *** [tests/llvm-src-base.o] Error 1 /home/jolsa/kernel/linux-perf/tools/build/Makefile.build:116: recipe for target 'tests' failed make[2]: *** [tests] Error 2
Makefile.perf:313: recipe for target 'perf-in.o' failed
make[1]: *** [perf-in.o] Error 2
Makefile:68: recipe for target 'all' failed
make: *** [all] Error 2

I think the problem is that you have a stale version of the auto-generated file llvm-src-base.c. Looks like "make clean" doesn't remove it. I'll add a patch to fix it.

Signature · 1 line
Josh
#18 lore raw
Quoted 70 lines · Josh Poimboeuf
Quoted 56 lines · Jiri Olsa
Quoted 38 lines · Ingo Molnar
Quoted 33 lines · Josh Poimboeuf

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 libapi, including parse-options.c, run-command.c, exec_cmd.c, help.c, usage.c, and their dependencies. Since several of the dependencies are more general-purpose "utilities" which aren't directly related to subcommands, I put everything in 'tools/lib/api/util'. They're linked into perf as part of the libapi.a library.

Patches 1-10 do some cleanups and splitting up of the code in preparation for the move.

Patch 11 does the actual moving of the files into tools/lib/api/util.

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

Josh Poimboeuf (13):
perf: Use -iquote for local include paths
perf: Split up util.h
perf: Move term functions out of util.c
perf: Remove unused pager_use_color variable
perf: Split up cache.h
perf: Remove cache.h
perf: Save cmdline arguments earlier
perf: Remove check for unused PERF_PAGER_IN_USE
perf: Move cmd_version() to builtin-version.c
perf: Move help_unknown_cmd() to its own file
perf tools: Move strlcpy() to tools/lib/string.c
perf tools: Move perf subcommand framework into a library perf tools: Move subcommand framework and related utils to libapi

Quoted 1 line
 133 files changed, 852 insertions(+), 761 deletions(-)
Quoted 9 lines

So this split-out looks great to me!

A bit of a background: this series is a necessary precondition of me being able to merge 'stacktool' and the frame pointer handling enhancements Josh is working on - but it would be nice if this could all be done via Arnaldo's perf tree to minimize any impact on pending perf work.

I've Cc:-ed Namhyung and Jiri as well, who've done a lot of work in perf/util/.

heya,
got compilation error over this patchset:

[jolsa@krava perf]$ make clean && make JOBS=1

...

Quoted 12 lines

CC tests/llvm-src-base.o
tests/llvm-src-base.c:1:24: fatal error: tests/llvm.h: No such file or directory compilation terminated.
mv: cannot stat ‘tests/.llvm-src-base.o.tmp’: No such file or directory /home/jolsa/kernel/linux-perf/tools/build/Makefile.build:77: recipe for target 'tests/llvm-src-base.o' failed make[3]: *** [tests/llvm-src-base.o] Error 1 /home/jolsa/kernel/linux-perf/tools/build/Makefile.build:116: recipe for target 'tests' failed make[2]: *** [tests] Error 2
Makefile.perf:313: recipe for target 'perf-in.o' failed
make[1]: *** [perf-in.o] Error 2
Makefile:68: recipe for target 'all' failed
make: *** [all] Error 2

Quoted 3 lines

I think the problem is that you have a stale version of the auto-generated file llvm-src-base.c. Looks like "make clean" doesn't remove it. I'll add a patch to fix it.

FYI I switched back to Arnaldo's perf/core and did 'make clean && make' which passed, then switched back to your change and build failed again

jirka

#19 lore raw

Em Mon, Dec 07, 2015 at 09:46:48AM +0100, Jiri Olsa escreveu:

Quoted 71 lines · Josh Poimboeuf
Quoted 70 lines · Jiri Olsa
Quoted 68 lines · Ingo Molnar
Quoted 38 lines · Josh Poimboeuf
Quoted 34 lines

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 libapi, including parse-options.c, run-command.c, exec_cmd.c, help.c, usage.c, and their dependencies. Since several of the dependencies are more general-purpose "utilities" which aren't directly related to subcommands, I put everything in 'tools/lib/api/util'. They're linked into perf as part of the libapi.a library.

Patches 1-10 do some cleanups and splitting up of the code in preparation for the move.

Patch 11 does the actual moving of the files into tools/lib/api/util.

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

Josh Poimboeuf (13):
perf: Use -iquote for local include paths
perf: Split up util.h
perf: Move term functions out of util.c
perf: Remove unused pager_use_color variable
perf: Split up cache.h
perf: Remove cache.h
perf: Save cmdline arguments earlier
perf: Remove check for unused PERF_PAGER_IN_USE
perf: Move cmd_version() to builtin-version.c
perf: Move help_unknown_cmd() to its own file
perf tools: Move strlcpy() to tools/lib/string.c
perf tools: Move perf subcommand framework into a library perf tools: Move subcommand framework and related utils to libapi

Quoted 1 line
 133 files changed, 852 insertions(+), 761 deletions(-)
Quoted 9 lines

So this split-out looks great to me!

A bit of a background: this series is a necessary precondition of me being able to merge 'stacktool' and the frame pointer handling enhancements Josh is working on - but it would be nice if this could all be done via Arnaldo's perf tree to minimize any impact on pending perf work.

I've Cc:-ed Namhyung and Jiri as well, who've done a lot of work in perf/util/.

heya,
got compilation error over this patchset:

[jolsa@krava perf]$ make clean && make JOBS=1

...

CC tests/llvm-src-base.o
tests/llvm-src-base.c:1:24: fatal error: tests/llvm.h: No such file or directory compilation terminated.
mv: cannot stat ‘tests/.llvm-src-base.o.tmp’: No such file or directory /home/jolsa/kernel/linux-perf/tools/build/Makefile.build:77: recipe for target 'tests/llvm-src-base.o' failed make[3]: *** [tests/llvm-src-base.o] Error 1 /home/jolsa/kernel/linux-perf/tools/build/Makefile.build:116: recipe for target 'tests' failed make[2]: *** [tests] Error 2
Makefile.perf:313: recipe for target 'perf-in.o' failed
make[1]: *** [perf-in.o] Error 2
Makefile:68: recipe for target 'all' failed
make: *** [all] Error 2

Quoted 6 lines
Quoted 3 lines

I think the problem is that you have a stale version of the auto-generated file llvm-src-base.c. Looks like "make clean" doesn't remove it. I'll add a patch to fix it.

FYI I switched back to Arnaldo's perf/core and did 'make clean && make' which passed, then switched back to your change and build failed again

Even after his patches, it doesn't work, but I think this time he is not taking $(OUTPUT) into account, and as I do use "O=/tmp/build/perf/" it fails, trying to fix this...

- Arnaldo

Applying: perf: Use -iquote for local include paths [perf/core dbb37aec117a] perf tools: Use -iquote for local include paths
Author: Josh Poimboeuf <[email protected]>
Date: Mon Dec 7 22:21:40 2015 -0600

 5 files changed, 11 insertions(+), 11 deletions(-)
[acme@zoo linux]$ m
make: Entering directory '/home/git/linux/tools/perf'
  BUILD:   Doing 'make -j4' parallel build
  CC       /tmp/build/perf/builtin-bench.o
  CC       /tmp/build/perf/util/abspath.o
  CC       /tmp/build/perf/util/alias.o
  CC       /tmp/build/perf/builtin-annotate.o
  CC       /tmp/build/perf/builtin-config.o
  CC       /tmp/build/perf/util/annotate.o
  CC       /tmp/build/perf/ui/gtk/browser.o
  CC       /tmp/build/perf/util/build-id.o
  CC       /tmp/build/perf/builtin-diff.o
  CC       /tmp/build/perf/util/config.o
  CC       /tmp/build/perf/ui/gtk/hists.o
  CC       /tmp/build/perf/util/ctype.o
  CC       /tmp/build/perf/ui/gtk/setup.o
  CC       /tmp/build/perf/builtin-evlist.o
  CC       /tmp/build/perf/ui/gtk/util.o
  CC       /tmp/build/perf/util/db-export.o
  CC       /tmp/build/perf/util/env.o
  CC       /tmp/build/perf/ui/gtk/helpline.o
  CC       /tmp/build/perf/builtin-help.o
  CC       /tmp/build/perf/ui/gtk/progress.o
  CC       /tmp/build/perf/builtin-sched.o
  CC       /tmp/build/perf/ui/gtk/annotate.o
  CC       /tmp/build/perf/util/environment.o
  CC       /tmp/build/perf/util/event.o
  CC       /tmp/build/perf/builtin-buildid-list.o
  LD       /tmp/build/perf/ui/gtk/gtk-in.o
  CC       /tmp/build/perf/builtin-buildid-cache.o
  CC       /tmp/build/perf/util/evlist.o
  LD       /tmp/build/perf/gtk-in.o
  CC       /tmp/build/perf/util/evsel.o
  CC       /tmp/build/perf/util/exec_cmd.o
  CC       /tmp/build/perf/arch/common.o
  CC       /tmp/build/perf/arch/x86/util/header.o
  CC       /tmp/build/perf/util/find_next_bit.o
  CC       /tmp/build/perf/arch/x86/util/tsc.o
  CC       /tmp/build/perf/arch/x86/util/pmu.o
  CC       /tmp/build/perf/builtin-list.o
  CC       /tmp/build/perf/util/help.o
  CC       /tmp/build/perf/arch/x86/util/kvm-stat.o
  CC       /tmp/build/perf/builtin-record.o
  CC       /tmp/build/perf/util/kallsyms.o
  CC       /tmp/build/perf/util/levenshtein.o
  CC       /tmp/build/perf/builtin-report.o
  CC       /tmp/build/perf/builtin-stat.o
  CC       /tmp/build/perf/util/llvm-utils.o
  CC       /tmp/build/perf/util/parse-options.o
  CC       /tmp/build/perf/arch/x86/util/perf_regs.o
  CC       /tmp/build/perf/builtin-timechart.o
  CC       /tmp/build/perf/arch/x86/tests/regs_load.o
  CC       /tmp/build/perf/arch/x86/util/dwarf-regs.o
  CC       /tmp/build/perf/builtin-top.o
  CC       /tmp/build/perf/arch/x86/tests/dwarf-unwind.o
  CC       /tmp/build/perf/util/parse-events.o
  CC       /tmp/build/perf/arch/x86/util/unwind-libunwind.o
  CC       /tmp/build/perf/arch/x86/tests/arch-tests.o
  CC       /tmp/build/perf/util/perf_regs.o
  CC       /tmp/build/perf/builtin-script.o
  CC       /tmp/build/perf/arch/x86/util/auxtrace.o
  CC       /tmp/build/perf/builtin-kmem.o
  CC       /tmp/build/perf/arch/x86/tests/rdpmc.o
  CC       /tmp/build/perf/arch/x86/util/intel-pt.o
  CC       /tmp/build/perf/util/path.o
  CC       /tmp/build/perf/arch/x86/tests/perf-time-to-tsc.o
  CC       /tmp/build/perf/builtin-lock.o
  CC       /tmp/build/perf/util/rbtree.o
  CC       /tmp/build/perf/arch/x86/util/intel-bts.o
  CC       /tmp/build/perf/arch/x86/tests/insn-x86.o
  CC       /tmp/build/perf/util/libstring.o
  LD       /tmp/build/perf/arch/x86/util/libperf-in.o
  CC       /tmp/build/perf/util/bitmap.o
  CC       /tmp/build/perf/builtin-kvm.o
  CC       /tmp/build/perf/arch/x86/tests/intel-cqm.o
  CC       /tmp/build/perf/util/hweight.o
  CC       /tmp/build/perf/builtin-inject.o
  CC       /tmp/build/perf/builtin-mem.o
  CC       /tmp/build/perf/ui/setup.o
  LD       /tmp/build/perf/arch/x86/tests/libperf-in.o
  LD       /tmp/build/perf/arch/x86/libperf-in.o
  LD       /tmp/build/perf/arch/libperf-in.o
  CC       /tmp/build/perf/util/run-command.o
  CC       /tmp/build/perf/builtin-data.o
  CC       /tmp/build/perf/ui/helpline.o
  CC       /tmp/build/perf/ui/progress.o
  CC       /tmp/build/perf/util/quote.o
  CC       /tmp/build/perf/scripts/perl/Perf-Trace-Util/Context.o
  CC       /tmp/build/perf/util/strbuf.o
  LD       /tmp/build/perf/scripts/perl/Perf-Trace-Util/libperf-in.o
  CC       /tmp/build/perf/scripts/python/Perf-Trace-Util/Context.o
  CC       /tmp/build/perf/ui/util.o
  CC       /tmp/build/perf/util/string.o
  CC       /tmp/build/perf/builtin-trace.o
  LD       /tmp/build/perf/scripts/python/Perf-Trace-Util/libperf-in.o
  LD       /tmp/build/perf/scripts/libperf-in.o
  CC       /tmp/build/perf/builtin-probe.o
  CC       /tmp/build/perf/ui/hist.o
  CC       /tmp/build/perf/util/strlist.o
  CC       /tmp/build/perf/ui/stdio/hist.o
  CC       /tmp/build/perf/bench/sched-messaging.o
  CC       /tmp/build/perf/util/strfilter.o
  CC       /tmp/build/perf/util/top.o
  CC       /tmp/build/perf/ui/browser.o
  CC       /tmp/build/perf/bench/sched-pipe.o
  CC       /tmp/build/perf/bench/mem-functions.o
  CC       /tmp/build/perf/ui/browsers/annotate.o
  CC       /tmp/build/perf/bench/futex-hash.o
  CC       /tmp/build/perf/ui/browsers/hists.o
  CC       /tmp/build/perf/util/usage.o
  CC       /tmp/build/perf/ui/tui/setup.o
  CC       /tmp/build/perf/ui/browsers/map.o
  CC       /tmp/build/perf/bench/futex-wake.o
  CC       /tmp/build/perf/util/wrapper.o
  CC       /tmp/build/perf/ui/tui/util.o
  CC       /tmp/build/perf/ui/browsers/scripts.o
  CC       /tmp/build/perf/util/sigchain.o
  CC       /tmp/build/perf/ui/tui/helpline.o
  CC       /tmp/build/perf/bench/futex-wake-parallel.o
  CC       /tmp/build/perf/util/dso.o
  CC       /tmp/build/perf/ui/browsers/header.o
  CC       /tmp/build/perf/bench/futex-requeue.o
  CC       /tmp/build/perf/ui/tui/progress.o
  CC       /tmp/build/perf/bench/futex-lock-pi.o
  LD       /tmp/build/perf/ui/browsers/libperf-in.o
  CC       /tmp/build/perf/bench/mem-memcpy-x86-64-asm.o
  CC       /tmp/build/perf/util/symbol.o
  CC       /tmp/build/perf/util/color.o
  LD       /tmp/build/perf/ui/tui/libperf-in.o
  LD       /tmp/build/perf/ui/libperf-in.o
  CC       /tmp/build/perf/util/pager.o
  CC       /tmp/build/perf/bench/mem-memset-x86-64-asm.o
  CC       /tmp/build/perf/tests/builtin-test.o
  CC       /tmp/build/perf/tests/parse-events.o
  CC       /tmp/build/perf/util/header.o
  CC       /tmp/build/perf/tests/dso-data.o
  CC       /tmp/build/perf/util/callchain.o
  CC       /tmp/build/perf/bench/numa.o
  CC       /tmp/build/perf/perf.o
  CC       /tmp/build/perf/tests/attr.o
  CC       /tmp/build/perf/tests/vmlinux-kallsyms.o
  LD       /tmp/build/perf/bench/perf-in.o
  CC       /tmp/build/perf/tests/openat-syscall.o
  CC       /tmp/build/perf/util/values.o
  CC       /tmp/build/perf/tests/openat-syscall-all-cpus.o
  CC       /tmp/build/perf/util/debug.o
  CC       /tmp/build/perf/util/machine.o
  CC       /tmp/build/perf/tests/openat-syscall-tp-fields.o
  CC       /tmp/build/perf/tests/mmap-basic.o
  CC       /tmp/build/perf/tests/perf-record.o
  CC       /tmp/build/perf/util/map.o
  CC       /tmp/build/perf/util/pstack.o
  CC       /tmp/build/perf/tests/evsel-roundtrip-name.o
  CC       /tmp/build/perf/tests/evsel-tp-sched.o
  CC       /tmp/build/perf/tests/fdarray.o
  CC       /tmp/build/perf/util/session.o
  CC       /tmp/build/perf/tests/pmu.o
  CC       /tmp/build/perf/util/ordered-events.o
  CC       /tmp/build/perf/util/comm.o
  CC       /tmp/build/perf/util/thread.o
  CC       /tmp/build/perf/tests/hists_common.o
  CC       /tmp/build/perf/tests/hists_link.o
  CC       /tmp/build/perf/tests/hists_filter.o
  CC       /tmp/build/perf/tests/hists_output.o
  CC       /tmp/build/perf/util/thread_map.o
  CC       /tmp/build/perf/tests/hists_cumulate.o
  CC       /tmp/build/perf/tests/python-use.o
  CC       /tmp/build/perf/util/trace-event-parse.o
  CC       /tmp/build/perf/util/parse-events-flex.o
  CC       /tmp/build/perf/util/parse-events-bison.o
  CC       /tmp/build/perf/tests/bp_signal.o
  CC       /tmp/build/perf/tests/bp_signal_overflow.o
  CC       /tmp/build/perf/util/pmu.o
  CC       /tmp/build/perf/util/pmu-flex.o
  CC       /tmp/build/perf/tests/task-exit.o
  CC       /tmp/build/perf/tests/sw-clock.o
  CC       /tmp/build/perf/util/pmu-bison.o
  CC       /tmp/build/perf/tests/mmap-thread-lookup.o
  CC       /tmp/build/perf/tests/thread-mg-share.o
  CC       /tmp/build/perf/tests/switch-tracking.o
  CC       /tmp/build/perf/util/trace-event-read.o
  CC       /tmp/build/perf/util/trace-event-info.o
  CC       /tmp/build/perf/util/trace-event-scripting.o
  CC       /tmp/build/perf/tests/keep-tracking.o
  CC       /tmp/build/perf/util/trace-event.o
  CC       /tmp/build/perf/tests/code-reading.o
  CC       /tmp/build/perf/util/svghelper.o
  CC       /tmp/build/perf/util/sort.o
  CC       /tmp/build/perf/tests/sample-parsing.o
  CC       /tmp/build/perf/tests/parse-no-sample-id-all.o
  CC       /tmp/build/perf/util/hist.o
  CC       /tmp/build/perf/tests/kmod-path.o
  CC       /tmp/build/perf/util/util.o
  CC       /tmp/build/perf/util/xyarray.o
  CC       /tmp/build/perf/tests/thread-map.o
  CC       /tmp/build/perf/tests/llvm.o
  CC       /tmp/build/perf/util/cpumap.o
  CC       /tmp/build/perf/util/cgroup.o
  CC       /tmp/build/perf/tests/llvm-src-base.o
  CC       /tmp/build/perf/tests/llvm-src-kbuild.o
  CC       /tmp/build/perf/util/target.o
  CC       /tmp/build/perf/util/rblist.o
  CC       /tmp/build/perf/util/intlist.o
/tmp/build/perf/tests/llvm-src-kbuild.c:1:24: fatal error: tests/llvm.h:
No such file or directory
 #include <tests/llvm.h>
                        ^

compilation terminated.
mv: cannot stat ‘/tmp/build/perf/tests/.llvm-src-kbuild.o.tmp’: No such file or directory /home/git/linux/tools/build/Makefile.build:77: recipe for target '/tmp/build/perf/tests/llvm-src-kbuild.o' failed
make[3]: *** [/tmp/build/perf/tests/llvm-src-kbuild.o] Error 1 make[3]: *** Waiting for unfinished jobs....

  CC       /tmp/build/perf/util/vdso.o
  CC       /tmp/build/perf/util/counts.o
  CC       /tmp/build/perf/util/stat.o
/tmp/build/perf/tests/llvm-src-base.c:1:24: fatal error: tests/llvm.h:
No such file or directory
 #include <tests/llvm.h>
                        ^

compilation terminated.
mv: cannot stat ‘/tmp/build/perf/tests/.llvm-src-base.o.tmp’: No such file or directory /home/git/linux/tools/build/Makefile.build:77: recipe for target '/tmp/build/perf/tests/llvm-src-base.o' failed
make[3]: *** [/tmp/build/perf/tests/llvm-src-base.o] Error 1 /home/git/linux/tools/build/Makefile.build:116: recipe for target 'tests' failed
make[2]: *** [tests] Error 2
Makefile.perf:313: recipe for target '/tmp/build/perf/perf-in.o' failed make[1]: *** [/tmp/build/perf/perf-in.o] Error 2
make[1]: *** Waiting for unfinished jobs....
CC /tmp/build/perf/util/stat-shadow.o

#20 lore raw

Em Tue, Dec 08, 2015 at 11:52:33AM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 6 lines

Em Mon, Dec 07, 2015 at 09:46:48AM +0100, Jiri Olsa escreveu:

Quoted 4 lines · Josh Poimboeuf
Quoted 3 lines

I think the problem is that you have a stale version of the auto-generated file llvm-src-base.c. Looks like "make clean" doesn't remove it. I'll add a patch to fix it.

Quoted 6 lines
Quoted 2 lines

FYI I switched back to Arnaldo's perf/core and did 'make clean && make' which passed, then switched back to your change and build failed again

Even after his patches, it doesn't work, but I think this time he is not taking $(OUTPUT) into account, and as I do use "O=/tmp/build/perf/" it fails, trying to fix this...

Nah, that was me not using O= for the 'make clean' call, after I do that, it works.

But its sad everytime we introduce the need to run 'make clean' to regain a clean build environment :-\

Quoted 242 lines

- Arnaldo

Applying: perf: Use -iquote for local include paths [perf/core dbb37aec117a] perf tools: Use -iquote for local include paths
Author: Josh Poimboeuf <[email protected]>
Date: Mon Dec 7 22:21:40 2015 -0600

 5 files changed, 11 insertions(+), 11 deletions(-)
[acme@zoo linux]$ m
make: Entering directory '/home/git/linux/tools/perf'
  BUILD:   Doing 'make -j4' parallel build
  CC       /tmp/build/perf/builtin-bench.o
  CC       /tmp/build/perf/util/abspath.o
  CC       /tmp/build/perf/util/alias.o
  CC       /tmp/build/perf/builtin-annotate.o
  CC       /tmp/build/perf/builtin-config.o
  CC       /tmp/build/perf/util/annotate.o
  CC       /tmp/build/perf/ui/gtk/browser.o
  CC       /tmp/build/perf/util/build-id.o
  CC       /tmp/build/perf/builtin-diff.o
  CC       /tmp/build/perf/util/config.o
  CC       /tmp/build/perf/ui/gtk/hists.o
  CC       /tmp/build/perf/util/ctype.o
  CC       /tmp/build/perf/ui/gtk/setup.o
  CC       /tmp/build/perf/builtin-evlist.o
  CC       /tmp/build/perf/ui/gtk/util.o
  CC       /tmp/build/perf/util/db-export.o
  CC       /tmp/build/perf/util/env.o
  CC       /tmp/build/perf/ui/gtk/helpline.o
  CC       /tmp/build/perf/builtin-help.o
  CC       /tmp/build/perf/ui/gtk/progress.o
  CC       /tmp/build/perf/builtin-sched.o
  CC       /tmp/build/perf/ui/gtk/annotate.o
  CC       /tmp/build/perf/util/environment.o
  CC       /tmp/build/perf/util/event.o
  CC       /tmp/build/perf/builtin-buildid-list.o
  LD       /tmp/build/perf/ui/gtk/gtk-in.o
  CC       /tmp/build/perf/builtin-buildid-cache.o
  CC       /tmp/build/perf/util/evlist.o
  LD       /tmp/build/perf/gtk-in.o
  CC       /tmp/build/perf/util/evsel.o
  CC       /tmp/build/perf/util/exec_cmd.o
  CC       /tmp/build/perf/arch/common.o
  CC       /tmp/build/perf/arch/x86/util/header.o
  CC       /tmp/build/perf/util/find_next_bit.o
  CC       /tmp/build/perf/arch/x86/util/tsc.o
  CC       /tmp/build/perf/arch/x86/util/pmu.o
  CC       /tmp/build/perf/builtin-list.o
  CC       /tmp/build/perf/util/help.o
  CC       /tmp/build/perf/arch/x86/util/kvm-stat.o
  CC       /tmp/build/perf/builtin-record.o
  CC       /tmp/build/perf/util/kallsyms.o
  CC       /tmp/build/perf/util/levenshtein.o
  CC       /tmp/build/perf/builtin-report.o
  CC       /tmp/build/perf/builtin-stat.o
  CC       /tmp/build/perf/util/llvm-utils.o
  CC       /tmp/build/perf/util/parse-options.o
  CC       /tmp/build/perf/arch/x86/util/perf_regs.o
  CC       /tmp/build/perf/builtin-timechart.o
  CC       /tmp/build/perf/arch/x86/tests/regs_load.o
  CC       /tmp/build/perf/arch/x86/util/dwarf-regs.o
  CC       /tmp/build/perf/builtin-top.o
  CC       /tmp/build/perf/arch/x86/tests/dwarf-unwind.o
  CC       /tmp/build/perf/util/parse-events.o
  CC       /tmp/build/perf/arch/x86/util/unwind-libunwind.o
  CC       /tmp/build/perf/arch/x86/tests/arch-tests.o
  CC       /tmp/build/perf/util/perf_regs.o
  CC       /tmp/build/perf/builtin-script.o
  CC       /tmp/build/perf/arch/x86/util/auxtrace.o
  CC       /tmp/build/perf/builtin-kmem.o
  CC       /tmp/build/perf/arch/x86/tests/rdpmc.o
  CC       /tmp/build/perf/arch/x86/util/intel-pt.o
  CC       /tmp/build/perf/util/path.o
  CC       /tmp/build/perf/arch/x86/tests/perf-time-to-tsc.o
  CC       /tmp/build/perf/builtin-lock.o
  CC       /tmp/build/perf/util/rbtree.o
  CC       /tmp/build/perf/arch/x86/util/intel-bts.o
  CC       /tmp/build/perf/arch/x86/tests/insn-x86.o
  CC       /tmp/build/perf/util/libstring.o
  LD       /tmp/build/perf/arch/x86/util/libperf-in.o
  CC       /tmp/build/perf/util/bitmap.o
  CC       /tmp/build/perf/builtin-kvm.o
  CC       /tmp/build/perf/arch/x86/tests/intel-cqm.o
  CC       /tmp/build/perf/util/hweight.o
  CC       /tmp/build/perf/builtin-inject.o
  CC       /tmp/build/perf/builtin-mem.o
  CC       /tmp/build/perf/ui/setup.o
  LD       /tmp/build/perf/arch/x86/tests/libperf-in.o
  LD       /tmp/build/perf/arch/x86/libperf-in.o
  LD       /tmp/build/perf/arch/libperf-in.o
  CC       /tmp/build/perf/util/run-command.o
  CC       /tmp/build/perf/builtin-data.o
  CC       /tmp/build/perf/ui/helpline.o
  CC       /tmp/build/perf/ui/progress.o
  CC       /tmp/build/perf/util/quote.o
  CC       /tmp/build/perf/scripts/perl/Perf-Trace-Util/Context.o
  CC       /tmp/build/perf/util/strbuf.o
  LD       /tmp/build/perf/scripts/perl/Perf-Trace-Util/libperf-in.o
  CC       /tmp/build/perf/scripts/python/Perf-Trace-Util/Context.o
  CC       /tmp/build/perf/ui/util.o
  CC       /tmp/build/perf/util/string.o
  CC       /tmp/build/perf/builtin-trace.o
  LD       /tmp/build/perf/scripts/python/Perf-Trace-Util/libperf-in.o
  LD       /tmp/build/perf/scripts/libperf-in.o
  CC       /tmp/build/perf/builtin-probe.o
  CC       /tmp/build/perf/ui/hist.o
  CC       /tmp/build/perf/util/strlist.o
  CC       /tmp/build/perf/ui/stdio/hist.o
  CC       /tmp/build/perf/bench/sched-messaging.o
  CC       /tmp/build/perf/util/strfilter.o
  CC       /tmp/build/perf/util/top.o
  CC       /tmp/build/perf/ui/browser.o
  CC       /tmp/build/perf/bench/sched-pipe.o
  CC       /tmp/build/perf/bench/mem-functions.o
  CC       /tmp/build/perf/ui/browsers/annotate.o
  CC       /tmp/build/perf/bench/futex-hash.o
  CC       /tmp/build/perf/ui/browsers/hists.o
  CC       /tmp/build/perf/util/usage.o
  CC       /tmp/build/perf/ui/tui/setup.o
  CC       /tmp/build/perf/ui/browsers/map.o
  CC       /tmp/build/perf/bench/futex-wake.o
  CC       /tmp/build/perf/util/wrapper.o
  CC       /tmp/build/perf/ui/tui/util.o
  CC       /tmp/build/perf/ui/browsers/scripts.o
  CC       /tmp/build/perf/util/sigchain.o
  CC       /tmp/build/perf/ui/tui/helpline.o
  CC       /tmp/build/perf/bench/futex-wake-parallel.o
  CC       /tmp/build/perf/util/dso.o
  CC       /tmp/build/perf/ui/browsers/header.o
  CC       /tmp/build/perf/bench/futex-requeue.o
  CC       /tmp/build/perf/ui/tui/progress.o
  CC       /tmp/build/perf/bench/futex-lock-pi.o
  LD       /tmp/build/perf/ui/browsers/libperf-in.o
  CC       /tmp/build/perf/bench/mem-memcpy-x86-64-asm.o
  CC       /tmp/build/perf/util/symbol.o
  CC       /tmp/build/perf/util/color.o
  LD       /tmp/build/perf/ui/tui/libperf-in.o
  LD       /tmp/build/perf/ui/libperf-in.o
  CC       /tmp/build/perf/util/pager.o
  CC       /tmp/build/perf/bench/mem-memset-x86-64-asm.o
  CC       /tmp/build/perf/tests/builtin-test.o
  CC       /tmp/build/perf/tests/parse-events.o
  CC       /tmp/build/perf/util/header.o
  CC       /tmp/build/perf/tests/dso-data.o
  CC       /tmp/build/perf/util/callchain.o
  CC       /tmp/build/perf/bench/numa.o
  CC       /tmp/build/perf/perf.o
  CC       /tmp/build/perf/tests/attr.o
  CC       /tmp/build/perf/tests/vmlinux-kallsyms.o
  LD       /tmp/build/perf/bench/perf-in.o
  CC       /tmp/build/perf/tests/openat-syscall.o
  CC       /tmp/build/perf/util/values.o
  CC       /tmp/build/perf/tests/openat-syscall-all-cpus.o
  CC       /tmp/build/perf/util/debug.o
  CC       /tmp/build/perf/util/machine.o
  CC       /tmp/build/perf/tests/openat-syscall-tp-fields.o
  CC       /tmp/build/perf/tests/mmap-basic.o
  CC       /tmp/build/perf/tests/perf-record.o
  CC       /tmp/build/perf/util/map.o
  CC       /tmp/build/perf/util/pstack.o
  CC       /tmp/build/perf/tests/evsel-roundtrip-name.o
  CC       /tmp/build/perf/tests/evsel-tp-sched.o
  CC       /tmp/build/perf/tests/fdarray.o
  CC       /tmp/build/perf/util/session.o
  CC       /tmp/build/perf/tests/pmu.o
  CC       /tmp/build/perf/util/ordered-events.o
  CC       /tmp/build/perf/util/comm.o
  CC       /tmp/build/perf/util/thread.o
  CC       /tmp/build/perf/tests/hists_common.o
  CC       /tmp/build/perf/tests/hists_link.o
  CC       /tmp/build/perf/tests/hists_filter.o
  CC       /tmp/build/perf/tests/hists_output.o
  CC       /tmp/build/perf/util/thread_map.o
  CC       /tmp/build/perf/tests/hists_cumulate.o
  CC       /tmp/build/perf/tests/python-use.o
  CC       /tmp/build/perf/util/trace-event-parse.o
  CC       /tmp/build/perf/util/parse-events-flex.o
  CC       /tmp/build/perf/util/parse-events-bison.o
  CC       /tmp/build/perf/tests/bp_signal.o
  CC       /tmp/build/perf/tests/bp_signal_overflow.o
  CC       /tmp/build/perf/util/pmu.o
  CC       /tmp/build/perf/util/pmu-flex.o
  CC       /tmp/build/perf/tests/task-exit.o
  CC       /tmp/build/perf/tests/sw-clock.o
  CC       /tmp/build/perf/util/pmu-bison.o
  CC       /tmp/build/perf/tests/mmap-thread-lookup.o
  CC       /tmp/build/perf/tests/thread-mg-share.o
  CC       /tmp/build/perf/tests/switch-tracking.o
  CC       /tmp/build/perf/util/trace-event-read.o
  CC       /tmp/build/perf/util/trace-event-info.o
  CC       /tmp/build/perf/util/trace-event-scripting.o
  CC       /tmp/build/perf/tests/keep-tracking.o
  CC       /tmp/build/perf/util/trace-event.o
  CC       /tmp/build/perf/tests/code-reading.o
  CC       /tmp/build/perf/util/svghelper.o
  CC       /tmp/build/perf/util/sort.o
  CC       /tmp/build/perf/tests/sample-parsing.o
  CC       /tmp/build/perf/tests/parse-no-sample-id-all.o
  CC       /tmp/build/perf/util/hist.o
  CC       /tmp/build/perf/tests/kmod-path.o
  CC       /tmp/build/perf/util/util.o
  CC       /tmp/build/perf/util/xyarray.o
  CC       /tmp/build/perf/tests/thread-map.o
  CC       /tmp/build/perf/tests/llvm.o
  CC       /tmp/build/perf/util/cpumap.o
  CC       /tmp/build/perf/util/cgroup.o
  CC       /tmp/build/perf/tests/llvm-src-base.o
  CC       /tmp/build/perf/tests/llvm-src-kbuild.o
  CC       /tmp/build/perf/util/target.o
  CC       /tmp/build/perf/util/rblist.o
  CC       /tmp/build/perf/util/intlist.o
/tmp/build/perf/tests/llvm-src-kbuild.c:1:24: fatal error: tests/llvm.h:
No such file or directory
 #include <tests/llvm.h>
                        ^

compilation terminated.
mv: cannot stat ‘/tmp/build/perf/tests/.llvm-src-kbuild.o.tmp’: No such file or directory /home/git/linux/tools/build/Makefile.build:77: recipe for target '/tmp/build/perf/tests/llvm-src-kbuild.o' failed
make[3]: *** [/tmp/build/perf/tests/llvm-src-kbuild.o] Error 1 make[3]: *** Waiting for unfinished jobs....

  CC       /tmp/build/perf/util/vdso.o
  CC       /tmp/build/perf/util/counts.o
  CC       /tmp/build/perf/util/stat.o
/tmp/build/perf/tests/llvm-src-base.c:1:24: fatal error: tests/llvm.h:
No such file or directory
 #include <tests/llvm.h>
                        ^

compilation terminated.
mv: cannot stat ‘/tmp/build/perf/tests/.llvm-src-base.o.tmp’: No such file or directory /home/git/linux/tools/build/Makefile.build:77: recipe for target '/tmp/build/perf/tests/llvm-src-base.o' failed
make[3]: *** [/tmp/build/perf/tests/llvm-src-base.o] Error 1 /home/git/linux/tools/build/Makefile.build:116: recipe for target 'tests' failed
make[2]: *** [tests] Error 2
Makefile.perf:313: recipe for target '/tmp/build/perf/perf-in.o' failed make[1]: *** [/tmp/build/perf/perf-in.o] Error 2
make[1]: *** Waiting for unfinished jobs....
CC /tmp/build/perf/util/stat-shadow.o

#21 lore raw
Quoted 14 lines · Arnaldo Carvalho de Melo

Em Tue, Dec 08, 2015 at 11:52:33AM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 6 lines

Em Mon, Dec 07, 2015 at 09:46:48AM +0100, Jiri Olsa escreveu:

Quoted 4 lines · Josh Poimboeuf
Quoted 3 lines

I think the problem is that you have a stale version of the auto-generated file llvm-src-base.c. Looks like "make clean" doesn't remove it. I'll add a patch to fix it.

Quoted 6 lines
Quoted 2 lines

FYI I switched back to Arnaldo's perf/core and did 'make clean && make' which passed, then switched back to your change and build failed again

Even after his patches, it doesn't work, but I think this time he is not taking $(OUTPUT) into account, and as I do use "O=/tmp/build/perf/" it fails, trying to fix this...

Quoted 5 lines

Nah, that was me not using O= for the 'make clean' call, after I do that, it works.

But its sad everytime we introduce the need to run 'make clean' to regain a clean build environment :-\

Yeah, having to run 'make clean' every time you apply the patches is less than ideal. The problem is that the Build file is also a source file, since it generates the llvm-src-* files. I guess we could add the Build file itself as a dependency, like:

tools/perf/tests/Build +3 -3
index f8888e8..1869d73 100644
@@ -35,21 +35,21 @@ perf-y += llvm.o llvm-src-base.o llvm-src-kbuild.o llvm-src-prologue.o
 perf-y += bpf.o
 perf-y += topology.o
 
-$(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c
+$(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c tests/Build
 	$(call rule_mkdir)
 	$(Q)echo '#include "tests/llvm.h"' > $@
 	$(Q)echo 'const char test_llvm__bpf_base_prog[] =' >> $@
 	$(Q)sed -e 's/"/\\"/g' -e 's/\(.*\)/"\1\\n"/g' $< >> $@
 	$(Q)echo ';' >> $@
 
-$(OUTPUT)tests/llvm-src-kbuild.c: tests/bpf-script-test-kbuild.c
+$(OUTPUT)tests/llvm-src-kbuild.c: tests/bpf-script-test-kbuild.c tests/Build
 	$(call rule_mkdir)
 	$(Q)echo '#include "tests/llvm.h"' > $@
 	$(Q)echo 'const char test_llvm__bpf_test_kbuild_prog[] =' >> $@
 	$(Q)sed -e 's/"/\\"/g' -e 's/\(.*\)/"\1\\n"/g' $< >> $@
 	$(Q)echo ';' >> $@
 
-$(OUTPUT)tests/llvm-src-prologue.c: tests/bpf-script-test-prologue.c
+$(OUTPUT)tests/llvm-src-prologue.c: tests/bpf-script-test-prologue.c tests/Build
 	$(call rule_mkdir)
 	$(Q)echo '#include "tests/llvm.h"' > $@
 	$(Q)echo 'const char test_llvm__bpf_test_prologue_prog[] =' >> $@
#22 lore raw
In reply to Arnaldo Carvalho de Melo

Em Tue, Dec 08, 2015 at 11:55:31AM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 14 lines

Em Tue, Dec 08, 2015 at 11:52:33AM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 6 lines

Em Mon, Dec 07, 2015 at 09:46:48AM +0100, Jiri Olsa escreveu:

Quoted 4 lines · Josh Poimboeuf
Quoted 3 lines

I think the problem is that you have a stale version of the auto-generated file llvm-src-base.c. Looks like "make clean" doesn't remove it. I'll add a patch to fix it.

Quoted 6 lines
Quoted 2 lines

FYI I switched back to Arnaldo's perf/core and did 'make clean && make' which passed, then switched back to your change and build failed again

Even after his patches, it doesn't work, but I think this time he is not taking $(OUTPUT) into account, and as I do use "O=/tmp/build/perf/" it fails, trying to fix this...

Quoted 5 lines

Nah, that was me not using O= for the 'make clean' call, after I do that, it works.

But its sad everytime we introduce the need to run 'make clean' to regain a clean build environment :-\

Ok, now trying to run:

make -C tools/perf build-test

It fails here with:

[acme@ssdandy linux]$ cat ./tools/perf/make_clean_all_O
cd . && make -f Makefile O=/tmp/tmp.4iuuIJy0Ia DESTDIR=/tmp/tmp.EeBhrZY9H2 clean all

  CLEAN    libtraceevent
  CLEAN    libapi
  CLEAN    libbpf
  CLEAN    config
  CLEAN    feature
  CLEAN    tests

find: ‘/tmp/tmp.4iuuIJy0Ia/tests’: No such file or directory make[4]: *** [tests-clean] Error 1
make[4]: *** Waiting for unfinished jobs.... make[3]: *** [clean] Error 2
[acme@ssdandy linux]$

This is after applying:

[acme@ssdandy perf]$ git log --oneline | head -3 dbb37aec117a perf tools: Use -iquote for local include paths e32ac4f249a1 perf tools: Fix 'make clean'
a30c99a0beb3 Merge branch 'perf/urgent' into perf/core, to pick up fixes [acme@ssdandy perf]$

-----------------------------------------------------------------------------------------------

[acme@ssdandy linux]$ ls -la /tmp/tmp.EeBhrZY9H2
total 4
drwx------. 2 acme acme 6 Dec 8 12:17 .
drwxrwxrwt. 26 root root 4096 Dec 8 12:17 ..
[acme@ssdandy linux]$
[acme@ssdandy linux]$ cd tools/perf
[acme@ssdandy perf]$ make -f Makefile O=/tmp/tmp.4iuuIJy0Ia DESTDIR=/tmp/tmp.EeBhrZY9H2 clean all

  CLEAN    libtraceevent
  CLEAN    libapi
  CLEAN    libbpf
  CLEAN    config
  CLEAN    feature
  CLEAN    tests

find: ‘/tmp/tmp.4iuuIJy0Ia/tests’: No such file or directory make[1]: *** [tests-clean] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [clean] Error 2
[acme@ssdandy perf]$

- Arnaldo

#23 lore raw

Em Tue, Dec 08, 2015 at 12:29:15PM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 5 lines

find: ‘/tmp/tmp.4iuuIJy0Ia/tests’: No such file or directory make[4]: *** [tests-clean] Error 1
make[4]: *** Waiting for unfinished jobs.... make[3]: *** [clean] Error 2
[acme@ssdandy linux]$

So, to reproduce:

[acme@zoo linux]$ rmdir /tmp/foo
[acme@zoo linux]$ mkdir /tmp/foo
[acme@zoo linux]$ make O=/tmp/foo -C tools/perf clean
make: Entering directory '/home/git/linux/tools/perf'

  CLEAN    libtraceevent
  CLEAN    libapi
  CLEAN    config
  CLEAN    libbpf
  CLEAN    feature
  CLEAN    tests

find: ‘/tmp/foo/tests’: No such file or directory Makefile.perf:592: recipe for target 'tests-clean' failed make[1]: *** [tests-clean] Error 1
make[1]: *** Waiting for unfinished jobs.... Makefile:75: recipe for target 'clean' failed
make: *** [clean] Error 2
make: Leaving directory '/home/git/linux/tools/perf' [acme@zoo linux]$

Then, applying the patch below, it works, Jiri, would this be the best way to solve this? The RM call right after the find works because it uses 'rm -f', I think:

o linux]$ patch -p1 < /tmp/a.patch
patching file tools/perf/Makefile.perf [acme@zoo linux]$ make O=/tmp/foo -C tools/perf clean
make: Entering directory '/home/git/linux/tools/perf'

  CLEAN    libapi
  CLEAN    libbpf
  CLEAN    libtraceevent
  CLEAN    config
  CLEAN    feature
  CLEAN    tests
  CLEAN    core-objs
  CLEAN    core-progs
  CLEAN    core-gen
  SUBDIR   Documentation
  CLEAN    Documentation
  CLEAN    python

make: Leaving directory '/home/git/linux/tools/perf' [acme@zoo linux]$ mkdir /tmp/foo/tests/ [acme@zoo linux]$ touch /tmp/foo/tests/.a.cmd [acme@zoo linux]$ make O=/tmp/foo -C tools/perf clean
make: Entering directory '/home/git/linux/tools/perf'

  CLEAN    libtraceevent
  CLEAN    libapi
  CLEAN    libbpf
  CLEAN    config
  CLEAN    feature
  CLEAN    tests
  CLEAN    core-objs
  CLEAN    core-progs
  CLEAN    core-gen
  SUBDIR   Documentation
  CLEAN    Documentation
  CLEAN    python

make: Leaving directory '/home/git/linux/tools/perf' [acme@zoo linux]$ ls /tmp/foo/tests/ [acme@zoo linux]$

Regards,

- Arnaldo

tools/perf/Makefile.perf +1 -1
index 8b63dbdff197..331a0377da1f 100644
@@ -590,7 +590,7 @@ feature-clean:
 
 tests-clean:
 	$(call QUIET_CLEAN, tests)
-	$(Q)find $(OUTPUT)tests -name '*.o' -delete -o -name '\.*.cmd' -delete
+	$(Q)$(test -d $(OUTPUT)tests && find $(OUTPUT)tests -name '*.o' -delete -o -name '\.*.cmd' -delete)
 	$(Q)$(RM) $(OUTPUT)tests/llvm-src-{base,kbuild,prologue}.c
 
 clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean config-clean feature-clean tests-clean
#24 lore raw
In reply to Ingo Molnar

Em Sun, Dec 06, 2015 at 10:37:52AM +0100, Ingo Molnar escreveu:

Quoted 36 lines · Josh Poimboeuf
Quoted 33 lines

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 libapi, including parse-options.c, run-command.c, exec_cmd.c, help.c, usage.c, and their dependencies. Since several of the dependencies are more general-purpose "utilities" which aren't directly related to subcommands, I put everything in 'tools/lib/api/util'. They're linked into perf as part of the libapi.a library.

Patches 1-10 do some cleanups and splitting up of the code in preparation for the move.

Patch 11 does the actual moving of the files into tools/lib/api/util.

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

Josh Poimboeuf (13):
perf: Use -iquote for local include paths
perf: Split up util.h
perf: Move term functions out of util.c
perf: Remove unused pager_use_color variable
perf: Split up cache.h
perf: Remove cache.h
perf: Save cmdline arguments earlier
perf: Remove check for unused PERF_PAGER_IN_USE
perf: Move cmd_version() to builtin-version.c
perf: Move help_unknown_cmd() to its own file
perf tools: Move strlcpy() to tools/lib/string.c
perf tools: Move perf subcommand framework into a library perf tools: Move subcommand framework and related utils to libapi

Quoted 3 lines
Quoted 1 line
 133 files changed, 852 insertions(+), 761 deletions(-)

So this split-out looks great to me!

I briefly looked at it on the smartphone, what I can remember as an issue was naming, i.e. IIRC there is a util_cfg struct that looks too vague, I'll re-read and suggest something.

Quoted 6 lines

A bit of a background: this series is a necessary precondition of me being able to merge 'stacktool' and the frame pointer handling enhancements Josh is working on - but it would be nice if this could all be done via Arnaldo's perf tree to minimize any impact on pending perf work.

I've Cc:-ed Namhyung and Jiri as well, who've done a lot of work in perf/util/.

Commens from them would be more than welcome, Acks, even more.

- Arnaldo