linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/13] perf tools: Move perf subcommand framework into lib/tools
@ 2015-12-04 21:59 Josh Poimboeuf
  2015-12-04 21:59 ` [PATCH 01/13] perf: Use -iquote for local include paths Josh Poimboeuf
                   ` (13 more replies)
  0 siblings, 14 replies; 25+ messages in thread
From: Josh Poimboeuf @ 2015-12-04 21:59 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo; +Cc: linux-kernel

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/cover.1445443144.git.jpoimboe@redhat.com

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

-- 
2.4.3


^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 01/13] perf: Use -iquote for local include paths
  2015-12-04 21:59 [PATCH 00/13] perf tools: Move perf subcommand framework into lib/tools Josh Poimboeuf
@ 2015-12-04 21:59 ` Josh Poimboeuf
  2015-12-04 21:59 ` [PATCH 02/13] perf: Split up util.h Josh Poimboeuf
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 25+ messages in thread
From: Josh Poimboeuf @ 2015-12-04 21:59 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo; +Cc: linux-kernel

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.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 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(-)

diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
index 6eb9a95..4f96ca3 100644
--- a/tools/perf/config/Makefile
+++ b/tools/perf/config/Makefile
@@ -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
diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
index 0ff8a97..f8888e8 100644
--- a/tools/perf/tests/Build
+++ b/tools/perf/tests/Build
@@ -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 ';' >> $@
diff --git a/tools/perf/tests/bpf.c b/tools/perf/tests/bpf.c
index 33689a0..044a119 100644
--- a/tools/perf/tests/bpf.c
+++ b/tools/perf/tests/bpf.c
@@ -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"
diff --git a/tools/perf/tests/llvm.c b/tools/perf/tests/llvm.c
index 06f45c1..dc90cea 100644
--- a/tools/perf/tests/llvm.c
+++ b/tools/perf/tests/llvm.c
@@ -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"
diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
index a0ac031..f0d1035 100644
--- a/tools/perf/util/thread.h
+++ b/tools/perf/util/thread.h
@@ -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;
 
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 02/13] perf: Split up util.h
  2015-12-04 21:59 [PATCH 00/13] perf tools: Move perf subcommand framework into lib/tools Josh Poimboeuf
  2015-12-04 21:59 ` [PATCH 01/13] perf: Use -iquote for local include paths Josh Poimboeuf
@ 2015-12-04 21:59 ` Josh Poimboeuf
  2015-12-04 21:59 ` [PATCH 03/13] perf: Move term functions out of util.c Josh Poimboeuf
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 25+ messages in thread
From: Josh Poimboeuf @ 2015-12-04 21:59 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo; +Cc: linux-kernel

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.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 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

diff --git a/tools/perf/util/compat-util.h b/tools/perf/util/compat-util.h
new file mode 100644
index 0000000..f472a98
--- /dev/null
+++ b/tools/perf/util/compat-util.h
@@ -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 */
diff --git a/tools/perf/util/config.h b/tools/perf/util/config.h
new file mode 100644
index 0000000..d48c647
--- /dev/null
+++ b/tools/perf/util/config.h
@@ -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 */
diff --git a/tools/perf/util/ctype.h b/tools/perf/util/ctype.h
new file mode 100644
index 0000000..b66bfeb
--- /dev/null
+++ b/tools/perf/util/ctype.h
@@ -0,0 +1,52 @@
+#ifndef __PERF_CTYPE_H
+#define __PERF_CTYPE_H
+
+/* Sane ctype - no locale, and works with signed chars */
+#undef isascii
+#undef isspace
+#undef isdigit
+#undef isxdigit
+#undef isalpha
+#undef isprint
+#undef isalnum
+#undef islower
+#undef isupper
+#undef tolower
+#undef toupper
+
+extern const char *graph_line;
+extern const char *graph_dotted_line;
+
+extern unsigned char sane_ctype[256];
+
+#define GIT_SPACE		0x01
+#define GIT_DIGIT		0x02
+#define GIT_ALPHA		0x04
+#define GIT_GLOB_SPECIAL	0x08
+#define GIT_REGEX_SPECIAL	0x10
+#define GIT_PRINT_EXTRA		0x20
+#define GIT_PRINT		0x3E
+
+#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)
+
+#define isascii(x) (((x) & ~0x7f) == 0)
+#define isspace(x) sane_istest(x,GIT_SPACE)
+#define isdigit(x) sane_istest(x,GIT_DIGIT)
+#define isxdigit(x)	\
+	(sane_istest(toupper(x), GIT_ALPHA | GIT_DIGIT) && toupper(x) < 'G')
+#define isalpha(x) sane_istest(x,GIT_ALPHA)
+#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT)
+#define isprint(x) sane_istest(x,GIT_PRINT)
+#define islower(x) (sane_istest(x,GIT_ALPHA) && (x & 0x20))
+#define isupper(x) (sane_istest(x,GIT_ALPHA) && !(x & 0x20))
+#define tolower(x) sane_case((unsigned char)(x), 0x20)
+#define toupper(x) sane_case((unsigned char)(x), 0)
+
+static inline int sane_case(int x, int high)
+{
+	if (sane_istest(x, GIT_ALPHA))
+		x = (x & ~0x20) | high;
+	return x;
+}
+
+#endif /* __PERF_CTYPE_H */
diff --git a/tools/perf/util/help.c b/tools/perf/util/help.c
index fa1fc4a..29efb03 100644
--- a/tools/perf/util/help.c
+++ b/tools/perf/util/help.c
@@ -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)
diff --git a/tools/perf/util/lzma.h b/tools/perf/util/lzma.h
new file mode 100644
index 0000000..ef286e9
--- /dev/null
+++ b/tools/perf/util/lzma.h
@@ -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 */
diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c
index 9fca092..29366ae 100644
--- a/tools/perf/util/parse-options.c
+++ b/tools/perf/util/parse-options.c
@@ -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)
diff --git a/tools/perf/util/srcline.h b/tools/perf/util/srcline.h
new file mode 100644
index 0000000..ef57dc5
--- /dev/null
+++ b/tools/perf/util/srcline.h
@@ -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 */
diff --git a/tools/perf/util/strbuf.h b/tools/perf/util/strbuf.h
index 529f2f0..39a1481 100644
--- a/tools/perf/util/strbuf.h
+++ b/tools/perf/util/strbuf.h
@@ -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 *);
diff --git a/tools/perf/util/string.h b/tools/perf/util/string.h
new file mode 100644
index 0000000..d124268
--- /dev/null
+++ b/tools/perf/util/string.h
@@ -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 */
diff --git a/tools/perf/util/usage.h b/tools/perf/util/usage.h
new file mode 100644
index 0000000..e3f1bd0
--- /dev/null
+++ b/tools/perf/util/usage.h
@@ -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 */
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index dcc6590..cd0d9b0 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -1,264 +1,26 @@
-#ifndef GIT_COMPAT_UTIL_H
-#define GIT_COMPAT_UTIL_H
+#ifndef __PERF_UTIL_H
+#define __PERF_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
+#include "compat-util.h"
 
-/*
- * 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>
-
-extern const char *graph_line;
-extern const char *graph_dotted_line;
-extern char buildid_dir[];
-
-/* 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
-
-#define PERF_GTK_DSO  "libperf-gtk.so"
-
-/* General helper functions */
-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));
-
-extern int prefixcmp(const char *str, const char *prefix);
-extern void set_buildid_dir(const char *dir);
-
-static inline const char *skip_prefix(const char *str, const char *prefix)
-{
-	size_t len = strlen(prefix);
-	return strncmp(str, prefix, len) ? NULL : str + len;
-}
-
-#ifdef __GLIBC_PREREQ
-#if __GLIBC_PREREQ(2, 1)
-#define HAVE_STRCHRNUL
-#endif
-#endif
-
-#ifndef HAVE_STRCHRNUL
-#define strchrnul gitstrchrnul
-static inline char *gitstrchrnul(const char *s, int c)
-{
-	while (*s && *s != c)
-		s++;
-	return (char *)s;
-}
-#endif
-
-/*
- * Wrappers:
- */
-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; })
-
-static inline int has_extension(const char *filename, const char *ext)
-{
-	size_t len = strlen(filename);
-	size_t extlen = strlen(ext);
-
-	return len > extlen && !memcmp(filename + len - extlen, ext, extlen);
-}
-
-/* Sane ctype - no locale, and works with signed chars */
-#undef isascii
-#undef isspace
-#undef isdigit
-#undef isxdigit
-#undef isalpha
-#undef isprint
-#undef isalnum
-#undef islower
-#undef isupper
-#undef tolower
-#undef toupper
-
-#ifndef NSEC_PER_MSEC
-#define NSEC_PER_MSEC	1000000L
-#endif
+#include "config.h"
+#include "ctype.h"
+#include "lzma.h"
+#include "srcline.h"
+#include "strbuf.h"
+#include "string.h"
+#include "usage.h"
+#include "wrapper.h"
+#include "zlib.h"
 
 int parse_nsec_time(const char *str, u64 *ptime);
 
-extern unsigned char sane_ctype[256];
-#define GIT_SPACE		0x01
-#define GIT_DIGIT		0x02
-#define GIT_ALPHA		0x04
-#define GIT_GLOB_SPECIAL	0x08
-#define GIT_REGEX_SPECIAL	0x10
-#define GIT_PRINT_EXTRA		0x20
-#define GIT_PRINT		0x3E
-#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)
-#define isascii(x) (((x) & ~0x7f) == 0)
-#define isspace(x) sane_istest(x,GIT_SPACE)
-#define isdigit(x) sane_istest(x,GIT_DIGIT)
-#define isxdigit(x)	\
-	(sane_istest(toupper(x), GIT_ALPHA | GIT_DIGIT) && toupper(x) < 'G')
-#define isalpha(x) sane_istest(x,GIT_ALPHA)
-#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT)
-#define isprint(x) sane_istest(x,GIT_PRINT)
-#define islower(x) (sane_istest(x,GIT_ALPHA) && (x & 0x20))
-#define isupper(x) (sane_istest(x,GIT_ALPHA) && !(x & 0x20))
-#define tolower(x) sane_case((unsigned char)(x), 0x20)
-#define toupper(x) sane_case((unsigned char)(x), 0)
-
-static inline int sane_case(int x, int high)
-{
-	if (sane_istest(x, GIT_ALPHA))
-		x = (x & ~0x20) | high;
-	return x;
-}
-
 int mkdir_p(char *path, mode_t mode);
 int rm_rf(char *path);
 int copyfile(const char *from, const char *to);
 int copyfile_mode(const char *from, const char *to, mode_t mode);
 int copyfile_offset(int fromfd, loff_t from_ofs, int tofd, loff_t to_ofs, u64 size);
 
-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);
 unsigned long convert_unit(unsigned long value, char *unit);
 ssize_t readn(int fd, void *buf, size_t n);
 ssize_t writen(int fd, void *buf, size_t n);
@@ -267,15 +29,9 @@ struct perf_event_attr;
 
 void event_attr_init(struct perf_event_attr *attr);
 
-#define _STR(x) #x
-#define STR(x) _STR(x)
-
 size_t hex_width(u64 v);
 int hex2u64(const char *ptr, u64 *val);
 
-char *ltrim(char *s);
-char *rtrim(char *s);
-
 void dump_stack(void);
 void sighandler_dump_stack(int sig);
 
@@ -292,8 +48,6 @@ struct parse_tag {
 
 unsigned long parse_tag_value(const char *str, struct parse_tag *tags);
 
-#define SRCLINE_UNKNOWN  ((char *) "??:0")
-
 static inline int path__join(char *bf, size_t size,
 			     const char *path1, const char *path2)
 {
@@ -309,16 +63,6 @@ static inline int path__join3(char *bf, size_t size,
 			 path2, path2[0] ? "/" : "", path3);
 }
 
-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);
-
 int filename__read_str(const char *filename, char **buf, size_t *sizep);
 int perf_event_paranoid(void);
 
@@ -328,26 +72,6 @@ void mem_bswap_32(void *src, int byte_size);
 const char *get_filename_for_perf_kvm(void);
 bool find_process(const char *name);
 
-#ifdef HAVE_ZLIB_SUPPORT
-int gzip_decompress_to_file(const char *input, int output_fd);
-#endif
-
-#ifdef HAVE_LZMA_SUPPORT
-int lzma_decompress_to_file(const char *input, int output_fd);
-#endif
-
-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);
-}
-
 int get_stack_size(const char *str, unsigned long *_size);
 
 int fetch_kernel_version(unsigned int *puint,
@@ -358,4 +82,4 @@ int fetch_kernel_version(unsigned int *puint,
 #define KVER_FMT	"%d.%d.%d"
 #define KVER_PARAM(x)	KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x)
 
-#endif /* GIT_COMPAT_UTIL_H */
+#endif /* __PERF_UTIL_H */
diff --git a/tools/perf/util/wrapper.h b/tools/perf/util/wrapper.h
new file mode 100644
index 0000000..510781b
--- /dev/null
+++ b/tools/perf/util/wrapper.h
@@ -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 */
diff --git a/tools/perf/util/zlib.h b/tools/perf/util/zlib.h
new file mode 100644
index 0000000..40ee6d8
--- /dev/null
+++ b/tools/perf/util/zlib.h
@@ -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 */
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 03/13] perf: Move term functions out of util.c
  2015-12-04 21:59 [PATCH 00/13] perf tools: Move perf subcommand framework into lib/tools Josh Poimboeuf
  2015-12-04 21:59 ` [PATCH 01/13] perf: Use -iquote for local include paths Josh Poimboeuf
  2015-12-04 21:59 ` [PATCH 02/13] perf: Split up util.h Josh Poimboeuf
@ 2015-12-04 21:59 ` Josh Poimboeuf
  2015-12-04 21:59 ` [PATCH 04/13] perf: Remove unused pager_use_color variable Josh Poimboeuf
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 25+ messages in thread
From: Josh Poimboeuf @ 2015-12-04 21:59 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo; +Cc: linux-kernel

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.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 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

diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 0513dd5..6c3bbd5 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -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
diff --git a/tools/perf/util/term.c b/tools/perf/util/term.c
new file mode 100644
index 0000000..90b47d8
--- /dev/null
+++ b/tools/perf/util/term.c
@@ -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);
+}
diff --git a/tools/perf/util/term.h b/tools/perf/util/term.h
new file mode 100644
index 0000000..7b13f46
--- /dev/null
+++ b/tools/perf/util/term.h
@@ -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 */
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index 75759ae..07da970 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -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;
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index cd0d9b0..d8e3d8d 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -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;
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 04/13] perf: Remove unused pager_use_color variable
  2015-12-04 21:59 [PATCH 00/13] perf tools: Move perf subcommand framework into lib/tools Josh Poimboeuf
                   ` (2 preceding siblings ...)
  2015-12-04 21:59 ` [PATCH 03/13] perf: Move term functions out of util.c Josh Poimboeuf
@ 2015-12-04 21:59 ` Josh Poimboeuf
  2015-12-04 21:59 ` [PATCH 05/13] perf: Split up cache.h Josh Poimboeuf
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 25+ messages in thread
From: Josh Poimboeuf @ 2015-12-04 21:59 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo; +Cc: linux-kernel

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 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

diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 6c3bbd5..65fef59 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -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
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h
index c861373..4c2b764 100644
--- a/tools/perf/util/cache.h
+++ b/tools/perf/util/cache.h
@@ -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);
diff --git a/tools/perf/util/color.c b/tools/perf/util/color.c
index 9b95654..e5fb88b 100644
--- a/tools/perf/util/color.c
+++ b/tools/perf/util/color.c
@@ -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;
diff --git a/tools/perf/util/environment.c b/tools/perf/util/environment.c
deleted file mode 100644
index 7405123..0000000
--- a/tools/perf/util/environment.c
+++ /dev/null
@@ -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;
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 05/13] perf: Split up cache.h
  2015-12-04 21:59 [PATCH 00/13] perf tools: Move perf subcommand framework into lib/tools Josh Poimboeuf
                   ` (3 preceding siblings ...)
  2015-12-04 21:59 ` [PATCH 04/13] perf: Remove unused pager_use_color variable Josh Poimboeuf
@ 2015-12-04 21:59 ` Josh Poimboeuf
  2015-12-04 21:59 ` [PATCH 06/13] perf: Remove cache.h Josh Poimboeuf
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 25+ messages in thread
From: Josh Poimboeuf @ 2015-12-04 21:59 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo; +Cc: linux-kernel

cache.h is a hodgepodge which consists of:

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

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

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

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


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 06/13] perf: Remove cache.h
  2015-12-04 21:59 [PATCH 00/13] perf tools: Move perf subcommand framework into lib/tools Josh Poimboeuf
                   ` (4 preceding siblings ...)
  2015-12-04 21:59 ` [PATCH 05/13] perf: Split up cache.h Josh Poimboeuf
@ 2015-12-04 21:59 ` Josh Poimboeuf
  2015-12-04 21:59 ` [PATCH 07/13] perf: Save cmdline arguments earlier Josh Poimboeuf
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 25+ messages in thread
From: Josh Poimboeuf @ 2015-12-04 21:59 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo; +Cc: linux-kernel

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

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 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

diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 2bf9b3f..50695c7 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -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"
 
diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c
index 7b8450c..bed484f 100644
--- a/tools/perf/builtin-buildid-cache.c
+++ b/tools/perf/builtin-buildid-cache.c
@@ -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"
diff --git a/tools/perf/builtin-buildid-list.c b/tools/perf/builtin-buildid-list.c
index 918b4de..bd7558e 100644
--- a/tools/perf/builtin-buildid-list.c
+++ b/tools/perf/builtin-buildid-list.c
@@ -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"
diff --git a/tools/perf/builtin-config.c b/tools/perf/builtin-config.c
index 427ea7a..03117c8 100644
--- a/tools/perf/builtin-config.c
+++ b/tools/perf/builtin-config.c
@@ -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[] = {
diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c
index a7d588b..23c3fdb 100644
--- a/tools/perf/builtin-help.c
+++ b/tools/perf/builtin-help.c
@@ -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"
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 93ce665..1c3d3d9 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -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"
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index dd94b4c..a9ad326 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -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"
diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
index bf679e2..70856ac 100644
--- a/tools/perf/builtin-list.c
+++ b/tools/perf/builtin-list.c
@@ -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"
 
diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
index de16aae..191d32f 100644
--- a/tools/perf/builtin-lock.c
+++ b/tools/perf/builtin-lock.c
@@ -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"
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index af5db88..61ed8f2 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -8,7 +8,6 @@
 #include "builtin.h"
 
 #include "util/util.h"
-#include "util/cache.h"
 
 #include "util/annotate.h"
 #include "util/color.h"
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index e3d3e32..43dedd4 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -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"
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 3c3f8d0..8873021 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -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"
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index 30e5962..ab75e5b 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -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>
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 7e2e72e..c8dd628 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -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"
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index 4bee53c..bcf4fab 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -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"
diff --git a/tools/perf/tests/llvm.c b/tools/perf/tests/llvm.c
index dc90cea..fdb7e84 100644
--- a/tools/perf/tests/llvm.c
+++ b/tools/perf/tests/llvm.c
@@ -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"
diff --git a/tools/perf/ui/browser.c b/tools/perf/ui/browser.c
index e9703c0..97b570d 100644
--- a/tools/perf/ui/browser.c
+++ b/tools/perf/ui/browser.c
@@ -1,5 +1,4 @@
 #include "../util.h"
-#include "../cache.h"
 #include "../../perf.h"
 #include "libslang.h"
 #include "ui.h"
diff --git a/tools/perf/ui/browsers/header.c b/tools/perf/ui/browsers/header.c
index edbeaaf..d4c9fac 100644
--- a/tools/perf/ui/browsers/header.c
+++ b/tools/perf/ui/browsers/header.c
@@ -1,4 +1,4 @@
-#include "util/cache.h"
+#include "util/util.h"
 #include "util/debug.h"
 #include "ui/browser.h"
 #include "ui/keysyms.h"
diff --git a/tools/perf/ui/gtk/browser.c b/tools/perf/ui/gtk/browser.c
index c24d912..4305b1b 100644
--- a/tools/perf/ui/gtk/browser.c
+++ b/tools/perf/ui/gtk/browser.c
@@ -1,5 +1,5 @@
 #include "../evlist.h"
-#include "../cache.h"
+#include "../util.h"
 #include "../evsel.h"
 #include "../sort.h"
 #include "../hist.h"
diff --git a/tools/perf/ui/gtk/hists.c b/tools/perf/ui/gtk/hists.c
index 4677172..9f3db1f 100644
--- a/tools/perf/ui/gtk/hists.c
+++ b/tools/perf/ui/gtk/hists.c
@@ -1,5 +1,5 @@
 #include "../evlist.h"
-#include "../cache.h"
+#include "../util.h"
 #include "../evsel.h"
 #include "../sort.h"
 #include "../hist.h"
diff --git a/tools/perf/ui/gtk/setup.c b/tools/perf/ui/gtk/setup.c
index 1d57676..562a800 100644
--- a/tools/perf/ui/gtk/setup.c
+++ b/tools/perf/ui/gtk/setup.c
@@ -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;
diff --git a/tools/perf/ui/helpline.h b/tools/perf/ui/helpline.h
index 46181f4..66901b2 100644
--- a/tools/perf/ui/helpline.h
+++ b/tools/perf/ui/helpline.h
@@ -4,7 +4,7 @@
 #include <stdio.h>
 #include <stdarg.h>
 
-#include "../util/cache.h"
+#include "../util/util.h"
 
 struct ui_helpline {
 	void (*pop)(void);
diff --git a/tools/perf/ui/progress.c b/tools/perf/ui/progress.c
index a0f24c7..8857f99 100644
--- a/tools/perf/ui/progress.c
+++ b/tools/perf/ui/progress.c
@@ -1,4 +1,4 @@
-#include "../cache.h"
+#include "../util.h"
 #include "progress.h"
 
 static void null_progress__update(struct ui_progress *p __maybe_unused)
diff --git a/tools/perf/ui/setup.c b/tools/perf/ui/setup.c
index ba51fa8..df4bd94 100644
--- a/tools/perf/ui/setup.c
+++ b/tools/perf/ui/setup.c
@@ -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"
 
diff --git a/tools/perf/ui/tui/progress.c b/tools/perf/ui/tui/progress.c
index c4b9900..89df2eb 100644
--- a/tools/perf/ui/tui/progress.c
+++ b/tools/perf/ui/tui/progress.c
@@ -1,4 +1,4 @@
-#include "../cache.h"
+#include "../util.h"
 #include "../progress.h"
 #include "../libslang.h"
 #include "../ui.h"
diff --git a/tools/perf/ui/tui/setup.c b/tools/perf/ui/tui/setup.c
index 7dfeba0..b498733 100644
--- a/tools/perf/ui/tui/setup.c
+++ b/tools/perf/ui/tui/setup.c
@@ -4,7 +4,6 @@
 #include <execinfo.h>
 #endif
 
-#include "../../util/cache.h"
 #include "../../util/debug.h"
 #include "../browser.h"
 #include "../helpline.h"
diff --git a/tools/perf/ui/tui/util.c b/tools/perf/ui/tui/util.c
index d96ad7c..c2de719 100644
--- a/tools/perf/ui/tui/util.c
+++ b/tools/perf/ui/tui/util.c
@@ -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"
diff --git a/tools/perf/util/abspath.c b/tools/perf/util/abspath.c
index 0e76aff..eab5d85 100644
--- a/tools/perf/util/abspath.c
+++ b/tools/perf/util/abspath.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "util.h"
 
 static const char *get_pwd_cwd(void)
 {
diff --git a/tools/perf/util/alias.c b/tools/perf/util/alias.c
index c0b43ee..f905664 100644
--- a/tools/perf/util/alias.c
+++ b/tools/perf/util/alias.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "util.h"
 
 static const char *alias_key;
 static char *alias_val;
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 1dd1949..2ab2407 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -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"
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h
deleted file mode 100644
index 32e1f52..0000000
--- a/tools/perf/util/cache.h
+++ /dev/null
@@ -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 */
diff --git a/tools/perf/util/color.c b/tools/perf/util/color.c
index e5fb88b..f436c12 100644
--- a/tools/perf/util/color.c
+++ b/tools/perf/util/color.c
@@ -1,5 +1,5 @@
 #include <linux/kernel.h>
-#include "cache.h"
+#include "util.h"
 #include "color.h"
 #include <math.h>
 
diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c
index 2e452ac..6b9e91f 100644
--- a/tools/perf/util/config.c
+++ b/tools/perf/util/config.c
@@ -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 */
diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c
index 86d9c73..8931f4e 100644
--- a/tools/perf/util/debug.c
+++ b/tools/perf/util/debug.c
@@ -6,7 +6,6 @@
 #include <stdarg.h>
 #include <stdio.h>
 
-#include "cache.h"
 #include "color.h"
 #include "event.h"
 #include "debug.h"
diff --git a/tools/perf/util/exec_cmd.c b/tools/perf/util/exec_cmd.c
index 1099e92..8d5661e 100644
--- a/tools/perf/util/exec_cmd.c
+++ b/tools/perf/util/exec_cmd.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "util.h"
 #include "exec_cmd.h"
 #include "quote.h"
 
diff --git a/tools/perf/util/help.c b/tools/perf/util/help.c
index 29efb03..2d5e304 100644
--- a/tools/perf/util/help.c
+++ b/tools/perf/util/help.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "util.h"
 #include "../builtin.h"
 #include "exec_cmd.h"
 #include "levenshtein.h"
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index 9409d01..697ed0a 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -23,7 +23,6 @@
 #include <stdint.h>
 #include <inttypes.h>
 
-#include "../cache.h"
 #include "../util.h"
 
 #include "intel-pt-insn-decoder.h"
diff --git a/tools/perf/util/levenshtein.c b/tools/perf/util/levenshtein.c
index e521d15..61bb371 100644
--- a/tools/perf/util/levenshtein.c
+++ b/tools/perf/util/levenshtein.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "util.h"
 #include "levenshtein.h"
 
 /*
diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c
index 00724d4..5f02deb 100644
--- a/tools/perf/util/llvm-utils.c
+++ b/tools/perf/util/llvm-utils.c
@@ -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 "\
diff --git a/tools/perf/util/pager.c b/tools/perf/util/pager.c
index 53ef006..bb19546 100644
--- a/tools/perf/util/pager.c
+++ b/tools/perf/util/pager.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "util.h"
 #include "run-command.h"
 #include "sigchain.h"
 
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 6fc8cd7..d2ec59d 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -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"
diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c
index 29366ae..9937e91 100644
--- a/tools/perf/util/parse-options.c
+++ b/tools/perf/util/parse-options.c
@@ -1,6 +1,5 @@
 #include "util.h"
 #include "parse-options.h"
-#include "cache.h"
 #include "header.h"
 #include <linux/string.h>
 
diff --git a/tools/perf/util/path.c b/tools/perf/util/path.c
index 5d13cb4..1e22ac0 100644
--- a/tools/perf/util/path.c
+++ b/tools/perf/util/path.c
@@ -10,7 +10,7 @@
  *
  * which is what it's designed for.
  */
-#include "cache.h"
+#include "util.h"
 
 static char bad_path[] = "/bad-path/";
 /*
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 93996ec..388fec5 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -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"
diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
index e3b3b92..724a6ce 100644
--- a/tools/perf/util/probe-file.c
+++ b/tools/perf/util/probe-file.c
@@ -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"
diff --git a/tools/perf/util/quote.c b/tools/perf/util/quote.c
index 01f0324..57ed644 100644
--- a/tools/perf/util/quote.c
+++ b/tools/perf/util/quote.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "util.h"
 #include "quote.h"
 
 /* Help to copy the thing properly quoted for the shell safety.
diff --git a/tools/perf/util/run-command.c b/tools/perf/util/run-command.c
index 34622b5..38d2cc6 100644
--- a/tools/perf/util/run-command.c
+++ b/tools/perf/util/run-command.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "util.h"
 #include "run-command.h"
 #include "exec_cmd.h"
 #include "debug.h"
diff --git a/tools/perf/util/sigchain.c b/tools/perf/util/sigchain.c
index ba785e9..5eebf88 100644
--- a/tools/perf/util/sigchain.c
+++ b/tools/perf/util/sigchain.c
@@ -1,5 +1,5 @@
+#include "util.h"
 #include "sigchain.h"
-#include "cache.h"
 
 #define SIGCHAIN_MAX_SIGNALS 32
 
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
index 3122885..139a566 100644
--- a/tools/perf/util/sort.h
+++ b/tools/perf/util/sort.h
@@ -6,7 +6,6 @@
 
 #include "color.h"
 #include <linux/list.h>
-#include "cache.h"
 #include <linux/rbtree.h>
 #include "symbol.h"
 #include "string.h"
diff --git a/tools/perf/util/strbuf.c b/tools/perf/util/strbuf.c
index 25671fa..0e53793 100644
--- a/tools/perf/util/strbuf.c
+++ b/tools/perf/util/strbuf.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "util.h"
 #include <linux/kernel.h>
 
 int prefixcmp(const char *str, const char *prefix)
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index d8e3d8d..c7b50d5 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -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"
diff --git a/tools/perf/util/wrapper.c b/tools/perf/util/wrapper.c
index 19f15b6..861ecfa 100644
--- a/tools/perf/util/wrapper.c
+++ b/tools/perf/util/wrapper.c
@@ -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
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 07/13] perf: Save cmdline arguments earlier
  2015-12-04 21:59 [PATCH 00/13] perf tools: Move perf subcommand framework into lib/tools Josh Poimboeuf
                   ` (5 preceding siblings ...)
  2015-12-04 21:59 ` [PATCH 06/13] perf: Remove cache.h Josh Poimboeuf
@ 2015-12-04 21:59 ` Josh Poimboeuf
  2015-12-04 21:59 ` [PATCH 08/13] perf: Remove check for unused PERF_PAGER_IN_USE Josh Poimboeuf
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 25+ messages in thread
From: Josh Poimboeuf @ 2015-12-04 21:59 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo; +Cc: linux-kernel

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.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 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(-)

diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index bcf4fab..c57e447 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -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);
diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c
index 6af4f7c..7dd5939 100644
--- a/tools/perf/util/env.c
+++ b/tools/perf/util/env.c
@@ -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)
diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c
index 9937e91..735c8c8 100644
--- a/tools/perf/util/parse-options.c
+++ b/tools/perf/util/parse-options.c
@@ -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;
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 08/13] perf: Remove check for unused PERF_PAGER_IN_USE
  2015-12-04 21:59 [PATCH 00/13] perf tools: Move perf subcommand framework into lib/tools Josh Poimboeuf
                   ` (6 preceding siblings ...)
  2015-12-04 21:59 ` [PATCH 07/13] perf: Save cmdline arguments earlier Josh Poimboeuf
@ 2015-12-04 21:59 ` Josh Poimboeuf
  2015-12-04 21:59 ` [PATCH 09/13] perf: Move cmd_version() to builtin-version.c Josh Poimboeuf
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 25+ messages in thread
From: Josh Poimboeuf @ 2015-12-04 21:59 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo; +Cc: linux-kernel

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.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 tools/perf/util/pager.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/tools/perf/util/pager.c b/tools/perf/util/pager.c
index bb19546..6cff2ac 100644
--- a/tools/perf/util/pager.c
+++ b/tools/perf/util/pager.c
@@ -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;
 }
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 09/13] perf: Move cmd_version() to builtin-version.c
  2015-12-04 21:59 [PATCH 00/13] perf tools: Move perf subcommand framework into lib/tools Josh Poimboeuf
                   ` (7 preceding siblings ...)
  2015-12-04 21:59 ` [PATCH 08/13] perf: Remove check for unused PERF_PAGER_IN_USE Josh Poimboeuf
@ 2015-12-04 21:59 ` Josh Poimboeuf
  2015-12-04 21:59 ` [PATCH 10/13] perf: Move help_unknown_cmd() to its own file Josh Poimboeuf
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 25+ messages in thread
From: Josh Poimboeuf @ 2015-12-04 21:59 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo; +Cc: linux-kernel

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

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 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

diff --git a/tools/perf/Build b/tools/perf/Build
index 2c7aaf2..2a41217 100644
--- a/tools/perf/Build
+++ b/tools/perf/Build
@@ -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
diff --git a/tools/perf/builtin-version.c b/tools/perf/builtin-version.c
new file mode 100644
index 0000000..0587ec6
--- /dev/null
+++ b/tools/perf/builtin-version.c
@@ -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;
+}
diff --git a/tools/perf/util/help.c b/tools/perf/util/help.c
index 2d5e304..573ce05 100644
--- a/tools/perf/util/help.c
+++ b/tools/perf/util/help.c
@@ -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;
-}
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 10/13] perf: Move help_unknown_cmd() to its own file
  2015-12-04 21:59 [PATCH 00/13] perf tools: Move perf subcommand framework into lib/tools Josh Poimboeuf
                   ` (8 preceding siblings ...)
  2015-12-04 21:59 ` [PATCH 09/13] perf: Move cmd_version() to builtin-version.c Josh Poimboeuf
@ 2015-12-04 21:59 ` Josh Poimboeuf
  2015-12-04 21:59 ` [PATCH 11/13] perf tools: Move strlcpy() to tools/lib/string.c Josh Poimboeuf
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 25+ messages in thread
From: Josh Poimboeuf @ 2015-12-04 21:59 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo; +Cc: linux-kernel

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.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 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

diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 65fef59..99b3dae 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -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
diff --git a/tools/perf/util/help-unknown-cmd.c b/tools/perf/util/help-unknown-cmd.c
new file mode 100644
index 0000000..c30ae78
--- /dev/null
+++ b/tools/perf/util/help-unknown-cmd.c
@@ -0,0 +1,103 @@
+#include "util.h"
+#include "help.h"
+#include "../builtin.h"
+#include "levenshtein.h"
+
+static int autocorrect;
+static struct cmdnames aliases;
+
+static int perf_unknown_cmd_config(const char *var, const char *value, void *cb)
+{
+	if (!strcmp(var, "help.autocorrect"))
+		autocorrect = perf_config_int(var,value);
+	/* Also use aliases for command lookup */
+	if (!prefixcmp(var, "alias."))
+		add_cmdname(&aliases, var + 6, strlen(var + 6));
+
+	return perf_default_config(var, value, cb);
+}
+
+static int levenshtein_compare(const void *p1, const void *p2)
+{
+	const struct cmdname *const *c1 = p1, *const *c2 = p2;
+	const char *s1 = (*c1)->name, *s2 = (*c2)->name;
+	int l1 = (*c1)->len;
+	int l2 = (*c2)->len;
+	return l1 != l2 ? l1 - l2 : strcmp(s1, s2);
+}
+
+static void add_cmd_list(struct cmdnames *cmds, struct cmdnames *old)
+{
+	unsigned int i;
+
+	ALLOC_GROW(cmds->names, cmds->cnt + old->cnt, cmds->alloc);
+
+	for (i = 0; i < old->cnt; i++)
+		cmds->names[cmds->cnt++] = old->names[i];
+	zfree(&old->names);
+	old->cnt = 0;
+}
+
+const char *help_unknown_cmd(const char *cmd)
+{
+	unsigned int i, n = 0, best_similarity = 0;
+	struct cmdnames main_cmds, other_cmds;
+
+	memset(&main_cmds, 0, sizeof(main_cmds));
+	memset(&other_cmds, 0, sizeof(main_cmds));
+	memset(&aliases, 0, sizeof(aliases));
+
+	perf_config(perf_unknown_cmd_config, NULL);
+
+	load_command_list("perf-", &main_cmds, &other_cmds);
+
+	add_cmd_list(&main_cmds, &aliases);
+	add_cmd_list(&main_cmds, &other_cmds);
+	qsort(main_cmds.names, main_cmds.cnt,
+	      sizeof(main_cmds.names), cmdname_compare);
+	uniq(&main_cmds);
+
+	if (main_cmds.cnt) {
+		/* This reuses cmdname->len for similarity index */
+		for (i = 0; i < main_cmds.cnt; ++i)
+			main_cmds.names[i]->len =
+				levenshtein(cmd, main_cmds.names[i]->name, 0, 2, 1, 4);
+
+		qsort(main_cmds.names, main_cmds.cnt,
+		      sizeof(*main_cmds.names), levenshtein_compare);
+
+		best_similarity = main_cmds.names[0]->len;
+		n = 1;
+		while (n < main_cmds.cnt && best_similarity == main_cmds.names[n]->len)
+			++n;
+	}
+
+	if (autocorrect && n == 1) {
+		const char *assumed = main_cmds.names[0]->name;
+
+		main_cmds.names[0] = NULL;
+		clean_cmdnames(&main_cmds);
+		fprintf(stderr, "WARNING: You called a perf program named '%s', "
+			"which does not exist.\n"
+			"Continuing under the assumption that you meant '%s'\n",
+			cmd, assumed);
+		if (autocorrect > 0) {
+			fprintf(stderr, "in %0.1f seconds automatically...\n",
+				(float)autocorrect/10.0);
+			poll(NULL, 0, autocorrect * 100);
+		}
+		return assumed;
+	}
+
+	fprintf(stderr, "perf: '%s' is not a perf-command. See 'perf --help'.\n", cmd);
+
+	if (main_cmds.cnt && best_similarity < 6) {
+		fprintf(stderr, "\nDid you mean %s?\n",
+			n < 2 ? "this": "one of these");
+
+		for (i = 0; i < n; i++)
+			fprintf(stderr, "\t%s\n", main_cmds.names[i]->name);
+	}
+
+	exit(1);
+}
diff --git a/tools/perf/util/help-unknown-cmd.h b/tools/perf/util/help-unknown-cmd.h
new file mode 100644
index 0000000..e69de29
diff --git a/tools/perf/util/help.c b/tools/perf/util/help.c
index 573ce05..dfe9c5f 100644
--- a/tools/perf/util/help.c
+++ b/tools/perf/util/help.c
@@ -1,9 +1,6 @@
 #include "util.h"
-#include "../builtin.h"
 #include "exec_cmd.h"
-#include "levenshtein.h"
 #include "help.h"
-#include <termios.h>
 
 void add_cmdname(struct cmdnames *cmds, const char *name, size_t len)
 {
@@ -17,7 +14,7 @@ void add_cmdname(struct cmdnames *cmds, const char *name, size_t len)
 	cmds->names[cmds->cnt++] = ent;
 }
 
-static void clean_cmdnames(struct cmdnames *cmds)
+void clean_cmdnames(struct cmdnames *cmds)
 {
 	unsigned int i;
 
@@ -28,14 +25,14 @@ static void clean_cmdnames(struct cmdnames *cmds)
 	cmds->alloc = 0;
 }
 
-static int cmdname_compare(const void *a_, const void *b_)
+int cmdname_compare(const void *a_, const void *b_)
 {
 	struct cmdname *a = *(struct cmdname **)a_;
 	struct cmdname *b = *(struct cmdname **)b_;
 	return strcmp(a->name, b->name);
 }
 
-static void uniq(struct cmdnames *cmds)
+void uniq(struct cmdnames *cmds)
 {
 	unsigned int i, j;
 
@@ -241,102 +238,3 @@ int is_in_cmdlist(struct cmdnames *c, const char *s)
 			return 1;
 	return 0;
 }
-
-static int autocorrect;
-static struct cmdnames aliases;
-
-static int perf_unknown_cmd_config(const char *var, const char *value, void *cb)
-{
-	if (!strcmp(var, "help.autocorrect"))
-		autocorrect = perf_config_int(var,value);
-	/* Also use aliases for command lookup */
-	if (!prefixcmp(var, "alias."))
-		add_cmdname(&aliases, var + 6, strlen(var + 6));
-
-	return perf_default_config(var, value, cb);
-}
-
-static int levenshtein_compare(const void *p1, const void *p2)
-{
-	const struct cmdname *const *c1 = p1, *const *c2 = p2;
-	const char *s1 = (*c1)->name, *s2 = (*c2)->name;
-	int l1 = (*c1)->len;
-	int l2 = (*c2)->len;
-	return l1 != l2 ? l1 - l2 : strcmp(s1, s2);
-}
-
-static void add_cmd_list(struct cmdnames *cmds, struct cmdnames *old)
-{
-	unsigned int i;
-
-	ALLOC_GROW(cmds->names, cmds->cnt + old->cnt, cmds->alloc);
-
-	for (i = 0; i < old->cnt; i++)
-		cmds->names[cmds->cnt++] = old->names[i];
-	zfree(&old->names);
-	old->cnt = 0;
-}
-
-const char *help_unknown_cmd(const char *cmd)
-{
-	unsigned int i, n = 0, best_similarity = 0;
-	struct cmdnames main_cmds, other_cmds;
-
-	memset(&main_cmds, 0, sizeof(main_cmds));
-	memset(&other_cmds, 0, sizeof(main_cmds));
-	memset(&aliases, 0, sizeof(aliases));
-
-	perf_config(perf_unknown_cmd_config, NULL);
-
-	load_command_list("perf-", &main_cmds, &other_cmds);
-
-	add_cmd_list(&main_cmds, &aliases);
-	add_cmd_list(&main_cmds, &other_cmds);
-	qsort(main_cmds.names, main_cmds.cnt,
-	      sizeof(main_cmds.names), cmdname_compare);
-	uniq(&main_cmds);
-
-	if (main_cmds.cnt) {
-		/* This reuses cmdname->len for similarity index */
-		for (i = 0; i < main_cmds.cnt; ++i)
-			main_cmds.names[i]->len =
-				levenshtein(cmd, main_cmds.names[i]->name, 0, 2, 1, 4);
-
-		qsort(main_cmds.names, main_cmds.cnt,
-		      sizeof(*main_cmds.names), levenshtein_compare);
-
-		best_similarity = main_cmds.names[0]->len;
-		n = 1;
-		while (n < main_cmds.cnt && best_similarity == main_cmds.names[n]->len)
-			++n;
-	}
-
-	if (autocorrect && n == 1) {
-		const char *assumed = main_cmds.names[0]->name;
-
-		main_cmds.names[0] = NULL;
-		clean_cmdnames(&main_cmds);
-		fprintf(stderr, "WARNING: You called a perf program named '%s', "
-			"which does not exist.\n"
-			"Continuing under the assumption that you meant '%s'\n",
-			cmd, assumed);
-		if (autocorrect > 0) {
-			fprintf(stderr, "in %0.1f seconds automatically...\n",
-				(float)autocorrect/10.0);
-			poll(NULL, 0, autocorrect * 100);
-		}
-		return assumed;
-	}
-
-	fprintf(stderr, "perf: '%s' is not a perf-command. See 'perf --help'.\n", cmd);
-
-	if (main_cmds.cnt && best_similarity < 6) {
-		fprintf(stderr, "\nDid you mean %s?\n",
-			n < 2 ? "this": "one of these");
-
-		for (i = 0; i < n; i++)
-			fprintf(stderr, "\t%s\n", main_cmds.names[i]->name);
-	}
-
-	exit(1);
-}
diff --git a/tools/perf/util/help.h b/tools/perf/util/help.h
index 7f5c6de..14851b0 100644
--- a/tools/perf/util/help.h
+++ b/tools/perf/util/help.h
@@ -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);
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 11/13] perf tools: Move strlcpy() to tools/lib/string.c
  2015-12-04 21:59 [PATCH 00/13] perf tools: Move perf subcommand framework into lib/tools Josh Poimboeuf
                   ` (9 preceding siblings ...)
  2015-12-04 21:59 ` [PATCH 10/13] perf: Move help_unknown_cmd() to its own file Josh Poimboeuf
@ 2015-12-04 21:59 ` Josh Poimboeuf
  2015-12-04 21:59 ` [PATCH 12/13] perf tools: Move perf subcommand framework into a library Josh Poimboeuf
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 25+ messages in thread
From: Josh Poimboeuf @ 2015-12-04 21:59 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo; +Cc: linux-kernel

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.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 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(-)

diff --git a/tools/include/linux/string.h b/tools/include/linux/string.h
index 2e2f736..eae1d87 100644
--- a/tools/include/linux/string.h
+++ b/tools/include/linux/string.h
@@ -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_ */
diff --git a/tools/lib/string.c b/tools/lib/string.c
index 065e54f..3366582 100644
--- a/tools/lib/string.c
+++ b/tools/lib/string.c
@@ -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;
+}
diff --git a/tools/perf/util/path.c b/tools/perf/util/path.c
index 1e22ac0..416fe7d 100644
--- a/tools/perf/util/path.c
+++ b/tools/perf/util/path.c
@@ -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];
diff --git a/tools/perf/util/path.h b/tools/perf/util/path.h
index 3604e82f..1df12e7 100644
--- a/tools/perf/util/path.h
+++ b/tools/perf/util/path.h
@@ -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 */
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index c7b50d5..2c6db35 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -3,6 +3,7 @@
 
 #include "compat-util.h"
 
+#include <linux/string.h>
 #include "../perf.h"
 #include "abspath.h"
 #include "alias.h"
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 12/13] perf tools: Move perf subcommand framework into a library
  2015-12-04 21:59 [PATCH 00/13] perf tools: Move perf subcommand framework into lib/tools Josh Poimboeuf
                   ` (10 preceding siblings ...)
  2015-12-04 21:59 ` [PATCH 11/13] perf tools: Move strlcpy() to tools/lib/string.c Josh Poimboeuf
@ 2015-12-04 21:59 ` Josh Poimboeuf
  2015-12-04 22:21   ` [PATCH 12/13 v1.1] perf tools: Move tools/lib/string.c to libapi Josh Poimboeuf
  2015-12-04 21:59 ` [PATCH 13/13] perf tools: Move subcommand framework and related utils " Josh Poimboeuf
  2015-12-06  9:37 ` [PATCH 00/13] perf tools: Move perf subcommand framework into lib/tools Ingo Molnar
  13 siblings, 1 reply; 25+ messages in thread
From: Josh Poimboeuf @ 2015-12-04 21:59 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo; +Cc: linux-kernel

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.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 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%)

diff --git a/tools/lib/api/Build b/tools/lib/api/Build
index e8b8a23..9e3967e 100644
--- a/tools/lib/api/Build
+++ b/tools/lib/api/Build
@@ -1,3 +1,4 @@
 libapi-y += fd/
 libapi-y += fs/
 libapi-y += cpu.o
+libapi-y += string/
diff --git a/tools/lib/api/string/Build b/tools/lib/api/string/Build
new file mode 100644
index 0000000..7707d3d
--- /dev/null
+++ b/tools/lib/api/string/Build
@@ -0,0 +1 @@
+libapi-y += string.o
diff --git a/tools/lib/string.c b/tools/lib/api/string/string.c
similarity index 93%
rename from tools/lib/string.c
rename to tools/lib/api/string/string.c
index 3366582..3140ba3 100644
--- a/tools/lib/string.c
+++ b/tools/lib/api/string/string.c
@@ -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
diff --git a/tools/include/linux/string.h b/tools/lib/api/string/string.h
similarity index 66%
rename from tools/include/linux/string.h
rename to tools/lib/api/string/string.h
index eae1d87..74bd4fd 100644
--- a/tools/include/linux/string.h
+++ b/tools/lib/api/string/string.h
@@ -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 */
diff --git a/tools/perf/MANIFEST b/tools/perf/MANIFEST
index 2562eac..39c38cb 100644
--- a/tools/perf/MANIFEST
+++ b/tools/perf/MANIFEST
@@ -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
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 1c3d3d9..cdf487b 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -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>
 
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 99b3dae..02d3a54 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -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)
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index 7f10430..cc83262 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -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>
diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index 540a7ef..5a99b6a 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -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"
diff --git a/tools/perf/util/intel-pt-decoder/insn.c b/tools/perf/util/intel-pt-decoder/insn.c
index 47314a6..bcf3a8e 100644
--- a/tools/perf/util/intel-pt-decoder/insn.c
+++ b/tools/perf/util/intel-pt-decoder/insn.c
@@ -19,7 +19,7 @@
  */
 
 #ifdef __KERNEL__
-#include <linux/string.h>
+#include <api/string/string.h>
 #else
 #include <string.h>
 #endif
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index 93d9f1c..c9f716d 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -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);
 
diff --git a/tools/perf/util/ordered-events.c b/tools/perf/util/ordered-events.c
index b1b9e23..867ae98 100644
--- a/tools/perf/util/ordered-events.c
+++ b/tools/perf/util/ordered-events.c
@@ -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"
diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c
index 735c8c8..8d70c1b 100644
--- a/tools/perf/util/parse-options.c
+++ b/tools/perf/util/parse-options.c
@@ -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
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 2c6db35..f1c07f6 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -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"
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 13/13] perf tools: Move subcommand framework and related utils to libapi
  2015-12-04 21:59 [PATCH 00/13] perf tools: Move perf subcommand framework into lib/tools Josh Poimboeuf
                   ` (11 preceding siblings ...)
  2015-12-04 21:59 ` [PATCH 12/13] perf tools: Move perf subcommand framework into a library Josh Poimboeuf
@ 2015-12-04 21:59 ` Josh Poimboeuf
  2015-12-06  9:37 ` [PATCH 00/13] perf tools: Move perf subcommand framework into lib/tools Ingo Molnar
  13 siblings, 0 replies; 25+ messages in thread
From: Josh Poimboeuf @ 2015-12-04 21:59 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo; +Cc: linux-kernel

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.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 tools/include/asm-generic/bitops/__fls.h     |  2 +-
 tools/include/asm-generic/bitops/fls.h       |  2 +-
 tools/include/asm-generic/bitops/fls64.h     |  2 +-
 tools/lib/api/Build                          |  1 +
 tools/lib/api/Makefile                       |  6 +++-
 tools/lib/api/util/Build                     | 13 +++++++++
 tools/{perf => lib/api}/util/abspath.c       |  6 +++-
 tools/{perf => lib/api}/util/abspath.h       |  6 ++--
 tools/lib/api/util/cfg.c                     | 12 ++++++++
 tools/lib/api/util/cfg.h                     | 15 ++++++++++
 tools/{perf => lib/api}/util/compat-util.h   |  7 ++---
 tools/{perf => lib/api}/util/ctype.c         |  3 +-
 tools/{perf => lib/api}/util/ctype.h         |  6 ++--
 tools/{perf => lib/api}/util/exec_cmd.c      | 42 ++++++++++++++--------------
 tools/{perf => lib/api}/util/exec_cmd.h      | 18 ++++++------
 tools/{perf => lib/api}/util/help.c          | 11 +++++---
 tools/{perf => lib/api}/util/help.h          |  0
 tools/{perf => lib/api}/util/pager.c         |  6 ++--
 tools/{perf => lib/api}/util/pager.h         |  6 ++--
 tools/{perf => lib/api}/util/parse-options.c | 21 ++++++++++----
 tools/{perf => lib/api}/util/parse-options.h |  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%)

diff --git a/tools/include/asm-generic/bitops/__fls.h b/tools/include/asm-generic/bitops/__fls.h
index 2218b9a..494c9c6 100644
--- a/tools/include/asm-generic/bitops/__fls.h
+++ b/tools/include/asm-generic/bitops/__fls.h
@@ -1 +1 @@
-#include <../../../../include/asm-generic/bitops/__fls.h>
+#include "../../../../include/asm-generic/bitops/__fls.h"
diff --git a/tools/include/asm-generic/bitops/fls.h b/tools/include/asm-generic/bitops/fls.h
index dbf711a..0e4995f 100644
--- a/tools/include/asm-generic/bitops/fls.h
+++ b/tools/include/asm-generic/bitops/fls.h
@@ -1 +1 @@
-#include <../../../../include/asm-generic/bitops/fls.h>
+#include "../../../../include/asm-generic/bitops/fls.h"
diff --git a/tools/include/asm-generic/bitops/fls64.h b/tools/include/asm-generic/bitops/fls64.h
index 980b1f6..35bee00 100644
--- a/tools/include/asm-generic/bitops/fls64.h
+++ b/tools/include/asm-generic/bitops/fls64.h
@@ -1 +1 @@
-#include <../../../../include/asm-generic/bitops/fls64.h>
+#include "../../../../include/asm-generic/bitops/fls64.h"
diff --git a/tools/lib/api/Build b/tools/lib/api/Build
index 9e3967e..6ad3ac2 100644
--- a/tools/lib/api/Build
+++ b/tools/lib/api/Build
@@ -2,3 +2,4 @@ libapi-y += fd/
 libapi-y += fs/
 libapi-y += cpu.o
 libapi-y += string/
+libapi-y += util/
diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile
index d85904d..ad896c2 100644
--- a/tools/lib/api/Makefile
+++ b/tools/lib/api/Makefile
@@ -17,7 +17,11 @@ LIBFILE = $(OUTPUT)libapi.a
 
 CFLAGS := $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
 CFLAGS += -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fPIC
-CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
+CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
+
+CFLAGS += -I$(srctree)/tools/include/
+CFLAGS += -I$(srctree)/include/uapi
+CFLAGS += -I$(srctree)/include
 
 RM = rm -f
 
diff --git a/tools/lib/api/util/Build b/tools/lib/api/util/Build
new file mode 100644
index 0000000..6f95278
--- /dev/null
+++ b/tools/lib/api/util/Build
@@ -0,0 +1,13 @@
+libapi-y += abspath.o
+libapi-y += cfg.o
+libapi-y += ctype.o
+libapi-y += exec_cmd.o
+libapi-y += help.o
+libapi-y += pager.o
+libapi-y += parse-options.o
+libapi-y += run-command.o
+libapi-y += sigchain.o
+libapi-y += strbuf.o
+libapi-y += term.o
+libapi-y += usage.o
+libapi-y += wrapper.o
diff --git a/tools/perf/util/abspath.c b/tools/lib/api/util/abspath.c
similarity index 90%
rename from tools/perf/util/abspath.c
rename to tools/lib/api/util/abspath.c
index eab5d85..9827a3f 100644
--- a/tools/perf/util/abspath.c
+++ b/tools/lib/api/util/abspath.c
@@ -1,4 +1,8 @@
-#include "util.h"
+#include "compat-util.h"
+
+#include "../string/string.h"
+#include "abspath.h"
+#include "usage.h"
 
 static const char *get_pwd_cwd(void)
 {
diff --git a/tools/perf/util/abspath.h b/tools/lib/api/util/abspath.h
similarity index 59%
rename from tools/perf/util/abspath.h
rename to tools/lib/api/util/abspath.h
index 13549fb..fa5d82a 100644
--- a/tools/perf/util/abspath.h
+++ b/tools/lib/api/util/abspath.h
@@ -1,5 +1,5 @@
-#ifndef __PERF_ABSPATH_H
-#define __PERF_ABSPATH_H
+#ifndef __API_UTIL_ABSPATH_H
+#define __API_UTIL_ABSPATH_H
 
 static inline int is_absolute_path(const char *path)
 {
@@ -8,4 +8,4 @@ static inline int is_absolute_path(const char *path)
 
 const char *make_nonrelative_path(const char *path);
 
-#endif /* __PERF_ABSPATH_H */
+#endif /* __API_UTIL_ABSPATH_H */
diff --git a/tools/lib/api/util/cfg.c b/tools/lib/api/util/cfg.c
new file mode 100644
index 0000000..40653dc
--- /dev/null
+++ b/tools/lib/api/util/cfg.c
@@ -0,0 +1,12 @@
+#include "compat-util.h"
+#include "cfg.h"
+
+#define UNDEFINED "UNDEFINED"
+
+struct util_cfg util_cfg = {
+	.prefix		= UNDEFINED,
+	.exec_name	= UNDEFINED,
+	.exec_path	= UNDEFINED,
+	.exec_path_env	= UNDEFINED,
+	.pager_env	= UNDEFINED,
+};
diff --git a/tools/lib/api/util/cfg.h b/tools/lib/api/util/cfg.h
new file mode 100644
index 0000000..f271732
--- /dev/null
+++ b/tools/lib/api/util/cfg.h
@@ -0,0 +1,15 @@
+#ifndef __API_UTIL_CONFIG_H
+#define __API_UTIL_CONFIG_H
+
+struct util_cfg {
+	const char *prefix;
+	const char *exec_name;
+	const char *exec_path;
+	const char *exec_path_env;
+	const char *pager_env;
+	void (*exit_browser)(void);
+};
+
+extern struct util_cfg util_cfg;
+
+#endif /* #define __API_UTIL_CONFIG_H */
diff --git a/tools/perf/util/compat-util.h b/tools/lib/api/util/compat-util.h
similarity index 95%
rename from tools/perf/util/compat-util.h
rename to tools/lib/api/util/compat-util.h
index f472a98..ab2b257 100644
--- a/tools/perf/util/compat-util.h
+++ b/tools/lib/api/util/compat-util.h
@@ -1,5 +1,5 @@
-#ifndef __PERF_COMPAT_UTIL_H
-#define __PERF_COMPAT_UTIL_H
+#ifndef __API_UTIL_COMPAT_UTIL_H
+#define __API_UTIL_COMPAT_UTIL_H
 
 #ifndef FLEX_ARRAY
 /*
@@ -74,7 +74,6 @@
 #include <linux/magic.h>
 #include <linux/types.h>
 #include <sys/ttydefaults.h>
-#include <api/fs/tracing_path.h>
 #include <termios.h>
 #include <linux/bitops.h>
 #include <termios.h>
@@ -127,4 +126,4 @@
 #define NSEC_PER_MSEC	1000000L
 #endif
 
-#endif /* __PERF_COMPAT_UTIL_H */
+#endif /* __API_UTIL_COMPAT_UTIL_H */
diff --git a/tools/perf/util/ctype.c b/tools/lib/api/util/ctype.c
similarity index 97%
rename from tools/perf/util/ctype.c
rename to tools/lib/api/util/ctype.c
index aada3ac..a7b2d33 100644
--- a/tools/perf/util/ctype.c
+++ b/tools/lib/api/util/ctype.c
@@ -3,7 +3,8 @@
  *
  * No surprises, and works with signed and unsigned chars.
  */
-#include "util.h"
+#include "compat-util.h"
+#include "ctype.h"
 
 enum {
 	S = GIT_SPACE,
diff --git a/tools/perf/util/ctype.h b/tools/lib/api/util/ctype.h
similarity index 93%
rename from tools/perf/util/ctype.h
rename to tools/lib/api/util/ctype.h
index b66bfeb..1be5f8d 100644
--- a/tools/perf/util/ctype.h
+++ b/tools/lib/api/util/ctype.h
@@ -1,5 +1,5 @@
-#ifndef __PERF_CTYPE_H
-#define __PERF_CTYPE_H
+#ifndef __API_UTIL_CTYPE_H
+#define __API_UTIL_CTYPE_H
 
 /* Sane ctype - no locale, and works with signed chars */
 #undef isascii
@@ -49,4 +49,4 @@ static inline int sane_case(int x, int high)
 	return x;
 }
 
-#endif /* __PERF_CTYPE_H */
+#endif /* __API_UTIL_CTYPE_H */
diff --git a/tools/perf/util/exec_cmd.c b/tools/lib/api/util/exec_cmd.c
similarity index 72%
rename from tools/perf/util/exec_cmd.c
rename to tools/lib/api/util/exec_cmd.c
index 8d5661e..7466924 100644
--- a/tools/perf/util/exec_cmd.c
+++ b/tools/lib/api/util/exec_cmd.c
@@ -1,8 +1,9 @@
-#include "util.h"
+#include "compat-util.h"
 #include "exec_cmd.h"
-#include "quote.h"
-
-#include <string.h>
+#include "strbuf.h"
+#include "abspath.h"
+#include "usage.h"
+#include "cfg.h"
 
 #define MAX_ARGS	32
 
@@ -11,18 +12,17 @@ static const char *argv0_path;
 
 char *system_path(const char *path)
 {
-	static const char *prefix = PREFIX;
 	struct strbuf d = STRBUF_INIT;
 
 	if (is_absolute_path(path))
 		return strdup(path);
 
-	strbuf_addf(&d, "%s/%s", prefix, path);
+	strbuf_addf(&d, "%s/%s", util_cfg.prefix, path);
 	path = strbuf_detach(&d, NULL);
 	return (char *)path;
 }
 
-const char *perf_extract_argv0_path(const char *argv0)
+const char *extract_argv0_path(const char *argv0)
 {
 	const char *slash;
 
@@ -41,29 +41,29 @@ const char *perf_extract_argv0_path(const char *argv0)
 	return argv0;
 }
 
-void perf_set_argv_exec_path(const char *exec_path)
+void set_argv_exec_path(const char *exec_path)
 {
 	argv_exec_path = exec_path;
 	/*
 	 * Propagate this setting to external programs.
 	 */
-	setenv(EXEC_PATH_ENVIRONMENT, exec_path, 1);
+	setenv(util_cfg.exec_path_env, exec_path, 1);
 }
 
 
-/* Returns the highest-priority, location to look for perf programs. */
-char *perf_exec_path(void)
+/* Returns the highest-priority location to look for subprograms. */
+char *get_argv_exec_path(void)
 {
 	char *env;
 
 	if (argv_exec_path)
 		return strdup(argv_exec_path);
 
-	env = getenv(EXEC_PATH_ENVIRONMENT);
+	env = getenv(util_cfg.exec_path_env);
 	if (env && *env)
 		return strdup(env);
 
-	return system_path(PERF_EXEC_PATH);
+	return system_path(util_cfg.exec_path);
 }
 
 static void add_path(struct strbuf *out, const char *path)
@@ -82,7 +82,7 @@ void setup_path(void)
 {
 	const char *old_path = getenv("PATH");
 	struct strbuf new_path = STRBUF_INIT;
-	char *tmp = perf_exec_path();
+	char *tmp = get_argv_exec_path();
 
 	add_path(&new_path, tmp);
 	add_path(&new_path, argv0_path);
@@ -98,7 +98,7 @@ void setup_path(void)
 	strbuf_release(&new_path);
 }
 
-static const char **prepare_perf_cmd(const char **argv)
+static const char **prepare_exec_cmd(const char **argv)
 {
 	int argc;
 	const char **nargv;
@@ -107,25 +107,25 @@ static const char **prepare_perf_cmd(const char **argv)
 		; /* just counting */
 	nargv = malloc(sizeof(*nargv) * (argc + 2));
 
-	nargv[0] = "perf";
+	nargv[0] = util_cfg.exec_name;
 	for (argc = 0; argv[argc]; argc++)
 		nargv[argc + 1] = argv[argc];
 	nargv[argc + 1] = NULL;
 	return nargv;
 }
 
-int execv_perf_cmd(const char **argv) {
-	const char **nargv = prepare_perf_cmd(argv);
+int execv_cmd(const char **argv) {
+	const char **nargv = prepare_exec_cmd(argv);
 
 	/* execvp() can only ever return if it fails */
-	execvp("perf", (char **)nargv);
+	execvp(util_cfg.exec_name, (char **)nargv);
 
 	free(nargv);
 	return -1;
 }
 
 
-int execl_perf_cmd(const char *cmd,...)
+int execl_cmd(const char *cmd,...)
 {
 	int argc;
 	const char *argv[MAX_ARGS + 1];
@@ -145,5 +145,5 @@ int execl_perf_cmd(const char *cmd,...)
 		return error("too many args to run %s", cmd);
 
 	argv[argc] = NULL;
-	return execv_perf_cmd(argv);
+	return execv_cmd(argv);
 }
diff --git a/tools/perf/util/exec_cmd.h b/tools/lib/api/util/exec_cmd.h
similarity index 14%
rename from tools/perf/util/exec_cmd.h
rename to tools/lib/api/util/exec_cmd.h
index 48b4175..c826713 100644
--- a/tools/perf/util/exec_cmd.h
+++ b/tools/lib/api/util/exec_cmd.h
@@ -1,13 +1,13 @@
-#ifndef __PERF_EXEC_CMD_H
-#define __PERF_EXEC_CMD_H
+#ifndef __API_UTIL_EXEC_CMD_H
+#define __API_UTIL_EXEC_CMD_H
 
-extern void perf_set_argv_exec_path(const char *exec_path);
-extern const char *perf_extract_argv0_path(const char *path);
+extern void set_argv_exec_path(const char *exec_path);
+extern const char *extract_argv0_path(const char *path);
 extern void setup_path(void);
-extern int execv_perf_cmd(const char **argv); /* NULL terminated */
-extern int execl_perf_cmd(const char *cmd, ...);
-/* perf_exec_path and system_path return malloc'd string, caller must free it */
-extern char *perf_exec_path(void);
+extern int execv_cmd(const char **argv); /* NULL terminated */
+extern int execl_cmd(const char *cmd, ...);
+/* get_argv_exec_path and system_path return malloc'd string, caller must free it */
+extern char *get_argv_exec_path(void);
 extern char *system_path(const char *path);
 
-#endif /* __PERF_EXEC_CMD_H */
+#endif /* __API_UTIL_EXEC_CMD_H */
diff --git a/tools/perf/util/help.c b/tools/lib/api/util/help.c
similarity index 96%
rename from tools/perf/util/help.c
rename to tools/lib/api/util/help.c
index dfe9c5f..36b3e60 100644
--- a/tools/perf/util/help.c
+++ b/tools/lib/api/util/help.c
@@ -1,6 +1,9 @@
-#include "util.h"
-#include "exec_cmd.h"
+#include "compat-util.h"
 #include "help.h"
+#include "exec_cmd.h"
+#include "strbuf.h"
+#include "wrapper.h"
+#include "term.h"
 
 void add_cmdname(struct cmdnames *cmds, const char *name, size_t len)
 {
@@ -164,7 +167,7 @@ void load_command_list(const char *prefix,
 		struct cmdnames *other_cmds)
 {
 	const char *env_path = getenv("PATH");
-	char *exec_path = perf_exec_path();
+	char *exec_path = get_argv_exec_path();
 
 	if (exec_path) {
 		list_commands_in_dir(main_cmds, exec_path, prefix);
@@ -209,7 +212,7 @@ void list_commands(const char *title, struct cmdnames *main_cmds,
 			longest = other_cmds->names[i]->len;
 
 	if (main_cmds->cnt) {
-		char *exec_path = perf_exec_path();
+		char *exec_path = get_argv_exec_path();
 		printf("available %s in '%s'\n", title, exec_path);
 		printf("----------------");
 		mput_char('-', strlen(title) + strlen(exec_path));
diff --git a/tools/perf/util/help.h b/tools/lib/api/util/help.h
similarity index 100%
rename from tools/perf/util/help.h
rename to tools/lib/api/util/help.h
diff --git a/tools/perf/util/pager.c b/tools/lib/api/util/pager.c
similarity index 93%
rename from tools/perf/util/pager.c
rename to tools/lib/api/util/pager.c
index 6cff2ac..97a59ed 100644
--- a/tools/perf/util/pager.c
+++ b/tools/lib/api/util/pager.c
@@ -1,6 +1,8 @@
-#include "util.h"
+#include "compat-util.h"
+#include "pager.h"
 #include "run-command.h"
 #include "sigchain.h"
+#include "cfg.h"
 
 /*
  * This is split up from the rest of git so that we can do
@@ -46,7 +48,7 @@ static void wait_for_pager_signal(int signo)
 
 void setup_pager(void)
 {
-	const char *pager = getenv("PERF_PAGER");
+	const char *pager = getenv(util_cfg.pager_env);
 
 	if (!isatty(1))
 		return;
diff --git a/tools/perf/util/pager.h b/tools/lib/api/util/pager.h
similarity index 42%
rename from tools/perf/util/pager.h
rename to tools/lib/api/util/pager.h
index 2794a83..3c13659 100644
--- a/tools/perf/util/pager.h
+++ b/tools/lib/api/util/pager.h
@@ -1,7 +1,7 @@
-#ifndef __PERF_PAGER_H
-#define __PERF_PAGER_H
+#ifndef __API_UTIL_PAGER_H
+#define __API_UTIL_PAGER_H
 
 extern void setup_pager(void);
 extern int pager_in_use(void);
 
-#endif /* __PERF_PAGER_H */
+#endif /* __API_UTIL_PAGER_H */
diff --git a/tools/perf/util/parse-options.c b/tools/lib/api/util/parse-options.c
similarity index 98%
rename from tools/perf/util/parse-options.c
rename to tools/lib/api/util/parse-options.c
index 8d70c1b..9e334a9 100644
--- a/tools/perf/util/parse-options.c
+++ b/tools/lib/api/util/parse-options.c
@@ -1,7 +1,12 @@
-#include "util.h"
+#include "compat-util.h"
+
+#include "../string/string.h"
 #include "parse-options.h"
-#include "header.h"
-#include <api/string/string.h>
+#include "strbuf.h"
+#include "usage.h"
+#include "ctype.h"
+#include "pager.h"
+#include "cfg.h"
 
 #define OPT_SHORT 1
 #define OPT_UNSET 2
@@ -510,7 +515,8 @@ int parse_options_subcommand(int argc, const char **argv, const struct option *o
 	if (subcommands && !usagestr[0]) {
 		struct strbuf buf = STRBUF_INIT;
 
-		strbuf_addf(&buf, "perf %s [<options>] {", argv[0]);
+		strbuf_addf(&buf, "%s %s [<options>] {",
+			    util_cfg.exec_name, argv[0]);
 		for (int i = 0; subcommands[i]; i++) {
 			if (i)
 				strbuf_addstr(&buf, "|");
@@ -771,7 +777,9 @@ int usage_with_options_internal(const char * const *usagestr,
 void usage_with_options(const char * const *usagestr,
 			const struct option *opts)
 {
-	exit_browser(false);
+	if (util_cfg.exit_browser)
+		util_cfg.exit_browser();
+
 	usage_with_options_internal(usagestr, opts, 0, NULL);
 	exit(129);
 }
@@ -781,7 +789,8 @@ void usage_with_options_msg(const char * const *usagestr,
 {
 	va_list ap;
 
-	exit_browser(false);
+	if (util_cfg.exit_browser)
+		util_cfg.exit_browser();
 
 	va_start(ap, fmt);
 	strbuf_addv(&error_buf, fmt, ap);
diff --git a/tools/perf/util/parse-options.h b/tools/lib/api/util/parse-options.h
similarity index 98%
rename from tools/perf/util/parse-options.h
rename to tools/lib/api/util/parse-options.h
index a8e407b..f880488 100644
--- a/tools/perf/util/parse-options.h
+++ b/tools/lib/api/util/parse-options.h
@@ -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 */
diff --git a/tools/perf/util/run-command.c b/tools/lib/api/util/run-command.c
similarity index 96%
rename from tools/perf/util/run-command.c
rename to tools/lib/api/util/run-command.c
index 38d2cc6..d5f2daa 100644
--- a/tools/perf/util/run-command.c
+++ b/tools/lib/api/util/run-command.c
@@ -1,7 +1,9 @@
-#include "util.h"
+#include "compat-util.h"
 #include "run-command.h"
 #include "exec_cmd.h"
-#include "debug.h"
+#include "usage.h"
+
+#define STRERR_BUFSIZE 128
 
 static inline void close_pair(int fd[2])
 {
@@ -112,8 +114,8 @@ int start_command(struct child_process *cmd)
 		}
 		if (cmd->preexec_cb)
 			cmd->preexec_cb();
-		if (cmd->perf_cmd) {
-			execv_perf_cmd(cmd->argv);
+		if (cmd->exec_cmd) {
+			execv_cmd(cmd->argv);
 		} else {
 			execvp(cmd->argv[0], (char *const*) cmd->argv);
 		}
@@ -207,7 +209,7 @@ static void prepare_run_command_v_opt(struct child_process *cmd,
 	memset(cmd, 0, sizeof(*cmd));
 	cmd->argv = argv;
 	cmd->no_stdin = opt & RUN_COMMAND_NO_STDIN ? 1 : 0;
-	cmd->perf_cmd = opt & RUN_PERF_CMD ? 1 : 0;
+	cmd->exec_cmd = opt & RUN_EXEC_CMD ? 1 : 0;
 	cmd->stdout_to_stderr = opt & RUN_COMMAND_STDOUT_TO_STDERR ? 1 : 0;
 }
 
diff --git a/tools/perf/util/run-command.h b/tools/lib/api/util/run-command.h
similarity index 87%
rename from tools/perf/util/run-command.h
rename to tools/lib/api/util/run-command.h
index 1ef264d..6876b14 100644
--- a/tools/perf/util/run-command.h
+++ b/tools/lib/api/util/run-command.h
@@ -1,5 +1,5 @@
-#ifndef __PERF_RUN_COMMAND_H
-#define __PERF_RUN_COMMAND_H
+#ifndef __API_UTIL_RUN_COMMAND_H
+#define __API_UTIL_RUN_COMMAND_H
 
 enum {
 	ERR_RUN_COMMAND_FORK = 10000,
@@ -41,7 +41,7 @@ struct child_process {
 	unsigned no_stdin:1;
 	unsigned no_stdout:1;
 	unsigned no_stderr:1;
-	unsigned perf_cmd:1; /* if this is to be perf sub-command */
+	unsigned exec_cmd:1; /* if this is to be external sub-command */
 	unsigned stdout_to_stderr:1;
 	void (*preexec_cb)(void);
 };
@@ -51,8 +51,8 @@ int finish_command(struct child_process *);
 int run_command(struct child_process *);
 
 #define RUN_COMMAND_NO_STDIN 1
-#define RUN_PERF_CMD	     2	/*If this is to be perf sub-command */
+#define RUN_EXEC_CMD	     2	/*If this is to be external sub-command */
 #define RUN_COMMAND_STDOUT_TO_STDERR 4
 int run_command_v_opt(const char **argv, int opt);
 
-#endif /* __PERF_RUN_COMMAND_H */
+#endif /* __API_UTIL_RUN_COMMAND_H */
diff --git a/tools/perf/util/sigchain.c b/tools/lib/api/util/sigchain.c
similarity index 93%
rename from tools/perf/util/sigchain.c
rename to tools/lib/api/util/sigchain.c
index 5eebf88..d7ed474 100644
--- a/tools/perf/util/sigchain.c
+++ b/tools/lib/api/util/sigchain.c
@@ -1,5 +1,7 @@
-#include "util.h"
+#include "compat-util.h"
 #include "sigchain.h"
+#include "usage.h"
+#include "wrapper.h"
 
 #define SIGCHAIN_MAX_SIGNALS 32
 
diff --git a/tools/perf/util/sigchain.h b/tools/lib/api/util/sigchain.h
similarity index 53%
rename from tools/perf/util/sigchain.h
rename to tools/lib/api/util/sigchain.h
index 959d64e..6038d7b 100644
--- a/tools/perf/util/sigchain.h
+++ b/tools/lib/api/util/sigchain.h
@@ -1,5 +1,5 @@
-#ifndef __PERF_SIGCHAIN_H
-#define __PERF_SIGCHAIN_H
+#ifndef __API_UTIL_SIGCHAIN_H
+#define __API_UTIL_SIGCHAIN_H
 
 typedef void (*sigchain_fun)(int);
 
@@ -7,4 +7,4 @@ int sigchain_pop(int sig);
 
 void sigchain_push_common(sigchain_fun f);
 
-#endif /* __PERF_SIGCHAIN_H */
+#endif /* __API_UTIL_SIGCHAIN_H */
diff --git a/tools/perf/util/strbuf.c b/tools/lib/api/util/strbuf.c
similarity index 97%
rename from tools/perf/util/strbuf.c
rename to tools/lib/api/util/strbuf.c
index 0e53793..6f0ae90 100644
--- a/tools/perf/util/strbuf.c
+++ b/tools/lib/api/util/strbuf.c
@@ -1,5 +1,9 @@
-#include "util.h"
+#include "compat-util.h"
+
 #include <linux/kernel.h>
+#include "strbuf.h"
+#include "wrapper.h"
+#include "usage.h"
 
 int prefixcmp(const char *str, const char *prefix)
 {
diff --git a/tools/perf/util/strbuf.h b/tools/lib/api/util/strbuf.h
similarity index 97%
rename from tools/perf/util/strbuf.h
rename to tools/lib/api/util/strbuf.h
index 39a1481..cc284a6 100644
--- a/tools/perf/util/strbuf.h
+++ b/tools/lib/api/util/strbuf.h
@@ -1,5 +1,5 @@
-#ifndef __PERF_STRBUF_H
-#define __PERF_STRBUF_H
+#ifndef __API_UTIL_STRBUF_H
+#define __API_UTIL_STRBUF_H
 
 /*
  * Strbuf's can be use in many ways: as a byte array, or to store arbitrary
@@ -93,4 +93,4 @@ extern void strbuf_addv(struct strbuf *sb, const char *fmt, va_list ap);
 /* XXX: if read fails, any partial read is undone */
 extern ssize_t strbuf_read(struct strbuf *, int fd, ssize_t hint);
 
-#endif /* __PERF_STRBUF_H */
+#endif /* __API_UTIL_STRBUF_H */
diff --git a/tools/perf/util/term.c b/tools/lib/api/util/term.c
similarity index 93%
rename from tools/perf/util/term.c
rename to tools/lib/api/util/term.c
index 90b47d8..e246994 100644
--- a/tools/perf/util/term.c
+++ b/tools/lib/api/util/term.c
@@ -1,4 +1,5 @@
-#include "util.h"
+#include "compat-util.h"
+#include "term.h"
 
 void get_term_dimensions(struct winsize *ws)
 {
diff --git a/tools/perf/util/term.h b/tools/lib/api/util/term.h
similarity index 100%
rename from tools/perf/util/term.h
rename to tools/lib/api/util/term.h
diff --git a/tools/perf/util/usage.c b/tools/lib/api/util/usage.c
similarity index 97%
rename from tools/perf/util/usage.c
rename to tools/lib/api/util/usage.c
index 6adfa18..69ec872 100644
--- a/tools/perf/util/usage.c
+++ b/tools/lib/api/util/usage.c
@@ -6,8 +6,8 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-#include "util.h"
-#include "debug.h"
+#include "compat-util.h"
+#include "usage.h"
 
 static void report(const char *prefix, const char *err, va_list params)
 {
diff --git a/tools/perf/util/usage.h b/tools/lib/api/util/usage.h
similarity index 84%
rename from tools/perf/util/usage.h
rename to tools/lib/api/util/usage.h
index e3f1bd0..05a6e43 100644
--- a/tools/perf/util/usage.h
+++ b/tools/lib/api/util/usage.h
@@ -1,5 +1,5 @@
-#ifndef __PERF_USAGE_H
-#define __PERF_USAGE_H
+#ifndef __API_UTIL_USAGE_H
+#define __API_UTIL_USAGE_H
 
 #include "compat-util.h"
 
@@ -8,7 +8,7 @@ extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1,
 extern int error(const char *err, ...) __attribute__((format (printf, 1, 2)));
 extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
 
-#include "../../../include/linux/stringify.h"
+#include <linux/stringify.h>
 
 #define DIE_IF(cnd)	\
 	do { if (cnd)	\
@@ -20,4 +20,4 @@ extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)))
 extern void set_die_routine(void (*routine)(const char *err, va_list params) NORETURN);
 extern void set_warning_routine(void (*routine)(const char *err, va_list params));
 
-#endif /* __PERF_USAGE_H */
+#endif /* __API_UTIL_USAGE_H */
diff --git a/tools/perf/util/wrapper.c b/tools/lib/api/util/wrapper.c
similarity index 92%
rename from tools/perf/util/wrapper.c
rename to tools/lib/api/util/wrapper.c
index 861ecfa..de59145 100644
--- a/tools/perf/util/wrapper.c
+++ b/tools/lib/api/util/wrapper.c
@@ -1,7 +1,9 @@
 /*
  * Various trivial helper wrappers around standard functions
  */
-#include "util.h"
+#include "compat-util.h"
+#include "wrapper.h"
+#include "usage.h"
 
 /*
  * There's no pack memory to release - but stay close to the Git
diff --git a/tools/perf/util/wrapper.h b/tools/lib/api/util/wrapper.h
similarity index 89%
rename from tools/perf/util/wrapper.h
rename to tools/lib/api/util/wrapper.h
index e2fa014..b8adda7 100644
--- a/tools/perf/util/wrapper.h
+++ b/tools/lib/api/util/wrapper.h
@@ -1,5 +1,5 @@
-#ifndef __PERF_WRAPPER_H
-#define __PERF_WRAPPER_H
+#ifndef __API_UTIL_WRAPPER_H
+#define __API_UTIL_WRAPPER_H
 
 extern char *xstrdup(const char *str);
 extern void *xrealloc(void *ptr, size_t size) __attribute__((weak));
@@ -31,4 +31,4 @@ static inline void *zalloc(size_t size)
 		} \
 	} while(0)
 
-#endif /* __PERF_WRAPPER_H */
+#endif /* __API_UTIL_WRAPPER_H */
diff --git a/tools/perf/Build b/tools/perf/Build
index 2a41217..050f3ad 100644
--- a/tools/perf/Build
+++ b/tools/perf/Build
@@ -36,7 +36,7 @@ paths += -DPERF_MAN_PATH="BUILD_STR($(mandir_SQ))"
 
 CFLAGS_builtin-help.o      += $(paths)
 CFLAGS_builtin-timechart.o += $(paths)
-CFLAGS_perf.o              += -DPERF_HTML_PATH="BUILD_STR($(htmldir_SQ))" -include $(OUTPUT)PERF-VERSION-FILE
+CFLAGS_perf.o              += -DPERF_HTML_PATH="BUILD_STR($(htmldir_SQ))" -DPERF_EXEC_PATH="BUILD_STR($(perfexecdir_SQ))" -DPREFIX="BUILD_STR($(prefix_SQ))" -include $(OUTPUT)PERF-VERSION-FILE
 CFLAGS_builtin-trace.o	   += -DSTRACE_GROUPS_DIR="BUILD_STR($(STRACE_GROUPS_DIR_SQ))"
 
 libperf-y += util/
diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c
index b02af06..bcc432a 100644
--- a/tools/perf/arch/x86/util/intel-pt.c
+++ b/tools/perf/arch/x86/util/intel-pt.c
@@ -26,7 +26,7 @@
 #include "../../util/evlist.h"
 #include "../../util/evsel.h"
 #include "../../util/cpumap.h"
-#include "../../util/parse-options.h"
+#include <api/util/parse-options.h>
 #include "../../util/parse-events.h"
 #include "../../util/pmu.h"
 #include "../../util/debug.h"
diff --git a/tools/perf/bench/futex-hash.c b/tools/perf/bench/futex-hash.c
index fc9bebd..07115cf 100644
--- a/tools/perf/bench/futex-hash.c
+++ b/tools/perf/bench/futex-hash.c
@@ -11,7 +11,7 @@
 #include "../perf.h"
 #include "../util/util.h"
 #include "../util/stat.h"
-#include "../util/parse-options.h"
+#include <api/util/parse-options.h>
 #include "../util/header.h"
 #include "bench.h"
 #include "futex.h"
diff --git a/tools/perf/bench/futex-lock-pi.c b/tools/perf/bench/futex-lock-pi.c
index bc6a16a..487c3d3 100644
--- a/tools/perf/bench/futex-lock-pi.c
+++ b/tools/perf/bench/futex-lock-pi.c
@@ -5,7 +5,7 @@
 #include "../perf.h"
 #include "../util/util.h"
 #include "../util/stat.h"
-#include "../util/parse-options.h"
+#include <api/util/parse-options.h>
 #include "../util/header.h"
 #include "bench.h"
 #include "futex.h"
diff --git a/tools/perf/bench/futex-requeue.c b/tools/perf/bench/futex-requeue.c
index ad0d9b5..eb56ddf 100644
--- a/tools/perf/bench/futex-requeue.c
+++ b/tools/perf/bench/futex-requeue.c
@@ -11,7 +11,7 @@
 #include "../perf.h"
 #include "../util/util.h"
 #include "../util/stat.h"
-#include "../util/parse-options.h"
+#include <api/util/parse-options.h>
 #include "../util/header.h"
 #include "bench.h"
 #include "futex.h"
diff --git a/tools/perf/bench/futex-wake-parallel.c b/tools/perf/bench/futex-wake-parallel.c
index 6d8c9fa..1bab7b0 100644
--- a/tools/perf/bench/futex-wake-parallel.c
+++ b/tools/perf/bench/futex-wake-parallel.c
@@ -10,7 +10,7 @@
 #include "../perf.h"
 #include "../util/util.h"
 #include "../util/stat.h"
-#include "../util/parse-options.h"
+#include <api/util/parse-options.h>
 #include "../util/header.h"
 #include "bench.h"
 #include "futex.h"
diff --git a/tools/perf/bench/futex-wake.c b/tools/perf/bench/futex-wake.c
index e5e41d3..d23e978 100644
--- a/tools/perf/bench/futex-wake.c
+++ b/tools/perf/bench/futex-wake.c
@@ -11,7 +11,7 @@
 #include "../perf.h"
 #include "../util/util.h"
 #include "../util/stat.h"
-#include "../util/parse-options.h"
+#include <api/util/parse-options.h>
 #include "../util/header.h"
 #include "bench.h"
 #include "futex.h"
diff --git a/tools/perf/bench/mem-functions.c b/tools/perf/bench/mem-functions.c
index 9419b94..ad11f26 100644
--- a/tools/perf/bench/mem-functions.c
+++ b/tools/perf/bench/mem-functions.c
@@ -8,7 +8,7 @@
 
 #include "../perf.h"
 #include "../util/util.h"
-#include "../util/parse-options.h"
+#include <api/util/parse-options.h>
 #include "../util/header.h"
 #include "../util/cloexec.h"
 #include "bench.h"
diff --git a/tools/perf/bench/numa.c b/tools/perf/bench/numa.c
index 492df27..8a42d13 100644
--- a/tools/perf/bench/numa.c
+++ b/tools/perf/bench/numa.c
@@ -7,7 +7,7 @@
 #include "../perf.h"
 #include "../builtin.h"
 #include "../util/util.h"
-#include "../util/parse-options.h"
+#include <api/util/parse-options.h>
 #include "../util/cloexec.h"
 
 #include "bench.h"
diff --git a/tools/perf/bench/sched-messaging.c b/tools/perf/bench/sched-messaging.c
index d4ff1b5..77e36e9 100644
--- a/tools/perf/bench/sched-messaging.c
+++ b/tools/perf/bench/sched-messaging.c
@@ -11,7 +11,7 @@
 
 #include "../perf.h"
 #include "../util/util.h"
-#include "../util/parse-options.h"
+#include <api/util/parse-options.h>
 #include "../builtin.h"
 #include "bench.h"
 
diff --git a/tools/perf/bench/sched-pipe.c b/tools/perf/bench/sched-pipe.c
index 005cc28..b1e84c8 100644
--- a/tools/perf/bench/sched-pipe.c
+++ b/tools/perf/bench/sched-pipe.c
@@ -10,7 +10,7 @@
  */
 #include "../perf.h"
 #include "../util/util.h"
-#include "../util/parse-options.h"
+#include <api/util/parse-options.h>
 #include "../builtin.h"
 #include "bench.h"
 
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 50695c7..bba340b 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -20,7 +20,7 @@
 #include "util/evsel.h"
 #include "util/annotate.h"
 #include "util/event.h"
-#include "util/parse-options.h"
+#include <api/util/parse-options.h>
 #include "util/parse-events.h"
 #include "util/thread.h"
 #include "util/sort.h"
diff --git a/tools/perf/builtin-bench.c b/tools/perf/builtin-bench.c
index b17aed3..48b4054 100644
--- a/tools/perf/builtin-bench.c
+++ b/tools/perf/builtin-bench.c
@@ -16,7 +16,7 @@
  */
 #include "perf.h"
 #include "util/util.h"
-#include "util/parse-options.h"
+#include <api/util/parse-options.h>
 #include "builtin.h"
 #include "bench/bench.h"
 
diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c
index bed484f..1dc9eb0 100644
--- a/tools/perf/builtin-buildid-cache.c
+++ b/tools/perf/builtin-buildid-cache.c
@@ -16,7 +16,7 @@
 #include "util/util.h"
 #include "util/debug.h"
 #include "util/header.h"
-#include "util/parse-options.h"
+#include <api/util/parse-options.h>
 #include "util/strlist.h"
 #include "util/build-id.h"
 #include "util/session.h"
diff --git a/tools/perf/builtin-buildid-list.c b/tools/perf/builtin-buildid-list.c
index bd7558e..4ff4f6c 100644
--- a/tools/perf/builtin-buildid-list.c
+++ b/tools/perf/builtin-buildid-list.c
@@ -12,7 +12,7 @@
 #include "util/build-id.h"
 #include "util/util.h"
 #include "util/debug.h"
-#include "util/parse-options.h"
+#include <api/util/parse-options.h>
 #include "util/session.h"
 #include "util/symbol.h"
 #include "util/data.h"
diff --git a/tools/perf/builtin-config.c b/tools/perf/builtin-config.c
index 03117c8..a2a087c 100644
--- a/tools/perf/builtin-config.c
+++ b/tools/perf/builtin-config.c
@@ -9,7 +9,7 @@
 #include "perf.h"
 
 #include "util/util.h"
-#include "util/parse-options.h"
+#include <api/util/parse-options.h>
 #include "util/debug.h"
 
 static const char * const config_usage[] = {
diff --git a/tools/perf/builtin-data.c b/tools/perf/builtin-data.c
index d6525bc..b27861f 100644
--- a/tools/perf/builtin-data.c
+++ b/tools/perf/builtin-data.c
@@ -2,7 +2,7 @@
 #include "builtin.h"
 #include "perf.h"
 #include "debug.h"
-#include "parse-options.h"
+#include <api/util/parse-options.h>
 #include "data-convert-bt.h"
 
 typedef int (*data_cmd_fn_t)(int argc, const char **argv, const char *prefix);
diff --git a/tools/perf/builtin-evlist.c b/tools/perf/builtin-evlist.c
index f4d6251..7f673a0 100644
--- a/tools/perf/builtin-evlist.c
+++ b/tools/perf/builtin-evlist.c
@@ -12,7 +12,7 @@
 #include "util/evlist.h"
 #include "util/evsel.h"
 #include "util/parse-events.h"
-#include "util/parse-options.h"
+#include <api/util/parse-options.h>
 #include "util/session.h"
 #include "util/data.h"
 #include "util/debug.h"
diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c
index 23c3fdb..6ddbffc 100644
--- a/tools/perf/builtin-help.c
+++ b/tools/perf/builtin-help.c
@@ -6,11 +6,10 @@
 #include "perf.h"
 #include "util/util.h"
 #include "builtin.h"
-#include "util/exec_cmd.h"
+#include <api/util/exec_cmd.h>
 #include "common-cmds.h"
-#include "util/parse-options.h"
-#include "util/run-command.h"
-#include "util/help.h"
+#include <api/util/parse-options.h>
+#include <api/util/run-command.h>
 #include "util/debug.h"
 
 static struct man_viewer_list {
@@ -407,7 +406,7 @@ static int get_html_page_path(struct strbuf *page_path, const char *page)
 #ifndef open_html
 static void open_html(const char *path)
 {
-	execl_perf_cmd("web--browse", "-c", "help.browser", path, NULL);
+	execl_cmd("web--browse", "-c", "help.browser", path, NULL);
 }
 #endif
 
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index 99d127f..a85ecba 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -18,7 +18,7 @@
 #include "util/data.h"
 #include "util/auxtrace.h"
 
-#include "util/parse-options.h"
+#include <api/util/parse-options.h>
 
 #include <linux/list.h>
 
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index cdf487b..e0c5b44 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -11,7 +11,7 @@
 #include "util/tool.h"
 #include "util/callchain.h"
 
-#include "util/parse-options.h"
+#include <api/util/parse-options.h>
 #include "util/trace-event.h"
 #include "util/data.h"
 #include "util/cpumap.h"
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index a9ad326..2202f54 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -9,7 +9,7 @@
 #include "util/header.h"
 #include "util/session.h"
 #include "util/intlist.h"
-#include "util/parse-options.h"
+#include <api/util/parse-options.h>
 #include "util/trace-event.h"
 #include "util/debug.h"
 #include "util/tool.h"
diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
index 70856ac..0b080cd 100644
--- a/tools/perf/builtin-list.c
+++ b/tools/perf/builtin-list.c
@@ -14,7 +14,7 @@
 #include "util/parse-events.h"
 #include "util/util.h"
 #include "util/pmu.h"
-#include "util/parse-options.h"
+#include <api/util/parse-options.h>
 
 int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
 {
diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
index 191d32f..2e14528 100644
--- a/tools/perf/builtin-lock.c
+++ b/tools/perf/builtin-lock.c
@@ -8,7 +8,7 @@
 #include "util/thread.h"
 #include "util/header.h"
 
-#include "util/parse-options.h"
+#include <api/util/parse-options.h>
 #include "util/trace-event.h"
 
 #include "util/debug.h"
diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c
index 80170aa..fd2adeb 100644
--- a/tools/perf/builtin-mem.c
+++ b/tools/perf/builtin-mem.c
@@ -1,7 +1,7 @@
 #include "builtin.h"
 #include "perf.h"
 
-#include "util/parse-options.h"
+#include <api/util/parse-options.h>
 #include "util/trace-event.h"
 #include "util/tool.h"
 #include "util/session.h"
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index 132afc9..d4a7885 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -37,7 +37,7 @@
 #include "util/strfilter.h"
 #include "util/symbol.h"
 #include "util/debug.h"
-#include "util/parse-options.h"
+#include <api/util/parse-options.h>
 #include "util/probe-finder.h"
 #include "util/probe-event.h"
 #include "util/probe-file.h"
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 199fc31..9c0d1bd 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -11,7 +11,7 @@
 
 #include "util/build-id.h"
 #include "util/util.h"
-#include "util/parse-options.h"
+#include <api/util/parse-options.h>
 #include "util/parse-events.h"
 
 #include "util/callchain.h"
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 61ed8f2..b998e26 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -26,7 +26,7 @@
 #include "util/session.h"
 #include "util/tool.h"
 
-#include "util/parse-options.h"
+#include <api/util/parse-options.h>
 #include "util/parse-events.h"
 
 #include "util/thread.h"
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 43dedd4..37ab946 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -11,7 +11,7 @@
 #include "util/tool.h"
 #include "util/cloexec.h"
 
-#include "util/parse-options.h"
+#include <api/util/parse-options.h>
 #include "util/trace-event.h"
 
 #include "util/debug.h"
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 8873021..ba344c0 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -2,9 +2,9 @@
 
 #include "perf.h"
 #include "util/debug.h"
-#include "util/exec_cmd.h"
+#include <api/util/exec_cmd.h>
 #include "util/header.h"
-#include "util/parse-options.h"
+#include <api/util/parse-options.h>
 #include "util/perf_regs.h"
 #include "util/session.h"
 #include "util/tool.h"
@@ -1393,7 +1393,7 @@ static int list_available_scripts(const struct option *opt __maybe_unused,
 	char first_half[BUFSIZ];
 	char *script_root;
 
-	snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path());
+	snprintf(scripts_path, MAXPATHLEN, "%s/scripts", get_argv_exec_path());
 
 	scripts_dir = opendir(scripts_path);
 	if (!scripts_dir)
@@ -1514,7 +1514,7 @@ int find_scripts(char **scripts_array, char **scripts_path_array)
 	if (!session)
 		return -1;
 
-	snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path());
+	snprintf(scripts_path, MAXPATHLEN, "%s/scripts", get_argv_exec_path());
 
 	scripts_dir = opendir(scripts_path);
 	if (!scripts_dir) {
@@ -1572,7 +1572,7 @@ static char *get_script_path(const char *script_root, const char *suffix)
 	char lang_path[MAXPATHLEN];
 	char *__script_root;
 
-	snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path());
+	snprintf(scripts_path, MAXPATHLEN, "%s/scripts", get_argv_exec_path());
 
 	scripts_dir = opendir(scripts_path);
 	if (!scripts_dir)
@@ -1808,7 +1808,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 		scripting_max_stack = itrace_synth_opts.callchain_sz;
 
 	/* make sure PERF_EXEC_PATH is set for scripts */
-	perf_set_argv_exec_path(perf_exec_path());
+	set_argv_exec_path(get_argv_exec_path());
 
 	if (argc && !script_name && !rec_script_path && !rep_script_path) {
 		int live_pipe[2];
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index df2fbf0..a1460b2 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -45,7 +45,7 @@
 #include "builtin.h"
 #include "util/cgroup.h"
 #include "util/util.h"
-#include "util/parse-options.h"
+#include <api/util/parse-options.h>
 #include "util/parse-events.h"
 #include "util/pmu.h"
 #include "util/event.h"
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index ab75e5b..89d6ca1 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -29,7 +29,7 @@
 
 #include "perf.h"
 #include "util/header.h"
-#include "util/parse-options.h"
+#include <api/util/parse-options.h>
 #include "util/parse-events.h"
 #include "util/event.h"
 #include "util/session.h"
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index c8dd628..ee1a733 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -33,7 +33,7 @@
 #include "util/top.h"
 #include "util/util.h"
 #include <linux/rbtree.h>
-#include "util/parse-options.h"
+#include <api/util/parse-options.h>
 #include "util/parse-events.h"
 #include "util/cpumap.h"
 #include "util/xyarray.h"
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index c783d8f..63b180a 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -22,11 +22,11 @@
 #include "util/color.h"
 #include "util/debug.h"
 #include "util/evlist.h"
-#include "util/exec_cmd.h"
+#include <api/util/exec_cmd.h>
 #include "util/machine.h"
 #include "util/session.h"
 #include "util/thread.h"
-#include "util/parse-options.h"
+#include <api/util/parse-options.h>
 #include "util/strlist.h"
 #include "util/intlist.h"
 #include "util/thread_map.h"
diff --git a/tools/perf/builtin.h b/tools/perf/builtin.h
index 3f871b5..123e66a 100644
--- a/tools/perf/builtin.h
+++ b/tools/perf/builtin.h
@@ -2,7 +2,7 @@
 #define BUILTIN_H
 
 #include "util/util.h"
-#include "util/strbuf.h"
+#include <api/util/strbuf.h>
 
 extern const char perf_usage_string[];
 extern const char perf_more_info_string[];
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index c57e447..1312c50 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -9,16 +9,17 @@
 #include "builtin.h"
 
 #include "util/env.h"
-#include "util/exec_cmd.h"
+#include <api/util/exec_cmd.h>
 #include "util/util.h"
 #include "util/quote.h"
-#include "util/run-command.h"
+#include <api/util/run-command.h>
 #include "util/parse-events.h"
-#include "util/parse-options.h"
+#include <api/util/parse-options.h>
 #include "util/bpf-loader.h"
 #include "util/debug.h"
 #include <api/fs/tracing_path.h>
 #include <pthread.h>
+#include <api/util/cfg.h>
 
 const char perf_usage_string[] =
 	"perf [--version] [--help] [OPTIONS] COMMAND [ARGS]";
@@ -119,7 +120,7 @@ static void commit_pager_choice(void)
 {
 	switch (use_pager) {
 	case 0:
-		setenv("PERF_PAGER", "cat", 1);
+		setenv(PERF_PAGER_ENVIRONMENT, "cat", 1);
 		break;
 	case 1:
 		/* setup_pager(); */
@@ -129,6 +130,16 @@ static void commit_pager_choice(void)
 	}
 }
 
+static void setup_util(void)
+{
+	util_cfg.prefix		= PREFIX;
+	util_cfg.exec_name	= "perf";
+	util_cfg.exec_path	= PERF_EXEC_PATH;
+	util_cfg.exec_path_env	= EXEC_PATH_ENVIRONMENT;
+	util_cfg.pager_env	= PERF_PAGER_ENVIRONMENT;
+	util_cfg.exit_browser	= exit_browser_no_wait;
+}
+
 struct option options[] = {
 	OPT_ARGUMENT("help", "help"),
 	OPT_ARGUMENT("version", "version"),
@@ -183,9 +194,9 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
 		if (!prefixcmp(cmd, CMD_EXEC_PATH)) {
 			cmd += strlen(CMD_EXEC_PATH);
 			if (*cmd == '=')
-				perf_set_argv_exec_path(cmd + 1);
+				set_argv_exec_path(cmd + 1);
 			else {
-				puts(perf_exec_path());
+				puts(get_argv_exec_path());
 				exit(0);
 			}
 		} else if (!strcmp(cmd, "--html-path")) {
@@ -530,11 +541,13 @@ int main(int argc, const char **argv)
 	const char *cmd;
 	char sbuf[STRERR_BUFSIZE];
 
+	setup_util();
+
 	/* The page_size is placed in util object. */
 	page_size = sysconf(_SC_PAGE_SIZE);
 	cacheline_size = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
 
-	cmd = perf_extract_argv0_path(argv[0]);
+	cmd = extract_argv0_path(argv[0]);
 	if (!cmd)
 		cmd = "perf-help";
 
diff --git a/tools/perf/perf.h b/tools/perf/perf.h
index 501acb4..8f314b5 100644
--- a/tools/perf/perf.h
+++ b/tools/perf/perf.h
@@ -17,6 +17,7 @@
 #define DEFAULT_PERF_DIR_ENVIRONMENT ".perf"
 #define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"
 #define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR"
+#define PERF_PAGER_ENVIRONMENT "PERF_PAGER"
 
 extern bool test_attr__enabled;
 void test_attr__init(void);
diff --git a/tools/perf/tests/attr.c b/tools/perf/tests/attr.c
index b66730e..bdc4a3b 100644
--- a/tools/perf/tests/attr.c
+++ b/tools/perf/tests/attr.c
@@ -24,7 +24,7 @@
 #include <linux/kernel.h>
 #include "../perf.h"
 #include "util.h"
-#include "exec_cmd.h"
+#include <api/util/exec_cmd.h>
 #include "tests.h"
 
 #define ENV "PERF_TEST_ATTR"
@@ -164,7 +164,7 @@ int test__attr(int subtest __maybe_unused)
 		return run_dir("./tests", "./perf");
 
 	/* Then installed path. */
-	snprintf(path_dir,  PATH_MAX, "%s/tests", perf_exec_path());
+	snprintf(path_dir,  PATH_MAX, "%s/tests", get_argv_exec_path());
 	snprintf(path_perf, PATH_MAX, "%s/perf", BINDIR);
 
 	if (!lstat(path_dir, &st) &&
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 2b1ade1..1b8af76 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -11,7 +11,7 @@
 #include "tests.h"
 #include "debug.h"
 #include "color.h"
-#include "parse-options.h"
+#include <api/util/parse-options.h>
 #include "symbol.h"
 
 struct test __weak arch_tests[] = {
diff --git a/tools/perf/ui/setup.c b/tools/perf/ui/setup.c
index df4bd94..f6eaee1 100644
--- a/tools/perf/ui/setup.c
+++ b/tools/perf/ui/setup.c
@@ -105,3 +105,8 @@ void exit_browser(bool wait_for_ok)
 		break;
 	}
 }
+
+void exit_browser_no_wait(void)
+{
+	exit_browser(false);
+}
diff --git a/tools/perf/ui/ui.h b/tools/perf/ui/ui.h
index ab88383..91ba964 100644
--- a/tools/perf/ui/ui.h
+++ b/tools/perf/ui/ui.h
@@ -12,6 +12,7 @@ extern int use_browser;
 
 void setup_browser(bool fallback_to_pager);
 void exit_browser(bool wait_for_ok);
+void exit_browser_no_wait(void);
 
 #ifdef HAVE_SLANG_SUPPORT
 int ui__init(void);
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 02d3a54..6732b3e 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -1,41 +1,30 @@
-libperf-y += abspath.o
 libperf-y += alias.o
 libperf-y += annotate.o
 libperf-y += build-id.o
 libperf-y += config.o
-libperf-y += ctype.o
 libperf-y += db-export.o
 libperf-y += env.o
 libperf-y += event.o
 libperf-y += evlist.o
 libperf-y += evsel.o
-libperf-y += exec_cmd.o
 libperf-y += find_next_bit.o
-libperf-y += help.o
 libperf-y += kallsyms.o
 libperf-y += levenshtein.o
 libperf-y += llvm-utils.o
-libperf-y += parse-options.o
 libperf-y += parse-events.o
 libperf-y += perf_regs.o
 libperf-y += path.o
 libperf-y += rbtree.o
 libperf-y += bitmap.o
 libperf-y += hweight.o
-libperf-y += run-command.o
 libperf-y += quote.o
-libperf-y += strbuf.o
 libperf-y += string.o
 libperf-y += strlist.o
 libperf-y += strfilter.o
 libperf-y += top.o
-libperf-y += usage.o
-libperf-y += wrapper.o
-libperf-y += sigchain.o
 libperf-y += dso.o
 libperf-y += symbol.o
 libperf-y += color.o
-libperf-y += pager.o
 libperf-y += header.o
 libperf-y += callchain.o
 libperf-y += values.o
@@ -85,7 +74,6 @@ libperf-$(CONFIG_AUXTRACE) += intel-pt.o
 libperf-$(CONFIG_AUXTRACE) += intel-bts.o
 libperf-y += parse-branch-options.o
 libperf-y += parse-regs-options.o
-libperf-y += term.o
 libperf-y += help-unknown-cmd.o
 
 libperf-$(CONFIG_LIBBPF) += bpf-loader.o
@@ -112,7 +100,6 @@ libperf-$(CONFIG_ZLIB) += zlib.o
 libperf-$(CONFIG_LZMA) += lzma.o
 
 CFLAGS_config.o   += -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
-CFLAGS_exec_cmd.o += -DPERF_EXEC_PATH="BUILD_STR($(perfexecdir_SQ))" -DPREFIX="BUILD_STR($(prefix_SQ))"
 
 $(OUTPUT)util/parse-events-flex.c: util/parse-events.l $(OUTPUT)util/parse-events-bison.c
 	$(call rule_mkdir)
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index cc83262..07f25ec 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -45,7 +45,7 @@
 #include "event.h"
 #include "session.h"
 #include "debug.h"
-#include "parse-options.h"
+#include <api/util/parse-options.h>
 
 #include "intel-pt.h"
 #include "intel-bts.h"
diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c
index 32e12ec..4543e72 100644
--- a/tools/perf/util/cgroup.c
+++ b/tools/perf/util/cgroup.c
@@ -1,6 +1,6 @@
 #include "util.h"
 #include "../perf.h"
-#include "parse-options.h"
+#include <api/util/parse-options.h>
 #include "evsel.h"
 #include "cgroup.h"
 #include "evlist.h"
diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c
index 6b9e91f..8bdc5c6 100644
--- a/tools/perf/util/config.c
+++ b/tools/perf/util/config.c
@@ -9,7 +9,7 @@
  *
  */
 #include "util.h"
-#include "exec_cmd.h"
+#include <api/util/exec_cmd.h>
 #include "util/hist.h"  /* perf_hist_config */
 #include "util/llvm-utils.h"   /* perf_llvm_config */
 
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index d139219..79eef69 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -18,7 +18,7 @@
 #include <unistd.h>
 
 #include "parse-events.h"
-#include "parse-options.h"
+#include <api/util/parse-options.h>
 
 #include <sys/mman.h>
 
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 4383800..ec7b508 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -20,7 +20,7 @@
 #include "cpumap.h"
 #include "pmu.h"
 #include "vdso.h"
-#include "strbuf.h"
+#include <api/util/strbuf.h>
 #include "build-id.h"
 #include "data.h"
 
diff --git a/tools/perf/util/help-unknown-cmd.c b/tools/perf/util/help-unknown-cmd.c
index c30ae78..e658c22 100644
--- a/tools/perf/util/help-unknown-cmd.c
+++ b/tools/perf/util/help-unknown-cmd.c
@@ -1,5 +1,5 @@
 #include "util.h"
-#include "help.h"
+#include <api/util/help.h>
 #include "../builtin.h"
 #include "levenshtein.h"
 
diff --git a/tools/perf/util/parse-branch-options.c b/tools/perf/util/parse-branch-options.c
index 355eecf..611f0f2 100644
--- a/tools/perf/util/parse-branch-options.c
+++ b/tools/perf/util/parse-branch-options.c
@@ -1,7 +1,7 @@
 #include "perf.h"
 #include "util/util.h"
 #include "util/debug.h"
-#include "util/parse-options.h"
+#include <api/util/parse-options.h>
 #include "util/parse-branch-options.h"
 
 #define BRANCH_OPT(n, m) \
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index d2ec59d..5263f87 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -4,9 +4,9 @@
 #include "../perf.h"
 #include "evlist.h"
 #include "evsel.h"
-#include "parse-options.h"
+#include <api/util/parse-options.h>
 #include "parse-events.h"
-#include "exec_cmd.h"
+#include <api/util/exec_cmd.h>
 #include "string.h"
 #include "symbol.h"
 #include "header.h"
diff --git a/tools/perf/util/parse-regs-options.c b/tools/perf/util/parse-regs-options.c
index 4f2c1c2..893d2ca 100644
--- a/tools/perf/util/parse-regs-options.c
+++ b/tools/perf/util/parse-regs-options.c
@@ -1,7 +1,7 @@
 #include "perf.h"
 #include "util/util.h"
 #include "util/debug.h"
-#include "util/parse-options.h"
+#include <api/util/parse-options.h>
 #include "util/parse-regs-options.h"
 
 int
diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ext-sources
index 51be28b..2f5a2d0 100644
--- a/tools/perf/util/python-ext-sources
+++ b/tools/perf/util/python-ext-sources
@@ -6,7 +6,6 @@
 #
 
 util/python.c
-util/ctype.c
 util/evlist.c
 util/evsel.c
 util/cpumap.c
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
index 139a566..3459ae1 100644
--- a/tools/perf/util/sort.h
+++ b/tools/perf/util/sort.h
@@ -17,7 +17,7 @@
 #include "debug.h"
 #include "header.h"
 
-#include "parse-options.h"
+#include <api/util/parse-options.h>
 #include "parse-events.h"
 #include "hist.h"
 #include "thread.h"
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index f1c07f6..6459f59 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -1,24 +1,27 @@
 #ifndef __PERF_UTIL_H
 #define __PERF_UTIL_H
 
-#include "compat-util.h"
+#include <api/util/compat-util.h>
 
+#include <api/fs/tracing_path.h>
 #include <api/string/string.h>
+#include <api/util/abspath.h>
+#include <api/util/ctype.h>
+#include <api/util/help.h>
+#include <api/util/pager.h>
+#include <api/util/strbuf.h>
+#include <api/util/term.h>
+#include <api/util/usage.h>
+#include <api/util/wrapper.h>
+
 #include "../perf.h"
-#include "abspath.h"
 #include "alias.h"
 #include "config.h"
-#include "ctype.h"
 #include "lzma.h"
-#include "pager.h"
 #include "path.h"
 #include "srcline.h"
-#include "strbuf.h"
 #include "string.h"
-#include "term.h"
 #include "../ui/ui.h"
-#include "usage.h"
-#include "wrapper.h"
 #include "zlib.h"
 
 int parse_nsec_time(const char *str, u64 *ptime);
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 12/13 v1.1] perf tools: Move tools/lib/string.c to libapi
  2015-12-04 21:59 ` [PATCH 12/13] perf tools: Move perf subcommand framework into a library Josh Poimboeuf
