Messages in this thread Patch in this message | | | From | Josh Poimboeuf <> | Subject | [PATCH 12/13] perf tools: Move perf subcommand framework into a library | Date | Fri, 4 Dec 2015 15:59:23 -0600 |
| |
The perf subcommand framework will soon be needed by stacktool. Move parse-options.c, run-command.c, exec_cmd.c, help.c, usage.c, and their dependencies over to libapi in 'tools/lib/api/util'.
Functions with 'perf' in their name have been given more generic names.
Also created a util_cfg struct for passing perf-specific configuration to the library. Specifying the configuration at runtime allows the same binary to be shared by multiple tools without having to recompile it.
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com> --- tools/lib/api/Build | 1 + tools/lib/api/string/Build | 1 + tools/lib/{ => api/string}/string.c | 7 ++++--- tools/{include/linux => lib/api/string}/string.h | 10 +++++----- tools/perf/MANIFEST | 2 -- tools/perf/builtin-kmem.c | 2 +- tools/perf/util/Build | 6 ------ tools/perf/util/auxtrace.c | 2 +- tools/perf/util/bpf-loader.c | 2 +- tools/perf/util/intel-pt-decoder/insn.c | 2 +- tools/perf/util/map.c | 2 +- tools/perf/util/ordered-events.c | 2 +- tools/perf/util/parse-options.c | 2 +- tools/perf/util/util.h | 2 +- 14 files changed, 19 insertions(+), 24 deletions(-) create mode 100644 tools/lib/api/string/Build rename tools/lib/{ => api/string}/string.c (93%) rename tools/{include/linux => lib/api/string}/string.h (66%)
diff --git a/tools/lib/api/Build b/tools/lib/api/Build index e8b8a23..9e3967e 100644 --- a/tools/lib/api/Build +++ b/tools/lib/api/Build @@ -1,3 +1,4 @@ libapi-y += fd/ libapi-y += fs/ libapi-y += cpu.o +libapi-y += string/ diff --git a/tools/lib/api/string/Build b/tools/lib/api/string/Build new file mode 100644 index 0000000..7707d3d --- /dev/null +++ b/tools/lib/api/string/Build @@ -0,0 +1 @@ +libapi-y += string.o diff --git a/tools/lib/string.c b/tools/lib/api/string/string.c similarity index 93% rename from tools/lib/string.c rename to tools/lib/api/string/string.c index 3366582..3140ba3 100644 --- a/tools/lib/string.c +++ b/tools/lib/api/string/string.c @@ -1,5 +1,5 @@ /* - * linux/tools/lib/string.c + * linux/tools/lib/api/string/string.c * * Copied from linux/lib/string.c, where it is: * @@ -15,8 +15,9 @@ #include <stdlib.h> #include <string.h> #include <errno.h> -#include <linux/string.h> -#include <linux/compiler.h> +#include "string.h" + +#define __weak __attribute__((weak)) /** * memdup - duplicate region of memory diff --git a/tools/include/linux/string.h b/tools/lib/api/string/string.h similarity index 66% rename from tools/include/linux/string.h rename to tools/lib/api/string/string.h index eae1d87..74bd4fd 100644 --- a/tools/include/linux/string.h +++ b/tools/lib/api/string/string.h @@ -1,8 +1,8 @@ -#ifndef _TOOLS_LINUX_STRING_H_ -#define _TOOLS_LINUX_STRING_H_ +#ifndef _API_STRING_H +#define _API_STRING_H - -#include <linux/types.h> /* for size_t */ +#include <stddef.h> +#include <stdbool.h> void *memdup(const void *src, size_t len); @@ -13,4 +13,4 @@ int strtobool(const char *s, bool *res); extern size_t strlcpy(char *dest, const char *src, size_t size); #endif -#endif /* _LINUX_STRING_H_ */ +#endif /* _API_STRING_H */ diff --git a/tools/perf/MANIFEST b/tools/perf/MANIFEST index 2562eac..39c38cb 100644 --- a/tools/perf/MANIFEST +++ b/tools/perf/MANIFEST @@ -22,7 +22,6 @@ tools/lib/api tools/lib/bpf tools/lib/hweight.c tools/lib/rbtree.c -tools/lib/string.c tools/lib/symbol/kallsyms.c tools/lib/symbol/kallsyms.h tools/lib/util/find_next_bit.c @@ -51,7 +50,6 @@ tools/include/linux/log2.h tools/include/linux/poison.h tools/include/linux/rbtree.h tools/include/linux/rbtree_augmented.h -tools/include/linux/string.h tools/include/linux/types.h tools/include/linux/err.h include/asm-generic/bitops/arch_hweight.h diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index 1c3d3d9..cdf487b 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -19,7 +19,7 @@ #include "util/debug.h" #include <linux/rbtree.h> -#include <linux/string.h> +#include <api/string/string.h> #include <locale.h> #include <regex.h> diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 99b3dae..02d3a54 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -20,7 +20,6 @@ libperf-y += parse-events.o libperf-y += perf_regs.o libperf-y += path.o libperf-y += rbtree.o -libperf-y += libstring.o libperf-y += bitmap.o libperf-y += hweight.o libperf-y += run-command.o @@ -141,7 +140,6 @@ $(OUTPUT)util/pmu.o: $(OUTPUT)util/pmu-flex.c $(OUTPUT)util/pmu-bison.c CFLAGS_find_next_bit.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" CFLAGS_rbtree.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" -CFLAGS_libstring.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" CFLAGS_hweight.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" CFLAGS_parse-events.o += -Wno-redundant-decls @@ -157,10 +155,6 @@ $(OUTPUT)util/rbtree.o: ../lib/rbtree.c FORCE $(call rule_mkdir) $(call if_changed_dep,cc_o_c) -$(OUTPUT)util/libstring.o: ../lib/string.c FORCE - $(call rule_mkdir) - $(call if_changed_dep,cc_o_c) - $(OUTPUT)util/hweight.o: ../lib/hweight.c FORCE $(call rule_mkdir) $(call if_changed_dep,cc_o_c) diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c index 7f10430..cc83262 100644 --- a/tools/perf/util/auxtrace.c +++ b/tools/perf/util/auxtrace.c @@ -22,7 +22,7 @@ #include <linux/types.h> #include <linux/bitops.h> #include <linux/log2.h> -#include <linux/string.h> +#include <api/string/string.h> #include <sys/param.h> #include <stdlib.h> diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c index 540a7ef..5a99b6a 100644 --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c @@ -8,7 +8,7 @@ #include <linux/bpf.h> #include <bpf/libbpf.h> #include <linux/err.h> -#include <linux/string.h> +#include <api/string/string.h> #include "perf.h" #include "debug.h" #include "bpf-loader.h" diff --git a/tools/perf/util/intel-pt-decoder/insn.c b/tools/perf/util/intel-pt-decoder/insn.c index 47314a6..bcf3a8e 100644 --- a/tools/perf/util/intel-pt-decoder/insn.c +++ b/tools/perf/util/intel-pt-decoder/insn.c @@ -19,7 +19,7 @@ */ #ifdef __KERNEL__ -#include <linux/string.h> +#include <api/string/string.h> #else #include <string.h> #endif diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index 93d9f1c..c9f716d 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -14,7 +14,7 @@ #include "util.h" #include "debug.h" #include "machine.h" -#include <linux/string.h> +#include <api/string/string.h> static void __maps__insert(struct maps *maps, struct map *map); diff --git a/tools/perf/util/ordered-events.c b/tools/perf/util/ordered-events.c index b1b9e23..867ae98 100644 --- a/tools/perf/util/ordered-events.c +++ b/tools/perf/util/ordered-events.c @@ -1,6 +1,6 @@ #include <linux/list.h> #include <linux/compiler.h> -#include <linux/string.h> +#include <api/string/string.h> #include "ordered-events.h" #include "session.h" #include "asm/bug.h" diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c index 735c8c8..8d70c1b 100644 --- a/tools/perf/util/parse-options.c +++ b/tools/perf/util/parse-options.c @@ -1,7 +1,7 @@ #include "util.h" #include "parse-options.h" #include "header.h" -#include <linux/string.h> +#include <api/string/string.h> #define OPT_SHORT 1 #define OPT_UNSET 2 diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index 2c6db35..f1c07f6 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h @@ -3,7 +3,7 @@ #include "compat-util.h" -#include <linux/string.h> +#include <api/string/string.h> #include "../perf.h" #include "abspath.h" #include "alias.h" -- 2.4.3
| |