perf tools: Move perf subcommand framework into lib/tools
Subsystems (2)
v2 cover perf tools: Move perf subcommand framework into lib/tools
Ingo suggested that I factor out the perf subcommand functionality (originally copied from git) into tools/lib so that it can be used by stacktool[*] and possibly others.
All the subcommand option handling files have been moved into libapi, including parse-options.c, run-command.c, exec_cmd.c, help.c, usage.c, and their dependencies. Since several of the dependencies are more general-purpose "utilities" which aren't directly related to subcommands, I put everything in 'tools/lib/api/util'. They're linked into perf as part of the libapi.a library.
Patches 1-13 do some cleanups and splitting up of the code in preparation for the move.
Patch 14 does the actual moving of the files into tools/lib/api/util.
Based on tip/perf/core.
[*] https://lkml.kernel.org/r/[email protected]
v2:
- Fix 'make clean' to remove tests/llvm-src-*.c and other leftover files
- Fix description for "Move tools/lib/string.c to libapi" patch
Josh Poimboeuf (14):
perf: Fix 'make clean'
perf: Use -iquote for local include paths
perf: Split up util.h
perf: Move term functions out of util.c
perf: Remove unused pager_use_color variable
perf: Split up cache.h
perf: Remove cache.h
perf: Save cmdline arguments earlier
perf: Remove check for unused PERF_PAGER_IN_USE
perf: Move cmd_version() to builtin-version.c
perf: Move help_unknown_cmd() to its own file
perf tools: Move strlcpy() to tools/lib/string.c
perf tools: Move tools/lib/string.c to libapi
perf tools: Move subcommand framework and related utils to libapi
tools/include/asm-generic/bitops/__fls.h | 2 +-
tools/include/asm-generic/bitops/fls.h | 2 +-
tools/include/asm-generic/bitops/fls64.h | 2 +-
tools/lib/api/Build | 2 +
tools/lib/api/Makefile | 6 +-
tools/lib/api/string/Build | 1 +
tools/lib/{ => api/string}/string.c | 24 +-
tools/{include/linux => lib/api/string}/string.h | 15 +-
tools/lib/api/util/Build | 13 +
tools/{perf => lib/api}/util/abspath.c | 6 +-
tools/lib/api/util/abspath.h | 11 +
tools/lib/api/util/cfg.c | 12 +
tools/lib/api/util/cfg.h | 15 +
tools/lib/api/util/compat-util.h | 129 +++++++++
tools/{perf => lib/api}/util/ctype.c | 3 +-
tools/lib/api/util/ctype.h | 52 ++++
tools/{perf => lib/api}/util/exec_cmd.c | 42 +--
tools/{perf => lib/api}/util/exec_cmd.h | 18 +-
tools/{perf => lib/api}/util/help.c | 134 ++-------
tools/{perf => lib/api}/util/help.h | 3 +
tools/{perf => lib/api}/util/pager.c | 14 +-
tools/lib/api/util/pager.h | 7 +
tools/{perf => lib/api}/util/parse-options.c | 30 +-
tools/{perf => lib/api}/util/parse-options.h | 10 +-
tools/{perf => lib/api}/util/run-command.c | 12 +-
tools/{perf => lib/api}/util/run-command.h | 10 +-
tools/{perf => lib/api}/util/sigchain.c | 4 +-
tools/{perf => lib/api}/util/sigchain.h | 6 +-
tools/{perf => lib/api}/util/strbuf.c | 6 +-
tools/{perf => lib/api}/util/strbuf.h | 8 +-
tools/lib/api/util/term.c | 36 +++
tools/lib/api/util/term.h | 7 +
tools/{perf => lib/api}/util/usage.c | 4 +-
tools/lib/api/util/usage.h | 23 ++
tools/{perf => lib/api}/util/wrapper.c | 4 +-
.../{perf/util/cache.h => lib/api/util/wrapper.h} | 65 +----
tools/perf/Build | 3 +-
tools/perf/MANIFEST | 2 -
tools/perf/Makefile.perf | 13 +-
tools/perf/arch/x86/util/intel-pt.c | 2 +-
tools/perf/bench/futex-hash.c | 2 +-
tools/perf/bench/futex-lock-pi.c | 2 +-
tools/perf/bench/futex-requeue.c | 2 +-
tools/perf/bench/futex-wake-parallel.c | 2 +-
tools/perf/bench/futex-wake.c | 2 +-
tools/perf/bench/mem-functions.c | 2 +-
tools/perf/bench/numa.c | 2 +-
tools/perf/bench/sched-messaging.c | 2 +-
tools/perf/bench/sched-pipe.c | 2 +-
tools/perf/builtin-annotate.c | 3 +-
tools/perf/builtin-bench.c | 2 +-
tools/perf/builtin-buildid-cache.c | 4 +-
tools/perf/builtin-buildid-list.c | 4 +-
tools/perf/builtin-config.c | 3 +-
tools/perf/builtin-data.c | 2 +-
tools/perf/builtin-evlist.c | 2 +-
tools/perf/builtin-help.c | 11 +-
tools/perf/builtin-inject.c | 2 +-
tools/perf/builtin-kmem.c | 5 +-
tools/perf/builtin-kvm.c | 3 +-
tools/perf/builtin-list.c | 4 +-
tools/perf/builtin-lock.c | 3 +-
tools/perf/builtin-mem.c | 2 +-
tools/perf/builtin-probe.c | 2 +-
tools/perf/builtin-record.c | 2 +-
tools/perf/builtin-report.c | 3 +-
tools/perf/builtin-sched.c | 3 +-
tools/perf/builtin-script.c | 13 +-
tools/perf/builtin-stat.c | 2 +-
tools/perf/builtin-timechart.c | 3 +-
tools/perf/builtin-top.c | 3 +-
tools/perf/builtin-trace.c | 4 +-
tools/perf/builtin-version.c | 9 +
tools/perf/builtin.h | 2 +-
tools/perf/config/Makefile | 4 +-
tools/perf/perf.c | 30 +-
tools/perf/perf.h | 13 +
tools/perf/tests/Build | 6 +-
tools/perf/tests/attr.c | 4 +-
tools/perf/tests/bpf.c | 4 +-
tools/perf/tests/builtin-test.c | 2 +-
tools/perf/tests/llvm.c | 4 +-
tools/perf/ui/browser.c | 1 -
tools/perf/ui/browsers/header.c | 2 +-
tools/perf/ui/gtk/browser.c | 2 +-
tools/perf/ui/gtk/hists.c | 2 +-
tools/perf/ui/gtk/setup.c | 2 +-
tools/perf/ui/helpline.h | 2 +-
tools/perf/ui/progress.c | 2 +-
tools/perf/ui/setup.c | 7 +-
tools/perf/ui/tui/progress.c | 2 +-
tools/perf/ui/tui/setup.c | 1 -
tools/perf/ui/tui/util.c | 1 -
tools/perf/ui/ui.h | 1 +
tools/perf/util/Build | 20 +-
tools/perf/util/alias.c | 2 +-
tools/perf/util/alias.h | 7 +
tools/perf/util/annotate.c | 1 -
tools/perf/util/auxtrace.c | 4 +-
tools/perf/util/bpf-loader.c | 2 +-
tools/perf/util/cgroup.c | 2 +-
tools/perf/util/color.c | 4 +-
tools/perf/util/config.c | 3 +-
tools/perf/util/config.h | 18 ++
tools/perf/util/debug.c | 1 -
tools/perf/util/env.c | 9 -
tools/perf/util/environment.c | 8 -
tools/perf/util/evlist.c | 2 +-
tools/perf/util/header.c | 2 +-
tools/perf/util/help-unknown-cmd.c | 103 +++++++
tools/perf/util/help-unknown-cmd.h | 0
tools/perf/util/intel-pt-decoder/insn.c | 2 +-
.../perf/util/intel-pt-decoder/intel-pt-decoder.c | 1 -
tools/perf/util/levenshtein.c | 2 +-
tools/perf/util/llvm-utils.c | 1 -
tools/perf/util/lzma.h | 8 +
tools/perf/util/map.c | 2 +-
tools/perf/util/ordered-events.c | 2 +-
tools/perf/util/parse-branch-options.c | 2 +-
tools/perf/util/parse-events.c | 5 +-
tools/perf/util/parse-regs-options.c | 2 +-
tools/perf/util/path.c | 20 +-
tools/perf/util/path.h | 12 +
tools/perf/util/probe-event.c | 1 -
tools/perf/util/probe-file.c | 1 -
tools/perf/util/python-ext-sources | 1 -
tools/perf/util/quote.c | 2 +-
tools/perf/util/sort.h | 3 +-
tools/perf/util/srcline.h | 16 ++
tools/perf/util/string.h | 34 +++
tools/perf/util/thread.h | 4 +-
tools/perf/util/util.c | 34 ---
tools/perf/util/util.h | 314 ++-------------------
tools/perf/util/zlib.h | 8 +
134 files changed, 864 insertions(+), 765 deletions(-)
create mode 100644 tools/lib/api/string/Build
rename tools/lib/{ => api/string}/string.c (73%)
rename tools/{include/linux => lib/api/string}/string.h (23%)
create mode 100644 tools/lib/api/util/Build
rename tools/{perf => lib/api}/util/abspath.c (90%)
create mode 100644 tools/lib/api/util/abspath.h
create mode 100644 tools/lib/api/util/cfg.c
create mode 100644 tools/lib/api/util/cfg.h
create mode 100644 tools/lib/api/util/compat-util.h
rename tools/{perf => lib/api}/util/ctype.c (97%)
create mode 100644 tools/lib/api/util/ctype.h
rename tools/{perf => lib/api}/util/exec_cmd.c (72%)
rename tools/{perf => lib/api}/util/exec_cmd.h (14%)
rename tools/{perf => lib/api}/util/help.c (59%)
rename tools/{perf => lib/api}/util/help.h (85%)
rename tools/{perf => lib/api}/util/pager.c (88%)
create mode 100644 tools/lib/api/util/pager.h
rename tools/{perf => lib/api}/util/parse-options.c (97%)
rename tools/{perf => lib/api}/util/parse-options.h (98%)
rename tools/{perf => lib/api}/util/run-command.c (96%)
rename tools/{perf => lib/api}/util/run-command.h (87%)
rename tools/{perf => lib/api}/util/sigchain.c (93%)
rename tools/{perf => lib/api}/util/sigchain.h (53%)
rename tools/{perf => lib/api}/util/strbuf.c (97%)
rename tools/{perf => lib/api}/util/strbuf.h (95%)
create mode 100644 tools/lib/api/util/term.c
create mode 100644 tools/lib/api/util/term.h
rename tools/{perf => lib/api}/util/usage.c (97%)
create mode 100644 tools/lib/api/util/usage.h
rename tools/{perf => lib/api}/util/wrapper.c (92%)
rename tools/{perf/util/cache.h => lib/api/util/wrapper.h} (22%)
create mode 100644 tools/perf/builtin-version.c
create mode 100644 tools/perf/util/alias.h
create mode 100644 tools/perf/util/config.h
delete mode 100644 tools/perf/util/environment.c
create mode 100644 tools/perf/util/help-unknown-cmd.c
create mode 100644 tools/perf/util/help-unknown-cmd.h
create mode 100644 tools/perf/util/lzma.h
create mode 100644 tools/perf/util/path.h
create mode 100644 tools/perf/util/srcline.h
create mode 100644 tools/perf/util/string.h
create mode 100644 tools/perf/util/zlib.hSignature · 1 line
2.4.3
PATCH v2 1/14 perf: Fix 'make clean'
Add some missing files to the 'make clean' target.
--- tools/perf/Makefile.perf | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
tools/perf/Makefile.perf +11 -2
@@ -584,13 +584,22 @@ config-clean: $(call QUIET_CLEAN, config) $(Q)$(MAKE) -C $(srctree)/tools/build/feature/ clean >/dev/null -clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean config-clean +feature-clean: + $(call QUIET_CLEAN, feature) + $(Q)$(RM) -r $(OUTPUT)feature + +tests-clean: + $(call QUIET_CLEAN, tests) + $(Q)find $(OUTPUT)tests -name '*.o' -delete -o -name '\.*.cmd' -delete + $(Q)$(RM) $(OUTPUT)tests/llvm-src-{base,kbuild,prologue}.c + +clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean config-clean feature-clean tests-clean $(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)$(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 $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean $(python-clean)
Signature · 1 line
2.4.3
Re: [PATCH v2 01/14] perf: Fix 'make clean'
Quoted 13 lines · Josh Poimboeuf
Add some missing files to the 'make clean' target.
Reported-by Jiri Olsa <[email protected]>Signed-off-by Josh Poimboeuf <[email protected]>--- tools/perf/Makefile.perf | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)tools/perf/Makefile.perf +0
-0
tools/perf/Makefile.perf config-clean: · line 589
Quoted 7 lines
tools/perf/Makefile.perf +3
-1@@ -584,13 +584,22 @@ config-clean: $(call QUIET_CLEAN, config) $(Q)$(MAKE) -C $(srctree)/tools/build/feature/ clean >/dev/null -clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean config-clean +feature-clean: + $(call QUIET_CLEAN, feature) + $(Q)$(RM) -r $(OUTPUT)feature
that should be within feature dir
tools/perf/Makefile.perf config-clean: · line 593
Quoted 4 lines
tools/perf/Makefile.perf +4
-0+ +tests-clean: + $(call QUIET_CLEAN, tests) + $(Q)find $(OUTPUT)tests -name '*.o' -delete -o -name '\.*.cmd' -delete
hum, that'd be excuted twice (another one below)
how about putting llvm-src* files under core-gen clean below
jirka
tools/perf/Makefile.perf config-clean: · line 604
Quoted 12 lines
tools/perf/Makefile.perf +4
-1+ $(Q)$(RM) $(OUTPUT)tests/llvm-src-{base,kbuild,prologue}.c + +clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean config-clean feature-clean tests-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)$(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 $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean $(python-clean)
---
tools/build/feature/Makefile +3 -0
@@ -179,3 +179,6 @@ test-bpf.bin: clean: rm -f $(FILES) *.d $(FILES:.bin=.make.output) +ifdef OUTPUT + rm -rf $(OUTPUT)feature +endif
tools/perf/Makefile.perf +2 -1
@@ -590,7 +590,8 @@ clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean config-clean $(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)tests/llvm-src-{base,kbuild,prologue}.c $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean $(python-clean)
Re: [PATCH v2 01/14] perf: Fix 'make clean'
Quoted 24 lines · Jiri Olsa
Quoted 13 lines · Josh Poimboeuf
Add some missing files to the 'make clean' target.
Reported-by Jiri Olsa <[email protected]>Signed-off-by Josh Poimboeuf <[email protected]>--- tools/perf/Makefile.perf | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)tools/perf/Makefile.perf +0
-0tools/perf/Makefile.perf config-clean: · line 589
Quoted 7 lines
tools/perf/Makefile.perf +3
-1@@ -584,13 +584,22 @@ config-clean: $(call QUIET_CLEAN, config) $(Q)$(MAKE) -C $(srctree)/tools/build/feature/ clean >/dev/null -clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean config-clean +feature-clean: + $(call QUIET_CLEAN, feature) + $(Q)$(RM) -r $(OUTPUT)featurethat should be within feature dir
Quoted 6 lines
tools/perf/Makefile.perf config-clean: · line 593
Quoted 4 lines
tools/perf/Makefile.perf +4
-0+ +tests-clean: + $(call QUIET_CLEAN, tests) + $(Q)find $(OUTPUT)tests -name '*.o' -delete -o -name '\.*.cmd' -deletehum, that'd be excuted twice (another one below)
it also crashes build test (make -f tests/make)
jirka
[jolsa@krava perf]$ make -f tests/make make_clean_all_O
Testing Makefile
- make_clean_all_O: cd . && make -f Makefile O=/tmp/tmp.glBnmXFNzM DESTDIR=/tmp/tmp.S5f5hGWoVy clean all cd . && make -f Makefile O=/tmp/tmp.glBnmXFNzM DESTDIR=/tmp/tmp.S5f5hGWoVy clean all
CLEAN libapi CLEAN libtraceevent CLEAN libbpf CLEAN config CLEAN feature CLEAN tests
find: ‘/tmp/tmp.glBnmXFNzM/tests’: No such file or directory Makefile.perf:592: recipe for target 'tests-clean' failed make[3]: *** [tests-clean] Error 1
make[3]: *** Waiting for unfinished jobs.... Makefile:75: recipe for target 'clean' failed make[2]: *** [clean] Error 2
tests/make:249: recipe for target 'make_clean_all_O' failed make[1]: *** [make_clean_all_O] Error 1 tests/make:10: recipe for target 'make_clean_all_O' failed
make: *** [make_clean_all_O] Error 2
Re: [PATCH v2 01/14] perf: Fix 'make clean'
Quoted 25 lines · Jiri Olsa
Quoted 24 lines · Jiri Olsa
Quoted 13 lines · Josh Poimboeuf
Add some missing files to the 'make clean' target.
Reported-by Jiri Olsa <[email protected]>Signed-off-by Josh Poimboeuf <[email protected]>--- tools/perf/Makefile.perf | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)tools/perf/Makefile.perf +0
-0tools/perf/Makefile.perf config-clean: · line 589
Quoted 7 lines
tools/perf/Makefile.perf +3
-1@@ -584,13 +584,22 @@ config-clean: $(call QUIET_CLEAN, config) $(Q)$(MAKE) -C $(srctree)/tools/build/feature/ clean >/dev/null -clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean config-clean +feature-clean: + $(call QUIET_CLEAN, feature) + $(Q)$(RM) -r $(OUTPUT)featurethat should be within feature dir
Quoted 8 lines
Quoted 6 lines
tools/perf/Makefile.perf config-clean: · line 593
Quoted 4 lines
tools/perf/Makefile.perf +4
-0+ +tests-clean: + $(call QUIET_CLEAN, tests) + $(Q)find $(OUTPUT)tests -name '*.o' -delete -o -name '\.*.cmd' -deletehum, that'd be excuted twice (another one below)
it also crashes build test (make -f tests/make)
Thanks, I'll look into it.
Quoted 23 lines
jirka
[jolsa@krava perf]$ make -f tests/make
make_clean_all_O
TestingMakefile
-make_clean_all_O: cd . && make -fMakefileO=/tmp/tmp.glBnmXFNzM DESTDIR=/tmp/tmp.S5f5hGWoVy clean all cd . && make -fMakefileO=/tmp/tmp.glBnmXFNzM DESTDIR=/tmp/tmp.S5f5hGWoVy clean allCLEAN libapi CLEAN libtraceevent CLEAN libbpf CLEAN config CLEAN feature CLEAN testsfind: ‘/tmp/tmp.glBnmXFNzM/tests’: No such file or directory Makefile.perf:592: recipe for target 'tests-clean' failed make[3]: *** [tests-clean] Error 1
make[3]: *** Waiting for unfinished jobs.... Makefile:75: recipe for target 'clean' failed make[2]: *** [clean] Error 2
tests/make:249: recipe for target 'make_clean_all_O' failed make[1]: *** [make_clean_all_O] Error 1 tests/make:10: recipe for target 'make_clean_all_O' failed
make: *** [make_clean_all_O] Error 2
Signature · 1 line
Josh
Re: [PATCH v2 01/14] perf: Fix 'make clean'
In reply to Jiri OlsaQuoted 17 lines · Jiri Olsa
Quoted 16 lines · Josh Poimboeuf
Add some missing files to the 'make clean' target.
Reported-by Jiri Olsa <[email protected]>Signed-off-by Josh Poimboeuf <[email protected]>--- tools/perf/Makefile.perf | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)tools/perf/Makefile.perf +0
-0@@ -584,13 +584,22 @@ config-clean: $(call QUIET_CLEAN, config) $(Q)$(MAKE) -C $(srctree)/tools/build/feature/ clean >/dev/null
Quoted 6 lines
tools/perf/Makefile.perf config-clean: · line 589
Quoted 4 lines
tools/perf/Makefile.perf +3
-1-clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean config-clean +feature-clean: + $(call QUIET_CLEAN, feature) + $(Q)$(RM) -r $(OUTPUT)featurethat should be within feature dir
Ok, I'll try to figure out how to use the feature Makefile to do it.
Quoted 6 lines
tools/perf/Makefile.perf config-clean: · line 593
Quoted 4 lines
tools/perf/Makefile.perf +4
-0+ +tests-clean: + $(call QUIET_CLEAN, tests) + $(Q)find $(OUTPUT)tests -name '*.o' -delete -o -name '\.*.cmd' -deletehum, that'd be excuted twice (another one below)
True, though the "find" statement below doesn't touch $(OUTPUT). I'll get rid of this one and make the below one more universal.
Quoted 1 line
how about putting llvm-src* files under core-gen clean below
Ok.
Quoted 41 lines
jirka
tools/perf/Makefile.perf clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean config-clean · line 596
Quoted 12 lines
tools/perf/Makefile.perf +4
-1+ $(Q)$(RM) $(OUTPUT)tests/llvm-src-{base,kbuild,prologue}.c + +clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean config-clean feature-clean tests-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)$(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 $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean $(python-clean)---
tools/build/feature/Makefile +3
-0@@ -179,3 +179,6 @@ test-bpf.bin: clean: rm -f $(FILES) *.d $(FILES:.bin=.make.output) +ifdef OUTPUT + rm -rf $(OUTPUT)feature +endiftools/perf/Makefile.perf +2
-1@@ -590,7 +590,8 @@ clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean config-clean $(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)tests/llvm-src-{base,kbuild,prologue}.c $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean $(python-clean)
Signature · 1 line
Josh
PATCH v2 2/14 perf: Use -iquote for local include paths
In reply to Josh PoimboeufIf there's a local header file which has the same name as a system header file, '#include <header.h>' will mistakenly include the local file instead of the system file.
With the next patch we'll have a string.h file. Use the '-iquote' option to prepare for it so that '#include "string.h"' picks up the local version.
Note that after applying this patch, a 'make clean' is needed to clear out the old versions of tools/perf/tests/llvm-src-*.c.
--- tools/perf/config/Makefile | 4 ++-- tools/perf/tests/Build | 6 +++--- tools/perf/tests/bpf.c | 4 ++-- tools/perf/tests/llvm.c | 4 ++-- tools/perf/util/thread.h | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-)
tools/perf/config/Makefile +2 -2
@@ -210,8 +210,8 @@ CFLAGS += -I$(obj-perf)/util CFLAGS += -I$(obj-perf) endif -CFLAGS += -I$(src-perf)/util -CFLAGS += -I$(src-perf) +CFLAGS += -iquote $(src-perf)/util +CFLAGS += -iquote $(src-perf) CFLAGS += -I$(srctree)/tools/lib/ CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
tools/perf/tests/Build +3 -3
@@ -37,21 +37,21 @@ perf-y += topology.o $(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c $(call rule_mkdir) - $(Q)echo '#include <tests/llvm.h>' > $@ + $(Q)echo '#include "tests/llvm.h"' > $@ $(Q)echo 'const char test_llvm__bpf_base_prog[] =' >> $@ $(Q)sed -e 's/"/\\"/g' -e 's/\(.*\)/"\1\\n"/g' $< >> $@ $(Q)echo ';' >> $@ $(OUTPUT)tests/llvm-src-kbuild.c: tests/bpf-script-test-kbuild.c $(call rule_mkdir) - $(Q)echo '#include <tests/llvm.h>' > $@ + $(Q)echo '#include "tests/llvm.h"' > $@ $(Q)echo 'const char test_llvm__bpf_test_kbuild_prog[] =' >> $@ $(Q)sed -e 's/"/\\"/g' -e 's/\(.*\)/"\1\\n"/g' $< >> $@ $(Q)echo ';' >> $@ $(OUTPUT)tests/llvm-src-prologue.c: tests/bpf-script-test-prologue.c $(call rule_mkdir) - $(Q)echo '#include <tests/llvm.h>' > $@ + $(Q)echo '#include "tests/llvm.h"' > $@ $(Q)echo 'const char test_llvm__bpf_test_prologue_prog[] =' >> $@ $(Q)sed -e 's/"/\\"/g' -e 's/\(.*\)/"\1\\n"/g' $< >> $@ $(Q)echo ';' >> $@
tools/perf/tests/bpf.c +2 -2
@@ -1,7 +1,7 @@#include <stdio.h> #include <sys/epoll.h> -#include <util/bpf-loader.h> -#include <util/evlist.h> +#include "util/bpf-loader.h" +#include "util/evlist.h" #include "tests.h" #include "llvm.h" #include "debug.h"
tools/perf/tests/llvm.c +2 -2
@@ -1,7 +1,7 @@#include <stdio.h> #include <bpf/libbpf.h> -#include <util/llvm-utils.h> -#include <util/cache.h> +#include "util/llvm-utils.h" +#include "util/cache.h" #include "llvm.h" #include "tests.h" #include "debug.h"
tools/perf/util/thread.h +2 -2
@@ -7,8 +7,8 @@#include <unistd.h> #include <sys/types.h> #include "symbol.h" -#include <strlist.h> -#include <intlist.h> +#include "strlist.h" +#include "intlist.h" struct thread_stack ;
Signature · 1 line
2.4.3
PATCH v2 3/14 perf: Split up util.h
In reply to Josh Poimboeufutil.h is a hodgepodge which consists of:
1) some compatibility macros and system includes
2) declarations for util.c
3) declarations for other .c files
Move the compatibility macros and system includes to compat-util.h. Move the declarations for other .c files to their respective proper locations, creating new header files where needed.
This makes the code better organized and will make it easier to untangle these pieces into separate components later.
--- tools/perf/util/compat-util.h | 130 +++++++++++++++++ tools/perf/util/config.h | 9 ++ tools/perf/util/ctype.h | 52 +++++++ tools/perf/util/help.c | 8 ++ tools/perf/util/lzma.h | 8 ++ tools/perf/util/parse-options.c | 6 + tools/perf/util/srcline.h | 16 +++ tools/perf/util/strbuf.h | 2 + tools/perf/util/string.h | 34 +++++ tools/perf/util/usage.h | 23 +++ tools/perf/util/util.h | 302 ++-------------------------------------- tools/perf/util/wrapper.h | 14 ++ tools/perf/util/zlib.h | 8 ++ 13 files changed, 323 insertions(+), 289 deletions(-) create mode 100644 tools/perf/util/compat-util.h create mode 100644 tools/perf/util/config.h create mode 100644 tools/perf/util/ctype.h create mode 100644 tools/perf/util/lzma.h create mode 100644 tools/perf/util/srcline.h create mode 100644 tools/perf/util/string.h create mode 100644 tools/perf/util/usage.h create mode 100644 tools/perf/util/wrapper.h create mode 100644 tools/perf/util/zlib.h
tools/perf/util/compat-util.h new file +130 -0
@@ -0,0 +1,130 @@ +#ifndef __PERF_COMPAT_UTIL_H +#define __PERF_COMPAT_UTIL_H + +#ifndef FLEX_ARRAY +/* +* See if our compiler is known to support flexible array members. +*/ +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >=199901L ) +# define FLEX_ARRAY /* empty */ +#elif defined(__GNUC__) +# if (__GNUC__ >=3 ) +# define FLEX_ARRAY /* empty */ +# else +# define FLEX_ARRAY 0/* older GNU extension */ +# endif +#endif + +/* +* Otherwise, default to safer but a bit wasteful traditional style +*/ +#ifndef FLEX_ARRAY +# define FLEX_ARRAY 1 +#endif +#endif + +#define ARRAY_SIZE (x) (sizeof(x)/sizeof(x[0])) + +#ifdef __GNUC__ +#define TYPEOF (x) (__typeof__(x)) +#else +#define TYPEOF (x) +#endif + +#define MSB (x, bits) ((x) & TYPEOF(x)(~0ULL << (sizeof(x) * 8 - (bits)))) +#define HAS_MULTI_BITS (i) ((i) & ((i) - 1))/* checks if an integer has more than 1 bit set */ + +/* Approximation of the length of the decimal representation of this type. */ +#define decimal_length (x) ((int)(sizeof(x) * 2.56 + 0.5) + 1) + +#define _ALL_SOURCE 1 +#define _BSD_SOURCE 1 +/* glibc 2.20 deprecates _BSD_SOURCE in favour of _DEFAULT_SOURCE */ +#define _DEFAULT_SOURCE 1 +#define HAS_BOOL + +#include <unistd.h> +#include <stdio.h> +#include <sys/stat.h> +#include <sys/statfs.h> +#include <fcntl.h> +#include <stdbool.h> +#include <stddef.h> +#include <stdlib.h> +#include <stdarg.h> +#include <string.h> +#include <errno.h> +#include <limits.h> +#include <sys/param.h> +#include <sys/types.h> +#include <dirent.h> +#include <sys/time.h> +#include <time.h> +#include <signal.h> +#include <fnmatch.h> +#include <assert.h> +#include <regex.h> +#include <utime.h> +#include <sys/wait.h> +#include <poll.h> +#include <sys/socket.h> +#include <sys/ioctl.h> +#include <inttypes.h> +#include <linux/kernel.h> +#include <linux/magic.h> +#include <linux/types.h> +#include <sys/ttydefaults.h> +#include <api/fs/tracing_path.h> +#include <termios.h> +#include <linux/bitops.h> +#include <termios.h> + +/* On most systems <limits.h> would have given us this, but +* not on some systems (e.g. GNU/Hurd). +*/ +#ifndef PATH_MAX +#define PATH_MAX 4096 +#endif + +#ifndef PRIuMAX +#define PRIuMAX "llu" +#endif + +#ifndef PRIu32 +#define PRIu32 "u" +#endif + +#ifndef PRIx32 +#define PRIx32 "x" +#endif + +#ifndef PATH_SEP +#define PATH_SEP ':' +#endif + +#ifndef STRIP_EXTENSION +#define STRIP_EXTENSION "" +#endif + +#ifndef has_dos_drive_prefix +#define has_dos_drive_prefix (path) 0 +#endif + +#ifndef is_dir_sep +#define is_dir_sep (c) ((c) == '/') +#endif + +#ifdef __GNUC__ +#define NORETURN __attribute__((__noreturn__)) +#else +#define NORETURN +#ifndef __attribute__ +#define __attribute__ (x) +#endif +#endif + +#ifndef NSEC_PER_MSEC +#define NSEC_PER_MSEC 1000000L +#endif + +#endif /* __PERF_COMPAT_UTIL_H */
tools/perf/util/config.h new file +9 -0
@@ -0,0 +1,9 @@ +#ifndef __PERF_CONFIG_H +#define __PERF_CONFIG_H + +#define PERF_GTK_DSO "libperf-gtk.so" + +extern char buildid_dir[]; +extern void set_buildid_dir (const char *dir); + +#endif /* __PERF_CONFIG_H */
tools/perf/util/ctype.h new file +52 -0
52 lines not on this page · raw message
tools/perf/util/help.c +8 -0
@@ -114,6 +114,14 @@ static int is_executable(const char *name)return st.st_mode &S_IXUSR ; } +static int has_extension (const char *filename,const char *ext) +{ +size_t len =strlen (filename); +size_t extlen =strlen (ext); + +return len > extlen && !memcmp (filename + len - extlen, ext, extlen); +} +static void list_commands_in_dir (struct cmdnames *cmds,const char *path,const char *prefix)
tools/perf/util/lzma.h new file +8 -0
@@ -0,0 +1,8 @@ +#ifndef __PERF_LZMA_H +#define __PERF_LZMA_H + +#ifdef HAVE_LZMA_SUPPORT +int lzma_decompress_to_file (const char *input,int output_fd); +#endif + +#endif /* __PERF_LZMA_H */
tools/perf/util/parse-options.c +6 -0
@@ -9,6 +9,12 @@static struct strbuf error_buf =STRBUF_INIT ; +static const char *skip_prefix (const char *str,const char *prefix) +{ +size_t len =strlen (prefix); +return strncmp (str, prefix, len) ?NULL : str + len; +} +static int opterror (const struct option *opt,const char *reason,int flags) {if (flags &OPT_SHORT )
tools/perf/util/srcline.h new file +16 -0
@@ -0,0 +1,16 @@ +#ifndef __PERF_SRCLINE_H +#define __PERF_SRCLINE_H + +#define SRCLINE_UNKNOWN ((char *) "??:0") + +struct dso ; +struct symbol ; + +extern bool srcline_full_filename; +char *get_srcline (struct dso *dso,u64 addr,struct symbol *sym, +bool show_sym); +char *__get_srcline (struct dso *dso,u64 addr,struct symbol *sym, +bool show_sym,bool unwind_inlines); +void free_srcline (char *srcline); + +#endif /* __PERF_SRCLINE_H */
tools/perf/util/strbuf.h +2 -0
@@ -50,6 +50,8 @@ struct strbuf {#define STRBUF_INIT { 0, 0, strbuf_slopbuf } +extern int prefixcmp (const char *str,const char *prefix); +/*----- strbuf life cycle -----*/ extern void strbuf_init (struct strbuf *buf,ssize_t hint);extern void strbuf_release (struct strbuf *);
tools/perf/util/string.h new file +34 -0
@@ -0,0 +1,34 @@ +#ifndef __PERF_STRING_H +#define __PERF_STRING_H + +s64 perf_atoll (const char *str); +char **argv_split (const char *str,int *argcp); +void argv_free (char **argv); +bool strglobmatch (const char *str,const char *pat); +bool strlazymatch (const char *str,const char *pat); +static inline bool strisglob (const char *str) +{ +return strpbrk (str,"*?[" ) !=NULL ; +} +int strtailcmp (const char *s1,const char *s2); +char *strxfrchar (char *s,char from,char to); + +#define _STR (x) #x +#define STR (x) _STR(x) + +char *ltrim (char *s); +char *rtrim (char *s); + +char *asprintf_expr_inout_ints (const char *var,bool in,size_t nints,int *ints); + +static inline char *asprintf_expr_in_ints (const char *var,size_t nints,int *ints) +{ +return asprintf_expr_inout_ints (var, true, nints, ints); +} + +static inline char *asprintf_expr_not_in_ints (const char *var,size_t nints,int *ints) +{ +return asprintf_expr_inout_ints (var, false, nints, ints); +} + +#endif /* __PERF_STRING_H */
tools/perf/util/usage.h new file +23 -0
@@ -0,0 +1,23 @@ +#ifndef __PERF_USAGE_H +#define __PERF_USAGE_H + +#include "compat-util.h" + +extern void usage(const char *err) NORETURN; +extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2))); +extern int error (const char *err, ...) __attribute__((format (printf,1 ,2 ))); +extern void warning (const char *err, ...) __attribute__((format (printf,1 ,2 ))); + +#include "../../../include/linux/stringify.h" + +#define DIE_IF (cnd) \ + do { if (cnd) \ + die(" at (" __FILE__ ":" __stringify(__LINE__) "): " \ + __stringify(cnd) "\n"); \ + } while (0) + + +extern void set_die_routine (void (*routine)(const char *err,va_list params)NORETURN ); +extern void set_warning_routine (void (*routine)(const char *err,va_list params)); + +#endif /* __PERF_USAGE_H */
tools/perf/util/util.h +13 -289
346 lines not on this page · raw message
tools/perf/util/wrapper.h new file +14 -0
@@ -0,0 +1,14 @@ +#ifndef __PERF_WRAPPER_H +#define __PERF_WRAPPER_H + +extern char *xstrdup (const char *str); +extern void *xrealloc (void *ptr,size_t size) __attribute__((weak)); + +static inline void *zalloc (size_t size) +{ +return calloc (1 , size); +} + +#define zfree (ptr) ({ free(*ptr); *ptr = NULL; }) + +#endif /* __PERF_WRAPPER_H */
tools/perf/util/zlib.h new file +8 -0
@@ -0,0 +1,8 @@ +#ifndef __PERF_ZLIB_H +#define __PERF_ZLIB_H + +#ifdef HAVE_ZLIB_SUPPORT +int gzip_decompress_to_file (const char *input,int output_fd); +#endif + +#endif /* __PERF_ZLIB_H */
Signature · 1 line
2.4.3
PATCH v2 4/14 perf: Move term functions out of util.c
In reply to Josh PoimboeufThe term functions are needed by help.c which is going to be moved into a separate library. Move them out of util.c and into their own file.
--- tools/perf/util/Build | 1 + tools/perf/util/term.c | 35 +++++++++++++++++++++++++++++++++++ tools/perf/util/term.h | 7 +++++++ tools/perf/util/util.c | 34 ---------------------------------- tools/perf/util/util.h | 4 +--- 5 files changed, 44 insertions(+), 37 deletions(-) create mode 100644 tools/perf/util/term.c create mode 100644 tools/perf/util/term.h
tools/perf/util/Build +1 -0
@@ -87,6 +87,7 @@ libperf-$(CONFIG_AUXTRACE) += intel-pt.o libperf-$(CONFIG_AUXTRACE) += intel-bts.o libperf-y += parse-branch-options.o libperf-y += parse-regs-options.o +libperf-y += term.o libperf-$(CONFIG_LIBBPF) += bpf-loader.o libperf-$(CONFIG_BPF_PROLOGUE) += bpf-prologue.o
tools/perf/util/term.c new file +35 -0
@@ -0,0 +1,35 @@ +#include "util.h" + +void get_term_dimensions (struct winsize *ws) +{ +char *s =getenv ("LINES" ); + +if (s !=NULL ) { + ws->ws_row =atoi (s); + s =getenv ("COLUMNS" ); +if (s !=NULL ) { + ws->ws_col =atoi (s); +if (ws->ws_row && ws->ws_col) +return ; + } + } +#ifdef TIOCGWINSZ +if (ioctl (1 ,TIOCGWINSZ , ws) ==0 && + ws->ws_row && ws->ws_col) +return ; +#endif + ws->ws_row =25 ; + ws->ws_col =80 ; +} + +void set_term_quiet_input (struct termios *old) +{ +struct termios tc; + +tcgetattr (0 , old); + tc = *old; + tc.c_lflag &= ~(ICANON |ECHO ); + tc.c_cc[VMIN ] =0 ; + tc.c_cc[VTIME ] =0 ; +tcsetattr (0 ,TCSANOW , &tc); +}
tools/perf/util/term.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef __PERF_TERM_H +#define __PERF_TERM_H + +void get_term_dimensions (struct winsize *ws); +void set_term_quiet_input (struct termios *old); + +#endif /* __PERF_TERM_H */
tools/perf/util/util.c +0 -34
@@ -355,40 +355,6 @@ void sighandler_dump_stack(int sig)exit (sig); } -void get_term_dimensions (struct winsize *ws) -{ -char *s =getenv ("LINES" ); - -if (s !=NULL ) { - ws->ws_row =atoi (s); - s =getenv ("COLUMNS" ); -if (s !=NULL ) { - ws->ws_col =atoi (s); -if (ws->ws_row && ws->ws_col) -return ; - } - } -#ifdef TIOCGWINSZ -if (ioctl (1 ,TIOCGWINSZ , ws) ==0 && - ws->ws_row && ws->ws_col) -return ; -#endif - ws->ws_row =25 ; - ws->ws_col =80 ; -} - -void set_term_quiet_input (struct termios *old) -{ -struct termios tc; - -tcgetattr (0 , old); - tc = *old; - tc.c_lflag &= ~(ICANON |ECHO ); - tc.c_cc[VMIN ] =0 ; - tc.c_cc[VTIME ] =0 ; -tcsetattr (0 ,TCSANOW , &tc); -} -int parse_nsec_time (const char *str,u64 *ptime) {u64 time_sec, time_nsec;
tools/perf/util/util.h +1 -3
@@ -9,6 +9,7 @@#include "srcline.h" #include "strbuf.h" #include "string.h" +#include "term.h" #include "usage.h" #include "wrapper.h" #include "zlib.h"
@@ -38,9 +39,6 @@ void sighandler_dump_stack(int sig);extern unsigned int page_size;extern int cacheline_size; -void get_term_dimensions (struct winsize *ws); -void set_term_quiet_input (struct termios *old); -struct parse_tag {char tag;int mult;
Signature · 1 line
2.4.3
Re: [PATCH v2 04/14] perf: Move term functions out of util.c
Em Mon, Dec 07, 2015 at 10:21:42PM -0600, Josh Poimboeuf escreveu:
Quoted 2 lines
The term functions are needed by
help.cwhich is going to be moved into a separate library. Move them out ofutil.cand into their own file.
Applied, after some minor fixups due to the fact that the previous patch is still being discussed.
Quoted 146 lines
Signed-off-by Josh Poimboeuf <[email protected]>--- tools/perf/util/Build | 1 + tools/perf/util/term.c | 35 +++++++++++++++++++++++++++++++++++ tools/perf/util/term.h | 7 +++++++ tools/perf/util/util.c | 34 ---------------------------------- tools/perf/util/util.h | 4 +--- 5 files changed, 44 insertions(+), 37 deletions(-) create mode 100644 tools/perf/util/term.c create mode 100644 tools/perf/util/term.htools/perf/util/Build +1
-0@@ -87,6 +87,7 @@ libperf-$(CONFIG_AUXTRACE) += intel-pt.o libperf-$(CONFIG_AUXTRACE) += intel-bts.o libperf-y += parse-branch-options.o libperf-y += parse-regs-options.o +libperf-y += term.o libperf-$(CONFIG_LIBBPF) += bpf-loader.o libperf-$(CONFIG_BPF_PROLOGUE) += bpf-prologue.otools/perf/util/term.c new file +35
-0@@ -0,0 +1,35 @@ +#include "util.h" + +void get_term_dimensions (struct winsize *ws) +{ +char *s =getenv ("LINES" ); + +if (s !=NULL ) { + ws->ws_row =atoi (s); + s =getenv ("COLUMNS" ); +if (s !=NULL ) { + ws->ws_col =atoi (s); +if (ws->ws_row && ws->ws_col) +return ; + } + } +#ifdef TIOCGWINSZ +if (ioctl (1 ,TIOCGWINSZ , ws) ==0 && + ws->ws_row && ws->ws_col) +return ; +#endif + ws->ws_row =25 ; + ws->ws_col =80 ; +} + +void set_term_quiet_input (struct termios *old) +{ +struct termios tc; + +tcgetattr (0 , old); + tc = *old; + tc.c_lflag &= ~(ICANON |ECHO ); + tc.c_cc[VMIN ] =0 ; + tc.c_cc[VTIME ] =0 ; +tcsetattr (0 ,TCSANOW , &tc); +}tools/perf/util/term.h new file +7
-0@@ -0,0 +1,7 @@ +#ifndef __PERF_TERM_H +#define __PERF_TERM_H + +void get_term_dimensions (struct winsize *ws); +void set_term_quiet_input (struct termios *old); + +#endif /* __PERF_TERM_H */ tools/perf/util/util.c +0
-34@@ -355,40 +355,6 @@ void sighandler_dump_stack(int sig)exit (sig); } -void get_term_dimensions (struct winsize *ws) -{ -char *s =getenv ("LINES" ); - -if (s !=NULL ) { - ws->ws_row =atoi (s); - s =getenv ("COLUMNS" ); -if (s !=NULL ) { - ws->ws_col =atoi (s); -if (ws->ws_row && ws->ws_col) -return ; - } - } -#ifdef TIOCGWINSZ -if (ioctl (1 ,TIOCGWINSZ , ws) ==0 && - ws->ws_row && ws->ws_col) -return ; -#endif - ws->ws_row =25 ; - ws->ws_col =80 ; -} - -void set_term_quiet_input (struct termios *old) -{ -struct termios tc; - -tcgetattr (0 , old); - tc = *old; - tc.c_lflag &= ~(ICANON |ECHO ); - tc.c_cc[VMIN ] =0 ; - tc.c_cc[VTIME ] =0 ; -tcsetattr (0 ,TCSANOW , &tc); -} -int parse_nsec_time (const char *str,u64 *ptime) {u64 time_sec, time_nsec;tools/perf/util/util.h +1
-3@@ -9,6 +9,7 @@#include "srcline.h" #include "strbuf.h" #include "string.h" +#include "term.h" #include "usage.h" #include "wrapper.h" #include "zlib.h" @@ -38,9 +39,6 @@ void sighandler_dump_stack(int sig);extern unsigned int page_size;extern int cacheline_size; -void get_term_dimensions (struct winsize *ws); -void set_term_quiet_input (struct termios *old); -struct parse_tag {char tag;int mult;Signature · 1 line
2.4.3
tip-bot for Josh Poimboeuf
merge bot[tip:perf/core] perf tools: Move term functions out of util.c
In reply to Josh Poimboeufperf tools: Move term functions out of util.c
Commit-ID: 1fe143c5f928e3d117355ce2655bac0eb80c1aa3 Gitweb: http://git.kernel.org/tip/1fe143c5f928e3d117355ce2655bac0eb80c1aa3 Author: Josh Poimboeuf <[email protected]> AuthorDate: Mon, 7 Dec 2015 22:21:42 -0600 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 9 Dec 2015 13:42:02 -0300
perf tools: Move term functions out of util.c
The term functions are needed by help.c which is going to be moved into a separate library. Move them out of util.c and into their own file.
--- tools/perf/util/Build | 1 + tools/perf/util/term.c | 35 +++++++++++++++++++++++++++++++++++ tools/perf/util/term.h | 10 ++++++++++ tools/perf/util/util.c | 34 ---------------------------------- tools/perf/util/util.h | 4 +--- 5 files changed, 47 insertions(+), 37 deletions(-)
tools/perf/util/Build +1 -0
@@ -86,6 +86,7 @@ libperf-$(CONFIG_AUXTRACE) += intel-pt.o libperf-$(CONFIG_AUXTRACE) += intel-bts.o libperf-y += parse-branch-options.o libperf-y += parse-regs-options.o +libperf-y += term.o libperf-$(CONFIG_LIBBPF) += bpf-loader.o libperf-$(CONFIG_BPF_PROLOGUE) += bpf-prologue.o
tools/perf/util/term.c new file +35 -0
@@ -0,0 +1,35 @@ +#include "util.h" + +void get_term_dimensions (struct winsize *ws) +{ +char *s =getenv ("LINES" ); + +if (s !=NULL ) { + ws->ws_row =atoi (s); + s =getenv ("COLUMNS" ); +if (s !=NULL ) { + ws->ws_col =atoi (s); +if (ws->ws_row && ws->ws_col) +return ; + } + } +#ifdef TIOCGWINSZ +if (ioctl (1 ,TIOCGWINSZ , ws) ==0 && + ws->ws_row && ws->ws_col) +return ; +#endif + ws->ws_row =25 ; + ws->ws_col =80 ; +} + +void set_term_quiet_input (struct termios *old) +{ +struct termios tc; + +tcgetattr (0 , old); + tc = *old; + tc.c_lflag &= ~(ICANON |ECHO ); + tc.c_cc[VMIN ] =0 ; + tc.c_cc[VTIME ] =0 ; +tcsetattr (0 ,TCSANOW , &tc); +}
tools/perf/util/term.h new file +10 -0
@@ -0,0 +1,10 @@ +#ifndef __PERF_TERM_H +#define __PERF_TERM_H + +struct termios ; +struct winsize ; + +void get_term_dimensions (struct winsize *ws); +void set_term_quiet_input (struct termios *old); + +#endif /* __PERF_TERM_H */
tools/perf/util/util.c +0 -34
@@ -355,40 +355,6 @@ void sighandler_dump_stack(int sig)exit (sig); } -void get_term_dimensions (struct winsize *ws) -{ -char *s =getenv ("LINES" ); - -if (s !=NULL ) { - ws->ws_row =atoi (s); - s =getenv ("COLUMNS" ); -if (s !=NULL ) { - ws->ws_col =atoi (s); -if (ws->ws_row && ws->ws_col) -return ; - } - } -#ifdef TIOCGWINSZ -if (ioctl (1 ,TIOCGWINSZ , ws) ==0 && - ws->ws_row && ws->ws_col) -return ; -#endif - ws->ws_row =25 ; - ws->ws_col =80 ; -} - -void set_term_quiet_input (struct termios *old) -{ -struct termios tc; - -tcgetattr (0 , old); - tc = *old; - tc.c_lflag &= ~(ICANON |ECHO ); - tc.c_cc[VMIN ] =0 ; - tc.c_cc[VTIME ] =0 ; -tcsetattr (0 ,TCSANOW , &tc); -} -int parse_nsec_time (const char *str,u64 *ptime) {u64 time_sec, time_nsec;
tools/perf/util/util.h +1 -3
@@ -53,6 +53,7 @@#include <stdlib.h> #include <stdarg.h> #include <string.h> +#include <term.h> #include <errno.h> #include <limits.h> #include <sys/param.h>
@@ -282,9 +283,6 @@ void sighandler_dump_stack(int sig);extern unsigned int page_size;extern int cacheline_size; -void get_term_dimensions (struct winsize *ws); -void set_term_quiet_input (struct termios *old); -struct parse_tag {char tag;int mult;
PATCH v2 5/14 perf: Remove unused pager_use_color variable
In reply to Josh Poimboeuf--- tools/perf/util/Build | 1 - tools/perf/util/cache.h | 1 - tools/perf/util/color.c | 2 +- tools/perf/util/environment.c | 8 -------- 4 files changed, 1 insertion(+), 11 deletions(-) delete mode 100644 tools/perf/util/environment.c
tools/perf/util/Build +0 -1
@@ -6,7 +6,6 @@ libperf-y += config.o libperf-y += ctype.o libperf-y += db-export.o libperf-y += env.o -libperf-y += environment.o libperf-y += event.o libperf-y += evlist.o libperf-y += evsel.o
tools/perf/util/cache.h +0 -1
@@ -31,7 +31,6 @@ extern const char *perf_config_dirname(const char *, const char *);/* pager.c */ extern void setup_pager (void );extern int pager_in_use (void ); -extern int pager_use_color;char *alias_lookup (const char *alias);int split_cmdline (char *cmdline,const char ***argv);
tools/perf/util/color.c +1 -1
@@ -24,7 +24,7 @@ int perf_config_colorbool(const char *var, const char *value, int stdout_is_tty) auto_color:if (stdout_is_tty <0 ) stdout_is_tty =isatty (1 ); -if (stdout_is_tty || (pager_in_use () && pager_use_color)) { +if (stdout_is_tty ||pager_in_use ()) {char *term =getenv ("TERM" );if (term &&strcmp (term,"dumb" ))return 1 ;
tools/perf/util/environment.c deleted +0 -8
@@ -1,8 +0,0 @@ -/* -* We put all the perf config variables in this same object -* file, so that programs can link against the config parser -* without having to link against all the rest of perf. -*/ -#include "cache.h" - -int pager_use_color =1 ;
Signature · 1 line
2.4.3
Re: [PATCH v2 05/14] perf: Remove unused pager_use_color variable
Em Mon, Dec 07, 2015 at 10:21:43PM -0600, Josh Poimboeuf escreveu:
Quoted 1 line
Signed-off-by Josh Poimboeuf <[email protected]>
Thanks, applied, trying to go thru the cherry pickable ones in this kit.
- Arnaldo
Quoted 61 lines
--- tools/perf/util/Build | 1 - tools/perf/util/cache.h | 1 - tools/perf/util/color.c | 2 +- tools/perf/util/environment.c | 8 -------- 4 files changed, 1 insertion(+), 11 deletions(-) delete mode 100644 tools/perf/util/environment.ctools/perf/util/Build +0
-1@@ -6,7 +6,6 @@ libperf-y += config.o libperf-y += ctype.o libperf-y += db-export.o libperf-y += env.o -libperf-y += environment.o libperf-y += event.o libperf-y += evlist.o libperf-y += evsel.otools/perf/util/cache.h +0
-1@@ -31,7 +31,6 @@ extern const char *perf_config_dirname(const char *, const char *);/* pager.c */ extern void setup_pager (void );extern int pager_in_use (void ); -extern int pager_use_color;char *alias_lookup (const char *alias);int split_cmdline (char *cmdline,const char ***argv);tools/perf/util/color.c +1
-1@@ -24,7 +24,7 @@ int perf_config_colorbool(const char *var, const char *value, int stdout_is_tty) auto_color:if (stdout_is_tty <0 ) stdout_is_tty =isatty (1 ); -if (stdout_is_tty || (pager_in_use () && pager_use_color)) { +if (stdout_is_tty ||pager_in_use ()) {char *term =getenv ("TERM" );if (term &&strcmp (term,"dumb" ))return 1 ;tools/perf/util/environment.c deleted +0
-8@@ -1,8 +0,0 @@ -/* -* We put all the perf config variables in this same object -* file, so that programs can link against the config parser -* without having to link against all the rest of perf. -*/ -#include "cache.h" - -int pager_use_color =1 ;Signature · 1 line
2.4.3
tip-bot for Josh Poimboeuf
merge bot[tip:perf/core] perf tools: Remove unused pager_use_color variable
In reply to Josh Poimboeufperf tools: Remove unused pager_use_color variable
Commit-ID: de7cf7cadca3a3c32c1f1dbf4593a54f236e2dcf Gitweb: http://git.kernel.org/tip/de7cf7cadca3a3c32c1f1dbf4593a54f236e2dcf Author: Josh Poimboeuf <[email protected]> AuthorDate: Mon, 7 Dec 2015 22:21:43 -0600 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 9 Dec 2015 13:42:02 -0300
perf tools: Remove unused pager_use_color variable
--- tools/perf/util/Build | 1 - tools/perf/util/cache.h | 1 - tools/perf/util/color.c | 2 +- tools/perf/util/environment.c | 8 -------- 4 files changed, 1 insertion(+), 11 deletions(-)
tools/perf/util/Build +0 -1
@@ -6,7 +6,6 @@ libperf-y += config.o libperf-y += ctype.o libperf-y += db-export.o libperf-y += env.o -libperf-y += environment.o libperf-y += event.o libperf-y += evlist.o libperf-y += evsel.o
tools/perf/util/cache.h +0 -1
@@ -31,7 +31,6 @@ extern const char *perf_config_dirname(const char *, const char *);/* pager.c */ extern void setup_pager (void );extern int pager_in_use (void ); -extern int pager_use_color;char *alias_lookup (const char *alias);int split_cmdline (char *cmdline,const char ***argv);
tools/perf/util/color.c +1 -1
@@ -24,7 +24,7 @@ int perf_config_colorbool(const char *var, const char *value, int stdout_is_tty) auto_color:if (stdout_is_tty <0 ) stdout_is_tty =isatty (1 ); -if (stdout_is_tty || (pager_in_use () && pager_use_color)) { +if (stdout_is_tty ||pager_in_use ()) {char *term =getenv ("TERM" );if (term &&strcmp (term,"dumb" ))return 1 ;
tools/perf/util/environment.c deleted +0 -8
@@ -1,8 +0,0 @@ -/* -* We put all the perf config variables in this same object -* file, so that programs can link against the config parser -* without having to link against all the rest of perf. -*/ -#include "cache.h" - -int pager_use_color =1 ;
PATCH v2 6/14 perf: Split up cache.h
In reply to Josh Poimboeufcache.h is a hodgepodge which consists of:
1) some macros
2) some includes
3) declarations for other .c files
Move the macros and declarations to more appropriate places. This makes the code more organized and makes it easier to separate out the components later. Some of the components will be moved out of perf into a separate library.
--- tools/perf/perf.h | 12 ++++++++ tools/perf/util/abspath.h | 11 ++++++++ tools/perf/util/alias.h | 7 +++++ tools/perf/util/cache.h | 72 ++++------------------------------------------- tools/perf/util/config.h | 9 ++++++ tools/perf/util/pager.h | 7 +++++ tools/perf/util/path.h | 17 +++++++++++ tools/perf/util/wrapper.h | 20 +++++++++++++ 8 files changed, 88 insertions(+), 67 deletions(-) create mode 100644 tools/perf/util/abspath.h create mode 100644 tools/perf/util/alias.h create mode 100644 tools/perf/util/pager.h create mode 100644 tools/perf/util/path.h
tools/perf/perf.h +12 -0
@@ -6,6 +6,18 @@#include <linux/types.h> #include <linux/perf_event.h> +#define CMD_EXEC_PATH "--exec-path" +#define CMD_PERF_DIR "--perf-dir=" +#define CMD_WORK_TREE "--work-tree=" +#define CMD_DEBUGFS_DIR "--debugfs-dir=" + +#define PERF_DIR_ENVIRONMENT "PERF_DIR" +#define PERF_WORK_TREE_ENVIRONMENT "PERF_WORK_TREE" +#define EXEC_PATH_ENVIRONMENT "PERF_EXEC_PATH" +#define DEFAULT_PERF_DIR_ENVIRONMENT ".perf" +#define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR" +#define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR" +extern bool test_attr__enabled;void test_attr__init (void ); void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu,
tools/perf/util/abspath.h new file +11 -0
@@ -0,0 +1,11 @@ +#ifndef __PERF_ABSPATH_H +#define __PERF_ABSPATH_H + +static inline int is_absolute_path (const char *path) +{ +return path[0 ] =='/' ; +} + +const char *make_nonrelative_path (const char *path); + +#endif /* __PERF_ABSPATH_H */
tools/perf/util/alias.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef __PERF_ALIAS_H +#define __PERF_ALIAS_H + +char *alias_lookup (const char *alias); +int split_cmdline (char *cmdline,const char ***argv); + +#endif /* __PERF_ALIAS_H */
tools/perf/util/cache.h +5 -67
77 lines not on this page · raw message
tools/perf/util/config.h +9 -0
@@ -6,4 +6,13 @@extern char buildid_dir[];extern void set_buildid_dir (const char *dir); +typedef int (*config_fn_t )(const char *,const char *,void *); +extern int perf_default_config (const char *,const char *,void *); +extern int perf_config (config_fn_t fn,void *); +extern int perf_config_int (const char *,const char *); +extern u64 perf_config_u64 (const char *,const char *); +extern int perf_config_bool (const char *,const char *); +extern int config_error_nonbool (const char *); +extern const char *perf_config_dirname (const char *,const char *); +#endif /* __PERF_CONFIG_H */
tools/perf/util/pager.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef __PERF_PAGER_H +#define __PERF_PAGER_H + +extern void setup_pager (void ); +extern int pager_in_use (void ); + +#endif /* __PERF_PAGER_H */
tools/perf/util/path.h new file +17 -0
@@ -0,0 +1,17 @@ +#ifndef __PERF_PATH_H +#define __PERF_PATH_H + +char *strip_path_suffix (const char *path,const char *suffix); + +extern char *mkpath (const char *fmt, ...) __attribute__((format (printf,1 ,2 ))); +extern char *perf_path (const char *fmt, ...) __attribute__((format (printf,1 ,2 ))); + +extern char *perf_pathdup (const char *fmt, ...) + __attribute__((format (printf,1 ,2 ))); + +#ifndef __UCLIBC__ +/* Matches the libc/libbsd function attribute so we declare this unconditionally: */ +extern size_t strlcpy (char *dest,const char *src,size_t size); +#endif + +#endif /* __PERF_PATH_H */
tools/perf/util/wrapper.h +20 -0
@@ -11,4 +11,24 @@ static inline void *zalloc(size_t size)#define zfree (ptr) ({ free(*ptr); *ptr = NULL; }) +#define alloc_nr (x) (((x)+16)*3/2) + +/* +* Realloc the buffer pointed at by variable 'x' so that it can hold +* at least 'nr' entries; the number of entries currently allocated +* is 'alloc', using the standard growing factor alloc_nr() macro. +* +* DO NOT USE any expression with side-effect for 'x' or 'alloc'. +*/ +#define ALLOC_GROW (x, nr, alloc) \ + do { \ + if ((nr) > alloc) { \ + if (alloc_nr(alloc) < (nr)) \ + alloc = (nr); \ + else \ + alloc = alloc_nr(alloc); \ + x = xrealloc((x), alloc * sizeof(*(x))); \ + } \ + } while(0) +#endif /* __PERF_WRAPPER_H */
Signature · 1 line
2.4.3
PATCH v2 7/14 perf: Remove cache.h
In reply to Josh Poimboeufcache.h is now just a collection of some commonly used includes. Move the includes to util.h, which has a similar collection.
--- tools/perf/builtin-annotate.c | 1 - tools/perf/builtin-buildid-cache.c | 2 +- tools/perf/builtin-buildid-list.c | 2 +- tools/perf/builtin-config.c | 3 +-- tools/perf/builtin-help.c | 2 +- tools/perf/builtin-kmem.c | 1 - tools/perf/builtin-kvm.c | 1 - tools/perf/builtin-list.c | 2 +- tools/perf/builtin-lock.c | 1 - tools/perf/builtin-report.c | 1 - tools/perf/builtin-sched.c | 1 - tools/perf/builtin-script.c | 1 - tools/perf/builtin-timechart.c | 1 - tools/perf/builtin-top.c | 1 - tools/perf/perf.c | 2 +- tools/perf/tests/llvm.c | 2 +- tools/perf/ui/browser.c | 1 - tools/perf/ui/browsers/header.c | 2 +- tools/perf/ui/gtk/browser.c | 2 +- tools/perf/ui/gtk/hists.c | 2 +- tools/perf/ui/gtk/setup.c | 2 +- tools/perf/ui/helpline.h | 2 +- tools/perf/ui/progress.c | 2 +- tools/perf/ui/setup.c | 2 +- tools/perf/ui/tui/progress.c | 2 +- tools/perf/ui/tui/setup.c | 1 - tools/perf/ui/tui/util.c | 1 - tools/perf/util/abspath.c | 2 +- tools/perf/util/alias.c | 2 +- tools/perf/util/annotate.c | 1 - tools/perf/util/cache.h | 16 ---------------- tools/perf/util/color.c | 2 +- tools/perf/util/config.c | 1 - tools/perf/util/debug.c | 1 - tools/perf/util/exec_cmd.c | 2 +- tools/perf/util/help.c | 2 +- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 1 - tools/perf/util/levenshtein.c | 2 +- tools/perf/util/llvm-utils.c | 1 - tools/perf/util/pager.c | 2 +- tools/perf/util/parse-events.c | 1 - tools/perf/util/parse-options.c | 1 - tools/perf/util/path.c | 2 +- tools/perf/util/probe-event.c | 1 - tools/perf/util/probe-file.c | 1 - tools/perf/util/quote.c | 2 +- tools/perf/util/run-command.c | 2 +- tools/perf/util/sigchain.c | 2 +- tools/perf/util/sort.h | 1 - tools/perf/util/strbuf.c | 2 +- tools/perf/util/util.h | 6 ++++++ tools/perf/util/wrapper.c | 2 +- 52 files changed, 34 insertions(+), 67 deletions(-) delete mode 100644 tools/perf/util/cache.h
tools/perf/builtin-annotate.c +0 -1
@@ -10,7 +10,6 @@#include "util/util.h" #include "util/color.h" #include <linux/list.h> -#include "util/cache.h" #include <linux/rbtree.h> #include "util/symbol.h"
tools/perf/builtin-buildid-cache.c +1 -1
@@ -13,7 +13,7 @@#include <unistd.h> #include "builtin.h" #include "perf.h" -#include "util/cache.h" +#include "util/util.h" #include "util/debug.h" #include "util/header.h" #include "util/parse-options.h"
tools/perf/builtin-buildid-list.c +1 -1
@@ -10,7 +10,7 @@#include "builtin.h" #include "perf.h" #include "util/build-id.h" -#include "util/cache.h" +#include "util/util.h" #include "util/debug.h" #include "util/parse-options.h" #include "util/session.h"
tools/perf/builtin-config.c +1 -2
@@ -8,9 +8,8 @@#include "perf.h" -#include "util/cache.h" -#include "util/parse-options.h" #include "util/util.h" +#include "util/parse-options.h" #include "util/debug.h" static const char *const config_usage[] = {
tools/perf/builtin-help.c +1 -1
@@ -4,7 +4,7 @@* Builtin help command */ #include "perf.h" -#include "util/cache.h" +#include "util/util.h" #include "builtin.h" #include "util/exec_cmd.h" #include "common-cmds.h"
tools/perf/builtin-kmem.c +0 -1
@@ -4,7 +4,6 @@#include "util/evlist.h" #include "util/evsel.h" #include "util/util.h" -#include "util/cache.h" #include "util/symbol.h" #include "util/thread.h" #include "util/header.h"
tools/perf/builtin-kvm.c +0 -1
@@ -4,7 +4,6 @@#include "util/evsel.h" #include "util/evlist.h" #include "util/util.h" -#include "util/cache.h" #include "util/symbol.h" #include "util/thread.h" #include "util/header.h"
tools/perf/builtin-list.c +1 -1
@@ -12,7 +12,7 @@#include "perf.h" #include "util/parse-events.h" -#include "util/cache.h" +#include "util/util.h" #include "util/pmu.h" #include "util/parse-options.h"
tools/perf/builtin-lock.c +0 -1
@@ -4,7 +4,6 @@#include "util/evlist.h" #include "util/evsel.h" #include "util/util.h" -#include "util/cache.h" #include "util/symbol.h" #include "util/thread.h" #include "util/header.h"
tools/perf/builtin-report.c +0 -1
@@ -8,7 +8,6 @@#include "builtin.h" #include "util/util.h" -#include "util/cache.h" #include "util/annotate.h" #include "util/color.h"
tools/perf/builtin-sched.c +0 -1
@@ -3,7 +3,6 @@#include "util/util.h" #include "util/evlist.h" -#include "util/cache.h" #include "util/evsel.h" #include "util/symbol.h" #include "util/thread.h"
tools/perf/builtin-script.c +0 -1
@@ -1,7 +1,6 @@#include "builtin.h" #include "perf.h" -#include "util/cache.h" #include "util/debug.h" #include "util/exec_cmd.h" #include "util/header.h"
tools/perf/builtin-timechart.c +0 -1
@@ -20,7 +20,6 @@#include "util/color.h" #include <linux/list.h> -#include "util/cache.h" #include "util/evlist.h" #include "util/evsel.h" #include <linux/rbtree.h>
tools/perf/builtin-top.c +0 -1
@@ -22,7 +22,6 @@#include "perf.h" #include "util/annotate.h" -#include "util/cache.h" #include "util/color.h" #include "util/evlist.h" #include "util/evsel.h"
tools/perf/perf.c +1 -1
@@ -10,7 +10,7 @@#include "util/env.h" #include "util/exec_cmd.h" -#include "util/cache.h" +#include "util/util.h" #include "util/quote.h" #include "util/run-command.h" #include "util/parse-events.h"
tools/perf/tests/llvm.c +1 -1
@@ -1,7 +1,7 @@#include <stdio.h> #include <bpf/libbpf.h> #include "util/llvm-utils.h" -#include "util/cache.h" +#include "util/util.h" #include "llvm.h" #include "tests.h" #include "debug.h"
tools/perf/ui/browser.c +0 -1
@@ -1,5 +1,4 @@#include "../util.h" -#include "../cache.h" #include "../../perf.h" #include "libslang.h" #include "ui.h"
tools/perf/ui/browsers/header.c +1 -1
@@ -1,4 +1,4 @@ -#include "util/cache.h" +#include "util/util.h" #include "util/debug.h" #include "ui/browser.h" #include "ui/keysyms.h"
tools/perf/ui/gtk/browser.c +1 -1
@@ -1,5 +1,5 @@#include "../evlist.h" -#include "../cache.h" +#include "../util.h" #include "../evsel.h" #include "../sort.h" #include "../hist.h"
tools/perf/ui/gtk/hists.c +1 -1
@@ -1,5 +1,5 @@#include "../evlist.h" -#include "../cache.h" +#include "../util.h" #include "../evsel.h" #include "../sort.h" #include "../hist.h"
tools/perf/ui/gtk/setup.c +1 -1
@@ -1,5 +1,5 @@#include "gtk.h" -#include "../../util/cache.h" +#include "../../util/util.h" #include "../../util/debug.h" extern struct perf_error_ops perf_gtk_eops;
tools/perf/ui/helpline.h +1 -1
@@ -4,7 +4,7 @@#include <stdio.h> #include <stdarg.h> -#include "../util/cache.h" +#include "../util/util.h" struct ui_helpline {void (*pop)(void );
tools/perf/ui/progress.c +1 -1
@@ -1,4 +1,4 @@ -#include "../cache.h" +#include "../util.h" #include "progress.h" static void null_progress__update (struct ui_progress *p__maybe_unused )
tools/perf/ui/setup.c +1 -1
@@ -1,7 +1,7 @@#include <pthread.h> #include <dlfcn.h> -#include "../util/cache.h" +#include "../util/util.h" #include "../util/debug.h" #include "../util/hist.h"
tools/perf/ui/tui/progress.c +1 -1
@@ -1,4 +1,4 @@ -#include "../cache.h" +#include "../util.h" #include "../progress.h" #include "../libslang.h" #include "../ui.h"
tools/perf/ui/tui/setup.c +0 -1
@@ -4,7 +4,6 @@#include <execinfo.h> #endif -#include "../../util/cache.h" #include "../../util/debug.h" #include "../browser.h" #include "../helpline.h"
tools/perf/ui/tui/util.c +0 -1
@@ -4,7 +4,6 @@#include <string.h> #include <sys/ttydefaults.h> -#include "../../util/cache.h" #include "../../util/debug.h" #include "../browser.h" #include "../keysyms.h"
tools/perf/util/abspath.c +1 -1
@@ -1,4 +1,4 @@ -#include "cache.h" +#include "util.h" static const char *get_pwd_cwd (void ) {
tools/perf/util/alias.c +1 -1
@@ -1,4 +1,4 @@ -#include "cache.h" +#include "util.h" static const char *alias_key;static char *alias_val;
tools/perf/util/annotate.c +0 -1
@@ -12,7 +12,6 @@#include "sort.h" #include "build-id.h" #include "color.h" -#include "cache.h" #include "symbol.h" #include "debug.h" #include "annotate.h"
tools/perf/util/cache.h deleted +0 -16
@@ -1,16 +0,0 @@ -#ifndef __PERF_CACHE_H -#define __PERF_CACHE_H - -#include <stdbool.h> -#include "util.h" -#include "strbuf.h" -#include "../perf.h" -#include "../ui/ui.h" - -#include "abspath.h" -#include "alias.h" -#include "config.h" -#include "pager.h" -#include "path.h" - -#endif /* __PERF_CACHE_H */
tools/perf/util/color.c +1 -1
@@ -1,5 +1,5 @@#include <linux/kernel.h> -#include "cache.h" +#include "util.h" #include "color.h" #include <math.h>
tools/perf/util/config.c +0 -1
@@ -9,7 +9,6 @@* */ #include "util.h" -#include "cache.h" #include "exec_cmd.h" #include "util/hist.h" /* perf_hist_config */ #include "util/llvm-utils.h" /* perf_llvm_config */
tools/perf/util/debug.c +0 -1
@@ -6,7 +6,6 @@#include <stdarg.h> #include <stdio.h> -#include "cache.h" #include "color.h" #include "event.h" #include "debug.h"
tools/perf/util/exec_cmd.c +1 -1
@@ -1,4 +1,4 @@ -#include "cache.h" +#include "util.h" #include "exec_cmd.h" #include "quote.h"
tools/perf/util/help.c +1 -1
@@ -1,4 +1,4 @@ -#include "cache.h" +#include "util.h" #include "../builtin.h" #include "exec_cmd.h" #include "levenshtein.h"
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +0 -1
@@ -23,7 +23,6 @@#include <stdint.h> #include <inttypes.h> -#include "../cache.h" #include "../util.h" #include "intel-pt-insn-decoder.h"
tools/perf/util/levenshtein.c +1 -1
@@ -1,4 +1,4 @@ -#include "cache.h" +#include "util.h" #include "levenshtein.h" /*
tools/perf/util/llvm-utils.c +0 -1
@@ -7,7 +7,6 @@#include "util.h" #include "debug.h" #include "llvm-utils.h" -#include "cache.h" #define CLANG_BPF_CMD_DEFAULT_TEMPLATE \ "$CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS "\
tools/perf/util/pager.c +1 -1
@@ -1,4 +1,4 @@ -#include "cache.h" +#include "util.h" #include "run-command.h" #include "sigchain.h"
tools/perf/util/parse-events.c +0 -1
@@ -9,7 +9,6 @@#include "exec_cmd.h" #include "string.h" #include "symbol.h" -#include "cache.h" #include "header.h" #include "bpf-loader.h" #include "debug.h"
tools/perf/util/parse-options.c +0 -1
@@ -1,6 +1,5 @@#include "util.h" #include "parse-options.h" -#include "cache.h" #include "header.h" #include <linux/string.h>
tools/perf/util/path.c +1 -1
@@ -10,7 +10,7 @@* * which is what it's designed for. */ -#include "cache.h" +#include "util.h" static char bad_path[] ="/bad-path/" ;/*
tools/perf/util/probe-event.c +0 -1
@@ -36,7 +36,6 @@#include "event.h" #include "strlist.h" #include "debug.h" -#include "cache.h" #include "color.h" #include "symbol.h" #include "thread.h"
tools/perf/util/probe-file.c +0 -1
@@ -18,7 +18,6 @@#include "event.h" #include "strlist.h" #include "debug.h" -#include "cache.h" #include "color.h" #include "symbol.h" #include "thread.h"
tools/perf/util/quote.c +1 -1
@@ -1,4 +1,4 @@ -#include "cache.h" +#include "util.h" #include "quote.h" /* Help to copy the thing properly quoted for the shell safety.
tools/perf/util/run-command.c +1 -1
@@ -1,4 +1,4 @@ -#include "cache.h" +#include "util.h" #include "run-command.h" #include "exec_cmd.h" #include "debug.h"
tools/perf/util/sigchain.c +1 -1
@@ -1,5 +1,5 @@ +#include "util.h" #include "sigchain.h" -#include "cache.h" #define SIGCHAIN_MAX_SIGNALS 32
tools/perf/util/sort.h +0 -1
@@ -6,7 +6,6 @@#include "color.h" #include <linux/list.h> -#include "cache.h" #include <linux/rbtree.h> #include "symbol.h" #include "string.h"
tools/perf/util/strbuf.c +1 -1
@@ -1,4 +1,4 @@ -#include "cache.h" +#include "util.h" #include <linux/kernel.h> int prefixcmp (const char *str,const char *prefix)
tools/perf/util/util.h +6 -0
@@ -3,13 +3,19 @@#include "compat-util.h" +#include "../perf.h" +#include "abspath.h" +#include "alias.h" #include "config.h" #include "ctype.h" #include "lzma.h" +#include "pager.h" +#include "path.h" #include "srcline.h" #include "strbuf.h" #include "string.h" #include "term.h" +#include "../ui/ui.h" #include "usage.h" #include "wrapper.h" #include "zlib.h"
tools/perf/util/wrapper.c +1 -1
@@ -1,7 +1,7 @@/* * Various trivial helper wrappers around standard functions */ -#include "cache.h" +#include "util.h" /* * There's no pack memory to release - but stay close to the Git
Signature · 1 line
2.4.3
PATCH v2 8/14 perf: Save cmdline arguments earlier
In reply to Josh Poimboeufperf_env__set_cmdline() only saves the arguments the first time it's called. It doesn't need to be called every time the options and suboptions are parsed. Instead it can just be called once.
This also has the advantage of making the option parsing code less perf-specific so it can be moved out to a library.
--- tools/perf/perf.c | 1 + tools/perf/util/env.c | 9 --------- tools/perf/util/parse-options.c | 2 -- 3 files changed, 1 insertion(+), 11 deletions(-)
tools/perf/perf.c +1 -0
@@ -384,6 +384,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) use_pager =1 ;commit_pager_choice (); +perf_env__set_cmdline (&perf_env, argc, argv); status = p->fn (argc, argv, prefix);exit_browser (status);perf_env__exit (&perf_env);
tools/perf/util/env.c +0 -9
@@ -25,15 +25,6 @@ int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[]) {int i; -/* -* If env->cmdline_argv has already been set, do not override it. This allows -* a command to set the cmdline, parse args and then call another -* builtin function that implements a command -- e.g, cmd_kvm calling -* cmd_record. -*/ -if (env->cmdline_argv !=NULL ) -return 0 ; -/* do not include NULL termination */ env->cmdline_argv =calloc (argc,sizeof (char *));if (env->cmdline_argv ==NULL )
tools/perf/util/parse-options.c +0 -2
@@ -506,8 +506,6 @@ int parse_options_subcommand(int argc, const char **argv, const struct option *o {struct parse_opt_ctx_t ctx; -perf_env__set_cmdline (&perf_env, argc, argv); -/* build usage string if it's not provided */ if (subcommands && !usagestr[0 ]) {struct strbuf buf =STRBUF_INIT ;
Signature · 1 line
2.4.3
tip-bot for Josh Poimboeuf
merge bot[tip:perf/core] perf tools: Save cmdline arguments earlier
perf tools: Save cmdline arguments earlier
Commit-ID: 2bdb2c2729d2ba2f2f90b729d04254308096c5a0 Gitweb: http://git.kernel.org/tip/2bdb2c2729d2ba2f2f90b729d04254308096c5a0 Author: Josh Poimboeuf <[email protected]> AuthorDate: Mon, 7 Dec 2015 22:21:46 -0600 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 9 Dec 2015 13:42:03 -0300
perf tools: Save cmdline arguments earlier
perf_env__set_cmdline() only saves the arguments the first time it's called. It doesn't need to be called every time the options and suboptions are parsed. Instead it can just be called once.
This also has the advantage of making the option parsing code less perf-specific so it can be moved out to a library.
--- tools/perf/perf.c | 1 + tools/perf/util/env.c | 9 --------- tools/perf/util/parse-options.c | 2 -- 3 files changed, 1 insertion(+), 11 deletions(-)
tools/perf/perf.c +1 -0
@@ -384,6 +384,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) use_pager =1 ;commit_pager_choice (); +perf_env__set_cmdline (&perf_env, argc, argv); status = p->fn (argc, argv, prefix);exit_browser (status);perf_env__exit (&perf_env);
tools/perf/util/env.c +0 -9
@@ -25,15 +25,6 @@ int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[]) {int i; -/* -* If env->cmdline_argv has already been set, do not override it. This allows -* a command to set the cmdline, parse args and then call another -* builtin function that implements a command -- e.g, cmd_kvm calling -* cmd_record. -*/ -if (env->cmdline_argv !=NULL ) -return 0 ; -/* do not include NULL termination */ env->cmdline_argv =calloc (argc,sizeof (char *));if (env->cmdline_argv ==NULL )
tools/perf/util/parse-options.c +0 -2
@@ -501,8 +501,6 @@ int parse_options_subcommand(int argc, const char **argv, const struct option *o {struct parse_opt_ctx_t ctx; -perf_env__set_cmdline (&perf_env, argc, argv); -/* build usage string if it's not provided */ if (subcommands && !usagestr[0 ]) {struct strbuf buf =STRBUF_INIT ;
PATCH v2 9/14 perf: Remove check for unused PERF_PAGER_IN_USE
In reply to Josh PoimboeufPERF_PAGER_IN_USE doesn't seem to be used anywhere, so let's remove it.
This will also make it easier to move pager.c into a separate library.
--- tools/perf/util/pager.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
tools/perf/util/pager.c +1 -7
@@ -85,11 +85,5 @@ void setup_pager(void)int pager_in_use (void ) { -const char *env; - -if (spawned_pager) -return 1 ; - - env =getenv ("PERF_PAGER_IN_USE" ); -return env ?perf_config_bool ("PERF_PAGER_IN_USE" , env) :0 ; +return spawned_pager; }
Signature · 1 line
2.4.3
PATCH v2 10/14 perf: Move cmd_version() to builtin-version.c
In reply to Josh PoimboeufMove cmd_version() to its own file so that help.c can be moved to a library.
--- tools/perf/Build | 1 + tools/perf/builtin-version.c | 9 +++++++++ tools/perf/util/help.c | 7 ------- 3 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 tools/perf/builtin-version.c
tools/perf/Build +1 -0
@@ -20,6 +20,7 @@ perf-y += builtin-kvm.o perf-y += builtin-inject.o perf-y += builtin-mem.o perf-y += builtin-data.o +perf-y += builtin-version.o perf-$(CONFIG_AUDIT) += builtin-trace.o perf-$(CONFIG_LIBELF) += builtin-probe.o
tools/perf/builtin-version.c new file +9 -0
@@ -0,0 +1,9 @@ +#include "util/util.h" +#include "builtin.h" + +int cmd_version (int argc__maybe_unused ,const char **argv__maybe_unused , +const char *prefix__maybe_unused ) +{ +printf ("perf version %s\n" , perf_version_string); +return 0 ; +}
tools/perf/util/help.c +0 -7
@@ -340,10 +340,3 @@ const char *help_unknown_cmd(const char *cmd)exit (1 ); } - -int cmd_version (int argc__maybe_unused ,const char **argv__maybe_unused , -const char *prefix__maybe_unused ) -{ -printf ("perf version %s\n" , perf_version_string); -return 0 ; -}
Signature · 1 line
2.4.3
tip-bot for Josh Poimboeuf
merge bot[tip:perf/core] perf tools: Move cmd_version() to builtin-version.c
perf tools: Move cmd_version() to builtin-version.c
Commit-ID: 0a4bb5da957b83ece8b4723c5bac7a5d29fbfb33 Gitweb: http://git.kernel.org/tip/0a4bb5da957b83ece8b4723c5bac7a5d29fbfb33 Author: Josh Poimboeuf <[email protected]> AuthorDate: Mon, 7 Dec 2015 22:21:48 -0600 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 9 Dec 2015 13:42:03 -0300
perf tools: Move cmd_version() to builtin-version.c
Move cmd_version() to its own file so that help.c can be moved to a library.
--- tools/perf/Build | 1 + tools/perf/builtin-version.c | 10 ++++++++++ tools/perf/util/help.c | 7 ------- 3 files changed, 11 insertions(+), 7 deletions(-)
tools/perf/Build +1 -0
@@ -20,6 +20,7 @@ perf-y += builtin-kvm.o perf-y += builtin-inject.o perf-y += builtin-mem.o perf-y += builtin-data.o +perf-y += builtin-version.o perf-$(CONFIG_AUDIT) += builtin-trace.o perf-$(CONFIG_LIBELF) += builtin-probe.o
tools/perf/builtin-version.c new file +10 -0
@@ -0,0 +1,10 @@ +#include "util/util.h" +#include "builtin.h" +#include "perf.h" + +int cmd_version (int argc__maybe_unused ,const char **argv__maybe_unused , +const char *prefix__maybe_unused ) +{ +printf ("perf version %s\n" , perf_version_string); +return 0 ; +}
tools/perf/util/help.c +0 -7
@@ -332,10 +332,3 @@ const char *help_unknown_cmd(const char *cmd)exit (1 ); } - -int cmd_version (int argc__maybe_unused ,const char **argv__maybe_unused , -const char *prefix__maybe_unused ) -{ -printf ("perf version %s\n" , perf_version_string); -return 0 ; -}
PATCH v2 11/14 perf: Move help_unknown_cmd() to its own file
In reply to Josh Poimboeufhelp_unknown_cmd() is quite perf-specific because it relies on some perf_config*() functions. Move it and its supporting functions out into a separate file so that help.c can be moved to a library.
--- tools/perf/util/Build | 1 + tools/perf/util/help-unknown-cmd.c | 103 +++++++++++++++++++++++++++++++++++ tools/perf/util/help-unknown-cmd.h | 0 tools/perf/util/help.c | 108 ++----------------------------------- tools/perf/util/help.h | 3 ++ 5 files changed, 110 insertions(+), 105 deletions(-) create mode 100644 tools/perf/util/help-unknown-cmd.c create mode 100644 tools/perf/util/help-unknown-cmd.h
tools/perf/util/Build +1 -0
@@ -87,6 +87,7 @@ libperf-$(CONFIG_AUXTRACE) += intel-bts.o libperf-y += parse-branch-options.o libperf-y += parse-regs-options.o libperf-y += term.o +libperf-y += help-unknown-cmd.o libperf-$(CONFIG_LIBBPF) += bpf-loader.o libperf-$(CONFIG_BPF_PROLOGUE) += bpf-prologue.o
tools/perf/util/help-unknown-cmd.c new file +103 -0
103 lines not on this page · raw message
tools/perf/util/help-unknown-cmd.h new file +0 -0
tools/perf/util/help.c +3 -105
135 lines not on this page · raw message
tools/perf/util/help.h +3 -0
@@ -20,6 +20,9 @@ void load_command_list(const char *prefix,struct cmdnames *main_cmds, struct cmdnames *other_cmds);void add_cmdname (struct cmdnames *cmds,const char *name,size_t len); +void clean_cmdnames (struct cmdnames *cmds); +int cmdname_compare (const void *a,const void *b); +void uniq (struct cmdnames *cmds);/* Here we require that excludes is a sorted list. */ void exclude_cmds (struct cmdnames *cmds,struct cmdnames *excludes);int is_in_cmdlist (struct cmdnames *c,const char *s);
Signature · 1 line
2.4.3
PATCH v2 12/14 perf tools: Move strlcpy() to tools/lib/string.c
In reply to Josh PoimboeufMove strlcpy() to tools/lib/string.c so it can be used by other tools, namely abspath.c which is getting moved to a library.
--- tools/include/linux/string.h | 5 +++++ tools/lib/string.c | 19 +++++++++++++++++++ tools/perf/util/path.c | 18 ------------------ tools/perf/util/path.h | 5 ----- tools/perf/util/util.h | 1 + 5 files changed, 25 insertions(+), 23 deletions(-)
tools/include/linux/string.h +5 -0
@@ -8,4 +8,9 @@ void *memdup(const void *src, size_t len);int strtobool (const char *s,bool *res); +#ifndef __UCLIBC__ +/* Matches the libc/libbsd function attribute so we declare this unconditionally: */ +extern size_t strlcpy (char *dest,const char *src,size_t size); +#endif +#endif /* _LINUX_STRING_H_ */
tools/lib/string.c +19 -0
@@ -16,6 +16,7 @@#include <string.h> #include <errno.h> #include <linux/string.h> +#include <linux/compiler.h> /** * memdup - duplicate region of memory
@@ -60,3 +61,21 @@ int strtobool(const char *s, bool *res) }return 0 ; } + +/* +* If libc has strlcpy() then that version will override this +* implementation: +*/ +size_t __weak strlcpy (char *dest,const char *src,size_t size) +{ +size_t ret =strlen (src); + +if (size) { +size_t len = (ret >= size) ? size -1 : ret; + +memcpy (dest, src, len); + dest[len] ='\0' ; + } + +return ret; +}
tools/perf/util/path.c +0 -18
@@ -22,24 +22,6 @@ static const char *get_perf_dir(void)return "." ; } -/* -* If libc has strlcpy() then that version will override this -* implementation: -*/ -size_t __weak strlcpy (char *dest,const char *src,size_t size) -{ -size_t ret =strlen (src); - -if (size) { -size_t len = (ret >= size) ? size -1 : ret; - -memcpy (dest, src, len); - dest[len] ='\0' ; - } - -return ret; -} -static char *get_pathname (void ) {static char pathname_array[4 ][PATH_MAX ];
tools/perf/util/path.h +0 -5
@@ -9,9 +9,4 @@ extern char *perf_path(const char *fmt, ...) __attribute__((format (printf, 1, 2extern char *perf_pathdup (const char *fmt, ...) __attribute__((format (printf,1 ,2 ))); -#ifndef __UCLIBC__ -/* Matches the libc/libbsd function attribute so we declare this unconditionally: */ -extern size_t strlcpy (char *dest,const char *src,size_t size); -#endif -#endif /* __PERF_PATH_H */
tools/perf/util/util.h +1 -0
@@ -3,6 +3,7 @@#include "compat-util.h" +#include <linux/string.h> #include "../perf.h" #include "abspath.h" #include "alias.h"
Signature · 1 line
2.4.3
PATCH v2 13/14 perf tools: Move tools/lib/string.c to libapi
In reply to Josh PoimboeufGet rid of libstring and move tools/lib/string.c to libapi where it can more easily be used by other tools.
---
tools/lib/api/Build | 1 +
tools/lib/api/string/Build | 1 +
tools/lib/{ => api/string}/string.c | 7 ++++---
tools/{include/linux => lib/api/string}/string.h | 10 +++++-----
tools/perf/MANIFEST | 2 --
tools/perf/builtin-kmem.c | 2 +-
tools/perf/util/Build | 6 ------
tools/perf/util/auxtrace.c | 2 +-
tools/perf/util/bpf-loader.c | 2 +-
tools/perf/util/intel-pt-decoder/insn.c | 2 +-
tools/perf/util/map.c | 2 +-
tools/perf/util/ordered-events.c | 2 +-
tools/perf/util/parse-options.c | 2 +-
tools/perf/util/util.h | 2 +-
14 files changed, 19 insertions(+), 24 deletions(-)
create mode 100644 tools/lib/api/string/Build
rename tools/lib/{ => api/string}/string.c (93%)
rename tools/{include/linux => lib/api/string}/string.h (66%)tools/lib/api/Build +1 -0
@@ -1,3 +1,4 @@ libapi-y += fd/ libapi-y += fs/ libapi-y += cpu.o +libapi-y += string/
tools/lib/api/string/Build new file +1 -0
@@ -0,0 +1 @@ +libapi-y += string.o
tools/lib/api/string/string.c renamed from tools/lib/string.c +4 -3
@@ -1,5 +1,5 @@/* -* linux/tools/lib/string.c +* linux/tools/lib/api/string/string.c * * Copied from linux/lib/string.c, where it is: *
@@ -15,8 +15,9 @@#include <stdlib.h> #include <string.h> #include <errno.h> -#include <linux/string.h> -#include <linux/compiler.h> +#include "string.h" + +#define __weak __attribute__((weak))/** * memdup - duplicate region of memory
tools/lib/api/string/string.h renamed from tools/include/linux/string.h +5 -5
@@ -1,8 +1,8 @@ -#ifndef _TOOLS_LINUX_STRING_H_ -#define _TOOLS_LINUX_STRING_H_ +#ifndef _API_STRING_H +#define _API_STRING_H - -#include <linux/types.h> /* for size_t */ +#include <stddef.h> +#include <stdbool.h> void *memdup (const void *src,size_t len);
@@ -13,4 +13,4 @@ int strtobool(const char *s, bool *res);extern size_t strlcpy (char *dest,const char *src,size_t size);#endif -#endif /* _LINUX_STRING_H_ */ +#endif /* _API_STRING_H */
tools/perf/MANIFEST +0 -2
@@ -22,7 +22,6 @@ tools/lib/api tools/lib/bpf tools/lib/hweight.c tools/lib/rbtree.c -tools/lib/string.c tools/lib/symbol/kallsyms.c tools/lib/symbol/kallsyms.h tools/lib/util/find_next_bit.c
@@ -51,7 +50,6 @@ tools/include/linux/log2.h tools/include/linux/poison.h tools/include/linux/rbtree.h tools/include/linux/rbtree_augmented.h -tools/include/linux/string.h tools/include/linux/types.h tools/include/linux/err.h include/asm-generic/bitops/arch_hweight.h
tools/perf/builtin-kmem.c +1 -1
@@ -19,7 +19,7 @@#include "util/debug.h" #include <linux/rbtree.h> -#include <linux/string.h> +#include <api/string/string.h> #include <locale.h> #include <regex.h>
tools/perf/util/Build +0 -6
@@ -20,7 +20,6 @@ libperf-y += parse-events.o libperf-y += perf_regs.o libperf-y += path.o libperf-y += rbtree.o -libperf-y += libstring.o libperf-y += bitmap.o libperf-y += hweight.o libperf-y += run-command.o
@@ -141,7 +140,6 @@ $(OUTPUT)util/pmu.o: $(OUTPUT)util/pmu-flex.c $(OUTPUT)util/pmu-bison.c CFLAGS_find_next_bit.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" CFLAGS_rbtree.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" -CFLAGS_libstring.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" CFLAGS_hweight.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" CFLAGS_parse-events.o += -Wno-redundant-decls
@@ -157,10 +155,6 @@ $(OUTPUT)util/rbtree.o: ../lib/rbtree.c FORCE $(call rule_mkdir) $(call if_changed_dep,cc_o_c) -$(OUTPUT)util/libstring.o: ../lib/string.c FORCE - $(call rule_mkdir) - $(call if_changed_dep,cc_o_c) - $(OUTPUT)util/hweight.o: ../lib/hweight.c FORCE $(call rule_mkdir) $(call if_changed_dep,cc_o_c)
tools/perf/util/auxtrace.c +1 -1
@@ -22,7 +22,7 @@#include <linux/types.h> #include <linux/bitops.h> #include <linux/log2.h> -#include <linux/string.h> +#include <api/string/string.h> #include <sys/param.h> #include <stdlib.h>
tools/perf/util/bpf-loader.c +1 -1
@@ -8,7 +8,7 @@#include <linux/bpf.h> #include <bpf/libbpf.h> #include <linux/err.h> -#include <linux/string.h> +#include <api/string/string.h> #include "perf.h" #include "debug.h" #include "bpf-loader.h"
tools/perf/util/intel-pt-decoder/insn.c +1 -1
@@ -19,7 +19,7 @@*/ #ifdef __KERNEL__ -#include <linux/string.h> +#include <api/string/string.h> #else #include <string.h> #endif
tools/perf/util/map.c +1 -1
@@ -14,7 +14,7 @@#include "util.h" #include "debug.h" #include "machine.h" -#include <linux/string.h> +#include <api/string/string.h> static void __maps__insert (struct maps *maps,struct map *map);
tools/perf/util/ordered-events.c +1 -1
@@ -1,6 +1,6 @@#include <linux/list.h> #include <linux/compiler.h> -#include <linux/string.h> +#include <api/string/string.h> #include "ordered-events.h" #include "session.h" #include "asm/bug.h"
tools/perf/util/parse-options.c +1 -1
@@ -1,7 +1,7 @@#include "util.h" #include "parse-options.h" #include "header.h" -#include <linux/string.h> +#include <api/string/string.h> #define OPT_SHORT 1#define OPT_UNSET 2
tools/perf/util/util.h +1 -1
@@ -3,7 +3,7 @@#include "compat-util.h" -#include <linux/string.h> +#include <api/string/string.h> #include "../perf.h" #include "abspath.h" #include "alias.h"
Signature · 1 line
2.4.3
PATCH v2 14/14 perf tools: Move subcommand framework and related utils to libapi
In reply to Josh PoimboeufThe perf subcommand framework is needed for other tools. Move parse-options.c and its dependencies over to libapi.
Any function names with 'perf' have been renamed to something more generic.
Also created a util_cfg struct for passing perf-specific configuration to the library. Specifying the configuration at runtime allows the same binary to be shared by multiple tools without having to recompile it.
---
tools/include/asm-generic/bitops/__fls.h | 2 +-
tools/include/asm-generic/bitops/fls.h | 2 +-
tools/include/asm-generic/bitops/fls64.h | 2 +-
tools/lib/api/Build | 1 +
tools/lib/api/Makefile | 6 +++-
tools/lib/api/util/Build | 13 +++++++++
tools/{perf => lib/api}/util/abspath.c | 6 +++-
tools/{perf => lib/api}/util/abspath.h | 6 ++--
tools/lib/api/util/cfg.c | 12 ++++++++
tools/lib/api/util/cfg.h | 15 ++++++++++
tools/{perf => lib/api}/util/compat-util.h | 7 ++---
tools/{perf => lib/api}/util/ctype.c | 3 +-
tools/{perf => lib/api}/util/ctype.h | 6 ++--
tools/{perf => lib/api}/util/exec_cmd.c | 42 ++++++++++++++--------------
tools/{perf => lib/api}/util/exec_cmd.h | 18 ++++++------
tools/{perf => lib/api}/util/help.c | 11 +++++---
tools/{perf => lib/api}/util/help.h | 0
tools/{perf => lib/api}/util/pager.c | 6 ++--
tools/{perf => lib/api}/util/pager.h | 6 ++--
tools/{perf => lib/api}/util/parse-options.c | 21 ++++++++++----
tools/{perf => lib/api}/util/parse-options.h | 10 +++----
tools/{perf => lib/api}/util/run-command.c | 12 ++++----
tools/{perf => lib/api}/util/run-command.h | 10 +++----
tools/{perf => lib/api}/util/sigchain.c | 4 ++-
tools/{perf => lib/api}/util/sigchain.h | 6 ++--
tools/{perf => lib/api}/util/strbuf.c | 6 +++-
tools/{perf => lib/api}/util/strbuf.h | 6 ++--
tools/{perf => lib/api}/util/term.c | 3 +-
tools/{perf => lib/api}/util/term.h | 0
tools/{perf => lib/api}/util/usage.c | 4 +--
tools/{perf => lib/api}/util/usage.h | 8 +++---
tools/{perf => lib/api}/util/wrapper.c | 4 ++-
tools/{perf => lib/api}/util/wrapper.h | 6 ++--
tools/perf/Build | 2 +-
tools/perf/arch/x86/util/intel-pt.c | 2 +-
tools/perf/bench/futex-hash.c | 2 +-
tools/perf/bench/futex-lock-pi.c | 2 +-
tools/perf/bench/futex-requeue.c | 2 +-
tools/perf/bench/futex-wake-parallel.c | 2 +-
tools/perf/bench/futex-wake.c | 2 +-
tools/perf/bench/mem-functions.c | 2 +-
tools/perf/bench/numa.c | 2 +-
tools/perf/bench/sched-messaging.c | 2 +-
tools/perf/bench/sched-pipe.c | 2 +-
tools/perf/builtin-annotate.c | 2 +-
tools/perf/builtin-bench.c | 2 +-
tools/perf/builtin-buildid-cache.c | 2 +-
tools/perf/builtin-buildid-list.c | 2 +-
tools/perf/builtin-config.c | 2 +-
tools/perf/builtin-data.c | 2 +-
tools/perf/builtin-evlist.c | 2 +-
tools/perf/builtin-help.c | 9 +++---
tools/perf/builtin-inject.c | 2 +-
tools/perf/builtin-kmem.c | 2 +-
tools/perf/builtin-kvm.c | 2 +-
tools/perf/builtin-list.c | 2 +-
tools/perf/builtin-lock.c | 2 +-
tools/perf/builtin-mem.c | 2 +-
tools/perf/builtin-probe.c | 2 +-
tools/perf/builtin-record.c | 2 +-
tools/perf/builtin-report.c | 2 +-
tools/perf/builtin-sched.c | 2 +-
tools/perf/builtin-script.c | 12 ++++----
tools/perf/builtin-stat.c | 2 +-
tools/perf/builtin-timechart.c | 2 +-
tools/perf/builtin-top.c | 2 +-
tools/perf/builtin-trace.c | 4 +--
tools/perf/builtin.h | 2 +-
tools/perf/perf.c | 27 +++++++++++++-----
tools/perf/perf.h | 1 +
tools/perf/tests/attr.c | 4 +--
tools/perf/tests/builtin-test.c | 2 +-
tools/perf/ui/setup.c | 5 ++++
tools/perf/ui/ui.h | 1 +
tools/perf/util/Build | 13 ---------
tools/perf/util/auxtrace.c | 2 +-
tools/perf/util/cgroup.c | 2 +-
tools/perf/util/config.c | 2 +-
tools/perf/util/evlist.c | 2 +-
tools/perf/util/header.c | 2 +-
tools/perf/util/help-unknown-cmd.c | 2 +-
tools/perf/util/parse-branch-options.c | 2 +-
tools/perf/util/parse-events.c | 4 +--
tools/perf/util/parse-regs-options.c | 2 +-
tools/perf/util/python-ext-sources | 1 -
tools/perf/util/sort.h | 2 +-
tools/perf/util/util.h | 19 +++++++------
87 files changed, 265 insertions(+), 183 deletions(-)
create mode 100644 tools/lib/api/util/Build
rename tools/{perf => lib/api}/util/abspath.c (90%)
rename tools/{perf => lib/api}/util/abspath.h (59%)
create mode 100644 tools/lib/api/util/cfg.c
create mode 100644 tools/lib/api/util/cfg.h
rename tools/{perf => lib/api}/util/compat-util.h (95%)
rename tools/{perf => lib/api}/util/ctype.c (97%)
rename tools/{perf => lib/api}/util/ctype.h (93%)
rename tools/{perf => lib/api}/util/exec_cmd.c (72%)
rename tools/{perf => lib/api}/util/exec_cmd.h (14%)
rename tools/{perf => lib/api}/util/help.c (96%)
rename tools/{perf => lib/api}/util/help.h (100%)
rename tools/{perf => lib/api}/util/pager.c (93%)
rename tools/{perf => lib/api}/util/pager.h (42%)
rename tools/{perf => lib/api}/util/parse-options.c (98%)
rename tools/{perf => lib/api}/util/parse-options.h (98%)
rename tools/{perf => lib/api}/util/run-command.c (96%)
rename tools/{perf => lib/api}/util/run-command.h (87%)
rename tools/{perf => lib/api}/util/sigchain.c (93%)
rename tools/{perf => lib/api}/util/sigchain.h (53%)
rename tools/{perf => lib/api}/util/strbuf.c (97%)
rename tools/{perf => lib/api}/util/strbuf.h (97%)
rename tools/{perf => lib/api}/util/term.c (93%)
rename tools/{perf => lib/api}/util/term.h (100%)
rename tools/{perf => lib/api}/util/usage.c (97%)
rename tools/{perf => lib/api}/util/usage.h (84%)
rename tools/{perf => lib/api}/util/wrapper.c (92%)
rename tools/{perf => lib/api}/util/wrapper.h (89%)tools/include/asm-generic/bitops/__fls.h +1 -1
@@ -1 +1 @@ -#include <../../../../include/asm-generic/bitops/__fls.h> +#include "../../../../include/asm-generic/bitops/__fls.h"
tools/include/asm-generic/bitops/fls.h +1 -1
@@ -1 +1 @@ -#include <../../../../include/asm-generic/bitops/fls.h> +#include "../../../../include/asm-generic/bitops/fls.h"
tools/include/asm-generic/bitops/fls64.h +1 -1
@@ -1 +1 @@ -#include <../../../../include/asm-generic/bitops/fls64.h> +#include "../../../../include/asm-generic/bitops/fls64.h"
tools/lib/api/Build +1 -0
@@ -2,3 +2,4 @@ libapi-y += fd/ libapi-y += fs/ libapi-y += cpu.o libapi-y += string/ +libapi-y += util/
tools/lib/api/Makefile +5 -1
@@ -17,7 +17,11 @@ LIBFILE = $(OUTPUT)libapi.a CFLAGS := $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) CFLAGS += -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fPIC -CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 +CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE + +CFLAGS += -I$(srctree)/tools/include/ +CFLAGS += -I$(srctree)/include/uapi +CFLAGS += -I$(srctree)/include RM = rm -f
tools/lib/api/util/Build new file +13 -0
@@ -0,0 +1,13 @@ +libapi-y += abspath.o +libapi-y += cfg.o +libapi-y += ctype.o +libapi-y += exec_cmd.o +libapi-y += help.o +libapi-y += pager.o +libapi-y += parse-options.o +libapi-y += run-command.o +libapi-y += sigchain.o +libapi-y += strbuf.o +libapi-y += term.o +libapi-y += usage.o +libapi-y += wrapper.o
tools/lib/api/util/abspath.c renamed from tools/perf/util/abspath.c +5 -1
@@ -1,4 +1,8 @@ -#include "util.h" +#include "compat-util.h" + +#include "../string/string.h" +#include "abspath.h" +#include "usage.h" static const char *get_pwd_cwd (void ) {
tools/lib/api/util/abspath.h renamed from tools/perf/util/abspath.h +3 -3
@@ -1,5 +1,5 @@ -#ifndef __PERF_ABSPATH_H -#define __PERF_ABSPATH_H +#ifndef __API_UTIL_ABSPATH_H +#define __API_UTIL_ABSPATH_Hstatic inline int is_absolute_path (const char *path) {
@@ -8,4 +8,4 @@ static inline int is_absolute_path(const char *path)const char *make_nonrelative_path (const char *path); -#endif /* __PERF_ABSPATH_H */ +#endif /* __API_UTIL_ABSPATH_H */
tools/lib/api/util/cfg.c new file +12 -0
@@ -0,0 +1,12 @@ +#include "compat-util.h" +#include "cfg.h" + +#define UNDEFINED "UNDEFINED" + +struct util_cfg util_cfg = { + .prefix =UNDEFINED , + .exec_name =UNDEFINED , + .exec_path =UNDEFINED , + .exec_path_env =UNDEFINED , + .pager_env =UNDEFINED , +};
tools/lib/api/util/cfg.h new file +15 -0
@@ -0,0 +1,15 @@ +#ifndef __API_UTIL_CONFIG_H +#define __API_UTIL_CONFIG_H + +struct util_cfg { +const char *prefix; +const char *exec_name; +const char *exec_path; +const char *exec_path_env; +const char *pager_env; +void (*exit_browser)(void ); +}; + +extern struct util_cfg util_cfg; + +#endif /* #define __API_UTIL_CONFIG_H */
tools/lib/api/util/compat-util.h renamed from tools/perf/util/compat-util.h +3 -4
@@ -1,5 +1,5 @@ -#ifndef __PERF_COMPAT_UTIL_H -#define __PERF_COMPAT_UTIL_H +#ifndef __API_UTIL_COMPAT_UTIL_H +#define __API_UTIL_COMPAT_UTIL_H#ifndef FLEX_ARRAY /*
@@ -74,7 +74,6 @@#include <linux/magic.h> #include <linux/types.h> #include <sys/ttydefaults.h> -#include <api/fs/tracing_path.h> #include <termios.h> #include <linux/bitops.h> #include <termios.h>
@@ -127,4 +126,4 @@#define NSEC_PER_MSEC 1000000L#endif -#endif /* __PERF_COMPAT_UTIL_H */ +#endif /* __API_UTIL_COMPAT_UTIL_H */
tools/lib/api/util/ctype.c renamed from tools/perf/util/ctype.c +2 -1
@@ -3,7 +3,8 @@* * No surprises, and works with signed and unsigned chars. */ -#include "util.h" +#include "compat-util.h" +#include "ctype.h" enum {S =GIT_SPACE ,
tools/lib/api/util/ctype.h renamed from tools/perf/util/ctype.h +3 -3
@@ -1,5 +1,5 @@ -#ifndef __PERF_CTYPE_H -#define __PERF_CTYPE_H +#ifndef __API_UTIL_CTYPE_H +#define __API_UTIL_CTYPE_H/* Sane ctype - no locale, and works with signed chars */ #undef isascii
@@ -49,4 +49,4 @@ static inline int sane_case(int x, int high) return x; } -#endif /* __PERF_CTYPE_H */ +#endif /* __API_UTIL_CTYPE_H */
tools/lib/api/util/exec_cmd.c renamed from tools/perf/util/exec_cmd.c +21 -21
120 lines not on this page · raw message
tools/lib/api/util/exec_cmd.h renamed from tools/perf/util/exec_cmd.h +9 -9
@@ -1,13 +1,13 @@ -#ifndef __PERF_EXEC_CMD_H -#define __PERF_EXEC_CMD_H +#ifndef __API_UTIL_EXEC_CMD_H +#define __API_UTIL_EXEC_CMD_H -extern void perf_set_argv_exec_path (const char *exec_path); -extern const char *perf_extract_argv0_path (const char *path); +extern void set_argv_exec_path (const char *exec_path); +extern const char *extract_argv0_path (const char *path);extern void setup_path (void ); -extern int execv_perf_cmd (const char **argv);/* NULL terminated */ -extern int execl_perf_cmd (const char *cmd, ...); -/* perf_exec_path and system_path return malloc'd string, caller must free it */ -extern char *perf_exec_path (void ); +extern int execv_cmd (const char **argv);/* NULL terminated */ +extern int execl_cmd (const char *cmd, ...); +/* get_argv_exec_path and system_path return malloc'd string, caller must free it */ +extern char *get_argv_exec_path (void );extern char *system_path (const char *path); -#endif /* __PERF_EXEC_CMD_H */ +#endif /* __API_UTIL_EXEC_CMD_H */
tools/lib/api/util/help.c renamed from tools/perf/util/help.c +7 -4
@@ -1,6 +1,9 @@ -#include "util.h" -#include "exec_cmd.h" +#include "compat-util.h" #include "help.h" +#include "exec_cmd.h" +#include "strbuf.h" +#include "wrapper.h" +#include "term.h" void add_cmdname (struct cmdnames *cmds,const char *name,size_t len) {
@@ -164,7 +167,7 @@ void load_command_list(const char *prefix, struct cmdnames *other_cmds) {const char *env_path =getenv ("PATH" ); -char *exec_path =perf_exec_path (); +char *exec_path =get_argv_exec_path ();if (exec_path) {list_commands_in_dir (main_cmds, exec_path, prefix);
@@ -209,7 +212,7 @@ void list_commands(const char *title, struct cmdnames *main_cmds, longest = other_cmds->names[i]->len;if (main_cmds->cnt) { -char *exec_path =perf_exec_path (); +char *exec_path =get_argv_exec_path ();printf ("available %s in '%s'\n" , title, exec_path);printf ("----------------" );mput_char ('-' ,strlen (title) +strlen (exec_path));
tools/lib/api/util/help.h renamed from tools/perf/util/help.h +0 -0
tools/lib/api/util/pager.c renamed from tools/perf/util/pager.c +4 -2
@@ -1,6 +1,8 @@ -#include "util.h" +#include "compat-util.h" +#include "pager.h" #include "run-command.h" #include "sigchain.h" +#include "cfg.h" /* * This is split up from the rest of git so that we can do
@@ -46,7 +48,7 @@ static void wait_for_pager_signal(int signo)void setup_pager (void ) { -const char *pager =getenv ("PERF_PAGER" ); +const char *pager =getenv (util_cfg.pager_env);if (!isatty (1 ))return ;
tools/lib/api/util/pager.h renamed from tools/perf/util/pager.h +3 -3
@@ -1,7 +1,7 @@ -#ifndef __PERF_PAGER_H -#define __PERF_PAGER_H +#ifndef __API_UTIL_PAGER_H +#define __API_UTIL_PAGER_Hextern void setup_pager (void );extern int pager_in_use (void ); -#endif /* __PERF_PAGER_H */ +#endif /* __API_UTIL_PAGER_H */
tools/lib/api/util/parse-options.c renamed from tools/perf/util/parse-options.c +15 -6
@@ -1,7 +1,12 @@ -#include "util.h" +#include "compat-util.h" + +#include "../string/string.h" #include "parse-options.h" -#include "header.h" -#include <api/string/string.h> +#include "strbuf.h" +#include "usage.h" +#include "ctype.h" +#include "pager.h" +#include "cfg.h" #define OPT_SHORT 1#define OPT_UNSET 2
@@ -510,7 +515,8 @@ int parse_options_subcommand(int argc, const char **argv, const struct option *oif (subcommands && !usagestr[0 ]) {struct strbuf buf =STRBUF_INIT ; -strbuf_addf (&buf,"perf %s [<options>] {" , argv[0 ]); +strbuf_addf (&buf,"%s %s [<options>] {" , + util_cfg.exec_name, argv[0 ]);for (int i =0 ; subcommands[i]; i++) {if (i)strbuf_addstr (&buf,"|" );
@@ -771,7 +777,9 @@ int usage_with_options_internal(const char * const *usagestr,void usage_with_options (const char *const *usagestr,const struct option *opts) { -exit_browser (false); +if (util_cfg.exit_browser) + util_cfg.exit_browser (); +usage_with_options_internal (usagestr, opts,0 ,NULL );exit (129 ); }
@@ -781,7 +789,8 @@ void usage_with_options_msg(const char * const *usagestr, {va_list ap; -exit_browser (false); +if (util_cfg.exit_browser) + util_cfg.exit_browser ();va_start (ap, fmt);strbuf_addv (&error_buf, fmt, ap);
tools/lib/api/util/parse-options.h renamed from tools/perf/util/parse-options.h +5 -5
@@ -1,8 +1,7 @@ -#ifndef __PERF_PARSE_OPTIONS_H -#define __PERF_PARSE_OPTIONS_H +#ifndef __API_UTIL_PARSE_OPTIONS_H +#define __API_UTIL_PARSE_OPTIONS_H -#include <linux/kernel.h> -#include <stdbool.h> +#include "compat-util.h" enum parse_opt_type {/* special types */
@@ -226,4 +225,5 @@ extern int parse_opt_verbosity_cb(const struct option *, const char *, int);extern const char *parse_options_fix_filename (const char *prefix,const char *file);void set_option_flag (struct option *opts,int sopt,const char *lopt,int flag); -#endif /* __PERF_PARSE_OPTIONS_H */ + +#endif /* __API_UTIL_PARSE_OPTIONS_H */
tools/lib/api/util/run-command.c renamed from tools/perf/util/run-command.c +7 -5
@@ -1,7 +1,9 @@ -#include "util.h" +#include "compat-util.h" #include "run-command.h" #include "exec_cmd.h" -#include "debug.h" +#include "usage.h" + +#define STRERR_BUFSIZE 128static inline void close_pair (int fd[2 ]) {
@@ -112,8 +114,8 @@ int start_command(struct child_process *cmd) }if (cmd->preexec_cb) cmd->preexec_cb (); -if (cmd->perf_cmd) { -execv_perf_cmd (cmd->argv); +if (cmd->exec_cmd) { +execv_cmd (cmd->argv); }else {execvp (cmd->argv[0 ], (char *const *) cmd->argv); }
@@ -207,7 +209,7 @@ static void prepare_run_command_v_opt(struct child_process *cmd,memset (cmd,0 ,sizeof (*cmd)); cmd->argv = argv; cmd->no_stdin = opt &RUN_COMMAND_NO_STDIN ?1 :0 ; - cmd->perf_cmd = opt &RUN_PERF_CMD ?1 :0 ; + cmd->exec_cmd = opt &RUN_EXEC_CMD ?1 :0 ; cmd->stdout_to_stderr = opt &RUN_COMMAND_STDOUT_TO_STDERR ?1 :0 ; }
tools/lib/api/util/run-command.h renamed from tools/perf/util/run-command.h +5 -5
@@ -1,5 +1,5 @@ -#ifndef __PERF_RUN_COMMAND_H -#define __PERF_RUN_COMMAND_H +#ifndef __API_UTIL_RUN_COMMAND_H +#define __API_UTIL_RUN_COMMAND_Henum { ERR_RUN_COMMAND_FORK = 10000,
@@ -41,7 +41,7 @@ struct child_process { unsigned no_stdin:1; unsigned no_stdout:1; unsigned no_stderr:1; - unsigned perf_cmd:1; /* if this is to be perf sub-command */ + unsigned exec_cmd:1; /* if this is to be external sub-command */ unsigned stdout_to_stderr:1;void (*preexec_cb)(void ); };
@@ -51,8 +51,8 @@ int finish_command(struct child_process *);int run_command (struct child_process *);#define RUN_COMMAND_NO_STDIN 1 -#define RUN_PERF_CMD 2/*If this is to be perf sub-command */ +#define RUN_EXEC_CMD 2/*If this is to be external sub-command */ #define RUN_COMMAND_STDOUT_TO_STDERR 4int run_command_v_opt (const char **argv,int opt); -#endif /* __PERF_RUN_COMMAND_H */ +#endif /* __API_UTIL_RUN_COMMAND_H */
tools/lib/api/util/sigchain.c renamed from tools/perf/util/sigchain.c +3 -1
@@ -1,5 +1,7 @@ -#include "util.h" +#include "compat-util.h" #include "sigchain.h" +#include "usage.h" +#include "wrapper.h" #define SIGCHAIN_MAX_SIGNALS 32
tools/lib/api/util/sigchain.h renamed from tools/perf/util/sigchain.h +3 -3
@@ -1,5 +1,5 @@ -#ifndef __PERF_SIGCHAIN_H -#define __PERF_SIGCHAIN_H +#ifndef __API_UTIL_SIGCHAIN_H +#define __API_UTIL_SIGCHAIN_Htypedef void (*sigchain_fun )(int );
@@ -7,4 +7,4 @@ int sigchain_pop(int sig);void sigchain_push_common (sigchain_fun f); -#endif /* __PERF_SIGCHAIN_H */ +#endif /* __API_UTIL_SIGCHAIN_H */
tools/lib/api/util/strbuf.c renamed from tools/perf/util/strbuf.c +5 -1
@@ -1,5 +1,9 @@ -#include "util.h" +#include "compat-util.h" +#include <linux/kernel.h> +#include "strbuf.h" +#include "wrapper.h" +#include "usage.h" int prefixcmp (const char *str,const char *prefix) {
tools/lib/api/util/strbuf.h renamed from tools/perf/util/strbuf.h +3 -3
@@ -1,5 +1,5 @@ -#ifndef __PERF_STRBUF_H -#define __PERF_STRBUF_H +#ifndef __API_UTIL_STRBUF_H +#define __API_UTIL_STRBUF_H/* * Strbuf's can be use in many ways: as a byte array, or to store arbitrary
@@ -93,4 +93,4 @@ extern void strbuf_addv(struct strbuf *sb, const char *fmt, va_list ap);/* XXX: if read fails, any partial read is undone */ extern ssize_t strbuf_read (struct strbuf *,int fd,ssize_t hint); -#endif /* __PERF_STRBUF_H */ +#endif /* __API_UTIL_STRBUF_H */
tools/lib/api/util/term.c renamed from tools/perf/util/term.c +2 -1
@@ -1,4 +1,5 @@ -#include "util.h" +#include "compat-util.h" +#include "term.h" void get_term_dimensions (struct winsize *ws) {
tools/lib/api/util/term.h renamed from tools/perf/util/term.h +0 -0
tools/lib/api/util/usage.c renamed from tools/perf/util/usage.c +2 -2
@@ -6,8 +6,8 @@* * Copyright (C) Linus Torvalds, 2005 */ -#include "util.h" -#include "debug.h" +#include "compat-util.h" +#include "usage.h" static void report (const char *prefix,const char *err,va_list params) {
tools/lib/api/util/usage.h renamed from tools/perf/util/usage.h +4 -4
@@ -1,5 +1,5 @@ -#ifndef __PERF_USAGE_H -#define __PERF_USAGE_H +#ifndef __API_UTIL_USAGE_H +#define __API_UTIL_USAGE_H#include "compat-util.h"
@@ -8,7 +8,7 @@ extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1,extern int error (const char *err, ...) __attribute__((format (printf,1 ,2 )));extern void warning (const char *err, ...) __attribute__((format (printf,1 ,2 ))); -#include "../../../include/linux/stringify.h" +#include <linux/stringify.h> #define DIE_IF (cnd) \ do { if (cnd) \
@@ -20,4 +20,4 @@ extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)))extern void set_die_routine (void (*routine)(const char *err,va_list params)NORETURN );extern void set_warning_routine (void (*routine)(const char *err,va_list params)); -#endif /* __PERF_USAGE_H */ +#endif /* __API_UTIL_USAGE_H */
tools/lib/api/util/wrapper.c renamed from tools/perf/util/wrapper.c +3 -1
@@ -1,7 +1,9 @@/* * Various trivial helper wrappers around standard functions */ -#include "util.h" +#include "compat-util.h" +#include "wrapper.h" +#include "usage.h" /* * There's no pack memory to release - but stay close to the Git
tools/lib/api/util/wrapper.h renamed from tools/perf/util/wrapper.h +3 -3
@@ -1,5 +1,5 @@ -#ifndef __PERF_WRAPPER_H -#define __PERF_WRAPPER_H +#ifndef __API_UTIL_WRAPPER_H +#define __API_UTIL_WRAPPER_Hextern char *xstrdup (const char *str);extern void *xrealloc (void *ptr,size_t size) __attribute__((weak));
@@ -31,4 +31,4 @@ static inline void *zalloc(size_t size) } \ }while (0 ) -#endif /* __PERF_WRAPPER_H */ +#endif /* __API_UTIL_WRAPPER_H */
tools/perf/Build +1 -1
@@ -36,7 +36,7 @@ paths += -DPERF_MAN_PATH="BUILD_STR($(mandir_SQ))" CFLAGS_builtin-help.o += $(paths) CFLAGS_builtin-timechart.o += $(paths) -CFLAGS_perf.o += -DPERF_HTML_PATH="BUILD_STR($(htmldir_SQ))" -include $(OUTPUT)PERF-VERSION-FILE +CFLAGS_perf.o += -DPERF_HTML_PATH="BUILD_STR($(htmldir_SQ))" -DPERF_EXEC_PATH="BUILD_STR($(perfexecdir_SQ))" -DPREFIX="BUILD_STR($(prefix_SQ))" -include $(OUTPUT)PERF-VERSION-FILE CFLAGS_builtin-trace.o += -DSTRACE_GROUPS_DIR="BUILD_STR($(STRACE_GROUPS_DIR_SQ))" libperf-y += util/
tools/perf/arch/x86/util/intel-pt.c +1 -1
@@ -26,7 +26,7 @@#include "../../util/evlist.h" #include "../../util/evsel.h" #include "../../util/cpumap.h" -#include "../../util/parse-options.h" +#include <api/util/parse-options.h> #include "../../util/parse-events.h" #include "../../util/pmu.h" #include "../../util/debug.h"
tools/perf/bench/futex-hash.c +1 -1
@@ -11,7 +11,7 @@#include "../perf.h" #include "../util/util.h" #include "../util/stat.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/header.h" #include "bench.h" #include "futex.h"
tools/perf/bench/futex-lock-pi.c +1 -1
@@ -5,7 +5,7 @@#include "../perf.h" #include "../util/util.h" #include "../util/stat.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/header.h" #include "bench.h" #include "futex.h"
tools/perf/bench/futex-requeue.c +1 -1
@@ -11,7 +11,7 @@#include "../perf.h" #include "../util/util.h" #include "../util/stat.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/header.h" #include "bench.h" #include "futex.h"
tools/perf/bench/futex-wake-parallel.c +1 -1
@@ -10,7 +10,7 @@#include "../perf.h" #include "../util/util.h" #include "../util/stat.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/header.h" #include "bench.h" #include "futex.h"
tools/perf/bench/futex-wake.c +1 -1
@@ -11,7 +11,7 @@#include "../perf.h" #include "../util/util.h" #include "../util/stat.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/header.h" #include "bench.h" #include "futex.h"
tools/perf/bench/mem-functions.c +1 -1
@@ -8,7 +8,7 @@#include "../perf.h" #include "../util/util.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/header.h" #include "../util/cloexec.h" #include "bench.h"
tools/perf/bench/numa.c +1 -1
@@ -7,7 +7,7 @@#include "../perf.h" #include "../builtin.h" #include "../util/util.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/cloexec.h" #include "bench.h"
tools/perf/bench/sched-messaging.c +1 -1
@@ -11,7 +11,7 @@#include "../perf.h" #include "../util/util.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../builtin.h" #include "bench.h"
tools/perf/bench/sched-pipe.c +1 -1
@@ -10,7 +10,7 @@*/ #include "../perf.h" #include "../util/util.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../builtin.h" #include "bench.h"
tools/perf/builtin-annotate.c +1 -1
@@ -20,7 +20,7 @@#include "util/evsel.h" #include "util/annotate.h" #include "util/event.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-events.h" #include "util/thread.h" #include "util/sort.h"
tools/perf/builtin-bench.c +1 -1
@@ -16,7 +16,7 @@*/ #include "perf.h" #include "util/util.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "builtin.h" #include "bench/bench.h"
tools/perf/builtin-buildid-cache.c +1 -1
@@ -16,7 +16,7 @@#include "util/util.h" #include "util/debug.h" #include "util/header.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/strlist.h" #include "util/build-id.h" #include "util/session.h"
tools/perf/builtin-buildid-list.c +1 -1
@@ -12,7 +12,7 @@#include "util/build-id.h" #include "util/util.h" #include "util/debug.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/session.h" #include "util/symbol.h" #include "util/data.h"
tools/perf/builtin-config.c +1 -1
@@ -9,7 +9,7 @@#include "perf.h" #include "util/util.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/debug.h" static const char *const config_usage[] = {
tools/perf/builtin-data.c +1 -1
@@ -2,7 +2,7 @@#include "builtin.h" #include "perf.h" #include "debug.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include "data-convert-bt.h" typedef int (*data_cmd_fn_t )(int argc,const char **argv,const char *prefix);
tools/perf/builtin-evlist.c +1 -1
@@ -12,7 +12,7 @@#include "util/evlist.h" #include "util/evsel.h" #include "util/parse-events.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/session.h" #include "util/data.h" #include "util/debug.h"
tools/perf/builtin-help.c +4 -5
@@ -6,11 +6,10 @@#include "perf.h" #include "util/util.h" #include "builtin.h" -#include "util/exec_cmd.h" +#include <api/util/exec_cmd.h> #include "common-cmds.h" -#include "util/parse-options.h" -#include "util/run-command.h" -#include "util/help.h" +#include <api/util/parse-options.h> +#include <api/util/run-command.h> #include "util/debug.h" static struct man_viewer_list {
@@ -407,7 +406,7 @@ static int get_html_page_path(struct strbuf *page_path, const char *page)#ifndef open_htmlstatic void open_html (const char *path) { -execl_perf_cmd ("web--browse" ,"-c" ,"help.browser" , path,NULL ); +execl_cmd ("web--browse" ,"-c" ,"help.browser" , path,NULL ); }#endif
tools/perf/builtin-inject.c +1 -1
@@ -18,7 +18,7 @@#include "util/data.h" #include "util/auxtrace.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include <linux/list.h>
tools/perf/builtin-kmem.c +1 -1
@@ -11,7 +11,7 @@#include "util/tool.h" #include "util/callchain.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/trace-event.h" #include "util/data.h" #include "util/cpumap.h"
tools/perf/builtin-kvm.c +1 -1
@@ -9,7 +9,7 @@#include "util/header.h" #include "util/session.h" #include "util/intlist.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/trace-event.h" #include "util/debug.h" #include "util/tool.h"
tools/perf/builtin-list.c +1 -1
@@ -14,7 +14,7 @@#include "util/parse-events.h" #include "util/util.h" #include "util/pmu.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> int cmd_list (int argc,const char **argv,const char *prefix__maybe_unused ) {
tools/perf/builtin-lock.c +1 -1
@@ -8,7 +8,7 @@#include "util/thread.h" #include "util/header.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/trace-event.h" #include "util/debug.h"
tools/perf/builtin-mem.c +1 -1
@@ -1,7 +1,7 @@#include "builtin.h" #include "perf.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/trace-event.h" #include "util/tool.h" #include "util/session.h"
tools/perf/builtin-probe.c +1 -1
@@ -37,7 +37,7 @@#include "util/strfilter.h" #include "util/symbol.h" #include "util/debug.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/probe-finder.h" #include "util/probe-event.h" #include "util/probe-file.h"
tools/perf/builtin-record.c +1 -1
@@ -11,7 +11,7 @@#include "util/build-id.h" #include "util/util.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-events.h" #include "util/callchain.h"
tools/perf/builtin-report.c +1 -1
@@ -26,7 +26,7 @@#include "util/session.h" #include "util/tool.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-events.h" #include "util/thread.h"
tools/perf/builtin-sched.c +1 -1
@@ -11,7 +11,7 @@#include "util/tool.h" #include "util/cloexec.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/trace-event.h" #include "util/debug.h"
tools/perf/builtin-script.c +6 -6
@@ -2,9 +2,9 @@#include "perf.h" #include "util/debug.h" -#include "util/exec_cmd.h" +#include <api/util/exec_cmd.h> #include "util/header.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/perf_regs.h" #include "util/session.h" #include "util/tool.h"
@@ -1393,7 +1393,7 @@ static int list_available_scripts(const struct option *opt __maybe_unused,char first_half[BUFSIZ ];char *script_root; -snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,perf_exec_path ()); +snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,get_argv_exec_path ()); scripts_dir =opendir (scripts_path);if (!scripts_dir)
@@ -1514,7 +1514,7 @@ int find_scripts(char **scripts_array, char **scripts_path_array)if (!session)return -1 ; -snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,perf_exec_path ()); +snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,get_argv_exec_path ()); scripts_dir =opendir (scripts_path);if (!scripts_dir) {
@@ -1572,7 +1572,7 @@ static char *get_script_path(const char *script_root, const char *suffix)char lang_path[MAXPATHLEN ];char *__script_root; -snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,perf_exec_path ()); +snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,get_argv_exec_path ()); scripts_dir =opendir (scripts_path);if (!scripts_dir)
@@ -1808,7 +1808,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) scripting_max_stack = itrace_synth_opts.callchain_sz;/* make sure PERF_EXEC_PATH is set for scripts */ -perf_set_argv_exec_path (perf_exec_path ()); +set_argv_exec_path (get_argv_exec_path ());if (argc && !script_name && !rec_script_path && !rep_script_path) {int live_pipe[2 ];
tools/perf/builtin-stat.c +1 -1
@@ -45,7 +45,7 @@#include "builtin.h" #include "util/cgroup.h" #include "util/util.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-events.h" #include "util/pmu.h" #include "util/event.h"
tools/perf/builtin-timechart.c +1 -1
@@ -29,7 +29,7 @@#include "perf.h" #include "util/header.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-events.h" #include "util/event.h" #include "util/session.h"
tools/perf/builtin-top.c +1 -1
@@ -33,7 +33,7 @@#include "util/top.h" #include "util/util.h" #include <linux/rbtree.h> -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-events.h" #include "util/cpumap.h" #include "util/xyarray.h"
tools/perf/builtin-trace.c +2 -2
@@ -22,11 +22,11 @@#include "util/color.h" #include "util/debug.h" #include "util/evlist.h" -#include "util/exec_cmd.h" +#include <api/util/exec_cmd.h> #include "util/machine.h" #include "util/session.h" #include "util/thread.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/strlist.h" #include "util/intlist.h" #include "util/thread_map.h"
tools/perf/builtin.h +1 -1
@@ -2,7 +2,7 @@#define BUILTIN_H #include "util/util.h" -#include "util/strbuf.h" +#include <api/util/strbuf.h> extern const char perf_usage_string[];extern const char perf_more_info_string[];
tools/perf/perf.c +20 -7
@@ -9,16 +9,17 @@#include "builtin.h" #include "util/env.h" -#include "util/exec_cmd.h" +#include <api/util/exec_cmd.h> #include "util/util.h" #include "util/quote.h" -#include "util/run-command.h" +#include <api/util/run-command.h> #include "util/parse-events.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/bpf-loader.h" #include "util/debug.h" #include <api/fs/tracing_path.h> #include <pthread.h> +#include <api/util/cfg.h> const char perf_usage_string[] ="perf [--version] [--help] [OPTIONS] COMMAND [ARGS]" ;
@@ -119,7 +120,7 @@ static void commit_pager_choice(void) {switch (use_pager) {case 0 : -setenv ("PERF_PAGER" ,"cat" ,1 ); +setenv (PERF_PAGER_ENVIRONMENT ,"cat" ,1 );break ;case 1 :/* setup_pager(); */
@@ -129,6 +130,16 @@ static void commit_pager_choice(void) } } +static void setup_util (void ) +{ + util_cfg.prefix =PREFIX ; + util_cfg.exec_name ="perf" ; + util_cfg.exec_path =PERF_EXEC_PATH ; + util_cfg.exec_path_env =EXEC_PATH_ENVIRONMENT ; + util_cfg.pager_env =PERF_PAGER_ENVIRONMENT ; + util_cfg.exit_browser = exit_browser_no_wait; +} +struct option options[] = {OPT_ARGUMENT ("help" ,"help" ),OPT_ARGUMENT ("version" ,"version" ),
@@ -183,9 +194,9 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)if (!prefixcmp (cmd,CMD_EXEC_PATH )) { cmd +=strlen (CMD_EXEC_PATH );if (*cmd =='=' ) -perf_set_argv_exec_path (cmd +1 ); +set_argv_exec_path (cmd +1 );else { -puts (perf_exec_path ()); +puts (get_argv_exec_path ());exit (0 ); } }else if (!strcmp (cmd,"--html-path" )) {
@@ -530,11 +541,13 @@ int main(int argc, const char **argv)const char *cmd;char sbuf[STRERR_BUFSIZE ]; +setup_util (); +/* The page_size is placed in util object. */ page_size =sysconf (_SC_PAGE_SIZE); cacheline_size =sysconf (_SC_LEVEL1_DCACHE_LINESIZE); - cmd =perf_extract_argv0_path (argv[0 ]); + cmd =extract_argv0_path (argv[0 ]);if (!cmd) cmd ="perf-help" ;
tools/perf/perf.h +1 -0
@@ -17,6 +17,7 @@#define DEFAULT_PERF_DIR_ENVIRONMENT ".perf"#define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"#define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR" +#define PERF_PAGER_ENVIRONMENT "PERF_PAGER"extern bool test_attr__enabled;void test_attr__init (void );
tools/perf/tests/attr.c +2 -2
@@ -24,7 +24,7 @@#include <linux/kernel.h> #include "../perf.h" #include "util.h" -#include "exec_cmd.h" +#include <api/util/exec_cmd.h> #include "tests.h" #define ENV "PERF_TEST_ATTR"
@@ -164,7 +164,7 @@ int test__attr(int subtest __maybe_unused)return run_dir ("./tests" ,"./perf" );/* Then installed path. */ -snprintf (path_dir,PATH_MAX ,"%s/tests" ,perf_exec_path ()); +snprintf (path_dir,PATH_MAX ,"%s/tests" ,get_argv_exec_path ());snprintf (path_perf,PATH_MAX ,"%s/perf" ,BINDIR ); if (!lstat(path_dir, &st) &&
tools/perf/tests/builtin-test.c +1 -1
@@ -11,7 +11,7 @@#include "tests.h" #include "debug.h" #include "color.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include "symbol.h" struct test __weak arch_tests[] = {
tools/perf/ui/setup.c +5 -0
@@ -105,3 +105,8 @@ void exit_browser(bool wait_for_ok)break ; } } + +void exit_browser_no_wait (void ) +{ +exit_browser (false); +}
tools/perf/ui/ui.h +1 -0
@@ -12,6 +12,7 @@ extern int use_browser;void setup_browser (bool fallback_to_pager);void exit_browser (bool wait_for_ok); +void exit_browser_no_wait (void );#ifdef HAVE_SLANG_SUPPORT int ui__init (void );
tools/perf/util/Build +0 -13
@@ -1,41 +1,30 @@ -libperf-y += abspath.o libperf-y += alias.o libperf-y += annotate.o libperf-y += build-id.o libperf-y += config.o -libperf-y += ctype.o libperf-y += db-export.o libperf-y += env.o libperf-y += event.o libperf-y += evlist.o libperf-y += evsel.o -libperf-y += exec_cmd.o libperf-y += find_next_bit.o -libperf-y += help.o libperf-y += kallsyms.o libperf-y += levenshtein.o libperf-y += llvm-utils.o -libperf-y += parse-options.o libperf-y += parse-events.o libperf-y += perf_regs.o libperf-y += path.o libperf-y += rbtree.o libperf-y += bitmap.o libperf-y += hweight.o -libperf-y += run-command.o libperf-y += quote.o -libperf-y += strbuf.o libperf-y += string.o libperf-y += strlist.o libperf-y += strfilter.o libperf-y += top.o -libperf-y += usage.o -libperf-y += wrapper.o -libperf-y += sigchain.o libperf-y += dso.o libperf-y += symbol.o libperf-y += color.o -libperf-y += pager.o libperf-y += header.o libperf-y += callchain.o libperf-y += values.o
@@ -85,7 +74,6 @@ libperf-$(CONFIG_AUXTRACE) += intel-pt.o libperf-$(CONFIG_AUXTRACE) += intel-bts.o libperf-y += parse-branch-options.o libperf-y += parse-regs-options.o -libperf-y += term.o libperf-y += help-unknown-cmd.o libperf-$(CONFIG_LIBBPF) += bpf-loader.o
@@ -112,7 +100,6 @@ libperf-$(CONFIG_ZLIB) += zlib.o libperf-$(CONFIG_LZMA) += lzma.o CFLAGS_config.o += -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" -CFLAGS_exec_cmd.o += -DPERF_EXEC_PATH="BUILD_STR($(perfexecdir_SQ))" -DPREFIX="BUILD_STR($(prefix_SQ))" $(OUTPUT)util/parse-events-flex.c: util/parse-events.l $(OUTPUT)util/parse-events-bison.c $(call rule_mkdir)
tools/perf/util/auxtrace.c +1 -1
@@ -45,7 +45,7 @@#include "event.h" #include "session.h" #include "debug.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include "intel-pt.h" #include "intel-bts.h"
tools/perf/util/cgroup.c +1 -1
@@ -1,6 +1,6 @@#include "util.h" #include "../perf.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include "evsel.h" #include "cgroup.h" #include "evlist.h"
tools/perf/util/config.c +1 -1
@@ -9,7 +9,7 @@* */ #include "util.h" -#include "exec_cmd.h" +#include <api/util/exec_cmd.h> #include "util/hist.h" /* perf_hist_config */ #include "util/llvm-utils.h" /* perf_llvm_config */
tools/perf/util/evlist.c +1 -1
@@ -18,7 +18,7 @@#include <unistd.h> #include "parse-events.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include <sys/mman.h>
tools/perf/util/header.c +1 -1
@@ -20,7 +20,7 @@#include "cpumap.h" #include "pmu.h" #include "vdso.h" -#include "strbuf.h" +#include <api/util/strbuf.h> #include "build-id.h" #include "data.h"
tools/perf/util/help-unknown-cmd.c +1 -1
@@ -1,5 +1,5 @@#include "util.h" -#include "help.h" +#include <api/util/help.h> #include "../builtin.h" #include "levenshtein.h"
tools/perf/util/parse-branch-options.c +1 -1
@@ -1,7 +1,7 @@#include "perf.h" #include "util/util.h" #include "util/debug.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-branch-options.h" #define BRANCH_OPT (n, m) \
tools/perf/util/parse-events.c +2 -2
@@ -4,9 +4,9 @@#include "../perf.h" #include "evlist.h" #include "evsel.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include "parse-events.h" -#include "exec_cmd.h" +#include <api/util/exec_cmd.h> #include "string.h" #include "symbol.h" #include "header.h"
tools/perf/util/parse-regs-options.c +1 -1
@@ -1,7 +1,7 @@#include "perf.h" #include "util/util.h" #include "util/debug.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-regs-options.h" int
tools/perf/util/python-ext-sources +0 -1
@@ -6,7 +6,6 @@ # util/python.c -util/ctype.c util/evlist.c util/evsel.c util/cpumap.c
tools/perf/util/sort.h +1 -1
@@ -17,7 +17,7 @@#include "debug.h" #include "header.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include "parse-events.h" #include "hist.h" #include "thread.h"
tools/perf/util/util.h +11 -8
@@ -1,24 +1,27 @@#ifndef __PERF_UTIL_H#define __PERF_UTIL_H -#include "compat-util.h" +#include <api/util/compat-util.h> +#include <api/fs/tracing_path.h> #include <api/string/string.h> +#include <api/util/abspath.h> +#include <api/util/ctype.h> +#include <api/util/help.h> +#include <api/util/pager.h> +#include <api/util/strbuf.h> +#include <api/util/term.h> +#include <api/util/usage.h> +#include <api/util/wrapper.h> +#include "../perf.h" -#include "abspath.h" #include "alias.h" #include "config.h" -#include "ctype.h" #include "lzma.h" -#include "pager.h" #include "path.h" #include "srcline.h" -#include "strbuf.h" #include "string.h" -#include "term.h" #include "../ui/ui.h" -#include "usage.h" -#include "wrapper.h" #include "zlib.h" int parse_nsec_time (const char *str,u64 *ptime);
Signature · 1 line
2.4.3
Re: [PATCH v2 14/14] perf tools: Move subcommand framework and related utils to libapi
Quoted 9 lines · Josh Poimboeuf
The perf subcommand framework is needed for other tools. Move
parse-options.cand its dependencies over to libapi.Any function names with 'perf' have been renamed to something more generic.
Also created a
util_cfgstruct for passing perf-specific configuration to the library. Specifying the configuration at runtime allows the same binary to be shared by multiple tools without having to recompile it.
this patch is too big.. IMO it needs to be split into 3 parts as described in above 3 paragraphs
thanks,
jirka
Quoted 1,825 lines
Signed-off-by Josh Poimboeuf <[email protected]>--- tools/include/asm-generic/bitops/__fls.h | 2 +- tools/include/asm-generic/bitops/fls.h | 2 +- tools/include/asm-generic/bitops/fls64.h | 2 +- tools/lib/api/Build | 1 + tools/lib/api/Makefile | 6 +++- tools/lib/api/util/Build | 13 +++++++++ tools/{perf => lib/api}/util/abspath.c | 6 +++- tools/{perf => lib/api}/util/abspath.h | 6 ++-- tools/lib/api/util/cfg.c | 12 ++++++++ tools/lib/api/util/cfg.h | 15 ++++++++++ tools/{perf => lib/api}/util/compat-util.h | 7 ++--- tools/{perf => lib/api}/util/ctype.c | 3 +- tools/{perf => lib/api}/util/ctype.h | 6 ++-- tools/{perf => lib/api}/util/exec_cmd.c | 42 ++++++++++++++-------------- tools/{perf => lib/api}/util/exec_cmd.h | 18 ++++++------ tools/{perf => lib/api}/util/help.c | 11 +++++--- tools/{perf => lib/api}/util/help.h | 0 tools/{perf => lib/api}/util/pager.c | 6 ++-- tools/{perf => lib/api}/util/pager.h | 6 ++-- tools/{perf => lib/api}/util/parse-options.c | 21 ++++++++++---- tools/{perf => lib/api}/util/parse-options.h | 10 +++---- tools/{perf => lib/api}/util/run-command.c | 12 ++++---- tools/{perf => lib/api}/util/run-command.h | 10 +++---- tools/{perf => lib/api}/util/sigchain.c | 4 ++- tools/{perf => lib/api}/util/sigchain.h | 6 ++-- tools/{perf => lib/api}/util/strbuf.c | 6 +++- tools/{perf => lib/api}/util/strbuf.h | 6 ++-- tools/{perf => lib/api}/util/term.c | 3 +- tools/{perf => lib/api}/util/term.h | 0 tools/{perf => lib/api}/util/usage.c | 4 +-- tools/{perf => lib/api}/util/usage.h | 8 +++--- tools/{perf => lib/api}/util/wrapper.c | 4 ++- tools/{perf => lib/api}/util/wrapper.h | 6 ++-- tools/perf/Build | 2 +- tools/perf/arch/x86/util/intel-pt.c | 2 +- tools/perf/bench/futex-hash.c | 2 +- tools/perf/bench/futex-lock-pi.c | 2 +- tools/perf/bench/futex-requeue.c | 2 +- tools/perf/bench/futex-wake-parallel.c | 2 +- tools/perf/bench/futex-wake.c | 2 +- tools/perf/bench/mem-functions.c | 2 +- tools/perf/bench/numa.c | 2 +- tools/perf/bench/sched-messaging.c | 2 +- tools/perf/bench/sched-pipe.c | 2 +- tools/perf/builtin-annotate.c | 2 +- tools/perf/builtin-bench.c | 2 +- tools/perf/builtin-buildid-cache.c | 2 +- tools/perf/builtin-buildid-list.c | 2 +- tools/perf/builtin-config.c | 2 +- tools/perf/builtin-data.c | 2 +- tools/perf/builtin-evlist.c | 2 +- tools/perf/builtin-help.c | 9 +++--- tools/perf/builtin-inject.c | 2 +- tools/perf/builtin-kmem.c | 2 +- tools/perf/builtin-kvm.c | 2 +- tools/perf/builtin-list.c | 2 +- tools/perf/builtin-lock.c | 2 +- tools/perf/builtin-mem.c | 2 +- tools/perf/builtin-probe.c | 2 +- tools/perf/builtin-record.c | 2 +- tools/perf/builtin-report.c | 2 +- tools/perf/builtin-sched.c | 2 +- tools/perf/builtin-script.c | 12 ++++---- tools/perf/builtin-stat.c | 2 +- tools/perf/builtin-timechart.c | 2 +- tools/perf/builtin-top.c | 2 +- tools/perf/builtin-trace.c | 4 +-- tools/perf/builtin.h | 2 +- tools/perf/perf.c | 27 +++++++++++++----- tools/perf/perf.h | 1 + tools/perf/tests/attr.c | 4 +-- tools/perf/tests/builtin-test.c | 2 +- tools/perf/ui/setup.c | 5 ++++ tools/perf/ui/ui.h | 1 + tools/perf/util/Build | 13 --------- tools/perf/util/auxtrace.c | 2 +- tools/perf/util/cgroup.c | 2 +- tools/perf/util/config.c | 2 +- tools/perf/util/evlist.c | 2 +- tools/perf/util/header.c | 2 +- tools/perf/util/help-unknown-cmd.c | 2 +- tools/perf/util/parse-branch-options.c | 2 +- tools/perf/util/parse-events.c | 4 +-- tools/perf/util/parse-regs-options.c | 2 +- tools/perf/util/python-ext-sources | 1 - tools/perf/util/sort.h | 2 +- tools/perf/util/util.h | 19 +++++++------ 87 files changed, 265 insertions(+), 183 deletions(-) create mode 100644 tools/lib/api/util/Build rename tools/{perf => lib/api}/util/abspath.c (90%) rename tools/{perf => lib/api}/util/abspath.h (59%) create mode 100644 tools/lib/api/util/cfg.c create mode 100644 tools/lib/api/util/cfg.h rename tools/{perf => lib/api}/util/compat-util.h (95%) rename tools/{perf => lib/api}/util/ctype.c (97%) rename tools/{perf => lib/api}/util/ctype.h (93%) rename tools/{perf => lib/api}/util/exec_cmd.c (72%) rename tools/{perf => lib/api}/util/exec_cmd.h (14%) rename tools/{perf => lib/api}/util/help.c (96%) rename tools/{perf => lib/api}/util/help.h (100%) rename tools/{perf => lib/api}/util/pager.c (93%) rename tools/{perf => lib/api}/util/pager.h (42%) rename tools/{perf => lib/api}/util/parse-options.c (98%) rename tools/{perf => lib/api}/util/parse-options.h (98%) rename tools/{perf => lib/api}/util/run-command.c (96%) rename tools/{perf => lib/api}/util/run-command.h (87%) rename tools/{perf => lib/api}/util/sigchain.c (93%) rename tools/{perf => lib/api}/util/sigchain.h (53%) rename tools/{perf => lib/api}/util/strbuf.c (97%) rename tools/{perf => lib/api}/util/strbuf.h (97%) rename tools/{perf => lib/api}/util/term.c (93%) rename tools/{perf => lib/api}/util/term.h (100%) rename tools/{perf => lib/api}/util/usage.c (97%) rename tools/{perf => lib/api}/util/usage.h (84%) rename tools/{perf => lib/api}/util/wrapper.c (92%) rename tools/{perf => lib/api}/util/wrapper.h (89%)tools/include/asm-generic/bitops/__fls.h +1
-1@@ -1 +1 @@ -#include <../../../../include/asm-generic/bitops/__fls.h> +#include "../../../../include/asm-generic/bitops/__fls.h" tools/include/asm-generic/bitops/fls.h +1
-1@@ -1 +1 @@ -#include <../../../../include/asm-generic/bitops/fls.h> +#include "../../../../include/asm-generic/bitops/fls.h" tools/include/asm-generic/bitops/fls64.h +1
-1@@ -1 +1 @@ -#include <../../../../include/asm-generic/bitops/fls64.h> +#include "../../../../include/asm-generic/bitops/fls64.h" tools/lib/api/Build +1
-0@@ -2,3 +2,4 @@ libapi-y += fd/ libapi-y += fs/ libapi-y += cpu.o libapi-y += string/ +libapi-y += util/tools/lib/api/Makefile +5
-1@@ -17,7 +17,11 @@ LIBFILE = $(OUTPUT)libapi.a CFLAGS := $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) CFLAGS += -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fPIC -CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 +CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE + +CFLAGS += -I$(srctree)/tools/include/ +CFLAGS += -I$(srctree)/include/uapi +CFLAGS += -I$(srctree)/include RM = rm -ftools/lib/api/util/Build new file +13
-0@@ -0,0 +1,13 @@ +libapi-y += abspath.o +libapi-y += cfg.o +libapi-y += ctype.o +libapi-y += exec_cmd.o +libapi-y += help.o +libapi-y += pager.o +libapi-y += parse-options.o +libapi-y += run-command.o +libapi-y += sigchain.o +libapi-y += strbuf.o +libapi-y += term.o +libapi-y += usage.o +libapi-y += wrapper.otools/lib/api/util/abspath.c renamed from tools/perf/util/abspath.c +5
-1@@ -1,4 +1,8 @@ -#include "util.h" +#include "compat-util.h" + +#include "../string/string.h" +#include "abspath.h" +#include "usage.h" static const char *get_pwd_cwd (void ) {tools/lib/api/util/abspath.h renamed from tools/perf/util/abspath.h +3
-3@@ -1,5 +1,5 @@ -#ifndef __PERF_ABSPATH_H -#define __PERF_ABSPATH_H +#ifndef __API_UTIL_ABSPATH_H +#define __API_UTIL_ABSPATH_Hstatic inline int is_absolute_path (const char *path) {@@ -8,4 +8,4 @@ static inline int is_absolute_path(const char *path)const char *make_nonrelative_path (const char *path); -#endif /* __PERF_ABSPATH_H */ +#endif /* __API_UTIL_ABSPATH_H */ tools/lib/api/util/cfg.c new file +12
-0@@ -0,0 +1,12 @@ +#include "compat-util.h" +#include "cfg.h" + +#define UNDEFINED "UNDEFINED" + +struct util_cfg util_cfg = { + .prefix =UNDEFINED , + .exec_name =UNDEFINED , + .exec_path =UNDEFINED , + .exec_path_env =UNDEFINED , + .pager_env =UNDEFINED , +};tools/lib/api/util/cfg.h new file +15
-0@@ -0,0 +1,15 @@ +#ifndef __API_UTIL_CONFIG_H +#define __API_UTIL_CONFIG_H + +struct util_cfg { +const char *prefix; +const char *exec_name; +const char *exec_path; +const char *exec_path_env; +const char *pager_env; +void (*exit_browser)(void ); +}; + +extern struct util_cfg util_cfg; + +#endif /* #define __API_UTIL_CONFIG_H */ tools/lib/api/util/compat-util.h renamed from tools/perf/util/compat-util.h +3
-4@@ -1,5 +1,5 @@ -#ifndef __PERF_COMPAT_UTIL_H -#define __PERF_COMPAT_UTIL_H +#ifndef __API_UTIL_COMPAT_UTIL_H +#define __API_UTIL_COMPAT_UTIL_H#ifndef FLEX_ARRAY /* @@ -74,7 +74,6 @@#include <linux/magic.h> #include <linux/types.h> #include <sys/ttydefaults.h> -#include <api/fs/tracing_path.h> #include <termios.h> #include <linux/bitops.h> #include <termios.h> @@ -127,4 +126,4 @@#define NSEC_PER_MSEC 1000000L#endif -#endif /* __PERF_COMPAT_UTIL_H */ +#endif /* __API_UTIL_COMPAT_UTIL_H */ tools/lib/api/util/ctype.c renamed from tools/perf/util/ctype.c +2
-1@@ -3,7 +3,8 @@* * No surprises, and works with signed and unsigned chars. */ -#include "util.h" +#include "compat-util.h" +#include "ctype.h" enum {S =GIT_SPACE ,tools/lib/api/util/ctype.h renamed from tools/perf/util/ctype.h +3
-3@@ -1,5 +1,5 @@ -#ifndef __PERF_CTYPE_H -#define __PERF_CTYPE_H +#ifndef __API_UTIL_CTYPE_H +#define __API_UTIL_CTYPE_H/* Sane ctype - no locale, and works with signed chars */ #undef isascii@@ -49,4 +49,4 @@ static inline int sane_case(int x, int high) return x; } -#endif /* __PERF_CTYPE_H */ +#endif /* __API_UTIL_CTYPE_H */ tools/lib/api/util/exec_cmd.c renamed from tools/perf/util/exec_cmd.c +21
-21@@ -1,8 +1,9 @@ -#include "util.h" +#include "compat-util.h" #include "exec_cmd.h" -#include "quote.h" - -#include <string.h> +#include "strbuf.h" +#include "abspath.h" +#include "usage.h" +#include "cfg.h" #define MAX_ARGS 32@@ -11,18 +12,17 @@ static const char *argv0_path;char *system_path (const char *path) { -static const char *prefix =PREFIX ;struct strbuf d =STRBUF_INIT ;if (is_absolute_path (path))return strdup (path); -strbuf_addf (&d,"%s/%s" , prefix, path); +strbuf_addf (&d,"%s/%s" , util_cfg.prefix, path); path =strbuf_detach (&d,NULL );return (char *)path; } -const char *perf_extract_argv0_path (const char *argv0) +const char *extract_argv0_path (const char *argv0) {const char *slash;@@ -41,29 +41,29 @@ const char *perf_extract_argv0_path(const char *argv0)return argv0; } -void perf_set_argv_exec_path (const char *exec_path) +void set_argv_exec_path (const char *exec_path) { argv_exec_path = exec_path;/* * Propagate this setting to external programs. */ -setenv (EXEC_PATH_ENVIRONMENT , exec_path,1 ); +setenv (util_cfg.exec_path_env, exec_path,1 ); } -/* Returns the highest-priority, location to look for perf programs. */ -char *perf_exec_path (void ) +/* Returns the highest-priority location to look for subprograms. */ +char *get_argv_exec_path (void ) {char *env;if (argv_exec_path)return strdup (argv_exec_path); - env =getenv (EXEC_PATH_ENVIRONMENT ); + env =getenv (util_cfg.exec_path_env);if (env && *env)return strdup (env); -return system_path (PERF_EXEC_PATH ); +return system_path (util_cfg.exec_path); }static void add_path (struct strbuf *out,const char *path)@@ -82,7 +82,7 @@ void setup_path(void) {const char *old_path =getenv ("PATH" );struct strbuf new_path =STRBUF_INIT ; -char *tmp =perf_exec_path (); +char *tmp =get_argv_exec_path ();add_path (&new_path, tmp);add_path (&new_path, argv0_path);@@ -98,7 +98,7 @@ void setup_path(void)strbuf_release (&new_path); } -static const char **prepare_perf_cmd (const char **argv) +static const char **prepare_exec_cmd (const char **argv) {int argc;const char **nargv;@@ -107,25 +107,25 @@ static const char **prepare_perf_cmd(const char **argv) ;/* just counting */ nargv =malloc (sizeof (*nargv) * (argc +2 )); - nargv[0 ] ="perf" ; + nargv[0 ] = util_cfg.exec_name;for (argc =0 ; argv[argc]; argc++) nargv[argc +1 ] = argv[argc]; nargv[argc +1 ] =NULL ;return nargv; } -int execv_perf_cmd (const char **argv) { -const char **nargv =prepare_perf_cmd (argv); +int execv_cmd (const char **argv) { +const char **nargv =prepare_exec_cmd (argv);/* execvp() can only ever return if it fails */ -execvp ("perf" , (char **)nargv); +execvp (util_cfg.exec_name, (char **)nargv);free (nargv);return -1 ; } -int execl_perf_cmd (const char *cmd,...) +int execl_cmd (const char *cmd,...) {int argc;const char *argv[MAX_ARGS +1 ];@@ -145,5 +145,5 @@ int execl_perf_cmd(const char *cmd,...)return error ("too many args to run %s" , cmd); argv[argc] =NULL ; -return execv_perf_cmd (argv); +return execv_cmd (argv); }tools/lib/api/util/exec_cmd.h renamed from tools/perf/util/exec_cmd.h +9
-9@@ -1,13 +1,13 @@ -#ifndef __PERF_EXEC_CMD_H -#define __PERF_EXEC_CMD_H +#ifndef __API_UTIL_EXEC_CMD_H +#define __API_UTIL_EXEC_CMD_H -extern void perf_set_argv_exec_path (const char *exec_path); -extern const char *perf_extract_argv0_path (const char *path); +extern void set_argv_exec_path (const char *exec_path); +extern const char *extract_argv0_path (const char *path);extern void setup_path (void ); -extern int execv_perf_cmd (const char **argv);/* NULL terminated */ -extern int execl_perf_cmd (const char *cmd, ...); -/* perf_exec_path and system_path return malloc'd string, caller must free it */ -extern char *perf_exec_path (void ); +extern int execv_cmd (const char **argv);/* NULL terminated */ +extern int execl_cmd (const char *cmd, ...); +/* get_argv_exec_path and system_path return malloc'd string, caller must free it */ +extern char *get_argv_exec_path (void );extern char *system_path (const char *path); -#endif /* __PERF_EXEC_CMD_H */ +#endif /* __API_UTIL_EXEC_CMD_H */ tools/lib/api/util/help.c renamed from tools/perf/util/help.c +7
-4@@ -1,6 +1,9 @@ -#include "util.h" -#include "exec_cmd.h" +#include "compat-util.h" #include "help.h" +#include "exec_cmd.h" +#include "strbuf.h" +#include "wrapper.h" +#include "term.h" void add_cmdname (struct cmdnames *cmds,const char *name,size_t len) {@@ -164,7 +167,7 @@ void load_command_list(const char *prefix, struct cmdnames *other_cmds) {const char *env_path =getenv ("PATH" ); -char *exec_path =perf_exec_path (); +char *exec_path =get_argv_exec_path ();if (exec_path) {list_commands_in_dir (main_cmds, exec_path, prefix);@@ -209,7 +212,7 @@ void list_commands(const char *title, struct cmdnames *main_cmds, longest = other_cmds->names[i]->len;if (main_cmds->cnt) { -char *exec_path =perf_exec_path (); +char *exec_path =get_argv_exec_path ();printf ("available %s in '%s'\n" , title, exec_path);printf ("----------------" );mput_char ('-' ,strlen (title) +strlen (exec_path));tools/lib/api/util/help.h renamed from tools/perf/util/help.h +0
-0tools/lib/api/util/pager.c renamed from tools/perf/util/pager.c +4
-2@@ -1,6 +1,8 @@ -#include "util.h" +#include "compat-util.h" +#include "pager.h" #include "run-command.h" #include "sigchain.h" +#include "cfg.h" /* * This is split up from the rest of git so that we can do @@ -46,7 +48,7 @@ static void wait_for_pager_signal(int signo)void setup_pager (void ) { -const char *pager =getenv ("PERF_PAGER" ); +const char *pager =getenv (util_cfg.pager_env);if (!isatty (1 ))return ;tools/lib/api/util/pager.h renamed from tools/perf/util/pager.h +3
-3@@ -1,7 +1,7 @@ -#ifndef __PERF_PAGER_H -#define __PERF_PAGER_H +#ifndef __API_UTIL_PAGER_H +#define __API_UTIL_PAGER_Hextern void setup_pager (void );extern int pager_in_use (void ); -#endif /* __PERF_PAGER_H */ +#endif /* __API_UTIL_PAGER_H */ tools/lib/api/util/parse-options.c renamed from tools/perf/util/parse-options.c +15
-6@@ -1,7 +1,12 @@ -#include "util.h" +#include "compat-util.h" + +#include "../string/string.h" #include "parse-options.h" -#include "header.h" -#include <api/string/string.h> +#include "strbuf.h" +#include "usage.h" +#include "ctype.h" +#include "pager.h" +#include "cfg.h" #define OPT_SHORT 1#define OPT_UNSET 2@@ -510,7 +515,8 @@ int parse_options_subcommand(int argc, const char **argv, const struct option *oif (subcommands && !usagestr[0 ]) {struct strbuf buf =STRBUF_INIT ; -strbuf_addf (&buf,"perf %s [<options>] {" , argv[0 ]); +strbuf_addf (&buf,"%s %s [<options>] {" , + util_cfg.exec_name, argv[0 ]);for (int i =0 ; subcommands[i]; i++) {if (i)strbuf_addstr (&buf,"|" );@@ -771,7 +777,9 @@ int usage_with_options_internal(const char * const *usagestr,void usage_with_options (const char *const *usagestr,const struct option *opts) { -exit_browser (false); +if (util_cfg.exit_browser) + util_cfg.exit_browser (); +usage_with_options_internal (usagestr, opts,0 ,NULL );exit (129 ); }@@ -781,7 +789,8 @@ void usage_with_options_msg(const char * const *usagestr, {va_list ap; -exit_browser (false); +if (util_cfg.exit_browser) + util_cfg.exit_browser ();va_start (ap, fmt);strbuf_addv (&error_buf, fmt, ap);tools/lib/api/util/parse-options.h renamed from tools/perf/util/parse-options.h +5
-5@@ -1,8 +1,7 @@ -#ifndef __PERF_PARSE_OPTIONS_H -#define __PERF_PARSE_OPTIONS_H +#ifndef __API_UTIL_PARSE_OPTIONS_H +#define __API_UTIL_PARSE_OPTIONS_H -#include <linux/kernel.h> -#include <stdbool.h> +#include "compat-util.h" enum parse_opt_type {/* special types */ @@ -226,4 +225,5 @@ extern int parse_opt_verbosity_cb(const struct option *, const char *, int);extern const char *parse_options_fix_filename (const char *prefix,const char *file);void set_option_flag (struct option *opts,int sopt,const char *lopt,int flag); -#endif /* __PERF_PARSE_OPTIONS_H */ + +#endif /* __API_UTIL_PARSE_OPTIONS_H */ tools/lib/api/util/run-command.c renamed from tools/perf/util/run-command.c +7
-5@@ -1,7 +1,9 @@ -#include "util.h" +#include "compat-util.h" #include "run-command.h" #include "exec_cmd.h" -#include "debug.h" +#include "usage.h" + +#define STRERR_BUFSIZE 128static inline void close_pair (int fd[2 ]) {@@ -112,8 +114,8 @@ int start_command(struct child_process *cmd) }if (cmd->preexec_cb) cmd->preexec_cb (); -if (cmd->perf_cmd) { -execv_perf_cmd (cmd->argv); +if (cmd->exec_cmd) { +execv_cmd (cmd->argv); }else {execvp (cmd->argv[0 ], (char *const *) cmd->argv); }@@ -207,7 +209,7 @@ static void prepare_run_command_v_opt(struct child_process *cmd,memset (cmd,0 ,sizeof (*cmd)); cmd->argv = argv; cmd->no_stdin = opt &RUN_COMMAND_NO_STDIN ?1 :0 ; - cmd->perf_cmd = opt &RUN_PERF_CMD ?1 :0 ; + cmd->exec_cmd = opt &RUN_EXEC_CMD ?1 :0 ; cmd->stdout_to_stderr = opt &RUN_COMMAND_STDOUT_TO_STDERR ?1 :0 ; }tools/lib/api/util/run-command.h renamed from tools/perf/util/run-command.h +5
-5@@ -1,5 +1,5 @@ -#ifndef __PERF_RUN_COMMAND_H -#define __PERF_RUN_COMMAND_H +#ifndef __API_UTIL_RUN_COMMAND_H +#define __API_UTIL_RUN_COMMAND_Henum { ERR_RUN_COMMAND_FORK = 10000,@@ -41,7 +41,7 @@ struct child_process { unsigned no_stdin:1; unsigned no_stdout:1; unsigned no_stderr:1; - unsigned perf_cmd:1; /* if this is to be perf sub-command */ + unsigned exec_cmd:1; /* if this is to be external sub-command */ unsigned stdout_to_stderr:1;void (*preexec_cb)(void ); };@@ -51,8 +51,8 @@ int finish_command(struct child_process *);int run_command (struct child_process *);#define RUN_COMMAND_NO_STDIN 1 -#define RUN_PERF_CMD 2/*If this is to be perf sub-command */ +#define RUN_EXEC_CMD 2/*If this is to be external sub-command */ #define RUN_COMMAND_STDOUT_TO_STDERR 4int run_command_v_opt (const char **argv,int opt); -#endif /* __PERF_RUN_COMMAND_H */ +#endif /* __API_UTIL_RUN_COMMAND_H */ tools/lib/api/util/sigchain.c renamed from tools/perf/util/sigchain.c +3
-1@@ -1,5 +1,7 @@ -#include "util.h" +#include "compat-util.h" #include "sigchain.h" +#include "usage.h" +#include "wrapper.h" #define SIGCHAIN_MAX_SIGNALS 32tools/lib/api/util/sigchain.h renamed from tools/perf/util/sigchain.h +3
-3@@ -1,5 +1,5 @@ -#ifndef __PERF_SIGCHAIN_H -#define __PERF_SIGCHAIN_H +#ifndef __API_UTIL_SIGCHAIN_H +#define __API_UTIL_SIGCHAIN_Htypedef void (*sigchain_fun )(int );@@ -7,4 +7,4 @@ int sigchain_pop(int sig);void sigchain_push_common (sigchain_fun f); -#endif /* __PERF_SIGCHAIN_H */ +#endif /* __API_UTIL_SIGCHAIN_H */ tools/lib/api/util/strbuf.c renamed from tools/perf/util/strbuf.c +5
-1@@ -1,5 +1,9 @@ -#include "util.h" +#include "compat-util.h" +#include <linux/kernel.h> +#include "strbuf.h" +#include "wrapper.h" +#include "usage.h" int prefixcmp (const char *str,const char *prefix) {tools/lib/api/util/strbuf.h renamed from tools/perf/util/strbuf.h +3
-3@@ -1,5 +1,5 @@ -#ifndef __PERF_STRBUF_H -#define __PERF_STRBUF_H +#ifndef __API_UTIL_STRBUF_H +#define __API_UTIL_STRBUF_H/* * Strbuf's can be use in many ways: as a byte array, or to store arbitrary @@ -93,4 +93,4 @@ extern void strbuf_addv(struct strbuf *sb, const char *fmt, va_list ap);/* XXX: if read fails, any partial read is undone */ extern ssize_t strbuf_read (struct strbuf *,int fd,ssize_t hint); -#endif /* __PERF_STRBUF_H */ +#endif /* __API_UTIL_STRBUF_H */ tools/lib/api/util/term.c renamed from tools/perf/util/term.c +2
-1@@ -1,4 +1,5 @@ -#include "util.h" +#include "compat-util.h" +#include "term.h" void get_term_dimensions (struct winsize *ws) {tools/lib/api/util/term.h renamed from tools/perf/util/term.h +0
-0tools/lib/api/util/usage.c renamed from tools/perf/util/usage.c +2
-2@@ -6,8 +6,8 @@* * Copyright (C) Linus Torvalds, 2005 */ -#include "util.h" -#include "debug.h" +#include "compat-util.h" +#include "usage.h" static void report (const char *prefix,const char *err,va_list params) {tools/lib/api/util/usage.h renamed from tools/perf/util/usage.h +4
-4@@ -1,5 +1,5 @@ -#ifndef __PERF_USAGE_H -#define __PERF_USAGE_H +#ifndef __API_UTIL_USAGE_H +#define __API_UTIL_USAGE_H#include "compat-util.h" @@ -8,7 +8,7 @@ extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1,extern int error (const char *err, ...) __attribute__((format (printf,1 ,2 )));extern void warning (const char *err, ...) __attribute__((format (printf,1 ,2 ))); -#include "../../../include/linux/stringify.h" +#include <linux/stringify.h> #define DIE_IF (cnd) \ do { if (cnd) \@@ -20,4 +20,4 @@ extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)))extern void set_die_routine (void (*routine)(const char *err,va_list params)NORETURN );extern void set_warning_routine (void (*routine)(const char *err,va_list params)); -#endif /* __PERF_USAGE_H */ +#endif /* __API_UTIL_USAGE_H */ tools/lib/api/util/wrapper.c renamed from tools/perf/util/wrapper.c +3
-1@@ -1,7 +1,9 @@/* * Various trivial helper wrappers around standard functions */ -#include "util.h" +#include "compat-util.h" +#include "wrapper.h" +#include "usage.h" /* * There's no pack memory to release - but stay close to the Git tools/lib/api/util/wrapper.h renamed from tools/perf/util/wrapper.h +3
-3@@ -1,5 +1,5 @@ -#ifndef __PERF_WRAPPER_H -#define __PERF_WRAPPER_H +#ifndef __API_UTIL_WRAPPER_H +#define __API_UTIL_WRAPPER_Hextern char *xstrdup (const char *str);extern void *xrealloc (void *ptr,size_t size) __attribute__((weak));@@ -31,4 +31,4 @@ static inline void *zalloc(size_t size) } \ }while (0 ) -#endif /* __PERF_WRAPPER_H */ +#endif /* __API_UTIL_WRAPPER_H */tools/perf/Build +1
-1@@ -36,7 +36,7 @@ paths += -DPERF_MAN_PATH="BUILD_STR($(mandir_SQ))" CFLAGS_builtin-help.o += $(paths) CFLAGS_builtin-timechart.o += $(paths) -CFLAGS_perf.o += -DPERF_HTML_PATH="BUILD_STR($(htmldir_SQ))" -include $(OUTPUT)PERF-VERSION-FILE +CFLAGS_perf.o += -DPERF_HTML_PATH="BUILD_STR($(htmldir_SQ))" -DPERF_EXEC_PATH="BUILD_STR($(perfexecdir_SQ))" -DPREFIX="BUILD_STR($(prefix_SQ))" -include $(OUTPUT)PERF-VERSION-FILE CFLAGS_builtin-trace.o += -DSTRACE_GROUPS_DIR="BUILD_STR($(STRACE_GROUPS_DIR_SQ))" libperf-y += util/tools/perf/arch/x86/util/intel-pt.c +1
-1@@ -26,7 +26,7 @@#include "../../util/evlist.h" #include "../../util/evsel.h" #include "../../util/cpumap.h" -#include "../../util/parse-options.h" +#include <api/util/parse-options.h> #include "../../util/parse-events.h" #include "../../util/pmu.h" #include "../../util/debug.h" tools/perf/bench/futex-hash.c +1
-1@@ -11,7 +11,7 @@#include "../perf.h" #include "../util/util.h" #include "../util/stat.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/header.h" #include "bench.h" #include "futex.h" tools/perf/bench/futex-lock-pi.c +1
-1@@ -5,7 +5,7 @@#include "../perf.h" #include "../util/util.h" #include "../util/stat.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/header.h" #include "bench.h" #include "futex.h" tools/perf/bench/futex-requeue.c +1
-1@@ -11,7 +11,7 @@#include "../perf.h" #include "../util/util.h" #include "../util/stat.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/header.h" #include "bench.h" #include "futex.h" tools/perf/bench/futex-wake-parallel.c +1
-1@@ -10,7 +10,7 @@#include "../perf.h" #include "../util/util.h" #include "../util/stat.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/header.h" #include "bench.h" #include "futex.h" tools/perf/bench/futex-wake.c +1
-1@@ -11,7 +11,7 @@#include "../perf.h" #include "../util/util.h" #include "../util/stat.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/header.h" #include "bench.h" #include "futex.h" tools/perf/bench/mem-functions.c +1
-1@@ -8,7 +8,7 @@#include "../perf.h" #include "../util/util.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/header.h" #include "../util/cloexec.h" #include "bench.h" tools/perf/bench/numa.c +1
-1@@ -7,7 +7,7 @@#include "../perf.h" #include "../builtin.h" #include "../util/util.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/cloexec.h" #include "bench.h" tools/perf/bench/sched-messaging.c +1
-1@@ -11,7 +11,7 @@#include "../perf.h" #include "../util/util.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../builtin.h" #include "bench.h" tools/perf/bench/sched-pipe.c +1
-1@@ -10,7 +10,7 @@*/ #include "../perf.h" #include "../util/util.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../builtin.h" #include "bench.h" tools/perf/builtin-annotate.c +1
-1@@ -20,7 +20,7 @@#include "util/evsel.h" #include "util/annotate.h" #include "util/event.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-events.h" #include "util/thread.h" #include "util/sort.h" tools/perf/builtin-bench.c +1
-1@@ -16,7 +16,7 @@*/ #include "perf.h" #include "util/util.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "builtin.h" #include "bench/bench.h" tools/perf/builtin-buildid-cache.c +1
-1@@ -16,7 +16,7 @@#include "util/util.h" #include "util/debug.h" #include "util/header.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/strlist.h" #include "util/build-id.h" #include "util/session.h" tools/perf/builtin-buildid-list.c +1
-1@@ -12,7 +12,7 @@#include "util/build-id.h" #include "util/util.h" #include "util/debug.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/session.h" #include "util/symbol.h" #include "util/data.h" tools/perf/builtin-config.c +1
-1@@ -9,7 +9,7 @@#include "perf.h" #include "util/util.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/debug.h" static const char *const config_usage[] = {tools/perf/builtin-data.c +1
-1@@ -2,7 +2,7 @@#include "builtin.h" #include "perf.h" #include "debug.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include "data-convert-bt.h" typedef int (*data_cmd_fn_t )(int argc,const char **argv,const char *prefix);tools/perf/builtin-evlist.c +1
-1@@ -12,7 +12,7 @@#include "util/evlist.h" #include "util/evsel.h" #include "util/parse-events.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/session.h" #include "util/data.h" #include "util/debug.h" tools/perf/builtin-help.c +4
-5@@ -6,11 +6,10 @@#include "perf.h" #include "util/util.h" #include "builtin.h" -#include "util/exec_cmd.h" +#include <api/util/exec_cmd.h> #include "common-cmds.h" -#include "util/parse-options.h" -#include "util/run-command.h" -#include "util/help.h" +#include <api/util/parse-options.h> +#include <api/util/run-command.h> #include "util/debug.h" static struct man_viewer_list {@@ -407,7 +406,7 @@ static int get_html_page_path(struct strbuf *page_path, const char *page)#ifndef open_htmlstatic void open_html (const char *path) { -execl_perf_cmd ("web--browse" ,"-c" ,"help.browser" , path,NULL ); +execl_cmd ("web--browse" ,"-c" ,"help.browser" , path,NULL ); }#endif tools/perf/builtin-inject.c +1
-1@@ -18,7 +18,7 @@#include "util/data.h" #include "util/auxtrace.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include <linux/list.h> tools/perf/builtin-kmem.c +1
-1@@ -11,7 +11,7 @@#include "util/tool.h" #include "util/callchain.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/trace-event.h" #include "util/data.h" #include "util/cpumap.h" tools/perf/builtin-kvm.c +1
-1@@ -9,7 +9,7 @@#include "util/header.h" #include "util/session.h" #include "util/intlist.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/trace-event.h" #include "util/debug.h" #include "util/tool.h" tools/perf/builtin-list.c +1
-1@@ -14,7 +14,7 @@#include "util/parse-events.h" #include "util/util.h" #include "util/pmu.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> int cmd_list (int argc,const char **argv,const char *prefix__maybe_unused ) {tools/perf/builtin-lock.c +1
-1@@ -8,7 +8,7 @@#include "util/thread.h" #include "util/header.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/trace-event.h" #include "util/debug.h" tools/perf/builtin-mem.c +1
-1@@ -1,7 +1,7 @@#include "builtin.h" #include "perf.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/trace-event.h" #include "util/tool.h" #include "util/session.h" tools/perf/builtin-probe.c +1
-1@@ -37,7 +37,7 @@#include "util/strfilter.h" #include "util/symbol.h" #include "util/debug.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/probe-finder.h" #include "util/probe-event.h" #include "util/probe-file.h" tools/perf/builtin-record.c +1
-1@@ -11,7 +11,7 @@#include "util/build-id.h" #include "util/util.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-events.h" #include "util/callchain.h" tools/perf/builtin-report.c +1
-1@@ -26,7 +26,7 @@#include "util/session.h" #include "util/tool.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-events.h" #include "util/thread.h" tools/perf/builtin-sched.c +1
-1@@ -11,7 +11,7 @@#include "util/tool.h" #include "util/cloexec.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/trace-event.h" #include "util/debug.h" tools/perf/builtin-script.c +6
-6@@ -2,9 +2,9 @@#include "perf.h" #include "util/debug.h" -#include "util/exec_cmd.h" +#include <api/util/exec_cmd.h> #include "util/header.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/perf_regs.h" #include "util/session.h" #include "util/tool.h" @@ -1393,7 +1393,7 @@ static int list_available_scripts(const struct option *opt __maybe_unused,char first_half[BUFSIZ ];char *script_root; -snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,perf_exec_path ()); +snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,get_argv_exec_path ()); scripts_dir =opendir (scripts_path);if (!scripts_dir)@@ -1514,7 +1514,7 @@ int find_scripts(char **scripts_array, char **scripts_path_array)if (!session)return -1 ; -snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,perf_exec_path ()); +snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,get_argv_exec_path ()); scripts_dir =opendir (scripts_path);if (!scripts_dir) {@@ -1572,7 +1572,7 @@ static char *get_script_path(const char *script_root, const char *suffix)char lang_path[MAXPATHLEN ];char *__script_root; -snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,perf_exec_path ()); +snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,get_argv_exec_path ()); scripts_dir =opendir (scripts_path);if (!scripts_dir)@@ -1808,7 +1808,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) scripting_max_stack = itrace_synth_opts.callchain_sz;/* make sure PERF_EXEC_PATH is set for scripts */ -perf_set_argv_exec_path (perf_exec_path ()); +set_argv_exec_path (get_argv_exec_path ());if (argc && !script_name && !rec_script_path && !rep_script_path) {int live_pipe[2 ];tools/perf/builtin-stat.c +1
-1@@ -45,7 +45,7 @@#include "builtin.h" #include "util/cgroup.h" #include "util/util.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-events.h" #include "util/pmu.h" #include "util/event.h" tools/perf/builtin-timechart.c +1
-1@@ -29,7 +29,7 @@#include "perf.h" #include "util/header.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-events.h" #include "util/event.h" #include "util/session.h" tools/perf/builtin-top.c +1
-1@@ -33,7 +33,7 @@#include "util/top.h" #include "util/util.h" #include <linux/rbtree.h> -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-events.h" #include "util/cpumap.h" #include "util/xyarray.h" tools/perf/builtin-trace.c +2
-2@@ -22,11 +22,11 @@#include "util/color.h" #include "util/debug.h" #include "util/evlist.h" -#include "util/exec_cmd.h" +#include <api/util/exec_cmd.h> #include "util/machine.h" #include "util/session.h" #include "util/thread.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/strlist.h" #include "util/intlist.h" #include "util/thread_map.h" tools/perf/builtin.h +1
-1@@ -2,7 +2,7 @@#define BUILTIN_H #include "util/util.h" -#include "util/strbuf.h" +#include <api/util/strbuf.h> extern const char perf_usage_string[];extern const char perf_more_info_string[];tools/perf/perf.c +20
-7@@ -9,16 +9,17 @@#include "builtin.h" #include "util/env.h" -#include "util/exec_cmd.h" +#include <api/util/exec_cmd.h> #include "util/util.h" #include "util/quote.h" -#include "util/run-command.h" +#include <api/util/run-command.h> #include "util/parse-events.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/bpf-loader.h" #include "util/debug.h" #include <api/fs/tracing_path.h> #include <pthread.h> +#include <api/util/cfg.h> const char perf_usage_string[] ="perf [--version] [--help] [OPTIONS] COMMAND [ARGS]" ;@@ -119,7 +120,7 @@ static void commit_pager_choice(void) {switch (use_pager) {case 0 : -setenv ("PERF_PAGER" ,"cat" ,1 ); +setenv (PERF_PAGER_ENVIRONMENT ,"cat" ,1 );break ;case 1 :/* setup_pager(); */ @@ -129,6 +130,16 @@ static void commit_pager_choice(void) } } +static void setup_util (void ) +{ + util_cfg.prefix =PREFIX ; + util_cfg.exec_name ="perf" ; + util_cfg.exec_path =PERF_EXEC_PATH ; + util_cfg.exec_path_env =EXEC_PATH_ENVIRONMENT ; + util_cfg.pager_env =PERF_PAGER_ENVIRONMENT ; + util_cfg.exit_browser = exit_browser_no_wait; +} +struct option options[] = {OPT_ARGUMENT ("help" ,"help" ),OPT_ARGUMENT ("version" ,"version" ),@@ -183,9 +194,9 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)if (!prefixcmp (cmd,CMD_EXEC_PATH )) { cmd +=strlen (CMD_EXEC_PATH );if (*cmd =='=' ) -perf_set_argv_exec_path (cmd +1 ); +set_argv_exec_path (cmd +1 );else { -puts (perf_exec_path ()); +puts (get_argv_exec_path ());exit (0 ); } }else if (!strcmp (cmd,"--html-path" )) {@@ -530,11 +541,13 @@ int main(int argc, const char **argv)const char *cmd;char sbuf[STRERR_BUFSIZE ]; +setup_util (); +/* The page_size is placed in util object. */ page_size =sysconf (_SC_PAGE_SIZE); cacheline_size =sysconf (_SC_LEVEL1_DCACHE_LINESIZE); - cmd =perf_extract_argv0_path (argv[0 ]); + cmd =extract_argv0_path (argv[0 ]);if (!cmd) cmd ="perf-help" ;tools/perf/perf.h +1
-0@@ -17,6 +17,7 @@#define DEFAULT_PERF_DIR_ENVIRONMENT ".perf"#define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"#define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR" +#define PERF_PAGER_ENVIRONMENT "PERF_PAGER"extern bool test_attr__enabled;void test_attr__init (void );tools/perf/tests/attr.c +2
-2@@ -24,7 +24,7 @@#include <linux/kernel.h> #include "../perf.h" #include "util.h" -#include "exec_cmd.h" +#include <api/util/exec_cmd.h> #include "tests.h" #define ENV "PERF_TEST_ATTR"@@ -164,7 +164,7 @@ int test__attr(int subtest __maybe_unused)return run_dir ("./tests" ,"./perf" );/* Then installed path. */ -snprintf (path_dir,PATH_MAX ,"%s/tests" ,perf_exec_path ()); +snprintf (path_dir,PATH_MAX ,"%s/tests" ,get_argv_exec_path ());snprintf (path_perf,PATH_MAX ,"%s/perf" ,BINDIR ); if (!lstat(path_dir, &st) &&tools/perf/tests/builtin-test.c +1
-1@@ -11,7 +11,7 @@#include "tests.h" #include "debug.h" #include "color.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include "symbol.h" struct test __weak arch_tests[] = {tools/perf/ui/setup.c +5
-0@@ -105,3 +105,8 @@ void exit_browser(bool wait_for_ok)break ; } } + +void exit_browser_no_wait (void ) +{ +exit_browser (false); +}tools/perf/ui/ui.h +1
-0@@ -12,6 +12,7 @@ extern int use_browser;void setup_browser (bool fallback_to_pager);void exit_browser (bool wait_for_ok); +void exit_browser_no_wait (void );#ifdef HAVE_SLANG_SUPPORT int ui__init (void );tools/perf/util/Build +0
-13@@ -1,41 +1,30 @@ -libperf-y += abspath.o libperf-y += alias.o libperf-y += annotate.o libperf-y += build-id.o libperf-y += config.o -libperf-y += ctype.o libperf-y += db-export.o libperf-y += env.o libperf-y += event.o libperf-y += evlist.o libperf-y += evsel.o -libperf-y += exec_cmd.o libperf-y += find_next_bit.o -libperf-y += help.o libperf-y += kallsyms.o libperf-y += levenshtein.o libperf-y += llvm-utils.o -libperf-y += parse-options.o libperf-y += parse-events.o libperf-y += perf_regs.o libperf-y += path.o libperf-y += rbtree.o libperf-y += bitmap.o libperf-y += hweight.o -libperf-y += run-command.o libperf-y += quote.o -libperf-y += strbuf.o libperf-y += string.o libperf-y += strlist.o libperf-y += strfilter.o libperf-y += top.o -libperf-y += usage.o -libperf-y += wrapper.o -libperf-y += sigchain.o libperf-y += dso.o libperf-y += symbol.o libperf-y += color.o -libperf-y += pager.o libperf-y += header.o libperf-y += callchain.o libperf-y += values.o@@ -85,7 +74,6 @@ libperf-$(CONFIG_AUXTRACE) += intel-pt.o libperf-$(CONFIG_AUXTRACE) += intel-bts.o libperf-y += parse-branch-options.o libperf-y += parse-regs-options.o -libperf-y += term.o libperf-y += help-unknown-cmd.o libperf-$(CONFIG_LIBBPF) += bpf-loader.o@@ -112,7 +100,6 @@ libperf-$(CONFIG_ZLIB) += zlib.o libperf-$(CONFIG_LZMA) += lzma.o CFLAGS_config.o += -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" -CFLAGS_exec_cmd.o += -DPERF_EXEC_PATH="BUILD_STR($(perfexecdir_SQ))" -DPREFIX="BUILD_STR($(prefix_SQ))" $(OUTPUT)util/parse-events-flex.c: util/parse-events.l $(OUTPUT)util/parse-events-bison.c $(call rule_mkdir)tools/perf/util/auxtrace.c +1
-1@@ -45,7 +45,7 @@#include "event.h" #include "session.h" #include "debug.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include "intel-pt.h" #include "intel-bts.h" tools/perf/util/cgroup.c +1
-1@@ -1,6 +1,6 @@#include "util.h" #include "../perf.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include "evsel.h" #include "cgroup.h" #include "evlist.h" tools/perf/util/config.c +1
-1@@ -9,7 +9,7 @@* */ #include "util.h" -#include "exec_cmd.h" +#include <api/util/exec_cmd.h> #include "util/hist.h" /* perf_hist_config */ #include "util/llvm-utils.h" /* perf_llvm_config */ tools/perf/util/evlist.c +1
-1@@ -18,7 +18,7 @@#include <unistd.h> #include "parse-events.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include <sys/mman.h> tools/perf/util/header.c +1
-1@@ -20,7 +20,7 @@#include "cpumap.h" #include "pmu.h" #include "vdso.h" -#include "strbuf.h" +#include <api/util/strbuf.h> #include "build-id.h" #include "data.h" tools/perf/util/help-unknown-cmd.c +1
-1@@ -1,5 +1,5 @@#include "util.h" -#include "help.h" +#include <api/util/help.h> #include "../builtin.h" #include "levenshtein.h" tools/perf/util/parse-branch-options.c +1
-1@@ -1,7 +1,7 @@#include "perf.h" #include "util/util.h" #include "util/debug.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-branch-options.h" #define BRANCH_OPT (n, m) \tools/perf/util/parse-events.c +2
-2@@ -4,9 +4,9 @@#include "../perf.h" #include "evlist.h" #include "evsel.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include "parse-events.h" -#include "exec_cmd.h" +#include <api/util/exec_cmd.h> #include "string.h" #include "symbol.h" #include "header.h" tools/perf/util/parse-regs-options.c +1
-1@@ -1,7 +1,7 @@#include "perf.h" #include "util/util.h" #include "util/debug.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-regs-options.h" int tools/perf/util/python-ext-sources +0
-1@@ -6,7 +6,6 @@ # util/python.c -util/ctype.c util/evlist.c util/evsel.c util/cpumap.ctools/perf/util/sort.h +1
-1@@ -17,7 +17,7 @@#include "debug.h" #include "header.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include "parse-events.h" #include "hist.h" #include "thread.h" tools/perf/util/util.h +11
-8@@ -1,24 +1,27 @@#ifndef __PERF_UTIL_H#define __PERF_UTIL_H -#include "compat-util.h" +#include <api/util/compat-util.h> +#include <api/fs/tracing_path.h> #include <api/string/string.h> +#include <api/util/abspath.h> +#include <api/util/ctype.h> +#include <api/util/help.h> +#include <api/util/pager.h> +#include <api/util/strbuf.h> +#include <api/util/term.h> +#include <api/util/usage.h> +#include <api/util/wrapper.h> +#include "../perf.h" -#include "abspath.h" #include "alias.h" #include "config.h" -#include "ctype.h" #include "lzma.h" -#include "pager.h" #include "path.h" #include "srcline.h" -#include "strbuf.h" #include "string.h" -#include "term.h" #include "../ui/ui.h" -#include "usage.h" -#include "wrapper.h" #include "zlib.h" int parse_nsec_time (const char *str,u64 *ptime);Signature · 1 line
2.4.3
Re: [PATCH v2 14/14] perf tools: Move subcommand framework and related utils to libapi
Quoted 7 lines · Jiri Olsa
Quoted 6 lines · Josh Poimboeuf
The perf subcommand framework is needed for other tools. Move
parse-options.cand its dependencies over to libapi.Any function names with 'perf' have been renamed to something more generic.
Quoted 6 lines
Quoted 3 lines
Also created a
util_cfgstruct for passing perf-specific configuration to the library. Specifying the configuration at runtime allows the same binary to be shared by multiple tools without having to recompile it.this patch is too big.. IMO it needs to be split into 3 parts as described in above 3 paragraphs
Ok, will do.
Quoted 1,829 lines
thanks,
jirkaQuoted 1,825 lines
Signed-off-by Josh Poimboeuf <[email protected]>--- tools/include/asm-generic/bitops/__fls.h | 2 +- tools/include/asm-generic/bitops/fls.h | 2 +- tools/include/asm-generic/bitops/fls64.h | 2 +- tools/lib/api/Build | 1 + tools/lib/api/Makefile | 6 +++- tools/lib/api/util/Build | 13 +++++++++ tools/{perf => lib/api}/util/abspath.c | 6 +++- tools/{perf => lib/api}/util/abspath.h | 6 ++-- tools/lib/api/util/cfg.c | 12 ++++++++ tools/lib/api/util/cfg.h | 15 ++++++++++ tools/{perf => lib/api}/util/compat-util.h | 7 ++--- tools/{perf => lib/api}/util/ctype.c | 3 +- tools/{perf => lib/api}/util/ctype.h | 6 ++-- tools/{perf => lib/api}/util/exec_cmd.c | 42 ++++++++++++++-------------- tools/{perf => lib/api}/util/exec_cmd.h | 18 ++++++------ tools/{perf => lib/api}/util/help.c | 11 +++++--- tools/{perf => lib/api}/util/help.h | 0 tools/{perf => lib/api}/util/pager.c | 6 ++-- tools/{perf => lib/api}/util/pager.h | 6 ++-- tools/{perf => lib/api}/util/parse-options.c | 21 ++++++++++---- tools/{perf => lib/api}/util/parse-options.h | 10 +++---- tools/{perf => lib/api}/util/run-command.c | 12 ++++---- tools/{perf => lib/api}/util/run-command.h | 10 +++---- tools/{perf => lib/api}/util/sigchain.c | 4 ++- tools/{perf => lib/api}/util/sigchain.h | 6 ++-- tools/{perf => lib/api}/util/strbuf.c | 6 +++- tools/{perf => lib/api}/util/strbuf.h | 6 ++-- tools/{perf => lib/api}/util/term.c | 3 +- tools/{perf => lib/api}/util/term.h | 0 tools/{perf => lib/api}/util/usage.c | 4 +-- tools/{perf => lib/api}/util/usage.h | 8 +++--- tools/{perf => lib/api}/util/wrapper.c | 4 ++- tools/{perf => lib/api}/util/wrapper.h | 6 ++-- tools/perf/Build | 2 +- tools/perf/arch/x86/util/intel-pt.c | 2 +- tools/perf/bench/futex-hash.c | 2 +- tools/perf/bench/futex-lock-pi.c | 2 +- tools/perf/bench/futex-requeue.c | 2 +- tools/perf/bench/futex-wake-parallel.c | 2 +- tools/perf/bench/futex-wake.c | 2 +- tools/perf/bench/mem-functions.c | 2 +- tools/perf/bench/numa.c | 2 +- tools/perf/bench/sched-messaging.c | 2 +- tools/perf/bench/sched-pipe.c | 2 +- tools/perf/builtin-annotate.c | 2 +- tools/perf/builtin-bench.c | 2 +- tools/perf/builtin-buildid-cache.c | 2 +- tools/perf/builtin-buildid-list.c | 2 +- tools/perf/builtin-config.c | 2 +- tools/perf/builtin-data.c | 2 +- tools/perf/builtin-evlist.c | 2 +- tools/perf/builtin-help.c | 9 +++--- tools/perf/builtin-inject.c | 2 +- tools/perf/builtin-kmem.c | 2 +- tools/perf/builtin-kvm.c | 2 +- tools/perf/builtin-list.c | 2 +- tools/perf/builtin-lock.c | 2 +- tools/perf/builtin-mem.c | 2 +- tools/perf/builtin-probe.c | 2 +- tools/perf/builtin-record.c | 2 +- tools/perf/builtin-report.c | 2 +- tools/perf/builtin-sched.c | 2 +- tools/perf/builtin-script.c | 12 ++++---- tools/perf/builtin-stat.c | 2 +- tools/perf/builtin-timechart.c | 2 +- tools/perf/builtin-top.c | 2 +- tools/perf/builtin-trace.c | 4 +-- tools/perf/builtin.h | 2 +- tools/perf/perf.c | 27 +++++++++++++----- tools/perf/perf.h | 1 + tools/perf/tests/attr.c | 4 +-- tools/perf/tests/builtin-test.c | 2 +- tools/perf/ui/setup.c | 5 ++++ tools/perf/ui/ui.h | 1 + tools/perf/util/Build | 13 --------- tools/perf/util/auxtrace.c | 2 +- tools/perf/util/cgroup.c | 2 +- tools/perf/util/config.c | 2 +- tools/perf/util/evlist.c | 2 +- tools/perf/util/header.c | 2 +- tools/perf/util/help-unknown-cmd.c | 2 +- tools/perf/util/parse-branch-options.c | 2 +- tools/perf/util/parse-events.c | 4 +-- tools/perf/util/parse-regs-options.c | 2 +- tools/perf/util/python-ext-sources | 1 - tools/perf/util/sort.h | 2 +- tools/perf/util/util.h | 19 +++++++------ 87 files changed, 265 insertions(+), 183 deletions(-) create mode 100644 tools/lib/api/util/Build rename tools/{perf => lib/api}/util/abspath.c (90%) rename tools/{perf => lib/api}/util/abspath.h (59%) create mode 100644 tools/lib/api/util/cfg.c create mode 100644 tools/lib/api/util/cfg.h rename tools/{perf => lib/api}/util/compat-util.h (95%) rename tools/{perf => lib/api}/util/ctype.c (97%) rename tools/{perf => lib/api}/util/ctype.h (93%) rename tools/{perf => lib/api}/util/exec_cmd.c (72%) rename tools/{perf => lib/api}/util/exec_cmd.h (14%) rename tools/{perf => lib/api}/util/help.c (96%) rename tools/{perf => lib/api}/util/help.h (100%) rename tools/{perf => lib/api}/util/pager.c (93%) rename tools/{perf => lib/api}/util/pager.h (42%) rename tools/{perf => lib/api}/util/parse-options.c (98%) rename tools/{perf => lib/api}/util/parse-options.h (98%) rename tools/{perf => lib/api}/util/run-command.c (96%) rename tools/{perf => lib/api}/util/run-command.h (87%) rename tools/{perf => lib/api}/util/sigchain.c (93%) rename tools/{perf => lib/api}/util/sigchain.h (53%) rename tools/{perf => lib/api}/util/strbuf.c (97%) rename tools/{perf => lib/api}/util/strbuf.h (97%) rename tools/{perf => lib/api}/util/term.c (93%) rename tools/{perf => lib/api}/util/term.h (100%) rename tools/{perf => lib/api}/util/usage.c (97%) rename tools/{perf => lib/api}/util/usage.h (84%) rename tools/{perf => lib/api}/util/wrapper.c (92%) rename tools/{perf => lib/api}/util/wrapper.h (89%)tools/include/asm-generic/bitops/__fls.h +1
-1@@ -1 +1 @@ -#include <../../../../include/asm-generic/bitops/__fls.h> +#include "../../../../include/asm-generic/bitops/__fls.h" tools/include/asm-generic/bitops/fls.h +1
-1@@ -1 +1 @@ -#include <../../../../include/asm-generic/bitops/fls.h> +#include "../../../../include/asm-generic/bitops/fls.h" tools/include/asm-generic/bitops/fls64.h +1
-1@@ -1 +1 @@ -#include <../../../../include/asm-generic/bitops/fls64.h> +#include "../../../../include/asm-generic/bitops/fls64.h" tools/lib/api/Build +1
-0@@ -2,3 +2,4 @@ libapi-y += fd/ libapi-y += fs/ libapi-y += cpu.o libapi-y += string/ +libapi-y += util/tools/lib/api/Makefile +5
-1@@ -17,7 +17,11 @@ LIBFILE = $(OUTPUT)libapi.a CFLAGS := $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) CFLAGS += -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fPIC -CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 +CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE + +CFLAGS += -I$(srctree)/tools/include/ +CFLAGS += -I$(srctree)/include/uapi +CFLAGS += -I$(srctree)/include RM = rm -ftools/lib/api/util/Build new file +13
-0@@ -0,0 +1,13 @@ +libapi-y += abspath.o +libapi-y += cfg.o +libapi-y += ctype.o +libapi-y += exec_cmd.o +libapi-y += help.o +libapi-y += pager.o +libapi-y += parse-options.o +libapi-y += run-command.o +libapi-y += sigchain.o +libapi-y += strbuf.o +libapi-y += term.o +libapi-y += usage.o +libapi-y += wrapper.otools/lib/api/util/abspath.c renamed from tools/perf/util/abspath.c +5
-1@@ -1,4 +1,8 @@ -#include "util.h" +#include "compat-util.h" + +#include "../string/string.h" +#include "abspath.h" +#include "usage.h" static const char *get_pwd_cwd (void ) {tools/lib/api/util/abspath.h renamed from tools/perf/util/abspath.h +3
-3@@ -1,5 +1,5 @@ -#ifndef __PERF_ABSPATH_H -#define __PERF_ABSPATH_H +#ifndef __API_UTIL_ABSPATH_H +#define __API_UTIL_ABSPATH_Hstatic inline int is_absolute_path (const char *path) {@@ -8,4 +8,4 @@ static inline int is_absolute_path(const char *path)const char *make_nonrelative_path (const char *path); -#endif /* __PERF_ABSPATH_H */ +#endif /* __API_UTIL_ABSPATH_H */ tools/lib/api/util/cfg.c new file +12
-0@@ -0,0 +1,12 @@ +#include "compat-util.h" +#include "cfg.h" + +#define UNDEFINED "UNDEFINED" + +struct util_cfg util_cfg = { + .prefix =UNDEFINED , + .exec_name =UNDEFINED , + .exec_path =UNDEFINED , + .exec_path_env =UNDEFINED , + .pager_env =UNDEFINED , +};tools/lib/api/util/cfg.h new file +15
-0@@ -0,0 +1,15 @@ +#ifndef __API_UTIL_CONFIG_H +#define __API_UTIL_CONFIG_H + +struct util_cfg { +const char *prefix; +const char *exec_name; +const char *exec_path; +const char *exec_path_env; +const char *pager_env; +void (*exit_browser)(void ); +}; + +extern struct util_cfg util_cfg; + +#endif /* #define __API_UTIL_CONFIG_H */ tools/lib/api/util/compat-util.h renamed from tools/perf/util/compat-util.h +3
-4@@ -1,5 +1,5 @@ -#ifndef __PERF_COMPAT_UTIL_H -#define __PERF_COMPAT_UTIL_H +#ifndef __API_UTIL_COMPAT_UTIL_H +#define __API_UTIL_COMPAT_UTIL_H#ifndef FLEX_ARRAY /* @@ -74,7 +74,6 @@#include <linux/magic.h> #include <linux/types.h> #include <sys/ttydefaults.h> -#include <api/fs/tracing_path.h> #include <termios.h> #include <linux/bitops.h> #include <termios.h> @@ -127,4 +126,4 @@#define NSEC_PER_MSEC 1000000L#endif -#endif /* __PERF_COMPAT_UTIL_H */ +#endif /* __API_UTIL_COMPAT_UTIL_H */ tools/lib/api/util/ctype.c renamed from tools/perf/util/ctype.c +2
-1@@ -3,7 +3,8 @@* * No surprises, and works with signed and unsigned chars. */ -#include "util.h" +#include "compat-util.h" +#include "ctype.h" enum {S =GIT_SPACE ,tools/lib/api/util/ctype.h renamed from tools/perf/util/ctype.h +3
-3@@ -1,5 +1,5 @@ -#ifndef __PERF_CTYPE_H -#define __PERF_CTYPE_H +#ifndef __API_UTIL_CTYPE_H +#define __API_UTIL_CTYPE_H/* Sane ctype - no locale, and works with signed chars */ #undef isascii@@ -49,4 +49,4 @@ static inline int sane_case(int x, int high) return x; } -#endif /* __PERF_CTYPE_H */ +#endif /* __API_UTIL_CTYPE_H */ tools/lib/api/util/exec_cmd.c renamed from tools/perf/util/exec_cmd.c +21
-21@@ -1,8 +1,9 @@ -#include "util.h" +#include "compat-util.h" #include "exec_cmd.h" -#include "quote.h" - -#include <string.h> +#include "strbuf.h" +#include "abspath.h" +#include "usage.h" +#include "cfg.h" #define MAX_ARGS 32@@ -11,18 +12,17 @@ static const char *argv0_path;char *system_path (const char *path) { -static const char *prefix =PREFIX ;struct strbuf d =STRBUF_INIT ;if (is_absolute_path (path))return strdup (path); -strbuf_addf (&d,"%s/%s" , prefix, path); +strbuf_addf (&d,"%s/%s" , util_cfg.prefix, path); path =strbuf_detach (&d,NULL );return (char *)path; } -const char *perf_extract_argv0_path (const char *argv0) +const char *extract_argv0_path (const char *argv0) {const char *slash;@@ -41,29 +41,29 @@ const char *perf_extract_argv0_path(const char *argv0)return argv0; } -void perf_set_argv_exec_path (const char *exec_path) +void set_argv_exec_path (const char *exec_path) { argv_exec_path = exec_path;/* * Propagate this setting to external programs. */ -setenv (EXEC_PATH_ENVIRONMENT , exec_path,1 ); +setenv (util_cfg.exec_path_env, exec_path,1 ); } -/* Returns the highest-priority, location to look for perf programs. */ -char *perf_exec_path (void ) +/* Returns the highest-priority location to look for subprograms. */ +char *get_argv_exec_path (void ) {char *env;if (argv_exec_path)return strdup (argv_exec_path); - env =getenv (EXEC_PATH_ENVIRONMENT ); + env =getenv (util_cfg.exec_path_env);if (env && *env)return strdup (env); -return system_path (PERF_EXEC_PATH ); +return system_path (util_cfg.exec_path); }static void add_path (struct strbuf *out,const char *path)@@ -82,7 +82,7 @@ void setup_path(void) {const char *old_path =getenv ("PATH" );struct strbuf new_path =STRBUF_INIT ; -char *tmp =perf_exec_path (); +char *tmp =get_argv_exec_path ();add_path (&new_path, tmp);add_path (&new_path, argv0_path);@@ -98,7 +98,7 @@ void setup_path(void)strbuf_release (&new_path); } -static const char **prepare_perf_cmd (const char **argv) +static const char **prepare_exec_cmd (const char **argv) {int argc;const char **nargv;@@ -107,25 +107,25 @@ static const char **prepare_perf_cmd(const char **argv) ;/* just counting */ nargv =malloc (sizeof (*nargv) * (argc +2 )); - nargv[0 ] ="perf" ; + nargv[0 ] = util_cfg.exec_name;for (argc =0 ; argv[argc]; argc++) nargv[argc +1 ] = argv[argc]; nargv[argc +1 ] =NULL ;return nargv; } -int execv_perf_cmd (const char **argv) { -const char **nargv =prepare_perf_cmd (argv); +int execv_cmd (const char **argv) { +const char **nargv =prepare_exec_cmd (argv);/* execvp() can only ever return if it fails */ -execvp ("perf" , (char **)nargv); +execvp (util_cfg.exec_name, (char **)nargv);free (nargv);return -1 ; } -int execl_perf_cmd (const char *cmd,...) +int execl_cmd (const char *cmd,...) {int argc;const char *argv[MAX_ARGS +1 ];@@ -145,5 +145,5 @@ int execl_perf_cmd(const char *cmd,...)return error ("too many args to run %s" , cmd); argv[argc] =NULL ; -return execv_perf_cmd (argv); +return execv_cmd (argv); }tools/lib/api/util/exec_cmd.h renamed from tools/perf/util/exec_cmd.h +9
-9@@ -1,13 +1,13 @@ -#ifndef __PERF_EXEC_CMD_H -#define __PERF_EXEC_CMD_H +#ifndef __API_UTIL_EXEC_CMD_H +#define __API_UTIL_EXEC_CMD_H -extern void perf_set_argv_exec_path (const char *exec_path); -extern const char *perf_extract_argv0_path (const char *path); +extern void set_argv_exec_path (const char *exec_path); +extern const char *extract_argv0_path (const char *path);extern void setup_path (void ); -extern int execv_perf_cmd (const char **argv);/* NULL terminated */ -extern int execl_perf_cmd (const char *cmd, ...); -/* perf_exec_path and system_path return malloc'd string, caller must free it */ -extern char *perf_exec_path (void ); +extern int execv_cmd (const char **argv);/* NULL terminated */ +extern int execl_cmd (const char *cmd, ...); +/* get_argv_exec_path and system_path return malloc'd string, caller must free it */ +extern char *get_argv_exec_path (void );extern char *system_path (const char *path); -#endif /* __PERF_EXEC_CMD_H */ +#endif /* __API_UTIL_EXEC_CMD_H */ tools/lib/api/util/help.c renamed from tools/perf/util/help.c +7
-4@@ -1,6 +1,9 @@ -#include "util.h" -#include "exec_cmd.h" +#include "compat-util.h" #include "help.h" +#include "exec_cmd.h" +#include "strbuf.h" +#include "wrapper.h" +#include "term.h" void add_cmdname (struct cmdnames *cmds,const char *name,size_t len) {@@ -164,7 +167,7 @@ void load_command_list(const char *prefix, struct cmdnames *other_cmds) {const char *env_path =getenv ("PATH" ); -char *exec_path =perf_exec_path (); +char *exec_path =get_argv_exec_path ();if (exec_path) {list_commands_in_dir (main_cmds, exec_path, prefix);@@ -209,7 +212,7 @@ void list_commands(const char *title, struct cmdnames *main_cmds, longest = other_cmds->names[i]->len;if (main_cmds->cnt) { -char *exec_path =perf_exec_path (); +char *exec_path =get_argv_exec_path ();printf ("available %s in '%s'\n" , title, exec_path);printf ("----------------" );mput_char ('-' ,strlen (title) +strlen (exec_path));tools/lib/api/util/help.h renamed from tools/perf/util/help.h +0
-0tools/lib/api/util/pager.c renamed from tools/perf/util/pager.c +4
-2@@ -1,6 +1,8 @@ -#include "util.h" +#include "compat-util.h" +#include "pager.h" #include "run-command.h" #include "sigchain.h" +#include "cfg.h" /* * This is split up from the rest of git so that we can do @@ -46,7 +48,7 @@ static void wait_for_pager_signal(int signo)void setup_pager (void ) { -const char *pager =getenv ("PERF_PAGER" ); +const char *pager =getenv (util_cfg.pager_env);if (!isatty (1 ))return ;tools/lib/api/util/pager.h renamed from tools/perf/util/pager.h +3
-3@@ -1,7 +1,7 @@ -#ifndef __PERF_PAGER_H -#define __PERF_PAGER_H +#ifndef __API_UTIL_PAGER_H +#define __API_UTIL_PAGER_Hextern void setup_pager (void );extern int pager_in_use (void ); -#endif /* __PERF_PAGER_H */ +#endif /* __API_UTIL_PAGER_H */ tools/lib/api/util/parse-options.c renamed from tools/perf/util/parse-options.c +15
-6@@ -1,7 +1,12 @@ -#include "util.h" +#include "compat-util.h" + +#include "../string/string.h" #include "parse-options.h" -#include "header.h" -#include <api/string/string.h> +#include "strbuf.h" +#include "usage.h" +#include "ctype.h" +#include "pager.h" +#include "cfg.h" #define OPT_SHORT 1#define OPT_UNSET 2@@ -510,7 +515,8 @@ int parse_options_subcommand(int argc, const char **argv, const struct option *oif (subcommands && !usagestr[0 ]) {struct strbuf buf =STRBUF_INIT ; -strbuf_addf (&buf,"perf %s [<options>] {" , argv[0 ]); +strbuf_addf (&buf,"%s %s [<options>] {" , + util_cfg.exec_name, argv[0 ]);for (int i =0 ; subcommands[i]; i++) {if (i)strbuf_addstr (&buf,"|" );@@ -771,7 +777,9 @@ int usage_with_options_internal(const char * const *usagestr,void usage_with_options (const char *const *usagestr,const struct option *opts) { -exit_browser (false); +if (util_cfg.exit_browser) + util_cfg.exit_browser (); +usage_with_options_internal (usagestr, opts,0 ,NULL );exit (129 ); }@@ -781,7 +789,8 @@ void usage_with_options_msg(const char * const *usagestr, {va_list ap; -exit_browser (false); +if (util_cfg.exit_browser) + util_cfg.exit_browser ();va_start (ap, fmt);strbuf_addv (&error_buf, fmt, ap);tools/lib/api/util/parse-options.h renamed from tools/perf/util/parse-options.h +5
-5@@ -1,8 +1,7 @@ -#ifndef __PERF_PARSE_OPTIONS_H -#define __PERF_PARSE_OPTIONS_H +#ifndef __API_UTIL_PARSE_OPTIONS_H +#define __API_UTIL_PARSE_OPTIONS_H -#include <linux/kernel.h> -#include <stdbool.h> +#include "compat-util.h" enum parse_opt_type {/* special types */ @@ -226,4 +225,5 @@ extern int parse_opt_verbosity_cb(const struct option *, const char *, int);extern const char *parse_options_fix_filename (const char *prefix,const char *file);void set_option_flag (struct option *opts,int sopt,const char *lopt,int flag); -#endif /* __PERF_PARSE_OPTIONS_H */ + +#endif /* __API_UTIL_PARSE_OPTIONS_H */ tools/lib/api/util/run-command.c renamed from tools/perf/util/run-command.c +7
-5@@ -1,7 +1,9 @@ -#include "util.h" +#include "compat-util.h" #include "run-command.h" #include "exec_cmd.h" -#include "debug.h" +#include "usage.h" + +#define STRERR_BUFSIZE 128static inline void close_pair (int fd[2 ]) {@@ -112,8 +114,8 @@ int start_command(struct child_process *cmd) }if (cmd->preexec_cb) cmd->preexec_cb (); -if (cmd->perf_cmd) { -execv_perf_cmd (cmd->argv); +if (cmd->exec_cmd) { +execv_cmd (cmd->argv); }else {execvp (cmd->argv[0 ], (char *const *) cmd->argv); }@@ -207,7 +209,7 @@ static void prepare_run_command_v_opt(struct child_process *cmd,memset (cmd,0 ,sizeof (*cmd)); cmd->argv = argv; cmd->no_stdin = opt &RUN_COMMAND_NO_STDIN ?1 :0 ; - cmd->perf_cmd = opt &RUN_PERF_CMD ?1 :0 ; + cmd->exec_cmd = opt &RUN_EXEC_CMD ?1 :0 ; cmd->stdout_to_stderr = opt &RUN_COMMAND_STDOUT_TO_STDERR ?1 :0 ; }tools/lib/api/util/run-command.h renamed from tools/perf/util/run-command.h +5
-5@@ -1,5 +1,5 @@ -#ifndef __PERF_RUN_COMMAND_H -#define __PERF_RUN_COMMAND_H +#ifndef __API_UTIL_RUN_COMMAND_H +#define __API_UTIL_RUN_COMMAND_Henum { ERR_RUN_COMMAND_FORK = 10000,@@ -41,7 +41,7 @@ struct child_process { unsigned no_stdin:1; unsigned no_stdout:1; unsigned no_stderr:1; - unsigned perf_cmd:1; /* if this is to be perf sub-command */ + unsigned exec_cmd:1; /* if this is to be external sub-command */ unsigned stdout_to_stderr:1;void (*preexec_cb)(void ); };@@ -51,8 +51,8 @@ int finish_command(struct child_process *);int run_command (struct child_process *);#define RUN_COMMAND_NO_STDIN 1 -#define RUN_PERF_CMD 2/*If this is to be perf sub-command */ +#define RUN_EXEC_CMD 2/*If this is to be external sub-command */ #define RUN_COMMAND_STDOUT_TO_STDERR 4int run_command_v_opt (const char **argv,int opt); -#endif /* __PERF_RUN_COMMAND_H */ +#endif /* __API_UTIL_RUN_COMMAND_H */ tools/lib/api/util/sigchain.c renamed from tools/perf/util/sigchain.c +3
-1@@ -1,5 +1,7 @@ -#include "util.h" +#include "compat-util.h" #include "sigchain.h" +#include "usage.h" +#include "wrapper.h" #define SIGCHAIN_MAX_SIGNALS 32tools/lib/api/util/sigchain.h renamed from tools/perf/util/sigchain.h +3
-3@@ -1,5 +1,5 @@ -#ifndef __PERF_SIGCHAIN_H -#define __PERF_SIGCHAIN_H +#ifndef __API_UTIL_SIGCHAIN_H +#define __API_UTIL_SIGCHAIN_Htypedef void (*sigchain_fun )(int );@@ -7,4 +7,4 @@ int sigchain_pop(int sig);void sigchain_push_common (sigchain_fun f); -#endif /* __PERF_SIGCHAIN_H */ +#endif /* __API_UTIL_SIGCHAIN_H */ tools/lib/api/util/strbuf.c renamed from tools/perf/util/strbuf.c +5
-1@@ -1,5 +1,9 @@ -#include "util.h" +#include "compat-util.h" +#include <linux/kernel.h> +#include "strbuf.h" +#include "wrapper.h" +#include "usage.h" int prefixcmp (const char *str,const char *prefix) {tools/lib/api/util/strbuf.h renamed from tools/perf/util/strbuf.h +3
-3@@ -1,5 +1,5 @@ -#ifndef __PERF_STRBUF_H -#define __PERF_STRBUF_H +#ifndef __API_UTIL_STRBUF_H +#define __API_UTIL_STRBUF_H/* * Strbuf's can be use in many ways: as a byte array, or to store arbitrary @@ -93,4 +93,4 @@ extern void strbuf_addv(struct strbuf *sb, const char *fmt, va_list ap);/* XXX: if read fails, any partial read is undone */ extern ssize_t strbuf_read (struct strbuf *,int fd,ssize_t hint); -#endif /* __PERF_STRBUF_H */ +#endif /* __API_UTIL_STRBUF_H */ tools/lib/api/util/term.c renamed from tools/perf/util/term.c +2
-1@@ -1,4 +1,5 @@ -#include "util.h" +#include "compat-util.h" +#include "term.h" void get_term_dimensions (struct winsize *ws) {tools/lib/api/util/term.h renamed from tools/perf/util/term.h +0
-0tools/lib/api/util/usage.c renamed from tools/perf/util/usage.c +2
-2@@ -6,8 +6,8 @@* * Copyright (C) Linus Torvalds, 2005 */ -#include "util.h" -#include "debug.h" +#include "compat-util.h" +#include "usage.h" static void report (const char *prefix,const char *err,va_list params) {tools/lib/api/util/usage.h renamed from tools/perf/util/usage.h +4
-4@@ -1,5 +1,5 @@ -#ifndef __PERF_USAGE_H -#define __PERF_USAGE_H +#ifndef __API_UTIL_USAGE_H +#define __API_UTIL_USAGE_H#include "compat-util.h" @@ -8,7 +8,7 @@ extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1,extern int error (const char *err, ...) __attribute__((format (printf,1 ,2 )));extern void warning (const char *err, ...) __attribute__((format (printf,1 ,2 ))); -#include "../../../include/linux/stringify.h" +#include <linux/stringify.h> #define DIE_IF (cnd) \ do { if (cnd) \@@ -20,4 +20,4 @@ extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)))extern void set_die_routine (void (*routine)(const char *err,va_list params)NORETURN );extern void set_warning_routine (void (*routine)(const char *err,va_list params)); -#endif /* __PERF_USAGE_H */ +#endif /* __API_UTIL_USAGE_H */ tools/lib/api/util/wrapper.c renamed from tools/perf/util/wrapper.c +3
-1@@ -1,7 +1,9 @@/* * Various trivial helper wrappers around standard functions */ -#include "util.h" +#include "compat-util.h" +#include "wrapper.h" +#include "usage.h" /* * There's no pack memory to release - but stay close to the Git tools/lib/api/util/wrapper.h renamed from tools/perf/util/wrapper.h +3
-3@@ -1,5 +1,5 @@ -#ifndef __PERF_WRAPPER_H -#define __PERF_WRAPPER_H +#ifndef __API_UTIL_WRAPPER_H +#define __API_UTIL_WRAPPER_Hextern char *xstrdup (const char *str);extern void *xrealloc (void *ptr,size_t size) __attribute__((weak));@@ -31,4 +31,4 @@ static inline void *zalloc(size_t size) } \ }while (0 ) -#endif /* __PERF_WRAPPER_H */ +#endif /* __API_UTIL_WRAPPER_H */tools/perf/Build +1
-1@@ -36,7 +36,7 @@ paths += -DPERF_MAN_PATH="BUILD_STR($(mandir_SQ))" CFLAGS_builtin-help.o += $(paths) CFLAGS_builtin-timechart.o += $(paths) -CFLAGS_perf.o += -DPERF_HTML_PATH="BUILD_STR($(htmldir_SQ))" -include $(OUTPUT)PERF-VERSION-FILE +CFLAGS_perf.o += -DPERF_HTML_PATH="BUILD_STR($(htmldir_SQ))" -DPERF_EXEC_PATH="BUILD_STR($(perfexecdir_SQ))" -DPREFIX="BUILD_STR($(prefix_SQ))" -include $(OUTPUT)PERF-VERSION-FILE CFLAGS_builtin-trace.o += -DSTRACE_GROUPS_DIR="BUILD_STR($(STRACE_GROUPS_DIR_SQ))" libperf-y += util/tools/perf/arch/x86/util/intel-pt.c +1
-1@@ -26,7 +26,7 @@#include "../../util/evlist.h" #include "../../util/evsel.h" #include "../../util/cpumap.h" -#include "../../util/parse-options.h" +#include <api/util/parse-options.h> #include "../../util/parse-events.h" #include "../../util/pmu.h" #include "../../util/debug.h" tools/perf/bench/futex-hash.c +1
-1@@ -11,7 +11,7 @@#include "../perf.h" #include "../util/util.h" #include "../util/stat.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/header.h" #include "bench.h" #include "futex.h" tools/perf/bench/futex-lock-pi.c +1
-1@@ -5,7 +5,7 @@#include "../perf.h" #include "../util/util.h" #include "../util/stat.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/header.h" #include "bench.h" #include "futex.h" tools/perf/bench/futex-requeue.c +1
-1@@ -11,7 +11,7 @@#include "../perf.h" #include "../util/util.h" #include "../util/stat.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/header.h" #include "bench.h" #include "futex.h" tools/perf/bench/futex-wake-parallel.c +1
-1@@ -10,7 +10,7 @@#include "../perf.h" #include "../util/util.h" #include "../util/stat.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/header.h" #include "bench.h" #include "futex.h" tools/perf/bench/futex-wake.c +1
-1@@ -11,7 +11,7 @@#include "../perf.h" #include "../util/util.h" #include "../util/stat.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/header.h" #include "bench.h" #include "futex.h" tools/perf/bench/mem-functions.c +1
-1@@ -8,7 +8,7 @@#include "../perf.h" #include "../util/util.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/header.h" #include "../util/cloexec.h" #include "bench.h" tools/perf/bench/numa.c +1
-1@@ -7,7 +7,7 @@#include "../perf.h" #include "../builtin.h" #include "../util/util.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/cloexec.h" #include "bench.h" tools/perf/bench/sched-messaging.c +1
-1@@ -11,7 +11,7 @@#include "../perf.h" #include "../util/util.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../builtin.h" #include "bench.h" tools/perf/bench/sched-pipe.c +1
-1@@ -10,7 +10,7 @@*/ #include "../perf.h" #include "../util/util.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../builtin.h" #include "bench.h" tools/perf/builtin-annotate.c +1
-1@@ -20,7 +20,7 @@#include "util/evsel.h" #include "util/annotate.h" #include "util/event.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-events.h" #include "util/thread.h" #include "util/sort.h" tools/perf/builtin-bench.c +1
-1@@ -16,7 +16,7 @@*/ #include "perf.h" #include "util/util.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "builtin.h" #include "bench/bench.h" tools/perf/builtin-buildid-cache.c +1
-1@@ -16,7 +16,7 @@#include "util/util.h" #include "util/debug.h" #include "util/header.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/strlist.h" #include "util/build-id.h" #include "util/session.h" tools/perf/builtin-buildid-list.c +1
-1@@ -12,7 +12,7 @@#include "util/build-id.h" #include "util/util.h" #include "util/debug.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/session.h" #include "util/symbol.h" #include "util/data.h" tools/perf/builtin-config.c +1
-1@@ -9,7 +9,7 @@#include "perf.h" #include "util/util.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/debug.h" static const char *const config_usage[] = {tools/perf/builtin-data.c +1
-1@@ -2,7 +2,7 @@#include "builtin.h" #include "perf.h" #include "debug.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include "data-convert-bt.h" typedef int (*data_cmd_fn_t )(int argc,const char **argv,const char *prefix);tools/perf/builtin-evlist.c +1
-1@@ -12,7 +12,7 @@#include "util/evlist.h" #include "util/evsel.h" #include "util/parse-events.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/session.h" #include "util/data.h" #include "util/debug.h" tools/perf/builtin-help.c +4
-5@@ -6,11 +6,10 @@#include "perf.h" #include "util/util.h" #include "builtin.h" -#include "util/exec_cmd.h" +#include <api/util/exec_cmd.h> #include "common-cmds.h" -#include "util/parse-options.h" -#include "util/run-command.h" -#include "util/help.h" +#include <api/util/parse-options.h> +#include <api/util/run-command.h> #include "util/debug.h" static struct man_viewer_list {@@ -407,7 +406,7 @@ static int get_html_page_path(struct strbuf *page_path, const char *page)#ifndef open_htmlstatic void open_html (const char *path) { -execl_perf_cmd ("web--browse" ,"-c" ,"help.browser" , path,NULL ); +execl_cmd ("web--browse" ,"-c" ,"help.browser" , path,NULL ); }#endif tools/perf/builtin-inject.c +1
-1@@ -18,7 +18,7 @@#include "util/data.h" #include "util/auxtrace.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include <linux/list.h> tools/perf/builtin-kmem.c +1
-1@@ -11,7 +11,7 @@#include "util/tool.h" #include "util/callchain.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/trace-event.h" #include "util/data.h" #include "util/cpumap.h" tools/perf/builtin-kvm.c +1
-1@@ -9,7 +9,7 @@#include "util/header.h" #include "util/session.h" #include "util/intlist.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/trace-event.h" #include "util/debug.h" #include "util/tool.h" tools/perf/builtin-list.c +1
-1@@ -14,7 +14,7 @@#include "util/parse-events.h" #include "util/util.h" #include "util/pmu.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> int cmd_list (int argc,const char **argv,const char *prefix__maybe_unused ) {tools/perf/builtin-lock.c +1
-1@@ -8,7 +8,7 @@#include "util/thread.h" #include "util/header.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/trace-event.h" #include "util/debug.h" tools/perf/builtin-mem.c +1
-1@@ -1,7 +1,7 @@#include "builtin.h" #include "perf.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/trace-event.h" #include "util/tool.h" #include "util/session.h" tools/perf/builtin-probe.c +1
-1@@ -37,7 +37,7 @@#include "util/strfilter.h" #include "util/symbol.h" #include "util/debug.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/probe-finder.h" #include "util/probe-event.h" #include "util/probe-file.h" tools/perf/builtin-record.c +1
-1@@ -11,7 +11,7 @@#include "util/build-id.h" #include "util/util.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-events.h" #include "util/callchain.h" tools/perf/builtin-report.c +1
-1@@ -26,7 +26,7 @@#include "util/session.h" #include "util/tool.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-events.h" #include "util/thread.h" tools/perf/builtin-sched.c +1
-1@@ -11,7 +11,7 @@#include "util/tool.h" #include "util/cloexec.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/trace-event.h" #include "util/debug.h" tools/perf/builtin-script.c +6
-6@@ -2,9 +2,9 @@#include "perf.h" #include "util/debug.h" -#include "util/exec_cmd.h" +#include <api/util/exec_cmd.h> #include "util/header.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/perf_regs.h" #include "util/session.h" #include "util/tool.h" @@ -1393,7 +1393,7 @@ static int list_available_scripts(const struct option *opt __maybe_unused,char first_half[BUFSIZ ];char *script_root; -snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,perf_exec_path ()); +snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,get_argv_exec_path ()); scripts_dir =opendir (scripts_path);if (!scripts_dir)@@ -1514,7 +1514,7 @@ int find_scripts(char **scripts_array, char **scripts_path_array)if (!session)return -1 ; -snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,perf_exec_path ()); +snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,get_argv_exec_path ()); scripts_dir =opendir (scripts_path);if (!scripts_dir) {@@ -1572,7 +1572,7 @@ static char *get_script_path(const char *script_root, const char *suffix)char lang_path[MAXPATHLEN ];char *__script_root; -snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,perf_exec_path ()); +snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,get_argv_exec_path ()); scripts_dir =opendir (scripts_path);if (!scripts_dir)@@ -1808,7 +1808,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) scripting_max_stack = itrace_synth_opts.callchain_sz;/* make sure PERF_EXEC_PATH is set for scripts */ -perf_set_argv_exec_path (perf_exec_path ()); +set_argv_exec_path (get_argv_exec_path ());if (argc && !script_name && !rec_script_path && !rep_script_path) {int live_pipe[2 ];tools/perf/builtin-stat.c +1
-1@@ -45,7 +45,7 @@#include "builtin.h" #include "util/cgroup.h" #include "util/util.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-events.h" #include "util/pmu.h" #include "util/event.h" tools/perf/builtin-timechart.c +1
-1@@ -29,7 +29,7 @@#include "perf.h" #include "util/header.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-events.h" #include "util/event.h" #include "util/session.h" tools/perf/builtin-top.c +1
-1@@ -33,7 +33,7 @@#include "util/top.h" #include "util/util.h" #include <linux/rbtree.h> -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-events.h" #include "util/cpumap.h" #include "util/xyarray.h" tools/perf/builtin-trace.c +2
-2@@ -22,11 +22,11 @@#include "util/color.h" #include "util/debug.h" #include "util/evlist.h" -#include "util/exec_cmd.h" +#include <api/util/exec_cmd.h> #include "util/machine.h" #include "util/session.h" #include "util/thread.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/strlist.h" #include "util/intlist.h" #include "util/thread_map.h" tools/perf/builtin.h +1
-1@@ -2,7 +2,7 @@#define BUILTIN_H #include "util/util.h" -#include "util/strbuf.h" +#include <api/util/strbuf.h> extern const char perf_usage_string[];extern const char perf_more_info_string[];tools/perf/perf.c +20
-7@@ -9,16 +9,17 @@#include "builtin.h" #include "util/env.h" -#include "util/exec_cmd.h" +#include <api/util/exec_cmd.h> #include "util/util.h" #include "util/quote.h" -#include "util/run-command.h" +#include <api/util/run-command.h> #include "util/parse-events.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/bpf-loader.h" #include "util/debug.h" #include <api/fs/tracing_path.h> #include <pthread.h> +#include <api/util/cfg.h> const char perf_usage_string[] ="perf [--version] [--help] [OPTIONS] COMMAND [ARGS]" ;@@ -119,7 +120,7 @@ static void commit_pager_choice(void) {switch (use_pager) {case 0 : -setenv ("PERF_PAGER" ,"cat" ,1 ); +setenv (PERF_PAGER_ENVIRONMENT ,"cat" ,1 );break ;case 1 :/* setup_pager(); */ @@ -129,6 +130,16 @@ static void commit_pager_choice(void) } } +static void setup_util (void ) +{ + util_cfg.prefix =PREFIX ; + util_cfg.exec_name ="perf" ; + util_cfg.exec_path =PERF_EXEC_PATH ; + util_cfg.exec_path_env =EXEC_PATH_ENVIRONMENT ; + util_cfg.pager_env =PERF_PAGER_ENVIRONMENT ; + util_cfg.exit_browser = exit_browser_no_wait; +} +struct option options[] = {OPT_ARGUMENT ("help" ,"help" ),OPT_ARGUMENT ("version" ,"version" ),@@ -183,9 +194,9 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)if (!prefixcmp (cmd,CMD_EXEC_PATH )) { cmd +=strlen (CMD_EXEC_PATH );if (*cmd =='=' ) -perf_set_argv_exec_path (cmd +1 ); +set_argv_exec_path (cmd +1 );else { -puts (perf_exec_path ()); +puts (get_argv_exec_path ());exit (0 ); } }else if (!strcmp (cmd,"--html-path" )) {@@ -530,11 +541,13 @@ int main(int argc, const char **argv)const char *cmd;char sbuf[STRERR_BUFSIZE ]; +setup_util (); +/* The page_size is placed in util object. */ page_size =sysconf (_SC_PAGE_SIZE); cacheline_size =sysconf (_SC_LEVEL1_DCACHE_LINESIZE); - cmd =perf_extract_argv0_path (argv[0 ]); + cmd =extract_argv0_path (argv[0 ]);if (!cmd) cmd ="perf-help" ;tools/perf/perf.h +1
-0@@ -17,6 +17,7 @@#define DEFAULT_PERF_DIR_ENVIRONMENT ".perf"#define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"#define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR" +#define PERF_PAGER_ENVIRONMENT "PERF_PAGER"extern bool test_attr__enabled;void test_attr__init (void );tools/perf/tests/attr.c +2
-2@@ -24,7 +24,7 @@#include <linux/kernel.h> #include "../perf.h" #include "util.h" -#include "exec_cmd.h" +#include <api/util/exec_cmd.h> #include "tests.h" #define ENV "PERF_TEST_ATTR"@@ -164,7 +164,7 @@ int test__attr(int subtest __maybe_unused)return run_dir ("./tests" ,"./perf" );/* Then installed path. */ -snprintf (path_dir,PATH_MAX ,"%s/tests" ,perf_exec_path ()); +snprintf (path_dir,PATH_MAX ,"%s/tests" ,get_argv_exec_path ());snprintf (path_perf,PATH_MAX ,"%s/perf" ,BINDIR ); if (!lstat(path_dir, &st) &&tools/perf/tests/builtin-test.c +1
-1@@ -11,7 +11,7 @@#include "tests.h" #include "debug.h" #include "color.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include "symbol.h" struct test __weak arch_tests[] = {tools/perf/ui/setup.c +5
-0@@ -105,3 +105,8 @@ void exit_browser(bool wait_for_ok)break ; } } + +void exit_browser_no_wait (void ) +{ +exit_browser (false); +}tools/perf/ui/ui.h +1
-0@@ -12,6 +12,7 @@ extern int use_browser;void setup_browser (bool fallback_to_pager);void exit_browser (bool wait_for_ok); +void exit_browser_no_wait (void );#ifdef HAVE_SLANG_SUPPORT int ui__init (void );tools/perf/util/Build +0
-13@@ -1,41 +1,30 @@ -libperf-y += abspath.o libperf-y += alias.o libperf-y += annotate.o libperf-y += build-id.o libperf-y += config.o -libperf-y += ctype.o libperf-y += db-export.o libperf-y += env.o libperf-y += event.o libperf-y += evlist.o libperf-y += evsel.o -libperf-y += exec_cmd.o libperf-y += find_next_bit.o -libperf-y += help.o libperf-y += kallsyms.o libperf-y += levenshtein.o libperf-y += llvm-utils.o -libperf-y += parse-options.o libperf-y += parse-events.o libperf-y += perf_regs.o libperf-y += path.o libperf-y += rbtree.o libperf-y += bitmap.o libperf-y += hweight.o -libperf-y += run-command.o libperf-y += quote.o -libperf-y += strbuf.o libperf-y += string.o libperf-y += strlist.o libperf-y += strfilter.o libperf-y += top.o -libperf-y += usage.o -libperf-y += wrapper.o -libperf-y += sigchain.o libperf-y += dso.o libperf-y += symbol.o libperf-y += color.o -libperf-y += pager.o libperf-y += header.o libperf-y += callchain.o libperf-y += values.o@@ -85,7 +74,6 @@ libperf-$(CONFIG_AUXTRACE) += intel-pt.o libperf-$(CONFIG_AUXTRACE) += intel-bts.o libperf-y += parse-branch-options.o libperf-y += parse-regs-options.o -libperf-y += term.o libperf-y += help-unknown-cmd.o libperf-$(CONFIG_LIBBPF) += bpf-loader.o@@ -112,7 +100,6 @@ libperf-$(CONFIG_ZLIB) += zlib.o libperf-$(CONFIG_LZMA) += lzma.o CFLAGS_config.o += -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" -CFLAGS_exec_cmd.o += -DPERF_EXEC_PATH="BUILD_STR($(perfexecdir_SQ))" -DPREFIX="BUILD_STR($(prefix_SQ))" $(OUTPUT)util/parse-events-flex.c: util/parse-events.l $(OUTPUT)util/parse-events-bison.c $(call rule_mkdir)tools/perf/util/auxtrace.c +1
-1@@ -45,7 +45,7 @@#include "event.h" #include "session.h" #include "debug.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include "intel-pt.h" #include "intel-bts.h" tools/perf/util/cgroup.c +1
-1@@ -1,6 +1,6 @@#include "util.h" #include "../perf.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include "evsel.h" #include "cgroup.h" #include "evlist.h" tools/perf/util/config.c +1
-1@@ -9,7 +9,7 @@* */ #include "util.h" -#include "exec_cmd.h" +#include <api/util/exec_cmd.h> #include "util/hist.h" /* perf_hist_config */ #include "util/llvm-utils.h" /* perf_llvm_config */ tools/perf/util/evlist.c +1
-1@@ -18,7 +18,7 @@#include <unistd.h> #include "parse-events.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include <sys/mman.h> tools/perf/util/header.c +1
-1@@ -20,7 +20,7 @@#include "cpumap.h" #include "pmu.h" #include "vdso.h" -#include "strbuf.h" +#include <api/util/strbuf.h> #include "build-id.h" #include "data.h" tools/perf/util/help-unknown-cmd.c +1
-1@@ -1,5 +1,5 @@#include "util.h" -#include "help.h" +#include <api/util/help.h> #include "../builtin.h" #include "levenshtein.h" tools/perf/util/parse-branch-options.c +1
-1@@ -1,7 +1,7 @@#include "perf.h" #include "util/util.h" #include "util/debug.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-branch-options.h" #define BRANCH_OPT (n, m) \tools/perf/util/parse-events.c +2
-2@@ -4,9 +4,9 @@#include "../perf.h" #include "evlist.h" #include "evsel.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include "parse-events.h" -#include "exec_cmd.h" +#include <api/util/exec_cmd.h> #include "string.h" #include "symbol.h" #include "header.h" tools/perf/util/parse-regs-options.c +1
-1@@ -1,7 +1,7 @@#include "perf.h" #include "util/util.h" #include "util/debug.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-regs-options.h" int tools/perf/util/python-ext-sources +0
-1@@ -6,7 +6,6 @@ # util/python.c -util/ctype.c util/evlist.c util/evsel.c util/cpumap.ctools/perf/util/sort.h +1
-1@@ -17,7 +17,7 @@#include "debug.h" #include "header.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include "parse-events.h" #include "hist.h" #include "thread.h" tools/perf/util/util.h +11
-8@@ -1,24 +1,27 @@#ifndef __PERF_UTIL_H#define __PERF_UTIL_H -#include "compat-util.h" +#include <api/util/compat-util.h> +#include <api/fs/tracing_path.h> #include <api/string/string.h> +#include <api/util/abspath.h> +#include <api/util/ctype.h> +#include <api/util/help.h> +#include <api/util/pager.h> +#include <api/util/strbuf.h> +#include <api/util/term.h> +#include <api/util/usage.h> +#include <api/util/wrapper.h> +#include "../perf.h" -#include "abspath.h" #include "alias.h" #include "config.h" -#include "ctype.h" #include "lzma.h" -#include "pager.h" #include "path.h" #include "srcline.h" -#include "strbuf.h" #include "string.h" -#include "term.h" #include "../ui/ui.h" -#include "usage.h" -#include "wrapper.h" #include "zlib.h" int parse_nsec_time (const char *str,u64 *ptime);Signature · 1 line
2.4.3
Signature · 1 line
Josh
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v2 14/14] perf tools: Move subcommand framework and related utils to libapi
Em Tue, Dec 08, 2015 at 12:49:53PM -0600, Josh Poimboeuf escreveu:
Quoted 8 lines · Jiri Olsa
Quoted 7 lines · Josh Poimboeuf
Quoted 6 lines
The perf subcommand framework is needed for other tools. Move
parse-options.cand its dependencies over to libapi.Any function names with 'perf' have been renamed to something more generic.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Also created a
util_cfgstruct for passing perf-specific configuration to the library. Specifying the configuration at runtime allows the same binary to be shared by multiple tools without having to recompile it.this patch is too big.. IMO it needs to be split into 3 parts as described in above 3 paragraphs
Ok, will do.
Also please rename this util_cfg struct to something more expressive, breaking down the patch may help in finding a better name, I guess.
- Arnaldo
Quoted 1,832 lines
Quoted 1,829 lines
thanks,
jirkaQuoted 1,825 lines
Signed-off-by Josh Poimboeuf <[email protected]>--- tools/include/asm-generic/bitops/__fls.h | 2 +- tools/include/asm-generic/bitops/fls.h | 2 +- tools/include/asm-generic/bitops/fls64.h | 2 +- tools/lib/api/Build | 1 + tools/lib/api/Makefile | 6 +++- tools/lib/api/util/Build | 13 +++++++++ tools/{perf => lib/api}/util/abspath.c | 6 +++- tools/{perf => lib/api}/util/abspath.h | 6 ++-- tools/lib/api/util/cfg.c | 12 ++++++++ tools/lib/api/util/cfg.h | 15 ++++++++++ tools/{perf => lib/api}/util/compat-util.h | 7 ++--- tools/{perf => lib/api}/util/ctype.c | 3 +- tools/{perf => lib/api}/util/ctype.h | 6 ++-- tools/{perf => lib/api}/util/exec_cmd.c | 42 ++++++++++++++-------------- tools/{perf => lib/api}/util/exec_cmd.h | 18 ++++++------ tools/{perf => lib/api}/util/help.c | 11 +++++--- tools/{perf => lib/api}/util/help.h | 0 tools/{perf => lib/api}/util/pager.c | 6 ++-- tools/{perf => lib/api}/util/pager.h | 6 ++-- tools/{perf => lib/api}/util/parse-options.c | 21 ++++++++++---- tools/{perf => lib/api}/util/parse-options.h | 10 +++---- tools/{perf => lib/api}/util/run-command.c | 12 ++++---- tools/{perf => lib/api}/util/run-command.h | 10 +++---- tools/{perf => lib/api}/util/sigchain.c | 4 ++- tools/{perf => lib/api}/util/sigchain.h | 6 ++-- tools/{perf => lib/api}/util/strbuf.c | 6 +++- tools/{perf => lib/api}/util/strbuf.h | 6 ++-- tools/{perf => lib/api}/util/term.c | 3 +- tools/{perf => lib/api}/util/term.h | 0 tools/{perf => lib/api}/util/usage.c | 4 +-- tools/{perf => lib/api}/util/usage.h | 8 +++--- tools/{perf => lib/api}/util/wrapper.c | 4 ++- tools/{perf => lib/api}/util/wrapper.h | 6 ++-- tools/perf/Build | 2 +- tools/perf/arch/x86/util/intel-pt.c | 2 +- tools/perf/bench/futex-hash.c | 2 +- tools/perf/bench/futex-lock-pi.c | 2 +- tools/perf/bench/futex-requeue.c | 2 +- tools/perf/bench/futex-wake-parallel.c | 2 +- tools/perf/bench/futex-wake.c | 2 +- tools/perf/bench/mem-functions.c | 2 +- tools/perf/bench/numa.c | 2 +- tools/perf/bench/sched-messaging.c | 2 +- tools/perf/bench/sched-pipe.c | 2 +- tools/perf/builtin-annotate.c | 2 +- tools/perf/builtin-bench.c | 2 +- tools/perf/builtin-buildid-cache.c | 2 +- tools/perf/builtin-buildid-list.c | 2 +- tools/perf/builtin-config.c | 2 +- tools/perf/builtin-data.c | 2 +- tools/perf/builtin-evlist.c | 2 +- tools/perf/builtin-help.c | 9 +++--- tools/perf/builtin-inject.c | 2 +- tools/perf/builtin-kmem.c | 2 +- tools/perf/builtin-kvm.c | 2 +- tools/perf/builtin-list.c | 2 +- tools/perf/builtin-lock.c | 2 +- tools/perf/builtin-mem.c | 2 +- tools/perf/builtin-probe.c | 2 +- tools/perf/builtin-record.c | 2 +- tools/perf/builtin-report.c | 2 +- tools/perf/builtin-sched.c | 2 +- tools/perf/builtin-script.c | 12 ++++---- tools/perf/builtin-stat.c | 2 +- tools/perf/builtin-timechart.c | 2 +- tools/perf/builtin-top.c | 2 +- tools/perf/builtin-trace.c | 4 +-- tools/perf/builtin.h | 2 +- tools/perf/perf.c | 27 +++++++++++++----- tools/perf/perf.h | 1 + tools/perf/tests/attr.c | 4 +-- tools/perf/tests/builtin-test.c | 2 +- tools/perf/ui/setup.c | 5 ++++ tools/perf/ui/ui.h | 1 + tools/perf/util/Build | 13 --------- tools/perf/util/auxtrace.c | 2 +- tools/perf/util/cgroup.c | 2 +- tools/perf/util/config.c | 2 +- tools/perf/util/evlist.c | 2 +- tools/perf/util/header.c | 2 +- tools/perf/util/help-unknown-cmd.c | 2 +- tools/perf/util/parse-branch-options.c | 2 +- tools/perf/util/parse-events.c | 4 +-- tools/perf/util/parse-regs-options.c | 2 +- tools/perf/util/python-ext-sources | 1 - tools/perf/util/sort.h | 2 +- tools/perf/util/util.h | 19 +++++++------ 87 files changed, 265 insertions(+), 183 deletions(-) create mode 100644 tools/lib/api/util/Build rename tools/{perf => lib/api}/util/abspath.c (90%) rename tools/{perf => lib/api}/util/abspath.h (59%) create mode 100644 tools/lib/api/util/cfg.c create mode 100644 tools/lib/api/util/cfg.h rename tools/{perf => lib/api}/util/compat-util.h (95%) rename tools/{perf => lib/api}/util/ctype.c (97%) rename tools/{perf => lib/api}/util/ctype.h (93%) rename tools/{perf => lib/api}/util/exec_cmd.c (72%) rename tools/{perf => lib/api}/util/exec_cmd.h (14%) rename tools/{perf => lib/api}/util/help.c (96%) rename tools/{perf => lib/api}/util/help.h (100%) rename tools/{perf => lib/api}/util/pager.c (93%) rename tools/{perf => lib/api}/util/pager.h (42%) rename tools/{perf => lib/api}/util/parse-options.c (98%) rename tools/{perf => lib/api}/util/parse-options.h (98%) rename tools/{perf => lib/api}/util/run-command.c (96%) rename tools/{perf => lib/api}/util/run-command.h (87%) rename tools/{perf => lib/api}/util/sigchain.c (93%) rename tools/{perf => lib/api}/util/sigchain.h (53%) rename tools/{perf => lib/api}/util/strbuf.c (97%) rename tools/{perf => lib/api}/util/strbuf.h (97%) rename tools/{perf => lib/api}/util/term.c (93%) rename tools/{perf => lib/api}/util/term.h (100%) rename tools/{perf => lib/api}/util/usage.c (97%) rename tools/{perf => lib/api}/util/usage.h (84%) rename tools/{perf => lib/api}/util/wrapper.c (92%) rename tools/{perf => lib/api}/util/wrapper.h (89%)tools/include/asm-generic/bitops/__fls.h +1
-1@@ -1 +1 @@ -#include <../../../../include/asm-generic/bitops/__fls.h> +#include "../../../../include/asm-generic/bitops/__fls.h" tools/include/asm-generic/bitops/fls.h +1
-1@@ -1 +1 @@ -#include <../../../../include/asm-generic/bitops/fls.h> +#include "../../../../include/asm-generic/bitops/fls.h" tools/include/asm-generic/bitops/fls64.h +1
-1@@ -1 +1 @@ -#include <../../../../include/asm-generic/bitops/fls64.h> +#include "../../../../include/asm-generic/bitops/fls64.h" tools/lib/api/Build +1
-0@@ -2,3 +2,4 @@ libapi-y += fd/ libapi-y += fs/ libapi-y += cpu.o libapi-y += string/ +libapi-y += util/tools/lib/api/Makefile +5
-1@@ -17,7 +17,11 @@ LIBFILE = $(OUTPUT)libapi.a CFLAGS := $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) CFLAGS += -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fPIC -CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 +CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE + +CFLAGS += -I$(srctree)/tools/include/ +CFLAGS += -I$(srctree)/include/uapi +CFLAGS += -I$(srctree)/include RM = rm -ftools/lib/api/util/Build new file +13
-0@@ -0,0 +1,13 @@ +libapi-y += abspath.o +libapi-y += cfg.o +libapi-y += ctype.o +libapi-y += exec_cmd.o +libapi-y += help.o +libapi-y += pager.o +libapi-y += parse-options.o +libapi-y += run-command.o +libapi-y += sigchain.o +libapi-y += strbuf.o +libapi-y += term.o +libapi-y += usage.o +libapi-y += wrapper.otools/lib/api/util/abspath.c renamed from tools/perf/util/abspath.c +5
-1@@ -1,4 +1,8 @@ -#include "util.h" +#include "compat-util.h" + +#include "../string/string.h" +#include "abspath.h" +#include "usage.h" static const char *get_pwd_cwd (void ) {tools/lib/api/util/abspath.h renamed from tools/perf/util/abspath.h +3
-3@@ -1,5 +1,5 @@ -#ifndef __PERF_ABSPATH_H -#define __PERF_ABSPATH_H +#ifndef __API_UTIL_ABSPATH_H +#define __API_UTIL_ABSPATH_Hstatic inline int is_absolute_path (const char *path) {@@ -8,4 +8,4 @@ static inline int is_absolute_path(const char *path)const char *make_nonrelative_path (const char *path); -#endif /* __PERF_ABSPATH_H */ +#endif /* __API_UTIL_ABSPATH_H */ tools/lib/api/util/cfg.c new file +12
-0@@ -0,0 +1,12 @@ +#include "compat-util.h" +#include "cfg.h" + +#define UNDEFINED "UNDEFINED" + +struct util_cfg util_cfg = { + .prefix =UNDEFINED , + .exec_name =UNDEFINED , + .exec_path =UNDEFINED , + .exec_path_env =UNDEFINED , + .pager_env =UNDEFINED , +};tools/lib/api/util/cfg.h new file +15
-0@@ -0,0 +1,15 @@ +#ifndef __API_UTIL_CONFIG_H +#define __API_UTIL_CONFIG_H + +struct util_cfg { +const char *prefix; +const char *exec_name; +const char *exec_path; +const char *exec_path_env; +const char *pager_env; +void (*exit_browser)(void ); +}; + +extern struct util_cfg util_cfg; + +#endif /* #define __API_UTIL_CONFIG_H */ tools/lib/api/util/compat-util.h renamed from tools/perf/util/compat-util.h +3
-4@@ -1,5 +1,5 @@ -#ifndef __PERF_COMPAT_UTIL_H -#define __PERF_COMPAT_UTIL_H +#ifndef __API_UTIL_COMPAT_UTIL_H +#define __API_UTIL_COMPAT_UTIL_H#ifndef FLEX_ARRAY /* @@ -74,7 +74,6 @@#include <linux/magic.h> #include <linux/types.h> #include <sys/ttydefaults.h> -#include <api/fs/tracing_path.h> #include <termios.h> #include <linux/bitops.h> #include <termios.h> @@ -127,4 +126,4 @@#define NSEC_PER_MSEC 1000000L#endif -#endif /* __PERF_COMPAT_UTIL_H */ +#endif /* __API_UTIL_COMPAT_UTIL_H */ tools/lib/api/util/ctype.c renamed from tools/perf/util/ctype.c +2
-1@@ -3,7 +3,8 @@* * No surprises, and works with signed and unsigned chars. */ -#include "util.h" +#include "compat-util.h" +#include "ctype.h" enum {S =GIT_SPACE ,tools/lib/api/util/ctype.h renamed from tools/perf/util/ctype.h +3
-3@@ -1,5 +1,5 @@ -#ifndef __PERF_CTYPE_H -#define __PERF_CTYPE_H +#ifndef __API_UTIL_CTYPE_H +#define __API_UTIL_CTYPE_H/* Sane ctype - no locale, and works with signed chars */ #undef isascii@@ -49,4 +49,4 @@ static inline int sane_case(int x, int high) return x; } -#endif /* __PERF_CTYPE_H */ +#endif /* __API_UTIL_CTYPE_H */ tools/lib/api/util/exec_cmd.c renamed from tools/perf/util/exec_cmd.c +21
-21@@ -1,8 +1,9 @@ -#include "util.h" +#include "compat-util.h" #include "exec_cmd.h" -#include "quote.h" - -#include <string.h> +#include "strbuf.h" +#include "abspath.h" +#include "usage.h" +#include "cfg.h" #define MAX_ARGS 32@@ -11,18 +12,17 @@ static const char *argv0_path;char *system_path (const char *path) { -static const char *prefix =PREFIX ;struct strbuf d =STRBUF_INIT ;if (is_absolute_path (path))return strdup (path); -strbuf_addf (&d,"%s/%s" , prefix, path); +strbuf_addf (&d,"%s/%s" , util_cfg.prefix, path); path =strbuf_detach (&d,NULL );return (char *)path; } -const char *perf_extract_argv0_path (const char *argv0) +const char *extract_argv0_path (const char *argv0) {const char *slash;@@ -41,29 +41,29 @@ const char *perf_extract_argv0_path(const char *argv0)return argv0; } -void perf_set_argv_exec_path (const char *exec_path) +void set_argv_exec_path (const char *exec_path) { argv_exec_path = exec_path;/* * Propagate this setting to external programs. */ -setenv (EXEC_PATH_ENVIRONMENT , exec_path,1 ); +setenv (util_cfg.exec_path_env, exec_path,1 ); } -/* Returns the highest-priority, location to look for perf programs. */ -char *perf_exec_path (void ) +/* Returns the highest-priority location to look for subprograms. */ +char *get_argv_exec_path (void ) {char *env;if (argv_exec_path)return strdup (argv_exec_path); - env =getenv (EXEC_PATH_ENVIRONMENT ); + env =getenv (util_cfg.exec_path_env);if (env && *env)return strdup (env); -return system_path (PERF_EXEC_PATH ); +return system_path (util_cfg.exec_path); }static void add_path (struct strbuf *out,const char *path)@@ -82,7 +82,7 @@ void setup_path(void) {const char *old_path =getenv ("PATH" );struct strbuf new_path =STRBUF_INIT ; -char *tmp =perf_exec_path (); +char *tmp =get_argv_exec_path ();add_path (&new_path, tmp);add_path (&new_path, argv0_path);@@ -98,7 +98,7 @@ void setup_path(void)strbuf_release (&new_path); } -static const char **prepare_perf_cmd (const char **argv) +static const char **prepare_exec_cmd (const char **argv) {int argc;const char **nargv;@@ -107,25 +107,25 @@ static const char **prepare_perf_cmd(const char **argv) ;/* just counting */ nargv =malloc (sizeof (*nargv) * (argc +2 )); - nargv[0 ] ="perf" ; + nargv[0 ] = util_cfg.exec_name;for (argc =0 ; argv[argc]; argc++) nargv[argc +1 ] = argv[argc]; nargv[argc +1 ] =NULL ;return nargv; } -int execv_perf_cmd (const char **argv) { -const char **nargv =prepare_perf_cmd (argv); +int execv_cmd (const char **argv) { +const char **nargv =prepare_exec_cmd (argv);/* execvp() can only ever return if it fails */ -execvp ("perf" , (char **)nargv); +execvp (util_cfg.exec_name, (char **)nargv);free (nargv);return -1 ; } -int execl_perf_cmd (const char *cmd,...) +int execl_cmd (const char *cmd,...) {int argc;const char *argv[MAX_ARGS +1 ];@@ -145,5 +145,5 @@ int execl_perf_cmd(const char *cmd,...)return error ("too many args to run %s" , cmd); argv[argc] =NULL ; -return execv_perf_cmd (argv); +return execv_cmd (argv); }tools/lib/api/util/exec_cmd.h renamed from tools/perf/util/exec_cmd.h +9
-9@@ -1,13 +1,13 @@ -#ifndef __PERF_EXEC_CMD_H -#define __PERF_EXEC_CMD_H +#ifndef __API_UTIL_EXEC_CMD_H +#define __API_UTIL_EXEC_CMD_H -extern void perf_set_argv_exec_path (const char *exec_path); -extern const char *perf_extract_argv0_path (const char *path); +extern void set_argv_exec_path (const char *exec_path); +extern const char *extract_argv0_path (const char *path);extern void setup_path (void ); -extern int execv_perf_cmd (const char **argv);/* NULL terminated */ -extern int execl_perf_cmd (const char *cmd, ...); -/* perf_exec_path and system_path return malloc'd string, caller must free it */ -extern char *perf_exec_path (void ); +extern int execv_cmd (const char **argv);/* NULL terminated */ +extern int execl_cmd (const char *cmd, ...); +/* get_argv_exec_path and system_path return malloc'd string, caller must free it */ +extern char *get_argv_exec_path (void );extern char *system_path (const char *path); -#endif /* __PERF_EXEC_CMD_H */ +#endif /* __API_UTIL_EXEC_CMD_H */ tools/lib/api/util/help.c renamed from tools/perf/util/help.c +7
-4@@ -1,6 +1,9 @@ -#include "util.h" -#include "exec_cmd.h" +#include "compat-util.h" #include "help.h" +#include "exec_cmd.h" +#include "strbuf.h" +#include "wrapper.h" +#include "term.h" void add_cmdname (struct cmdnames *cmds,const char *name,size_t len) {@@ -164,7 +167,7 @@ void load_command_list(const char *prefix, struct cmdnames *other_cmds) {const char *env_path =getenv ("PATH" ); -char *exec_path =perf_exec_path (); +char *exec_path =get_argv_exec_path ();if (exec_path) {list_commands_in_dir (main_cmds, exec_path, prefix);@@ -209,7 +212,7 @@ void list_commands(const char *title, struct cmdnames *main_cmds, longest = other_cmds->names[i]->len;if (main_cmds->cnt) { -char *exec_path =perf_exec_path (); +char *exec_path =get_argv_exec_path ();printf ("available %s in '%s'\n" , title, exec_path);printf ("----------------" );mput_char ('-' ,strlen (title) +strlen (exec_path));tools/lib/api/util/help.h renamed from tools/perf/util/help.h +0
-0tools/lib/api/util/pager.c renamed from tools/perf/util/pager.c +4
-2@@ -1,6 +1,8 @@ -#include "util.h" +#include "compat-util.h" +#include "pager.h" #include "run-command.h" #include "sigchain.h" +#include "cfg.h" /* * This is split up from the rest of git so that we can do @@ -46,7 +48,7 @@ static void wait_for_pager_signal(int signo)void setup_pager (void ) { -const char *pager =getenv ("PERF_PAGER" ); +const char *pager =getenv (util_cfg.pager_env);if (!isatty (1 ))return ;tools/lib/api/util/pager.h renamed from tools/perf/util/pager.h +3
-3@@ -1,7 +1,7 @@ -#ifndef __PERF_PAGER_H -#define __PERF_PAGER_H +#ifndef __API_UTIL_PAGER_H +#define __API_UTIL_PAGER_Hextern void setup_pager (void );extern int pager_in_use (void ); -#endif /* __PERF_PAGER_H */ +#endif /* __API_UTIL_PAGER_H */ tools/lib/api/util/parse-options.c renamed from tools/perf/util/parse-options.c +15
-6@@ -1,7 +1,12 @@ -#include "util.h" +#include "compat-util.h" + +#include "../string/string.h" #include "parse-options.h" -#include "header.h" -#include <api/string/string.h> +#include "strbuf.h" +#include "usage.h" +#include "ctype.h" +#include "pager.h" +#include "cfg.h" #define OPT_SHORT 1#define OPT_UNSET 2@@ -510,7 +515,8 @@ int parse_options_subcommand(int argc, const char **argv, const struct option *oif (subcommands && !usagestr[0 ]) {struct strbuf buf =STRBUF_INIT ; -strbuf_addf (&buf,"perf %s [<options>] {" , argv[0 ]); +strbuf_addf (&buf,"%s %s [<options>] {" , + util_cfg.exec_name, argv[0 ]);for (int i =0 ; subcommands[i]; i++) {if (i)strbuf_addstr (&buf,"|" );@@ -771,7 +777,9 @@ int usage_with_options_internal(const char * const *usagestr,void usage_with_options (const char *const *usagestr,const struct option *opts) { -exit_browser (false); +if (util_cfg.exit_browser) + util_cfg.exit_browser (); +usage_with_options_internal (usagestr, opts,0 ,NULL );exit (129 ); }@@ -781,7 +789,8 @@ void usage_with_options_msg(const char * const *usagestr, {va_list ap; -exit_browser (false); +if (util_cfg.exit_browser) + util_cfg.exit_browser ();va_start (ap, fmt);strbuf_addv (&error_buf, fmt, ap);tools/lib/api/util/parse-options.h renamed from tools/perf/util/parse-options.h +5
-5@@ -1,8 +1,7 @@ -#ifndef __PERF_PARSE_OPTIONS_H -#define __PERF_PARSE_OPTIONS_H +#ifndef __API_UTIL_PARSE_OPTIONS_H +#define __API_UTIL_PARSE_OPTIONS_H -#include <linux/kernel.h> -#include <stdbool.h> +#include "compat-util.h" enum parse_opt_type {/* special types */ @@ -226,4 +225,5 @@ extern int parse_opt_verbosity_cb(const struct option *, const char *, int);extern const char *parse_options_fix_filename (const char *prefix,const char *file);void set_option_flag (struct option *opts,int sopt,const char *lopt,int flag); -#endif /* __PERF_PARSE_OPTIONS_H */ + +#endif /* __API_UTIL_PARSE_OPTIONS_H */ tools/lib/api/util/run-command.c renamed from tools/perf/util/run-command.c +7
-5@@ -1,7 +1,9 @@ -#include "util.h" +#include "compat-util.h" #include "run-command.h" #include "exec_cmd.h" -#include "debug.h" +#include "usage.h" + +#define STRERR_BUFSIZE 128static inline void close_pair (int fd[2 ]) {@@ -112,8 +114,8 @@ int start_command(struct child_process *cmd) }if (cmd->preexec_cb) cmd->preexec_cb (); -if (cmd->perf_cmd) { -execv_perf_cmd (cmd->argv); +if (cmd->exec_cmd) { +execv_cmd (cmd->argv); }else {execvp (cmd->argv[0 ], (char *const *) cmd->argv); }@@ -207,7 +209,7 @@ static void prepare_run_command_v_opt(struct child_process *cmd,memset (cmd,0 ,sizeof (*cmd)); cmd->argv = argv; cmd->no_stdin = opt &RUN_COMMAND_NO_STDIN ?1 :0 ; - cmd->perf_cmd = opt &RUN_PERF_CMD ?1 :0 ; + cmd->exec_cmd = opt &RUN_EXEC_CMD ?1 :0 ; cmd->stdout_to_stderr = opt &RUN_COMMAND_STDOUT_TO_STDERR ?1 :0 ; }tools/lib/api/util/run-command.h renamed from tools/perf/util/run-command.h +5
-5@@ -1,5 +1,5 @@ -#ifndef __PERF_RUN_COMMAND_H -#define __PERF_RUN_COMMAND_H +#ifndef __API_UTIL_RUN_COMMAND_H +#define __API_UTIL_RUN_COMMAND_Henum { ERR_RUN_COMMAND_FORK = 10000,@@ -41,7 +41,7 @@ struct child_process { unsigned no_stdin:1; unsigned no_stdout:1; unsigned no_stderr:1; - unsigned perf_cmd:1; /* if this is to be perf sub-command */ + unsigned exec_cmd:1; /* if this is to be external sub-command */ unsigned stdout_to_stderr:1;void (*preexec_cb)(void ); };@@ -51,8 +51,8 @@ int finish_command(struct child_process *);int run_command (struct child_process *);#define RUN_COMMAND_NO_STDIN 1 -#define RUN_PERF_CMD 2/*If this is to be perf sub-command */ +#define RUN_EXEC_CMD 2/*If this is to be external sub-command */ #define RUN_COMMAND_STDOUT_TO_STDERR 4int run_command_v_opt (const char **argv,int opt); -#endif /* __PERF_RUN_COMMAND_H */ +#endif /* __API_UTIL_RUN_COMMAND_H */ tools/lib/api/util/sigchain.c renamed from tools/perf/util/sigchain.c +3
-1@@ -1,5 +1,7 @@ -#include "util.h" +#include "compat-util.h" #include "sigchain.h" +#include "usage.h" +#include "wrapper.h" #define SIGCHAIN_MAX_SIGNALS 32tools/lib/api/util/sigchain.h renamed from tools/perf/util/sigchain.h +3
-3@@ -1,5 +1,5 @@ -#ifndef __PERF_SIGCHAIN_H -#define __PERF_SIGCHAIN_H +#ifndef __API_UTIL_SIGCHAIN_H +#define __API_UTIL_SIGCHAIN_Htypedef void (*sigchain_fun )(int );@@ -7,4 +7,4 @@ int sigchain_pop(int sig);void sigchain_push_common (sigchain_fun f); -#endif /* __PERF_SIGCHAIN_H */ +#endif /* __API_UTIL_SIGCHAIN_H */ tools/lib/api/util/strbuf.c renamed from tools/perf/util/strbuf.c +5
-1@@ -1,5 +1,9 @@ -#include "util.h" +#include "compat-util.h" +#include <linux/kernel.h> +#include "strbuf.h" +#include "wrapper.h" +#include "usage.h" int prefixcmp (const char *str,const char *prefix) {tools/lib/api/util/strbuf.h renamed from tools/perf/util/strbuf.h +3
-3@@ -1,5 +1,5 @@ -#ifndef __PERF_STRBUF_H -#define __PERF_STRBUF_H +#ifndef __API_UTIL_STRBUF_H +#define __API_UTIL_STRBUF_H/* * Strbuf's can be use in many ways: as a byte array, or to store arbitrary @@ -93,4 +93,4 @@ extern void strbuf_addv(struct strbuf *sb, const char *fmt, va_list ap);/* XXX: if read fails, any partial read is undone */ extern ssize_t strbuf_read (struct strbuf *,int fd,ssize_t hint); -#endif /* __PERF_STRBUF_H */ +#endif /* __API_UTIL_STRBUF_H */ tools/lib/api/util/term.c renamed from tools/perf/util/term.c +2
-1@@ -1,4 +1,5 @@ -#include "util.h" +#include "compat-util.h" +#include "term.h" void get_term_dimensions (struct winsize *ws) {tools/lib/api/util/term.h renamed from tools/perf/util/term.h +0
-0tools/lib/api/util/usage.c renamed from tools/perf/util/usage.c +2
-2@@ -6,8 +6,8 @@* * Copyright (C) Linus Torvalds, 2005 */ -#include "util.h" -#include "debug.h" +#include "compat-util.h" +#include "usage.h" static void report (const char *prefix,const char *err,va_list params) {tools/lib/api/util/usage.h renamed from tools/perf/util/usage.h +4
-4@@ -1,5 +1,5 @@ -#ifndef __PERF_USAGE_H -#define __PERF_USAGE_H +#ifndef __API_UTIL_USAGE_H +#define __API_UTIL_USAGE_H#include "compat-util.h" @@ -8,7 +8,7 @@ extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1,extern int error (const char *err, ...) __attribute__((format (printf,1 ,2 )));extern void warning (const char *err, ...) __attribute__((format (printf,1 ,2 ))); -#include "../../../include/linux/stringify.h" +#include <linux/stringify.h> #define DIE_IF (cnd) \ do { if (cnd) \@@ -20,4 +20,4 @@ extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)))extern void set_die_routine (void (*routine)(const char *err,va_list params)NORETURN );extern void set_warning_routine (void (*routine)(const char *err,va_list params)); -#endif /* __PERF_USAGE_H */ +#endif /* __API_UTIL_USAGE_H */ tools/lib/api/util/wrapper.c renamed from tools/perf/util/wrapper.c +3
-1@@ -1,7 +1,9 @@/* * Various trivial helper wrappers around standard functions */ -#include "util.h" +#include "compat-util.h" +#include "wrapper.h" +#include "usage.h" /* * There's no pack memory to release - but stay close to the Git tools/lib/api/util/wrapper.h renamed from tools/perf/util/wrapper.h +3
-3@@ -1,5 +1,5 @@ -#ifndef __PERF_WRAPPER_H -#define __PERF_WRAPPER_H +#ifndef __API_UTIL_WRAPPER_H +#define __API_UTIL_WRAPPER_Hextern char *xstrdup (const char *str);extern void *xrealloc (void *ptr,size_t size) __attribute__((weak));@@ -31,4 +31,4 @@ static inline void *zalloc(size_t size) } \ }while (0 ) -#endif /* __PERF_WRAPPER_H */ +#endif /* __API_UTIL_WRAPPER_H */tools/perf/Build +1
-1@@ -36,7 +36,7 @@ paths += -DPERF_MAN_PATH="BUILD_STR($(mandir_SQ))" CFLAGS_builtin-help.o += $(paths) CFLAGS_builtin-timechart.o += $(paths) -CFLAGS_perf.o += -DPERF_HTML_PATH="BUILD_STR($(htmldir_SQ))" -include $(OUTPUT)PERF-VERSION-FILE +CFLAGS_perf.o += -DPERF_HTML_PATH="BUILD_STR($(htmldir_SQ))" -DPERF_EXEC_PATH="BUILD_STR($(perfexecdir_SQ))" -DPREFIX="BUILD_STR($(prefix_SQ))" -include $(OUTPUT)PERF-VERSION-FILE CFLAGS_builtin-trace.o += -DSTRACE_GROUPS_DIR="BUILD_STR($(STRACE_GROUPS_DIR_SQ))" libperf-y += util/tools/perf/arch/x86/util/intel-pt.c +1
-1@@ -26,7 +26,7 @@#include "../../util/evlist.h" #include "../../util/evsel.h" #include "../../util/cpumap.h" -#include "../../util/parse-options.h" +#include <api/util/parse-options.h> #include "../../util/parse-events.h" #include "../../util/pmu.h" #include "../../util/debug.h" tools/perf/bench/futex-hash.c +1
-1@@ -11,7 +11,7 @@#include "../perf.h" #include "../util/util.h" #include "../util/stat.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/header.h" #include "bench.h" #include "futex.h" tools/perf/bench/futex-lock-pi.c +1
-1@@ -5,7 +5,7 @@#include "../perf.h" #include "../util/util.h" #include "../util/stat.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/header.h" #include "bench.h" #include "futex.h" tools/perf/bench/futex-requeue.c +1
-1@@ -11,7 +11,7 @@#include "../perf.h" #include "../util/util.h" #include "../util/stat.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/header.h" #include "bench.h" #include "futex.h" tools/perf/bench/futex-wake-parallel.c +1
-1@@ -10,7 +10,7 @@#include "../perf.h" #include "../util/util.h" #include "../util/stat.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/header.h" #include "bench.h" #include "futex.h" tools/perf/bench/futex-wake.c +1
-1@@ -11,7 +11,7 @@#include "../perf.h" #include "../util/util.h" #include "../util/stat.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/header.h" #include "bench.h" #include "futex.h" tools/perf/bench/mem-functions.c +1
-1@@ -8,7 +8,7 @@#include "../perf.h" #include "../util/util.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/header.h" #include "../util/cloexec.h" #include "bench.h" tools/perf/bench/numa.c +1
-1@@ -7,7 +7,7 @@#include "../perf.h" #include "../builtin.h" #include "../util/util.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/cloexec.h" #include "bench.h" tools/perf/bench/sched-messaging.c +1
-1@@ -11,7 +11,7 @@#include "../perf.h" #include "../util/util.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../builtin.h" #include "bench.h" tools/perf/bench/sched-pipe.c +1
-1@@ -10,7 +10,7 @@*/ #include "../perf.h" #include "../util/util.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../builtin.h" #include "bench.h" tools/perf/builtin-annotate.c +1
-1@@ -20,7 +20,7 @@#include "util/evsel.h" #include "util/annotate.h" #include "util/event.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-events.h" #include "util/thread.h" #include "util/sort.h" tools/perf/builtin-bench.c +1
-1@@ -16,7 +16,7 @@*/ #include "perf.h" #include "util/util.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "builtin.h" #include "bench/bench.h" tools/perf/builtin-buildid-cache.c +1
-1@@ -16,7 +16,7 @@#include "util/util.h" #include "util/debug.h" #include "util/header.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/strlist.h" #include "util/build-id.h" #include "util/session.h" tools/perf/builtin-buildid-list.c +1
-1@@ -12,7 +12,7 @@#include "util/build-id.h" #include "util/util.h" #include "util/debug.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/session.h" #include "util/symbol.h" #include "util/data.h" tools/perf/builtin-config.c +1
-1@@ -9,7 +9,7 @@#include "perf.h" #include "util/util.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/debug.h" static const char *const config_usage[] = {tools/perf/builtin-data.c +1
-1@@ -2,7 +2,7 @@#include "builtin.h" #include "perf.h" #include "debug.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include "data-convert-bt.h" typedef int (*data_cmd_fn_t )(int argc,const char **argv,const char *prefix);tools/perf/builtin-evlist.c +1
-1@@ -12,7 +12,7 @@#include "util/evlist.h" #include "util/evsel.h" #include "util/parse-events.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/session.h" #include "util/data.h" #include "util/debug.h" tools/perf/builtin-help.c +4
-5@@ -6,11 +6,10 @@#include "perf.h" #include "util/util.h" #include "builtin.h" -#include "util/exec_cmd.h" +#include <api/util/exec_cmd.h> #include "common-cmds.h" -#include "util/parse-options.h" -#include "util/run-command.h" -#include "util/help.h" +#include <api/util/parse-options.h> +#include <api/util/run-command.h> #include "util/debug.h" static struct man_viewer_list {@@ -407,7 +406,7 @@ static int get_html_page_path(struct strbuf *page_path, const char *page)#ifndef open_htmlstatic void open_html (const char *path) { -execl_perf_cmd ("web--browse" ,"-c" ,"help.browser" , path,NULL ); +execl_cmd ("web--browse" ,"-c" ,"help.browser" , path,NULL ); }#endif tools/perf/builtin-inject.c +1
-1@@ -18,7 +18,7 @@#include "util/data.h" #include "util/auxtrace.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include <linux/list.h> tools/perf/builtin-kmem.c +1
-1@@ -11,7 +11,7 @@#include "util/tool.h" #include "util/callchain.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/trace-event.h" #include "util/data.h" #include "util/cpumap.h" tools/perf/builtin-kvm.c +1
-1@@ -9,7 +9,7 @@#include "util/header.h" #include "util/session.h" #include "util/intlist.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/trace-event.h" #include "util/debug.h" #include "util/tool.h" tools/perf/builtin-list.c +1
-1@@ -14,7 +14,7 @@#include "util/parse-events.h" #include "util/util.h" #include "util/pmu.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> int cmd_list (int argc,const char **argv,const char *prefix__maybe_unused ) {tools/perf/builtin-lock.c +1
-1@@ -8,7 +8,7 @@#include "util/thread.h" #include "util/header.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/trace-event.h" #include "util/debug.h" tools/perf/builtin-mem.c +1
-1@@ -1,7 +1,7 @@#include "builtin.h" #include "perf.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/trace-event.h" #include "util/tool.h" #include "util/session.h" tools/perf/builtin-probe.c +1
-1@@ -37,7 +37,7 @@#include "util/strfilter.h" #include "util/symbol.h" #include "util/debug.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/probe-finder.h" #include "util/probe-event.h" #include "util/probe-file.h" tools/perf/builtin-record.c +1
-1@@ -11,7 +11,7 @@#include "util/build-id.h" #include "util/util.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-events.h" #include "util/callchain.h" tools/perf/builtin-report.c +1
-1@@ -26,7 +26,7 @@#include "util/session.h" #include "util/tool.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-events.h" #include "util/thread.h" tools/perf/builtin-sched.c +1
-1@@ -11,7 +11,7 @@#include "util/tool.h" #include "util/cloexec.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/trace-event.h" #include "util/debug.h" tools/perf/builtin-script.c +6
-6@@ -2,9 +2,9 @@#include "perf.h" #include "util/debug.h" -#include "util/exec_cmd.h" +#include <api/util/exec_cmd.h> #include "util/header.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/perf_regs.h" #include "util/session.h" #include "util/tool.h" @@ -1393,7 +1393,7 @@ static int list_available_scripts(const struct option *opt __maybe_unused,char first_half[BUFSIZ ];char *script_root; -snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,perf_exec_path ()); +snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,get_argv_exec_path ()); scripts_dir =opendir (scripts_path);if (!scripts_dir)@@ -1514,7 +1514,7 @@ int find_scripts(char **scripts_array, char **scripts_path_array)if (!session)return -1 ; -snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,perf_exec_path ()); +snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,get_argv_exec_path ()); scripts_dir =opendir (scripts_path);if (!scripts_dir) {@@ -1572,7 +1572,7 @@ static char *get_script_path(const char *script_root, const char *suffix)char lang_path[MAXPATHLEN ];char *__script_root; -snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,perf_exec_path ()); +snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,get_argv_exec_path ()); scripts_dir =opendir (scripts_path);if (!scripts_dir)@@ -1808,7 +1808,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) scripting_max_stack = itrace_synth_opts.callchain_sz;/* make sure PERF_EXEC_PATH is set for scripts */ -perf_set_argv_exec_path (perf_exec_path ()); +set_argv_exec_path (get_argv_exec_path ());if (argc && !script_name && !rec_script_path && !rep_script_path) {int live_pipe[2 ];tools/perf/builtin-stat.c +1
-1@@ -45,7 +45,7 @@#include "builtin.h" #include "util/cgroup.h" #include "util/util.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-events.h" #include "util/pmu.h" #include "util/event.h" tools/perf/builtin-timechart.c +1
-1@@ -29,7 +29,7 @@#include "perf.h" #include "util/header.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-events.h" #include "util/event.h" #include "util/session.h" tools/perf/builtin-top.c +1
-1@@ -33,7 +33,7 @@#include "util/top.h" #include "util/util.h" #include <linux/rbtree.h> -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-events.h" #include "util/cpumap.h" #include "util/xyarray.h" tools/perf/builtin-trace.c +2
-2@@ -22,11 +22,11 @@#include "util/color.h" #include "util/debug.h" #include "util/evlist.h" -#include "util/exec_cmd.h" +#include <api/util/exec_cmd.h> #include "util/machine.h" #include "util/session.h" #include "util/thread.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/strlist.h" #include "util/intlist.h" #include "util/thread_map.h" tools/perf/builtin.h +1
-1@@ -2,7 +2,7 @@#define BUILTIN_H #include "util/util.h" -#include "util/strbuf.h" +#include <api/util/strbuf.h> extern const char perf_usage_string[];extern const char perf_more_info_string[];tools/perf/perf.c +20
-7@@ -9,16 +9,17 @@#include "builtin.h" #include "util/env.h" -#include "util/exec_cmd.h" +#include <api/util/exec_cmd.h> #include "util/util.h" #include "util/quote.h" -#include "util/run-command.h" +#include <api/util/run-command.h> #include "util/parse-events.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/bpf-loader.h" #include "util/debug.h" #include <api/fs/tracing_path.h> #include <pthread.h> +#include <api/util/cfg.h> const char perf_usage_string[] ="perf [--version] [--help] [OPTIONS] COMMAND [ARGS]" ;@@ -119,7 +120,7 @@ static void commit_pager_choice(void) {switch (use_pager) {case 0 : -setenv ("PERF_PAGER" ,"cat" ,1 ); +setenv (PERF_PAGER_ENVIRONMENT ,"cat" ,1 );break ;case 1 :/* setup_pager(); */ @@ -129,6 +130,16 @@ static void commit_pager_choice(void) } } +static void setup_util (void ) +{ + util_cfg.prefix =PREFIX ; + util_cfg.exec_name ="perf" ; + util_cfg.exec_path =PERF_EXEC_PATH ; + util_cfg.exec_path_env =EXEC_PATH_ENVIRONMENT ; + util_cfg.pager_env =PERF_PAGER_ENVIRONMENT ; + util_cfg.exit_browser = exit_browser_no_wait; +} +struct option options[] = {OPT_ARGUMENT ("help" ,"help" ),OPT_ARGUMENT ("version" ,"version" ),@@ -183,9 +194,9 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)if (!prefixcmp (cmd,CMD_EXEC_PATH )) { cmd +=strlen (CMD_EXEC_PATH );if (*cmd =='=' ) -perf_set_argv_exec_path (cmd +1 ); +set_argv_exec_path (cmd +1 );else { -puts (perf_exec_path ()); +puts (get_argv_exec_path ());exit (0 ); } }else if (!strcmp (cmd,"--html-path" )) {@@ -530,11 +541,13 @@ int main(int argc, const char **argv)const char *cmd;char sbuf[STRERR_BUFSIZE ]; +setup_util (); +/* The page_size is placed in util object. */ page_size =sysconf (_SC_PAGE_SIZE); cacheline_size =sysconf (_SC_LEVEL1_DCACHE_LINESIZE); - cmd =perf_extract_argv0_path (argv[0 ]); + cmd =extract_argv0_path (argv[0 ]);if (!cmd) cmd ="perf-help" ;tools/perf/perf.h +1
-0@@ -17,6 +17,7 @@#define DEFAULT_PERF_DIR_ENVIRONMENT ".perf"#define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"#define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR" +#define PERF_PAGER_ENVIRONMENT "PERF_PAGER"extern bool test_attr__enabled;void test_attr__init (void );tools/perf/tests/attr.c +2
-2@@ -24,7 +24,7 @@#include <linux/kernel.h> #include "../perf.h" #include "util.h" -#include "exec_cmd.h" +#include <api/util/exec_cmd.h> #include "tests.h" #define ENV "PERF_TEST_ATTR"@@ -164,7 +164,7 @@ int test__attr(int subtest __maybe_unused)return run_dir ("./tests" ,"./perf" );/* Then installed path. */ -snprintf (path_dir,PATH_MAX ,"%s/tests" ,perf_exec_path ()); +snprintf (path_dir,PATH_MAX ,"%s/tests" ,get_argv_exec_path ());snprintf (path_perf,PATH_MAX ,"%s/perf" ,BINDIR ); if (!lstat(path_dir, &st) &&tools/perf/tests/builtin-test.c +1
-1@@ -11,7 +11,7 @@#include "tests.h" #include "debug.h" #include "color.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include "symbol.h" struct test __weak arch_tests[] = {tools/perf/ui/setup.c +5
-0@@ -105,3 +105,8 @@ void exit_browser(bool wait_for_ok)break ; } } + +void exit_browser_no_wait (void ) +{ +exit_browser (false); +}tools/perf/ui/ui.h +1
-0@@ -12,6 +12,7 @@ extern int use_browser;void setup_browser (bool fallback_to_pager);void exit_browser (bool wait_for_ok); +void exit_browser_no_wait (void );#ifdef HAVE_SLANG_SUPPORT int ui__init (void );tools/perf/util/Build +0
-13@@ -1,41 +1,30 @@ -libperf-y += abspath.o libperf-y += alias.o libperf-y += annotate.o libperf-y += build-id.o libperf-y += config.o -libperf-y += ctype.o libperf-y += db-export.o libperf-y += env.o libperf-y += event.o libperf-y += evlist.o libperf-y += evsel.o -libperf-y += exec_cmd.o libperf-y += find_next_bit.o -libperf-y += help.o libperf-y += kallsyms.o libperf-y += levenshtein.o libperf-y += llvm-utils.o -libperf-y += parse-options.o libperf-y += parse-events.o libperf-y += perf_regs.o libperf-y += path.o libperf-y += rbtree.o libperf-y += bitmap.o libperf-y += hweight.o -libperf-y += run-command.o libperf-y += quote.o -libperf-y += strbuf.o libperf-y += string.o libperf-y += strlist.o libperf-y += strfilter.o libperf-y += top.o -libperf-y += usage.o -libperf-y += wrapper.o -libperf-y += sigchain.o libperf-y += dso.o libperf-y += symbol.o libperf-y += color.o -libperf-y += pager.o libperf-y += header.o libperf-y += callchain.o libperf-y += values.o@@ -85,7 +74,6 @@ libperf-$(CONFIG_AUXTRACE) += intel-pt.o libperf-$(CONFIG_AUXTRACE) += intel-bts.o libperf-y += parse-branch-options.o libperf-y += parse-regs-options.o -libperf-y += term.o libperf-y += help-unknown-cmd.o libperf-$(CONFIG_LIBBPF) += bpf-loader.o@@ -112,7 +100,6 @@ libperf-$(CONFIG_ZLIB) += zlib.o libperf-$(CONFIG_LZMA) += lzma.o CFLAGS_config.o += -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" -CFLAGS_exec_cmd.o += -DPERF_EXEC_PATH="BUILD_STR($(perfexecdir_SQ))" -DPREFIX="BUILD_STR($(prefix_SQ))" $(OUTPUT)util/parse-events-flex.c: util/parse-events.l $(OUTPUT)util/parse-events-bison.c $(call rule_mkdir)tools/perf/util/auxtrace.c +1
-1@@ -45,7 +45,7 @@#include "event.h" #include "session.h" #include "debug.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include "intel-pt.h" #include "intel-bts.h" tools/perf/util/cgroup.c +1
-1@@ -1,6 +1,6 @@#include "util.h" #include "../perf.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include "evsel.h" #include "cgroup.h" #include "evlist.h" tools/perf/util/config.c +1
-1@@ -9,7 +9,7 @@* */ #include "util.h" -#include "exec_cmd.h" +#include <api/util/exec_cmd.h> #include "util/hist.h" /* perf_hist_config */ #include "util/llvm-utils.h" /* perf_llvm_config */ tools/perf/util/evlist.c +1
-1@@ -18,7 +18,7 @@#include <unistd.h> #include "parse-events.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include <sys/mman.h> tools/perf/util/header.c +1
-1@@ -20,7 +20,7 @@#include "cpumap.h" #include "pmu.h" #include "vdso.h" -#include "strbuf.h" +#include <api/util/strbuf.h> #include "build-id.h" #include "data.h" tools/perf/util/help-unknown-cmd.c +1
-1@@ -1,5 +1,5 @@#include "util.h" -#include "help.h" +#include <api/util/help.h> #include "../builtin.h" #include "levenshtein.h" tools/perf/util/parse-branch-options.c +1
-1@@ -1,7 +1,7 @@#include "perf.h" #include "util/util.h" #include "util/debug.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-branch-options.h" #define BRANCH_OPT (n, m) \tools/perf/util/parse-events.c +2
-2@@ -4,9 +4,9 @@#include "../perf.h" #include "evlist.h" #include "evsel.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include "parse-events.h" -#include "exec_cmd.h" +#include <api/util/exec_cmd.h> #include "string.h" #include "symbol.h" #include "header.h" tools/perf/util/parse-regs-options.c +1
-1@@ -1,7 +1,7 @@#include "perf.h" #include "util/util.h" #include "util/debug.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-regs-options.h" int tools/perf/util/python-ext-sources +0
-1@@ -6,7 +6,6 @@ # util/python.c -util/ctype.c util/evlist.c util/evsel.c util/cpumap.ctools/perf/util/sort.h +1
-1@@ -17,7 +17,7 @@#include "debug.h" #include "header.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include "parse-events.h" #include "hist.h" #include "thread.h" tools/perf/util/util.h +11
-8@@ -1,24 +1,27 @@#ifndef __PERF_UTIL_H#define __PERF_UTIL_H -#include "compat-util.h" +#include <api/util/compat-util.h> +#include <api/fs/tracing_path.h> #include <api/string/string.h> +#include <api/util/abspath.h> +#include <api/util/ctype.h> +#include <api/util/help.h> +#include <api/util/pager.h> +#include <api/util/strbuf.h> +#include <api/util/term.h> +#include <api/util/usage.h> +#include <api/util/wrapper.h> +#include "../perf.h" -#include "abspath.h" #include "alias.h" #include "config.h" -#include "ctype.h" #include "lzma.h" -#include "pager.h" #include "path.h" #include "srcline.h" -#include "strbuf.h" #include "string.h" -#include "term.h" #include "../ui/ui.h" -#include "usage.h" -#include "wrapper.h" #include "zlib.h" int parse_nsec_time (const char *str,u64 *ptime);Signature · 1 line
2.4.3Signature · 1 line
Josh
Re: [PATCH v2 14/14] perf tools: Move subcommand framework and related utils to libapi
Quoted 13 lines · Arnaldo Carvalho de Melo
Em Tue, Dec 08, 2015 at 12:49:53PM -0600, Josh Poimboeuf escreveu:
Quoted 12 lines · Jiri Olsa
Quoted 11 lines · Josh Poimboeuf
Quoted 9 lines
The perf subcommand framework is needed for other tools. Move
parse-options.cand its dependencies over to libapi.Any function names with 'perf' have been renamed to something more generic.
Also created a
util_cfgstruct for passing perf-specific configuration to the library. Specifying the configuration at runtime allows the same binary to be shared by multiple tools without having to recompile it.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
this patch is too big.. IMO it needs to be split into 3 parts as described in above 3 paragraphs
Ok, will do.
Also please rename this
util_cfgstruct to something more expressive, breaking down the patch may help in finding a better name, I guess.
I'm certainly open to doing so, but I'm having trouble coming up with a better name. The current name makes sense to me, because the struct contains various configuration options needed by the libapi "util" code.
Would 'libapi_util_config' be better? Or do you have any other suggestions?
Signature · 1 line
Josh
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v2 14/14] perf tools: Move subcommand framework and related utils to libapi
Em Tue, Dec 08, 2015 at 01:17:00PM -0600, Josh Poimboeuf escreveu:
Quoted 22 lines · Arnaldo Carvalho de Melo
Quoted 13 lines
Em Tue, Dec 08, 2015 at 12:49:53PM -0600, Josh Poimboeuf escreveu:
Quoted 12 lines · Jiri Olsa
Quoted 11 lines · Josh Poimboeuf
Quoted 9 lines
The perf subcommand framework is needed for other tools. Move
parse-options.cand its dependencies over to libapi.Any function names with 'perf' have been renamed to something more generic.
Also created a
util_cfgstruct for passing perf-specific configuration to the library. Specifying the configuration at runtime allows the same binary to be shared by multiple tools without having to recompile it.Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
this patch is too big.. IMO it needs to be split into 3 parts as described in above 3 paragraphs
Ok, will do.
Also please rename this
util_cfgstruct to something more expressive, breaking down the patch may help in finding a better name, I guess.
Quoted 6 lines
I'm certainly open to doing so, but I'm having trouble coming up with a better name. The current name makes sense to me, because the struct contains various configuration options needed by the libapi "util" code.
Would '
libapi_util_config' be better? Or do you have any other suggestions?
Please break it up into multiple pieces, as suggested by Jiri, in doing so you may find some better name.
But since several are related to command environment setup, perhaps 'struct cmd_exec_env'?
- Arnaldo
Re: [PATCH v2 14/14] perf tools: Move subcommand framework and related utils to libapi
Quoted 27 lines · Arnaldo Carvalho de Melo
Em Tue, Dec 08, 2015 at 01:17:00PM -0600, Josh Poimboeuf escreveu:
Quoted 26 lines · Arnaldo Carvalho de Melo
Quoted 13 lines
Em Tue, Dec 08, 2015 at 12:49:53PM -0600, Josh Poimboeuf escreveu:
Quoted 12 lines · Jiri Olsa
Quoted 11 lines · Josh Poimboeuf
Quoted 9 lines
The perf subcommand framework is needed for other tools. Move
parse-options.cand its dependencies over to libapi.Any function names with 'perf' have been renamed to something more generic.
Also created a
util_cfgstruct for passing perf-specific configuration to the library. Specifying the configuration at runtime allows the same binary to be shared by multiple tools without having to recompile it.Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
this patch is too big.. IMO it needs to be split into 3 parts as described in above 3 paragraphs
Ok, will do.
Also please rename this
util_cfgstruct to something more expressive, breaking down the patch may help in finding a better name, I guess.I'm certainly open to doing so, but I'm having trouble coming up with a better name. The current name makes sense to me, because the struct contains various configuration options needed by the libapi "util" code.
Quoted 8 lines
Quoted 2 lines
Would '
libapi_util_config' be better? Or do you have any other suggestions?Please break it up into multiple pieces, as suggested by Jiri, in doing so you may find some better name.
But since several are related to command environment setup, perhaps 'struct
cmd_exec_env'?
IMO, 'struct cmd_exec_env' doesn't describe the struct accurately. I think it tangentially describes some features of some of the fields, but not all of them. That seems more confusing to me.
Is your complaint that the name is too vague? If so, that's actually by design, because the struct is meant to be a generic interface for providing various unrelated configuration variables to libapi.
I've split the patch up into the above 3 paragraphs as Jiri suggested. But I still don't have any ideas for a name better than 'util_cfg' (other than something more verbose like 'libapi_util_config').
Instead of a single struct, we could consider splitting it into multiple structs (e.g., one for exec_cmd.c, one for parse-options.c, and one for pager.c). But the 'exec_name' field is used by multiple files, so it wouldn't necessarily be a clean split. It would also possibly create more room for error for the users of libapi, since there would then be three config interfaces instead of one.
Signature · 1 line
Josh
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v2 14/14] perf tools: Move subcommand framework and related utils to libapi
Em Tue, Dec 08, 2015 at 03:48:25PM -0600, Josh Poimboeuf escreveu:
Quoted 34 lines · Arnaldo Carvalho de Melo
Quoted 33 lines
Em Tue, Dec 08, 2015 at 01:17:00PM -0600, Josh Poimboeuf escreveu:
Quoted 22 lines · Arnaldo Carvalho de Melo
Quoted 13 lines
Em Tue, Dec 08, 2015 at 12:49:53PM -0600, Josh Poimboeuf escreveu:
Quoted 12 lines · Jiri Olsa
Quoted 11 lines · Josh Poimboeuf
Quoted 9 lines
The perf subcommand framework is needed for other tools. Move
parse-options.cand its dependencies over to libapi.Any function names with 'perf' have been renamed to something more generic.
Also created a
util_cfgstruct for passing perf-specific configuration to the library. Specifying the configuration at runtime allows the same binary to be shared by multiple tools without having to recompile it.Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
this patch is too big.. IMO it needs to be split into 3 parts as described in above 3 paragraphs
Ok, will do.
Also please rename this
util_cfgstruct to something more expressive, breaking down the patch may help in finding a better name, I guess.Quoted 6 lines
I'm certainly open to doing so, but I'm having trouble coming up with a better name. The current name makes sense to me, because the struct contains various configuration options needed by the libapi "util" code.
Would '
libapi_util_config' be better? Or do you have any other suggestions?Please break it up into multiple pieces, as suggested by Jiri, in doing so you may find some better name.
Quoted 6 lines
Quoted 2 lines
But since several are related to command environment setup, perhaps 'struct
cmd_exec_env'?IMO, 'struct
cmd_exec_env' doesn't describe the struct accurately. I think it tangentially describes some features of some of the fields, but not all of them. That seems more confusing to me.
So do not try to keep in a single struct unrelated stuff, create two. :-)
Quoted 11 lines
Is your complaint that the name is too vague? If so, that's actually by design, because the struct is meant to be a generic interface for providing various unrelated configuration variables to libapi.
I've split the patch up into the above 3 paragraphs as Jiri suggested. But I still don't have any ideas for a name better than '
util_cfg' (other than something more verbose like 'libapi_util_config').Instead of a single struct, we could consider splitting it into multiple structs (e.g., one for
exec_cmd.c, one forparse-options.c, and one forpager.c). But the 'exec_name' field is used by multiple files, so it
Yeah, got the same conclusion some lines above :)
Quoted 3 lines
wouldn't necessarily be a clean split. It would also possibly create more room for error for the users of libapi, since there would then be three config interfaces instead of one.
Humm, and now that you talk... libapi was supposed to be just sugar coating kernel APIs, perhaps we need to put it somewhere else in tools/lib/ than in tools/lib/api/?
Borislav, ideas?
- Arnaldo
Re: [PATCH v2 14/14] perf tools: Move subcommand framework and related utils to libapi
Quoted 53 lines · Arnaldo Carvalho de Melo
Em Tue, Dec 08, 2015 at 03:48:25PM -0600, Josh Poimboeuf escreveu:
Quoted 34 lines · Arnaldo Carvalho de Melo
Quoted 33 lines
Em Tue, Dec 08, 2015 at 01:17:00PM -0600, Josh Poimboeuf escreveu:
Quoted 22 lines · Arnaldo Carvalho de Melo
Quoted 13 lines
Em Tue, Dec 08, 2015 at 12:49:53PM -0600, Josh Poimboeuf escreveu:
Quoted 12 lines · Jiri Olsa
Quoted 11 lines · Josh Poimboeuf
Quoted 9 lines
The perf subcommand framework is needed for other tools. Move
parse-options.cand its dependencies over to libapi.Any function names with 'perf' have been renamed to something more generic.
Also created a
util_cfgstruct for passing perf-specific configuration to the library. Specifying the configuration at runtime allows the same binary to be shared by multiple tools without having to recompile it.Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
this patch is too big.. IMO it needs to be split into 3 parts as described in above 3 paragraphs
Ok, will do.
Also please rename this
util_cfgstruct to something more expressive, breaking down the patch may help in finding a better name, I guess.Quoted 6 lines
I'm certainly open to doing so, but I'm having trouble coming up with a better name. The current name makes sense to me, because the struct contains various configuration options needed by the libapi "util" code.
Would '
libapi_util_config' be better? Or do you have any other suggestions?Please break it up into multiple pieces, as suggested by Jiri, in doing so you may find some better name.
Quoted 6 lines
Quoted 2 lines
But since several are related to command environment setup, perhaps 'struct
cmd_exec_env'?IMO, 'struct
cmd_exec_env' doesn't describe the struct accurately. I think it tangentially describes some features of some of the fields, but not all of them. That seems more confusing to me.So do not try to keep in a single struct unrelated stuff, create two. :-)
Quoted 8 lines
Is your complaint that the name is too vague? If so, that's actually by design, because the struct is meant to be a generic interface for providing various unrelated configuration variables to libapi.
I've split the patch up into the above 3 paragraphs as Jiri suggested. But I still don't have any ideas for a name better than '
util_cfg' (other than something more verbose like 'libapi_util_config').
Quoted 5 lines
Quoted 3 lines
Instead of a single struct, we could consider splitting it into multiple structs (e.g., one for
exec_cmd.c, one forparse-options.c, and one forpager.c). But the 'exec_name' field is used by multiple files, so itYeah, got the same conclusion some lines above :)
Ok. Instead of per-file structs, if there are no objections, I think I'll go with per-file init functions. For example:
void exec_cmd_init(const char *exec_name, const char *prefix,
const char *exec_path, const char *exec_path_env);
void pager_init(const char *pager_env);
I think that would be a clearer and less surprising interface.
Quoted 7 lines
Quoted 3 lines
wouldn't necessarily be a clean split. It would also possibly create more room for error for the users of libapi, since there would then be three config interfaces instead of one.
Humm, and now that you talk... libapi was supposed to be just sugar coating kernel APIs, perhaps we need to put it somewhere else in
tools/lib/than intools/lib/api/?
Ah, I didn't realize libapi was a kernel API abstraction library. Shall we put it in tools/lib/util instead?
Quoted 3 lines
Borislav, ideas?
- Arnaldo
Signature · 1 line
Josh
Re: [PATCH v2 14/14] perf tools: Move subcommand framework and related utils to libapi
Quoted 10 lines · Josh Poimboeuf
Quoted 7 lines
Quoted 3 lines
wouldn't necessarily be a clean split. It would also possibly create more room for error for the users of libapi, since there would then be three config interfaces instead of one.
Humm, and now that you talk... libapi was supposed to be just sugar coating kernel APIs, perhaps we need to put it somewhere else in
tools/lib/than intools/lib/api/?Ah, I didn't realize libapi was a kernel API abstraction library. Shall we put it in
tools/lib/utilinstead?
Yay, naming discussion! ;-)
So if this is about abstracting out the (Git derived) command-line option parsing UI and help system, 'util' sounds a bit too generic.
We could call it something like 'lib/cmdline', 'lib/options'?
The (old) argument against making too finegrained user-space libraries was that shared libraries do have extra runtime costs - this thinking resulted in catch-all super-libraries like libgtk:
size /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
text data bss dec hex filename
7199789 57712 15128 7272629 6ef8b5 /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
But in tools/ we typically link the libraries statically so there's no shared library cost to worry about. (Build time linking is a good idea anyway, should we ever want to make use of link-time optimizations. It also eliminates version skew and library compatibility breakage.)
The other reason for the emergence of super-libraries was the high setup cost of new libraries: it's a lot easier to add yet another unrelated API to libgtk than to start up a whole new project and a new library. But this setup cost is very low in tools/ - one of the advantage of shared repositories.
So I think in tools/lib/ we can continue to do a clean topical separation of libraries, super-libraries are not needed.
Thanks,
Ingo
Re: [PATCH v2 14/14] perf tools: Move subcommand framework and related utils to libapi
Quoted 7 lines · Ingo Molnar
Quoted 4 lines · Josh Poimboeuf
Quoted 4 lines
Quoted 3 lines
wouldn't necessarily be a clean split. It would also possibly create more room for error for the users of libapi, since there would then be three config interfaces instead of one.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Humm, and now that you talk... libapi was supposed to be just sugar coating kernel APIs, perhaps we need to put it somewhere else in
tools/lib/than intools/lib/api/?Ah, I didn't realize libapi was a kernel API abstraction library. Shall we put it in
tools/lib/utilinstead?Yay, naming discussion! ;-)
Oh boy! ;-)
Quoted 18 lines
So if this is about abstracting out the (Git derived) command-line option parsing UI and help system, 'util' sounds a bit too generic.
We could call it something like 'lib/cmdline', 'lib/options'?
The (old) argument against making too finegrained user-space libraries was that shared libraries do have extra runtime costs - this thinking resulted in catch-all super-libraries like libgtk:
size
/usr/lib/x86_64-linux-gnu/libgtk-3.so.0
text data bss dec hex filename
7199789 57712 15128 7272629 6ef8b5/usr/lib/x86_64-linux-gnu/libgtk-3.so.0But in
tools/we typically link the libraries statically so there's no shared library cost to worry about. (Build time linking is a good idea anyway, should we ever want to make use of link-time optimizations. It also eliminates version skew and library compatibility breakage.)
Quoted 7 lines
The other reason for the emergence of super-libraries was the high setup cost of new libraries: it's a lot easier to add yet another unrelated API to libgtk than to start up a whole new project and a new library. But this setup cost is very low in
tools/- one of the advantage of shared repositories.So I think in
tools/lib/we can continue to do a clean topical separation of libraries, super-libraries are not needed.
I definitely agree that for the reasons you outlined, something like 'lib/cmdline' would be a good idea. Except... there's a wrinkle, of course.
The library also includes non-cmdline-related dependencies. And these dependencies are directly used by perf as well. So if we name it 'cmdline', perf would have includes like:
#include <cmdline/pager.h>
#include <cmdline/strbuf.h>
#include <cmdline/term.h>
#include <cmdline/wrapper.h>
...etc...
So it would be using several functions from the 'cmdline' library which are unrelated to 'cmdline'.
For that reason I would vote to name it 'lib/util'. But I don't really care, I'd be ok with 'lib/marshmallow' if that's what you guys wanted :-)
Thoughts?
Signature · 1 line
Josh
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v2 14/14] perf tools: Move subcommand framework and related utils to libapi
Em Wed, Dec 09, 2015 at 06:33:15AM -0600, Josh Poimboeuf escreveu:
Quoted 59 lines · Ingo Molnar
Quoted 7 lines · Josh Poimboeuf
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
wouldn't necessarily be a clean split. It would also possibly create more room for error for the users of libapi, since there would then be three config interfaces instead of one.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Humm, and now that you talk... libapi was supposed to be just sugar coating kernel APIs, perhaps we need to put it somewhere else in
tools/lib/than intools/lib/api/?Ah, I didn't realize libapi was a kernel API abstraction library. Shall we put it in
tools/lib/utilinstead?Yay, naming discussion! ;-)
Oh boy! ;-)
Quoted 18 lines
So if this is about abstracting out the (Git derived) command-line option parsing UI and help system, 'util' sounds a bit too generic.
We could call it something like 'lib/cmdline', 'lib/options'?
The (old) argument against making too finegrained user-space libraries was that shared libraries do have extra runtime costs - this thinking resulted in catch-all super-libraries like libgtk:
size
/usr/lib/x86_64-linux-gnu/libgtk-3.so.0
text data bss dec hex filename
7199789 57712 15128 7272629 6ef8b5/usr/lib/x86_64-linux-gnu/libgtk-3.so.0But in
tools/we typically link the libraries statically so there's no shared library cost to worry about. (Build time linking is a good idea anyway, should we ever want to make use of link-time optimizations. It also eliminates version skew and library compatibility breakage.)Quoted 7 lines
The other reason for the emergence of super-libraries was the high setup cost of new libraries: it's a lot easier to add yet another unrelated API to libgtk than to start up a whole new project and a new library. But this setup cost is very low in
tools/- one of the advantage of shared repositories.So I think in
tools/lib/we can continue to do a clean topical separation of libraries, super-libraries are not needed.I definitely agree that for the reasons you outlined, something like 'lib/cmdline' would be a good idea. Except... there's a wrinkle, of course.
The library also includes non-cmdline-related dependencies. And these dependencies are directly used by perf as well. So if we name it 'cmdline', perf would have includes like:
#include <
cmdline/pager.h>
#include <cmdline/strbuf.h>
#include <cmdline/term.h>
#include <cmdline/wrapper.h>
...etc...
Quoted 6 lines
So it would be using several functions from the 'cmdline' library which are unrelated to 'cmdline'.
For that reason I would vote to name it 'lib/util'. But I don't really care, I'd be ok with 'lib/marshmallow' if that's what you guys wanted :-)
Right, now you see why this wasn't librarised before, huh? Untangling bits in a way that this gets sane takes a bit of time.
I'm going thru your patchkit to erode it a bit, taking uncontroversial patches.
I also would just do one thing first, i.e. just move the cmdline parts to lib/cmdline/, then we would look at the rest. I.e. reduce the problem first.
Yeah, I haven't looked deeply how difficult that would be :-\
- Arnaldo
Re: [PATCH v2 14/14] perf tools: Move subcommand framework and related utils to libapi
Quoted 70 lines · Arnaldo Carvalho de Melo
Em Wed, Dec 09, 2015 at 06:33:15AM -0600, Josh Poimboeuf escreveu:
Quoted 59 lines · Ingo Molnar
Quoted 7 lines · Josh Poimboeuf
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
wouldn't necessarily be a clean split. It would also possibly create more room for error for the users of libapi, since there would then be three config interfaces instead of one.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Humm, and now that you talk... libapi was supposed to be just sugar coating kernel APIs, perhaps we need to put it somewhere else in
tools/lib/than intools/lib/api/?Ah, I didn't realize libapi was a kernel API abstraction library. Shall we put it in
tools/lib/utilinstead?Yay, naming discussion! ;-)
Oh boy! ;-)
Quoted 18 lines
So if this is about abstracting out the (Git derived) command-line option parsing UI and help system, 'util' sounds a bit too generic.
We could call it something like 'lib/cmdline', 'lib/options'?
The (old) argument against making too finegrained user-space libraries was that shared libraries do have extra runtime costs - this thinking resulted in catch-all super-libraries like libgtk:
size
/usr/lib/x86_64-linux-gnu/libgtk-3.so.0
text data bss dec hex filename
7199789 57712 15128 7272629 6ef8b5/usr/lib/x86_64-linux-gnu/libgtk-3.so.0But in
tools/we typically link the libraries statically so there's no shared library cost to worry about. (Build time linking is a good idea anyway, should we ever want to make use of link-time optimizations. It also eliminates version skew and library compatibility breakage.)Quoted 7 lines
The other reason for the emergence of super-libraries was the high setup cost of new libraries: it's a lot easier to add yet another unrelated API to libgtk than to start up a whole new project and a new library. But this setup cost is very low in
tools/- one of the advantage of shared repositories.So I think in
tools/lib/we can continue to do a clean topical separation of libraries, super-libraries are not needed.I definitely agree that for the reasons you outlined, something like 'lib/cmdline' would be a good idea. Except... there's a wrinkle, of course.
The library also includes non-cmdline-related dependencies. And these dependencies are directly used by perf as well. So if we name it 'cmdline', perf would have includes like:
#include <
cmdline/pager.h>
#include <cmdline/strbuf.h>
#include <cmdline/term.h>
#include <cmdline/wrapper.h>
...etc...Quoted 6 lines
So it would be using several functions from the 'cmdline' library which are unrelated to 'cmdline'.
For that reason I would vote to name it 'lib/util'. But I don't really care, I'd be ok with 'lib/marshmallow' if that's what you guys wanted :-)
Right, now you see why this wasn't librarised before, huh? Untangling bits in a way that this gets sane takes a bit of time.
Quoted 8 lines
I'm going thru your patchkit to erode it a bit, taking uncontroversial patches.
I also would just do one thing first, i.e. just move the cmdline parts to
lib/cmdline/, then we would look at the rest. I.e. reduce the problem first.Yeah, I haven't looked deeply how difficult that would be :-\
Ok. I've taken a deeper look at how we could just have a 'cmdline' library without the extra unrelated utils.
(BTW, I actually think a name like 'subcmd' would be a better fit than 'cmdline'. Because it deals not only with the cmdline, but more specifically with subcommands, as well as the exec'ing of external subcommands and other subprograms. And any program that wants to have a "perf"- or "git"-like "subcommand" interface would use it, thus 'subcmd' is a more natural fit.)
I looked at the files which are unrelated to subcommands and which are used by both the subcmd code and perf:
- abspath.c: needed by exec_cmd.c for the make_nonrelative_path() function, but it's a small function which can just be duplicated by copying it into exec_cmd.c.
- ctype.c: used by parse-options.c for tolower(), but it's not strictly necessary; instead the glibc version of tolower() can be used.
- pager.c: this isn't directly 'cmdline' related, but does fit the theme of 'subcmd', since it pipes a child process to 'less'. So it could reasonably live in the library.
- strbuf.c: used sparingly by parse-options.c, exec_cmd.c, and help.c. I think all the uses can be replaced rather easily with calls to sprintf() and similar glibc string functions.
(Another option would be to duplicate the ~150 lines of strbuf.c inside the library. That would require renaming all the functions and structs in order to avoid duplicate symbol errors when linking with perf.)
- term.c: used by help.c for the get_term_dimensions() function, which is a small function which can be duplicated in help.c.
- usage.c: used in several places for die() and error(), but these are trivial functions which can be duplicated.
- wrapper.c: used in a few places for ALLOC_GROW() and xrealloc(), but ALLOC_GROW() can be duplicated locally and xrealloc() can be replaced by the use of realloc().
So in summary, with a small amount of code duplication, and a little rewrite of the strbuf usage, I think I can extract a libsubcmd rather cleanly.
How does that sound?
Signature · 1 line
Josh
Namhyung Kim
maintainerRe: [PATCH v2 14/14] perf tools: Move subcommand framework and related utils to libapi
Hi Josh,
Quoted 83 lines · Josh Poimboeuf
Quoted 70 lines · Arnaldo Carvalho de Melo
Em Wed, Dec 09, 2015 at 06:33:15AM -0600, Josh Poimboeuf escreveu:
Quoted 59 lines · Ingo Molnar
Quoted 7 lines · Josh Poimboeuf
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
wouldn't necessarily be a clean split. It would also possibly create more room for error for the users of libapi, since there would then be three config interfaces instead of one.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Humm, and now that you talk... libapi was supposed to be just sugar coating kernel APIs, perhaps we need to put it somewhere else in
tools/lib/than intools/lib/api/?Ah, I didn't realize libapi was a kernel API abstraction library. Shall we put it in
tools/lib/utilinstead?Yay, naming discussion! ;-)
Oh boy! ;-)
Quoted 18 lines
So if this is about abstracting out the (Git derived) command-line option parsing UI and help system, 'util' sounds a bit too generic.
We could call it something like 'lib/cmdline', 'lib/options'?
The (old) argument against making too finegrained user-space libraries was that shared libraries do have extra runtime costs - this thinking resulted in catch-all super-libraries like libgtk:
size
/usr/lib/x86_64-linux-gnu/libgtk-3.so.0
text data bss dec hex filename
7199789 57712 15128 7272629 6ef8b5/usr/lib/x86_64-linux-gnu/libgtk-3.so.0But in
tools/we typically link the libraries statically so there's no shared library cost to worry about. (Build time linking is a good idea anyway, should we ever want to make use of link-time optimizations. It also eliminates version skew and library compatibility breakage.)Quoted 7 lines
The other reason for the emergence of super-libraries was the high setup cost of new libraries: it's a lot easier to add yet another unrelated API to libgtk than to start up a whole new project and a new library. But this setup cost is very low in
tools/- one of the advantage of shared repositories.So I think in
tools/lib/we can continue to do a clean topical separation of libraries, super-libraries are not needed.I definitely agree that for the reasons you outlined, something like 'lib/cmdline' would be a good idea. Except... there's a wrinkle, of course.
The library also includes non-cmdline-related dependencies. And these dependencies are directly used by perf as well. So if we name it 'cmdline', perf would have includes like:
#include <
cmdline/pager.h>
#include <cmdline/strbuf.h>
#include <cmdline/term.h>
#include <cmdline/wrapper.h>
...etc...Quoted 6 lines
So it would be using several functions from the 'cmdline' library which are unrelated to 'cmdline'.
For that reason I would vote to name it 'lib/util'. But I don't really care, I'd be ok with 'lib/marshmallow' if that's what you guys wanted :-)
Right, now you see why this wasn't librarised before, huh? Untangling bits in a way that this gets sane takes a bit of time.
Quoted 8 lines
I'm going thru your patchkit to erode it a bit, taking uncontroversial patches.
I also would just do one thing first, i.e. just move the cmdline parts to
lib/cmdline/, then we would look at the rest. I.e. reduce the problem first.Yeah, I haven't looked deeply how difficult that would be :-\
Ok. I've taken a deeper look at how we could just have a 'cmdline' library without the extra unrelated utils.
Quoted 6 lines
(BTW, I actually think a name like 'subcmd' would be a better fit than 'cmdline'. Because it deals not only with the cmdline, but more specifically with subcommands, as well as the exec'ing of external subcommands and other subprograms. And any program that wants to have a "perf"- or "git"-like "subcommand" interface would use it, thus 'subcmd' is a more natural fit.)
'subcmd' looks good to me too.
Quoted 10 lines
I looked at the files which are unrelated to subcommands and which are used by both the subcmd code and perf:
-
abspath.c: needed byexec_cmd.cfor themake_nonrelative_path()function, but it's a small function which can just be duplicated by copying it intoexec_cmd.c.-
ctype.c: used byparse-options.cfortolower(), but it's not strictly necessary; instead the glibc version oftolower()can be used.
I vaguely recall that it's related to a locale issue. But I don't know what was the problem exactly.
Quoted 14 lines
-
pager.c: this isn't directly 'cmdline' related, but does fit the theme of 'subcmd', since it pipes a child process to 'less'. So it could reasonably live in the library.-
strbuf.c: used sparingly byparse-options.c,exec_cmd.c, andhelp.c. I think all the uses can be replaced rather easily with calls tosprintf()and similar glibc string functions.(Another option would be to duplicate the ~150 lines of
strbuf.cinside the library. That would require renaming all the functions and structs in order to avoid duplicate symbol errors when linking with perf.)
Quoted 5 lines
-
term.c: used byhelp.cfor theget_term_dimensions()function, which is a small function which can be duplicated inhelp.c.-
usage.c: used in several places fordie()anderror(), but these are trivial functions which can be duplicated.
Not sure it's ok to call die() or similar in a library. The error should be reported to the caller rather than exiting inside unless explicitly requested like in usage_with_options() IMHO.
Thanks,
Namhyung
Quoted 13 lines
-
wrapper.c: used in a few places forALLOC_GROW()andxrealloc(), butALLOC_GROW()can be duplicated locally andxrealloc()can be replaced by the use ofrealloc().So in summary, with a small amount of code duplication, and a little rewrite of the strbuf usage, I think I can extract a libsubcmd rather cleanly.
How does that sound?
Signature · 1 line
Josh
Re: [PATCH v2 14/14] perf tools: Move subcommand framework and related utils to libapi
Quoted 86 lines · Namhyung Kim
Hi Josh,
Quoted 83 lines · Josh Poimboeuf
Quoted 70 lines · Arnaldo Carvalho de Melo
Em Wed, Dec 09, 2015 at 06:33:15AM -0600, Josh Poimboeuf escreveu:
Quoted 59 lines · Ingo Molnar
Quoted 7 lines · Josh Poimboeuf
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
wouldn't necessarily be a clean split. It would also possibly create more room for error for the users of libapi, since there would then be three config interfaces instead of one.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Humm, and now that you talk... libapi was supposed to be just sugar coating kernel APIs, perhaps we need to put it somewhere else in
tools/lib/than intools/lib/api/?Ah, I didn't realize libapi was a kernel API abstraction library. Shall we put it in
tools/lib/utilinstead?Yay, naming discussion! ;-)
Oh boy! ;-)
Quoted 18 lines
So if this is about abstracting out the (Git derived) command-line option parsing UI and help system, 'util' sounds a bit too generic.
We could call it something like 'lib/cmdline', 'lib/options'?
The (old) argument against making too finegrained user-space libraries was that shared libraries do have extra runtime costs - this thinking resulted in catch-all super-libraries like libgtk:
size
/usr/lib/x86_64-linux-gnu/libgtk-3.so.0
text data bss dec hex filename
7199789 57712 15128 7272629 6ef8b5/usr/lib/x86_64-linux-gnu/libgtk-3.so.0But in
tools/we typically link the libraries statically so there's no shared library cost to worry about. (Build time linking is a good idea anyway, should we ever want to make use of link-time optimizations. It also eliminates version skew and library compatibility breakage.)Quoted 7 lines
The other reason for the emergence of super-libraries was the high setup cost of new libraries: it's a lot easier to add yet another unrelated API to libgtk than to start up a whole new project and a new library. But this setup cost is very low in
tools/- one of the advantage of shared repositories.So I think in
tools/lib/we can continue to do a clean topical separation of libraries, super-libraries are not needed.I definitely agree that for the reasons you outlined, something like 'lib/cmdline' would be a good idea. Except... there's a wrinkle, of course.
The library also includes non-cmdline-related dependencies. And these dependencies are directly used by perf as well. So if we name it 'cmdline', perf would have includes like:
#include <
cmdline/pager.h>
#include <cmdline/strbuf.h>
#include <cmdline/term.h>
#include <cmdline/wrapper.h>
...etc...Quoted 6 lines
So it would be using several functions from the 'cmdline' library which are unrelated to 'cmdline'.
For that reason I would vote to name it 'lib/util'. But I don't really care, I'd be ok with 'lib/marshmallow' if that's what you guys wanted :-)
Right, now you see why this wasn't librarised before, huh? Untangling bits in a way that this gets sane takes a bit of time.
Quoted 8 lines
I'm going thru your patchkit to erode it a bit, taking uncontroversial patches.
I also would just do one thing first, i.e. just move the cmdline parts to
lib/cmdline/, then we would look at the rest. I.e. reduce the problem first.Yeah, I haven't looked deeply how difficult that would be :-\
Ok. I've taken a deeper look at how we could just have a 'cmdline' library without the extra unrelated utils.
Quoted 8 lines
Quoted 6 lines
(BTW, I actually think a name like 'subcmd' would be a better fit than 'cmdline'. Because it deals not only with the cmdline, but more specifically with subcommands, as well as the exec'ing of external subcommands and other subprograms. And any program that wants to have a "perf"- or "git"-like "subcommand" interface would use it, thus 'subcmd' is a more natural fit.)
'subcmd' looks good to me too.
Ok, thanks!
Quoted 7 lines
Quoted 7 lines
I looked at the files which are unrelated to subcommands and which are used by both the subcmd code and perf:
-
abspath.c: needed byexec_cmd.cfor themake_nonrelative_path()function, but it's a small function which can just be duplicated by copying it intoexec_cmd.c.
Quoted 5 lines
Quoted 2 lines
-
ctype.c: used byparse-options.cfortolower(), but it's not strictly necessary; instead the glibc version oftolower()can be used.I vaguely recall that it's related to a locale issue. But I don't know what was the problem exactly.
Ah, I think you're right. From the ctype man page:
If c is a uppercase letter, tolower() returns its lowercase equivalent, if a lowercase representation exists in the current locale.
In this case, tolower() is just used for sorting the printed option list by the lowercase version of their short option. IMO it's fine to use the glibc locale-specific conversion here.
Quoted 16 lines
Quoted 16 lines
-
pager.c: this isn't directly 'cmdline' related, but does fit the theme of 'subcmd', since it pipes a child process to 'less'. So it could reasonably live in the library.-
strbuf.c: used sparingly byparse-options.c,exec_cmd.c, andhelp.c. I think all the uses can be replaced rather easily with calls tosprintf()and similar glibc string functions.(Another option would be to duplicate the ~150 lines of
strbuf.cinside the library. That would require renaming all the functions and structs in order to avoid duplicate symbol errors when linking with perf.)-
term.c: used byhelp.cfor theget_term_dimensions()function, which is a small function which can be duplicated inhelp.c.
Quoted 6 lines
Quoted 2 lines
-
usage.c: used in several places fordie()anderror(), but these are trivial functions which can be duplicated.Not sure it's ok to call
die()or similar in a library. The error should be reported to the caller rather than exiting inside unless explicitly requested like inusage_with_options()IMHO.
Thanks, good point. I'll try to remove all exits from the library (except for the explicit requests).
Signature · 1 line
Josh
Re: [PATCH v2 14/14] perf tools: Move subcommand framework and related utils to libapi
Quoted 10 lines · Josh Poimboeuf
Quoted 6 lines · Namhyung Kim
Quoted 2 lines
-
usage.c: used in several places fordie()anderror(), but these are trivial functions which can be duplicated.Not sure it's ok to call
die()or similar in a library. The error should be reported to the caller rather than exiting inside unless explicitly requested like inusage_with_options()IMHO.Thanks, good point. I'll try to remove all exits from the library (except for the explicit requests).
As it turns out, some special options like '--list-opts' and '--list-cmds' are implemented within parse_options_subcommand(), which then does an exit(). If those exit()'s were replaced with negative return codes, we'd have to provide a way for callers to distinguish between a normal early exit and a real error (in which the usage printout might be appropriate). That would be a disruptive change and require the 40+ callers of the parse_options*() functions to have more complexity (because they'd need to check for more return conditions).
So I'm thinking I'll leave the code as it is for now and just document the fact that these functions can exit().
Signature · 1 line
Josh
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v2 14/14] perf tools: Move subcommand framework and related utils to libapi
Em Thu, Dec 10, 2015 at 03:35:24PM -0600, Josh Poimboeuf escreveu:
Quoted 12 lines · Josh Poimboeuf
Quoted 10 lines · Namhyung Kim
Quoted 6 lines
Quoted 2 lines
-
usage.c: used in several places fordie()anderror(), but these are trivial functions which can be duplicated.Not sure it's ok to call
die()or similar in a library. The error should be reported to the caller rather than exiting inside unless explicitly requested like inusage_with_options()IMHO.Thanks, good point. I'll try to remove all exits from the library (except for the explicit requests).
Quoted 8 lines
As it turns out, some special options like '--list-opts' and '--list-cmds' are implemented within
parse_options_subcommand(), which then does anexit(). If those exit()'s were replaced with negative return codes, we'd have to provide a way for callers to distinguish between a normal early exit and a real error (in which the usage printout might be appropriate). That would be a disruptive change and require the 40+ callers of the parse_options*() functions to have more complexity (because they'd need to check for more return conditions).
Well, what you're doing is an improvement, so lets go with it. But I'm not afraid of at some point doing a N+ files change if that makes sense, and I find any panic() like libary function to be horrible and in need of removing.
Quoted 2 lines
So I'm thinking I'll leave the code as it is for now and just document the fact that these functions can
exit().
Fair enough, as code using this library will live in tools/ we can always change all the callers in one go when we see fit.
- Arnaldo
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v2 14/14] perf tools: Move subcommand framework and related utils to libapi
In reply to Josh PoimboeufEm Wed, Dec 09, 2015 at 12:59:15PM -0600, Josh Poimboeuf escreveu:
Quoted 83 lines · Arnaldo Carvalho de Melo
Quoted 70 lines
Em Wed, Dec 09, 2015 at 06:33:15AM -0600, Josh Poimboeuf escreveu:
Quoted 59 lines · Ingo Molnar
Quoted 7 lines · Josh Poimboeuf
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
wouldn't necessarily be a clean split. It would also possibly create more room for error for the users of libapi, since there would then be three config interfaces instead of one.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Humm, and now that you talk... libapi was supposed to be just sugar coating kernel APIs, perhaps we need to put it somewhere else in
tools/lib/than intools/lib/api/?Ah, I didn't realize libapi was a kernel API abstraction library. Shall we put it in
tools/lib/utilinstead?Yay, naming discussion! ;-)
Oh boy! ;-)
Quoted 18 lines
So if this is about abstracting out the (Git derived) command-line option parsing UI and help system, 'util' sounds a bit too generic.
We could call it something like 'lib/cmdline', 'lib/options'?
The (old) argument against making too finegrained user-space libraries was that shared libraries do have extra runtime costs - this thinking resulted in catch-all super-libraries like libgtk:
size
/usr/lib/x86_64-linux-gnu/libgtk-3.so.0
text data bss dec hex filename
7199789 57712 15128 7272629 6ef8b5/usr/lib/x86_64-linux-gnu/libgtk-3.so.0But in
tools/we typically link the libraries statically so there's no shared library cost to worry about. (Build time linking is a good idea anyway, should we ever want to make use of link-time optimizations. It also eliminates version skew and library compatibility breakage.)Quoted 7 lines
The other reason for the emergence of super-libraries was the high setup cost of new libraries: it's a lot easier to add yet another unrelated API to libgtk than to start up a whole new project and a new library. But this setup cost is very low in
tools/- one of the advantage of shared repositories.So I think in
tools/lib/we can continue to do a clean topical separation of libraries, super-libraries are not needed.I definitely agree that for the reasons you outlined, something like 'lib/cmdline' would be a good idea. Except... there's a wrinkle, of course.
The library also includes non-cmdline-related dependencies. And these dependencies are directly used by perf as well. So if we name it 'cmdline', perf would have includes like:
#include <
cmdline/pager.h>
#include <cmdline/strbuf.h>
#include <cmdline/term.h>
#include <cmdline/wrapper.h>
...etc...Quoted 6 lines
So it would be using several functions from the 'cmdline' library which are unrelated to 'cmdline'.
For that reason I would vote to name it 'lib/util'. But I don't really care, I'd be ok with 'lib/marshmallow' if that's what you guys wanted :-)
Right, now you see why this wasn't librarised before, huh? Untangling bits in a way that this gets sane takes a bit of time.
Quoted 8 lines
I'm going thru your patchkit to erode it a bit, taking uncontroversial patches.
I also would just do one thing first, i.e. just move the cmdline parts to
lib/cmdline/, then we would look at the rest. I.e. reduce the problem first.Yeah, I haven't looked deeply how difficult that would be :-\
Ok. I've taken a deeper look at how we could just have a 'cmdline' library without the extra unrelated utils.
Quoted 6 lines
(BTW, I actually think a name like 'subcmd' would be a better fit than 'cmdline'. Because it deals not only with the cmdline, but more specifically with subcommands, as well as the exec'ing of external subcommands and other subprograms. And any program that wants to have a "perf"- or "git"-like "subcommand" interface would use it, thus 'subcmd' is a more natural fit.)
Ack, see? We'd eventually get to some better name than "util" :-)
Quoted 6 lines
I looked at the files which are unrelated to subcommands and which are used by both the subcmd code and perf:
-
abspath.c: needed byexec_cmd.cfor themake_nonrelative_path()function, but it's a small function which can just be duplicated by copying it intoexec_cmd.c.
ack
Quoted 2 lines
-
ctype.c: used byparse-options.cfortolower(), but it's not strictly necessary; instead the glibc version oftolower()can be used.
ack
Quoted 3 lines
-
pager.c: this isn't directly 'cmdline' related, but does fit the theme of 'subcmd', since it pipes a child process to 'less'. So it could reasonably live in the library.
ack
Quoted 3 lines
-
strbuf.c: used sparingly byparse-options.c,exec_cmd.c, andhelp.c. I think all the uses can be replaced rather easily with calls tosprintf()and similar glibc string functions.
go for it, use asprintf, probably is all that is needed, it will allocate and format, extending would be just using existing stuff plus new call to asprintf.
Quoted 15 lines
(Another option would be to duplicate the ~150 lines of
strbuf.cinside the library. That would require renaming all the functions and structs in order to avoid duplicate symbol errors when linking with perf.)-
term.c: used byhelp.cfor theget_term_dimensions()function, which is a small function which can be duplicated inhelp.c.-
usage.c: used in several places fordie()anderror(), but these are trivial functions which can be duplicated.-
wrapper.c: used in a few places forALLOC_GROW()andxrealloc(), butALLOC_GROW()can be duplicated locally andxrealloc()can be replaced by the use ofrealloc().
Quoted 5 lines
So in summary, with a small amount of code duplication, and a little rewrite of the strbuf usage, I think I can extract a libsubcmd rather cleanly.
How does that sound?
Just fine, proceed :-)
- Arnaldo
Re: [PATCH v2 14/14] perf tools: Move subcommand framework and related utils to libapi
Quoted 84 lines · Arnaldo Carvalho de Melo
Em Wed, Dec 09, 2015 at 12:59:15PM -0600, Josh Poimboeuf escreveu:
Quoted 83 lines · Arnaldo Carvalho de Melo
Quoted 70 lines
Em Wed, Dec 09, 2015 at 06:33:15AM -0600, Josh Poimboeuf escreveu:
Quoted 59 lines · Ingo Molnar
Quoted 7 lines · Josh Poimboeuf
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
wouldn't necessarily be a clean split. It would also possibly create more room for error for the users of libapi, since there would then be three config interfaces instead of one.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Humm, and now that you talk... libapi was supposed to be just sugar coating kernel APIs, perhaps we need to put it somewhere else in
tools/lib/than intools/lib/api/?Ah, I didn't realize libapi was a kernel API abstraction library. Shall we put it in
tools/lib/utilinstead?Yay, naming discussion! ;-)
Oh boy! ;-)
Quoted 18 lines
So if this is about abstracting out the (Git derived) command-line option parsing UI and help system, 'util' sounds a bit too generic.
We could call it something like 'lib/cmdline', 'lib/options'?
The (old) argument against making too finegrained user-space libraries was that shared libraries do have extra runtime costs - this thinking resulted in catch-all super-libraries like libgtk:
size
/usr/lib/x86_64-linux-gnu/libgtk-3.so.0
text data bss dec hex filename
7199789 57712 15128 7272629 6ef8b5/usr/lib/x86_64-linux-gnu/libgtk-3.so.0But in
tools/we typically link the libraries statically so there's no shared library cost to worry about. (Build time linking is a good idea anyway, should we ever want to make use of link-time optimizations. It also eliminates version skew and library compatibility breakage.)Quoted 7 lines
The other reason for the emergence of super-libraries was the high setup cost of new libraries: it's a lot easier to add yet another unrelated API to libgtk than to start up a whole new project and a new library. But this setup cost is very low in
tools/- one of the advantage of shared repositories.So I think in
tools/lib/we can continue to do a clean topical separation of libraries, super-libraries are not needed.I definitely agree that for the reasons you outlined, something like 'lib/cmdline' would be a good idea. Except... there's a wrinkle, of course.
The library also includes non-cmdline-related dependencies. And these dependencies are directly used by perf as well. So if we name it 'cmdline', perf would have includes like:
#include <
cmdline/pager.h>
#include <cmdline/strbuf.h>
#include <cmdline/term.h>
#include <cmdline/wrapper.h>
...etc...Quoted 6 lines
So it would be using several functions from the 'cmdline' library which are unrelated to 'cmdline'.
For that reason I would vote to name it 'lib/util'. But I don't really care, I'd be ok with 'lib/marshmallow' if that's what you guys wanted :-)
Right, now you see why this wasn't librarised before, huh? Untangling bits in a way that this gets sane takes a bit of time.
Quoted 8 lines
I'm going thru your patchkit to erode it a bit, taking uncontroversial patches.
I also would just do one thing first, i.e. just move the cmdline parts to
lib/cmdline/, then we would look at the rest. I.e. reduce the problem first.Yeah, I haven't looked deeply how difficult that would be :-\
Ok. I've taken a deeper look at how we could just have a 'cmdline' library without the extra unrelated utils.
Quoted 8 lines
Quoted 6 lines
(BTW, I actually think a name like 'subcmd' would be a better fit than 'cmdline'. Because it deals not only with the cmdline, but more specifically with subcommands, as well as the exec'ing of external subcommands and other subprograms. And any program that wants to have a "perf"- or "git"-like "subcommand" interface would use it, thus 'subcmd' is a more natural fit.)
Ack, see? We'd eventually get to some better name than "util" :-)
Yes, this is much better than both 'libutil' and 'libmarshmallow' ;-)
Quoted 47 lines
Quoted 6 lines
I looked at the files which are unrelated to subcommands and which are used by both the subcmd code and perf:
-
abspath.c: needed byexec_cmd.cfor themake_nonrelative_path()function, but it's a small function which can just be duplicated by copying it intoexec_cmd.c.ack
Quoted 2 lines
-
ctype.c: used byparse-options.cfortolower(), but it's not strictly necessary; instead the glibc version oftolower()can be used.ack
Quoted 3 lines
-
pager.c: this isn't directly 'cmdline' related, but does fit the theme of 'subcmd', since it pipes a child process to 'less'. So it could reasonably live in the library.ack
Quoted 3 lines
-
strbuf.c: used sparingly byparse-options.c,exec_cmd.c, andhelp.c. I think all the uses can be replaced rather easily with calls tosprintf()and similar glibc string functions.go for it, use asprintf, probably is all that is needed, it will allocate and format, extending would be just using existing stuff plus new call to asprintf.
Quoted 19 lines
(Another option would be to duplicate the ~150 lines of
strbuf.cinside the library. That would require renaming all the functions and structs in order to avoid duplicate symbol errors when linking with perf.)-
term.c: used byhelp.cfor theget_term_dimensions()function, which is a small function which can be duplicated inhelp.c.-
usage.c: used in several places fordie()anderror(), but these are trivial functions which can be duplicated.-
wrapper.c: used in a few places forALLOC_GROW()andxrealloc(), butALLOC_GROW()can be duplicated locally andxrealloc()can be replaced by the use ofrealloc().So in summary, with a small amount of code duplication, and a little rewrite of the strbuf usage, I think I can extract a libsubcmd rather cleanly.
Quoted 5 lines
Quoted 1 line
How does that sound?
Just fine, proceed :-)
- Arnaldo
Thanks! Working on v3 now.
Signature · 1 line
Josh
Namhyung Kim
maintainerRe: [PATCH v2 14/14] perf tools: Move subcommand framework and related utils to libapi
In reply to Josh PoimboeufQuoted 622 lines · Josh Poimboeuf
The perf subcommand framework is needed for other tools. Move
parse-options.cand its dependencies over to libapi.Any function names with 'perf' have been renamed to something more generic.
Also created a
util_cfgstruct for passing perf-specific configuration to the library. Specifying the configuration at runtime allows the same binary to be shared by multiple tools without having to recompile it.Signed-off-by Josh Poimboeuf <[email protected]>--- tools/include/asm-generic/bitops/__fls.h | 2 +- tools/include/asm-generic/bitops/fls.h | 2 +- tools/include/asm-generic/bitops/fls64.h | 2 +- tools/lib/api/Build | 1 + tools/lib/api/Makefile | 6 +++- tools/lib/api/util/Build | 13 +++++++++ tools/{perf => lib/api}/util/abspath.c | 6 +++- tools/{perf => lib/api}/util/abspath.h | 6 ++-- tools/lib/api/util/cfg.c | 12 ++++++++ tools/lib/api/util/cfg.h | 15 ++++++++++ tools/{perf => lib/api}/util/compat-util.h | 7 ++--- tools/{perf => lib/api}/util/ctype.c | 3 +- tools/{perf => lib/api}/util/ctype.h | 6 ++-- tools/{perf => lib/api}/util/exec_cmd.c | 42 ++++++++++++++-------------- tools/{perf => lib/api}/util/exec_cmd.h | 18 ++++++------ tools/{perf => lib/api}/util/help.c | 11 +++++--- tools/{perf => lib/api}/util/help.h | 0 tools/{perf => lib/api}/util/pager.c | 6 ++-- tools/{perf => lib/api}/util/pager.h | 6 ++-- tools/{perf => lib/api}/util/parse-options.c | 21 ++++++++++---- tools/{perf => lib/api}/util/parse-options.h | 10 +++---- tools/{perf => lib/api}/util/run-command.c | 12 ++++---- tools/{perf => lib/api}/util/run-command.h | 10 +++---- tools/{perf => lib/api}/util/sigchain.c | 4 ++- tools/{perf => lib/api}/util/sigchain.h | 6 ++-- tools/{perf => lib/api}/util/strbuf.c | 6 +++- tools/{perf => lib/api}/util/strbuf.h | 6 ++-- tools/{perf => lib/api}/util/term.c | 3 +- tools/{perf => lib/api}/util/term.h | 0 tools/{perf => lib/api}/util/usage.c | 4 +-- tools/{perf => lib/api}/util/usage.h | 8 +++--- tools/{perf => lib/api}/util/wrapper.c | 4 ++- tools/{perf => lib/api}/util/wrapper.h | 6 ++-- tools/perf/Build | 2 +- tools/perf/arch/x86/util/intel-pt.c | 2 +- tools/perf/bench/futex-hash.c | 2 +- tools/perf/bench/futex-lock-pi.c | 2 +- tools/perf/bench/futex-requeue.c | 2 +- tools/perf/bench/futex-wake-parallel.c | 2 +- tools/perf/bench/futex-wake.c | 2 +- tools/perf/bench/mem-functions.c | 2 +- tools/perf/bench/numa.c | 2 +- tools/perf/bench/sched-messaging.c | 2 +- tools/perf/bench/sched-pipe.c | 2 +- tools/perf/builtin-annotate.c | 2 +- tools/perf/builtin-bench.c | 2 +- tools/perf/builtin-buildid-cache.c | 2 +- tools/perf/builtin-buildid-list.c | 2 +- tools/perf/builtin-config.c | 2 +- tools/perf/builtin-data.c | 2 +- tools/perf/builtin-evlist.c | 2 +- tools/perf/builtin-help.c | 9 +++--- tools/perf/builtin-inject.c | 2 +- tools/perf/builtin-kmem.c | 2 +- tools/perf/builtin-kvm.c | 2 +- tools/perf/builtin-list.c | 2 +- tools/perf/builtin-lock.c | 2 +- tools/perf/builtin-mem.c | 2 +- tools/perf/builtin-probe.c | 2 +- tools/perf/builtin-record.c | 2 +- tools/perf/builtin-report.c | 2 +- tools/perf/builtin-sched.c | 2 +- tools/perf/builtin-script.c | 12 ++++---- tools/perf/builtin-stat.c | 2 +- tools/perf/builtin-timechart.c | 2 +- tools/perf/builtin-top.c | 2 +- tools/perf/builtin-trace.c | 4 +-- tools/perf/builtin.h | 2 +- tools/perf/perf.c | 27 +++++++++++++----- tools/perf/perf.h | 1 + tools/perf/tests/attr.c | 4 +-- tools/perf/tests/builtin-test.c | 2 +- tools/perf/ui/setup.c | 5 ++++ tools/perf/ui/ui.h | 1 + tools/perf/util/Build | 13 --------- tools/perf/util/auxtrace.c | 2 +- tools/perf/util/cgroup.c | 2 +- tools/perf/util/config.c | 2 +- tools/perf/util/evlist.c | 2 +- tools/perf/util/header.c | 2 +- tools/perf/util/help-unknown-cmd.c | 2 +- tools/perf/util/parse-branch-options.c | 2 +- tools/perf/util/parse-events.c | 4 +-- tools/perf/util/parse-regs-options.c | 2 +- tools/perf/util/python-ext-sources | 1 - tools/perf/util/sort.h | 2 +- tools/perf/util/util.h | 19 +++++++------ 87 files changed, 265 insertions(+), 183 deletions(-) create mode 100644 tools/lib/api/util/Build rename tools/{perf => lib/api}/util/abspath.c (90%) rename tools/{perf => lib/api}/util/abspath.h (59%) create mode 100644 tools/lib/api/util/cfg.c create mode 100644 tools/lib/api/util/cfg.h rename tools/{perf => lib/api}/util/compat-util.h (95%) rename tools/{perf => lib/api}/util/ctype.c (97%) rename tools/{perf => lib/api}/util/ctype.h (93%) rename tools/{perf => lib/api}/util/exec_cmd.c (72%) rename tools/{perf => lib/api}/util/exec_cmd.h (14%) rename tools/{perf => lib/api}/util/help.c (96%) rename tools/{perf => lib/api}/util/help.h (100%) rename tools/{perf => lib/api}/util/pager.c (93%) rename tools/{perf => lib/api}/util/pager.h (42%) rename tools/{perf => lib/api}/util/parse-options.c (98%) rename tools/{perf => lib/api}/util/parse-options.h (98%) rename tools/{perf => lib/api}/util/run-command.c (96%) rename tools/{perf => lib/api}/util/run-command.h (87%) rename tools/{perf => lib/api}/util/sigchain.c (93%) rename tools/{perf => lib/api}/util/sigchain.h (53%) rename tools/{perf => lib/api}/util/strbuf.c (97%) rename tools/{perf => lib/api}/util/strbuf.h (97%) rename tools/{perf => lib/api}/util/term.c (93%) rename tools/{perf => lib/api}/util/term.h (100%) rename tools/{perf => lib/api}/util/usage.c (97%) rename tools/{perf => lib/api}/util/usage.h (84%) rename tools/{perf => lib/api}/util/wrapper.c (92%) rename tools/{perf => lib/api}/util/wrapper.h (89%)tools/include/asm-generic/bitops/__fls.h +1
-1@@ -1 +1 @@ -#include <../../../../include/asm-generic/bitops/__fls.h> +#include "../../../../include/asm-generic/bitops/__fls.h" tools/include/asm-generic/bitops/fls.h +1
-1@@ -1 +1 @@ -#include <../../../../include/asm-generic/bitops/fls.h> +#include "../../../../include/asm-generic/bitops/fls.h" tools/include/asm-generic/bitops/fls64.h +1
-1@@ -1 +1 @@ -#include <../../../../include/asm-generic/bitops/fls64.h> +#include "../../../../include/asm-generic/bitops/fls64.h" tools/lib/api/Build +1
-0@@ -2,3 +2,4 @@ libapi-y += fd/ libapi-y += fs/ libapi-y += cpu.o libapi-y += string/ +libapi-y += util/tools/lib/api/Makefile +5
-1@@ -17,7 +17,11 @@ LIBFILE = $(OUTPUT)libapi.a CFLAGS := $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) CFLAGS += -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fPIC -CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 +CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE + +CFLAGS += -I$(srctree)/tools/include/ +CFLAGS += -I$(srctree)/include/uapi +CFLAGS += -I$(srctree)/include RM = rm -ftools/lib/api/util/Build new file +13
-0@@ -0,0 +1,13 @@ +libapi-y += abspath.o +libapi-y += cfg.o +libapi-y += ctype.o +libapi-y += exec_cmd.o +libapi-y += help.o +libapi-y += pager.o +libapi-y += parse-options.o +libapi-y += run-command.o +libapi-y += sigchain.o +libapi-y += strbuf.o +libapi-y += term.o +libapi-y += usage.o +libapi-y += wrapper.otools/lib/api/util/abspath.c renamed from tools/perf/util/abspath.c +5
-1@@ -1,4 +1,8 @@ -#include "util.h" +#include "compat-util.h" + +#include "../string/string.h" +#include "abspath.h" +#include "usage.h" static const char *get_pwd_cwd (void ) {tools/lib/api/util/abspath.h renamed from tools/perf/util/abspath.h +3
-3@@ -1,5 +1,5 @@ -#ifndef __PERF_ABSPATH_H -#define __PERF_ABSPATH_H +#ifndef __API_UTIL_ABSPATH_H +#define __API_UTIL_ABSPATH_Hstatic inline int is_absolute_path (const char *path) {@@ -8,4 +8,4 @@ static inline int is_absolute_path(const char *path)const char *make_nonrelative_path (const char *path); -#endif /* __PERF_ABSPATH_H */ +#endif /* __API_UTIL_ABSPATH_H */ tools/lib/api/util/cfg.c new file +12
-0@@ -0,0 +1,12 @@ +#include "compat-util.h" +#include "cfg.h" + +#define UNDEFINED "UNDEFINED" + +struct util_cfg util_cfg = { + .prefix =UNDEFINED , + .exec_name =UNDEFINED , + .exec_path =UNDEFINED , + .exec_path_env =UNDEFINED , + .pager_env =UNDEFINED , +};tools/lib/api/util/cfg.h new file +15
-0@@ -0,0 +1,15 @@ +#ifndef __API_UTIL_CONFIG_H +#define __API_UTIL_CONFIG_H + +struct util_cfg { +const char *prefix; +const char *exec_name; +const char *exec_path; +const char *exec_path_env; +const char *pager_env; +void (*exit_browser)(void ); +}; + +extern struct util_cfg util_cfg; + +#endif /* #define __API_UTIL_CONFIG_H */ tools/lib/api/util/compat-util.h renamed from tools/perf/util/compat-util.h +3
-4@@ -1,5 +1,5 @@ -#ifndef __PERF_COMPAT_UTIL_H -#define __PERF_COMPAT_UTIL_H +#ifndef __API_UTIL_COMPAT_UTIL_H +#define __API_UTIL_COMPAT_UTIL_H#ifndef FLEX_ARRAY /* @@ -74,7 +74,6 @@#include <linux/magic.h> #include <linux/types.h> #include <sys/ttydefaults.h> -#include <api/fs/tracing_path.h> #include <termios.h> #include <linux/bitops.h> #include <termios.h> @@ -127,4 +126,4 @@#define NSEC_PER_MSEC 1000000L#endif -#endif /* __PERF_COMPAT_UTIL_H */ +#endif /* __API_UTIL_COMPAT_UTIL_H */ tools/lib/api/util/ctype.c renamed from tools/perf/util/ctype.c +2
-1@@ -3,7 +3,8 @@* * No surprises, and works with signed and unsigned chars. */ -#include "util.h" +#include "compat-util.h" +#include "ctype.h" enum {S =GIT_SPACE ,tools/lib/api/util/ctype.h renamed from tools/perf/util/ctype.h +3
-3@@ -1,5 +1,5 @@ -#ifndef __PERF_CTYPE_H -#define __PERF_CTYPE_H +#ifndef __API_UTIL_CTYPE_H +#define __API_UTIL_CTYPE_H/* Sane ctype - no locale, and works with signed chars */ #undef isascii@@ -49,4 +49,4 @@ static inline int sane_case(int x, int high) return x; } -#endif /* __PERF_CTYPE_H */ +#endif /* __API_UTIL_CTYPE_H */ tools/lib/api/util/exec_cmd.c renamed from tools/perf/util/exec_cmd.c +21
-21@@ -1,8 +1,9 @@ -#include "util.h" +#include "compat-util.h" #include "exec_cmd.h" -#include "quote.h" - -#include <string.h> +#include "strbuf.h" +#include "abspath.h" +#include "usage.h" +#include "cfg.h" #define MAX_ARGS 32@@ -11,18 +12,17 @@ static const char *argv0_path;char *system_path (const char *path) { -static const char *prefix =PREFIX ;struct strbuf d =STRBUF_INIT ;if (is_absolute_path (path))return strdup (path); -strbuf_addf (&d,"%s/%s" , prefix, path); +strbuf_addf (&d,"%s/%s" , util_cfg.prefix, path); path =strbuf_detach (&d,NULL );return (char *)path; } -const char *perf_extract_argv0_path (const char *argv0) +const char *extract_argv0_path (const char *argv0) {const char *slash;@@ -41,29 +41,29 @@ const char *perf_extract_argv0_path(const char *argv0)return argv0; } -void perf_set_argv_exec_path (const char *exec_path) +void set_argv_exec_path (const char *exec_path) { argv_exec_path = exec_path;/* * Propagate this setting to external programs. */ -setenv (EXEC_PATH_ENVIRONMENT , exec_path,1 ); +setenv (util_cfg.exec_path_env, exec_path,1 ); } -/* Returns the highest-priority, location to look for perf programs. */ -char *perf_exec_path (void ) +/* Returns the highest-priority location to look for subprograms. */ +char *get_argv_exec_path (void ) {char *env;if (argv_exec_path)return strdup (argv_exec_path); - env =getenv (EXEC_PATH_ENVIRONMENT ); + env =getenv (util_cfg.exec_path_env);if (env && *env)return strdup (env); -return system_path (PERF_EXEC_PATH ); +return system_path (util_cfg.exec_path); }static void add_path (struct strbuf *out,const char *path)@@ -82,7 +82,7 @@ void setup_path(void) {const char *old_path =getenv ("PATH" );struct strbuf new_path =STRBUF_INIT ; -char *tmp =perf_exec_path (); +char *tmp =get_argv_exec_path ();add_path (&new_path, tmp);add_path (&new_path, argv0_path);@@ -98,7 +98,7 @@ void setup_path(void)strbuf_release (&new_path); } -static const char **prepare_perf_cmd (const char **argv) +static const char **prepare_exec_cmd (const char **argv) {int argc;const char **nargv;@@ -107,25 +107,25 @@ static const char **prepare_perf_cmd(const char **argv) ;/* just counting */ nargv =malloc (sizeof (*nargv) * (argc +2 )); - nargv[0 ] ="perf" ; + nargv[0 ] = util_cfg.exec_name;for (argc =0 ; argv[argc]; argc++) nargv[argc +1 ] = argv[argc]; nargv[argc +1 ] =NULL ;return nargv; } -int execv_perf_cmd (const char **argv) { -const char **nargv =prepare_perf_cmd (argv); +int execv_cmd (const char **argv) { +const char **nargv =prepare_exec_cmd (argv);/* execvp() can only ever return if it fails */ -execvp ("perf" , (char **)nargv); +execvp (util_cfg.exec_name, (char **)nargv);free (nargv);return -1 ; } -int execl_perf_cmd (const char *cmd,...) +int execl_cmd (const char *cmd,...) {int argc;const char *argv[MAX_ARGS +1 ];@@ -145,5 +145,5 @@ int execl_perf_cmd(const char *cmd,...)return error ("too many args to run %s" , cmd); argv[argc] =NULL ; -return execv_perf_cmd (argv); +return execv_cmd (argv); }tools/lib/api/util/exec_cmd.h renamed from tools/perf/util/exec_cmd.h +9
-9@@ -1,13 +1,13 @@ -#ifndef __PERF_EXEC_CMD_H -#define __PERF_EXEC_CMD_H +#ifndef __API_UTIL_EXEC_CMD_H +#define __API_UTIL_EXEC_CMD_H -extern void perf_set_argv_exec_path (const char *exec_path); -extern const char *perf_extract_argv0_path (const char *path); +extern void set_argv_exec_path (const char *exec_path); +extern const char *extract_argv0_path (const char *path);extern void setup_path (void ); -extern int execv_perf_cmd (const char **argv);/* NULL terminated */ -extern int execl_perf_cmd (const char *cmd, ...); -/* perf_exec_path and system_path return malloc'd string, caller must free it */ -extern char *perf_exec_path (void ); +extern int execv_cmd (const char **argv);/* NULL terminated */ +extern int execl_cmd (const char *cmd, ...); +/* get_argv_exec_path and system_path return malloc'd string, caller must free it */ +extern char *get_argv_exec_path (void );extern char *system_path (const char *path); -#endif /* __PERF_EXEC_CMD_H */ +#endif /* __API_UTIL_EXEC_CMD_H */ tools/lib/api/util/help.c renamed from tools/perf/util/help.c +7
-4@@ -1,6 +1,9 @@ -#include "util.h" -#include "exec_cmd.h" +#include "compat-util.h" #include "help.h" +#include "exec_cmd.h" +#include "strbuf.h" +#include "wrapper.h" +#include "term.h" void add_cmdname (struct cmdnames *cmds,const char *name,size_t len) {@@ -164,7 +167,7 @@ void load_command_list(const char *prefix, struct cmdnames *other_cmds) {const char *env_path =getenv ("PATH" ); -char *exec_path =perf_exec_path (); +char *exec_path =get_argv_exec_path ();if (exec_path) {list_commands_in_dir (main_cmds, exec_path, prefix);@@ -209,7 +212,7 @@ void list_commands(const char *title, struct cmdnames *main_cmds, longest = other_cmds->names[i]->len;if (main_cmds->cnt) { -char *exec_path =perf_exec_path (); +char *exec_path =get_argv_exec_path ();printf ("available %s in '%s'\n" , title, exec_path);printf ("----------------" );mput_char ('-' ,strlen (title) +strlen (exec_path));tools/lib/api/util/help.h renamed from tools/perf/util/help.h +0
-0tools/lib/api/util/pager.c renamed from tools/perf/util/pager.c +4
-2@@ -1,6 +1,8 @@ -#include "util.h" +#include "compat-util.h" +#include "pager.h" #include "run-command.h" #include "sigchain.h" +#include "cfg.h" /* * This is split up from the rest of git so that we can do @@ -46,7 +48,7 @@ static void wait_for_pager_signal(int signo)void setup_pager (void ) { -const char *pager =getenv ("PERF_PAGER" ); +const char *pager =getenv (util_cfg.pager_env);if (!isatty (1 ))return ;tools/lib/api/util/pager.h renamed from tools/perf/util/pager.h +3
-3@@ -1,7 +1,7 @@ -#ifndef __PERF_PAGER_H -#define __PERF_PAGER_H +#ifndef __API_UTIL_PAGER_H +#define __API_UTIL_PAGER_Hextern void setup_pager (void );extern int pager_in_use (void ); -#endif /* __PERF_PAGER_H */ +#endif /* __API_UTIL_PAGER_H */ tools/lib/api/util/parse-options.c renamed from tools/perf/util/parse-options.c +10
-4@@ -1,7 +1,12 @@ -#include "util.h" +#include "compat-util.h" + +#include "../string/string.h" #include "parse-options.h" -#include "header.h" -#include <api/string/string.h> +#include "strbuf.h" +#include "usage.h" +#include "ctype.h" +#include "pager.h" +#include "cfg.h" #define OPT_SHORT 1#define OPT_UNSET 2@@ -510,7 +515,8 @@ int parse_options_subcommand(int argc, const char **argv, const struct option *oif (subcommands && !usagestr[0 ]) {struct strbuf buf =STRBUF_INIT ; -strbuf_addf (&buf,"perf %s [<options>] {" , argv[0 ]); +strbuf_addf (&buf,"%s %s [<options>] {" , + util_cfg.exec_name, argv[0 ]);for (int i =0 ; subcommands[i]; i++) {if (i)strbuf_addstr (&buf,"|" );
tools/lib/api/util/parse-options.c int usage_with_options_internal(const char * const *usagestr, · line 782
Quoted 7 lines
tools/lib/api/util/parse-options.c renamed from tools/perf/util/parse-options.c +3
-1@@ -771,7 +777,9 @@ int usage_with_options_internal(const char * const *usagestr,void usage_with_options (const char *const *usagestr,const struct option *opts) { -exit_browser (false); +if (util_cfg.exit_browser) + util_cfg.exit_browser (); +
I think it's better to remove this exit_browser() part from util_cfg (or whatever name it). The usage_with_options() deals with command line arguments and options so they should be processed before entering any UI (browser) code.
AFAICS there're only few callers of this function after setup_browser() and it seems possible to change them to do the works before setup_browser(). Will try to send patches soon.
Thanks,
Namhyung
Quoted 1,205 lines
tools/lib/api/util/parse-options.c renamed from tools/perf/util/parse-options.c +2
-1usage_with_options_internal (usagestr, opts,0 ,NULL );exit (129 ); }@@ -781,7 +789,8 @@ void usage_with_options_msg(const char * const *usagestr, {va_list ap; -exit_browser (false); +if (util_cfg.exit_browser) + util_cfg.exit_browser ();va_start (ap, fmt);strbuf_addv (&error_buf, fmt, ap);tools/lib/api/util/parse-options.h renamed from tools/perf/util/parse-options.h +5
-5@@ -1,8 +1,7 @@ -#ifndef __PERF_PARSE_OPTIONS_H -#define __PERF_PARSE_OPTIONS_H +#ifndef __API_UTIL_PARSE_OPTIONS_H +#define __API_UTIL_PARSE_OPTIONS_H -#include <linux/kernel.h> -#include <stdbool.h> +#include "compat-util.h" enum parse_opt_type {/* special types */ @@ -226,4 +225,5 @@ extern int parse_opt_verbosity_cb(const struct option *, const char *, int);extern const char *parse_options_fix_filename (const char *prefix,const char *file);void set_option_flag (struct option *opts,int sopt,const char *lopt,int flag); -#endif /* __PERF_PARSE_OPTIONS_H */ + +#endif /* __API_UTIL_PARSE_OPTIONS_H */ tools/lib/api/util/run-command.c renamed from tools/perf/util/run-command.c +7
-5@@ -1,7 +1,9 @@ -#include "util.h" +#include "compat-util.h" #include "run-command.h" #include "exec_cmd.h" -#include "debug.h" +#include "usage.h" + +#define STRERR_BUFSIZE 128static inline void close_pair (int fd[2 ]) {@@ -112,8 +114,8 @@ int start_command(struct child_process *cmd) }if (cmd->preexec_cb) cmd->preexec_cb (); -if (cmd->perf_cmd) { -execv_perf_cmd (cmd->argv); +if (cmd->exec_cmd) { +execv_cmd (cmd->argv); }else {execvp (cmd->argv[0 ], (char *const *) cmd->argv); }@@ -207,7 +209,7 @@ static void prepare_run_command_v_opt(struct child_process *cmd,memset (cmd,0 ,sizeof (*cmd)); cmd->argv = argv; cmd->no_stdin = opt &RUN_COMMAND_NO_STDIN ?1 :0 ; - cmd->perf_cmd = opt &RUN_PERF_CMD ?1 :0 ; + cmd->exec_cmd = opt &RUN_EXEC_CMD ?1 :0 ; cmd->stdout_to_stderr = opt &RUN_COMMAND_STDOUT_TO_STDERR ?1 :0 ; }tools/lib/api/util/run-command.h renamed from tools/perf/util/run-command.h +5
-5@@ -1,5 +1,5 @@ -#ifndef __PERF_RUN_COMMAND_H -#define __PERF_RUN_COMMAND_H +#ifndef __API_UTIL_RUN_COMMAND_H +#define __API_UTIL_RUN_COMMAND_Henum { ERR_RUN_COMMAND_FORK = 10000,@@ -41,7 +41,7 @@ struct child_process { unsigned no_stdin:1; unsigned no_stdout:1; unsigned no_stderr:1; - unsigned perf_cmd:1; /* if this is to be perf sub-command */ + unsigned exec_cmd:1; /* if this is to be external sub-command */ unsigned stdout_to_stderr:1;void (*preexec_cb)(void ); };@@ -51,8 +51,8 @@ int finish_command(struct child_process *);int run_command (struct child_process *);#define RUN_COMMAND_NO_STDIN 1 -#define RUN_PERF_CMD 2/*If this is to be perf sub-command */ +#define RUN_EXEC_CMD 2/*If this is to be external sub-command */ #define RUN_COMMAND_STDOUT_TO_STDERR 4int run_command_v_opt (const char **argv,int opt); -#endif /* __PERF_RUN_COMMAND_H */ +#endif /* __API_UTIL_RUN_COMMAND_H */ tools/lib/api/util/sigchain.c renamed from tools/perf/util/sigchain.c +3
-1@@ -1,5 +1,7 @@ -#include "util.h" +#include "compat-util.h" #include "sigchain.h" +#include "usage.h" +#include "wrapper.h" #define SIGCHAIN_MAX_SIGNALS 32tools/lib/api/util/sigchain.h renamed from tools/perf/util/sigchain.h +3
-3@@ -1,5 +1,5 @@ -#ifndef __PERF_SIGCHAIN_H -#define __PERF_SIGCHAIN_H +#ifndef __API_UTIL_SIGCHAIN_H +#define __API_UTIL_SIGCHAIN_Htypedef void (*sigchain_fun )(int );@@ -7,4 +7,4 @@ int sigchain_pop(int sig);void sigchain_push_common (sigchain_fun f); -#endif /* __PERF_SIGCHAIN_H */ +#endif /* __API_UTIL_SIGCHAIN_H */ tools/lib/api/util/strbuf.c renamed from tools/perf/util/strbuf.c +5
-1@@ -1,5 +1,9 @@ -#include "util.h" +#include "compat-util.h" +#include <linux/kernel.h> +#include "strbuf.h" +#include "wrapper.h" +#include "usage.h" int prefixcmp (const char *str,const char *prefix) {tools/lib/api/util/strbuf.h renamed from tools/perf/util/strbuf.h +3
-3@@ -1,5 +1,5 @@ -#ifndef __PERF_STRBUF_H -#define __PERF_STRBUF_H +#ifndef __API_UTIL_STRBUF_H +#define __API_UTIL_STRBUF_H/* * Strbuf's can be use in many ways: as a byte array, or to store arbitrary @@ -93,4 +93,4 @@ extern void strbuf_addv(struct strbuf *sb, const char *fmt, va_list ap);/* XXX: if read fails, any partial read is undone */ extern ssize_t strbuf_read (struct strbuf *,int fd,ssize_t hint); -#endif /* __PERF_STRBUF_H */ +#endif /* __API_UTIL_STRBUF_H */ tools/lib/api/util/term.c renamed from tools/perf/util/term.c +2
-1@@ -1,4 +1,5 @@ -#include "util.h" +#include "compat-util.h" +#include "term.h" void get_term_dimensions (struct winsize *ws) {tools/lib/api/util/term.h renamed from tools/perf/util/term.h +0
-0tools/lib/api/util/usage.c renamed from tools/perf/util/usage.c +2
-2@@ -6,8 +6,8 @@* * Copyright (C) Linus Torvalds, 2005 */ -#include "util.h" -#include "debug.h" +#include "compat-util.h" +#include "usage.h" static void report (const char *prefix,const char *err,va_list params) {tools/lib/api/util/usage.h renamed from tools/perf/util/usage.h +4
-4@@ -1,5 +1,5 @@ -#ifndef __PERF_USAGE_H -#define __PERF_USAGE_H +#ifndef __API_UTIL_USAGE_H +#define __API_UTIL_USAGE_H#include "compat-util.h" @@ -8,7 +8,7 @@ extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1,extern int error (const char *err, ...) __attribute__((format (printf,1 ,2 )));extern void warning (const char *err, ...) __attribute__((format (printf,1 ,2 ))); -#include "../../../include/linux/stringify.h" +#include <linux/stringify.h> #define DIE_IF (cnd) \ do { if (cnd) \@@ -20,4 +20,4 @@ extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)))extern void set_die_routine (void (*routine)(const char *err,va_list params)NORETURN );extern void set_warning_routine (void (*routine)(const char *err,va_list params)); -#endif /* __PERF_USAGE_H */ +#endif /* __API_UTIL_USAGE_H */ tools/lib/api/util/wrapper.c renamed from tools/perf/util/wrapper.c +3
-1@@ -1,7 +1,9 @@/* * Various trivial helper wrappers around standard functions */ -#include "util.h" +#include "compat-util.h" +#include "wrapper.h" +#include "usage.h" /* * There's no pack memory to release - but stay close to the Git tools/lib/api/util/wrapper.h renamed from tools/perf/util/wrapper.h +3
-3@@ -1,5 +1,5 @@ -#ifndef __PERF_WRAPPER_H -#define __PERF_WRAPPER_H +#ifndef __API_UTIL_WRAPPER_H +#define __API_UTIL_WRAPPER_Hextern char *xstrdup (const char *str);extern void *xrealloc (void *ptr,size_t size) __attribute__((weak));@@ -31,4 +31,4 @@ static inline void *zalloc(size_t size) } \ }while (0 ) -#endif /* __PERF_WRAPPER_H */ +#endif /* __API_UTIL_WRAPPER_H */tools/perf/Build +1
-1@@ -36,7 +36,7 @@ paths += -DPERF_MAN_PATH="BUILD_STR($(mandir_SQ))" CFLAGS_builtin-help.o += $(paths) CFLAGS_builtin-timechart.o += $(paths) -CFLAGS_perf.o += -DPERF_HTML_PATH="BUILD_STR($(htmldir_SQ))" -include $(OUTPUT)PERF-VERSION-FILE +CFLAGS_perf.o += -DPERF_HTML_PATH="BUILD_STR($(htmldir_SQ))" -DPERF_EXEC_PATH="BUILD_STR($(perfexecdir_SQ))" -DPREFIX="BUILD_STR($(prefix_SQ))" -include $(OUTPUT)PERF-VERSION-FILE CFLAGS_builtin-trace.o += -DSTRACE_GROUPS_DIR="BUILD_STR($(STRACE_GROUPS_DIR_SQ))" libperf-y += util/tools/perf/arch/x86/util/intel-pt.c +1
-1@@ -26,7 +26,7 @@#include "../../util/evlist.h" #include "../../util/evsel.h" #include "../../util/cpumap.h" -#include "../../util/parse-options.h" +#include <api/util/parse-options.h> #include "../../util/parse-events.h" #include "../../util/pmu.h" #include "../../util/debug.h" tools/perf/bench/futex-hash.c +1
-1@@ -11,7 +11,7 @@#include "../perf.h" #include "../util/util.h" #include "../util/stat.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/header.h" #include "bench.h" #include "futex.h" tools/perf/bench/futex-lock-pi.c +1
-1@@ -5,7 +5,7 @@#include "../perf.h" #include "../util/util.h" #include "../util/stat.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/header.h" #include "bench.h" #include "futex.h" tools/perf/bench/futex-requeue.c +1
-1@@ -11,7 +11,7 @@#include "../perf.h" #include "../util/util.h" #include "../util/stat.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/header.h" #include "bench.h" #include "futex.h" tools/perf/bench/futex-wake-parallel.c +1
-1@@ -10,7 +10,7 @@#include "../perf.h" #include "../util/util.h" #include "../util/stat.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/header.h" #include "bench.h" #include "futex.h" tools/perf/bench/futex-wake.c +1
-1@@ -11,7 +11,7 @@#include "../perf.h" #include "../util/util.h" #include "../util/stat.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/header.h" #include "bench.h" #include "futex.h" tools/perf/bench/mem-functions.c +1
-1@@ -8,7 +8,7 @@#include "../perf.h" #include "../util/util.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/header.h" #include "../util/cloexec.h" #include "bench.h" tools/perf/bench/numa.c +1
-1@@ -7,7 +7,7 @@#include "../perf.h" #include "../builtin.h" #include "../util/util.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../util/cloexec.h" #include "bench.h" tools/perf/bench/sched-messaging.c +1
-1@@ -11,7 +11,7 @@#include "../perf.h" #include "../util/util.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../builtin.h" #include "bench.h" tools/perf/bench/sched-pipe.c +1
-1@@ -10,7 +10,7 @@*/ #include "../perf.h" #include "../util/util.h" -#include "../util/parse-options.h" +#include <api/util/parse-options.h> #include "../builtin.h" #include "bench.h" tools/perf/builtin-annotate.c +1
-1@@ -20,7 +20,7 @@#include "util/evsel.h" #include "util/annotate.h" #include "util/event.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-events.h" #include "util/thread.h" #include "util/sort.h" tools/perf/builtin-bench.c +1
-1@@ -16,7 +16,7 @@*/ #include "perf.h" #include "util/util.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "builtin.h" #include "bench/bench.h" tools/perf/builtin-buildid-cache.c +1
-1@@ -16,7 +16,7 @@#include "util/util.h" #include "util/debug.h" #include "util/header.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/strlist.h" #include "util/build-id.h" #include "util/session.h" tools/perf/builtin-buildid-list.c +1
-1@@ -12,7 +12,7 @@#include "util/build-id.h" #include "util/util.h" #include "util/debug.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/session.h" #include "util/symbol.h" #include "util/data.h" tools/perf/builtin-config.c +1
-1@@ -9,7 +9,7 @@#include "perf.h" #include "util/util.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/debug.h" static const char *const config_usage[] = {tools/perf/builtin-data.c +1
-1@@ -2,7 +2,7 @@#include "builtin.h" #include "perf.h" #include "debug.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include "data-convert-bt.h" typedef int (*data_cmd_fn_t )(int argc,const char **argv,const char *prefix);tools/perf/builtin-evlist.c +1
-1@@ -12,7 +12,7 @@#include "util/evlist.h" #include "util/evsel.h" #include "util/parse-events.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/session.h" #include "util/data.h" #include "util/debug.h" tools/perf/builtin-help.c +4
-5@@ -6,11 +6,10 @@#include "perf.h" #include "util/util.h" #include "builtin.h" -#include "util/exec_cmd.h" +#include <api/util/exec_cmd.h> #include "common-cmds.h" -#include "util/parse-options.h" -#include "util/run-command.h" -#include "util/help.h" +#include <api/util/parse-options.h> +#include <api/util/run-command.h> #include "util/debug.h" static struct man_viewer_list {@@ -407,7 +406,7 @@ static int get_html_page_path(struct strbuf *page_path, const char *page)#ifndef open_htmlstatic void open_html (const char *path) { -execl_perf_cmd ("web--browse" ,"-c" ,"help.browser" , path,NULL ); +execl_cmd ("web--browse" ,"-c" ,"help.browser" , path,NULL ); }#endif tools/perf/builtin-inject.c +1
-1@@ -18,7 +18,7 @@#include "util/data.h" #include "util/auxtrace.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include <linux/list.h> tools/perf/builtin-kmem.c +1
-1@@ -11,7 +11,7 @@#include "util/tool.h" #include "util/callchain.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/trace-event.h" #include "util/data.h" #include "util/cpumap.h" tools/perf/builtin-kvm.c +1
-1@@ -9,7 +9,7 @@#include "util/header.h" #include "util/session.h" #include "util/intlist.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/trace-event.h" #include "util/debug.h" #include "util/tool.h" tools/perf/builtin-list.c +1
-1@@ -14,7 +14,7 @@#include "util/parse-events.h" #include "util/util.h" #include "util/pmu.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> int cmd_list (int argc,const char **argv,const char *prefix__maybe_unused ) {tools/perf/builtin-lock.c +1
-1@@ -8,7 +8,7 @@#include "util/thread.h" #include "util/header.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/trace-event.h" #include "util/debug.h" tools/perf/builtin-mem.c +1
-1@@ -1,7 +1,7 @@#include "builtin.h" #include "perf.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/trace-event.h" #include "util/tool.h" #include "util/session.h" tools/perf/builtin-probe.c +1
-1@@ -37,7 +37,7 @@#include "util/strfilter.h" #include "util/symbol.h" #include "util/debug.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/probe-finder.h" #include "util/probe-event.h" #include "util/probe-file.h" tools/perf/builtin-record.c +1
-1@@ -11,7 +11,7 @@#include "util/build-id.h" #include "util/util.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-events.h" #include "util/callchain.h" tools/perf/builtin-report.c +1
-1@@ -26,7 +26,7 @@#include "util/session.h" #include "util/tool.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-events.h" #include "util/thread.h" tools/perf/builtin-sched.c +1
-1@@ -11,7 +11,7 @@#include "util/tool.h" #include "util/cloexec.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/trace-event.h" #include "util/debug.h" tools/perf/builtin-script.c +6
-6@@ -2,9 +2,9 @@#include "perf.h" #include "util/debug.h" -#include "util/exec_cmd.h" +#include <api/util/exec_cmd.h> #include "util/header.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/perf_regs.h" #include "util/session.h" #include "util/tool.h" @@ -1393,7 +1393,7 @@ static int list_available_scripts(const struct option *opt __maybe_unused,char first_half[BUFSIZ ];char *script_root; -snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,perf_exec_path ()); +snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,get_argv_exec_path ()); scripts_dir =opendir (scripts_path);if (!scripts_dir)@@ -1514,7 +1514,7 @@ int find_scripts(char **scripts_array, char **scripts_path_array)if (!session)return -1 ; -snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,perf_exec_path ()); +snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,get_argv_exec_path ()); scripts_dir =opendir (scripts_path);if (!scripts_dir) {@@ -1572,7 +1572,7 @@ static char *get_script_path(const char *script_root, const char *suffix)char lang_path[MAXPATHLEN ];char *__script_root; -snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,perf_exec_path ()); +snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,get_argv_exec_path ()); scripts_dir =opendir (scripts_path);if (!scripts_dir)@@ -1808,7 +1808,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) scripting_max_stack = itrace_synth_opts.callchain_sz;/* make sure PERF_EXEC_PATH is set for scripts */ -perf_set_argv_exec_path (perf_exec_path ()); +set_argv_exec_path (get_argv_exec_path ());if (argc && !script_name && !rec_script_path && !rep_script_path) {int live_pipe[2 ];tools/perf/builtin-stat.c +1
-1@@ -45,7 +45,7 @@#include "builtin.h" #include "util/cgroup.h" #include "util/util.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-events.h" #include "util/pmu.h" #include "util/event.h" tools/perf/builtin-timechart.c +1
-1@@ -29,7 +29,7 @@#include "perf.h" #include "util/header.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-events.h" #include "util/event.h" #include "util/session.h" tools/perf/builtin-top.c +1
-1@@ -33,7 +33,7 @@#include "util/top.h" #include "util/util.h" #include <linux/rbtree.h> -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-events.h" #include "util/cpumap.h" #include "util/xyarray.h" tools/perf/builtin-trace.c +2
-2@@ -22,11 +22,11 @@#include "util/color.h" #include "util/debug.h" #include "util/evlist.h" -#include "util/exec_cmd.h" +#include <api/util/exec_cmd.h> #include "util/machine.h" #include "util/session.h" #include "util/thread.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/strlist.h" #include "util/intlist.h" #include "util/thread_map.h" tools/perf/builtin.h +1
-1@@ -2,7 +2,7 @@#define BUILTIN_H #include "util/util.h" -#include "util/strbuf.h" +#include <api/util/strbuf.h> extern const char perf_usage_string[];extern const char perf_more_info_string[];tools/perf/perf.c +20
-7@@ -9,16 +9,17 @@#include "builtin.h" #include "util/env.h" -#include "util/exec_cmd.h" +#include <api/util/exec_cmd.h> #include "util/util.h" #include "util/quote.h" -#include "util/run-command.h" +#include <api/util/run-command.h> #include "util/parse-events.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/bpf-loader.h" #include "util/debug.h" #include <api/fs/tracing_path.h> #include <pthread.h> +#include <api/util/cfg.h> const char perf_usage_string[] ="perf [--version] [--help] [OPTIONS] COMMAND [ARGS]" ;@@ -119,7 +120,7 @@ static void commit_pager_choice(void) {switch (use_pager) {case 0 : -setenv ("PERF_PAGER" ,"cat" ,1 ); +setenv (PERF_PAGER_ENVIRONMENT ,"cat" ,1 );break ;case 1 :/* setup_pager(); */ @@ -129,6 +130,16 @@ static void commit_pager_choice(void) } } +static void setup_util (void ) +{ + util_cfg.prefix =PREFIX ; + util_cfg.exec_name ="perf" ; + util_cfg.exec_path =PERF_EXEC_PATH ; + util_cfg.exec_path_env =EXEC_PATH_ENVIRONMENT ; + util_cfg.pager_env =PERF_PAGER_ENVIRONMENT ; + util_cfg.exit_browser = exit_browser_no_wait; +} +struct option options[] = {OPT_ARGUMENT ("help" ,"help" ),OPT_ARGUMENT ("version" ,"version" ),@@ -183,9 +194,9 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)if (!prefixcmp (cmd,CMD_EXEC_PATH )) { cmd +=strlen (CMD_EXEC_PATH );if (*cmd =='=' ) -perf_set_argv_exec_path (cmd +1 ); +set_argv_exec_path (cmd +1 );else { -puts (perf_exec_path ()); +puts (get_argv_exec_path ());exit (0 ); } }else if (!strcmp (cmd,"--html-path" )) {@@ -530,11 +541,13 @@ int main(int argc, const char **argv)const char *cmd;char sbuf[STRERR_BUFSIZE ]; +setup_util (); +/* The page_size is placed in util object. */ page_size =sysconf (_SC_PAGE_SIZE); cacheline_size =sysconf (_SC_LEVEL1_DCACHE_LINESIZE); - cmd =perf_extract_argv0_path (argv[0 ]); + cmd =extract_argv0_path (argv[0 ]);if (!cmd) cmd ="perf-help" ;tools/perf/perf.h +1
-0@@ -17,6 +17,7 @@#define DEFAULT_PERF_DIR_ENVIRONMENT ".perf"#define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"#define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR" +#define PERF_PAGER_ENVIRONMENT "PERF_PAGER"extern bool test_attr__enabled;void test_attr__init (void );tools/perf/tests/attr.c +2
-2@@ -24,7 +24,7 @@#include <linux/kernel.h> #include "../perf.h" #include "util.h" -#include "exec_cmd.h" +#include <api/util/exec_cmd.h> #include "tests.h" #define ENV "PERF_TEST_ATTR"@@ -164,7 +164,7 @@ int test__attr(int subtest __maybe_unused)return run_dir ("./tests" ,"./perf" );/* Then installed path. */ -snprintf (path_dir,PATH_MAX ,"%s/tests" ,perf_exec_path ()); +snprintf (path_dir,PATH_MAX ,"%s/tests" ,get_argv_exec_path ());snprintf (path_perf,PATH_MAX ,"%s/perf" ,BINDIR ); if (!lstat(path_dir, &st) &&tools/perf/tests/builtin-test.c +1
-1@@ -11,7 +11,7 @@#include "tests.h" #include "debug.h" #include "color.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include "symbol.h" struct test __weak arch_tests[] = {tools/perf/ui/setup.c +5
-0@@ -105,3 +105,8 @@ void exit_browser(bool wait_for_ok)break ; } } + +void exit_browser_no_wait (void ) +{ +exit_browser (false); +}tools/perf/ui/ui.h +1
-0@@ -12,6 +12,7 @@ extern int use_browser;void setup_browser (bool fallback_to_pager);void exit_browser (bool wait_for_ok); +void exit_browser_no_wait (void );#ifdef HAVE_SLANG_SUPPORT int ui__init (void );tools/perf/util/Build +0
-13@@ -1,41 +1,30 @@ -libperf-y += abspath.o libperf-y += alias.o libperf-y += annotate.o libperf-y += build-id.o libperf-y += config.o -libperf-y += ctype.o libperf-y += db-export.o libperf-y += env.o libperf-y += event.o libperf-y += evlist.o libperf-y += evsel.o -libperf-y += exec_cmd.o libperf-y += find_next_bit.o -libperf-y += help.o libperf-y += kallsyms.o libperf-y += levenshtein.o libperf-y += llvm-utils.o -libperf-y += parse-options.o libperf-y += parse-events.o libperf-y += perf_regs.o libperf-y += path.o libperf-y += rbtree.o libperf-y += bitmap.o libperf-y += hweight.o -libperf-y += run-command.o libperf-y += quote.o -libperf-y += strbuf.o libperf-y += string.o libperf-y += strlist.o libperf-y += strfilter.o libperf-y += top.o -libperf-y += usage.o -libperf-y += wrapper.o -libperf-y += sigchain.o libperf-y += dso.o libperf-y += symbol.o libperf-y += color.o -libperf-y += pager.o libperf-y += header.o libperf-y += callchain.o libperf-y += values.o@@ -85,7 +74,6 @@ libperf-$(CONFIG_AUXTRACE) += intel-pt.o libperf-$(CONFIG_AUXTRACE) += intel-bts.o libperf-y += parse-branch-options.o libperf-y += parse-regs-options.o -libperf-y += term.o libperf-y += help-unknown-cmd.o libperf-$(CONFIG_LIBBPF) += bpf-loader.o@@ -112,7 +100,6 @@ libperf-$(CONFIG_ZLIB) += zlib.o libperf-$(CONFIG_LZMA) += lzma.o CFLAGS_config.o += -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" -CFLAGS_exec_cmd.o += -DPERF_EXEC_PATH="BUILD_STR($(perfexecdir_SQ))" -DPREFIX="BUILD_STR($(prefix_SQ))" $(OUTPUT)util/parse-events-flex.c: util/parse-events.l $(OUTPUT)util/parse-events-bison.c $(call rule_mkdir)tools/perf/util/auxtrace.c +1
-1@@ -45,7 +45,7 @@#include "event.h" #include "session.h" #include "debug.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include "intel-pt.h" #include "intel-bts.h" tools/perf/util/cgroup.c +1
-1@@ -1,6 +1,6 @@#include "util.h" #include "../perf.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include "evsel.h" #include "cgroup.h" #include "evlist.h" tools/perf/util/config.c +1
-1@@ -9,7 +9,7 @@* */ #include "util.h" -#include "exec_cmd.h" +#include <api/util/exec_cmd.h> #include "util/hist.h" /* perf_hist_config */ #include "util/llvm-utils.h" /* perf_llvm_config */ tools/perf/util/evlist.c +1
-1@@ -18,7 +18,7 @@#include <unistd.h> #include "parse-events.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include <sys/mman.h> tools/perf/util/header.c +1
-1@@ -20,7 +20,7 @@#include "cpumap.h" #include "pmu.h" #include "vdso.h" -#include "strbuf.h" +#include <api/util/strbuf.h> #include "build-id.h" #include "data.h" tools/perf/util/help-unknown-cmd.c +1
-1@@ -1,5 +1,5 @@#include "util.h" -#include "help.h" +#include <api/util/help.h> #include "../builtin.h" #include "levenshtein.h" tools/perf/util/parse-branch-options.c +1
-1@@ -1,7 +1,7 @@#include "perf.h" #include "util/util.h" #include "util/debug.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-branch-options.h" #define BRANCH_OPT (n, m) \tools/perf/util/parse-events.c +2
-2@@ -4,9 +4,9 @@#include "../perf.h" #include "evlist.h" #include "evsel.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include "parse-events.h" -#include "exec_cmd.h" +#include <api/util/exec_cmd.h> #include "string.h" #include "symbol.h" #include "header.h" tools/perf/util/parse-regs-options.c +1
-1@@ -1,7 +1,7 @@#include "perf.h" #include "util/util.h" #include "util/debug.h" -#include "util/parse-options.h" +#include <api/util/parse-options.h> #include "util/parse-regs-options.h" int tools/perf/util/python-ext-sources +0
-1@@ -6,7 +6,6 @@ # util/python.c -util/ctype.c util/evlist.c util/evsel.c util/cpumap.ctools/perf/util/sort.h +1
-1@@ -17,7 +17,7 @@#include "debug.h" #include "header.h" -#include "parse-options.h" +#include <api/util/parse-options.h> #include "parse-events.h" #include "hist.h" #include "thread.h" tools/perf/util/util.h +11
-8@@ -1,24 +1,27 @@#ifndef __PERF_UTIL_H#define __PERF_UTIL_H -#include "compat-util.h" +#include <api/util/compat-util.h> +#include <api/fs/tracing_path.h> #include <api/string/string.h> +#include <api/util/abspath.h> +#include <api/util/ctype.h> +#include <api/util/help.h> +#include <api/util/pager.h> +#include <api/util/strbuf.h> +#include <api/util/term.h> +#include <api/util/usage.h> +#include <api/util/wrapper.h> +#include "../perf.h" -#include "abspath.h" #include "alias.h" #include "config.h" -#include "ctype.h" #include "lzma.h" -#include "pager.h" #include "path.h" #include "srcline.h" -#include "strbuf.h" #include "string.h" -#include "term.h" #include "../ui/ui.h" -#include "usage.h" -#include "wrapper.h" #include "zlib.h" int parse_nsec_time (const char *str,u64 *ptime);Signature · 1 line
2.4.3
Namhyung Kim
maintainerQuoted 11 lines · Josh Poimboeuf
Ingo suggested that I factor out the perf subcommand functionality (originally copied from git) into
tools/libso that it can be used by stacktool[*] and possibly others.All the subcommand option handling files have been moved into libapi, including
parse-options.c,run-command.c,exec_cmd.c,help.c,usage.c, and their dependencies. Since several of the dependencies are more general-purpose "utilities" which aren't directly related to subcommands, I put everything in 'tools/lib/api/util'. They're linked into perf as part of the libapi.a library.
Quoted 8 lines
Patches 1-13 do some cleanups and splitting up of the code in preparation for the move.
Patch 14 does the actual moving of the files into
tools/lib/api/util.Based on tip/perf/core.
Is there a public repo that I can pull and test?
Thanks,
Namhyung
Quoted 15 lines · Namhyung Kim
Quoted 14 lines · Josh Poimboeuf
Ingo suggested that I factor out the perf subcommand functionality (originally copied from git) into
tools/libso that it can be used by stacktool[*] and possibly others.All the subcommand option handling files have been moved into libapi, including
parse-options.c,run-command.c,exec_cmd.c,help.c,usage.c, and their dependencies. Since several of the dependencies are more general-purpose "utilities" which aren't directly related to subcommands, I put everything in 'tools/lib/api/util'. They're linked into perf as part of the libapi.a library.Patches 1-13 do some cleanups and splitting up of the code in preparation for the move.
Quoted 7 lines
Quoted 5 lines
Patch 14 does the actual moving of the files into
tools/lib/api/util.Based on tip/perf/core.
Is there a public repo that I can pull and test?
When I post v3 (probably later today), I'll add a repo link.
Signature · 1 line
Josh