@ 2015-12-04 22:21   ` Josh Poimboeuf
  0 siblings, 0 replies; 25+ messages in thread
From: Josh Poimboeuf @ 2015-12-04 22:21 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo; +Cc: linux-kernel

On Fri, Dec 04, 2015 at 03:59:23PM -0600, Josh Poimboeuf wrote:
> 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.
> 
> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>

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.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 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%)

diff --git a/tools/lib/api/Build b/tools/lib/api/Build
index e8b8a23..9e3967e 100644
--- a/tools/lib/api/Build
+++ b/tools/lib/api/Build
@@ -1,3 +1,4 @@
 libapi-y += fd/
 libapi-y += fs/
 libapi-y += cpu.o
+libapi-y += string/
diff --git a/tools/lib/api/string/Build b/tools/lib/api/string/Build
new file mode 100644
index 0000000..7707d3d
--- /dev/null
+++ b/tools/lib/api/string/Build
@@ -0,0 +1 @@
+libapi-y += string.o
diff --git a/tools/lib/string.c b/tools/lib/api/string/string.c
similarity index 93%
rename from tools/lib/string.c
rename to tools/lib/api/string/string.c
index 3366582..3140ba3 100644
--- a/tools/lib/string.c
+++ b/tools/lib/api/string/string.c
@@ -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
diff --git a/tools/include/linux/string.h b/tools/lib/api/string/string.h
similarity index 66%
rename from tools/include/linux/string.h
rename to tools/lib/api/string/string.h
index eae1d87..74bd4fd 100644
--- a/tools/include/linux/string.h
+++ b/tools/lib/api/string/string.h
@@ -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 */
diff --git a/tools/perf/MANIFEST b/tools/perf/MANIFEST
index 2562eac..39c38cb 100644
--- a/tools/perf/MANIFEST
+++ b/tools/perf/MANIFEST
@@ -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
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 1c3d3d9..cdf487b 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -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>
 
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 99b3dae..02d3a54 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -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)
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index 7f10430..cc83262 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -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>
diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index 540a7ef..5a99b6a 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -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"
diff --git a/tools/perf/util/intel-pt-decoder/insn.c b/tools/perf/util/intel-pt-decoder/insn.c
index 47314a6..bcf3a8e 100644
--- a/tools/perf/util/intel-pt-decoder/insn.c
+++ b/tools/perf/util/intel-pt-decoder/insn.c
@@ -19,7 +19,7 @@
  */
 
 #ifdef __KERNEL__
-#include <linux/string.h>
+#include <api/string/string.h>
 #else
 #include <string.h>
 #endif
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index 93d9f1c..c9f716d 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -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);
 
diff --git a/tools/perf/util/ordered-events.c b/tools/perf/util/ordered-events.c
index b1b9e23..867ae98 100644
--- a/tools/perf/util/ordered-events.c
+++ b/tools/perf/util/ordered-events.c
@@ -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"
diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c
index 735c8c8..8d70c1b 100644
--- a/tools/perf/util/parse-options.c
+++ b/tools/perf/util/parse-options.c
@@ -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
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 2c6db35..f1c07f6 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -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"
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [PATCH 00/13] perf tools: Move perf subcommand framework into lib/tools
  2015-12-04 21:59 [PATCH 00/13] perf tools: Move perf subcommand framework into lib/tools Josh Poimboeuf
                   ` (12 preceding siblings ...)
  2015-12-04 21:59 ` [PATCH 13/13] perf tools: Move subcommand framework and related utils " Josh Poimboeuf
@ 2015-12-06  9:37 ` Ingo Molnar
  2015-12-06 15:50   ` Jiri Olsa
  2015-12-06 18:28   ` Arnaldo Carvalho de Melo
  13 siblings, 2 replies; 25+ messages in thread
