All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 00/17] perf tools: Move perf subcommand framework to a library
@ 2015-12-14  4:18 Josh Poimboeuf
  2015-12-14  4:18 ` [PATCH v3 01/17] perf build: Remove unnecessary line in Makefile.feature Josh Poimboeuf
                   ` (16 more replies)
  0 siblings, 17 replies; 56+ messages in thread
From: Josh Poimboeuf @ 2015-12-14  4:18 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo
  Cc: linux-kernel, Jiri Olsa, Namhyung Kim

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

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

Patches 1-6 are some assorted cleanups I discovered in the process of
making the patch set.  They're completely separate from the rest of the
patches and can be merged independently.

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

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

Patch 17 updates the header guards for the moved .h files.

Based on acme/perf/core.

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

  https://github.com/jpoimboe/linux


[*] https://lkml.kernel.org/r/cover.1445443144.git.jpoimboe@redhat.com

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

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

Josh Poimboeuf (17):
  perf build: Remove unnecessary line in Makefile.feature
  tools build: Fix feature Makefile dependencies for 'O='
  perf test: Add Build file to dependencies for llvm-src-*.c
  perf test: remove tarpkg at end of test
  perf build: Fix 'make clean'
  perf build: Rename LIB_PATH -> API_PATH
  perf: Create pager.h
  perf: Remove check for unused PERF_PAGER_IN_USE
  perf: Move help_unknown_cmd() to its own file
  perf: Provide subcmd configuration at runtime
  perf: Remove 'perf' from subcmd function and variable names
  perf: Convert parse-options.c internal functions to static
  perf: Document the fact that parse_options*() may exit
  perf: Remove subcmd dependencies on strbuf
  perf: Finalize subcmd independence
  perf subcmd: Create subcmd library
  tools subcmd: Rename subcmd header include guards

 tools/build/Makefile.feature                    |   3 +-
 tools/build/feature/Makefile                    |  95 +++++-----
 tools/lib/subcmd/Build                          |   6 +
 tools/lib/subcmd/Makefile                       |  48 +++++
 tools/lib/subcmd/exec-cmd.c                     | 227 ++++++++++++++++++++++++
 tools/lib/subcmd/exec-cmd.h                     |  16 ++
 tools/{perf/util => lib/subcmd}/help.c          | 170 ++++++------------
 tools/{perf/util => lib/subcmd}/help.h          |  13 +-
 tools/{perf/util => lib/subcmd}/pager.c         |  24 ++-
 tools/lib/subcmd/pager.h                        |   9 +
 tools/{perf/util => lib/subcmd}/parse-options.c | 134 ++++++++------
 tools/{perf/util => lib/subcmd}/parse-options.h |  23 ++-
 tools/{perf/util => lib/subcmd}/run-command.c   |  24 ++-
 tools/{perf/util => lib/subcmd}/run-command.h   |  12 +-
 tools/{perf/util => lib/subcmd}/sigchain.c      |   3 +-
 tools/{perf/util => lib/subcmd}/sigchain.h      |   6 +-
 tools/lib/subcmd/subcmd-util.h                  |  91 ++++++++++
 tools/perf/Build                                |   5 +-
 tools/perf/MANIFEST                             |   1 +
 tools/perf/Makefile.perf                        |  35 ++--
 tools/perf/arch/x86/util/intel-pt.c             |   2 +-
 tools/perf/bench/futex-hash.c                   |   2 +-
 tools/perf/bench/futex-lock-pi.c                |   2 +-
 tools/perf/bench/futex-requeue.c                |   2 +-
 tools/perf/bench/futex-wake-parallel.c          |   2 +-
 tools/perf/bench/futex-wake.c                   |   2 +-
 tools/perf/bench/mem-functions.c                |   2 +-
 tools/perf/bench/numa.c                         |   2 +-
 tools/perf/bench/sched-messaging.c              |   2 +-
 tools/perf/bench/sched-pipe.c                   |   2 +-
 tools/perf/builtin-annotate.c                   |   2 +-
 tools/perf/builtin-bench.c                      |   2 +-
 tools/perf/builtin-buildid-cache.c              |   2 +-
 tools/perf/builtin-buildid-list.c               |   2 +-
 tools/perf/builtin-config.c                     |   2 +-
 tools/perf/builtin-data.c                       |   2 +-
 tools/perf/builtin-evlist.c                     |   2 +-
 tools/perf/builtin-help.c                       |  10 +-
 tools/perf/builtin-inject.c                     |   2 +-
 tools/perf/builtin-kmem.c                       |   2 +-
 tools/perf/builtin-kvm.c                        |   2 +-
 tools/perf/builtin-list.c                       |   2 +-
 tools/perf/builtin-lock.c                       |   2 +-
 tools/perf/builtin-mem.c                        |   2 +-
 tools/perf/builtin-probe.c                      |   2 +-
 tools/perf/builtin-record.c                     |   2 +-
 tools/perf/builtin-report.c                     |   2 +-
 tools/perf/builtin-sched.c                      |   2 +-
 tools/perf/builtin-script.c                     |  12 +-
 tools/perf/builtin-stat.c                       |   2 +-
 tools/perf/builtin-timechart.c                  |   2 +-
 tools/perf/builtin-top.c                        |   2 +-
 tools/perf/builtin-trace.c                      |   4 +-
 tools/perf/perf.c                               |  19 +-
 tools/perf/tests/Build                          |   6 +-
 tools/perf/tests/attr.c                         |   4 +-
 tools/perf/tests/builtin-test.c                 |   2 +-
 tools/perf/tests/make                           |   3 +-
 tools/perf/util/Build                           |   8 +-
 tools/perf/util/auxtrace.c                      |   2 +-
 tools/perf/util/cache.h                         |   6 +-
 tools/perf/util/cgroup.c                        |   2 +-
 tools/perf/util/config.c                        |   2 +-
 tools/perf/util/evlist.c                        |   2 +-
 tools/perf/util/exec_cmd.c                      | 149 ----------------
 tools/perf/util/exec_cmd.h                      |  13 --
 tools/perf/util/help-unknown-cmd.c              | 103 +++++++++++
 tools/perf/util/help-unknown-cmd.h              |   0
 tools/perf/util/parse-branch-options.c          |   2 +-
 tools/perf/util/parse-events.c                  |   4 +-
 tools/perf/util/parse-regs-options.c            |   2 +-
 tools/perf/util/sort.h                          |   2 +-
 tools/perf/util/util.h                          |  14 --
 73 files changed, 848 insertions(+), 528 deletions(-)
 create mode 100644 tools/lib/subcmd/Build
 create mode 100644 tools/lib/subcmd/Makefile
 create mode 100644 tools/lib/subcmd/exec-cmd.c
 create mode 100644 tools/lib/subcmd/exec-cmd.h
 rename tools/{perf/util => lib/subcmd}/help.c (58%)
 rename tools/{perf/util => lib/subcmd}/help.h (73%)
 rename tools/{perf/util => lib/subcmd}/pager.c (84%)
 create mode 100644 tools/lib/subcmd/pager.h
 rename tools/{perf/util => lib/subcmd}/parse-options.c (87%)
 rename tools/{perf/util => lib/subcmd}/parse-options.h (95%)
 rename tools/{perf/util => lib/subcmd}/run-command.c (90%)
 rename tools/{perf/util => lib/subcmd}/run-command.h (86%)
 rename tools/{perf/util => lib/subcmd}/sigchain.c (95%)
 rename tools/{perf/util => lib/subcmd}/sigchain.h (55%)
 create mode 100644 tools/lib/subcmd/subcmd-util.h
 delete mode 100644 tools/perf/util/exec_cmd.c
 delete mode 100644 tools/perf/util/exec_cmd.h
 create mode 100644 tools/perf/util/help-unknown-cmd.c
 create mode 100644 tools/perf/util/help-unknown-cmd.h

-- 
2.4.3


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

* [PATCH v3 01/17] perf build: Remove unnecessary line in Makefile.feature
  2015-12-14  4:18 [PATCH v3 00/17] perf tools: Move perf subcommand framework to a library Josh Poimboeuf
@ 2015-12-14  4:18 ` Josh Poimboeuf
  2015-12-14 10:05   ` Jiri Olsa
  2015-12-18  8:47   ` [tip:perf/core] " tip-bot for Josh Poimboeuf
  2015-12-14  4:18 ` [PATCH v3 02/17] tools build: Fix feature Makefile dependencies for 'O=' Josh Poimboeuf
                   ` (15 subsequent siblings)
  16 siblings, 2 replies; 56+ messages in thread
From: Josh Poimboeuf @ 2015-12-14  4:18 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo
  Cc: linux-kernel, Jiri Olsa, Namhyung Kim

This line always silently fails because it doesn't add the 'test-'
prefix to the .bin file.

And it seems to be unnecessary anyway: the line immediately after it
does all the individual feature checks.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 tools/build/Makefile.feature | 1 -
 1 file changed, 1 deletion(-)

diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature
index 37ff4c9..b8c31ec 100644
--- a/tools/build/Makefile.feature
+++ b/tools/build/Makefile.feature
@@ -101,7 +101,6 @@ ifeq ($(feature-all), 1)
   #
   $(foreach feat,$(FEATURE_TESTS),$(call feature_set,$(feat)))
 else
-  $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS)" LDFLAGS=$(LDFLAGS) -i -j -C $(feature_dir) $(addsuffix .bin,$(FEATURE_TESTS)) >/dev/null 2>&1)
   $(foreach feat,$(FEATURE_TESTS),$(call feature_check,$(feat)))
 endif
 
-- 
2.4.3


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

* [PATCH v3 02/17] tools build: Fix feature Makefile dependencies for 'O='
  2015-12-14  4:18 [PATCH v3 00/17] perf tools: Move perf subcommand framework to a library Josh Poimboeuf
  2015-12-14  4:18 ` [PATCH v3 01/17] perf build: Remove unnecessary line in Makefile.feature Josh Poimboeuf
@ 2015-12-14  4:18 ` Josh Poimboeuf
  2015-12-14 10:08   ` Jiri Olsa
  2015-12-14  4:18 ` [PATCH v3 03/17] perf test: Add Build file to dependencies for llvm-src-*.c Josh Poimboeuf
                   ` (14 subsequent siblings)
  16 siblings, 1 reply; 56+ messages in thread
From: Josh Poimboeuf @ 2015-12-14  4:18 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo
  Cc: linux-kernel, Jiri Olsa, Namhyung Kim

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 tools/build/Makefile.feature |  2 +-
 tools/build/feature/Makefile | 95 ++++++++++++++++++++++----------------------
 2 files changed, 49 insertions(+), 48 deletions(-)

diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature
index b8c31ec..6c0519d 100644
--- a/tools/build/Makefile.feature
+++ b/tools/build/Makefile.feature
@@ -7,7 +7,7 @@ endif
 
 feature_check = $(eval $(feature_check_code))
 define feature_check_code
-  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C $(feature_dir) test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0)
+  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C $(feature_dir) $(OUTPUT_FEATURES)test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0)
 endef
 
 feature_set = $(eval $(feature_set_code))
diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
index cea04ce9..8fec49d 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -1,4 +1,3 @@
-
 FILES=					\
 	test-all.bin			\
 	test-backtrace.bin		\
@@ -38,38 +37,40 @@ FILES=					\
 	test-bpf.bin			\
 	test-get_cpuid.bin
 
+OUTPUT_FILES = $(addprefix $(OUTPUT),$(FILES))
+
 CC := $(CROSS_COMPILE)gcc -MD
 PKG_CONFIG := $(CROSS_COMPILE)pkg-config
 
-all: $(FILES)
+all: $(OUTPUT_FILES)
 
-__BUILD = $(CC) $(CFLAGS) -Wall -Werror -o $(OUTPUT)$@ $(patsubst %.bin,%.c,$@) $(LDFLAGS)
-  BUILD = $(__BUILD) > $(OUTPUT)$(@:.bin=.make.output) 2>&1
+__BUILD = $(CC) $(CFLAGS) -Wall -Werror -o $@ $(patsubst %.bin,%.c,$(@F)) $(LDFLAGS)
+  BUILD = $(__BUILD) > $(@:.bin=.make.output) 2>&1
 
 ###############################
 
-test-all.bin:
+$(OUTPUT)test-all.bin:
 	$(BUILD) -fstack-protector-all -O2 -D_FORTIFY_SOURCE=2 -ldw -lelf -lnuma -lelf -laudit -I/usr/include/slang -lslang $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) $(FLAGS_PERL_EMBED) $(FLAGS_PYTHON_EMBED) -DPACKAGE='"perf"' -lbfd -ldl -lz -llzma
 
-test-hello.bin:
+$(OUTPUT)test-hello.bin:
 	$(BUILD)
 
-test-pthread-attr-setaffinity-np.bin:
+$(OUTPUT)test-pthread-attr-setaffinity-np.bin:
 	$(BUILD) -D_GNU_SOURCE -lpthread
 
-test-stackprotector-all.bin:
+$(OUTPUT)test-stackprotector-all.bin:
 	$(BUILD) -fstack-protector-all
 
-test-fortify-source.bin:
+$(OUTPUT)test-fortify-source.bin:
 	$(BUILD) -O2 -D_FORTIFY_SOURCE=2
 
-test-bionic.bin:
+$(OUTPUT)test-bionic.bin:
 	$(BUILD)
 
-test-libelf.bin:
+$(OUTPUT)test-libelf.bin:
 	$(BUILD) -lelf
 
-test-glibc.bin:
+$(OUTPUT)test-glibc.bin:
 	$(BUILD)
 
 DWARFLIBS := -ldw
@@ -77,37 +78,37 @@ ifeq ($(findstring -static,${LDFLAGS}),-static)
 DWARFLIBS += -lelf -lebl -lz -llzma -lbz2
 endif
 
-test-dwarf.bin:
+$(OUTPUT)test-dwarf.bin:
 	$(BUILD) $(DWARFLIBS)
 
-test-libelf-mmap.bin:
+$(OUTPUT)test-libelf-mmap.bin:
 	$(BUILD) -lelf
 
-test-libelf-getphdrnum.bin:
+$(OUTPUT)test-libelf-getphdrnum.bin:
 	$(BUILD) -lelf
 
-test-libnuma.bin:
+$(OUTPUT)test-libnuma.bin:
 	$(BUILD) -lnuma
 
-test-numa_num_possible_cpus.bin:
+$(OUTPUT)test-numa_num_possible_cpus.bin:
 	$(BUILD) -lnuma
 
-test-libunwind.bin:
+$(OUTPUT)test-libunwind.bin:
 	$(BUILD) -lelf
 
-test-libunwind-debug-frame.bin:
+$(OUTPUT)test-libunwind-debug-frame.bin:
 	$(BUILD) -lelf
 
-test-libaudit.bin:
+$(OUTPUT)test-libaudit.bin:
 	$(BUILD) -laudit
 
-test-libslang.bin:
+$(OUTPUT)test-libslang.bin:
 	$(BUILD) -I/usr/include/slang -lslang
 
-test-gtk2.bin:
+$(OUTPUT)test-gtk2.bin:
 	$(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
 
-test-gtk2-infobar.bin:
+$(OUTPUT)test-gtk2-infobar.bin:
 	$(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
 
 grep-libs  = $(filter -l%,$(1))
@@ -119,63 +120,63 @@ PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
 PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null`
 FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
 
-test-libperl.bin:
+$(OUTPUT)test-libperl.bin:
 	$(BUILD) $(FLAGS_PERL_EMBED)
 
-test-libpython.bin:
+$(OUTPUT)test-libpython.bin:
 	$(BUILD)
 
-test-libpython-version.bin:
+$(OUTPUT)test-libpython-version.bin:
 	$(BUILD)
 
-test-libbfd.bin:
+$(OUTPUT)test-libbfd.bin:
 	$(BUILD) -DPACKAGE='"perf"' -lbfd -lz -liberty -ldl
 
-test-liberty.bin:
-	$(CC) $(CFLAGS) -Wall -Werror -o $(OUTPUT)$@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty
+$(OUTPUT)test-liberty.bin:
+	$(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty
 
-test-liberty-z.bin:
-	$(CC) $(CFLAGS) -Wall -Werror -o $(OUTPUT)$@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty -lz
+$(OUTPUT)test-liberty-z.bin:
+	$(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty -lz
 
-test-cplus-demangle.bin:
+$(OUTPUT)test-cplus-demangle.bin:
 	$(BUILD) -liberty
 
-test-backtrace.bin:
+$(OUTPUT)test-backtrace.bin:
 	$(BUILD)
 
-test-timerfd.bin:
+$(OUTPUT)test-timerfd.bin:
 	$(BUILD)
 
-test-libdw-dwarf-unwind.bin:
+$(OUTPUT)test-libdw-dwarf-unwind.bin:
 	$(BUILD) # -ldw provided by $(FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind)
 
-test-libbabeltrace.bin:
+$(OUTPUT)test-libbabeltrace.bin:
 	$(BUILD) # -lbabeltrace provided by $(FEATURE_CHECK_LDFLAGS-libbabeltrace)
 
-test-sync-compare-and-swap.bin:
+$(OUTPUT)test-sync-compare-and-swap.bin:
 	$(BUILD)
 
-test-compile-32.bin:
-	$(CC) -m32 -o $(OUTPUT)$@ test-compile.c
+$(OUTPUT)test-compile-32.bin:
+	$(CC) -m32 -o $@ test-compile.c
 
-test-compile-x32.bin:
-	$(CC) -mx32 -o $(OUTPUT)$@ test-compile.c
+$(OUTPUT)test-compile-x32.bin:
+	$(CC) -mx32 -o $@ test-compile.c
 
-test-zlib.bin:
+$(OUTPUT)test-zlib.bin:
 	$(BUILD) -lz
 
-test-lzma.bin:
+$(OUTPUT)test-lzma.bin:
 	$(BUILD) -llzma
 
-test-get_cpuid.bin:
+$(OUTPUT)test-get_cpuid.bin:
 	$(BUILD)
 
-test-bpf.bin:
+$(OUTPUT)test-bpf.bin:
 	$(BUILD)
 
--include *.d
+-include $(OUTPUT)*.d
 
 ###############################
 
 clean:
-	rm -f $(FILES) *.d $(FILES:.bin=.make.output)
+	rm -f $(OUTPUT_FILES) $(OUTPUT)*.d $(OUTPUT_FILES:.bin=.make.output)
-- 
2.4.3


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

* [PATCH v3 03/17] perf test: Add Build file to dependencies for llvm-src-*.c
  2015-12-14  4:18 [PATCH v3 00/17] perf tools: Move perf subcommand framework to a library Josh Poimboeuf
  2015-12-14  4:18 ` [PATCH v3 01/17] perf build: Remove unnecessary line in Makefile.feature Josh Poimboeuf
  2015-12-14  4:18 ` [PATCH v3 02/17] tools build: Fix feature Makefile dependencies for 'O=' Josh Poimboeuf
@ 2015-12-14  4:18 ` Josh Poimboeuf
  2015-12-14 10:10   ` Jiri Olsa
  2015-12-18  8:47   ` [tip:perf/core] " tip-bot for Josh Poimboeuf
  2015-12-14  4:18 ` [PATCH v3 04/17] perf test: remove tarpkg at end of test Josh Poimboeuf
                   ` (13 subsequent siblings)
  16 siblings, 2 replies; 56+ messages in thread
From: Josh Poimboeuf @ 2015-12-14  4:18 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo
  Cc: linux-kernel, Jiri Olsa, Namhyung Kim

Because the Build file writes source code to the generated llvm-src-*.c
files, it should be listed as one of the dependencies, so that any
future changes to the code being echoed won't require a 'make clean'.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 tools/perf/tests/Build | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
index 0ff8a97..f23fb7e 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[] =' >> $@
-- 
2.4.3


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

* [PATCH v3 04/17] perf test: remove tarpkg at end of test
  2015-12-14  4:18 [PATCH v3 00/17] perf tools: Move perf subcommand framework to a library Josh Poimboeuf
                   ` (2 preceding siblings ...)
  2015-12-14  4:18 ` [PATCH v3 03/17] perf test: Add Build file to dependencies for llvm-src-*.c Josh Poimboeuf
@ 2015-12-14  4:18 ` Josh Poimboeuf
  2015-12-18  8:48   ` [tip:perf/core] perf test: Remove " tip-bot for Josh Poimboeuf
  2015-12-14  4:18 ` [PATCH v3 05/17] perf build: Fix 'make clean' Josh Poimboeuf
                   ` (12 subsequent siblings)
  16 siblings, 1 reply; 56+ messages in thread
From: Josh Poimboeuf @ 2015-12-14  4:18 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo
  Cc: linux-kernel, Jiri Olsa, Namhyung Kim

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 tools/perf/tests/make | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/perf/tests/make b/tools/perf/tests/make
index 8ea3dff..c1fbb8e 100644
--- a/tools/perf/tests/make
+++ b/tools/perf/tests/make
@@ -259,7 +259,8 @@ $(run_O):
 tarpkg:
 	@cmd="$(PERF)/tests/perf-targz-src-pkg $(PERF)"; \
 	echo "- $@: $$cmd" && echo $$cmd > $@ && \
-	( eval $$cmd ) >> $@ 2>&1
+	( eval $$cmd ) >> $@ 2>&1 && \
+	rm -f $@
 
 make_kernelsrc:
 	@echo "- make -C <kernelsrc> tools/perf"
-- 
2.4.3


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

* [PATCH v3 05/17] perf build: Fix 'make clean'
  2015-12-14  4:18 [PATCH v3 00/17] perf tools: Move perf subcommand framework to a library Josh Poimboeuf
                   ` (3 preceding siblings ...)
  2015-12-14  4:18 ` [PATCH v3 04/17] perf test: remove tarpkg at end of test Josh Poimboeuf
@ 2015-12-14  4:18 ` Josh Poimboeuf
  2015-12-14 10:14   ` Jiri Olsa
  2015-12-18  8:48   ` [tip:perf/core] " tip-bot for Josh Poimboeuf
  2015-12-14  4:18 ` [PATCH v3 06/17] perf build: Rename LIB_PATH -> API_PATH Josh Poimboeuf
                   ` (11 subsequent siblings)
  16 siblings, 2 replies; 56+ messages in thread
From: Josh Poimboeuf @ 2015-12-14  4:18 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo
  Cc: linux-kernel, Jiri Olsa, Namhyung Kim

Add some missing files to the 'make clean' target.

Reported-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 tools/perf/Makefile.perf | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 929a32b..906c723 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -582,15 +582,16 @@ $(INSTALL_DOC_TARGETS):
 #
 config-clean:
 	$(call QUIET_CLEAN, config)
-	$(Q)$(MAKE) -C $(srctree)/tools/build/feature/ clean >/dev/null
+	$(Q)$(MAKE) -C $(srctree)/tools/build/feature/ $(if $(OUTPUT),OUTPUT=$(OUTPUT)feature/,) clean >/dev/null
 
 clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean config-clean
 	$(call QUIET_CLEAN, core-objs)  $(RM) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(LANG_BINDINGS)
-	$(Q)find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
+	$(Q)find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
 	$(Q)$(RM) $(OUTPUT).config-detected
 	$(call QUIET_CLEAN, core-progs) $(RM) $(ALL_PROGRAMS) perf perf-read-vdso32 perf-read-vdsox32
 	$(call QUIET_CLEAN, core-gen)   $(RM)  *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope* $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)FEATURE-DUMP $(OUTPUT)util/*-bison* $(OUTPUT)util/*-flex* \
-		$(OUTPUT)util/intel-pt-decoder/inat-tables.c
+		$(OUTPUT)util/intel-pt-decoder/inat-tables.c $(OUTPUT)fixdep \
+		$(OUTPUT)tests/llvm-src-{base,kbuild,prologue}.c
 	$(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean
 	$(python-clean)
 
-- 
2.4.3


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

* [PATCH v3 06/17] perf build: Rename LIB_PATH -> API_PATH
  2015-12-14  4:18 [PATCH v3 00/17] perf tools: Move perf subcommand framework to a library Josh Poimboeuf
                   ` (4 preceding siblings ...)
  2015-12-14  4:18 ` [PATCH v3 05/17] perf build: Fix 'make clean' Josh Poimboeuf
@ 2015-12-14  4:18 ` Josh Poimboeuf
  2015-12-14 10:34   ` Jiri Olsa
  2015-12-18  8:49   ` [tip:perf/core] " tip-bot for Josh Poimboeuf
  2015-12-14  4:18 ` [PATCH v3 07/17] perf: Create pager.h Josh Poimboeuf
                   ` (10 subsequent siblings)
  16 siblings, 2 replies; 56+ messages in thread
From: Josh Poimboeuf @ 2015-12-14  4:18 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo
  Cc: linux-kernel, Jiri Olsa, Namhyung Kim

'LIB_PATH' is a misnomer because there are multiple library paths.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 tools/perf/Makefile.perf | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 906c723..388ec64 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -185,13 +185,13 @@ ifneq ($(OUTPUT),)
   TE_PATH=$(OUTPUT)
   BPF_PATH=$(OUTPUT)
 ifneq ($(subdir),)
-  LIB_PATH=$(OUTPUT)/../lib/api/
+  API_PATH=$(OUTPUT)/../lib/api/
 else
-  LIB_PATH=$(OUTPUT)
+  API_PATH=$(OUTPUT)
 endif
 else
   TE_PATH=$(TRACE_EVENT_DIR)
-  LIB_PATH=$(LIB_DIR)
+  API_PATH=$(LIB_DIR)
   BPF_PATH=$(BPF_DIR)
 endif
 
@@ -201,7 +201,7 @@ export LIBTRACEEVENT
 LIBTRACEEVENT_DYNAMIC_LIST = $(TE_PATH)libtraceevent-dynamic-list
 LIBTRACEEVENT_DYNAMIC_LIST_LDFLAGS = -Xlinker --dynamic-list=$(LIBTRACEEVENT_DYNAMIC_LIST)
 
-LIBAPI = $(LIB_PATH)libapi.a
+LIBAPI = $(API_PATH)libapi.a
 export LIBAPI
 
 LIBBPF = $(BPF_PATH)libbpf.a
-- 
2.4.3


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

* [PATCH v3 07/17] perf: Create pager.h
  2015-12-14  4:18 [PATCH v3 00/17] perf tools: Move perf subcommand framework to a library Josh Poimboeuf
                   ` (5 preceding siblings ...)
  2015-12-14  4:18 ` [PATCH v3 06/17] perf build: Rename LIB_PATH -> API_PATH Josh Poimboeuf
@ 2015-12-14  4:18 ` Josh Poimboeuf
  2015-12-18  8:49   ` [tip:perf/core] perf tools: " tip-bot for Josh Poimboeuf
  2015-12-14  4:18 ` [PATCH v3 08/17] perf: Remove check for unused PERF_PAGER_IN_USE Josh Poimboeuf
                   ` (9 subsequent siblings)
  16 siblings, 1 reply; 56+ messages in thread
From: Josh Poimboeuf @ 2015-12-14  4:18 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo
  Cc: linux-kernel, Jiri Olsa, Namhyung Kim

Move the 'pager' function prototypes into a new pager.h so that the
pager code can be moved out to a library.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 tools/perf/util/cache.h | 5 +----
 tools/perf/util/pager.h | 7 +++++++
 2 files changed, 8 insertions(+), 4 deletions(-)
 create mode 100644 tools/perf/util/pager.h

diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h
index 4c2b764..9ca4a58 100644
--- a/tools/perf/util/cache.h
+++ b/tools/perf/util/cache.h
@@ -4,6 +4,7 @@
 #include <stdbool.h>
 #include "util.h"
 #include "strbuf.h"
+#include "pager.h"
 #include "../perf.h"
 #include "../ui/ui.h"
 
@@ -28,10 +29,6 @@ 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);
 
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 */
-- 
2.4.3


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

* [PATCH v3 08/17] perf: Remove check for unused PERF_PAGER_IN_USE
  2015-12-14  4:18 [PATCH v3 00/17] perf tools: Move perf subcommand framework to a library Josh Poimboeuf
                   ` (6 preceding siblings ...)
  2015-12-14  4:18 ` [PATCH v3 07/17] perf: Create pager.h Josh Poimboeuf
@ 2015-12-14  4:18 ` Josh Poimboeuf
  2015-12-18  8:49   ` [tip:perf/core] perf tools: " tip-bot for Josh Poimboeuf
  2015-12-14  4:18 ` [PATCH v3 09/17] perf: Move help_unknown_cmd() to its own file Josh Poimboeuf
                   ` (8 subsequent siblings)
  16 siblings, 1 reply; 56+ messages in thread
From: Josh Poimboeuf @ 2015-12-14  4:18 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo
  Cc: linux-kernel, Jiri Olsa, Namhyung Kim

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 53ef006..7dcbef6 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] 56+ messages in thread

* [PATCH v3 09/17] perf: Move help_unknown_cmd() to its own file
  2015-12-14  4:18 [PATCH v3 00/17] perf tools: Move perf subcommand framework to a library Josh Poimboeuf
                   ` (7 preceding siblings ...)
  2015-12-14  4:18 ` [PATCH v3 08/17] perf: Remove check for unused PERF_PAGER_IN_USE Josh Poimboeuf
@ 2015-12-14  4:18 ` Josh Poimboeuf
  2015-12-18  8:50   ` [tip:perf/core] perf tools: " tip-bot for Josh Poimboeuf
  2015-12-14  4:18 ` [PATCH v3 10/17] perf: Provide subcmd configuration at runtime Josh Poimboeuf
                   ` (7 subsequent siblings)
  16 siblings, 1 reply; 56+ messages in thread
From: Josh Poimboeuf @ 2015-12-14  4:18 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo
  Cc: linux-kernel, Jiri Olsa, Namhyung Kim

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             | 107 ++-----------------------------------
 tools/perf/util/help.h             |   3 ++
 5 files changed, 110 insertions(+), 104 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..a0820f1
--- /dev/null
+++ b/tools/perf/util/help-unknown-cmd.c
@@ -0,0 +1,103 @@
+#include "cache.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 929c93f..8d74f7d 100644
--- a/tools/perf/util/help.c
+++ b/tools/perf/util/help.c
@@ -1,9 +1,7 @@
 #include "cache.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 +15,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 +26,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;
 
@@ -233,102 +231,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] 56+ messages in thread

* [PATCH v3 10/17] perf: Provide subcmd configuration at runtime
  2015-12-14  4:18 [PATCH v3 00/17] perf tools: Move perf subcommand framework to a library Josh Poimboeuf
                   ` (8 preceding siblings ...)
  2015-12-14  4:18 ` [PATCH v3 09/17] perf: Move help_unknown_cmd() to its own file Josh Poimboeuf