From: Ingo Molnar @ 2015-12-06  9:37 UTC (permalink / raw)
  To: Josh Poimboeuf, Jiri Olsa, Namhyung Kim
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, linux-kernel


* Josh Poimboeuf <jpoimboe@redhat.com> wrote:

> 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/cover.1445443144.git.jpoimboe@redhat.com
> 
> 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

>  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

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 00/13] perf tools: Move perf subcommand framework into lib/tools
  2015-12-06  9:37 ` [PATCH 00/13] perf tools: Move perf subcommand framework into lib/tools Ingo Molnar
@ 2015-12-06 15:50   ` Jiri Olsa
  2015-12-06 20:02     ` Josh Poimboeuf
  2015-12-06 18:28   ` Arnaldo Carvalho de Melo
  1 sibling, 1 reply; 25+ messages in thread
From: Jiri Olsa @ 2015-12-06 15:50 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Josh Poimboeuf, Namhyung Kim, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, linux-kernel

On Sun, Dec 06, 2015 at 10:37:52AM +0100, Ingo Molnar wrote:
> 
> * Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> 
> > 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/cover.1445443144.git.jpoimboe@redhat.com
> > 
> > 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
> 
> >  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/.
> 

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

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 00/13] perf tools: Move perf subcommand framework into lib/tools
  2015-12-06  9:37 ` [PATCH 00/13] perf tools: Move perf subcommand framework into lib/tools Ingo Molnar
  2015-12-06 15:50   ` Jiri Olsa
@ 2015-12-06 18:28   ` Arnaldo Carvalho de Melo
  1 sibling, 0 replies; 25+ messages in thread
From: Arnaldo Carvalho de Melo @ 2015-12-06 18:28 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Josh Poimboeuf, Jiri Olsa, Namhyung Kim, Peter Zijlstra,
	Ingo Molnar, linux-kernel

Em Sun, Dec 06, 2015 at 10:37:52AM +0100, Ingo Molnar escreveu:
> 
> * Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> 
> > 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/cover.1445443144.git.jpoimboe@redhat.com
> > 
> > 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
> 
> >  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.
 
> 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

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 00/13] perf tools: Move perf subcommand framework into lib/tools
  2015-12-06 15:50   ` Jiri Olsa
@ 2015-12-06 20:02     ` Josh Poimboeuf
  2015-12-07  8:46       ` Jiri Olsa
  0 siblings, 1 reply; 25+ messages in thread
From: Josh Poimboeuf @ 2015-12-06 20:02 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Ingo Molnar, Namhyung Kim, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, linux-kernel

On Sun, Dec 06, 2015 at 04:50:06PM +0100, Jiri Olsa wrote:
> On Sun, Dec 06, 2015 at 10:37:52AM +0100, Ingo Molnar wrote:
> > 
> > * Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> > 
> > > 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/cover.1445443144.git.jpoimboe@redhat.com
> > > 
> > > 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
> > 
> > >  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/.
> > 
> 
> 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

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.