@ 2015-12-14  4:18 ` Josh Poimboeuf
  2015-12-14 10:33   ` Jiri Olsa
  2015-12-14  4:18 ` [PATCH v3 11/17] perf: Remove 'perf' from subcmd function and variable names Josh Poimboeuf
                   ` (6 subsequent siblings)
  16 siblings, 1 reply; 56+ messages in thread
From: Josh Poimboeuf @ 2015-12-14  4:18 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo
  Cc: linux-kernel, Jiri Olsa, Namhyung Kim

Create init functions for exec_cmd.c, parse-option.c, and pager.c.  This
allows their configuration to be specified at runtime so they can be
split out into a separate library which can be used by other programs.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 tools/perf/Build                |  5 ++++-
 tools/perf/perf.c               |  7 ++++++-
 tools/perf/util/Build           |  1 -
 tools/perf/util/cache.h         |  1 +
 tools/perf/util/exec_cmd.c      | 28 +++++++++++++++++++++-------
 tools/perf/util/exec_cmd.h      |  3 +++
 tools/perf/util/pager.c         |  9 ++++++++-
 tools/perf/util/pager.h         |  2 ++
 tools/perf/util/parse-options.c | 10 +++++++++-
 tools/perf/util/parse-options.h |  2 ++
 10 files changed, 56 insertions(+), 12 deletions(-)

diff --git a/tools/perf/Build b/tools/perf/Build
index 2a41217..00c4b8c 100644
--- a/tools/perf/Build
+++ b/tools/perf/Build
@@ -36,7 +36,10 @@ paths += -DPERF_MAN_PATH="BUILD_STR($(mandir_SQ))"
 
 CFLAGS_builtin-help.o      += $(paths)
 CFLAGS_builtin-timechart.o += $(paths)
-CFLAGS_perf.o              += -DPERF_HTML_PATH="BUILD_STR($(htmldir_SQ))" -include $(OUTPUT)PERF-VERSION-FILE
+CFLAGS_perf.o              += -DPERF_HTML_PATH="BUILD_STR($(htmldir_SQ))"	\
+			      -DPERF_EXEC_PATH="BUILD_STR($(perfexecdir_SQ))"	\
+			      -DPREFIX="BUILD_STR($(prefix_SQ))"		\
+			      -include $(OUTPUT)PERF-VERSION-FILE
 CFLAGS_builtin-trace.o	   += -DSTRACE_GROUPS_DIR="BUILD_STR($(STRACE_GROUPS_DIR_SQ))"
 
 libperf-y += util/
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index 59ea48c..4d94c80 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -119,7 +119,7 @@ static void commit_pager_choice(void)
 {
 	switch (use_pager) {
 	case 0:
-		setenv("PERF_PAGER", "cat", 1);
+		setenv(PERF_PAGER_ENVIRONMENT, "cat", 1);
 		break;
 	case 1:
 		/* setup_pager(); */
@@ -530,6 +530,11 @@ int main(int argc, const char **argv)
 	const char *cmd;
 	char sbuf[STRERR_BUFSIZE];
 
+	/* libsubcmd init */
+	exec_cmd_init("perf", PREFIX, PERF_EXEC_PATH, EXEC_PATH_ENVIRONMENT);
+	parse_options_init("perf");
+	pager_init(PERF_PAGER_ENVIRONMENT);
+
 	/* The page_size is placed in util object. */
 	page_size = sysconf(_SC_PAGE_SIZE);
 	cacheline_size = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 99b3dae..470515b 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -113,7 +113,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/cache.h b/tools/perf/util/cache.h
index 9ca4a58..4b9d7da 100644
--- a/tools/perf/util/cache.h
+++ b/tools/perf/util/cache.h
@@ -19,6 +19,7 @@
 #define DEFAULT_PERF_DIR_ENVIRONMENT ".perf"
 #define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"
 #define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR"
+#define PERF_PAGER_ENVIRONMENT "PERF_PAGER"
 
 typedef int (*config_fn_t)(const char *, const char *, void *);
 extern int perf_default_config(const char *, const char *, void *);
diff --git a/tools/perf/util/exec_cmd.c b/tools/perf/util/exec_cmd.c
index 1099e92..84f9dc5 100644
--- a/tools/perf/util/exec_cmd.c
+++ b/tools/perf/util/exec_cmd.c
@@ -5,19 +5,33 @@
 #include <string.h>
 
 #define MAX_ARGS	32
+#define UNDEFINED	"UNDEFINED"
 
 static const char *argv_exec_path;
 static const char *argv0_path;
 
+static const char *cfg_exec_name	= UNDEFINED;
+static const char *cfg_prefix		= UNDEFINED;
+static const char *cfg_exec_path	= UNDEFINED;
+static const char *cfg_exec_path_env	= UNDEFINED;
+
+void exec_cmd_init(const char *exec_name, const char *prefix,
+		   const char *exec_path, const char *exec_path_env)
+{
+	cfg_exec_name		= exec_name;
+	cfg_prefix		= prefix;
+	cfg_exec_path		= exec_path;
+	cfg_exec_path_env	= exec_path_env;
+}
+
 char *system_path(const char *path)
 {
-	static const char *prefix = PREFIX;
 	struct strbuf d = STRBUF_INIT;
 
 	if (is_absolute_path(path))
 		return strdup(path);
 
-	strbuf_addf(&d, "%s/%s", prefix, path);
+	strbuf_addf(&d, "%s/%s", cfg_prefix, path);
 	path = strbuf_detach(&d, NULL);
 	return (char *)path;
 }
@@ -47,7 +61,7 @@ void perf_set_argv_exec_path(const char *exec_path)
 	/*
 	 * Propagate this setting to external programs.
 	 */
-	setenv(EXEC_PATH_ENVIRONMENT, exec_path, 1);
+	setenv(cfg_exec_path_env, exec_path, 1);
 }
 
 
@@ -59,11 +73,11 @@ char *perf_exec_path(void)
 	if (argv_exec_path)
 		return strdup(argv_exec_path);
 
-	env = getenv(EXEC_PATH_ENVIRONMENT);
+	env = getenv(cfg_exec_path_env);
 	if (env && *env)
 		return strdup(env);
 
-	return system_path(PERF_EXEC_PATH);
+	return system_path(cfg_exec_path);
 }
 
 static void add_path(struct strbuf *out, const char *path)
@@ -107,7 +121,7 @@ static const char **prepare_perf_cmd(const char **argv)
 		; /* just counting */
 	nargv = malloc(sizeof(*nargv) * (argc + 2));
 
-	nargv[0] = "perf";
+	nargv[0] = cfg_exec_name;
 	for (argc = 0; argv[argc]; argc++)
 		nargv[argc + 1] = argv[argc];
 	nargv[argc + 1] = NULL;
@@ -118,7 +132,7 @@ int execv_perf_cmd(const char **argv) {
 	const char **nargv = prepare_perf_cmd(argv);
 
 	/* execvp() can only ever return if it fails */
-	execvp("perf", (char **)nargv);
+	execvp(cfg_exec_name, (char **)nargv);
 
 	free(nargv);
 	return -1;
diff --git a/tools/perf/util/exec_cmd.h b/tools/perf/util/exec_cmd.h
index 48b4175..fd4434e 100644
--- a/tools/perf/util/exec_cmd.h
+++ b/tools/perf/util/exec_cmd.h
@@ -1,6 +1,9 @@
 #ifndef __PERF_EXEC_CMD_H
 #define __PERF_EXEC_CMD_H
 
+extern void exec_cmd_init(const char *exec_name, const char *prefix,
+			  const char *exec_path, const char *exec_path_env);
+
 extern void perf_set_argv_exec_path(const char *exec_path);
 extern const char *perf_extract_argv0_path(const char *path);
 extern void setup_path(void);
diff --git a/tools/perf/util/pager.c b/tools/perf/util/pager.c
index 7dcbef6..f6153a1 100644
--- a/tools/perf/util/pager.c
+++ b/tools/perf/util/pager.c
@@ -9,6 +9,13 @@
 
 static int spawned_pager;
 
+static const char *cfg_pager_env = "UNDEFINED";
+
+void pager_init(const char *pager_env)
+{
+	cfg_pager_env = pager_env;
+}
+
 static void pager_preexec(void)
 {
 	/*
@@ -46,7 +53,7 @@ static void wait_for_pager_signal(int signo)
 
 void setup_pager(void)
 {
-	const char *pager = getenv("PERF_PAGER");
+	const char *pager = getenv(cfg_pager_env);
 
 	if (!isatty(1))
 		return;
diff --git a/tools/perf/util/pager.h b/tools/perf/util/pager.h
index 2794a83..d6a591a 100644
--- a/tools/perf/util/pager.h
+++ b/tools/perf/util/pager.h
@@ -1,6 +1,8 @@
 #ifndef __PERF_PAGER_H
 #define __PERF_PAGER_H
 
+extern void pager_init(const char *pager_env);
+
 extern void setup_pager(void);
 extern int pager_in_use(void);
 
diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c
index de3290b..00a03a9 100644
--- a/tools/perf/util/parse-options.c
+++ b/tools/perf/util/parse-options.c
@@ -9,6 +9,13 @@
 
 static struct strbuf error_buf = STRBUF_INIT;
 
+static const char *cfg_exec_name = "UNDEFINED";
+
+void parse_options_init(const char *exec_name)
+{
+	cfg_exec_name		= exec_name;
+}
+
 static int opterror(const struct option *opt, const char *reason, int flags)
 {
 	if (flags & OPT_SHORT)
@@ -505,7 +512,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>] {",
+			    cfg_exec_name, argv[0]);
 		for (int i = 0; subcommands[i]; i++) {
 			if (i)
 				strbuf_addstr(&buf, "|");
diff --git a/tools/perf/util/parse-options.h b/tools/perf/util/parse-options.h
index a8e407b..2c7ee90 100644
--- a/tools/perf/util/parse-options.h
+++ b/tools/perf/util/parse-options.h
@@ -4,6 +4,8 @@
 #include <linux/kernel.h>
 #include <stdbool.h>
 
+extern void parse_options_init(const char *exec_name);
+
 enum parse_opt_type {
 	/* special types */
 	OPTION_END,
-- 
2.4.3


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

* [PATCH v3 11/17] perf: Remove 'perf' from subcmd function and variable names
  2015-12-14  4:18 [PATCH v3 00/17] perf tools: Move perf subcommand framework to a library Josh Poimboeuf
                   ` (9 preceding siblings ...)
  2015-12-14  4:18 ` [PATCH v3 10/17] perf: Provide subcmd configuration at runtime Josh Poimboeuf
@ 2015-12-14  4:18 ` Josh Poimboeuf
  2015-12-14  4:18 ` [PATCH v3 12/17] perf: Convert parse-options.c internal functions to static Josh Poimboeuf
                   ` (5 subsequent siblings)
  16 siblings, 0 replies; 56+ messages in thread
From: Josh Poimboeuf @ 2015-12-14  4:18 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo
  Cc: linux-kernel, Jiri Olsa, Namhyung Kim

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

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 tools/perf/builtin-help.c     |  2 +-
 tools/perf/builtin-script.c   |  8 ++++----
 tools/perf/perf.c             |  6 +++---
 tools/perf/tests/attr.c       |  2 +-
 tools/perf/util/exec_cmd.c    | 20 ++++++++++----------
 tools/perf/util/exec_cmd.h    | 12 ++++++------
 tools/perf/util/help.c        |  4 ++--
 tools/perf/util/run-command.c |  6 +++---
 tools/perf/util/run-command.h |  4 ++--
 9 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c
index a7d588b..275aa64 100644
--- a/tools/perf/builtin-help.c
+++ b/tools/perf/builtin-help.c
@@ -407,7 +407,7 @@ static int get_html_page_path(struct strbuf *page_path, const char *page)
 #ifndef open_html
 static void open_html(const char *path)
 {
-	execl_perf_cmd("web--browse", "-c", "help.browser", path, NULL);
+	execl_cmd("web--browse", "-c", "help.browser", path, NULL);
 }
 #endif
 
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index d259e9a..571016f 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1408,7 +1408,7 @@ static int list_available_scripts(const struct option *opt __maybe_unused,
 	char first_half[BUFSIZ];
 	char *script_root;
 
-	snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path());
+	snprintf(scripts_path, MAXPATHLEN, "%s/scripts", get_argv_exec_path());
 
 	scripts_dir = opendir(scripts_path);
 	if (!scripts_dir)
@@ -1529,7 +1529,7 @@ int find_scripts(char **scripts_array, char **scripts_path_array)
 	if (!session)
 		return -1;
 
-	snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path());
+	snprintf(scripts_path, MAXPATHLEN, "%s/scripts", get_argv_exec_path());
 
 	scripts_dir = opendir(scripts_path);
 	if (!scripts_dir) {
@@ -1587,7 +1587,7 @@ static char *get_script_path(const char *script_root, const char *suffix)
 	char lang_path[MAXPATHLEN];
 	char *__script_root;
 
-	snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path());
+	snprintf(scripts_path, MAXPATHLEN, "%s/scripts", get_argv_exec_path());
 
 	scripts_dir = opendir(scripts_path);
 	if (!scripts_dir)
@@ -1823,7 +1823,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 		scripting_max_stack = itrace_synth_opts.callchain_sz;
 
 	/* make sure PERF_EXEC_PATH is set for scripts */
-	perf_set_argv_exec_path(perf_exec_path());
+	set_argv_exec_path(get_argv_exec_path());
 
 	if (argc && !script_name && !rec_script_path && !rep_script_path) {
 		int live_pipe[2];
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index 4d94c80..c0fa9a5 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -183,9 +183,9 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
 		if (!prefixcmp(cmd, CMD_EXEC_PATH)) {
 			cmd += strlen(CMD_EXEC_PATH);
 			if (*cmd == '=')
-				perf_set_argv_exec_path(cmd + 1);
+				set_argv_exec_path(cmd + 1);
 			else {
-				puts(perf_exec_path());
+				puts(get_argv_exec_path());
 				exit(0);
 			}
 		} else if (!strcmp(cmd, "--html-path")) {
@@ -539,7 +539,7 @@ int main(int argc, const char **argv)
 	page_size = sysconf(_SC_PAGE_SIZE);
 	cacheline_size = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
 
-	cmd = perf_extract_argv0_path(argv[0]);
+	cmd = extract_argv0_path(argv[0]);
 	if (!cmd)
 		cmd = "perf-help";
 
diff --git a/tools/perf/tests/attr.c b/tools/perf/tests/attr.c
index b66730e..6337f1c 100644
--- a/tools/perf/tests/attr.c
+++ b/tools/perf/tests/attr.c
@@ -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/util/exec_cmd.c b/tools/perf/util/exec_cmd.c
index 84f9dc5..1e8d31f 100644
--- a/tools/perf/util/exec_cmd.c
+++ b/tools/perf/util/exec_cmd.c
@@ -36,7 +36,7 @@ char *system_path(const char *path)
 	return (char *)path;
 }
 
-const char *perf_extract_argv0_path(const char *argv0)
+const char *extract_argv0_path(const char *argv0)
 {
 	const char *slash;
 
@@ -55,7 +55,7 @@ const char *perf_extract_argv0_path(const char *argv0)
 	return argv0;
 }
 
-void perf_set_argv_exec_path(const char *exec_path)
+void set_argv_exec_path(const char *exec_path)
 {
 	argv_exec_path = exec_path;
 	/*
@@ -65,8 +65,8 @@ void perf_set_argv_exec_path(const char *exec_path)
 }
 
 
-/* Returns the highest-priority, location to look for perf programs. */
-char *perf_exec_path(void)
+/* Returns the highest-priority location to look for subprograms. */
+char *get_argv_exec_path(void)
 {
 	char *env;
 
@@ -96,7 +96,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);
@@ -112,7 +112,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;
@@ -128,8 +128,8 @@ static const char **prepare_perf_cmd(const char **argv)
 	return nargv;
 }
 
-int execv_perf_cmd(const char **argv) {
-	const char **nargv = prepare_perf_cmd(argv);
+int execv_cmd(const char **argv) {
+	const char **nargv = prepare_exec_cmd(argv);
 
 	/* execvp() can only ever return if it fails */
 	execvp(cfg_exec_name, (char **)nargv);
@@ -139,7 +139,7 @@ int execv_perf_cmd(const char **argv) {
 }
 
 
-int execl_perf_cmd(const char *cmd,...)
+int execl_cmd(const char *cmd,...)
 {
 	int argc;
 	const char *argv[MAX_ARGS + 1];
@@ -159,5 +159,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/perf/util/exec_cmd.h
index fd4434e..f1bd343 100644
--- a/tools/perf/util/exec_cmd.h
+++ b/tools/perf/util/exec_cmd.h
@@ -4,13 +4,13 @@
 extern void exec_cmd_init(const char *exec_name, const char *prefix,
 			  const char *exec_path, const char *exec_path_env);
 
-extern void perf_set_argv_exec_path(const char *exec_path);
-extern const char *perf_extract_argv0_path(const char *path);
+extern void set_argv_exec_path(const char *exec_path);
+extern const char *extract_argv0_path(const char *path);
 extern void setup_path(void);
-extern int execv_perf_cmd(const char **argv); /* NULL terminated */
-extern int execl_perf_cmd(const char *cmd, ...);
-/* perf_exec_path and system_path return malloc'd string, caller must free it */
-extern char *perf_exec_path(void);
+extern int execv_cmd(const char **argv); /* NULL terminated */
+extern int execl_cmd(const char *cmd, ...);
+/* get_argv_exec_path and system_path return malloc'd string, caller must free it */
+extern char *get_argv_exec_path(void);
 extern char *system_path(const char *path);
 
 #endif /* __PERF_EXEC_CMD_H */
diff --git a/tools/perf/util/help.c b/tools/perf/util/help.c
index 8d74f7d..89fc81b 100644
--- a/tools/perf/util/help.c
+++ b/tools/perf/util/help.c
@@ -157,7 +157,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);
@@ -202,7 +202,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/run-command.c b/tools/perf/util/run-command.c
index 34622b5..910c0f6 100644
--- a/tools/perf/util/run-command.c
+++ b/tools/perf/util/run-command.c
@@ -112,8 +112,8 @@ int start_command(struct child_process *cmd)
 		}
 		if (cmd->preexec_cb)
 			cmd->preexec_cb();
-		if (cmd->perf_cmd) {
-			execv_perf_cmd(cmd->argv);
+		if (cmd->exec_cmd) {
+			execv_cmd(cmd->argv);
 		} else {
 			execvp(cmd->argv[0], (char *const*) cmd->argv);
 		}
@@ -207,7 +207,7 @@ static void prepare_run_command_v_opt(struct child_process *cmd,
 	memset(cmd, 0, sizeof(*cmd));
 	cmd->argv = argv;
 	cmd->no_stdin = opt & RUN_COMMAND_NO_STDIN ? 1 : 0;
-	cmd->perf_cmd = opt & RUN_PERF_CMD ? 1 : 0;
+	cmd->exec_cmd = opt & RUN_EXEC_CMD ? 1 : 0;
 	cmd->stdout_to_stderr = opt & RUN_COMMAND_STDOUT_TO_STDERR ? 1 : 0;
 }
 
diff --git a/tools/perf/util/run-command.h b/tools/perf/util/run-command.h
index 1ef264d..cf7d655 100644
--- a/tools/perf/util/run-command.h
+++ b/tools/perf/util/run-command.h
@@ -41,7 +41,7 @@ struct child_process {
 	unsigned no_stdin:1;
 	unsigned no_stdout:1;
 	unsigned no_stderr:1;
-	unsigned perf_cmd:1; /* if this is to be perf sub-command */
+	unsigned exec_cmd:1; /* if this is to be external sub-command */
 	unsigned stdout_to_stderr:1;
 	void (*preexec_cb)(void);
 };
@@ -51,7 +51,7 @@ int finish_command(struct child_process *);
 int run_command(struct child_process *);
 
 #define RUN_COMMAND_NO_STDIN 1
-#define RUN_PERF_CMD	     2	/*If this is to be perf sub-command */
+#define RUN_EXEC_CMD	     2	/*If this is to be external sub-command */
 #define RUN_COMMAND_STDOUT_TO_STDERR 4
 int run_command_v_opt(const char **argv, int opt);
 
-- 
2.4.3


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

* [PATCH v3 12/17] perf: Convert parse-options.c internal functions to static
  2015-12-14  4:18 [PATCH v3 00/17] perf tools: Move perf subcommand framework to a library Josh Poimboeuf
                   ` (10 preceding siblings ...)
  2015-12-14  4:18 ` [PATCH v3 11/17] perf: Remove 'perf' from subcmd function and variable names Josh Poimboeuf
@ 2015-12-14  4:18 ` Josh Poimboeuf
  2015-12-18  8:50   ` [tip:perf/core] perf tools: " tip-bot for Josh Poimboeuf
  2015-12-14  4:18 ` [PATCH v3 13/17] perf: Document the fact that parse_options*() may exit Josh Poimboeuf
                   ` (4 subsequent siblings)
  16 siblings, 1 reply; 56+ messages in thread
From: Josh Poimboeuf @ 2015-12-14  4:18 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo
  Cc: linux-kernel, Jiri Olsa, Namhyung Kim

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 tools/perf/util/parse-options.c | 18 +++++++++---------
 tools/perf/util/parse-options.h |  9 ---------
 2 files changed, 9 insertions(+), 18 deletions(-)

diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c
index 00a03a9..ac49525 100644
--- a/tools/perf/util/parse-options.c
+++ b/tools/perf/util/parse-options.c
@@ -367,8 +367,8 @@ static void check_typos(const char *arg, const struct option *options)
 	}
 }
 
-void parse_options_start(struct parse_opt_ctx_t *ctx,
-			 int argc, const char **argv, int flags)
+static void parse_options_start(struct parse_opt_ctx_t *ctx,
+				int argc, const char **argv, int flags)
 {
 	memset(ctx, 0, sizeof(*ctx));
 	ctx->argc = argc - 1;
@@ -385,9 +385,9 @@ static int usage_with_options_internal(const char * const *,
 				       const struct option *, int,
 				       struct parse_opt_ctx_t *);
 
-int parse_options_step(struct parse_opt_ctx_t *ctx,
-		       const struct option *options,
-		       const char * const usagestr[])
+static int parse_options_step(struct parse_opt_ctx_t *ctx,
+			      const struct option *options,
+			      const char * const usagestr[])
 {
 	int internal_help = !(ctx->flags & PARSE_OPT_NO_INTERNAL_HELP);
 	int excl_short_opt = 1;
@@ -496,7 +496,7 @@ exclusive:
 	return PARSE_OPT_HELP;
 }
 
-int parse_options_end(struct parse_opt_ctx_t *ctx)
+static int parse_options_end(struct parse_opt_ctx_t *ctx)
 {
 	memmove(ctx->out + ctx->cpidx, ctx->argv, ctx->argc * sizeof(*ctx->out));
 	ctx->out[ctx->cpidx + ctx->argc] = NULL;
@@ -725,9 +725,9 @@ static bool option__in_argv(const struct option *opt, const struct parse_opt_ctx
 	return false;
 }
 
-int usage_with_options_internal(const char * const *usagestr,
-				const struct option *opts, int full,
-				struct parse_opt_ctx_t *ctx)
+static int usage_with_options_internal(const char * const *usagestr,
+				       const struct option *opts, int full,
+				       struct parse_opt_ctx_t *ctx)
 {
 	struct option *ordered;
 
diff --git a/tools/perf/util/parse-options.h b/tools/perf/util/parse-options.h
index 2c7ee90..b04190a 100644
--- a/tools/perf/util/parse-options.h
+++ b/tools/perf/util/parse-options.h
@@ -197,15 +197,6 @@ extern int parse_options_usage(const char * const *usagestr,
 			       const char *optstr,
 			       bool short_opt);
 
-extern void parse_options_start(struct parse_opt_ctx_t *ctx,
-				int argc, const char **argv, int flags);
-
-extern int parse_options_step(struct parse_opt_ctx_t *ctx,
-			      const struct option *options,
-			      const char * const usagestr[]);
-
-extern int parse_options_end(struct parse_opt_ctx_t *ctx);
-
 
 /*----- some often used options -----*/
 extern int parse_opt_abbrev_cb(const struct option *, const char *, int);
-- 
2.4.3


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

* [PATCH v3 13/17] perf: Document the fact that parse_options*() may exit
  2015-12-14  4:18 [PATCH v3 00/17] perf tools: Move perf subcommand framework to a library Josh Poimboeuf
                   ` (11 preceding siblings ...)
  2015-12-14  4:18 ` [PATCH v3 12/17] perf: Convert parse-options.c internal functions to static Josh Poimboeuf
@ 2015-12-14  4:18 ` Josh Poimboeuf
  2015-12-14  4:18 ` [PATCH v3 14/17] perf: Remove subcmd dependencies on strbuf Josh Poimboeuf
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 56+ messages in thread
From: Josh Poimboeuf @ 2015-12-14  4:18 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo
  Cc: linux-kernel, Jiri Olsa, Namhyung Kim

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 tools/perf/util/parse-options.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/perf/util/parse-options.h b/tools/perf/util/parse-options.h
index b04190a..fff954e 100644
--- a/tools/perf/util/parse-options.h
+++ b/tools/perf/util/parse-options.h
@@ -151,6 +151,9 @@ struct option {
 /* parse_options() will filter out the processed options and leave the
  * non-option argments in argv[].
  * Returns the number of arguments left in argv[].
+ *
+ * NOTE: parse_options() and parse_options_subcommand() may call exit() in the
+ * case of an error (or for 'special' options like --list-cmds or --list-opts).
  */
 extern int parse_options(int argc, const char **argv,
                          const struct option *options,
-- 
2.4.3


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

* [PATCH v3 14/17] perf: Remove subcmd dependencies on strbuf
  2015-12-14  4:18 [PATCH v3 00/17] perf tools: Move perf subcommand framework to a library Josh Poimboeuf
                   ` (12 preceding siblings ...)
  2015-12-14  4:18 ` [PATCH v3 13/17] perf: Document the fact that parse_options*() may exit Josh Poimboeuf
@ 2015-12-14  4:18 ` Josh Poimboeuf
  2015-12-14 10:25   ` Jiri Olsa
  2015-12-14 15:44   ` Arnaldo Carvalho de Melo
  2015-12-14  4:18 ` [PATCH v3 15/17] perf: Finalize subcmd independence Josh Poimboeuf
                   ` (2 subsequent siblings)
  16 siblings, 2 replies; 56+ messages in thread
From: Josh Poimboeuf @ 2015-12-14  4:18 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo
  Cc: linux-kernel, Jiri Olsa, Namhyung Kim

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

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 tools/perf/util/exec_cmd.c      | 27 +++++++++++++-------------
 tools/perf/util/help.c          | 14 ++++++--------
 tools/perf/util/parse-options.c | 42 +++++++++++++++++++++--------------------
 tools/perf/util/subcmd-util.h   | 24 +++++++++++++++++++++++
 4 files changed, 66 insertions(+), 41 deletions(-)
 create mode 100644 tools/perf/util/subcmd-util.h

diff --git a/tools/perf/util/exec_cmd.c b/tools/perf/util/exec_cmd.c
index 1e8d31f..d4f6dda 100644
--- a/tools/perf/util/exec_cmd.c
+++ b/tools/perf/util/exec_cmd.c
@@ -3,6 +3,7 @@
 #include "quote.h"
 
 #include <string.h>
+#include "subcmd-util.h"
 
 #define MAX_ARGS	32
 #define UNDEFINED	"UNDEFINED"
@@ -26,14 +27,14 @@ void exec_cmd_init(const char *exec_name, const char *prefix,
 
 char *system_path(const char *path)
 {
-	struct strbuf d = STRBUF_INIT;
+	char *buf = NULL;
 
 	if (is_absolute_path(path))
 		return strdup(path);
 
-	strbuf_addf(&d, "%s/%s", cfg_prefix, path);
-	path = strbuf_detach(&d, NULL);
-	return (char *)path;
+	astrcatf(&buf, "%s/%s", cfg_prefix, path);
+
+	return buf;
 }
 
 const char *extract_argv0_path(const char *argv0)
@@ -80,22 +81,22 @@ char *get_argv_exec_path(void)
 	return system_path(cfg_exec_path);
 }
 
-static void add_path(struct strbuf *out, const char *path)
+static void add_path(char **out, const char *path)
 {
 	if (path && *path) {
 		if (is_absolute_path(path))
-			strbuf_addstr(out, path);
+			astrcat(out, path);
 		else
-			strbuf_addstr(out, make_nonrelative_path(path));
+			astrcat(out, make_nonrelative_path(path));
 
-		strbuf_addch(out, PATH_SEP);
+		astrcat(out, ":");
 	}
 }
 
 void setup_path(void)
 {
 	const char *old_path = getenv("PATH");
-	struct strbuf new_path = STRBUF_INIT;
+	char *new_path = NULL;
 	char *tmp = get_argv_exec_path();
 
 	add_path(&new_path, tmp);
@@ -103,13 +104,13 @@ void setup_path(void)
 	free(tmp);
 
 	if (old_path)
-		strbuf_addstr(&new_path, old_path);
+		astrcat(&new_path, old_path);
 	else
-		strbuf_addstr(&new_path, "/usr/local/bin:/usr/bin:/bin");
+		astrcat(&new_path, "/usr/local/bin:/usr/bin:/bin");
 
-	setenv("PATH", new_path.buf, 1);
+	setenv("PATH", new_path, 1);
 
-	strbuf_release(&new_path);
+	free(new_path);
 }
 
 static const char **prepare_exec_cmd(const char **argv)
diff --git a/tools/perf/util/help.c b/tools/perf/util/help.c
index 89fc81b..303a347 100644
--- a/tools/perf/util/help.c
+++ b/tools/perf/util/help.c
@@ -2,6 +2,7 @@
 #include "../builtin.h"
 #include "exec_cmd.h"
 #include "help.h"
+#include "subcmd-util.h"
 
 void add_cmdname(struct cmdnames *cmds, const char *name, size_t len)
 {
@@ -119,8 +120,7 @@ static void list_commands_in_dir(struct cmdnames *cmds,
 	int prefix_len;
 	DIR *dir = opendir(path);
 	struct dirent *de;
-	struct strbuf buf = STRBUF_INIT;
-	int len;
+	char *buf = NULL;
 
 	if (!dir)
 		return;
@@ -128,8 +128,7 @@ static void list_commands_in_dir(struct cmdnames *cmds,
 		prefix = "perf-";
 	prefix_len = strlen(prefix);
 
-	strbuf_addf(&buf, "%s/", path);
-	len = buf.len;
+	astrcatf(&buf, "%s/", path);
 
 	while ((de = readdir(dir)) != NULL) {
 		int entlen;
@@ -137,9 +136,8 @@ static void list_commands_in_dir(struct cmdnames *cmds,
 		if (prefixcmp(de->d_name, prefix))
 			continue;
 
-		strbuf_setlen(&buf, len);
-		strbuf_addstr(&buf, de->d_name);
-		if (!is_executable(buf.buf))
+		astrcat(&buf, de->d_name);
+		if (!is_executable(buf))
 			continue;
 
 		entlen = strlen(de->d_name) - prefix_len;
@@ -149,7 +147,7 @@ static void list_commands_in_dir(struct cmdnames *cmds,
 		add_cmdname(cmds, de->d_name + prefix_len, entlen);
 	}
 	closedir(dir);
-	strbuf_release(&buf);
+	free(buf);
 }
 
 void load_command_list(const char *prefix,
diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c
index ac49525..0189f78 100644
--- a/tools/perf/util/parse-options.c
+++ b/tools/perf/util/parse-options.c
@@ -1,4 +1,5 @@
 #include "util.h"
+#include "subcmd-util.h"
 #include "parse-options.h"
 #include "cache.h"
 #include "header.h"
@@ -7,7 +8,7 @@
 #define OPT_SHORT 1
 #define OPT_UNSET 2
 
-static struct strbuf error_buf = STRBUF_INIT;
+char *error_buf;
 
 static const char *cfg_exec_name = "UNDEFINED";
 
@@ -510,19 +511,18 @@ int parse_options_subcommand(int argc, const char **argv, const struct option *o
 
 	/* build usage string if it's not provided */
 	if (subcommands && !usagestr[0]) {
-		struct strbuf buf = STRBUF_INIT;
+		char *buf = NULL;
+
+		astrcatf(&buf, "%s %s [<options>] {", cfg_exec_name, argv[0]);
 
-		strbuf_addf(&buf, "%s %s [<options>] {",
-			    cfg_exec_name, argv[0]);
 		for (int i = 0; subcommands[i]; i++) {
 			if (i)
-				strbuf_addstr(&buf, "|");
-			strbuf_addstr(&buf, subcommands[i]);
+				astrcat(&buf, "|");
+			astrcat(&buf, subcommands[i]);
 		}
-		strbuf_addstr(&buf, "}");
+		astrcat(&buf, "}");
 
-		usagestr[0] = strdup(buf.buf);
-		strbuf_release(&buf);
+		usagestr[0] = buf;
 	}
 
 	parse_options_start(&ctx, argc, argv, flags);
@@ -547,13 +547,11 @@ int parse_options_subcommand(int argc, const char **argv, const struct option *o
 		putchar('\n');
 		exit(130);
 	default: /* PARSE_OPT_UNKNOWN */
-		if (ctx.argv[0][1] == '-') {
-			strbuf_addf(&error_buf, "unknown option `%s'",
-				    ctx.argv[0] + 2);
-		} else {
-			strbuf_addf(&error_buf, "unknown switch `%c'",
-				    *ctx.opt);
-		}
+		if (ctx.argv[0][1] == '-')
+			astrcatf(&error_buf, "unknown option `%s'",
+				 ctx.argv[0] + 2);
+		else
+			astrcatf(&error_buf, "unknown switch `%c'", *ctx.opt);
 		usage_with_options(usagestr, options);
 	}
 
@@ -736,9 +734,9 @@ static int usage_with_options_internal(const char * const *usagestr,
 
 	setup_pager();
 
-	if (strbuf_avail(&error_buf)) {
-		fprintf(stderr, "  Error: %s\n", error_buf.buf);
-		strbuf_release(&error_buf);
+	if (error_buf) {
+		fprintf(stderr, "  Error: %s\n", error_buf);
+		zfree(&error_buf);
 	}
 
 	fprintf(stderr, "\n Usage: %s\n", *usagestr++);
@@ -782,11 +780,15 @@ void usage_with_options_msg(const char * const *usagestr,
 			    const struct option *opts, const char *fmt, ...)
 {
 	va_list ap;
+	char *tmp = error_buf;
 
 	va_start(ap, fmt);
-	strbuf_addv(&error_buf, fmt, ap);
+	if (vasprintf(&error_buf, fmt, ap) == -1)
+		die("vasprintf failed");
 	va_end(ap);
 
+	free(tmp);
+
 	usage_with_options_internal(usagestr, opts, 0, NULL);
 	exit(129);
 }
diff --git a/tools/perf/util/subcmd-util.h b/tools/perf/util/subcmd-util.h
new file mode 100644
index 0000000..98fb9f9
--- /dev/null
+++ b/tools/perf/util/subcmd-util.h
@@ -0,0 +1,24 @@
+#ifndef __PERF_SUBCMD_UTIL_H
+#define __PERF_SUBCMD_UTIL_H
+
+#include <stdio.h>
+
+#define astrcatf(out, fmt, ...)						\
+({									\
+	char *tmp = *(out);						\
+	if (asprintf((out), "%s" fmt, tmp ?: "", ## __VA_ARGS__) == -1)	\
+		die("asprintf failed");					\
+	free(tmp);							\
+})
+
+static inline void astrcat(char **out, const char *add)
+{
+	char *tmp = *out;
+
+	if (asprintf(out, "%s%s", tmp ?: "", add) == -1)
+		die("asprintf failed");
+
+	free(tmp);
+}
+
+#endif /* __PERF_SUBCMD_UTIL_H */
-- 
2.4.3


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

* [PATCH v3 15/17] perf: Finalize subcmd independence
  2015-12-14  4:18 [PATCH v3 00/17] perf tools: Move perf subcommand framework to a library Josh Poimboeuf
                   ` (13 preceding siblings ...)
  2015-12-14  4:18 ` [PATCH v3 14/17] perf: Remove subcmd dependencies on strbuf Josh Poimboeuf
@ 2015-12-14  4:18 ` Josh Poimboeuf
  2015-12-14 10:32   ` Jiri Olsa
  2015-12-14  4:18 ` [PATCH v3 16/17] perf subcmd: Create subcmd library Josh Poimboeuf
  2015-12-14  4:18 ` [PATCH v3 17/17] tools subcmd: Rename subcmd header include guards Josh Poimboeuf
  16 siblings, 1 reply; 56+ messages in thread
From: Josh Poimboeuf @ 2015-12-14  4:18 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo
  Cc: linux-kernel, Jiri Olsa, Namhyung Kim

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

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 tools/perf/util/exec_cmd.c      | 75 +++++++++++++++++++++++++++++++++++++----
 tools/perf/util/help.c          | 47 +++++++++++++++++++++++---
 tools/perf/util/help.h          |  4 ++-
 tools/perf/util/pager.c         |  7 +++-
 tools/perf/util/parse-options.c | 68 +++++++++++++++++++++++--------------
 tools/perf/util/parse-options.h |  2 +-
 tools/perf/util/run-command.c   | 16 ++++++---
 tools/perf/util/run-command.h   |  2 ++
 tools/perf/util/sigchain.c      |  3 +-
 tools/perf/util/subcmd-util.h   | 67 ++++++++++++++++++++++++++++++++++++
 tools/perf/util/util.h          | 14 --------
 11 files changed, 247 insertions(+), 58 deletions(-)

diff --git a/tools/perf/util/exec_cmd.c b/tools/perf/util/exec_cmd.c
index d4f6dda..4a9292d 100644
--- a/tools/perf/util/exec_cmd.c
+++ b/tools/perf/util/exec_cmd.c
@@ -1,11 +1,15 @@
-#include "cache.h"
-#include "exec_cmd.h"
-#include "quote.h"
-
+#include <linux/compiler.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
 #include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
 #include "subcmd-util.h"
+#include "exec_cmd.h"
 
 #define MAX_ARGS	32
+#define PATH_MAX	4096
 #define UNDEFINED	"UNDEFINED"
 
 static const char *argv_exec_path;
@@ -25,6 +29,63 @@ void exec_cmd_init(const char *exec_name, const char *prefix,
 	cfg_exec_path_env	= exec_path_env;
 }
 
+#define is_dir_sep(c) ((c) == '/')
+
+static size_t 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 int is_absolute_path(const char *path)
+{
+	return path[0] == '/';
+}
+
+static const char *get_pwd_cwd(void)
+{
+	static char cwd[PATH_MAX + 1];
+	char *pwd;
+	struct stat cwd_stat, pwd_stat;
+	if (getcwd(cwd, PATH_MAX) == NULL)
+		return NULL;
+	pwd = getenv("PWD");
+	if (pwd && strcmp(pwd, cwd)) {
+		stat(cwd, &cwd_stat);
+		if (!stat(pwd, &pwd_stat) &&
+		    pwd_stat.st_dev == cwd_stat.st_dev &&
+		    pwd_stat.st_ino == cwd_stat.st_ino) {
+			strlcpy(cwd, pwd, PATH_MAX);
+		}
+	}
+	return cwd;
+}
+
+static const char *make_nonrelative_path(const char *path)
+{
+	static char buf[PATH_MAX + 1];
+
+	if (is_absolute_path(path)) {
+		if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX)
+			die("Too long path: %.*s", 60, path);
+	} else {
+		const char *cwd = get_pwd_cwd();
+		if (!cwd)
+			die("Cannot determine the current working directory");
+		if (snprintf(buf, PATH_MAX, "%s/%s", cwd, path) >= PATH_MAX)
+			die("Too long path: %.*s", 60, path);
+	}
+	return buf;
+}
+
 char *system_path(const char *path)
 {
 	char *buf = NULL;
@@ -156,8 +217,10 @@ int execl_cmd(const char *cmd,...)
 			break;
 	}
 	va_end(param);
-	if (MAX_ARGS <= argc)
-		return error("too many args to run %s", cmd);
+	if (MAX_ARGS <= argc) {
+		fprintf(stderr, " Error: too many args to run %s\n", cmd);
+		return -1;
+	}
 
 	argv[argc] = NULL;
 	return execv_cmd(argv);
diff --git a/tools/perf/util/help.c b/tools/perf/util/help.c
index 303a347..8169480 100644
--- a/tools/perf/util/help.c
+++ b/tools/perf/util/help.c
@@ -1,8 +1,15 @@
-#include "cache.h"
-#include "../builtin.h"
-#include "exec_cmd.h"
-#include "help.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <termios.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <dirent.h>
 #include "subcmd-util.h"
+#include "help.h"
+#include "exec_cmd.h"
 
 void add_cmdname(struct cmdnames *cmds, const char *name, size_t len)
 {
@@ -70,6 +77,28 @@ void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes)
 	cmds->cnt = cj;
 }
 
+static 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;
+}
+
 static void pretty_print_string_list(struct cmdnames *cmds, int longest)
 {
 	int cols = 1, rows;
@@ -113,6 +142,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)
@@ -168,7 +205,7 @@ void load_command_list(const char *prefix,
 		char *paths, *path, *colon;
 		path = paths = strdup(env_path);
 		while (1) {
-			if ((colon = strchr(path, PATH_SEP)))
+			if ((colon = strchr(path, ':')))
 				*colon = 0;
 			if (!exec_path || strcmp(path, exec_path))
 				list_commands_in_dir(other_cmds, path, prefix);
diff --git a/tools/perf/util/help.h b/tools/perf/util/help.h
index 14851b0..096c8bc 100644
--- a/tools/perf/util/help.h
+++ b/tools/perf/util/help.h
@@ -1,12 +1,14 @@
 #ifndef __PERF_HELP_H
 #define __PERF_HELP_H
 
+#include <sys/types.h>
+
 struct cmdnames {
 	size_t alloc;
 	size_t cnt;
 	struct cmdname {
 		size_t len; /* also used for similarity index in help.c */
-		char name[FLEX_ARRAY];
+		char name[];
 	} **names;
 };
 
diff --git a/tools/perf/util/pager.c b/tools/perf/util/pager.c
index f6153a1..ecd1b41 100644
--- a/tools/perf/util/pager.c
+++ b/tools/perf/util/pager.c
@@ -1,4 +1,9 @@
-#include "cache.h"
+#include <sys/select.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+#include "pager.h"
 #include "run-command.h"
 #include "sigchain.h"
 
diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c
index 0189f78..cb8f412 100644
--- a/tools/perf/util/parse-options.c
+++ b/tools/perf/util/parse-options.c
@@ -1,13 +1,18 @@
-#include "util.h"
+#include <linux/compiler.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <ctype.h>
 #include "subcmd-util.h"
 #include "parse-options.h"
-#include "cache.h"
-#include "header.h"
-#include <linux/string.h>
+#include "pager.h"
 
 #define OPT_SHORT 1
 #define OPT_UNSET 2
 
+typedef uint64_t u64;
+
 char *error_buf;
 
 static const char *cfg_exec_name = "UNDEFINED";
@@ -20,10 +25,19 @@ void parse_options_init(const char *exec_name)
 static int opterror(const struct option *opt, const char *reason, int flags)
 {
 	if (flags & OPT_SHORT)
-		return error("switch `%c' %s", opt->short_name, reason);
-	if (flags & OPT_UNSET)
-		return error("option `no-%s' %s", opt->long_name, reason);
-	return error("option `%s' %s", opt->long_name, reason);
+		fprintf(stderr, " Error: switch `%c' %s", opt->short_name, reason);
+	else if (flags & OPT_UNSET)
+		fprintf(stderr, " Error: option `no-%s' %s", opt->long_name, reason);
+	else
+		fprintf(stderr, " Error: option `%s' %s", opt->long_name, reason);
+
+	return -1;
+}
+
+static const char *skip_prefix(const char *str, const char *prefix)
+{
+	size_t len = strlen(prefix);
+	return strncmp(str, prefix, len) ? NULL : str + len;
 }
 
 static int get_arg(struct parse_opt_ctx_t *p, const struct option *opt,
@@ -63,11 +77,11 @@ static int get_value(struct parse_opt_ctx_t *p,
 
 			if (((flags & OPT_SHORT) && p->excl_opt->short_name) ||
 			    p->excl_opt->long_name == NULL) {
-				scnprintf(msg, sizeof(msg), "cannot be used with switch `%c'",
-					  p->excl_opt->short_name);
+				snprintf(msg, sizeof(msg), "cannot be used with switch `%c'",
+					 p->excl_opt->short_name);
 			} else {
-				scnprintf(msg, sizeof(msg), "cannot be used with %s",
-					  p->excl_opt->long_name);
+				snprintf(msg, sizeof(msg), "cannot be used with %s",
+					 p->excl_opt->long_name);
 			}
 			opterror(opt, msg, flags);
 			return -3;
@@ -335,14 +349,16 @@ match:
 		return get_value(p, options, flags);
 	}
 
-	if (ambiguous_option)
-		return error("Ambiguous option: %s "
-			"(could be --%s%s or --%s%s)",
-			arg,
-			(ambiguous_flags & OPT_UNSET) ?  "no-" : "",
-			ambiguous_option->long_name,
-			(abbrev_flags & OPT_UNSET) ?  "no-" : "",
-			abbrev_option->long_name);
+	if (ambiguous_option) {
+		 fprintf(stderr,
+			 " Error: Ambiguous option: %s (could be --%s%s or --%s%s)",
+			 arg,
+			 (ambiguous_flags & OPT_UNSET) ?  "no-" : "",
+			 ambiguous_option->long_name,
+			 (abbrev_flags & OPT_UNSET) ?  "no-" : "",
+			 abbrev_option->long_name);
+		 return -1;
+	}
 	if (abbrev_option)
 		return get_value(p, abbrev_option, abbrev_flags);
 	return -2;
@@ -354,7 +370,7 @@ static void check_typos(const char *arg, const struct option *options)
 		return;
 
 	if (!prefixcmp(arg, "no-")) {
-		error ("did you mean `--%s` (with two dashes ?)", arg);
+		fprintf(stderr, " Error: did you mean `--%s` (with two dashes ?)", arg);
 		exit(129);
 	}
 
@@ -362,7 +378,7 @@ static void check_typos(const char *arg, const struct option *options)
 		if (!options->long_name)
 			continue;
 		if (!prefixcmp(options->long_name, arg)) {
-			error ("did you mean `--%s` (with two dashes ?)", arg);
+			fprintf(stderr, " Error: did you mean `--%s` (with two dashes ?)", arg);
 			exit(129);
 		}
 	}
@@ -676,16 +692,18 @@ static int option__cmp(const void *va, const void *vb)
 
 static struct option *options__order(const struct option *opts)
 {
-	int nr_opts = 0;
+	int nr_opts = 0, len;
 	const struct option *o = opts;
 	struct option *ordered;
 
 	for (o = opts; o->type != OPTION_END; o++)
 		++nr_opts;
 
-	ordered = memdup(opts, sizeof(*o) * (nr_opts + 1));
-	if (ordered == NULL)
+	len = sizeof(*o) * (nr_opts + 1);
+	ordered = malloc(len);
+	if (!ordered)
 		goto out;
+	memcpy(ordered, opts, len);
 
 	qsort(ordered, nr_opts, sizeof(*o), option__cmp);
 out:
diff --git a/tools/perf/util/parse-options.h b/tools/perf/util/parse-options.h
index fff954e..7f0c88d 100644
--- a/tools/perf/util/parse-options.h
+++ b/tools/perf/util/parse-options.h
@@ -1,8 +1,8 @@
 #ifndef __PERF_PARSE_OPTIONS_H
 #define __PERF_PARSE_OPTIONS_H
 
-#include <linux/kernel.h>
 #include <stdbool.h>
+#include <stdint.h>
 
 extern void parse_options_init(const char *exec_name);
 
diff --git a/tools/perf/util/run-command.c b/tools/perf/util/run-command.c
index 910c0f6..fed37d6 100644
--- a/tools/perf/util/run-command.c
+++ b/tools/perf/util/run-command.c
@@ -1,7 +1,15 @@
-#include "cache.h"
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/wait.h>
+#include "subcmd-util.h"
 #include "run-command.h"
 #include "exec_cmd.h"
-#include "debug.h"
+
+#define STRERR_BUFSIZE 128
 
 static inline void close_pair(int fd[2])
 {
@@ -164,8 +172,8 @@ static int wait_or_whine(pid_t pid)
 		if (waiting < 0) {
 			if (errno == EINTR)
 				continue;
-			error("waitpid failed (%s)",
-			      strerror_r(errno, sbuf, sizeof(sbuf)));
+			fprintf(stderr, " Error: waitpid failed (%s)",
+				strerror_r(errno, sbuf, sizeof(sbuf)));
 			return -ERR_RUN_COMMAND_WAITPID;
 		}
 		if (waiting != pid)
diff --git a/tools/perf/util/run-command.h b/tools/perf/util/run-command.h
index cf7d655..4a55393 100644
--- a/tools/perf/util/run-command.h
+++ b/tools/perf/util/run-command.h
@@ -1,6 +1,8 @@
 #ifndef __PERF_RUN_COMMAND_H
 #define __PERF_RUN_COMMAND_H
 
+#include <unistd.h>
+
 enum {
 	ERR_RUN_COMMAND_FORK = 10000,
 	ERR_RUN_COMMAND_EXEC,
diff --git a/tools/perf/util/sigchain.c b/tools/perf/util/sigchain.c
index ba785e9..3537c34 100644
--- a/tools/perf/util/sigchain.c
+++ b/tools/perf/util/sigchain.c
@@ -1,5 +1,6 @@
+#include <signal.h>
+#include "subcmd-util.h"
 #include "sigchain.h"
-#include "cache.h"
 
 #define SIGCHAIN_MAX_SIGNALS 32
 
diff --git a/tools/perf/util/subcmd-util.h b/tools/perf/util/subcmd-util.h
index 98fb9f9..321aeb1 100644
--- a/tools/perf/util/subcmd-util.h
+++ b/tools/perf/util/subcmd-util.h
@@ -1,8 +1,66 @@
 #ifndef __PERF_SUBCMD_UTIL_H
 #define __PERF_SUBCMD_UTIL_H
 
+#include <stdarg.h>
+#include <stdlib.h>
 #include <stdio.h>
 
+#define NORETURN __attribute__((__noreturn__))
+
+static inline void report(const char *prefix, const char *err, va_list params)
+{
+	char msg[1024];
+	vsnprintf(msg, sizeof(msg), err, params);
+	fprintf(stderr, " %s%s\n", prefix, msg);
+}
+
+static NORETURN inline void die(const char *err, ...)
+{
+	va_list params;
+
+	va_start(params, err);
+	report(" Fatal: ", err, params);
+	exit(128);
+	va_end(params);
+}
+
+#define zfree(ptr) ({ free(*ptr); *ptr = NULL; })
+
+#define alloc_nr(x) (((x)+16)*3/2)
+
+/*
+ * Realloc the buffer pointed at by variable 'x' so that it can hold
+ * at least 'nr' entries; the number of entries currently allocated
+ * is 'alloc', using the standard growing factor alloc_nr() macro.
+ *
+ * DO NOT USE any expression with side-effect for 'x' or 'alloc'.
+ */
+#define ALLOC_GROW(x, nr, alloc) \
+	do { \
+		if ((nr) > alloc) { \
+			if (alloc_nr(alloc) < (nr)) \
+				alloc = (nr); \
+			else \
+				alloc = alloc_nr(alloc); \
+			x = xrealloc((x), alloc * sizeof(*(x))); \
+		} \
+	} while(0)
+
+static inline void *xrealloc(void *ptr, size_t size)
+{
+	void *ret = realloc(ptr, size);
+	if (!ret && !size)
+		ret = realloc(ptr, 1);
+	if (!ret) {
+		ret = realloc(ptr, size);
+		if (!ret && !size)
+			ret = realloc(ptr, 1);
+		if (!ret)
+			die("Out of memory, realloc failed");
+	}
+	return ret;
+}
+
 #define astrcatf(out, fmt, ...)						\
 ({									\
 	char *tmp = *(out);						\
@@ -21,4 +79,13 @@ static inline void astrcat(char **out, const char *add)
 	free(tmp);
 }
 
+static inline int prefixcmp(const char *str, const char *prefix)
+{
+	for (; ; str++, prefix++)
+		if (!*prefix)
+			return 0;
+		else if (*str != *prefix)
+			return (unsigned char)*prefix - (unsigned char)*str;
+}
+
 #endif /* __PERF_SUBCMD_UTIL_H */
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 150858f..4b519c5 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -151,12 +151,6 @@ extern void set_warning_routine(void (*routine)(const char *err, va_list params)
 extern int prefixcmp(const char *str, const char *prefix);
 extern void set_buildid_dir(const char *dir);
 
-static inline const char *skip_prefix(const char *str, const char *prefix)
-{
-	size_t len = strlen(prefix);
-	return strncmp(str, prefix, len) ? NULL : str + len;
-}
-
 #ifdef __GLIBC_PREREQ
 #if __GLIBC_PREREQ(2, 1)
 #define HAVE_STRCHRNUL
@@ -187,14 +181,6 @@ static inline void *zalloc(size_t size)
 
 #define zfree(ptr) ({ free(*ptr); *ptr = NULL; })
 
-static inline int has_extension(const char *filename, const char *ext)
-{
-	size_t len = strlen(filename);
-	size_t extlen = strlen(ext);
-
-	return len > extlen && !memcmp(filename + len - extlen, ext, extlen);
-}
-
 /* Sane ctype - no locale, and works with signed chars */
 #undef isascii
 #undef isspace
-- 
2.4.3


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

* [PATCH v3 16/17] perf subcmd: Create subcmd library
  2015-12-14  4:18 [PATCH v3 00/17] perf tools: Move perf subcommand framework to a library Josh Poimboeuf
                   ` (14 preceding siblings ...)
  2015-12-14  4:18 ` [PATCH v3 15/17] perf: Finalize subcmd independence Josh Poimboeuf
@ 2015-12-14  4:18 ` Josh Poimboeuf
  2015-12-14  4:18 ` [PATCH v3 17/17] tools subcmd: Rename subcmd header include guards Josh Poimboeuf
  16 siblings, 0 replies; 56+ messages in thread
From: Josh Poimboeuf @ 2015-12-14  4:18 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo
  Cc: linux-kernel, Jiri Olsa, Namhyung Kim

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

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

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 tools/lib/subcmd/Build                             |  6 +++
 tools/lib/subcmd/Makefile                          | 48 ++++++++++++++++++++++
 .../util/exec_cmd.c => lib/subcmd/exec-cmd.c}      |  2 +-
 .../util/exec_cmd.h => lib/subcmd/exec-cmd.h}      |  0
 tools/{perf/util => lib/subcmd}/help.c             |  2 +-
 tools/{perf/util => lib/subcmd}/help.h             |  0
 tools/{perf/util => lib/subcmd}/pager.c            |  0
 tools/{perf/util => lib/subcmd}/pager.h            |  0
 tools/{perf/util => lib/subcmd}/parse-options.c    |  0
 tools/{perf/util => lib/subcmd}/parse-options.h    |  0
 tools/{perf/util => lib/subcmd}/run-command.c      |  2 +-
 tools/{perf/util => lib/subcmd}/run-command.h      |  0
 tools/{perf/util => lib/subcmd}/sigchain.c         |  0
 tools/{perf/util => lib/subcmd}/sigchain.h         |  0
 tools/{perf/util => lib/subcmd}/subcmd-util.h      |  0
 tools/perf/MANIFEST                                |  1 +
 tools/perf/Makefile.perf                           | 20 +++++++--
 tools/perf/arch/x86/util/intel-pt.c                |  2 +-
 tools/perf/bench/futex-hash.c                      |  2 +-
 tools/perf/bench/futex-lock-pi.c                   |  2 +-
 tools/perf/bench/futex-requeue.c                   |  2 +-
 tools/perf/bench/futex-wake-parallel.c             |  2 +-
 tools/perf/bench/futex-wake.c                      |  2 +-
 tools/perf/bench/mem-functions.c                   |  2 +-
 tools/perf/bench/numa.c                            |  2 +-
 tools/perf/bench/sched-messaging.c                 |  2 +-
 tools/perf/bench/sched-pipe.c                      |  2 +-
 tools/perf/builtin-annotate.c                      |  2 +-
 tools/perf/builtin-bench.c                         |  2 +-
 tools/perf/builtin-buildid-cache.c                 |  2 +-
 tools/perf/builtin-buildid-list.c                  |  2 +-
 tools/perf/builtin-config.c                        |  2 +-
 tools/perf/builtin-data.c                          |  2 +-
 tools/perf/builtin-evlist.c                        |  2 +-
 tools/perf/builtin-help.c                          |  8 ++--
 tools/perf/builtin-inject.c                        |  2 +-
 tools/perf/builtin-kmem.c                          |  2 +-
 tools/perf/builtin-kvm.c                           |  2 +-
 tools/perf/builtin-list.c                          |  2 +-
 tools/perf/builtin-lock.c                          |  2 +-
 tools/perf/builtin-mem.c                           |  2 +-
 tools/perf/builtin-probe.c                         |  2 +-
 tools/perf/builtin-record.c                        |  2 +-
 tools/perf/builtin-report.c                        |  2 +-
 tools/perf/builtin-sched.c                         |  2 +-
 tools/perf/builtin-script.c                        |  4 +-
 tools/perf/builtin-stat.c                          |  2 +-
 tools/perf/builtin-timechart.c                     |  2 +-
 tools/perf/builtin-top.c                           |  2 +-
 tools/perf/builtin-trace.c                         |  4 +-
 tools/perf/perf.c                                  |  6 +--
 tools/perf/tests/attr.c                            |  2 +-
 tools/perf/tests/builtin-test.c                    |  2 +-
 tools/perf/util/Build                              |  6 ---
 tools/perf/util/auxtrace.c                         |  2 +-
 tools/perf/util/cache.h                            |  2 +-
 tools/perf/util/cgroup.c                           |  2 +-
 tools/perf/util/config.c                           |  2 +-
 tools/perf/util/evlist.c                           |  2 +-
 tools/perf/util/help-unknown-cmd.c                 |  2 +-
 tools/perf/util/parse-branch-options.c             |  2 +-
 tools/perf/util/parse-events.c                     |  4 +-
 tools/perf/util/parse-regs-options.c               |  2 +-
 tools/perf/util/sort.h                             |  2 +-
 64 files changed, 128 insertions(+), 67 deletions(-)
 create mode 100644 tools/lib/subcmd/Build
 create mode 100644 tools/lib/subcmd/Makefile
 rename tools/{perf/util/exec_cmd.c => lib/subcmd/exec-cmd.c} (99%)
 rename tools/{perf/util/exec_cmd.h => lib/subcmd/exec-cmd.h} (100%)
 rename tools/{perf/util => lib/subcmd}/help.c (99%)
 rename tools/{perf/util => lib/subcmd}/help.h (100%)
 rename tools/{perf/util => lib/subcmd}/pager.c (100%)
 rename tools/{perf/util => lib/subcmd}/pager.h (100%)
 rename tools/{perf/util => lib/subcmd}/parse-options.c (100%)
 rename tools/{perf/util => lib/subcmd}/parse-options.h (100%)
 rename tools/{perf/util => lib/subcmd}/run-command.c (99%)
 rename tools/{perf/util => lib/subcmd}/run-command.h (100%)
 rename tools/{perf/util => lib/subcmd}/sigchain.c (100%)
 rename tools/{perf/util => lib/subcmd}/sigchain.h (100%)
 rename tools/{perf/util => lib/subcmd}/subcmd-util.h (100%)

diff --git a/tools/lib/subcmd/Build b/tools/lib/subcmd/Build
new file mode 100644
index 0000000..84aeda3
--- /dev/null
+++ b/tools/lib/subcmd/Build
@@ -0,0 +1,6 @@
+libsubcmd-y += exec-cmd.o
+libsubcmd-y += help.o
+libsubcmd-y += pager.o
+libsubcmd-y += parse-options.o
+libsubcmd-y += run-command.o
+libsubcmd-y += sigchain.o
diff --git a/tools/lib/subcmd/Makefile b/tools/lib/subcmd/Makefile
new file mode 100644
index 0000000..629cf8c
--- /dev/null
+++ b/tools/lib/subcmd/Makefile
@@ -0,0 +1,48 @@
+include ../../scripts/Makefile.include
+include ../../perf/config/utilities.mak		# QUIET_CLEAN
+
+ifeq ($(srctree),)
+srctree := $(patsubst %/,%,$(dir $(shell pwd)))
+srctree := $(patsubst %/,%,$(dir $(srctree)))
+srctree := $(patsubst %/,%,$(dir $(srctree)))
+#$(info Determined 'srctree' to be $(srctree))
+endif
+
+CC = $(CROSS_COMPILE)gcc
+AR = $(CROSS_COMPILE)ar
+RM = rm -f
+
+MAKEFLAGS += --no-print-directory
+
+LIBFILE = $(OUTPUT)libsubcmd.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 -D_GNU_SOURCE
+
+CFLAGS += -I$(srctree)/tools/include/
+CFLAGS += -I$(srctree)/include/uapi
+CFLAGS += -I$(srctree)/include
+
+SUBCMD_IN := $(OUTPUT)libsubcmd-in.o
+
+all:
+
+export srctree OUTPUT CC LD CFLAGS V
+include $(srctree)/tools/build/Makefile.include
+
+all: fixdep $(LIBFILE)
+
+$(SUBCMD_IN): FORCE
+	@$(MAKE) $(build)=libsubcmd
+
+$(LIBFILE): $(SUBCMD_IN)
+	$(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(SUBCMD_IN)
+
+clean:
+	$(call QUIET_CLEAN, libsubcmd) $(RM) $(LIBFILE); \
+	find $(if $(OUTPUT),$(OUTPUT),.) -name \*.o -or -name \*.o.cmd -or -name \*.o.d | xargs $(RM)
+
+FORCE:
+
+.PHONY: clean FORCE
diff --git a/tools/perf/util/exec_cmd.c b/tools/lib/subcmd/exec-cmd.c
similarity index 99%
rename from tools/perf/util/exec_cmd.c
rename to tools/lib/subcmd/exec-cmd.c
index 4a9292d..9eb6716 100644
--- a/tools/perf/util/exec_cmd.c
+++ b/tools/lib/subcmd/exec-cmd.c
@@ -6,7 +6,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include "subcmd-util.h"
-#include "exec_cmd.h"
+#include "exec-cmd.h"
 
 #define MAX_ARGS	32
 #define PATH_MAX	4096
diff --git a/tools/perf/util/exec_cmd.h b/tools/lib/subcmd/exec-cmd.h
similarity index 100%
rename from tools/perf/util/exec_cmd.h
rename to tools/lib/subcmd/exec-cmd.h
diff --git a/tools/perf/util/help.c b/tools/lib/subcmd/help.c
similarity index 99%
rename from tools/perf/util/help.c
rename to tools/lib/subcmd/help.c
index 8169480..e228c3c 100644
--- a/tools/perf/util/help.c
+++ b/tools/lib/subcmd/help.c
@@ -9,7 +9,7 @@
 #include <dirent.h>
 #include "subcmd-util.h"
 #include "help.h"
-#include "exec_cmd.h"
+#include "exec-cmd.h"
 
 void add_cmdname(struct cmdnames *cmds, const char *name, size_t len)
 {
diff --git a/tools/perf/util/help.h b/tools/lib/subcmd/help.h
similarity index 100%
rename from tools/perf/util/help.h
rename to tools/lib/subcmd/help.h
diff --git a/tools/perf/util/pager.c b/tools/lib/subcmd/pager.c
similarity index 100%
rename from tools/perf/util/pager.c
rename to tools/lib/subcmd/pager.c
diff --git a/tools/perf/util/pager.h b/tools/lib/subcmd/pager.h
similarity index 100%
rename from tools/perf/util/pager.h
rename to tools/lib/subcmd/pager.h
diff --git a/tools/perf/util/parse-options.c b/tools/lib/subcmd/parse-options.c
similarity index 100%
rename from tools/perf/util/parse-options.c
rename to tools/lib/subcmd/parse-options.c
diff --git a/tools/perf/util/parse-options.h b/tools/lib/subcmd/parse-options.h
similarity index 100%
rename from tools/perf/util/parse-options.h
rename to tools/lib/subcmd/parse-options.h
diff --git a/tools/perf/util/run-command.c b/tools/lib/subcmd/run-command.c
similarity index 99%
rename from tools/perf/util/run-command.c
rename to tools/lib/subcmd/run-command.c
index fed37d6..f4f6c9e 100644
--- a/tools/perf/util/run-command.c
+++ b/tools/lib/subcmd/run-command.c
@@ -7,7 +7,7 @@
 #include <sys/wait.h>
 #include "subcmd-util.h"
 #include "run-command.h"
-#include "exec_cmd.h"
+#include "exec-cmd.h"
 
 #define STRERR_BUFSIZE 128
 
diff --git a/tools/perf/util/run-command.h b/tools/lib/subcmd/run-command.h
similarity index 100%
rename from tools/perf/util/run-command.h
rename to tools/lib/subcmd/run-command.h
diff --git a/tools/perf/util/sigchain.c b/tools/lib/subcmd/sigchain.c
similarity index 100%
rename from tools/perf/util/sigchain.c
rename to tools/lib/subcmd/sigchain.c
diff --git a/tools/perf/util/sigchain.h b/tools/lib/subcmd/sigchain.h
similarity index 100%
rename from tools/perf/util/sigchain.h
rename to tools/lib/subcmd/sigchain.h
diff --git a/tools/perf/util/subcmd-util.h b/tools/lib/subcmd/subcmd-util.h
similarity index 100%
rename from tools/perf/util/subcmd-util.h
rename to tools/lib/subcmd/subcmd-util.h
diff --git a/tools/perf/MANIFEST b/tools/perf/MANIFEST
index 2562eac..ce3932e 100644
--- a/tools/perf/MANIFEST
+++ b/tools/perf/MANIFEST
@@ -20,6 +20,7 @@ tools/lib/traceevent
 tools/lib/bpf
 tools/lib/api
 tools/lib/bpf
+tools/lib/subcmd
 tools/lib/hweight.c
 tools/lib/rbtree.c
 tools/lib/string.c
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 388ec64..569fcf0 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -145,9 +145,10 @@ BISON   = bison
 STRIP   = strip
 AWK     = awk
 
-LIB_DIR          = $(srctree)/tools/lib/api/
+LIB_DIR		= $(srctree)/tools/lib/api/
 TRACE_EVENT_DIR = $(srctree)/tools/lib/traceevent/
-BPF_DIR = $(srctree)/tools/lib/bpf/
+BPF_DIR		= $(srctree)/tools/lib/bpf/
+SUBCMD_DIR	= $(srctree)/tools/lib/subcmd/
 
 # include config/Makefile by default and rule out
 # non-config cases
@@ -184,6 +185,7 @@ strip-libs = $(filter-out -l%,$(1))
 ifneq ($(OUTPUT),)
   TE_PATH=$(OUTPUT)
   BPF_PATH=$(OUTPUT)
+  SUBCMD_PATH=$(OUTPUT)
 ifneq ($(subdir),)
   API_PATH=$(OUTPUT)/../lib/api/
 else
@@ -193,6 +195,7 @@ else
   TE_PATH=$(TRACE_EVENT_DIR)
   API_PATH=$(LIB_DIR)
   BPF_PATH=$(BPF_DIR)
+  SUBCMD_PATH=$(SUBCMD_DIR)
 endif
 
 LIBTRACEEVENT = $(TE_PATH)libtraceevent.a
@@ -206,6 +209,8 @@ export LIBAPI
 
 LIBBPF = $(BPF_PATH)libbpf.a
 
+LIBSUBCMD = $(SUBCMD_PATH)libsubcmd.a
+
 # python extension build directories
 PYTHON_EXTBUILD     := $(OUTPUT)python_ext_build/
 PYTHON_EXTBUILD_LIB := $(PYTHON_EXTBUILD)lib/
@@ -257,7 +262,7 @@ export PERL_PATH
 
 LIB_FILE=$(OUTPUT)libperf.a
 
-PERFLIBS = $(LIB_FILE) $(LIBAPI) $(LIBTRACEEVENT)
+PERFLIBS = $(LIB_FILE) $(LIBAPI) $(LIBTRACEEVENT) $(LIBSUBCMD)
 ifndef NO_LIBBPF
   PERFLIBS += $(LIBBPF)
 endif
@@ -437,6 +442,13 @@ $(LIBBPF)-clean:
 	$(call QUIET_CLEAN, libbpf)
 	$(Q)$(MAKE) -C $(BPF_DIR) O=$(OUTPUT) clean >/dev/null
 
+$(LIBSUBCMD): fixdep FORCE
+	$(Q)$(MAKE) -C $(SUBCMD_DIR) O=$(OUTPUT) $(OUTPUT)libsubcmd.a
+
+$(LIBSUBCMD)-clean:
+	$(call QUIET_CLEAN, libsubcmd)
+	$(Q)$(MAKE) -C $(SUBCMD_DIR) O=$(OUTPUT) clean
+
 help:
 	@echo 'Perf make targets:'
 	@echo '  doc		- make *all* documentation (see below)'
@@ -584,7 +596,7 @@ config-clean:
 	$(call QUIET_CLEAN, config)
 	$(Q)$(MAKE) -C $(srctree)/tools/build/feature/ $(if $(OUTPUT),OUTPUT=$(OUTPUT)feature/,) clean >/dev/null
 
-clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean config-clean
+clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean config-clean
 	$(call QUIET_CLEAN, core-objs)  $(RM) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(LANG_BINDINGS)
 	$(Q)find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
 	$(Q)$(RM) $(OUTPUT).config-detected
diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c
index b02af06..b64d462 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 <subcmd/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..0999ac5 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 <subcmd/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..6a18ce2 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 <subcmd/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..7182386 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 <subcmd/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..91aaf2a 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 <subcmd/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..f416bd7 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 <subcmd/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..a91aa85 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 <subcmd/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..5049d63 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 <subcmd/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..bfaf950 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 <subcmd/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..1dc2d13 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 <subcmd/parse-options.h>
 #include "../builtin.h"
 #include "bench.h"
 
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 1f00dc7..e18f1b9 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -21,7 +21,7 @@
 #include "util/evsel.h"
 #include "util/annotate.h"
 #include "util/event.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/parse-events.h"
 #include "util/thread.h"
 #include "util/sort.h"
diff --git a/tools/perf/builtin-bench.c b/tools/perf/builtin-bench.c
index b17aed3..a1cddc6 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 <subcmd/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 7b8450c..d93bff7 100644
--- a/tools/perf/builtin-buildid-cache.c
+++ b/tools/perf/builtin-buildid-cache.c
@@ -16,7 +16,7 @@
 #include "util/cache.h"
 #include "util/debug.h"
 #include "util/header.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/strlist.h"
 #include "util/build-id.h"
 #include "util/session.h"
diff --git a/tools/perf/builtin-buildid-list.c b/tools/perf/builtin-buildid-list.c
index 6419f57..5e914ee 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/cache.h"
 #include "util/debug.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/session.h"
 #include "util/symbol.h"
 #include "util/data.h"
diff --git a/tools/perf/builtin-config.c b/tools/perf/builtin-config.c
index 427ea7a..f04e804 100644
--- a/tools/perf/builtin-config.c
+++ b/tools/perf/builtin-config.c
@@ -9,7 +9,7 @@
 #include "perf.h"
 
 #include "util/cache.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/util.h"
 #include "util/debug.h"
 
diff --git a/tools/perf/builtin-data.c b/tools/perf/builtin-data.c
index d6525bc..b97bc15 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 <subcmd/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..08a7d36 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 <subcmd/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 275aa64..96c1a4c 100644
--- a/tools/perf/builtin-help.c
+++ b/tools/perf/builtin-help.c
@@ -6,11 +6,11 @@
 #include "perf.h"
 #include "util/cache.h"
 #include "builtin.h"
-#include "util/exec_cmd.h"
+#include <subcmd/exec-cmd.h>
 #include "common-cmds.h"
-#include "util/parse-options.h"
-#include "util/run-command.h"
-#include "util/help.h"
+#include <subcmd/parse-options.h>
+#include <subcmd/run-command.h>
+#include <subcmd/help.h>
 #include "util/debug.h"
 
 static struct man_viewer_list {
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index 99d127f..0022e02 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 <subcmd/parse-options.h>
 
 #include <linux/list.h>
 
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 93ce665..1180105 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -12,7 +12,7 @@
 #include "util/tool.h"
 #include "util/callchain.h"
 
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/trace-event.h"
 #include "util/data.h"
 #include "util/cpumap.h"
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 031f9f5..4418d92 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -10,7 +10,7 @@
 #include "util/header.h"
 #include "util/session.h"
 #include "util/intlist.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/trace-event.h"
 #include "util/debug.h"
 #include "util/tool.h"
diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
index bf679e2..5e22db4 100644
--- a/tools/perf/builtin-list.c
+++ b/tools/perf/builtin-list.c
@@ -14,7 +14,7 @@
 #include "util/parse-events.h"
 #include "util/cache.h"
 #include "util/pmu.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 
 int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
 {
diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
index de16aae..ce3bfb4 100644
--- a/tools/perf/builtin-lock.c
+++ b/tools/perf/builtin-lock.c
@@ -9,7 +9,7 @@
 #include "util/thread.h"
 #include "util/header.h"
 
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/trace-event.h"
 
 #include "util/debug.h"
diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c
index 80170aa..3901700 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 <subcmd/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..ed4f3aa 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 <subcmd/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..135b1b3 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 <subcmd/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 5a45466..2a7330b 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -27,7 +27,7 @@
 #include "util/session.h"
 #include "util/tool.h"
 
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/parse-events.h"
 
 #include "util/thread.h"
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index e3d3e32..871b55ae 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -12,7 +12,7 @@
 #include "util/tool.h"
 #include "util/cloexec.h"
 
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/trace-event.h"
 
 #include "util/debug.h"
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 571016f..bcc3542 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -3,9 +3,9 @@
 #include "perf.h"
 #include "util/cache.h"
 #include "util/debug.h"
-#include "util/exec_cmd.h"
+#include <subcmd/exec-cmd.h>
 #include "util/header.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/perf_regs.h"
 #include "util/session.h"
 #include "util/tool.h"
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 25a95f4..bbf42ee 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 <subcmd/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 30e5962..bd7a775 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -30,7 +30,7 @@
 
 #include "perf.h"
 #include "util/header.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/parse-events.h"
 #include "util/event.h"
 #include "util/session.h"
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 92fe963..9ebd67a 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -34,7 +34,7 @@
 #include "util/top.h"
 #include "util/util.h"
 #include <linux/rbtree.h>
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/parse-events.h"
 #include "util/cpumap.h"
 #include "util/xyarray.h"
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index c783d8f..20916dd 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 <subcmd/exec-cmd.h>
 #include "util/machine.h"
 #include "util/session.h"
 #include "util/thread.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/strlist.h"
 #include "util/intlist.h"
 #include "util/thread_map.h"
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index c0fa9a5..af3b3f4 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -9,12 +9,12 @@
 #include "builtin.h"
 
 #include "util/env.h"
-#include "util/exec_cmd.h"
+#include <subcmd/exec-cmd.h>
 #include "util/cache.h"
 #include "util/quote.h"
-#include "util/run-command.h"
+#include <subcmd/run-command.h>
 #include "util/parse-events.h"
-#include "util/parse-options.h"
+#include <subcmd/parse-options.h>
 #include "util/bpf-loader.h"
 #include "util/debug.h"
 #include <api/fs/tracing_path.h>
diff --git a/tools/perf/tests/attr.c b/tools/perf/tests/attr.c
index 6337f1c..28d1605 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 <subcmd/exec-cmd.h>
 #include "tests.h"
 
 #define ENV "PERF_TEST_ATTR"
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index fa98406..0372d59 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 <subcmd/parse-options.h>
 #include "symbol.h"
 
 struct test __weak arch_tests[] = {
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 470515b..94b1099 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -9,13 +9,10 @@ libperf-y += env.o
 libperf-y += event.o
 libperf-y += evlist.o
 libperf-y += evsel.o
-libperf-y += exec_cmd.o
 libperf-y += find_next_bit.o
-libperf-y += help.o
 libperf-y += kallsyms.o
 libperf-y += levenshtein.o
 libperf-y += llvm-utils.o
-libperf-y += parse-options.o
 libperf-y += parse-events.o
 libperf-y += perf_regs.o
 libperf-y += path.o
@@ -23,7 +20,6 @@ libperf-y += rbtree.o
 libperf-y += libstring.o
 libperf-y += bitmap.o
 libperf-y += hweight.o
-libperf-y += run-command.o
 libperf-y += quote.o
 libperf-y += strbuf.o
 libperf-y += string.o
@@ -32,11 +28,9 @@ libperf-y += strfilter.o
 libperf-y += top.o
 libperf-y += usage.o
 libperf-y += wrapper.o
-libperf-y += sigchain.o
 libperf-y += dso.o
 libperf-y += symbol.o
 libperf-y += color.o
-libperf-y += pager.o
 libperf-y += header.o
 libperf-y += callchain.o
 libperf-y += values.o
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index 7f10430..360fda0 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 <subcmd/parse-options.h>
 
 #include "intel-pt.h"
 #include "intel-bts.h"
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h
index 4b9d7da..a2e230e 100644
--- a/tools/perf/util/cache.h
+++ b/tools/perf/util/cache.h
@@ -4,7 +4,7 @@
 #include <stdbool.h>
 #include "util.h"
 #include "strbuf.h"
-#include "pager.h"
+#include <subcmd/pager.h>
 #include "../perf.h"
 #include "../ui/ui.h"
 
diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c
index 32e12ec..90aa1b4 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 <subcmd/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 2e452ac..d3e12e3 100644
--- a/tools/perf/util/config.c
+++ b/tools/perf/util/config.c
@@ -10,7 +10,7 @@
  */
 #include "util.h"
 #include "cache.h"
-#include "exec_cmd.h"
+#include <subcmd/exec-cmd.h>
 #include "util/hist.h"  /* perf_hist_config */
 #include "util/llvm-utils.h"   /* perf_llvm_config */
 
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index d1b6c20..8c44aad 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 <subcmd/parse-options.h>
 
 #include <sys/mman.h>
 
diff --git a/tools/perf/util/help-unknown-cmd.c b/tools/perf/util/help-unknown-cmd.c
index a0820f1..dc1e41c 100644
--- a/tools/perf/util/help-unknown-cmd.c
+++ b/tools/perf/util/help-unknown-cmd.c
@@ -1,5 +1,5 @@
 #include "cache.h"
-#include "help.h"
+#include <subcmd/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..afc088d 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 <subcmd/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 6fc8cd7..4f7b0ef 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 <subcmd/parse-options.h>
 #include "parse-events.h"
-#include "exec_cmd.h"
+#include <subcmd/exec-cmd.h>
 #include "string.h"
 #include "symbol.h"
 #include "cache.h"
diff --git a/tools/perf/util/parse-regs-options.c b/tools/perf/util/parse-regs-options.c
index 4f2c1c2..646ecf7 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 <subcmd/parse-options.h>
 #include "util/parse-regs-options.h"
 
 int
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
index 3122885..86f05e7 100644
--- a/tools/perf/util/sort.h
+++ b/tools/perf/util/sort.h
@@ -18,7 +18,7 @@
 #include "debug.h"
 #include "header.h"
 
-#include "parse-options.h"
+#include <subcmd/parse-options.h>
 #include "parse-events.h"
 #include "hist.h"
 #include "thread.h"
-- 
2.4.3


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

* [PATCH v3 17/17] tools subcmd: Rename subcmd header include guards
  2015-12-14  4:18 [PATCH v3 00/17] perf tools: Move perf subcommand framework to a library Josh Poimboeuf
                   ` (15 preceding siblings ...)
  2015-12-14  4:18 ` [PATCH v3 16/17] perf subcmd: Create subcmd library Josh Poimboeuf
@ 2015-12-14  4:18 ` Josh Poimboeuf
  16 siblings, 0 replies; 56+ messages in thread
From: Josh Poimboeuf @ 2015-12-14  4:18 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo
  Cc: linux-kernel, Jiri Olsa, Namhyung Kim

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 tools/lib/subcmd/exec-cmd.h      | 6 +++---
 tools/lib/subcmd/help.h          | 6 +++---
 tools/lib/subcmd/pager.h         | 6 +++---
 tools/lib/subcmd/parse-options.h | 7 ++++---
 tools/lib/subcmd/run-command.h   | 6 +++---
 tools/lib/subcmd/sigchain.h      | 6 +++---
 tools/lib/subcmd/subcmd-util.h   | 6 +++---
 7 files changed, 22 insertions(+), 21 deletions(-)

diff --git a/tools/lib/subcmd/exec-cmd.h b/tools/lib/subcmd/exec-cmd.h
index f1bd343..5d08bda 100644
--- a/tools/lib/subcmd/exec-cmd.h
+++ b/tools/lib/subcmd/exec-cmd.h
@@ -1,5 +1,5 @@
-#ifndef __PERF_EXEC_CMD_H
-#define __PERF_EXEC_CMD_H
+#ifndef __SUBCMD_EXEC_CMD_H
+#define __SUBCMD_EXEC_CMD_H
 
 extern void exec_cmd_init(const char *exec_name, const char *prefix,
 			  const char *exec_path, const char *exec_path_env);
@@ -13,4 +13,4 @@ extern int execl_cmd(const char *cmd, ...);
 extern char *get_argv_exec_path(void);
 extern char *system_path(const char *path);
 
-#endif /* __PERF_EXEC_CMD_H */
+#endif /* __SUBCMD_EXEC_CMD_H */
diff --git a/tools/lib/subcmd/help.h b/tools/lib/subcmd/help.h
index 096c8bc..e145a02 100644
--- a/tools/lib/subcmd/help.h
+++ b/tools/lib/subcmd/help.h
@@ -1,5 +1,5 @@
-#ifndef __PERF_HELP_H
-#define __PERF_HELP_H
+#ifndef __SUBCMD_HELP_H
+#define __SUBCMD_HELP_H
 
 #include <sys/types.h>
 
@@ -31,4 +31,4 @@ int is_in_cmdlist(struct cmdnames *c, const char *s);
 void list_commands(const char *title, struct cmdnames *main_cmds,
 		   struct cmdnames *other_cmds);
 
-#endif /* __PERF_HELP_H */
+#endif /* __SUBCMD_HELP_H */
diff --git a/tools/lib/subcmd/pager.h b/tools/lib/subcmd/pager.h
index d6a591a..8b83714 100644
--- a/tools/lib/subcmd/pager.h
+++ b/tools/lib/subcmd/pager.h
@@ -1,9 +1,9 @@
-#ifndef __PERF_PAGER_H
-#define __PERF_PAGER_H
+#ifndef __SUBCMD_PAGER_H
+#define __SUBCMD_PAGER_H
 
 extern void pager_init(const char *pager_env);
 
 extern void setup_pager(void);
 extern int pager_in_use(void);
 
-#endif /* __PERF_PAGER_H */
+#endif /* __SUBCMD_PAGER_H */
diff --git a/tools/lib/subcmd/parse-options.h b/tools/lib/subcmd/parse-options.h
index 7f0c88d..6ba1859 100644
--- a/tools/lib/subcmd/parse-options.h
+++ b/tools/lib/subcmd/parse-options.h
@@ -1,5 +1,5 @@
-#ifndef __PERF_PARSE_OPTIONS_H
-#define __PERF_PARSE_OPTIONS_H
+#ifndef __SUBCMD_PARSE_OPTIONS_H
+#define __SUBCMD_PARSE_OPTIONS_H
 
 #include <stdbool.h>
 #include <stdint.h>
@@ -222,4 +222,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 /* __SUBCMD_PARSE_OPTIONS_H */
diff --git a/tools/lib/subcmd/run-command.h b/tools/lib/subcmd/run-command.h
index 4a55393..fe2befe 100644
--- a/tools/lib/subcmd/run-command.h
+++ b/tools/lib/subcmd/run-command.h
@@ -1,5 +1,5 @@
-#ifndef __PERF_RUN_COMMAND_H
-#define __PERF_RUN_COMMAND_H
+#ifndef __SUBCMD_RUN_COMMAND_H
+#define __SUBCMD_RUN_COMMAND_H
 
 #include <unistd.h>
 
@@ -57,4 +57,4 @@ int run_command(struct child_process *);
 #define RUN_COMMAND_STDOUT_TO_STDERR 4
 int run_command_v_opt(const char **argv, int opt);
 
-#endif /* __PERF_RUN_COMMAND_H */
+#endif /* __SUBCMD_RUN_COMMAND_H */
diff --git a/tools/lib/subcmd/sigchain.h b/tools/lib/subcmd/sigchain.h
index 959d64e..0c919f2 100644
--- a/tools/lib/subcmd/sigchain.h
+++ b/tools/lib/subcmd/sigchain.h
@@ -1,5 +1,5 @@
-#ifndef __PERF_SIGCHAIN_H
-#define __PERF_SIGCHAIN_H
+#ifndef __SUBCMD_SIGCHAIN_H
+#define __SUBCMD_SIGCHAIN_H
 
 typedef void (*sigchain_fun)(int);
 
@@ -7,4 +7,4 @@ int sigchain_pop(int sig);
 
 void sigchain_push_common(sigchain_fun f);
 
-#endif /* __PERF_SIGCHAIN_H */
+#endif /* __SUBCMD_SIGCHAIN_H */
diff --git a/tools/lib/subcmd/subcmd-util.h b/tools/lib/subcmd/subcmd-util.h
index 321aeb1..fc2e45d 100644
--- a/tools/lib/subcmd/subcmd-util.h
+++ b/tools/lib/subcmd/subcmd-util.h
@@ -1,5 +1,5 @@
-#ifndef __PERF_SUBCMD_UTIL_H
-#define __PERF_SUBCMD_UTIL_H
+#ifndef __SUBCMD_UTIL_H
+#define __SUBCMD_UTIL_H
 
 #include <stdarg.h>
 #include <stdlib.h>
@@ -88,4 +88,4 @@ static inline int prefixcmp(const char *str, const char *prefix)
 			return (unsigned char)*prefix - (unsigned char)*str;
 }
 
-#endif /* __PERF_SUBCMD_UTIL_H */
+#endif /* __SUBCMD_UTIL_H */
-- 
2.4.3


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

* Re: [PATCH v3 01/17] perf build: Remove unnecessary line in Makefile.feature
  2015-12-14  4:18 ` [PATCH v3 01/17] perf build: Remove unnecessary line in Makefile.feature Josh Poimboeuf
@ 2015-12-14 10:05   ` Jiri Olsa
  2015-12-14 15:16     ` Arnaldo Carvalho de Melo
  2015-12-18  8:47   ` [tip:perf/core] " tip-bot for Josh Poimboeuf
  1 sibling, 1 reply; 56+ messages in thread
From: Jiri Olsa @ 2015-12-14 10:05 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	linux-kernel, Namhyung Kim

On Sun, Dec 13, 2015 at 10:18:01PM -0600, Josh Poimboeuf wrote:
> This line always silently fails because it doesn't add the 'test-'
> prefix to the .bin file.
> 
> And it seems to be unnecessary anyway: the line immediately after it
> does all the individual feature checks.
> 
> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
> ---
>  tools/build/Makefile.feature | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature
> index 37ff4c9..b8c31ec 100644
> --- a/tools/build/Makefile.feature
> +++ b/tools/build/Makefile.feature
> @@ -101,7 +101,6 @@ ifeq ($(feature-all), 1)
>    #
>    $(foreach feat,$(FEATURE_TESTS),$(call feature_set,$(feat)))
>  else
> -  $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS)" LDFLAGS=$(LDFLAGS) -i -j -C $(feature_dir) $(addsuffix .bin,$(FEATURE_TESTS)) >/dev/null 2>&1)
>    $(foreach feat,$(FEATURE_TESTS),$(call feature_check,$(feat)))

ugh, nice ;-)

Acked-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka

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

* Re: [PATCH v3 02/17] tools build: Fix feature Makefile dependencies for 'O='
  2015-12-14  4:18 ` [PATCH v3 02/17] tools build: Fix feature Makefile dependencies for 'O=' Josh Poimboeuf
@ 2015-12-14 10:08   ` Jiri Olsa
  2015-12-14 14:02     ` Josh Poimboeuf
  0 siblings, 1 reply; 56+ messages in thread
From: Jiri Olsa @ 2015-12-14 10:08 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	linux-kernel, Namhyung Kim

On Sun, Dec 13, 2015 at 10:18:02PM -0600, Josh Poimboeuf wrote:
> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
> ---
>  tools/build/Makefile.feature |  2 +-
>  tools/build/feature/Makefile | 95 ++++++++++++++++++++++----------------------
>  2 files changed, 49 insertions(+), 48 deletions(-)
> 
> diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature
> index b8c31ec..6c0519d 100644
> --- a/tools/build/Makefile.feature
> +++ b/tools/build/Makefile.feature
> @@ -7,7 +7,7 @@ endif
>  
>  feature_check = $(eval $(feature_check_code))
>  define feature_check_code
> -  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C $(feature_dir) test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0)
> +  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C $(feature_dir) $(OUTPUT_FEATURES)test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0)
>  endef
>  
>  feature_set = $(eval $(feature_set_code))
> diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
> index cea04ce9..8fec49d 100644
> --- a/tools/build/feature/Makefile
> +++ b/tools/build/feature/Makefile
> @@ -1,4 +1,3 @@
> -
>  FILES=					\
>  	test-all.bin			\
>  	test-backtrace.bin		\
> @@ -38,38 +37,40 @@ FILES=					\
>  	test-bpf.bin			\
>  	test-get_cpuid.bin
>  
> +OUTPUT_FILES = $(addprefix $(OUTPUT),$(FILES))

seems there's no need to introduce new variable, you could use FILES:

FILES := $(addprefix $(OUTPUT),$(FILES))

jirka

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

* Re: [PATCH v3 03/17] perf test: Add Build file to dependencies for llvm-src-*.c
  2015-12-14  4:18 ` [PATCH v3 03/17] perf test: Add Build file to dependencies for llvm-src-*.c Josh Poimboeuf
@ 2015-12-14 10:10   ` Jiri Olsa
  2015-12-14 15:17     ` Arnaldo Carvalho de Melo
  2015-12-18  8:47   ` [tip:perf/core] " tip-bot for Josh Poimboeuf
  1 sibling, 1 reply; 56+ messages in thread
From: Jiri Olsa @ 2015-12-14 10:10 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	linux-kernel, Namhyung Kim

On Sun, Dec 13, 2015 at 10:18:03PM -0600, Josh Poimboeuf wrote:
> Because the Build file writes source code to the generated llvm-src-*.c
> files, it should be listed as one of the dependencies, so that any
> future changes to the code being echoed won't require a 'make clean'.

Acked-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka

> 
> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
> ---
>  tools/perf/tests/Build | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
> index 0ff8a97..f23fb7e 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[] =' >> $@
> -- 
> 2.4.3
> 

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

* Re: [PATCH v3 05/17] perf build: Fix 'make clean'
  2015-12-14  4:18 ` [PATCH v3 05/17] perf build: Fix 'make clean' Josh Poimboeuf
@ 2015-12-14 10:14   ` Jiri Olsa
  2015-12-14 15:18     ` Arnaldo Carvalho de Melo
  2015-12-18  8:48   ` [tip:perf/core] " tip-bot for Josh Poimboeuf
  1 sibling, 1 reply; 56+ messages in thread
From: Jiri Olsa @ 2015-12-14 10:14 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	linux-kernel, Namhyung Kim

On Sun, Dec 13, 2015 at 10:18:05PM -0600, Josh Poimboeuf wrote:
> Add some missing files to the 'make clean' target.
> 
> Reported-by: Jiri Olsa <jolsa@redhat.com>

Acked-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka

> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
> ---
>  tools/perf/Makefile.perf | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
> index 929a32b..906c723 100644
> --- a/tools/perf/Makefile.perf
> +++ b/tools/perf/Makefile.perf
> @@ -582,15 +582,16 @@ $(INSTALL_DOC_TARGETS):
>  #
>  config-clean:
>  	$(call QUIET_CLEAN, config)
> -	$(Q)$(MAKE) -C $(srctree)/tools/build/feature/ clean >/dev/null
> +	$(Q)$(MAKE) -C $(srctree)/tools/build/feature/ $(if $(OUTPUT),OUTPUT=$(OUTPUT)feature/,) clean >/dev/null
>  
>  clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean config-clean
>  	$(call QUIET_CLEAN, core-objs)  $(RM) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(LANG_BINDINGS)
> -	$(Q)find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
> +	$(Q)find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
>  	$(Q)$(RM) $(OUTPUT).config-detected
>  	$(call QUIET_CLEAN, core-progs) $(RM) $(ALL_PROGRAMS) perf perf-read-vdso32 perf-read-vdsox32
>  	$(call QUIET_CLEAN, core-gen)   $(RM)  *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope* $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)FEATURE-DUMP $(OUTPUT)util/*-bison* $(OUTPUT)util/*-flex* \
> -		$(OUTPUT)util/intel-pt-decoder/inat-tables.c
> +		$(OUTPUT)util/intel-pt-decoder/inat-tables.c $(OUTPUT)fixdep \
> +		$(OUTPUT)tests/llvm-src-{base,kbuild,prologue}.c
>  	$(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean
>  	$(python-clean)
>  
> -- 
> 2.4.3
> 

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

* Re: [PATCH v3 14/17] perf: Remove subcmd dependencies on strbuf
  2015-12-14  4:18 ` [PATCH v3 14/17] perf: Remove subcmd dependencies on strbuf Josh Poimboeuf
@ 2015-12-14 10:25   ` Jiri Olsa
  2015-12-14 14:11     ` Josh Poimboeuf
  2015-12-14 15:44   ` Arnaldo Carvalho de Melo
  1 sibling, 1 reply; 56+ messages in thread
From: Jiri Olsa @ 2015-12-14 10:25 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	linux-kernel, Namhyung Kim

On Sun, Dec 13, 2015 at 10:18:14PM -0600, Josh Poimboeuf wrote:
> Introduce and use new astrcat() and astrcatf() functions which replace
> the strbuf functionality for subcmd.

hum, would it be better then to put strbuf into lib as well?

jirka

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

* Re: [PATCH v3 15/17] perf: Finalize subcmd independence
  2015-12-14  4:18 ` [PATCH v3 15/17] perf: Finalize subcmd independence Josh Poimboeuf
@ 2015-12-14 10:32   ` Jiri Olsa
  2015-12-14 14:13     ` Josh Poimboeuf
  0 siblings, 1 reply; 56+ messages in thread
From: Jiri Olsa @ 2015-12-14 10:32 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	linux-kernel, Namhyung Kim

On Sun, Dec 13, 2015 at 10:18:15PM -0600, Josh Poimboeuf wrote:
> For the files that will be moved to the subcmd library, remove all their
> perf-specific includes and duplicate any needed functionality.
> 
> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
> ---
>  tools/perf/util/exec_cmd.c      | 75 +++++++++++++++++++++++++++++++++++++----
>  tools/perf/util/help.c          | 47 +++++++++++++++++++++++---
>  tools/perf/util/help.h          |  4 ++-
>  tools/perf/util/pager.c         |  7 +++-
>  tools/perf/util/parse-options.c | 68 +++++++++++++++++++++++--------------
>  tools/perf/util/parse-options.h |  2 +-
>  tools/perf/util/run-command.c   | 16 ++++++---
>  tools/perf/util/run-command.h   |  2 ++
>  tools/perf/util/sigchain.c      |  3 +-
>  tools/perf/util/subcmd-util.h   | 67 ++++++++++++++++++++++++++++++++++++
>  tools/perf/util/util.h          | 14 --------
>  11 files changed, 247 insertions(+), 58 deletions(-)

this duplicates functions that we have already in perf,
I think we better move them into lib first..
  strlcpy, die, xrealloc, ALLOC_GROW

and probably some others...

jirka

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

* Re: [PATCH v3 10/17] perf: Provide subcmd configuration at runtime
  2015-12-14  4:18 ` [PATCH v3 10/17] perf: Provide subcmd configuration at runtime Josh Poimboeuf
@ 2015-12-14 10:33   ` Jiri Olsa
  2015-12-14 14:06     ` Josh Poimboeuf
  0 siblings, 1 reply; 56+ messages in thread
From: Jiri Olsa @ 2015-12-14 10:33 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	linux-kernel, Namhyung Kim

On Sun, Dec 13, 2015 at 10:18:10PM -0600, Josh Poimboeuf wrote:

SNIP

>  
>  typedef int (*config_fn_t)(const char *, const char *, void *);
>  extern int perf_default_config(const char *, const char *, void *);
> diff --git a/tools/perf/util/exec_cmd.c b/tools/perf/util/exec_cmd.c
> index 1099e92..84f9dc5 100644
> --- a/tools/perf/util/exec_cmd.c
> +++ b/tools/perf/util/exec_cmd.c
> @@ -5,19 +5,33 @@
>  #include <string.h>
>  
>  #define MAX_ARGS	32
> +#define UNDEFINED	"UNDEFINED"
>  
>  static const char *argv_exec_path;
>  static const char *argv0_path;
>  
> +static const char *cfg_exec_name	= UNDEFINED;
> +static const char *cfg_prefix		= UNDEFINED;
> +static const char *cfg_exec_path	= UNDEFINED;
> +static const char *cfg_exec_path_env	= UNDEFINED;

so instead of forcing each object to hold some subset
of cfg_* configuration, why not create global cfg
object that would carry this data.. cfg_path or so ;-)

jirka

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

* Re: [PATCH v3 06/17] perf build: Rename LIB_PATH -> API_PATH
  2015-12-14  4:18 ` [PATCH v3 06/17] perf build: Rename LIB_PATH -> API_PATH Josh Poimboeuf
@ 2015-12-14 10:34   ` Jiri Olsa
  2015-12-14 15:19     ` Arnaldo Carvalho de Melo
  2015-12-18  8:49   ` [tip:perf/core] " tip-bot for Josh Poimboeuf
  1 sibling, 1 reply; 56+ messages in thread
From: Jiri Olsa @ 2015-12-14 10:34 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	linux-kernel, Namhyung Kim

On Sun, Dec 13, 2015 at 10:18:06PM -0600, Josh Poimboeuf wrote:
> 'LIB_PATH' is a misnomer because there are multiple library paths.
> 
> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>

Acked-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka

> ---
>  tools/perf/Makefile.perf | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
> index 906c723..388ec64 100644
> --- a/tools/perf/Makefile.perf
> +++ b/tools/perf/Makefile.perf
> @@ -185,13 +185,13 @@ ifneq ($(OUTPUT),)
>    TE_PATH=$(OUTPUT)
>    BPF_PATH=$(OUTPUT)
>  ifneq ($(subdir),)
> -  LIB_PATH=$(OUTPUT)/../lib/api/
> +  API_PATH=$(OUTPUT)/../lib/api/
>  else
> -  LIB_PATH=$(OUTPUT)
> +  API_PATH=$(OUTPUT)
>  endif
>  else
>    TE_PATH=$(TRACE_EVENT_DIR)
> -  LIB_PATH=$(LIB_DIR)
> +  API_PATH=$(LIB_DIR)
>    BPF_PATH=$(BPF_DIR)
>  endif
>  
> @@ -201,7 +201,7 @@ export LIBTRACEEVENT
>  LIBTRACEEVENT_DYNAMIC_LIST = $(TE_PATH)libtraceevent-dynamic-list
>  LIBTRACEEVENT_DYNAMIC_LIST_LDFLAGS = -Xlinker --dynamic-list=$(LIBTRACEEVENT_DYNAMIC_LIST)
>  
> -LIBAPI = $(LIB_PATH)libapi.a
> +LIBAPI = $(API_PATH)libapi.a
>  export LIBAPI
>  
>  LIBBPF = $(BPF_PATH)libbpf.a
> -- 
> 2.4.3
> 

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

* Re: [PATCH v3 02/17] tools build: Fix feature Makefile dependencies for 'O='
  2015-12-14 10:08   ` Jiri Olsa
@ 2015-12-14 14:02     ` Josh Poimboeuf
  2015-12-14 14:29       ` [PATCH v3.1 " Josh Poimboeuf
  0 siblings, 1 reply; 56+ messages in thread
From: Josh Poimboeuf @ 2015-12-14 14:02 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	linux-kernel, Namhyung Kim

On Mon, Dec 14, 2015 at 11:08:51AM +0100, Jiri Olsa wrote:
> On Sun, Dec 13, 2015 at 10:18:02PM -0600, Josh Poimboeuf wrote:
> > Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
> > ---
> >  tools/build/Makefile.feature |  2 +-
> >  tools/build/feature/Makefile | 95 ++++++++++++++++++++++----------------------
> >  2 files changed, 49 insertions(+), 48 deletions(-)
> > 
> > diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature
> > index b8c31ec..6c0519d 100644
> > --- a/tools/build/Makefile.feature
> > +++ b/tools/build/Makefile.feature
> > @@ -7,7 +7,7 @@ endif
> >  
> >  feature_check = $(eval $(feature_check_code))
> >  define feature_check_code
> > -  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C $(feature_dir) test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0)
> > +  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C $(feature_dir) $(OUTPUT_FEATURES)test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0)
> >  endef
> >  
> >  feature_set = $(eval $(feature_set_code))
> > diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
> > index cea04ce9..8fec49d 100644
> > --- a/tools/build/feature/Makefile
> > +++ b/tools/build/feature/Makefile
> > @@ -1,4 +1,3 @@
> > -
> >  FILES=					\
> >  	test-all.bin			\
> >  	test-backtrace.bin		\
> > @@ -38,38 +37,40 @@ FILES=					\
> >  	test-bpf.bin			\
> >  	test-get_cpuid.bin
> >  
> > +OUTPUT_FILES = $(addprefix $(OUTPUT),$(FILES))
> 
> seems there's no need to introduce new variable, you could use FILES:
> 
> FILES := $(addprefix $(OUTPUT),$(FILES))

Sure, will do that.

-- 
Josh

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

* Re: [PATCH v3 10/17] perf: Provide subcmd configuration at runtime
  2015-12-14 10:33   ` Jiri Olsa
@ 2015-12-14 14:06     ` Josh Poimboeuf
  0 siblings, 0 replies; 56+ messages in thread
From: Josh Poimboeuf @ 2015-12-14 14:06 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	linux-kernel, Namhyung Kim

On Mon, Dec 14, 2015 at 11:33:58AM +0100, Jiri Olsa wrote:
> On Sun, Dec 13, 2015 at 10:18:10PM -0600, Josh Poimboeuf wrote:
> 
> SNIP
> 
> >  
> >  typedef int (*config_fn_t)(const char *, const char *, void *);
> >  extern int perf_default_config(const char *, const char *, void *);
> > diff --git a/tools/perf/util/exec_cmd.c b/tools/perf/util/exec_cmd.c
> > index 1099e92..84f9dc5 100644
> > --- a/tools/perf/util/exec_cmd.c
> > +++ b/tools/perf/util/exec_cmd.c
> > @@ -5,19 +5,33 @@
> >  #include <string.h>
> >  
> >  #define MAX_ARGS	32
> > +#define UNDEFINED	"UNDEFINED"
> >  
> >  static const char *argv_exec_path;
> >  static const char *argv0_path;
> >  
> > +static const char *cfg_exec_name	= UNDEFINED;
> > +static const char *cfg_prefix		= UNDEFINED;
> > +static const char *cfg_exec_path	= UNDEFINED;
> > +static const char *cfg_exec_path_env	= UNDEFINED;
> 
> so instead of forcing each object to hold some subset
> of cfg_* configuration, why not create global cfg
> object that would carry this data.. cfg_path or so ;-)

Sure, though if it has the config for the entire library, I'd propose a
broader name like 'subcmd_cfg'.

-- 
Josh

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

* Re: [PATCH v3 14/17] perf: Remove subcmd dependencies on strbuf
  2015-12-14 10:25   ` Jiri Olsa
@ 2015-12-14 14:11     ` Josh Poimboeuf
  0 siblings, 0 replies; 56+ messages in thread
From: Josh Poimboeuf @ 2015-12-14 14:11 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	linux-kernel, Namhyung Kim

On Mon, Dec 14, 2015 at 11:25:51AM +0100, Jiri Olsa wrote:
> On Sun, Dec 13, 2015 at 10:18:14PM -0600, Josh Poimboeuf wrote:
> > Introduce and use new astrcat() and astrcatf() functions which replace
> > the strbuf functionality for subcmd.
> 
> hum, would it be better then to put strbuf into lib as well?

Based on the v2 discussion, I think we don't want to move it to lib,
because it's also used by perf, and it's outside the scope of 'subcmd'.

But we could certainly duplicate it for internal use by the library.

Arnaldo, what do you think?

-- 
Josh

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

* Re: [PATCH v3 15/17] perf: Finalize subcmd independence
  2015-12-14 10:32   ` Jiri Olsa
@ 2015-12-14 14:13     ` Josh Poimboeuf
  2015-12-14 15:27       ` Jiri Olsa
  2015-12-14 15:51       ` Arnaldo Carvalho de Melo
  0 siblings, 2 replies; 56+ messages in thread
From: Josh Poimboeuf @ 2015-12-14 14:13 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	linux-kernel, Namhyung Kim

On Mon, Dec 14, 2015 at 11:32:20AM +0100, Jiri Olsa wrote:
> On Sun, Dec 13, 2015 at 10:18:15PM -0600, Josh Poimboeuf wrote:
> > For the files that will be moved to the subcmd library, remove all their
> > perf-specific includes and duplicate any needed functionality.
> > 
> > Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
> > ---
> >  tools/perf/util/exec_cmd.c      | 75 +++++++++++++++++++++++++++++++++++++----
> >  tools/perf/util/help.c          | 47 +++++++++++++++++++++++---
> >  tools/perf/util/help.h          |  4 ++-
> >  tools/perf/util/pager.c         |  7 +++-
> >  tools/perf/util/parse-options.c | 68 +++++++++++++++++++++++--------------
> >  tools/perf/util/parse-options.h |  2 +-
> >  tools/perf/util/run-command.c   | 16 ++++++---
> >  tools/perf/util/run-command.h   |  2 ++
> >  tools/perf/util/sigchain.c      |  3 +-
> >  tools/perf/util/subcmd-util.h   | 67 ++++++++++++++++++++++++++++++++++++
> >  tools/perf/util/util.h          | 14 --------
> >  11 files changed, 247 insertions(+), 58 deletions(-)
> 
> this duplicates functions that we have already in perf,
> I think we better move them into lib first..
>   strlcpy, die, xrealloc, ALLOC_GROW
> 
> and probably some others...

The duplication was an intentional decision we made in the v2 discussion
in order to keep the library's scope focused on 'subcmd'.

-- 
Josh

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

* [PATCH v3.1 02/17] tools build: Fix feature Makefile dependencies for 'O='
  2015-12-14 14:02     ` Josh Poimboeuf
@ 2015-12-14 14:29       ` Josh Poimboeuf
  2015-12-14 15:16         ` Arnaldo Carvalho de Melo
  2015-12-14 15:29         ` Jiri Olsa
  0 siblings, 2 replies; 56+ messages in thread
From: Josh Poimboeuf @ 2015-12-14 14:29 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	linux-kernel, Namhyung Kim

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 tools/build/Makefile.feature |  2 +-
 tools/build/feature/Makefile | 93 ++++++++++++++++++++++----------------------
 2 files changed, 48 insertions(+), 47 deletions(-)

diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature
index b8c31ec..6c0519d 100644
--- a/tools/build/Makefile.feature
+++ b/tools/build/Makefile.feature
@@ -7,7 +7,7 @@ endif
 
 feature_check = $(eval $(feature_check_code))
 define feature_check_code
-  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C $(feature_dir) test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0)
+  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C $(feature_dir) $(OUTPUT_FEATURES)test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0)
 endef
 
 feature_set = $(eval $(feature_set_code))
diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
index cea04ce9..bf8f035 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -1,4 +1,3 @@
-
 FILES=					\
 	test-all.bin			\
 	test-backtrace.bin		\
@@ -38,38 +37,40 @@ FILES=					\
 	test-bpf.bin			\
 	test-get_cpuid.bin
 
+FILES := $(addprefix $(OUTPUT),$(FILES))
+
 CC := $(CROSS_COMPILE)gcc -MD
 PKG_CONFIG := $(CROSS_COMPILE)pkg-config
 
 all: $(FILES)
 
-__BUILD = $(CC) $(CFLAGS) -Wall -Werror -o $(OUTPUT)$@ $(patsubst %.bin,%.c,$@) $(LDFLAGS)
-  BUILD = $(__BUILD) > $(OUTPUT)$(@:.bin=.make.output) 2>&1
+__BUILD = $(CC) $(CFLAGS) -Wall -Werror -o $@ $(patsubst %.bin,%.c,$(@F)) $(LDFLAGS)
+  BUILD = $(__BUILD) > $(@:.bin=.make.output) 2>&1
 
 ###############################
 
-test-all.bin:
+$(OUTPUT)test-all.bin:
 	$(BUILD) -fstack-protector-all -O2 -D_FORTIFY_SOURCE=2 -ldw -lelf -lnuma -lelf -laudit -I/usr/include/slang -lslang $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) $(FLAGS_PERL_EMBED) $(FLAGS_PYTHON_EMBED) -DPACKAGE='"perf"' -lbfd -ldl -lz -llzma
 
-test-hello.bin:
+$(OUTPUT)test-hello.bin:
 	$(BUILD)
 
-test-pthread-attr-setaffinity-np.bin:
+$(OUTPUT)test-pthread-attr-setaffinity-np.bin:
 	$(BUILD) -D_GNU_SOURCE -lpthread
 
-test-stackprotector-all.bin:
+$(OUTPUT)test-stackprotector-all.bin:
 	$(BUILD) -fstack-protector-all
 
-test-fortify-source.bin:
+$(OUTPUT)test-fortify-source.bin:
 	$(BUILD) -O2 -D_FORTIFY_SOURCE=2
 
-test-bionic.bin:
+$(OUTPUT)test-bionic.bin:
 	$(BUILD)
 
-test-libelf.bin:
+$(OUTPUT)test-libelf.bin:
 	$(BUILD) -lelf
 
-test-glibc.bin:
+$(OUTPUT)test-glibc.bin:
 	$(BUILD)
 
 DWARFLIBS := -ldw
@@ -77,37 +78,37 @@ ifeq ($(findstring -static,${LDFLAGS}),-static)
 DWARFLIBS += -lelf -lebl -lz -llzma -lbz2
 endif
 
-test-dwarf.bin:
+$(OUTPUT)test-dwarf.bin:
 	$(BUILD) $(DWARFLIBS)
 
-test-libelf-mmap.bin:
+$(OUTPUT)test-libelf-mmap.bin:
 	$(BUILD) -lelf
 
-test-libelf-getphdrnum.bin:
+$(OUTPUT)test-libelf-getphdrnum.bin:
 	$(BUILD) -lelf
 
-test-libnuma.bin:
+$(OUTPUT)test-libnuma.bin:
 	$(BUILD) -lnuma
 
-test-numa_num_possible_cpus.bin:
+$(OUTPUT)test-numa_num_possible_cpus.bin:
 	$(BUILD) -lnuma
 
-test-libunwind.bin:
+$(OUTPUT)test-libunwind.bin:
 	$(BUILD) -lelf
 
-test-libunwind-debug-frame.bin:
+$(OUTPUT)test-libunwind-debug-frame.bin:
 	$(BUILD) -lelf
 
-test-libaudit.bin:
+$(OUTPUT)test-libaudit.bin:
 	$(BUILD) -laudit
 
-test-libslang.bin:
+$(OUTPUT)test-libslang.bin:
 	$(BUILD) -I/usr/include/slang -lslang
 
-test-gtk2.bin:
+$(OUTPUT)test-gtk2.bin:
 	$(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
 
-test-gtk2-infobar.bin:
+$(OUTPUT)test-gtk2-infobar.bin:
 	$(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
 
 grep-libs  = $(filter -l%,$(1))
@@ -119,63 +120,63 @@ PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
 PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null`
 FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
 
-test-libperl.bin:
+$(OUTPUT)test-libperl.bin:
 	$(BUILD) $(FLAGS_PERL_EMBED)
 
-test-libpython.bin:
+$(OUTPUT)test-libpython.bin:
 	$(BUILD)
 
-test-libpython-version.bin:
+$(OUTPUT)test-libpython-version.bin:
 	$(BUILD)
 
-test-libbfd.bin:
+$(OUTPUT)test-libbfd.bin:
 	$(BUILD) -DPACKAGE='"perf"' -lbfd -lz -liberty -ldl
 
-test-liberty.bin:
-	$(CC) $(CFLAGS) -Wall -Werror -o $(OUTPUT)$@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty
+$(OUTPUT)test-liberty.bin:
+	$(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty
 
-test-liberty-z.bin:
-	$(CC) $(CFLAGS) -Wall -Werror -o $(OUTPUT)$@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty -lz
+$(OUTPUT)test-liberty-z.bin:
+	$(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty -lz
 
-test-cplus-demangle.bin:
+$(OUTPUT)test-cplus-demangle.bin:
 	$(BUILD) -liberty
 
-test-backtrace.bin:
+$(OUTPUT)test-backtrace.bin:
 	$(BUILD)
 
-test-timerfd.bin:
+$(OUTPUT)test-timerfd.bin:
 	$(BUILD)
 
-test-libdw-dwarf-unwind.bin:
+$(OUTPUT)test-libdw-dwarf-unwind.bin:
 	$(BUILD) # -ldw provided by $(FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind)
 
-test-libbabeltrace.bin:
+$(OUTPUT)test-libbabeltrace.bin:
 	$(BUILD) # -lbabeltrace provided by $(FEATURE_CHECK_LDFLAGS-libbabeltrace)
 
-test-sync-compare-and-swap.bin:
+$(OUTPUT)test-sync-compare-and-swap.bin:
 	$(BUILD)
 
-test-compile-32.bin:
-	$(CC) -m32 -o $(OUTPUT)$@ test-compile.c
+$(OUTPUT)test-compile-32.bin:
+	$(CC) -m32 -o $@ test-compile.c
 
-test-compile-x32.bin:
-	$(CC) -mx32 -o $(OUTPUT)$@ test-compile.c
+$(OUTPUT)test-compile-x32.bin:
+	$(CC) -mx32 -o $@ test-compile.c
 
-test-zlib.bin:
+$(OUTPUT)test-zlib.bin:
 	$(BUILD) -lz
 
-test-lzma.bin:
+$(OUTPUT)test-lzma.bin:
 	$(BUILD) -llzma
 
-test-get_cpuid.bin:
+$(OUTPUT)test-get_cpuid.bin:
 	$(BUILD)
 
-test-bpf.bin:
+$(OUTPUT)test-bpf.bin:
 	$(BUILD)
 
--include *.d
+-include $(OUTPUT)*.d
 
 ###############################
 
 clean:
-	rm -f $(FILES) *.d $(FILES:.bin=.make.output)
+	rm -f $(FILES) $(OUTPUT)*.d $(FILES:.bin=.make.output)
-- 
2.4.3


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

* Re: [PATCH v3 01/17] perf build: Remove unnecessary line in Makefile.feature
  2015-12-14 10:05   ` Jiri Olsa
@ 2015-12-14 15:16     ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 56+ messages in thread
From: Arnaldo Carvalho de Melo @ 2015-12-14 15:16 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Josh Poimboeuf, Peter Zijlstra, Ingo Molnar, linux-kernel, Namhyung Kim

Em Mon, Dec 14, 2015 at 11:05:07AM +0100, Jiri Olsa escreveu:
> On Sun, Dec 13, 2015 at 10:18:01PM -0600, Josh Poimboeuf wrote:
> > This line always silently fails because it doesn't add the 'test-'
> > prefix to the .bin file.
> > 
> > And it seems to be unnecessary anyway: the line immediately after it
> > does all the individual feature checks.
> > 
> > Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
> > ---
> >  tools/build/Makefile.feature | 1 -
> >  1 file changed, 1 deletion(-)
> > 
> > diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature
> > index 37ff4c9..b8c31ec 100644
> > --- a/tools/build/Makefile.feature
> > +++ b/tools/build/Makefile.feature
> > @@ -101,7 +101,6 @@ ifeq ($(feature-all), 1)
> >    #
> >    $(foreach feat,$(FEATURE_TESTS),$(call feature_set,$(feat)))
> >  else
> > -  $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS)" LDFLAGS=$(LDFLAGS) -i -j -C $(feature_dir) $(addsuffix .bin,$(FEATURE_TESTS)) >/dev/null 2>&1)
> >    $(foreach feat,$(FEATURE_TESTS),$(call feature_check,$(feat)))
> 
> ugh, nice ;-)
> 
> Acked-by: Jiri Olsa <jolsa@kernel.org>

Thanks, applied.

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

* Re: [PATCH v3.1 02/17] tools build: Fix feature Makefile dependencies for 'O='
  2015-12-14 14:29       ` [PATCH v3.1 " Josh Poimboeuf
@ 2015-12-14 15:16         ` Arnaldo Carvalho de Melo
  2015-12-14 15:29         ` Jiri Olsa
  1 sibling, 0 replies; 56+ messages in thread
From: Arnaldo Carvalho de Melo @ 2015-12-14 15:16 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Jiri Olsa, Peter Zijlstra, Ingo Molnar, linux-kernel, Namhyung Kim

Em Mon, Dec 14, 2015 at 08:29:07AM -0600, Josh Poimboeuf escreveu:
> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
> ---
>  tools/build/Makefile.feature |  2 +-
>  tools/build/feature/Makefile | 93 ++++++++++++++++++++++----------------------
>  2 files changed, 48 insertions(+), 47 deletions(-)

Jiri, Ok now?

- Arnaldo
 
> diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature
> index b8c31ec..6c0519d 100644
> --- a/tools/build/Makefile.feature
> +++ b/tools/build/Makefile.feature
> @@ -7,7 +7,7 @@ endif
>  
>  feature_check = $(eval $(feature_check_code))
>  define feature_check_code
> -  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C $(feature_dir) test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0)
> +  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C $(feature_dir) $(OUTPUT_FEATURES)test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0)
>  endef
>  
>  feature_set = $(eval $(feature_set_code))
> diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
> index cea04ce9..bf8f035 100644
> --- a/tools/build/feature/Makefile
> +++ b/tools/build/feature/Makefile
> @@ -1,4 +1,3 @@
> -
>  FILES=					\
>  	test-all.bin			\
>  	test-backtrace.bin		\
> @@ -38,38 +37,40 @@ FILES=					\
>  	test-bpf.bin			\
>  	test-get_cpuid.bin
>  
> +FILES := $(addprefix $(OUTPUT),$(FILES))
> +
>  CC := $(CROSS_COMPILE)gcc -MD
>  PKG_CONFIG := $(CROSS_COMPILE)pkg-config
>  
>  all: $(FILES)
>  
> -__BUILD = $(CC) $(CFLAGS) -Wall -Werror -o $(OUTPUT)$@ $(patsubst %.bin,%.c,$@) $(LDFLAGS)
> -  BUILD = $(__BUILD) > $(OUTPUT)$(@:.bin=.make.output) 2>&1
> +__BUILD = $(CC) $(CFLAGS) -Wall -Werror -o $@ $(patsubst %.bin,%.c,$(@F)) $(LDFLAGS)
> +  BUILD = $(__BUILD) > $(@:.bin=.make.output) 2>&1
>  
>  ###############################
>  
> -test-all.bin:
> +$(OUTPUT)test-all.bin:
>  	$(BUILD) -fstack-protector-all -O2 -D_FORTIFY_SOURCE=2 -ldw -lelf -lnuma -lelf -laudit -I/usr/include/slang -lslang $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) $(FLAGS_PERL_EMBED) $(FLAGS_PYTHON_EMBED) -DPACKAGE='"perf"' -lbfd -ldl -lz -llzma
>  
> -test-hello.bin:
> +$(OUTPUT)test-hello.bin:
>  	$(BUILD)
>  
> -test-pthread-attr-setaffinity-np.bin:
> +$(OUTPUT)test-pthread-attr-setaffinity-np.bin:
>  	$(BUILD) -D_GNU_SOURCE -lpthread
>  
> -test-stackprotector-all.bin:
> +$(OUTPUT)test-stackprotector-all.bin:
>  	$(BUILD) -fstack-protector-all
>  
> -test-fortify-source.bin:
> +$(OUTPUT)test-fortify-source.bin:
>  	$(BUILD) -O2 -D_FORTIFY_SOURCE=2
>  
> -test-bionic.bin:
> +$(OUTPUT)test-bionic.bin:
>  	$(BUILD)
>  
> -test-libelf.bin:
> +$(OUTPUT)test-libelf.bin:
>  	$(BUILD) -lelf
>  
> -test-glibc.bin:
> +$(OUTPUT)test-glibc.bin:
>  	$(BUILD)
>  
>  DWARFLIBS := -ldw
> @@ -77,37 +78,37 @@ ifeq ($(findstring -static,${LDFLAGS}),-static)
>  DWARFLIBS += -lelf -lebl -lz -llzma -lbz2
>  endif
>  
> -test-dwarf.bin:
> +$(OUTPUT)test-dwarf.bin:
>  	$(BUILD) $(DWARFLIBS)
>  
> -test-libelf-mmap.bin:
> +$(OUTPUT)test-libelf-mmap.bin:
>  	$(BUILD) -lelf
>  
> -test-libelf-getphdrnum.bin:
> +$(OUTPUT)test-libelf-getphdrnum.bin:
>  	$(BUILD) -lelf
>  
> -test-libnuma.bin:
> +$(OUTPUT)test-libnuma.bin:
>  	$(BUILD) -lnuma
>  
> -test-numa_num_possible_cpus.bin:
> +$(OUTPUT)test-numa_num_possible_cpus.bin:
>  	$(BUILD) -lnuma
>  
> -test-libunwind.bin:
> +$(OUTPUT)test-libunwind.bin:
>  	$(BUILD) -lelf
>  
> -test-libunwind-debug-frame.bin:
> +$(OUTPUT)test-libunwind-debug-frame.bin:
>  	$(BUILD) -lelf
>  
> -test-libaudit.bin:
> +$(OUTPUT)test-libaudit.bin:
>  	$(BUILD) -laudit
>  
> -test-libslang.bin:
> +$(OUTPUT)test-libslang.bin:
>  	$(BUILD) -I/usr/include/slang -lslang
>  
> -test-gtk2.bin:
> +$(OUTPUT)test-gtk2.bin:
>  	$(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
>  
> -test-gtk2-infobar.bin:
> +$(OUTPUT)test-gtk2-infobar.bin:
>  	$(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
>  
>  grep-libs  = $(filter -l%,$(1))
> @@ -119,63 +120,63 @@ PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
>  PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null`
>  FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
>  
> -test-libperl.bin:
> +$(OUTPUT)test-libperl.bin:
>  	$(BUILD) $(FLAGS_PERL_EMBED)
>  
> -test-libpython.bin:
> +$(OUTPUT)test-libpython.bin:
>  	$(BUILD)
>  
> -test-libpython-version.bin:
> +$(OUTPUT)test-libpython-version.bin:
>  	$(BUILD)
>  
> -test-libbfd.bin:
> +$(OUTPUT)test-libbfd.bin:
>  	$(BUILD) -DPACKAGE='"perf"' -lbfd -lz -liberty -ldl
>  
> -test-liberty.bin:
> -	$(CC) $(CFLAGS) -Wall -Werror -o $(OUTPUT)$@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty
> +$(OUTPUT)test-liberty.bin:
> +	$(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty
>  
> -test-liberty-z.bin:
> -	$(CC) $(CFLAGS) -Wall -Werror -o $(OUTPUT)$@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty -lz
> +$(OUTPUT)test-liberty-z.bin:
> +	$(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty -lz
>  
> -test-cplus-demangle.bin:
> +$(OUTPUT)test-cplus-demangle.bin:
>  	$(BUILD) -liberty
>  
> -test-backtrace.bin:
> +$(OUTPUT)test-backtrace.bin:
>  	$(BUILD)
>  
> -test-timerfd.bin:
> +$(OUTPUT)test-timerfd.bin:
>  	$(BUILD)
>  
> -test-libdw-dwarf-unwind.bin:
> +$(OUTPUT)test-libdw-dwarf-unwind.bin:
>  	$(BUILD) # -ldw provided by $(FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind)
>  
> -test-libbabeltrace.bin:
> +$(OUTPUT)test-libbabeltrace.bin:
>  	$(BUILD) # -lbabeltrace provided by $(FEATURE_CHECK_LDFLAGS-libbabeltrace)
>  
> -test-sync-compare-and-swap.bin:
> +$(OUTPUT)test-sync-compare-and-swap.bin:
>  	$(BUILD)
>  
> -test-compile-32.bin:
> -	$(CC) -m32 -o $(OUTPUT)$@ test-compile.c
> +$(OUTPUT)test-compile-32.bin:
> +	$(CC) -m32 -o $@ test-compile.c
>  
> -test-compile-x32.bin:
> -	$(CC) -mx32 -o $(OUTPUT)$@ test-compile.c
> +$(OUTPUT)test-compile-x32.bin:
> +	$(CC) -mx32 -o $@ test-compile.c
>  
> -test-zlib.bin:
> +$(OUTPUT)test-zlib.bin:
>  	$(BUILD) -lz
>  
> -test-lzma.bin:
> +$(OUTPUT)test-lzma.bin:
>  	$(BUILD) -llzma
>  
> -test-get_cpuid.bin:
> +$(OUTPUT)test-get_cpuid.bin:
>  	$(BUILD)
>  
> -test-bpf.bin:
> +$(OUTPUT)test-bpf.bin:
>  	$(BUILD)
>  
> --include *.d
> +-include $(OUTPUT)*.d
>  
>  ###############################
>  
>  clean:
> -	rm -f $(FILES) *.d $(FILES:.bin=.make.output)
> +	rm -f $(FILES) $(OUTPUT)*.d $(FILES:.bin=.make.output)
> -- 
> 2.4.3

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

* Re: [PATCH v3 03/17] perf test: Add Build file to dependencies for llvm-src-*.c
  2015-12-14 10:10   ` Jiri Olsa
@ 2015-12-14 15:17     ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 56+ messages in thread
From: Arnaldo Carvalho de Melo @ 2015-12-14 15:17 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Josh Poimboeuf, Peter Zijlstra, Ingo Molnar, linux-kernel, Namhyung Kim

Em Mon, Dec 14, 2015 at 11:10:43AM +0100, Jiri Olsa escreveu:
> On Sun, Dec 13, 2015 at 10:18:03PM -0600, Josh Poimboeuf wrote:
> > Because the Build file writes source code to the generated llvm-src-*.c
> > files, it should be listed as one of the dependencies, so that any
> > future changes to the code being echoed won't require a 'make clean'.
> 
> Acked-by: Jiri Olsa <jolsa@kernel.org>

Thanks, applied.
 
> thanks,
> jirka
> 
> > 
> > Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
> > ---
> >  tools/perf/tests/Build | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
> > index 0ff8a97..f23fb7e 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[] =' >> $@
> > -- 
> > 2.4.3
> > 

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

* Re: [PATCH v3 05/17] perf build: Fix 'make clean'
  2015-12-14 10:14   ` Jiri Olsa
@ 2015-12-14 15:18     ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 56+ messages in thread
From: Arnaldo Carvalho de Melo @ 2015-12-14 15:18 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Josh Poimboeuf, Peter Zijlstra, Ingo Molnar, linux-kernel, Namhyung Kim

Em Mon, Dec 14, 2015 at 11:14:21AM +0100, Jiri Olsa escreveu:
> On Sun, Dec 13, 2015 at 10:18:05PM -0600, Josh Poimboeuf wrote:
> > Add some missing files to the 'make clean' target.
> > 
> > Reported-by: Jiri Olsa <jolsa@redhat.com>
> 
> Acked-by: Jiri Olsa <jolsa@kernel.org>

Applied.
 
> thanks,
> jirka
> 
> > Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
> > ---
> >  tools/perf/Makefile.perf | 7 ++++---
> >  1 file changed, 4 insertions(+), 3 deletions(-)
> > 
> > diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
> > index 929a32b..906c723 100644
> > --- a/tools/perf/Makefile.perf
> > +++ b/tools/perf/Makefile.perf
> > @@ -582,15 +582,16 @@ $(INSTALL_DOC_TARGETS):
> >  #
> >  config-clean:
> >  	$(call QUIET_CLEAN, config)
> > -	$(Q)$(MAKE) -C $(srctree)/tools/build/feature/ clean >/dev/null
> > +	$(Q)$(MAKE) -C $(srctree)/tools/build/feature/ $(if $(OUTPUT),OUTPUT=$(OUTPUT)feature/,) clean >/dev/null
> >  
> >  clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean config-clean
> >  	$(call QUIET_CLEAN, core-objs)  $(RM) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(LANG_BINDINGS)
> > -	$(Q)find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
> > +	$(Q)find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
> >  	$(Q)$(RM) $(OUTPUT).config-detected
> >  	$(call QUIET_CLEAN, core-progs) $(RM) $(ALL_PROGRAMS) perf perf-read-vdso32 perf-read-vdsox32
> >  	$(call QUIET_CLEAN, core-gen)   $(RM)  *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope* $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)FEATURE-DUMP $(OUTPUT)util/*-bison* $(OUTPUT)util/*-flex* \
> > -		$(OUTPUT)util/intel-pt-decoder/inat-tables.c
> > +		$(OUTPUT)util/intel-pt-decoder/inat-tables.c $(OUTPUT)fixdep \
> > +		$(OUTPUT)tests/llvm-src-{base,kbuild,prologue}.c
> >  	$(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean
> >  	$(python-clean)
> >  
> > -- 
> > 2.4.3
> > 

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

* Re: [PATCH v3 06/17] perf build: Rename LIB_PATH -> API_PATH
  2015-12-14 10:34   ` Jiri Olsa
@ 2015-12-14 15:19     ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 56+ messages in thread
From: Arnaldo Carvalho de Melo @ 2015-12-14 15:19 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Josh Poimboeuf, Peter Zijlstra, Ingo Molnar, linux-kernel, Namhyung Kim

Em Mon, Dec 14, 2015 at 11:34:42AM +0100, Jiri Olsa escreveu:
> On Sun, Dec 13, 2015 at 10:18:06PM -0600, Josh Poimboeuf wrote:
> > 'LIB_PATH' is a misnomer because there are multiple library paths.
> > 
> > Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
> 
> Acked-by: Jiri Olsa <jolsa@kernel.org>

Applied.
 
> thanks,
> jirka
> 
> > ---
> >  tools/perf/Makefile.perf | 8 ++++----
> >  1 file changed, 4 insertions(+), 4 deletions(-)
> > 
> > diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
> > index 906c723..388ec64 100644
> > --- a/tools/perf/Makefile.perf
> > +++ b/tools/perf/Makefile.perf
> > @@ -185,13 +185,13 @@ ifneq ($(OUTPUT),)
> >    TE_PATH=$(OUTPUT)
> >    BPF_PATH=$(OUTPUT)
> >  ifneq ($(subdir),)
> > -  LIB_PATH=$(OUTPUT)/../lib/api/
> > +  API_PATH=$(OUTPUT)/../lib/api/
> >  else
> > -  LIB_PATH=$(OUTPUT)
> > +  API_PATH=$(OUTPUT)
> >  endif
> >  else
> >    TE_PATH=$(TRACE_EVENT_DIR)
> > -  LIB_PATH=$(LIB_DIR)
> > +  API_PATH=$(LIB_DIR)
> >    BPF_PATH=$(BPF_DIR)
> >  endif
> >  
> > @@ -201,7 +201,7 @@ export LIBTRACEEVENT
> >  LIBTRACEEVENT_DYNAMIC_LIST = $(TE_PATH)libtraceevent-dynamic-list
> >  LIBTRACEEVENT_DYNAMIC_LIST_LDFLAGS = -Xlinker --dynamic-list=$(LIBTRACEEVENT_DYNAMIC_LIST)
> >  
> > -LIBAPI = $(LIB_PATH)libapi.a
> > +LIBAPI = $(API_PATH)libapi.a
> >  export LIBAPI
> >  
> >  LIBBPF = $(BPF_PATH)libbpf.a
> > -- 
> > 2.4.3
> > 

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

* Re: [PATCH v3 15/17] perf: Finalize subcmd independence
  2015-12-14 14:13     ` Josh Poimboeuf
@ 2015-12-14 15:27       ` Jiri Olsa
  2015-12-14 15:51       ` Arnaldo Carvalho de Melo
  1 sibling, 0 replies; 56+ messages in thread
From: Jiri Olsa @ 2015-12-14 15:27 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	linux-kernel, Namhyung Kim

On Mon, Dec 14, 2015 at 08:13:59AM -0600, Josh Poimboeuf wrote:
> On Mon, Dec 14, 2015 at 11:32:20AM +0100, Jiri Olsa wrote:
> > On Sun, Dec 13, 2015 at 10:18:15PM -0600, Josh Poimboeuf wrote:
> > > For the files that will be moved to the subcmd library, remove all their
> > > perf-specific includes and duplicate any needed functionality.
> > > 
> > > Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
> > > ---
> > >  tools/perf/util/exec_cmd.c      | 75 +++++++++++++++++++++++++++++++++++++----
> > >  tools/perf/util/help.c          | 47 +++++++++++++++++++++++---
> > >  tools/perf/util/help.h          |  4 ++-
> > >  tools/perf/util/pager.c         |  7 +++-
> > >  tools/perf/util/parse-options.c | 68 +++++++++++++++++++++++--------------
> > >  tools/perf/util/parse-options.h |  2 +-
> > >  tools/perf/util/run-command.c   | 16 ++++++---
> > >  tools/perf/util/run-command.h   |  2 ++
> > >  tools/perf/util/sigchain.c      |  3 +-
> > >  tools/perf/util/subcmd-util.h   | 67 ++++++++++++++++++++++++++++++++++++
> > >  tools/perf/util/util.h          | 14 --------
> > >  11 files changed, 247 insertions(+), 58 deletions(-)
> > 
> > this duplicates functions that we have already in perf,
> > I think we better move them into lib first..
> >   strlcpy, die, xrealloc, ALLOC_GROW
> > 
> > and probably some others...
> 
> The duplication was an intentional decision we made in the v2 discussion
> in order to keep the library's scope focused on 'subcmd'.

I see, I haven't read those completely.. I guess we can unify
it (librarize it) after this change is done

jirka

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

* Re: [PATCH v3.1 02/17] tools build: Fix feature Makefile dependencies for 'O='
  2015-12-14 14:29       ` [PATCH v3.1 " Josh Poimboeuf
  2015-12-14 15:16         ` Arnaldo Carvalho de Melo
@ 2015-12-14 15:29         ` Jiri Olsa
  2015-12-14 15:38           ` Josh Poimboeuf
  1 sibling, 1 reply; 56+ messages in thread
From: Jiri Olsa @ 2015-12-14 15:29 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	linux-kernel, Namhyung Kim

On Mon, Dec 14, 2015 at 08:29:07AM -0600, Josh Poimboeuf wrote:
> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>

you might want to work on your changelogs
a little..  aaand actually include some ;-)

did you update your branch with this change?

jirka

> ---
>  tools/build/Makefile.feature |  2 +-
>  tools/build/feature/Makefile | 93 ++++++++++++++++++++++----------------------
>  2 files changed, 48 insertions(+), 47 deletions(-)
> 
> diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature
> index b8c31ec..6c0519d 100644
> --- a/tools/build/Makefile.feature
> +++ b/tools/build/Makefile.feature
> @@ -7,7 +7,7 @@ endif
>  
>  feature_check = $(eval $(feature_check_code))
>  define feature_check_code
> -  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C $(feature_dir) test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0)
> +  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C $(feature_dir) $(OUTPUT_FEATURES)test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0)
>  endef
>  
>  feature_set = $(eval $(feature_set_code))
> diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
> index cea04ce9..bf8f035 100644
> --- a/tools/build/feature/Makefile
> +++ b/tools/build/feature/Makefile
> @@ -1,4 +1,3 @@
> -
>  FILES=					\
>  	test-all.bin			\
>  	test-backtrace.bin		\
> @@ -38,38 +37,40 @@ FILES=					\
>  	test-bpf.bin			\
>  	test-get_cpuid.bin
>  
> +FILES := $(addprefix $(OUTPUT),$(FILES))
> +
>  CC := $(CROSS_COMPILE)gcc -MD
>  PKG_CONFIG := $(CROSS_COMPILE)pkg-config
>  
>  all: $(FILES)
>  
> -__BUILD = $(CC) $(CFLAGS) -Wall -Werror -o $(OUTPUT)$@ $(patsubst %.bin,%.c,$@) $(LDFLAGS)
> -  BUILD = $(__BUILD) > $(OUTPUT)$(@:.bin=.make.output) 2>&1
> +__BUILD = $(CC) $(CFLAGS) -Wall -Werror -o $@ $(patsubst %.bin,%.c,$(@F)) $(LDFLAGS)
> +  BUILD = $(__BUILD) > $(@:.bin=.make.output) 2>&1
>  
>  ###############################
>  
> -test-all.bin:
> +$(OUTPUT)test-all.bin:
>  	$(BUILD) -fstack-protector-all -O2 -D_FORTIFY_SOURCE=2 -ldw -lelf -lnuma -lelf -laudit -I/usr/include/slang -lslang $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) $(FLAGS_PERL_EMBED) $(FLAGS_PYTHON_EMBED) -DPACKAGE='"perf"' -lbfd -ldl -lz -llzma
>  
> -test-hello.bin:
> +$(OUTPUT)test-hello.bin:
>  	$(BUILD)
>  
> -test-pthread-attr-setaffinity-np.bin:
> +$(OUTPUT)test-pthread-attr-setaffinity-np.bin:
>  	$(BUILD) -D_GNU_SOURCE -lpthread
>  
> -test-stackprotector-all.bin:
> +$(OUTPUT)test-stackprotector-all.bin:
>  	$(BUILD) -fstack-protector-all
>  
> -test-fortify-source.bin:
> +$(OUTPUT)test-fortify-source.bin:
>  	$(BUILD) -O2 -D_FORTIFY_SOURCE=2
>  
> -test-bionic.bin:
> +$(OUTPUT)test-bionic.bin:
>  	$(BUILD)
>  
> -test-libelf.bin:
> +$(OUTPUT)test-libelf.bin:
>  	$(BUILD) -lelf
>  
> -test-glibc.bin:
> +$(OUTPUT)test-glibc.bin:
>  	$(BUILD)
>  
>  DWARFLIBS := -ldw
> @@ -77,37 +78,37 @@ ifeq ($(findstring -static,${LDFLAGS}),-static)
>  DWARFLIBS += -lelf -lebl -lz -llzma -lbz2
>  endif
>  
> -test-dwarf.bin:
> +$(OUTPUT)test-dwarf.bin:
>  	$(BUILD) $(DWARFLIBS)
>  
> -test-libelf-mmap.bin:
> +$(OUTPUT)test-libelf-mmap.bin:
>  	$(BUILD) -lelf
>  
> -test-libelf-getphdrnum.bin:
> +$(OUTPUT)test-libelf-getphdrnum.bin:
>  	$(BUILD) -lelf
>  
> -test-libnuma.bin:
> +$(OUTPUT)test-libnuma.bin:
>  	$(BUILD) -lnuma
>  
> -test-numa_num_possible_cpus.bin:
> +$(OUTPUT)test-numa_num_possible_cpus.bin:
>  	$(BUILD) -lnuma
>  
> -test-libunwind.bin:
> +$(OUTPUT)test-libunwind.bin:
>  	$(BUILD) -lelf
>  
> -test-libunwind-debug-frame.bin:
> +$(OUTPUT)test-libunwind-debug-frame.bin:
>  	$(BUILD) -lelf
>  
> -test-libaudit.bin:
> +$(OUTPUT)test-libaudit.bin:
>  	$(BUILD) -laudit
>  
> -test-libslang.bin:
> +$(OUTPUT)test-libslang.bin:
>  	$(BUILD) -I/usr/include/slang -lslang
>  
> -test-gtk2.bin:
> +$(OUTPUT)test-gtk2.bin:
>  	$(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
>  
> -test-gtk2-infobar.bin:
> +$(OUTPUT)test-gtk2-infobar.bin:
>  	$(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
>  
>  grep-libs  = $(filter -l%,$(1))
> @@ -119,63 +120,63 @@ PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
>  PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null`
>  FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
>  
> -test-libperl.bin:
> +$(OUTPUT)test-libperl.bin:
>  	$(BUILD) $(FLAGS_PERL_EMBED)
>  
> -test-libpython.bin:
> +$(OUTPUT)test-libpython.bin:
>  	$(BUILD)
>  
> -test-libpython-version.bin:
> +$(OUTPUT)test-libpython-version.bin:
>  	$(BUILD)
>  
> -test-libbfd.bin:
> +$(OUTPUT)test-libbfd.bin:
>  	$(BUILD) -DPACKAGE='"perf"' -lbfd -lz -liberty -ldl
>  
> -test-liberty.bin:
> -	$(CC) $(CFLAGS) -Wall -Werror -o $(OUTPUT)$@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty
> +$(OUTPUT)test-liberty.bin:
> +	$(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty
>  
> -test-liberty-z.bin:
> -	$(CC) $(CFLAGS) -Wall -Werror -o $(OUTPUT)$@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty -lz
> +$(OUTPUT)test-liberty-z.bin:
> +	$(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty -lz
>  
> -test-cplus-demangle.bin:
> +$(OUTPUT)test-cplus-demangle.bin:
>  	$(BUILD) -liberty
>  
> -test-backtrace.bin:
> +$(OUTPUT)test-backtrace.bin:
>  	$(BUILD)
>  
> -test-timerfd.bin:
> +$(OUTPUT)test-timerfd.bin:
>  	$(BUILD)
>  
> -test-libdw-dwarf-unwind.bin:
> +$(OUTPUT)test-libdw-dwarf-unwind.bin:
>  	$(BUILD) # -ldw provided by $(FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind)
>  
> -test-libbabeltrace.bin:
> +$(OUTPUT)test-libbabeltrace.bin:
>  	$(BUILD) # -lbabeltrace provided by $(FEATURE_CHECK_LDFLAGS-libbabeltrace)
>  
> -test-sync-compare-and-swap.bin:
> +$(OUTPUT)test-sync-compare-and-swap.bin:
>  	$(BUILD)
>  
> -test-compile-32.bin:
> -	$(CC) -m32 -o $(OUTPUT)$@ test-compile.c
> +$(OUTPUT)test-compile-32.bin:
> +	$(CC) -m32 -o $@ test-compile.c
>  
> -test-compile-x32.bin:
> -	$(CC) -mx32 -o $(OUTPUT)$@ test-compile.c
> +$(OUTPUT)test-compile-x32.bin:
> +	$(CC) -mx32 -o $@ test-compile.c
>  
> -test-zlib.bin:
> +$(OUTPUT)test-zlib.bin:
>  	$(BUILD) -lz
>  
> -test-lzma.bin:
> +$(OUTPUT)test-lzma.bin:
>  	$(BUILD) -llzma
>  
> -test-get_cpuid.bin:
> +$(OUTPUT)test-get_cpuid.bin:
>  	$(BUILD)
>  
> -test-bpf.bin:
> +$(OUTPUT)test-bpf.bin:
>  	$(BUILD)
>  
> --include *.d
> +-include $(OUTPUT)*.d
>  
>  ###############################
>  
>  clean:
> -	rm -f $(FILES) *.d $(FILES:.bin=.make.output)
> +	rm -f $(FILES) $(OUTPUT)*.d $(FILES:.bin=.make.output)
> -- 
> 2.4.3
> 

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

* Re: [PATCH v3.1 02/17] tools build: Fix feature Makefile dependencies for 'O='
  2015-12-14 15:29         ` Jiri Olsa
@ 2015-12-14 15:38           ` Josh Poimboeuf
  2015-12-14 15:55             ` Jiri Olsa
  0 siblings, 1 reply; 56+ messages in thread
From: Josh Poimboeuf @ 2015-12-14 15:38 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	linux-kernel, Namhyung Kim

On Mon, Dec 14, 2015 at 04:29:39PM +0100, Jiri Olsa wrote:
> On Mon, Dec 14, 2015 at 08:29:07AM -0600, Josh Poimboeuf wrote:
> > Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
> 
> you might want to work on your changelogs
> a little..  aaand actually include some ;-)

Well, I thought the subject said it all :-)

> did you update your branch with this change?

Sure, see branch 'perf-subcmd-v3.1':

  https://github.com/jpoimboe/linux

> 
> jirka
> 
> > ---
> >  tools/build/Makefile.feature |  2 +-
> >  tools/build/feature/Makefile | 93 ++++++++++++++++++++++----------------------
> >  2 files changed, 48 insertions(+), 47 deletions(-)
> > 
> > diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature
> > index b8c31ec..6c0519d 100644
> > --- a/tools/build/Makefile.feature
> > +++ b/tools/build/Makefile.feature
> > @@ -7,7 +7,7 @@ endif
> >  
> >  feature_check = $(eval $(feature_check_code))
> >  define feature_check_code
> > -  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C $(feature_dir) test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0)
> > +  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C $(feature_dir) $(OUTPUT_FEATURES)test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0)
> >  endef
> >  
> >  feature_set = $(eval $(feature_set_code))
> > diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
> > index cea04ce9..bf8f035 100644
> > --- a/tools/build/feature/Makefile
> > +++ b/tools/build/feature/Makefile
> > @@ -1,4 +1,3 @@
> > -
> >  FILES=					\
> >  	test-all.bin			\
> >  	test-backtrace.bin		\
> > @@ -38,38 +37,40 @@ FILES=					\
> >  	test-bpf.bin			\
> >  	test-get_cpuid.bin
> >  
> > +FILES := $(addprefix $(OUTPUT),$(FILES))
> > +
> >  CC := $(CROSS_COMPILE)gcc -MD
> >  PKG_CONFIG := $(CROSS_COMPILE)pkg-config
> >  
> >  all: $(FILES)
> >  
> > -__BUILD = $(CC) $(CFLAGS) -Wall -Werror -o $(OUTPUT)$@ $(patsubst %.bin,%.c,$@) $(LDFLAGS)
> > -  BUILD = $(__BUILD) > $(OUTPUT)$(@:.bin=.make.output) 2>&1
> > +__BUILD = $(CC) $(CFLAGS) -Wall -Werror -o $@ $(patsubst %.bin,%.c,$(@F)) $(LDFLAGS)
> > +  BUILD = $(__BUILD) > $(@:.bin=.make.output) 2>&1
> >  
> >  ###############################
> >  
> > -test-all.bin:
> > +$(OUTPUT)test-all.bin:
> >  	$(BUILD) -fstack-protector-all -O2 -D_FORTIFY_SOURCE=2 -ldw -lelf -lnuma -lelf -laudit -I/usr/include/slang -lslang $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) $(FLAGS_PERL_EMBED) $(FLAGS_PYTHON_EMBED) -DPACKAGE='"perf"' -lbfd -ldl -lz -llzma
> >  
> > -test-hello.bin:
> > +$(OUTPUT)test-hello.bin:
> >  	$(BUILD)
> >  
> > -test-pthread-attr-setaffinity-np.bin:
> > +$(OUTPUT)test-pthread-attr-setaffinity-np.bin:
> >  	$(BUILD) -D_GNU_SOURCE -lpthread
> >  
> > -test-stackprotector-all.bin:
> > +$(OUTPUT)test-stackprotector-all.bin:
> >  	$(BUILD) -fstack-protector-all
> >  
> > -test-fortify-source.bin:
> > +$(OUTPUT)test-fortify-source.bin:
> >  	$(BUILD) -O2 -D_FORTIFY_SOURCE=2
> >  
> > -test-bionic.bin:
> > +$(OUTPUT)test-bionic.bin:
> >  	$(BUILD)
> >  
> > -test-libelf.bin:
> > +$(OUTPUT)test-libelf.bin:
> >  	$(BUILD) -lelf
> >  
> > -test-glibc.bin:
> > +$(OUTPUT)test-glibc.bin:
> >  	$(BUILD)
> >  
> >  DWARFLIBS := -ldw
> > @@ -77,37 +78,37 @@ ifeq ($(findstring -static,${LDFLAGS}),-static)
> >  DWARFLIBS += -lelf -lebl -lz -llzma -lbz2
> >  endif
> >  
> > -test-dwarf.bin:
> > +$(OUTPUT)test-dwarf.bin:
> >  	$(BUILD) $(DWARFLIBS)
> >  
> > -test-libelf-mmap.bin:
> > +$(OUTPUT)test-libelf-mmap.bin:
> >  	$(BUILD) -lelf
> >  
> > -test-libelf-getphdrnum.bin:
> > +$(OUTPUT)test-libelf-getphdrnum.bin:
> >  	$(BUILD) -lelf
> >  
> > -test-libnuma.bin:
> > +$(OUTPUT)test-libnuma.bin:
> >  	$(BUILD) -lnuma
> >  
> > -test-numa_num_possible_cpus.bin:
> > +$(OUTPUT)test-numa_num_possible_cpus.bin:
> >  	$(BUILD) -lnuma
> >  
> > -test-libunwind.bin:
> > +$(OUTPUT)test-libunwind.bin:
> >  	$(BUILD) -lelf
> >  
> > -test-libunwind-debug-frame.bin:
> > +$(OUTPUT)test-libunwind-debug-frame.bin:
> >  	$(BUILD) -lelf
> >  
> > -test-libaudit.bin:
> > +$(OUTPUT)test-libaudit.bin:
> >  	$(BUILD) -laudit
> >  
> > -test-libslang.bin:
> > +$(OUTPUT)test-libslang.bin:
> >  	$(BUILD) -I/usr/include/slang -lslang
> >  
> > -test-gtk2.bin:
> > +$(OUTPUT)test-gtk2.bin:
> >  	$(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
> >  
> > -test-gtk2-infobar.bin:
> > +$(OUTPUT)test-gtk2-infobar.bin:
> >  	$(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
> >  
> >  grep-libs  = $(filter -l%,$(1))
> > @@ -119,63 +120,63 @@ PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
> >  PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null`
> >  FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
> >  
> > -test-libperl.bin:
> > +$(OUTPUT)test-libperl.bin:
> >  	$(BUILD) $(FLAGS_PERL_EMBED)
> >  
> > -test-libpython.bin:
> > +$(OUTPUT)test-libpython.bin:
> >  	$(BUILD)
> >  
> > -test-libpython-version.bin:
> > +$(OUTPUT)test-libpython-version.bin:
> >  	$(BUILD)
> >  
> > -test-libbfd.bin:
> > +$(OUTPUT)test-libbfd.bin:
> >  	$(BUILD) -DPACKAGE='"perf"' -lbfd -lz -liberty -ldl
> >  
> > -test-liberty.bin:
> > -	$(CC) $(CFLAGS) -Wall -Werror -o $(OUTPUT)$@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty
> > +$(OUTPUT)test-liberty.bin:
> > +	$(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty
> >  
> > -test-liberty-z.bin:
> > -	$(CC) $(CFLAGS) -Wall -Werror -o $(OUTPUT)$@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty -lz
> > +$(OUTPUT)test-liberty-z.bin:
> > +	$(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty -lz
> >  
> > -test-cplus-demangle.bin:
> > +$(OUTPUT)test-cplus-demangle.bin:
> >  	$(BUILD) -liberty
> >  
> > -test-backtrace.bin:
> > +$(OUTPUT)test-backtrace.bin:
> >  	$(BUILD)
> >  
> > -test-timerfd.bin:
> > +$(OUTPUT)test-timerfd.bin:
> >  	$(BUILD)
> >  
> > -test-libdw-dwarf-unwind.bin:
> > +$(OUTPUT)test-libdw-dwarf-unwind.bin:
> >  	$(BUILD) # -ldw provided by $(FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind)
> >  
> > -test-libbabeltrace.bin:
> > +$(OUTPUT)test-libbabeltrace.bin:
> >  	$(BUILD) # -lbabeltrace provided by $(FEATURE_CHECK_LDFLAGS-libbabeltrace)
> >  
> > -test-sync-compare-and-swap.bin:
> > +$(OUTPUT)test-sync-compare-and-swap.bin:
> >  	$(BUILD)
> >  
> > -test-compile-32.bin:
> > -	$(CC) -m32 -o $(OUTPUT)$@ test-compile.c
> > +$(OUTPUT)test-compile-32.bin:
> > +	$(CC) -m32 -o $@ test-compile.c
> >  
> > -test-compile-x32.bin:
> > -	$(CC) -mx32 -o $(OUTPUT)$@ test-compile.c
> > +$(OUTPUT)test-compile-x32.bin:
> > +	$(CC) -mx32 -o $@ test-compile.c
> >  
> > -test-zlib.bin:
> > +$(OUTPUT)test-zlib.bin:
> >  	$(BUILD) -lz
> >  
> > -test-lzma.bin:
> > +$(OUTPUT)test-lzma.bin:
> >  	$(BUILD) -llzma
> >  
> > -test-get_cpuid.bin:
> > +$(OUTPUT)test-get_cpuid.bin:
> >  	$(BUILD)
> >  
> > -test-bpf.bin:
> > +$(OUTPUT)test-bpf.bin:
> >  	$(BUILD)
> >  
> > --include *.d
> > +-include $(OUTPUT)*.d
> >  
> >  ###############################
> >  
> >  clean:
> > -	rm -f $(FILES) *.d $(FILES:.bin=.make.output)
> > +	rm -f $(FILES) $(OUTPUT)*.d $(FILES:.bin=.make.output)
> > -- 
> > 2.4.3
> > 

-- 
Josh

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

* Re: [PATCH v3 14/17] perf: Remove subcmd dependencies on strbuf
  2015-12-14  4:18 ` [PATCH v3 14/17] perf: Remove subcmd dependencies on strbuf Josh Poimboeuf
  2015-12-14 10:25   ` Jiri Olsa
@ 2015-12-14 15:44   ` Arnaldo Carvalho de Melo
  2015-12-14 16:05     ` Josh Poimboeuf
  1 sibling, 1 reply; 56+ messages in thread
From: Arnaldo Carvalho de Melo @ 2015-12-14 15:44 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Peter Zijlstra, Ingo Molnar, linux-kernel, Jiri Olsa, Namhyung Kim

Em Sun, Dec 13, 2015 at 10:18:14PM -0600, Josh Poimboeuf escreveu:
> Introduce and use new astrcat() and astrcatf() functions which replace
> the strbuf functionality for subcmd.

<SNIP>
 
> diff --git a/tools/perf/util/subcmd-util.h b/tools/perf/util/subcmd-util.h
> new file mode 100644
> index 0000000..98fb9f9
> --- /dev/null
> +++ b/tools/perf/util/subcmd-util.h
> @@ -0,0 +1,24 @@
> +#ifndef __PERF_SUBCMD_UTIL_H
> +#define __PERF_SUBCMD_UTIL_H
> +
> +#include <stdio.h>
> +
> +#define astrcatf(out, fmt, ...)						\
> +({									\
> +	char *tmp = *(out);						\
> +	if (asprintf((out), "%s" fmt, tmp ?: "", ## __VA_ARGS__) == -1)	\
> +		die("asprintf failed");					\
> +	free(tmp);							\
> +})

Hey, don't add die() calls, please.

> +
> +static inline void astrcat(char **out, const char *add)
> +{
> +	char *tmp = *out;
> +
> +	if (asprintf(out, "%s%s", tmp ?: "", add) == -1)
> +		die("asprintf failed");
> +
> +	free(tmp);

Ditto.

And I think that this should go into tools/include/string.h and
tools/lib/string.c, no?

We should try to look at the kernel and try to follow naming, semantics,
etc as much as possible. The kernel doesn't have a astrcat, just
kasprintf() (that is in linux/kernel.h, perhaps because in userland
asprintf is in stdio.h, not in string.h) , wonder how something like
astrcat is done there... Doing some research now.

- Arnaldo

> +}
> +
> +#endif /* __PERF_SUBCMD_UTIL_H */
> -- 
> 2.4.3

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

* Re: [PATCH v3 15/17] perf: Finalize subcmd independence
  2015-12-14 14:13     ` Josh Poimboeuf
  2015-12-14 15:27       ` Jiri Olsa
@ 2015-12-14 15:51       ` Arnaldo Carvalho de Melo
  1 sibling, 0 replies; 56+ messages in thread
From: Arnaldo Carvalho de Melo @ 2015-12-14 15:51 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Jiri Olsa, Peter Zijlstra, Ingo Molnar, linux-kernel, Namhyung Kim

Em Mon, Dec 14, 2015 at 08:13:59AM -0600, Josh Poimboeuf escreveu:
> On Mon, Dec 14, 2015 at 11:32:20AM +0100, Jiri Olsa wrote:
> > On Sun, Dec 13, 2015 at 10:18:15PM -0600, Josh Poimboeuf wrote:
> > > For the files that will be moved to the subcmd library, remove all their
> > > perf-specific includes and duplicate any needed functionality.
> > > 
> > > Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
> > > ---
> > >  tools/perf/util/exec_cmd.c      | 75 +++++++++++++++++++++++++++++++++++++----
> > >  tools/perf/util/help.c          | 47 +++++++++++++++++++++++---
> > >  tools/perf/util/help.h          |  4 ++-
> > >  tools/perf/util/pager.c         |  7 +++-
> > >  tools/perf/util/parse-options.c | 68 +++++++++++++++++++++++--------------
> > >  tools/perf/util/parse-options.h |  2 +-
> > >  tools/perf/util/run-command.c   | 16 ++++++---
> > >  tools/perf/util/run-command.h   |  2 ++
> > >  tools/perf/util/sigchain.c      |  3 +-
> > >  tools/perf/util/subcmd-util.h   | 67 ++++++++++++++++++++++++++++++++++++
> > >  tools/perf/util/util.h          | 14 --------
> > >  11 files changed, 247 insertions(+), 58 deletions(-)
> > 
> > this duplicates functions that we have already in perf,
> > I think we better move them into lib first..
> >   strlcpy, die, xrealloc, ALLOC_GROW

Some stuff should move to other, non-subcmd libraries that will then be
used by both subcmd, tools/perf/, etc, while some we take the oportunity
to kill, like die() and perhaps strbuf :-)

> > and probably some others...
> 
> The duplication was an intentional decision we made in the v2 discussion
> in order to keep the library's scope focused on 'subcmd'.

Ok, I merged a good chunk now, will push soon.

- Arnaldo

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

* Re: [PATCH v3.1 02/17] tools build: Fix feature Makefile dependencies for 'O='
  2015-12-14 15:38           ` Josh Poimboeuf
@ 2015-12-14 15:55             ` Jiri Olsa
  2015-12-14 16:03               ` Josh Poimboeuf
  2015-12-14 18:32               ` [PATCH v3.2] tools build: Fix feature Makefile issues with 'O=' Josh Poimboeuf
  0 siblings, 2 replies; 56+ messages in thread
From: Jiri Olsa @ 2015-12-14 15:55 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	linux-kernel, Namhyung Kim

On Mon, Dec 14, 2015 at 09:38:15AM -0600, Josh Poimboeuf wrote:
> On Mon, Dec 14, 2015 at 04:29:39PM +0100, Jiri Olsa wrote:
> > On Mon, Dec 14, 2015 at 08:29:07AM -0600, Josh Poimboeuf wrote:
> > > Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
> > 
> > you might want to work on your changelogs
> > a little..  aaand actually include some ;-)
> 
> Well, I thought the subject said it all :-)

well, you could be more specific, like:
- how was it broken before
- what did you do to fix it
- how you added a test case to ensure this will never happen again ;-)

it makes the life of reviewer a bit easier, anyway:

Acked-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka

> 
> > did you update your branch with this change?
> 
> Sure, see branch 'perf-subcmd-v3.1':
> 
>   https://github.com/jpoimboe/linux
> 
> > 
> > jirka
> > 
> > > ---
> > >  tools/build/Makefile.feature |  2 +-
> > >  tools/build/feature/Makefile | 93 ++++++++++++++++++++++----------------------
> > >  2 files changed, 48 insertions(+), 47 deletions(-)


> > > 
> > > diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature
> > > index b8c31ec..6c0519d 100644
> > > --- a/tools/build/Makefile.feature
> > > +++ b/tools/build/Makefile.feature
> > > @@ -7,7 +7,7 @@ endif
> > >  
> > >  feature_check = $(eval $(feature_check_code))
> > >  define feature_check_code
> > > -  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C $(feature_dir) test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0)
> > > +  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C $(feature_dir) $(OUTPUT_FEATURES)test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0)
> > >  endef
> > >  
> > >  feature_set = $(eval $(feature_set_code))
> > > diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
> > > index cea04ce9..bf8f035 100644
> > > --- a/tools/build/feature/Makefile
> > > +++ b/tools/build/feature/Makefile
> > > @@ -1,4 +1,3 @@
> > > -
> > >  FILES=					\
> > >  	test-all.bin			\
> > >  	test-backtrace.bin		\
> > > @@ -38,38 +37,40 @@ FILES=					\
> > >  	test-bpf.bin			\
> > >  	test-get_cpuid.bin
> > >  
> > > +FILES := $(addprefix $(OUTPUT),$(FILES))
> > > +
> > >  CC := $(CROSS_COMPILE)gcc -MD
> > >  PKG_CONFIG := $(CROSS_COMPILE)pkg-config
> > >  
> > >  all: $(FILES)
> > >  
> > > -__BUILD = $(CC) $(CFLAGS) -Wall -Werror -o $(OUTPUT)$@ $(patsubst %.bin,%.c,$@) $(LDFLAGS)
> > > -  BUILD = $(__BUILD) > $(OUTPUT)$(@:.bin=.make.output) 2>&1
> > > +__BUILD = $(CC) $(CFLAGS) -Wall -Werror -o $@ $(patsubst %.bin,%.c,$(@F)) $(LDFLAGS)
> > > +  BUILD = $(__BUILD) > $(@:.bin=.make.output) 2>&1
> > >  
> > >  ###############################
> > >  
> > > -test-all.bin:
> > > +$(OUTPUT)test-all.bin:
> > >  	$(BUILD) -fstack-protector-all -O2 -D_FORTIFY_SOURCE=2 -ldw -lelf -lnuma -lelf -laudit -I/usr/include/slang -lslang $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) $(FLAGS_PERL_EMBED) $(FLAGS_PYTHON_EMBED) -DPACKAGE='"perf"' -lbfd -ldl -lz -llzma
> > >  
> > > -test-hello.bin:
> > > +$(OUTPUT)test-hello.bin:
> > >  	$(BUILD)
> > >  
> > > -test-pthread-attr-setaffinity-np.bin:
> > > +$(OUTPUT)test-pthread-attr-setaffinity-np.bin:
> > >  	$(BUILD) -D_GNU_SOURCE -lpthread
> > >  
> > > -test-stackprotector-all.bin:
> > > +$(OUTPUT)test-stackprotector-all.bin:
> > >  	$(BUILD) -fstack-protector-all
> > >  
> > > -test-fortify-source.bin:
> > > +$(OUTPUT)test-fortify-source.bin:
> > >  	$(BUILD) -O2 -D_FORTIFY_SOURCE=2
> > >  
> > > -test-bionic.bin:
> > > +$(OUTPUT)test-bionic.bin:
> > >  	$(BUILD)
> > >  
> > > -test-libelf.bin:
> > > +$(OUTPUT)test-libelf.bin:
> > >  	$(BUILD) -lelf
> > >  
> > > -test-glibc.bin:
> > > +$(OUTPUT)test-glibc.bin:
> > >  	$(BUILD)
> > >  
> > >  DWARFLIBS := -ldw
> > > @@ -77,37 +78,37 @@ ifeq ($(findstring -static,${LDFLAGS}),-static)
> > >  DWARFLIBS += -lelf -lebl -lz -llzma -lbz2
> > >  endif
> > >  
> > > -test-dwarf.bin:
> > > +$(OUTPUT)test-dwarf.bin:
> > >  	$(BUILD) $(DWARFLIBS)
> > >  
> > > -test-libelf-mmap.bin:
> > > +$(OUTPUT)test-libelf-mmap.bin:
> > >  	$(BUILD) -lelf
> > >  
> > > -test-libelf-getphdrnum.bin:
> > > +$(OUTPUT)test-libelf-getphdrnum.bin:
> > >  	$(BUILD) -lelf
> > >  
> > > -test-libnuma.bin:
> > > +$(OUTPUT)test-libnuma.bin:
> > >  	$(BUILD) -lnuma
> > >  
> > > -test-numa_num_possible_cpus.bin:
> > > +$(OUTPUT)test-numa_num_possible_cpus.bin:
> > >  	$(BUILD) -lnuma
> > >  
> > > -test-libunwind.bin:
> > > +$(OUTPUT)test-libunwind.bin:
> > >  	$(BUILD) -lelf
> > >  
> > > -test-libunwind-debug-frame.bin:
> > > +$(OUTPUT)test-libunwind-debug-frame.bin:
> > >  	$(BUILD) -lelf
> > >  
> > > -test-libaudit.bin:
> > > +$(OUTPUT)test-libaudit.bin:
> > >  	$(BUILD) -laudit
> > >  
> > > -test-libslang.bin:
> > > +$(OUTPUT)test-libslang.bin:
> > >  	$(BUILD) -I/usr/include/slang -lslang
> > >  
> > > -test-gtk2.bin:
> > > +$(OUTPUT)test-gtk2.bin:
> > >  	$(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
> > >  
> > > -test-gtk2-infobar.bin:
> > > +$(OUTPUT)test-gtk2-infobar.bin:
> > >  	$(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
> > >  
> > >  grep-libs  = $(filter -l%,$(1))
> > > @@ -119,63 +120,63 @@ PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
> > >  PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null`
> > >  FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
> > >  
> > > -test-libperl.bin:
> > > +$(OUTPUT)test-libperl.bin:
> > >  	$(BUILD) $(FLAGS_PERL_EMBED)
> > >  
> > > -test-libpython.bin:
> > > +$(OUTPUT)test-libpython.bin:
> > >  	$(BUILD)
> > >  
> > > -test-libpython-version.bin:
> > > +$(OUTPUT)test-libpython-version.bin:
> > >  	$(BUILD)
> > >  
> > > -test-libbfd.bin:
> > > +$(OUTPUT)test-libbfd.bin:
> > >  	$(BUILD) -DPACKAGE='"perf"' -lbfd -lz -liberty -ldl
> > >  
> > > -test-liberty.bin:
> > > -	$(CC) $(CFLAGS) -Wall -Werror -o $(OUTPUT)$@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty
> > > +$(OUTPUT)test-liberty.bin:
> > > +	$(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty
> > >  
> > > -test-liberty-z.bin:
> > > -	$(CC) $(CFLAGS) -Wall -Werror -o $(OUTPUT)$@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty -lz
> > > +$(OUTPUT)test-liberty-z.bin:
> > > +	$(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty -lz
> > >  
> > > -test-cplus-demangle.bin:
> > > +$(OUTPUT)test-cplus-demangle.bin:
> > >  	$(BUILD) -liberty
> > >  
> > > -test-backtrace.bin:
> > > +$(OUTPUT)test-backtrace.bin:
> > >  	$(BUILD)
> > >  
> > > -test-timerfd.bin:
> > > +$(OUTPUT)test-timerfd.bin:
> > >  	$(BUILD)
> > >  
> > > -test-libdw-dwarf-unwind.bin:
> > > +$(OUTPUT)test-libdw-dwarf-unwind.bin:
> > >  	$(BUILD) # -ldw provided by $(FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind)
> > >  
> > > -test-libbabeltrace.bin:
> > > +$(OUTPUT)test-libbabeltrace.bin:
> > >  	$(BUILD) # -lbabeltrace provided by $(FEATURE_CHECK_LDFLAGS-libbabeltrace)
> > >  
> > > -test-sync-compare-and-swap.bin:
> > > +$(OUTPUT)test-sync-compare-and-swap.bin:
> > >  	$(BUILD)
> > >  
> > > -test-compile-32.bin:
> > > -	$(CC) -m32 -o $(OUTPUT)$@ test-compile.c
> > > +$(OUTPUT)test-compile-32.bin:
> > > +	$(CC) -m32 -o $@ test-compile.c
> > >  
> > > -test-compile-x32.bin:
> > > -	$(CC) -mx32 -o $(OUTPUT)$@ test-compile.c
> > > +$(OUTPUT)test-compile-x32.bin:
> > > +	$(CC) -mx32 -o $@ test-compile.c
> > >  
> > > -test-zlib.bin:
> > > +$(OUTPUT)test-zlib.bin:
> > >  	$(BUILD) -lz
> > >  
> > > -test-lzma.bin:
> > > +$(OUTPUT)test-lzma.bin:
> > >  	$(BUILD) -llzma
> > >  
> > > -test-get_cpuid.bin:
> > > +$(OUTPUT)test-get_cpuid.bin:
> > >  	$(BUILD)
> > >  
> > > -test-bpf.bin:
> > > +$(OUTPUT)test-bpf.bin:
> > >  	$(BUILD)
> > >  
> > > --include *.d
> > > +-include $(OUTPUT)*.d
> > >  
> > >  ###############################
> > >  
> > >  clean:
> > > -	rm -f $(FILES) *.d $(FILES:.bin=.make.output)
> > > +	rm -f $(FILES) $(OUTPUT)*.d $(FILES:.bin=.make.output)
> > > -- 
> > > 2.4.3
> > > 
> 
> -- 
> Josh

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

* Re: [PATCH v3.1 02/17] tools build: Fix feature Makefile dependencies for 'O='
  2015-12-14 15:55             ` Jiri Olsa
@ 2015-12-14 16:03               ` Josh Poimboeuf
  2015-12-14 18:32               ` [PATCH v3.2] tools build: Fix feature Makefile issues with 'O=' Josh Poimboeuf
  1 sibling, 0 replies; 56+ messages in thread
From: Josh Poimboeuf @ 2015-12-14 16:03 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	linux-kernel, Namhyung Kim

On Mon, Dec 14, 2015 at 04:55:28PM +0100, Jiri Olsa wrote:
> On Mon, Dec 14, 2015 at 09:38:15AM -0600, Josh Poimboeuf wrote:
> > On Mon, Dec 14, 2015 at 04:29:39PM +0100, Jiri Olsa wrote:
> > > On Mon, Dec 14, 2015 at 08:29:07AM -0600, Josh Poimboeuf wrote:
> > > > Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
> > > 
> > > you might want to work on your changelogs
> > > a little..  aaand actually include some ;-)
> > 
> > Well, I thought the subject said it all :-)
> 
> well, you could be more specific, like:
> - how was it broken before
> - what did you do to fix it
> - how you added a test case to ensure this will never happen again ;-)
> 
> it makes the life of reviewer a bit easier, anyway:
> 
> Acked-by: Jiri Olsa <jolsa@kernel.org>

Thanks.  I'll try to be more verbose in future changelogs.

-- 
Josh

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

* Re: [PATCH v3 14/17] perf: Remove subcmd dependencies on strbuf
  2015-12-14 15:44   ` Arnaldo Carvalho de Melo
@ 2015-12-14 16:05     ` Josh Poimboeuf
  2015-12-14 17:50       ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 56+ messages in thread
From: Josh Poimboeuf @ 2015-12-14 16:05 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Peter Zijlstra, Ingo Molnar, linux-kernel, Jiri Olsa, Namhyung Kim

On Mon, Dec 14, 2015 at 12:44:21PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Sun, Dec 13, 2015 at 10:18:14PM -0600, Josh Poimboeuf escreveu:
> > Introduce and use new astrcat() and astrcatf() functions which replace
> > the strbuf functionality for subcmd.
> 
> <SNIP>
>  
> > diff --git a/tools/perf/util/subcmd-util.h b/tools/perf/util/subcmd-util.h
> > new file mode 100644
> > index 0000000..98fb9f9
> > --- /dev/null
> > +++ b/tools/perf/util/subcmd-util.h
> > @@ -0,0 +1,24 @@
> > +#ifndef __PERF_SUBCMD_UTIL_H
> > +#define __PERF_SUBCMD_UTIL_H
> > +
> > +#include <stdio.h>
> > +
> > +#define astrcatf(out, fmt, ...)						\
> > +({									\
> > +	char *tmp = *(out);						\
> > +	if (asprintf((out), "%s" fmt, tmp ?: "", ## __VA_ARGS__) == -1)	\
> > +		die("asprintf failed");					\
> > +	free(tmp);							\
> > +})
> 
> Hey, don't add die() calls, please.
> 
> > +
> > +static inline void astrcat(char **out, const char *add)
> > +{
> > +	char *tmp = *out;
> > +
> > +	if (asprintf(out, "%s%s", tmp ?: "", add) == -1)
> > +		die("asprintf failed");
> > +
> > +	free(tmp);
> 
> Ditto.

This replaces strbuf, which also calls die() when allocations fail.  So
this duplicates the existing die-on-allocation-error functionality and
is nothing "new" from my perspective.

Do you want me to change all the callers (and callers' callers, etc) of
these functions to check for errors?

> And I think that this should go into tools/include/string.h and
> tools/lib/string.c, no?

If these functions simply duplicate some of strbuf's functionality and
they aren't used outside of libsubcmd then I don't see any reason to do
that.

> We should try to look at the kernel and try to follow naming, semantics,
> etc as much as possible. The kernel doesn't have a astrcat, just
> kasprintf() (that is in linux/kernel.h, perhaps because in userland
> asprintf is in stdio.h, not in string.h) , wonder how something like
> astrcat is done there... Doing some research now.

Ok.

-- 
Josh

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

* Re: [PATCH v3 14/17] perf: Remove subcmd dependencies on strbuf
  2015-12-14 16:05     ` Josh Poimboeuf
@ 2015-12-14 17:50       ` Arnaldo Carvalho de Melo
  2015-12-14 18:04         ` Josh Poimboeuf
  0 siblings, 1 reply; 56+ messages in thread
From: Arnaldo Carvalho de Melo @ 2015-12-14 17:50 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Peter Zijlstra, Ingo Molnar, linux-kernel, Jiri Olsa, Namhyung Kim

Em Mon, Dec 14, 2015 at 10:05:37AM -0600, Josh Poimboeuf escreveu:
> On Mon, Dec 14, 2015 at 12:44:21PM -0300, Arnaldo Carvalho de Melo wrote:
> > Em Sun, Dec 13, 2015 at 10:18:14PM -0600, Josh Poimboeuf escreveu:
> > > Introduce and use new astrcat() and astrcatf() functions which replace
> > > the strbuf functionality for subcmd.
> > 
> > <SNIP>
> >  
> > > diff --git a/tools/perf/util/subcmd-util.h b/tools/perf/util/subcmd-util.h
> > > new file mode 100644
> > > index 0000000..98fb9f9
> > > --- /dev/null
> > > +++ b/tools/perf/util/subcmd-util.h
> > > @@ -0,0 +1,24 @@
> > > +#ifndef __PERF_SUBCMD_UTIL_H
> > > +#define __PERF_SUBCMD_UTIL_H
> > > +
> > > +#include <stdio.h>
> > > +
> > > +#define astrcatf(out, fmt, ...)						\
> > > +({									\
> > > +	char *tmp = *(out);						\
> > > +	if (asprintf((out), "%s" fmt, tmp ?: "", ## __VA_ARGS__) == -1)	\
> > > +		die("asprintf failed");					\
> > > +	free(tmp);							\
> > > +})
> > 
> > Hey, don't add die() calls, please.
> > 
> > > +
> > > +static inline void astrcat(char **out, const char *add)
> > > +{
> > > +	char *tmp = *out;
> > > +
> > > +	if (asprintf(out, "%s%s", tmp ?: "", add) == -1)
> > > +		die("asprintf failed");
> > > +
> > > +	free(tmp);
> > 
> > Ditto.
> 
> This replaces strbuf, which also calls die() when allocations fail.  So
> this duplicates the existing die-on-allocation-error functionality and
> is nothing "new" from my perspective.
> 
> Do you want me to change all the callers (and callers' callers, etc) of
> these functions to check for errors?

Fair enough, we could do it later, but yeah, ultimately we should call
all die() calls.
 
> > And I think that this should go into tools/include/string.h and
> > tools/lib/string.c, no?
> 
> If these functions simply duplicate some of strbuf's functionality and
> they aren't used outside of libsubcmd then I don't see any reason to do
> that.

Well, we might as well follow that principle, i.e. as soon as there are
more users, we move it.

But removing strbuf and using something already in libc or something
equal or slighly similar to what is in the kernel is something I like to
have in place.
 
> > We should try to look at the kernel and try to follow naming, semantics,
> > etc as much as possible. The kernel doesn't have a astrcat, just
> > kasprintf() (that is in linux/kernel.h, perhaps because in userland
> > asprintf is in stdio.h, not in string.h) , wonder how something like
> > astrcat is done there... Doing some research now.
> 
> Ok.
> 
> -- 
> Josh

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

* Re: [PATCH v3 14/17] perf: Remove subcmd dependencies on strbuf
  2015-12-14 17:50       ` Arnaldo Carvalho de Melo
@ 2015-12-14 18:04         ` Josh Poimboeuf
  0 siblings, 0 replies; 56+ messages in thread
From: Josh Poimboeuf @ 2015-12-14 18:04 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Peter Zijlstra, Ingo Molnar, linux-kernel, Jiri Olsa, Namhyung Kim

On Mon, Dec 14, 2015 at 02:50:12PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Mon, Dec 14, 2015 at 10:05:37AM -0600, Josh Poimboeuf escreveu:
> > On Mon, Dec 14, 2015 at 12:44:21PM -0300, Arnaldo Carvalho de Melo wrote:
> > > Em Sun, Dec 13, 2015 at 10:18:14PM -0600, Josh Poimboeuf escreveu:
> > > > Introduce and use new astrcat() and astrcatf() functions which replace
> > > > the strbuf functionality for subcmd.
> > > 
> > > <SNIP>
> > >  
> > > > diff --git a/tools/perf/util/subcmd-util.h b/tools/perf/util/subcmd-util.h
> > > > new file mode 100644
> > > > index 0000000..98fb9f9
> > > > --- /dev/null
> > > > +++ b/tools/perf/util/subcmd-util.h
> > > > @@ -0,0 +1,24 @@
> > > > +#ifndef __PERF_SUBCMD_UTIL_H
> > > > +#define __PERF_SUBCMD_UTIL_H
> > > > +
> > > > +#include <stdio.h>
> > > > +
> > > > +#define astrcatf(out, fmt, ...)						\
> > > > +({									\
> > > > +	char *tmp = *(out);						\
> > > > +	if (asprintf((out), "%s" fmt, tmp ?: "", ## __VA_ARGS__) == -1)	\
> > > > +		die("asprintf failed");					\
> > > > +	free(tmp);							\
> > > > +})
> > > 
> > > Hey, don't add die() calls, please.
> > > 
> > > > +
> > > > +static inline void astrcat(char **out, const char *add)
> > > > +{
> > > > +	char *tmp = *out;
> > > > +
> > > > +	if (asprintf(out, "%s%s", tmp ?: "", add) == -1)
> > > > +		die("asprintf failed");
> > > > +
> > > > +	free(tmp);
> > > 
> > > Ditto.
> > 
> > This replaces strbuf, which also calls die() when allocations fail.  So
> > this duplicates the existing die-on-allocation-error functionality and
> > is nothing "new" from my perspective.
> > 
> > Do you want me to change all the callers (and callers' callers, etc) of
> > these functions to check for errors?
> 
> Fair enough, we could do it later, but yeah, ultimately we should call
> all die() calls.
>  
> > > And I think that this should go into tools/include/string.h and
> > > tools/lib/string.c, no?
> > 
> > If these functions simply duplicate some of strbuf's functionality and
> > they aren't used outside of libsubcmd then I don't see any reason to do
> > that.
> 
> Well, we might as well follow that principle, i.e. as soon as there are
> more users, we move it.
> 
> But removing strbuf and using something already in libc or something
> equal or slighly similar to what is in the kernel is something I like to
> have in place.

Ok, so just to clarify, is this patch ok in it's current state or is
there anything you'd like me to change for v4?  I didn't see anything
similar to astrcat() or astrcatf() in glibc or in the kernel.

> > > We should try to look at the kernel and try to follow naming, semantics,
> > > etc as much as possible. The kernel doesn't have a astrcat, just
> > > kasprintf() (that is in linux/kernel.h, perhaps because in userland
> > > asprintf is in stdio.h, not in string.h) , wonder how something like
> > > astrcat is done there... Doing some research now.
> > 
> > Ok.

-- 
Josh

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

* [PATCH v3.2] tools build: Fix feature Makefile issues with 'O='
  2015-12-14 15:55             ` Jiri Olsa
  2015-12-14 16:03               ` Josh Poimboeuf
@ 2015-12-14 18:32               ` Josh Poimboeuf
  1 sibling, 0 replies; 56+ messages in thread
From: Josh Poimboeuf @ 2015-12-14 18:32 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	linux-kernel, Namhyung Kim

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

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

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

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
---
v3.2: add changelog

 tools/build/Makefile.feature |  2 +-
 tools/build/feature/Makefile | 93 ++++++++++++++++++++++----------------------
 2 files changed, 48 insertions(+), 47 deletions(-)

diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature
index b8c31ec..6c0519d 100644
--- a/tools/build/Makefile.feature
+++ b/tools/build/Makefile.feature
@@ -7,7 +7,7 @@ endif
 
 feature_check = $(eval $(feature_check_code))
 define feature_check_code
-  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C $(feature_dir) test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0)
+  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C $(feature_dir) $(OUTPUT_FEATURES)test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0)
 endef
 
 feature_set = $(eval $(feature_set_code))
diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
index cea04ce9..bf8f035 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -1,4 +1,3 @@
-
 FILES=					\
 	test-all.bin			\
 	test-backtrace.bin		\
@@ -38,38 +37,40 @@ FILES=					\
 	test-bpf.bin			\
 	test-get_cpuid.bin
 
+FILES := $(addprefix $(OUTPUT),$(FILES))
+
 CC := $(CROSS_COMPILE)gcc -MD
 PKG_CONFIG := $(CROSS_COMPILE)pkg-config
 
 all: $(FILES)
 
-__BUILD = $(CC) $(CFLAGS) -Wall -Werror -o $(OUTPUT)$@ $(patsubst %.bin,%.c,$@) $(LDFLAGS)
-  BUILD = $(__BUILD) > $(OUTPUT)$(@:.bin=.make.output) 2>&1
+__BUILD = $(CC) $(CFLAGS) -Wall -Werror -o $@ $(patsubst %.bin,%.c,$(@F)) $(LDFLAGS)
+  BUILD = $(__BUILD) > $(@:.bin=.make.output) 2>&1
 
 ###############################
 
-test-all.bin:
+$(OUTPUT)test-all.bin:
 	$(BUILD) -fstack-protector-all -O2 -D_FORTIFY_SOURCE=2 -ldw -lelf -lnuma -lelf -laudit -I/usr/include/slang -lslang $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) $(FLAGS_PERL_EMBED) $(FLAGS_PYTHON_EMBED) -DPACKAGE='"perf"' -lbfd -ldl -lz -llzma
 
-test-hello.bin:
+$(OUTPUT)test-hello.bin:
 	$(BUILD)
 
-test-pthread-attr-setaffinity-np.bin:
+$(OUTPUT)test-pthread-attr-setaffinity-np.bin:
 	$(BUILD) -D_GNU_SOURCE -lpthread
 
-test-stackprotector-all.bin:
+$(OUTPUT)test-stackprotector-all.bin:
 	$(BUILD) -fstack-protector-all
 
-test-fortify-source.bin:
+$(OUTPUT)test-fortify-source.bin:
 	$(BUILD) -O2 -D_FORTIFY_SOURCE=2
 
-test-bionic.bin:
+$(OUTPUT)test-bionic.bin:
 	$(BUILD)
 
-test-libelf.bin:
+$(OUTPUT)test-libelf.bin:
 	$(BUILD) -lelf
 
-test-glibc.bin:
+$(OUTPUT)test-glibc.bin:
 	$(BUILD)
 
 DWARFLIBS := -ldw
@@ -77,37 +78,37 @@ ifeq ($(findstring -static,${LDFLAGS}),-static)
 DWARFLIBS += -lelf -lebl -lz -llzma -lbz2
 endif
 
-test-dwarf.bin:
+$(OUTPUT)test-dwarf.bin:
 	$(BUILD) $(DWARFLIBS)
 
-test-libelf-mmap.bin:
+$(OUTPUT)test-libelf-mmap.bin:
 	$(BUILD) -lelf
 
-test-libelf-getphdrnum.bin:
+$(OUTPUT)test-libelf-getphdrnum.bin:
 	$(BUILD) -lelf
 
-test-libnuma.bin:
+$(OUTPUT)test-libnuma.bin:
 	$(BUILD) -lnuma
 
-test-numa_num_possible_cpus.bin:
+$(OUTPUT)test-numa_num_possible_cpus.bin:
 	$(BUILD) -lnuma
 
-test-libunwind.bin:
+$(OUTPUT)test-libunwind.bin:
 	$(BUILD) -lelf
 
-test-libunwind-debug-frame.bin:
+$(OUTPUT)test-libunwind-debug-frame.bin:
 	$(BUILD) -lelf
 
-test-libaudit.bin:
+$(OUTPUT)test-libaudit.bin:
 	$(BUILD) -laudit
 
-test-libslang.bin:
+$(OUTPUT)test-libslang.bin:
 	$(BUILD) -I/usr/include/slang -lslang
 
-test-gtk2.bin:
+$(OUTPUT)test-gtk2.bin:
 	$(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
 
-test-gtk2-infobar.bin:
+$(OUTPUT)test-gtk2-infobar.bin:
 	$(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
 
 grep-libs  = $(filter -l%,$(1))
@@ -119,63 +120,63 @@ PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
 PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null`
 FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
 
-test-libperl.bin:
+$(OUTPUT)test-libperl.bin:
 	$(BUILD) $(FLAGS_PERL_EMBED)
 
-test-libpython.bin:
+$(OUTPUT)test-libpython.bin:
 	$(BUILD)
 
-test-libpython-version.bin:
+$(OUTPUT)test-libpython-version.bin:
 	$(BUILD)
 
-test-libbfd.bin:
+$(OUTPUT)test-libbfd.bin:
 	$(BUILD) -DPACKAGE='"perf"' -lbfd -lz -liberty -ldl
 
-test-liberty.bin:
-	$(CC) $(CFLAGS) -Wall -Werror -o $(OUTPUT)$@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty
+$(OUTPUT)test-liberty.bin:
+	$(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty
 
-test-liberty-z.bin:
-	$(CC) $(CFLAGS) -Wall -Werror -o $(OUTPUT)$@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty -lz
+$(OUTPUT)test-liberty-z.bin:
+	$(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty -lz
 
-test-cplus-demangle.bin:
+$(OUTPUT)test-cplus-demangle.bin:
 	$(BUILD) -liberty
 
-test-backtrace.bin:
+$(OUTPUT)test-backtrace.bin:
 	$(BUILD)
 
-test-timerfd.bin:
+$(OUTPUT)test-timerfd.bin:
 	$(BUILD)
 
-test-libdw-dwarf-unwind.bin:
+$(OUTPUT)test-libdw-dwarf-unwind.bin:
 	$(BUILD) # -ldw provided by $(FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind)
 
-test-libbabeltrace.bin:
+$(OUTPUT)test-libbabeltrace.bin:
 	$(BUILD) # -lbabeltrace provided by $(FEATURE_CHECK_LDFLAGS-libbabeltrace)
 
-test-sync-compare-and-swap.bin:
+$(OUTPUT)test-sync-compare-and-swap.bin:
 	$(BUILD)
 
-test-compile-32.bin:
-	$(CC) -m32 -o $(OUTPUT)$@ test-compile.c
+$(OUTPUT)test-compile-32.bin:
+	$(CC) -m32 -o $@ test-compile.c
 
-test-compile-x32.bin:
-	$(CC) -mx32 -o $(OUTPUT)$@ test-compile.c
+$(OUTPUT)test-compile-x32.bin:
+	$(CC) -mx32 -o $@ test-compile.c
 
-test-zlib.bin:
+$(OUTPUT)test-zlib.bin:
 	$(BUILD) -lz
 
-test-lzma.bin:
+$(OUTPUT)test-lzma.bin:
 	$(BUILD) -llzma
 
-test-get_cpuid.bin:
+$(OUTPUT)test-get_cpuid.bin:
 	$(BUILD)
 
-test-bpf.bin:
+$(OUTPUT)test-bpf.bin:
 	$(BUILD)
 
--include *.d
+-include $(OUTPUT)*.d
 
 ###############################
 
 clean:
-	rm -f $(FILES) *.d $(FILES:.bin=.make.output)
+	rm -f $(FILES) $(OUTPUT)*.d $(FILES:.bin=.make.output)
-- 
2.4.3


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

* [tip:perf/core] perf build: Remove unnecessary line in Makefile.feature
  2015-12-14  4:18 ` [PATCH v3 01/17] perf build: Remove unnecessary line in Makefile.feature Josh Poimboeuf
  2015-12-14 10:05   ` Jiri Olsa
@ 2015-12-18  8:47   ` tip-bot for Josh Poimboeuf
  1 sibling, 0 replies; 56+ messages in thread
From: tip-bot for Josh Poimboeuf @ 2015-12-18  8:47 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: hpa, jpoimboe, jolsa, namhyung, linux-kernel, acme, peterz, tglx, mingo

Commit-ID:  26bc9b2df1f38536cdfd58df94bf8b5601eb894a
Gitweb:     http://git.kernel.org/tip/26bc9b2df1f38536cdfd58df94bf8b5601eb894a
Author:     Josh Poimboeuf <jpoimboe@redhat.com>
AuthorDate: Sun, 13 Dec 2015 22:18:01 -0600
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 14 Dec 2015 12:16:15 -0300

perf build: Remove unnecessary line in Makefile.feature

This line always silently fails because it doesn't add the 'test-'
prefix to the .bin file.

And it seems to be unnecessary anyway: the line immediately after it
does all the individual feature checks.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/554a05c18af564ba015c9e68f25730126e0f4acb.1449965119.git.jpoimboe@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/build/Makefile.feature | 1 -
 1 file changed, 1 deletion(-)

diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature
index 37ff4c9..b8c31ec 100644
--- a/tools/build/Makefile.feature
+++ b/tools/build/Makefile.feature
@@ -101,7 +101,6 @@ ifeq ($(feature-all), 1)
   #
   $(foreach feat,$(FEATURE_TESTS),$(call feature_set,$(feat)))
 else
-  $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS)" LDFLAGS=$(LDFLAGS) -i -j -C $(feature_dir) $(addsuffix .bin,$(FEATURE_TESTS)) >/dev/null 2>&1)
   $(foreach feat,$(FEATURE_TESTS),$(call feature_check,$(feat)))
 endif
 

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

* [tip:perf/core] perf test: Add Build file to dependencies for llvm-src-*.c
  2015-12-14  4:18 ` [PATCH v3 03/17] perf test: Add Build file to dependencies for llvm-src-*.c Josh Poimboeuf
  2015-12-14 10:10   ` Jiri Olsa
@ 2015-12-18  8:47   ` tip-bot for Josh Poimboeuf
  1 sibling, 0 replies; 56+ messages in thread
From: tip-bot for Josh Poimboeuf @ 2015-12-18  8:47 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: mingo, linux-kernel, acme, hpa, jolsa, peterz, tglx, jpoimboe, namhyung

Commit-ID:  8bda6a63a049caee4f8ddf2dd99055794df96e4f
Gitweb:     http://git.kernel.org/tip/8bda6a63a049caee4f8ddf2dd99055794df96e4f
Author:     Josh Poimboeuf <jpoimboe@redhat.com>
AuthorDate: Sun, 13 Dec 2015 22:18:03 -0600
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 14 Dec 2015 12:17:09 -0300

perf test: Add Build file to dependencies for llvm-src-*.c

Because the Build file writes source code to the generated llvm-src-*.c
files, it should be listed as one of the dependencies, so that any
future changes to the code being echoed won't require a 'make clean'.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/9b9886c295750dc83cbbb29a665d280f9c5e8b3e.1449965119.git.jpoimboe@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/tests/Build | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
index 0ff8a97..f23fb7e 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] 56+ messages in thread

* [tip:perf/core] perf test: Remove tarpkg at end of test
  2015-12-14  4:18 ` [PATCH v3 04/17] perf test: remove tarpkg at end of test Josh Poimboeuf
@ 2015-12-18  8:48   ` tip-bot for Josh Poimboeuf
  0 siblings, 0 replies; 56+ messages in thread
From: tip-bot for Josh Poimboeuf @ 2015-12-18  8:48 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: namhyung, tglx, acme, mingo, jolsa, peterz, linux-kernel, hpa, jpoimboe

Commit-ID:  004bd89da8c8e7df87e951bf88e34af67348e4e9
Gitweb:     http://git.kernel.org/tip/004bd89da8c8e7df87e951bf88e34af67348e4e9
Author:     Josh Poimboeuf <jpoimboe@redhat.com>
AuthorDate: Sun, 13 Dec 2015 22:18:04 -0600
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 14 Dec 2015 12:17:58 -0300

perf test: Remove tarpkg at end of test

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/5e7e97a23e3ce11b59d1009b39ebb6d2813a0560.1449965119.git.jpoimboe@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/tests/make | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/perf/tests/make b/tools/perf/tests/make
index 8ea3dff..c1fbb8e 100644
--- a/tools/perf/tests/make
+++ b/tools/perf/tests/make
@@ -259,7 +259,8 @@ $(run_O):
 tarpkg:
 	@cmd="$(PERF)/tests/perf-targz-src-pkg $(PERF)"; \
 	echo "- $@: $$cmd" && echo $$cmd > $@ && \
-	( eval $$cmd ) >> $@ 2>&1
+	( eval $$cmd ) >> $@ 2>&1 && \
+	rm -f $@
 
 make_kernelsrc:
 	@echo "- make -C <kernelsrc> tools/perf"

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

* [tip:perf/core] perf build: Fix 'make clean'
  2015-12-14  4:18 ` [PATCH v3 05/17] perf build: Fix 'make clean' Josh Poimboeuf
  2015-12-14 10:14   ` Jiri Olsa
@ 2015-12-18  8:48   ` tip-bot for Josh Poimboeuf
  1 sibling, 0 replies; 56+ messages in thread
From: tip-bot for Josh Poimboeuf @ 2015-12-18  8:48 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tglx, peterz, acme, jpoimboe, linux-kernel, mingo, namhyung, jolsa, hpa

Commit-ID:  8f46dfd73e5378909834bd32a4e7710cd5522506
Gitweb:     http://git.kernel.org/tip/8f46dfd73e5378909834bd32a4e7710cd5522506
Author:     Josh Poimboeuf <jpoimboe@redhat.com>
AuthorDate: Sun, 13 Dec 2015 22:18:05 -0600
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 14 Dec 2015 12:18:16 -0300

perf build: Fix 'make clean'

Add some missing files to the 'make clean' target.

Reported-and-Acked-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/8b1f5a5bd66a652be071d423e64aaa994254be31.1449965119.git.jpoimboe@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Makefile.perf | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 929a32b..906c723 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -582,15 +582,16 @@ $(INSTALL_DOC_TARGETS):
 #
 config-clean:
 	$(call QUIET_CLEAN, config)
-	$(Q)$(MAKE) -C $(srctree)/tools/build/feature/ clean >/dev/null
+	$(Q)$(MAKE) -C $(srctree)/tools/build/feature/ $(if $(OUTPUT),OUTPUT=$(OUTPUT)feature/,) clean >/dev/null
 
 clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean config-clean
 	$(call QUIET_CLEAN, core-objs)  $(RM) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(LANG_BINDINGS)
-	$(Q)find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
+	$(Q)find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
 	$(Q)$(RM) $(OUTPUT).config-detected
 	$(call QUIET_CLEAN, core-progs) $(RM) $(ALL_PROGRAMS) perf perf-read-vdso32 perf-read-vdsox32
 	$(call QUIET_CLEAN, core-gen)   $(RM)  *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope* $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)FEATURE-DUMP $(OUTPUT)util/*-bison* $(OUTPUT)util/*-flex* \
-		$(OUTPUT)util/intel-pt-decoder/inat-tables.c
+		$(OUTPUT)util/intel-pt-decoder/inat-tables.c $(OUTPUT)fixdep \
+		$(OUTPUT)tests/llvm-src-{base,kbuild,prologue}.c
 	$(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean
 	$(python-clean)
 

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

* [tip:perf/core] perf build: Rename LIB_PATH -> API_PATH
  2015-12-14  4:18 ` [PATCH v3 06/17] perf build: Rename LIB_PATH -> API_PATH Josh Poimboeuf
  2015-12-14 10:34   ` Jiri Olsa
@ 2015-12-18  8:49   ` tip-bot for Josh Poimboeuf
  1 sibling, 0 replies; 56+ messages in thread
From: tip-bot for Josh Poimboeuf @ 2015-12-18  8:49 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: hpa, jpoimboe, namhyung, tglx, peterz, mingo, acme, linux-kernel, jolsa

Commit-ID:  212e984a07d19c2e6b83da4ebac4e965dd92efd3
Gitweb:     http://git.kernel.org/tip/212e984a07d19c2e6b83da4ebac4e965dd92efd3
Author:     Josh Poimboeuf <jpoimboe@redhat.com>
AuthorDate: Sun, 13 Dec 2015 22:18:06 -0600
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 14 Dec 2015 12:19:03 -0300

perf build: Rename LIB_PATH -> API_PATH

'LIB_PATH' is a misnomer because there are multiple library paths.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/c10df0b749a27f05cc531fe06b8dd71a329341fa.1449965119.git.jpoimboe@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Makefile.perf | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 906c723..388ec64 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -185,13 +185,13 @@ ifneq ($(OUTPUT),)
   TE_PATH=$(OUTPUT)
   BPF_PATH=$(OUTPUT)
 ifneq ($(subdir),)
-  LIB_PATH=$(OUTPUT)/../lib/api/
+  API_PATH=$(OUTPUT)/../lib/api/
 else
-  LIB_PATH=$(OUTPUT)
+  API_PATH=$(OUTPUT)
 endif
 else
   TE_PATH=$(TRACE_EVENT_DIR)
-  LIB_PATH=$(LIB_DIR)
+  API_PATH=$(LIB_DIR)
   BPF_PATH=$(BPF_DIR)
 endif
 
@@ -201,7 +201,7 @@ export LIBTRACEEVENT
 LIBTRACEEVENT_DYNAMIC_LIST = $(TE_PATH)libtraceevent-dynamic-list
 LIBTRACEEVENT_DYNAMIC_LIST_LDFLAGS = -Xlinker --dynamic-list=$(LIBTRACEEVENT_DYNAMIC_LIST)
 
-LIBAPI = $(LIB_PATH)libapi.a
+LIBAPI = $(API_PATH)libapi.a
 export LIBAPI
 
 LIBBPF = $(BPF_PATH)libbpf.a

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

* [tip:perf/core] perf tools: Create pager.h
  2015-12-14  4:18 ` [PATCH v3 07/17] perf: Create pager.h Josh Poimboeuf
@ 2015-12-18  8:49   ` tip-bot for Josh Poimboeuf
  0 siblings, 0 replies; 56+ messages in thread
From: tip-bot for Josh Poimboeuf @ 2015-12-18  8:49 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: mingo, namhyung, linux-kernel, jpoimboe, tglx, hpa, peterz, acme, jolsa

Commit-ID:  32a56bd438ab3023d08874e2770aa0675364b8ab
Gitweb:     http://git.kernel.org/tip/32a56bd438ab3023d08874e2770aa0675364b8ab
Author:     Josh Poimboeuf <jpoimboe@redhat.com>
AuthorDate: Sun, 13 Dec 2015 22:18:07 -0600
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 14 Dec 2015 12:19:40 -0300

perf tools: Create pager.h

Move the 'pager' function prototypes into a new pager.h so that the
pager code can be moved out to a library.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/ba7c316474dd6bfc047e5c6dc4dcab39a982caf5.1449965119.git.jpoimboe@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/cache.h | 5 +----
 tools/perf/util/pager.h | 7 +++++++
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h
index 4c2b764..9ca4a58 100644
--- a/tools/perf/util/cache.h
+++ b/tools/perf/util/cache.h
@@ -4,6 +4,7 @@
 #include <stdbool.h>
 #include "util.h"
 #include "strbuf.h"
+#include "pager.h"
 #include "../perf.h"
 #include "../ui/ui.h"
 
@@ -28,10 +29,6 @@ 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);
 
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 */

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

* [tip:perf/core] perf tools: Remove check for unused PERF_PAGER_IN_USE
  2015-12-14  4:18 ` [PATCH v3 08/17] perf: Remove check for unused PERF_PAGER_IN_USE Josh Poimboeuf
@ 2015-12-18  8:49   ` tip-bot for Josh Poimboeuf
  0 siblings, 0 replies; 56+ messages in thread
From: tip-bot for Josh Poimboeuf @ 2015-12-18  8:49 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: peterz, jolsa, namhyung, linux-kernel, jpoimboe, hpa, acme, tglx, mingo

Commit-ID:  a871a775172ac586b76199fd158e2843971bd052
Gitweb:     http://git.kernel.org/tip/a871a775172ac586b76199fd158e2843971bd052
Author:     Josh Poimboeuf <jpoimboe@redhat.com>
AuthorDate: Sun, 13 Dec 2015 22:18:08 -0600
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 14 Dec 2015 12:30:18 -0300

perf tools: Remove check for unused PERF_PAGER_IN_USE

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>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/ed9e8370db9811746dc590544cf48c36dcfb1731.1449965119.git.jpoimboe@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@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 53ef006..7dcbef6 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;
 }

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

* [tip:perf/core] perf tools: Move help_unknown_cmd() to its own file
  2015-12-14  4:18 ` [PATCH v3 09/17] perf: Move help_unknown_cmd() to its own file Josh Poimboeuf
@ 2015-12-18  8:50   ` tip-bot for Josh Poimboeuf
  0 siblings, 0 replies; 56+ messages in thread
From: tip-bot for Josh Poimboeuf @ 2015-12-18  8:50 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: jolsa, hpa, peterz, jpoimboe, linux-kernel, tglx, namhyung, mingo, acme

Commit-ID:  5feaac248a46dd5f9876c4ae45c4bbbde5472e90
Gitweb:     http://git.kernel.org/tip/5feaac248a46dd5f9876c4ae45c4bbbde5472e90
Author:     Josh Poimboeuf <jpoimboe@redhat.com>
AuthorDate: Sun, 13 Dec 2015 22:18:09 -0600
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 14 Dec 2015 12:30:37 -0300

perf tools: Move help_unknown_cmd() to its own file

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>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/562d918bcaaf340c1ae3e47586b3f0ae33b9918b.1449965119.git.jpoimboe@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/Build                              |   1 +
 tools/perf/util/help-unknown-cmd.c                 | 103 ++++++++++++++++++++
 .../perf/util/help-unknown-cmd.h                   |   0
 tools/perf/util/help.c                             | 107 +--------------------
 tools/perf/util/help.h                             |   3 +
 5 files changed, 110 insertions(+), 104 deletions(-)

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..a0820f1
--- /dev/null
+++ b/tools/perf/util/help-unknown-cmd.c
@@ -0,0 +1,103 @@
+#include "cache.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/arch/arm/mach-imx/Makefile.boot b/tools/perf/util/help-unknown-cmd.h
similarity index 100%
copy from arch/arm/mach-imx/Makefile.boot
copy to tools/perf/util/help-unknown-cmd.h
diff --git a/tools/perf/util/help.c b/tools/perf/util/help.c
index 929c93f..8d74f7d 100644
--- a/tools/perf/util/help.c
+++ b/tools/perf/util/help.c
@@ -1,9 +1,7 @@
 #include "cache.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 +15,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 +26,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;
 
@@ -233,102 +231,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);

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

* [tip:perf/core] perf tools: Convert parse-options.c internal functions to static
  2015-12-14  4:18 ` [PATCH v3 12/17] perf: Convert parse-options.c internal functions to static Josh Poimboeuf
@ 2015-12-18  8:50   ` tip-bot for Josh Poimboeuf
  0 siblings, 0 replies; 56+ messages in thread
From: tip-bot for Josh Poimboeuf @ 2015-12-18  8:50 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: jolsa, hpa, linux-kernel, jpoimboe, namhyung, acme, peterz, tglx, mingo

Commit-ID:  408cf34c176e1832bc2f9f68033a55a765484f93
Gitweb:     http://git.kernel.org/tip/408cf34c176e1832bc2f9f68033a55a765484f93
Author:     Josh Poimboeuf <jpoimboe@redhat.com>
AuthorDate: Sun, 13 Dec 2015 22:18:12 -0600
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 14 Dec 2015 12:33:01 -0300

perf tools: Convert parse-options.c internal functions to static

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/c027b5f47ec1055077f5650edb1c7ad37c191e6c.1449965119.git.jpoimboe@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/parse-options.c | 18 +++++++++---------
 tools/perf/util/parse-options.h |  9 ---------
 2 files changed, 9 insertions(+), 18 deletions(-)

diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c
index de3290b..14b2bee 100644
--- a/tools/perf/util/parse-options.c
+++ b/tools/perf/util/parse-options.c
@@ -360,8 +360,8 @@ static void check_typos(const char *arg, const struct option *options)
 	}
 }
 
-void parse_options_start(struct parse_opt_ctx_t *ctx,
-			 int argc, const char **argv, int flags)
+static void parse_options_start(struct parse_opt_ctx_t *ctx,
+				int argc, const char **argv, int flags)
 {
 	memset(ctx, 0, sizeof(*ctx));
 	ctx->argc = argc - 1;
@@ -378,9 +378,9 @@ static int usage_with_options_internal(const char * const *,
 				       const struct option *, int,
 				       struct parse_opt_ctx_t *);
 
-int parse_options_step(struct parse_opt_ctx_t *ctx,
-		       const struct option *options,
-		       const char * const usagestr[])
+static int parse_options_step(struct parse_opt_ctx_t *ctx,
+			      const struct option *options,
+			      const char * const usagestr[])
 {
 	int internal_help = !(ctx->flags & PARSE_OPT_NO_INTERNAL_HELP);
 	int excl_short_opt = 1;
@@ -489,7 +489,7 @@ exclusive:
 	return PARSE_OPT_HELP;
 }
 
-int parse_options_end(struct parse_opt_ctx_t *ctx)
+static int parse_options_end(struct parse_opt_ctx_t *ctx)
 {
 	memmove(ctx->out + ctx->cpidx, ctx->argv, ctx->argc * sizeof(*ctx->out));
 	ctx->out[ctx->cpidx + ctx->argc] = NULL;
@@ -717,9 +717,9 @@ static bool option__in_argv(const struct option *opt, const struct parse_opt_ctx
 	return false;
 }
 
-int usage_with_options_internal(const char * const *usagestr,
-				const struct option *opts, int full,
-				struct parse_opt_ctx_t *ctx)
+static int usage_with_options_internal(const char * const *usagestr,
+				       const struct option *opts, int full,
+				       struct parse_opt_ctx_t *ctx)
 {
 	struct option *ordered;
 
diff --git a/tools/perf/util/parse-options.h b/tools/perf/util/parse-options.h
index a8e407b..dd1236d 100644
--- a/tools/perf/util/parse-options.h
+++ b/tools/perf/util/parse-options.h
@@ -195,15 +195,6 @@ extern int parse_options_usage(const char * const *usagestr,
 			       const char *optstr,
 			       bool short_opt);
 
-extern void parse_options_start(struct parse_opt_ctx_t *ctx,
-				int argc, const char **argv, int flags);
-
-extern int parse_options_step(struct parse_opt_ctx_t *ctx,
-			      const struct option *options,
-			      const char * const usagestr[]);
-
-extern int parse_options_end(struct parse_opt_ctx_t *ctx);
-
 
 /*----- some often used options -----*/
 extern int parse_opt_abbrev_cb(const struct option *, const char *, int);

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

end of thread, other threads:[~2015-12-18  8:51 UTC | newest]

Thread overview: 56+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-14  4:18 [PATCH v3 00/17] perf tools: Move perf subcommand framework to a library Josh Poimboeuf
2015-12-14  4:18 ` [PATCH v3 01/17] perf build: Remove unnecessary line in Makefile.feature Josh Poimboeuf
2015-12-14 10:05   ` Jiri Olsa
2015-12-14 15:16     ` Arnaldo Carvalho de Melo
2015-12-18  8:47   ` [tip:perf/core] " tip-bot for Josh Poimboeuf
2015-12-14  4:18 ` [PATCH v3 02/17] tools build: Fix feature Makefile dependencies for 'O=' Josh Poimboeuf
2015-12-14 10:08   ` Jiri Olsa
2015-12-14 14:02     ` Josh Poimboeuf
2015-12-14 14:29       ` [PATCH v3.1 " Josh Poimboeuf
2015-12-14 15:16         ` Arnaldo Carvalho de Melo
2015-12-14 15:29         ` Jiri Olsa
2015-12-14 15:38           ` Josh Poimboeuf
2015-12-14 15:55             ` Jiri Olsa
2015-12-14 16:03               ` Josh Poimboeuf
2015-12-14 18:32               ` [PATCH v3.2] tools build: Fix feature Makefile issues with 'O=' Josh Poimboeuf
2015-12-14  4:18 ` [PATCH v3 03/17] perf test: Add Build file to dependencies for llvm-src-*.c Josh Poimboeuf
2015-12-14 10:10   ` Jiri Olsa
2015-12-14 15:17     ` Arnaldo Carvalho de Melo
2015-12-18  8:47   ` [tip:perf/core] " tip-bot for Josh Poimboeuf
2015-12-14  4:18 ` [PATCH v3 04/17] perf test: remove tarpkg at end of test Josh Poimboeuf
2015-12-18  8:48   ` [tip:perf/core] perf test: Remove " tip-bot for Josh Poimboeuf
2015-12-14  4:18 ` [PATCH v3 05/17] perf build: Fix 'make clean' Josh Poimboeuf
2015-12-14 10:14   ` Jiri Olsa
2015-12-14 15:18     ` Arnaldo Carvalho de Melo
2015-12-18  8:48   ` [tip:perf/core] " tip-bot for Josh Poimboeuf
2015-12-14  4:18 ` [PATCH v3 06/17] perf build: Rename LIB_PATH -> API_PATH Josh Poimboeuf
2015-12-14 10:34   ` Jiri Olsa
2015-12-14 15:19     ` Arnaldo Carvalho de Melo
2015-12-18  8:49   ` [tip:perf/core] " tip-bot for Josh Poimboeuf
2015-12-14  4:18 ` [PATCH v3 07/17] perf: Create pager.h Josh Poimboeuf
2015-12-18  8:49   ` [tip:perf/core] perf tools: " tip-bot for Josh Poimboeuf
2015-12-14  4:18 ` [PATCH v3 08/17] perf: Remove check for unused PERF_PAGER_IN_USE Josh Poimboeuf
2015-12-18  8:49   ` [tip:perf/core] perf tools: " tip-bot for Josh Poimboeuf
2015-12-14  4:18 ` [PATCH v3 09/17] perf: Move help_unknown_cmd() to its own file Josh Poimboeuf
2015-12-18  8:50   ` [tip:perf/core] perf tools: " tip-bot for Josh Poimboeuf
2015-12-14  4:18 ` [PATCH v3 10/17] perf: Provide subcmd configuration at runtime Josh Poimboeuf
2015-12-14 10:33   ` Jiri Olsa
2015-12-14 14:06     ` Josh Poimboeuf
2015-12-14  4:18 ` [PATCH v3 11/17] perf: Remove 'perf' from subcmd function and variable names Josh Poimboeuf
2015-12-14  4:18 ` [PATCH v3 12/17] perf: Convert parse-options.c internal functions to static Josh Poimboeuf
2015-12-18  8:50   ` [tip:perf/core] perf tools: " tip-bot for Josh Poimboeuf
2015-12-14  4:18 ` [PATCH v3 13/17] perf: Document the fact that parse_options*() may exit Josh Poimboeuf
2015-12-14  4:18 ` [PATCH v3 14/17] perf: Remove subcmd dependencies on strbuf Josh Poimboeuf
2015-12-14 10:25   ` Jiri Olsa
2015-12-14 14:11     ` Josh Poimboeuf
2015-12-14 15:44   ` Arnaldo Carvalho de Melo
2015-12-14 16:05     ` Josh Poimboeuf
2015-12-14 17:50       ` Arnaldo Carvalho de Melo
2015-12-14 18:04         ` Josh Poimboeuf
2015-12-14  4:18 ` [PATCH v3 15/17] perf: Finalize subcmd independence Josh Poimboeuf
2015-12-14 10:32   ` Jiri Olsa
2015-12-14 14:13     ` Josh Poimboeuf
2015-12-14 15:27       ` Jiri Olsa
2015-12-14 15:51       ` Arnaldo Carvalho de Melo
2015-12-14  4:18 ` [PATCH v3 16/17] perf subcmd: Create subcmd library Josh Poimboeuf
2015-12-14  4:18 ` [PATCH v3 17/17] tools subcmd: Rename subcmd header include guards Josh Poimboeuf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.