-- 
Josh

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 00/13] perf tools: Move perf subcommand framework into lib/tools
  2015-12-06 20:02     ` Josh Poimboeuf
@ 2015-12-07  8:46       ` Jiri Olsa
  2015-12-08 14:52         ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 25+ messages in thread
From: Jiri Olsa @ 2015-12-07  8:46 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Ingo Molnar, Namhyung Kim, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, linux-kernel

On Sun, Dec 06, 2015 at 02:02:42PM -0600, Josh Poimboeuf wrote:
> On Sun, Dec 06, 2015 at 04:50:06PM +0100, Jiri Olsa wrote:
> > On Sun, Dec 06, 2015 at 10:37:52AM +0100, Ingo Molnar wrote:
> > > 
> > > * Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> > > 
> > > > 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/cover.1445443144.git.jpoimboe@redhat.com
> > > > 
> > > > 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
> > > 
> > > >  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/.
> > > 
> > 
> > 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
> 
> 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

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 00/13] perf tools: Move perf subcommand framework into lib/tools
  2015-12-07  8:46       ` Jiri Olsa
@ 2015-12-08 14:52         ` Arnaldo Carvalho de Melo
  2015-12-08 14:55           ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 25+ messages in thread
From: Arnaldo Carvalho de Melo @ 2015-12-08 14:52 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Josh Poimboeuf, Ingo Molnar, Namhyung Kim, Peter Zijlstra,
	Ingo Molnar, linux-kernel

Em Mon, Dec 07, 2015 at 09:46:48AM +0100, Jiri Olsa escreveu:
> On Sun, Dec 06, 2015 at 02:02:42PM -0600, Josh Poimboeuf wrote:
> > On Sun, Dec 06, 2015 at 04:50:06PM +0100, Jiri Olsa wrote:
> > > On Sun, Dec 06, 2015 at 10:37:52AM +0100, Ingo Molnar wrote:
> > > > 
> > > > * Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> > > > 
> > > > > 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/cover.1445443144.git.jpoimboe@redhat.com
> > > > > 
> > > > > 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
> > > > 
> > > > >  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/.
> > > > 
> > > 
> > > 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
> > 
> > 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 <jpoimboe@redhat.com>
 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


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 00/13] perf tools: Move perf subcommand framework into lib/tools
  2015-12-08 14:52         ` Arnaldo Carvalho de Melo
@ 2015-12-08 14:55           ` Arnaldo Carvalho de Melo
  2015-12-08 15:27             ` Josh Poimboeuf
  2015-12-08 15:29             ` Arnaldo Carvalho de Melo
  0 siblings, 2 replies; 25+ messages in thread
From: Arnaldo Carvalho de Melo @ 2015-12-08 14:55 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Josh Poimboeuf, Ingo Molnar, Namhyung Kim, Peter Zijlstra,
	Ingo Molnar, linux-kernel

Em Tue, Dec 08, 2015 at 11:52:33AM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Mon, Dec 07, 2015 at 09:46:48AM +0100, Jiri Olsa escreveu:
> > On Sun, Dec 06, 2015 at 02:02:42PM -0600, Josh Poimboeuf wrote:
> > > 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...

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 :-\
 
> - Arnaldo
> 
> Applying: perf: Use -iquote for local include paths
> [perf/core dbb37aec117a] perf tools: Use -iquote for local include paths
>  Author: Josh Poimboeuf <jpoimboe@redhat.com>
>  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
> 

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 00/13] perf tools: Move perf subcommand framework into lib/tools
  2015-12-08 14:55           ` Arnaldo Carvalho de Melo
@ 2015-12-08 15:27             ` Josh Poimboeuf
  2015-12-08 15:29             ` Arnaldo Carvalho de Melo
  1 sibling, 0 replies; 25+ messages in thread
From: Josh Poimboeuf @ 2015-12-08 15:27 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Jiri Olsa, Ingo Molnar, Namhyung Kim, Peter Zijlstra,
	Ingo Molnar, linux-kernel

On Tue, Dec 08, 2015 at 11:55:31AM -0300, Arnaldo Carvalho de Melo wrote:
> Em Tue, Dec 08, 2015 at 11:52:33AM -0300, Arnaldo Carvalho de Melo escreveu:
> > Em Mon, Dec 07, 2015 at 09:46:48AM +0100, Jiri Olsa escreveu:
> > > On Sun, Dec 06, 2015 at 02:02:42PM -0600, Josh Poimboeuf wrote:
> > > > 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...
> 
> 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:


diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
index f8888e8..1869d73 100644
--- a/tools/perf/tests/Build
+++ b/tools/perf/tests/Build
@@ -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[] =' >> $@


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [PATCH 00/13] perf tools: Move perf subcommand framework into lib/tools
  2015-12-08 14:55           ` Arnaldo Carvalho de Melo
  2015-12-08 15:27             ` Josh Poimboeuf
@ 2015-12-08 15:29             ` Arnaldo Carvalho de Melo
  2015-12-08 15:41               ` Arnaldo Carvalho de Melo
  1 sibling, 1 reply; 25+ messages in thread
From: Arnaldo Carvalho de Melo @ 2015-12-08 15:29 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Jiri Olsa, Ingo Molnar, Namhyung Kim, Peter Zijlstra,
	Ingo Molnar, linux-kernel

Em Tue, Dec 08, 2015 at 11:55:31AM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Tue, Dec 08, 2015 at 11:52:33AM -0300, Arnaldo Carvalho de Melo escreveu:
> > Em Mon, Dec 07, 2015 at 09:46:48AM +0100, Jiri Olsa escreveu:
> > > On Sun, Dec 06, 2015 at 02:02:42PM -0600, Josh Poimboeuf wrote:
> > > > 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...
> 
> 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

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 00/13] perf tools: Move perf subcommand framework into lib/tools
  2015-12-08 15:29             ` Arnaldo Carvalho de Melo
@ 2015-12-08 15:41               ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 25+ messages in thread
From: Arnaldo Carvalho de Melo @ 2015-12-08 15:41 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Jiri Olsa, Ingo Molnar, Namhyung Kim, Peter Zijlstra,
	Ingo Molnar, linux-kernel

Em Tue, Dec 08, 2015 at 12:29:15PM -0300, Arnaldo Carvalho de Melo escreveu:
> 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

diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 8b63dbdff197..331a0377da1f 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -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

^ permalink raw reply related	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2015-12-08 15:41 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-04 21:59 [PATCH 00/13] perf tools: Move perf subcommand framework into lib/tools Josh Poimboeuf
2015-12-04 21:59 ` [PATCH 01/13] perf: Use -iquote for local include paths Josh Poimboeuf
2015-12-04 21:59 ` [PATCH 02/13] perf: Split up util.h Josh Poimboeuf
2015-12-04 21:59 ` [PATCH 03/13] perf: Move term functions out of util.c Josh Poimboeuf
2015-12-04 21:59 ` [PATCH 04/13] perf: Remove unused pager_use_color variable Josh Poimboeuf
2015-12-04 21:59 ` [PATCH 05/13] perf: Split up cache.h Josh Poimboeuf
2015-12-04 21:59 ` [PATCH 06/13] perf: Remove cache.h Josh Poimboeuf
2015-12-04 21:59 ` [PATCH 07/13] perf: Save cmdline arguments earlier Josh Poimboeuf
2015-12-04 21:59 ` [PATCH 08/13] perf: Remove check for unused PERF_PAGER_IN_USE Josh Poimboeuf
2015-12-04 21:59 ` [PATCH 09/13] perf: Move cmd_version() to builtin-version.c Josh Poimboeuf
2015-12-04 21:59 ` [PATCH 10/13] perf: Move help_unknown_cmd() to its own file Josh Poimboeuf
2015-12-04 21:59 ` [PATCH 11/13] perf tools: Move strlcpy() to tools/lib/string.c Josh Poimboeuf
2015-12-04 21:59 ` [PATCH 12/13] perf tools: Move perf subcommand framework into a library Josh Poimboeuf
2015-12-04 22:21   ` [PATCH 12/13 v1.1] perf tools: Move tools/lib/string.c to libapi Josh Poimboeuf
2015-12-04 21:59 ` [PATCH 13/13] perf tools: Move subcommand framework and related utils " Josh Poimboeuf
2015-12-06  9:37 ` [PATCH 00/13] perf tools: Move perf subcommand framework into lib/tools Ingo Molnar
2015-12-06 15:50   ` Jiri Olsa
2015-12-06 20:02     ` Josh Poimboeuf
2015-12-07  8:46       ` Jiri Olsa
2015-12-08 14:52         ` Arnaldo Carvalho de Melo
2015-12-08 14:55           ` Arnaldo Carvalho de Melo
2015-12-08 15:27             ` Josh Poimboeuf
2015-12-08 15:29             ` Arnaldo Carvalho de Melo
2015-12-08 15:41               ` Arnaldo Carvalho de Melo
2015-12-06 18:28   ` Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).