diff options
Diffstat (limited to 'tools')
207 files changed, 1070 insertions, 645 deletions
diff --git a/tools/arch/x86/include/asm/cpufeatures.h b/tools/arch/x86/include/asm/cpufeatures.h index b04bb6dfed7f..0fe00446f9ca 100644 --- a/tools/arch/x86/include/asm/cpufeatures.h +++ b/tools/arch/x86/include/asm/cpufeatures.h @@ -187,6 +187,7 @@ * Reuse free bits when adding new feature flags! */ #define X86_FEATURE_RING3MWAIT ( 7*32+ 0) /* Ring 3 MONITOR/MWAIT */ +#define X86_FEATURE_CPUID_FAULT ( 7*32+ 1) /* Intel CPUID faulting */ #define X86_FEATURE_CPB ( 7*32+ 2) /* AMD Core Performance Boost */ #define X86_FEATURE_EPB ( 7*32+ 3) /* IA32_ENERGY_PERF_BIAS support */ #define X86_FEATURE_CAT_L3 ( 7*32+ 4) /* Cache Allocation Technology L3 */ diff --git a/tools/arch/x86/lib/memcpy_64.S b/tools/arch/x86/lib/memcpy_64.S index 49e6ebac7e73..98dcc112b363 100644 --- a/tools/arch/x86/lib/memcpy_64.S +++ b/tools/arch/x86/lib/memcpy_64.S @@ -286,7 +286,7 @@ ENDPROC(memcpy_mcsafe_unrolled) _ASM_EXTABLE_FAULT(.L_copy_leading_bytes, .L_memcpy_mcsafe_fail) _ASM_EXTABLE_FAULT(.L_cache_w0, .L_memcpy_mcsafe_fail) _ASM_EXTABLE_FAULT(.L_cache_w1, .L_memcpy_mcsafe_fail) - _ASM_EXTABLE_FAULT(.L_cache_w3, .L_memcpy_mcsafe_fail) + _ASM_EXTABLE_FAULT(.L_cache_w2, .L_memcpy_mcsafe_fail) _ASM_EXTABLE_FAULT(.L_cache_w3, .L_memcpy_mcsafe_fail) _ASM_EXTABLE_FAULT(.L_cache_w4, .L_memcpy_mcsafe_fail) _ASM_EXTABLE_FAULT(.L_cache_w5, .L_memcpy_mcsafe_fail) diff --git a/tools/include/linux/bug.h b/tools/include/linux/bug.h new file mode 100644 index 000000000000..8e4a4f49135d --- /dev/null +++ b/tools/include/linux/bug.h @@ -0,0 +1,10 @@ +#ifndef _TOOLS_PERF_LINUX_BUG_H +#define _TOOLS_PERF_LINUX_BUG_H + +/* Force a compilation error if condition is true, but also produce a + result (of value 0 and type size_t), so the expression can be used + e.g. in a structure initializer (or where-ever else comma expressions + aren't permitted). */ +#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) + +#endif /* _TOOLS_PERF_LINUX_BUG_H */ diff --git a/tools/include/linux/compiler-gcc.h b/tools/include/linux/compiler-gcc.h index 616935f1ff56..825d44f89a29 100644 --- a/tools/include/linux/compiler-gcc.h +++ b/tools/include/linux/compiler-gcc.h @@ -16,3 +16,6 @@ #if GCC_VERSION >= 40300 # define __compiletime_error(message) __attribute__((error(message))) #endif /* GCC_VERSION >= 40300 */ + +/* &a[0] degrades to a pointer: a different type from an array */ +#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h index c9e65e8faacd..23299d7e7160 100644 --- a/tools/include/linux/compiler.h +++ b/tools/include/linux/compiler.h @@ -17,6 +17,11 @@ # define __always_inline inline __attribute__((always_inline)) #endif +/* Are two types/vars the same type (ignoring qualifiers)? */ +#ifndef __same_type +# define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b)) +#endif + #ifdef __ANDROID__ /* * FIXME: Big hammer to get rid of tons of: diff --git a/tools/include/linux/hashtable.h b/tools/include/linux/hashtable.h index c65cc0aa2659..251eabf2a05e 100644 --- a/tools/include/linux/hashtable.h +++ b/tools/include/linux/hashtable.h @@ -13,10 +13,6 @@ #include <linux/hash.h> #include <linux/log2.h> -#ifndef ARRAY_SIZE -#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) -#endif - #define DEFINE_HASHTABLE(name, bits) \ struct hlist_head name[1 << (bits)] = \ { [0 ... ((1 << (bits)) - 1)] = HLIST_HEAD_INIT } diff --git a/tools/include/linux/kernel.h b/tools/include/linux/kernel.h index adb4d0147755..73ccc48126bb 100644 --- a/tools/include/linux/kernel.h +++ b/tools/include/linux/kernel.h @@ -4,6 +4,7 @@ #include <stdarg.h> #include <stddef.h> #include <assert.h> +#include <linux/compiler.h> #ifndef UINT_MAX #define UINT_MAX (~0U) @@ -76,6 +77,8 @@ int vscnprintf(char *buf, size_t size, const char *fmt, va_list args); int scnprintf(char * buf, size_t size, const char * fmt, ...); +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) + /* * This looks more complex than it should be. But we need to * get the type for the ~ right in round_down (it needs to be diff --git a/tools/include/linux/log2.h b/tools/include/linux/log2.h index d5677d39c1e4..0325cefc2220 100644 --- a/tools/include/linux/log2.h +++ b/tools/include/linux/log2.h @@ -12,6 +12,9 @@ #ifndef _TOOLS_LINUX_LOG2_H #define _TOOLS_LINUX_LOG2_H +#include <linux/bitops.h> +#include <linux/types.h> + /* * non-constant log of base 2 calculators * - the arch may override these in asm/bitops.h if they can be implemented diff --git a/tools/include/uapi/linux/stat.h b/tools/include/uapi/linux/stat.h index 51a6b86e3700..d538897b8e08 100644 --- a/tools/include/uapi/linux/stat.h +++ b/tools/include/uapi/linux/stat.h @@ -114,7 +114,7 @@ struct statx { __u64 stx_ino; /* Inode number */ __u64 stx_size; /* File size */ __u64 stx_blocks; /* Number of 512-byte blocks allocated */ - __u64 __spare1[1]; + __u64 stx_attributes_mask; /* Mask to show what's supported in stx_attributes */ /* 0x40 */ struct statx_timestamp stx_atime; /* Last access time */ struct statx_timestamp stx_btime; /* File creation time */ @@ -152,9 +152,10 @@ struct statx { #define STATX_BASIC_STATS 0x000007ffU /* The stuff in the normal stat struct */ #define STATX_BTIME 0x00000800U /* Want/got stx_btime */ #define STATX_ALL 0x00000fffU /* All currently supported flags */ +#define STATX__RESERVED 0x80000000U /* Reserved for future struct statx expansion */ /* - * Attributes to be found in stx_attributes + * Attributes to be found in stx_attributes and masked in stx_attributes_mask. * * These give information about the features or the state of a file that might * be of use to ordinary userspace programs such as GUIs or ls rather than diff --git a/tools/lib/subcmd/help.h b/tools/lib/subcmd/help.h index e145a020780c..9bd4223dc722 100644 --- a/tools/lib/subcmd/help.h +++ b/tools/lib/subcmd/help.h @@ -2,6 +2,7 @@ #define __SUBCMD_HELP_H #include <sys/types.h> +#include <stdio.h> struct cmdnames { size_t alloc; diff --git a/tools/lib/symbol/kallsyms.c b/tools/lib/symbol/kallsyms.c index 5e431077fcd6..d270ac00613d 100644 --- a/tools/lib/symbol/kallsyms.c +++ b/tools/lib/symbol/kallsyms.c @@ -1,3 +1,4 @@ +#include <ctype.h> #include "symbol/kallsyms.h" #include <stdio.h> #include <stdlib.h> diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index 066086dd59a8..282a60368b14 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -36,8 +36,7 @@ #include "warn.h" #include <linux/hashtable.h> - -#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#include <linux/kernel.h> #define STATE_FP_SAVED 0x1 #define STATE_FP_SETUP 0x2 diff --git a/tools/objtool/objtool.c b/tools/objtool/objtool.c index 46c326db4f46..ecc5b1b5d15d 100644 --- a/tools/objtool/objtool.c +++ b/tools/objtool/objtool.c @@ -31,11 +31,10 @@ #include <stdlib.h> #include <subcmd/exec-cmd.h> #include <subcmd/pager.h> +#include <linux/kernel.h> #include "builtin.h" -#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) - struct cmd_struct { const char *name; int (*fn)(int, const char **); diff --git a/tools/perf/MANIFEST b/tools/perf/MANIFEST index 89018c7311a4..a29da46d180f 100644 --- a/tools/perf/MANIFEST +++ b/tools/perf/MANIFEST @@ -64,6 +64,7 @@ tools/include/linux/bitops.h tools/include/linux/compiler.h tools/include/linux/compiler-gcc.h tools/include/linux/coresight-pmu.h +tools/include/linux/bug.h tools/include/linux/filter.h tools/include/linux/hash.h tools/include/linux/kernel.h diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c index dfea6b635525..29361d9b635a 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -33,6 +33,7 @@ #include "../../util/cs-etm.h" #include <stdlib.h> +#include <sys/stat.h> #define ENABLE_SINK_MAX 128 #define CS_BUS_DEVICE_PATH "/bus/coresight/devices/" diff --git a/tools/perf/arch/arm/util/dwarf-regs.c b/tools/perf/arch/arm/util/dwarf-regs.c index 33ec5b339da8..8bb176a37990 100644 --- a/tools/perf/arch/arm/util/dwarf-regs.c +++ b/tools/perf/arch/arm/util/dwarf-regs.c @@ -9,6 +9,7 @@ */ #include <stddef.h> +#include <linux/stringify.h> #include <dwarf-regs.h> struct pt_regs_dwarfnum { @@ -16,10 +17,9 @@ struct pt_regs_dwarfnum { unsigned int dwarfnum; }; -#define STR(s) #s #define REG_DWARFNUM_NAME(r, num) {.name = r, .dwarfnum = num} #define GPR_DWARFNUM_NAME(num) \ - {.name = STR(%r##num), .dwarfnum = num} + {.name = __stringify(%r##num), .dwarfnum = num} #define REG_DWARFNUM_END {.name = NULL, .dwarfnum = 0} /* diff --git a/tools/perf/arch/arm/util/unwind-libdw.c b/tools/perf/arch/arm/util/unwind-libdw.c index b4176c60117a..bacfa00fca39 100644 --- a/tools/perf/arch/arm/util/unwind-libdw.c +++ b/tools/perf/arch/arm/util/unwind-libdw.c @@ -1,6 +1,7 @@ #include <elfutils/libdwfl.h> #include "../../util/unwind-libdw.h" #include "../../util/perf_regs.h" +#include "../../util/event.h" bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg) { diff --git a/tools/perf/arch/arm64/util/dwarf-regs.c b/tools/perf/arch/arm64/util/dwarf-regs.c index 068b6189157b..cd764a9fd098 100644 --- a/tools/perf/arch/arm64/util/dwarf-regs.c +++ b/tools/perf/arch/arm64/util/dwarf-regs.c @@ -8,9 +8,12 @@ * published by the Free Software Foundation. */ +#include <errno.h> #include <stddef.h> +#include <string.h> #include <dwarf-regs.h> #include <linux/ptrace.h> /* for struct user_pt_regs */ +#include <linux/stringify.h> #include "util.h" struct pt_regs_dwarfnum { @@ -20,7 +23,7 @@ struct pt_regs_dwarfnum { #define REG_DWARFNUM_NAME(r, num) {.name = r, .dwarfnum = num} #define GPR_DWARFNUM_NAME(num) \ - {.name = STR(%x##num), .dwarfnum = num} + {.name = __stringify(%x##num), .dwarfnum = num} #define REG_DWARFNUM_END {.name = NULL, .dwarfnum = 0} #define DWARFNUM2OFFSET(index) \ (index * sizeof((struct user_pt_regs *)0)->regs[0]) diff --git a/tools/perf/arch/arm64/util/unwind-libunwind.c b/tools/perf/arch/arm64/util/unwind-libunwind.c index c116b713f7f7..b415dfdbccca 100644 --- a/tools/perf/arch/arm64/util/unwind-libunwind.c +++ b/tools/perf/arch/arm64/util/unwind-libunwind.c @@ -1,6 +1,6 @@ +#include <errno.h> #ifndef REMOTE_UNWIND_LIBUNWIND -#include <errno.h> #include <libunwind.h> #include "perf_regs.h" #include "../../util/unwind.h" diff --git a/tools/perf/arch/common.c b/tools/perf/arch/common.c index 886dd2aaff0d..837067f48a4c 100644 --- a/tools/perf/arch/common.c +++ b/tools/perf/arch/common.c @@ -4,6 +4,8 @@ #include "../util/util.h" #include "../util/debug.h" +#include "sane_ctype.h" + const char *const arm_triplets[] = { "arm-eabi-", "arm-linux-androideabi-", diff --git a/tools/perf/arch/powerpc/util/dwarf-regs.c b/tools/perf/arch/powerpc/util/dwarf-regs.c index 41bdf9530d82..98ac87052a74 100644 --- a/tools/perf/arch/powerpc/util/dwarf-regs.c +++ b/tools/perf/arch/powerpc/util/dwarf-regs.c @@ -15,6 +15,7 @@ #include <dwarf-regs.h> #include <linux/ptrace.h> #include <linux/kernel.h> +#include <linux/stringify.h> #include "util.h" struct pt_regs_dwarfnum { @@ -24,10 +25,10 @@ struct pt_regs_dwarfnum { }; #define REG_DWARFNUM_NAME(r, num) \ - {.name = STR(%)STR(r), .dwarfnum = num, \ + {.name = __stringify(%)__stringify(r), .dwarfnum = num, \ .ptregs_offset = offsetof(struct pt_regs, r)} #define GPR_DWARFNUM_NAME(num) \ - {.name = STR(%gpr##num), .dwarfnum = num, \ + {.name = __stringify(%gpr##num), .dwarfnum = num, \ .ptregs_offset = offsetof(struct pt_regs, gpr[num])} #define REG_DWARFNUM_END {.name = NULL, .dwarfnum = 0, .ptregs_offset = 0} diff --git a/tools/perf/arch/powerpc/util/kvm-stat.c b/tools/perf/arch/powerpc/util/kvm-stat.c index 74eee30398f8..249723f0e6a9 100644 --- a/tools/perf/arch/powerpc/util/kvm-stat.c +++ b/tools/perf/arch/powerpc/util/kvm-stat.c @@ -1,3 +1,4 @@ +#include <errno.h> #include "util/kvm-stat.h" #include "util/parse-events.h" #include "util/debug.h" diff --git a/tools/perf/arch/powerpc/util/perf_regs.c b/tools/perf/arch/powerpc/util/perf_regs.c index 4268f7762e25..f860dc411f69 100644 --- a/tools/perf/arch/powerpc/util/perf_regs.c +++ b/tools/perf/arch/powerpc/util/perf_regs.c @@ -1,3 +1,4 @@ +#include <errno.h> #include <string.h> #include <regex.h> diff --git a/tools/perf/arch/s390/util/kvm-stat.c b/tools/perf/arch/s390/util/kvm-stat.c index ed57df2e6d68..d233e2eb9592 100644 --- a/tools/perf/arch/s390/util/kvm-stat.c +++ b/tools/perf/arch/s390/util/kvm-stat.c @@ -9,6 +9,7 @@ * as published by the Free Software Foundation. */ +#include <errno.h> #include "../../util/kvm-stat.h" #include <asm/sie.h> diff --git a/tools/perf/arch/x86/tests/intel-cqm.c b/tools/perf/arch/x86/tests/intel-cqm.c index 7f064eb37158..f9713a71d77e 100644 --- a/tools/perf/arch/x86/tests/intel-cqm.c +++ b/tools/perf/arch/x86/tests/intel-cqm.c @@ -6,7 +6,10 @@ #include "evsel.h" #include "arch-tests.h" +#include <signal.h> #include <sys/mman.h> +#include <sys/wait.h> +#include <errno.h> #include <string.h> static pid_t spawn(void) diff --git a/tools/perf/arch/x86/tests/perf-time-to-tsc.c b/tools/perf/arch/x86/tests/perf-time-to-tsc.c index 5c76cc83186a..e3ae9cff2b67 100644 --- a/tools/perf/arch/x86/tests/perf-time-to-tsc.c +++ b/tools/perf/arch/x86/tests/perf-time-to-tsc.c @@ -1,3 +1,5 @@ +#include <errno.h> +#include <inttypes.h> #include <stdio.h> #include <unistd.h> #include <linux/types.h> diff --git a/tools/perf/arch/x86/util/auxtrace.c b/tools/perf/arch/x86/util/auxtrace.c index cc1d865e31f1..6aa3f2a38321 100644 --- a/tools/perf/arch/x86/util/auxtrace.c +++ b/tools/perf/arch/x86/util/auxtrace.c @@ -13,6 +13,7 @@ * */ +#include <errno.h> #include <stdbool.h> #include "../../util/header.h" diff --git a/tools/perf/arch/x86/util/intel-bts.c b/tools/perf/arch/x86/util/intel-bts.c index 5132775a044f..af2bce7a2cd6 100644 --- a/tools/perf/arch/x86/util/intel-bts.c +++ b/tools/perf/arch/x86/util/intel-bts.c @@ -13,6 +13,7 @@ * */ +#include <errno.h> #include <linux/kernel.h> #include <linux/types.h> #include <linux/bitops.h> diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c index 90fa2286edcf..f630de0206a1 100644 --- a/tools/perf/arch/x86/util/intel-pt.c +++ b/tools/perf/arch/x86/util/intel-pt.c @@ -13,6 +13,7 @@ * */ +#include <errno.h> #include <stdbool.h> #include <linux/kernel.h> #include <linux/types.h> diff --git a/tools/perf/arch/x86/util/kvm-stat.c b/tools/perf/arch/x86/util/kvm-stat.c index b63d4be655a2..bf817beca0a8 100644 --- a/tools/perf/arch/x86/util/kvm-stat.c +++ b/tools/perf/arch/x86/util/kvm-stat.c @@ -1,3 +1,4 @@ +#include <errno.h> #include "../../util/kvm-stat.h" #include <asm/svm.h> #include <asm/vmx.h> diff --git a/tools/perf/arch/x86/util/perf_regs.c b/tools/perf/arch/x86/util/perf_regs.c index 3bf3548c5e2d..f95edebfb716 100644 --- a/tools/perf/arch/x86/util/perf_regs.c +++ b/tools/perf/arch/x86/util/perf_regs.c @@ -1,3 +1,4 @@ +#include <errno.h> #include <string.h> #include <regex.h> diff --git a/tools/perf/arch/x86/util/unwind-libdw.c b/tools/perf/arch/x86/util/unwind-libdw.c index c4b72176ca83..38dc9bb2a7c9 100644 --- a/tools/perf/arch/x86/util/unwind-libdw.c +++ b/tools/perf/arch/x86/util/unwind-libdw.c @@ -1,6 +1,7 @@ #include <elfutils/libdwfl.h> #include "../../util/unwind-libdw.h" #include "../../util/perf_regs.h" +#include "../../util/event.h" bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg) { diff --git a/tools/perf/bench/mem-functions.c b/tools/perf/bench/mem-functions.c index d1dea33dcfcf..fbd732b54047 100644 --- a/tools/perf/bench/mem-functions.c +++ b/tools/perf/bench/mem-functions.c @@ -12,6 +12,7 @@ #include <subcmd/parse-options.h> #include "../util/header.h" #include "../util/cloexec.h" +#include "../util/string2.h" #include "bench.h" #include "mem-memcpy-arch.h" #include "mem-memset-arch.h" diff --git a/tools/perf/bench/numa.c b/tools/perf/bench/numa.c index 1fe43bd5a012..27de0c8c5c19 100644 --- a/tools/perf/bench/numa.c +++ b/tools/perf/bench/numa.c @@ -4,6 +4,7 @@ * numa: Simulate NUMA-sensitive workload and measure their NUMA performance */ +#include <inttypes.h> /* For the CLR_() macros */ #include <pthread.h> @@ -30,6 +31,7 @@ #include <sys/wait.h> #include <sys/prctl.h> #include <sys/types.h> +#include <linux/kernel.h> #include <linux/time64.h> #include <numa.h> diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index b2b2722f6bb7..7a5dc7e5c577 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -33,6 +33,7 @@ #include "util/block-range.h" #include <dlfcn.h> +#include <errno.h> #include <linux/bitmap.h> struct perf_annotate { diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c index 94b55eee0d9b..64b44e81c771 100644 --- a/tools/perf/builtin-buildid-cache.c +++ b/tools/perf/builtin-buildid-cache.c @@ -10,6 +10,7 @@ #include <sys/time.h> #include <time.h> #include <dirent.h> +#include <errno.h> #include <unistd.h> #include "builtin.h" #include "perf.h" @@ -21,6 +22,7 @@ #include "util/build-id.h" #include "util/session.h" #include "util/symbol.h" +#include "util/time-utils.h" static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuildid) { diff --git a/tools/perf/builtin-buildid-list.c b/tools/perf/builtin-buildid-list.c index 26f4e608207f..fdaca16e0c74 100644 --- a/tools/perf/builtin-buildid-list.c +++ b/tools/perf/builtin-buildid-list.c @@ -16,6 +16,7 @@ #include "util/session.h" #include "util/symbol.h" #include "util/data.h" +#include <errno.h> static int sysfs__fprintf_build_id(FILE *fp) { diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index 70c2c773a2b8..e33b4acece90 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -9,10 +9,13 @@ * Dick Fowles <fowles@inreach.com> * Joe Mario <jmario@redhat.com> */ +#include <errno.h> +#include <inttypes.h> #include <linux/compiler.h> #include <linux/kernel.h> #include <linux/stringify.h> #include <asm/bug.h> +#include <sys/param.h> #include "util.h" #include "debug.h" #include "builtin.h" @@ -29,6 +32,7 @@ #include <asm/bug.h> #include "ui/browsers/hists.h" #include "evlist.h" +#include "thread.h" struct c2c_hists { struct hists hists; diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index cd2605d86984..eec5df80f5a3 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c @@ -19,6 +19,8 @@ #include "util/data.h" #include "util/config.h" +#include <errno.h> +#include <inttypes.h> #include <stdlib.h> #include <math.h> diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c index f80fb60b00b0..9e0b35cd0eea 100644 --- a/tools/perf/builtin-ftrace.c +++ b/tools/perf/builtin-ftrace.c @@ -9,12 +9,15 @@ #include "builtin.h" #include "perf.h" +#include <errno.h> #include <unistd.h> #include <signal.h> #include <fcntl.h> +#include <poll.h> #include "debug.h" #include <subcmd/parse-options.h> +#include <api/fs/tracing_path.h> #include "evlist.h" #include "target.h" #include "cpumap.h" diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c index 1eec96a0fa67..492f8e14ab09 100644 --- a/tools/perf/builtin-help.c +++ b/tools/perf/builtin-help.c @@ -12,16 +12,22 @@ #include <subcmd/run-command.h> #include <subcmd/help.h> #include "util/debug.h" +#include <linux/kernel.h> +#include <errno.h> +#include <stdio.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> static struct man_viewer_list { struct man_viewer_list *next; - char name[FLEX_ARRAY]; + char name[0]; } *man_viewer_list; static struct man_viewer_info_list { struct man_viewer_info_list *next; const char *info; - char name[FLEX_ARRAY]; + char name[0]; } *man_viewer_info_list; enum help_format { diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 65e1c026a2f0..ea8db38eedd1 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -18,10 +18,13 @@ #include "util/data.h" #include "util/auxtrace.h" #include "util/jit.h" +#include "util/thread.h" #include <subcmd/parse-options.h> #include <linux/list.h> +#include <errno.h> +#include <signal.h> struct perf_inject { struct perf_tool tool; diff --git a/tools/perf/builtin-kallsyms.c b/tools/perf/builtin-kallsyms.c index 8ff38c4eb2c0..bcfb363112d3 100644 --- a/tools/perf/builtin-kallsyms.c +++ b/tools/perf/builtin-kallsyms.c @@ -7,6 +7,7 @@ * * Released under the GPL v2. (and only v2, not any later version) */ +#include <inttypes.h> #include "builtin.h" #include <linux/compiler.h> #include <subcmd/parse-options.h> diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index 515587825af4..9409c9464667 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -20,11 +20,16 @@ #include "util/debug.h" +#include <linux/kernel.h> #include <linux/rbtree.h> #include <linux/string.h> +#include <errno.h> +#include <inttypes.h> #include <locale.h> #include <regex.h> +#include "sane_ctype.h" + static int kmem_slab; static int kmem_page; diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 38b409173693..f309c3773522 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -3,6 +3,7 @@ #include "util/evsel.h" #include "util/evlist.h" +#include "util/term.h" #include "util/util.h" #include "util/cache.h" #include "util/symbol.h" @@ -23,13 +24,33 @@ #ifdef HAVE_TIMERFD_SUPPORT #include <sys/timerfd.h> #endif +#include <sys/time.h> +#include <linux/kernel.h> #include <linux/time64.h> +#include <errno.h> +#include <inttypes.h> +#include <poll.h> #include <termios.h> #include <semaphore.h> +#include <signal.h> #include <pthread.h> #include <math.h> +static const char *get_filename_for_perf_kvm(void) +{ + const char *filename; + + if (perf_host && !perf_guest) + filename = strdup("perf.data.host"); + else if (!perf_host && perf_guest) + filename = strdup("perf.data.guest"); + else + filename = strdup("perf.data.kvm"); + + return filename; +} + #ifdef HAVE_KVM_STAT_SUPPORT #include "util/kvm-stat.h" diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index b686fb6759da..ff98652484a7 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -1,3 +1,5 @@ +#include <errno.h> +#include <inttypes.h> #include "builtin.h" #include "perf.h" @@ -26,6 +28,7 @@ #include <linux/list.h> #include <linux/hash.h> +#include <linux/kernel.h> static struct perf_session *session; diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c index 643f4faac0d0..e001c0290793 100644 --- a/tools/perf/builtin-mem.c +++ b/tools/perf/builtin-mem.c @@ -1,3 +1,7 @@ +#include <inttypes.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> #include "builtin.h" #include "perf.h" @@ -8,6 +12,7 @@ #include "util/data.h" #include "util/mem-events.h" #include "util/debug.h" +#include "util/symbol.h" #define MEM_OPERATION_LOAD 0x1 #define MEM_OPERATION_STORE 0x2 diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 3191ab063852..ee7d0a82ccd0 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -38,11 +38,18 @@ #include "util/bpf-loader.h" #include "util/trigger.h" #include "util/perf-hooks.h" +#include "util/time-utils.h" +#include "util/units.h" #include "asm/bug.h" +#include <errno.h> +#include <inttypes.h> +#include <poll.h> #include <unistd.h> #include <sched.h> +#include <signal.h> #include <sys/mman.h> +#include <sys/wait.h> #include <asm/bug.h> #include <linux/time64.h> diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index c18158b83eb1..22478ff2b706 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -16,7 +16,6 @@ #include <linux/rbtree.h> #include "util/symbol.h" #include "util/callchain.h" -#include "util/strlist.h" #include "util/values.h" #include "perf.h" @@ -38,10 +37,18 @@ #include "arch/common.h" #include "util/time-utils.h" #include "util/auxtrace.h" +#include "util/units.h" #include <dlfcn.h> +#include <errno.h> +#include <inttypes.h> +#include <regex.h> +#include <signal.h> #include <linux/bitmap.h> #include <linux/stringify.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> struct report { struct perf_tool tool; diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 79833e226789..39996c53995a 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -22,16 +22,21 @@ #include "util/debug.h" +#include <linux/kernel.h> #include <linux/log2.h> #include <sys/prctl.h> #include <sys/resource.h> +#include <inttypes.h> +#include <errno.h> #include <semaphore.h> #include <pthread.h> #include <math.h> #include <api/fs/fs.h> #include <linux/time64.h> +#include "sane_ctype.h" + #define PR_SET_NAME 15 /* Set process name */ #define MAX_CPUS 4096 #define COMM_LEN 20 diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 2dab70fba2ba..d05aec491cff 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -21,14 +21,27 @@ #include "util/cpumap.h" #include "util/thread_map.h" #include "util/stat.h" +#include "util/string2.h" #include "util/thread-stack.h" #include "util/time-utils.h" +#include "print_binary.h" #include <linux/bitmap.h> +#include <linux/kernel.h> #include <linux/stringify.h> #include <linux/time64.h> #include "asm/bug.h" #include "util/mem-events.h" #include "util/dump-insn.h" +#include <dirent.h> +#include <errno.h> +#include <inttypes.h> +#include <signal.h> +#include <sys/param.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> + +#include "sane_ctype.h" static char const *script_name; static char const *generate_script_lang; diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 610225b6326e..a935b5023732 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -64,14 +64,24 @@ #include "util/session.h" #include "util/tool.h" #include "util/group.h" +#include "util/string2.h" #include "asm/bug.h" #include <linux/time64.h> #include <api/fs/fs.h> +#include <errno.h> +#include <signal.h> #include <stdlib.h> #include <sys/prctl.h> +#include <inttypes.h> #include <locale.h> #include <math.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/wait.h> +#include <unistd.h> + +#include "sane_ctype.h" #define DEFAULT_SEPARATOR " " #define CNTR_NOT_SUPPORTED "<not supported>" diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c index fafdb44b8bcb..4e2e61695986 100644 --- a/tools/perf/builtin-timechart.c +++ b/tools/perf/builtin-timechart.c @@ -12,6 +12,8 @@ * of the License. */ +#include <errno.h> +#include <inttypes.h> #include <traceevent/event-parse.h> #include "builtin.h" @@ -23,11 +25,12 @@ #include "util/cache.h" #include "util/evlist.h" #include "util/evsel.h" +#include <linux/kernel.h> #include <linux/rbtree.h> #include <linux/time64.h> #include "util/symbol.h" +#include "util/thread.h" #include "util/callchain.h" -#include "util/strlist.h" #include "perf.h" #include "util/header.h" diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index a0c97c70ec81..7ab42b8311a1 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -40,6 +40,7 @@ #include "util/cpumap.h" #include "util/xyarray.h" #include "util/sort.h" +#include "util/term.h" #include "util/intlist.h" #include "util/parse-branch-options.h" #include "arch/common.h" @@ -58,6 +59,7 @@ #include <errno.h> #include <time.h> #include <sched.h> +#include <signal.h> #include <sys/syscall.h> #include <sys/ioctl.h> @@ -72,6 +74,8 @@ #include <linux/time64.h> #include <linux/types.h> +#include "sane_ctype.h" + static volatile int done; #define HEADER_LINE_NR 5 diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index fce278d5fada..eaa66fb57347 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -24,6 +24,7 @@ #include "util/evlist.h" #include <subcmd/exec-cmd.h> #include "util/machine.h" +#include "util/path.h" #include "util/session.h" #include "util/thread.h" #include <subcmd/parse-options.h> @@ -36,19 +37,28 @@ #include "util/parse-events.h" #include "util/bpf-loader.h" #include "callchain.h" +#include "print_binary.h" +#include "string2.h" #include "syscalltbl.h" #include "rb_resort.h" +#include <errno.h> +#include <inttypes.h> #include <libaudit.h> /* FIXME: Still needed for audit_errno_to_name */ +#include <poll.h> +#include <signal.h> #include <stdlib.h> #include <string.h> #include <linux/err.h> #include <linux/filter.h> #include <linux/audit.h> +#include <linux/kernel.h> #include <linux/random.h> #include <linux/stringify.h> #include <linux/time64.h> +#include "sane_ctype.h" + #ifndef O_CLOEXEC # define O_CLOEXEC 02000000 #endif diff --git a/tools/perf/builtin-version.c b/tools/perf/builtin-version.c index b9a095b1db99..d25149456a2f 100644 --- a/tools/perf/builtin-version.c +++ b/tools/perf/builtin-version.c @@ -1,6 +1,7 @@ -#include "util/util.h" #include "builtin.h" #include "perf.h" +#include <linux/compiler.h> +#include <stdio.h> int cmd_version(int argc __maybe_unused, const char **argv __maybe_unused) { diff --git a/tools/perf/builtin.h b/tools/perf/builtin.h index 26669bf9129c..d4d19fe3d050 100644 --- a/tools/perf/builtin.h +++ b/tools/perf/builtin.h @@ -2,16 +2,12 @@ #define BUILTIN_H #include "util/util.h" -#include "util/strbuf.h" extern const char perf_usage_string[]; extern const char perf_more_info_string[]; void list_common_cmds_help(void); const char *help_unknown_cmd(const char *cmd); -void prune_packed_objects(int); -int read_line_with_nul(char *buf, int size, FILE *file); -int check_pager_config(const char *cmd); int cmd_annotate(int argc, const char **argv); int cmd_bench(int argc, const char **argv); diff --git a/tools/perf/perf.c b/tools/perf/perf.c index 9dc346f2b255..4cc6960f6226 100644 --- a/tools/perf/perf.c +++ b/tools/perf/perf.c @@ -19,9 +19,15 @@ #include "util/debug.h" #include <api/fs/fs.h> #include <api/fs/tracing_path.h> +#include <errno.h> #include <pthread.h> +#include <signal.h> #include <stdlib.h> #include <time.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <linux/kernel.h> const char perf_usage_string[] = "perf [--version] [--help] [OPTIONS] COMMAND [ARGS]"; @@ -88,7 +94,7 @@ static int pager_command_config(const char *var, const char *value, void *data) } /* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */ -int check_pager_config(const char *cmd) +static int check_pager_config(const char *cmd) { int err; struct pager_config c; @@ -327,16 +333,6 @@ static void handle_internal_command(int argc, const char **argv) { const char *cmd = argv[0]; unsigned int i; - static const char ext[] = STRIP_EXTENSION; - - if (sizeof(ext) > 1) { - i = strlen(argv[0]) - strlen(ext); - if (i > 0 && !strcmp(argv[0] + i, ext)) { - char *argv0 = strdup(argv[0]); - argv[0] = cmd = argv0; - argv0[i] = '\0'; - } - } /* Turn "perf cmd --help" into "perf help cmd" */ if (argc > 1 && !strcmp(argv[1], "--help")) { diff --git a/tools/perf/tests/attr.c b/tools/perf/tests/attr.c index 88dc51f4c27b..0dd77494bb58 100644 --- a/tools/perf/tests/attr.c +++ b/tools/perf/tests/attr.c @@ -18,10 +18,16 @@ * permissions. All the event text files are stored there. */ +#include <errno.h> +#include <inttypes.h> #include <stdlib.h> #include <stdio.h> #include <linux/types.h> #include <linux/kernel.h> +#include <sys/param.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> #include "../perf.h" #include "util.h" #include <subcmd/exec-cmd.h> diff --git a/tools/perf/tests/backward-ring-buffer.c b/tools/perf/tests/backward-ring-buffer.c index 42e892b1e979..50f6d7afee58 100644 --- a/tools/perf/tests/backward-ring-buffer.c +++ b/tools/perf/tests/backward-ring-buffer.c @@ -8,6 +8,7 @@ #include <sys/prctl.h> #include "tests.h" #include "debug.h" +#include <errno.h> #define NR_ITERS 111 diff --git a/tools/perf/tests/bpf.c b/tools/perf/tests/bpf.c index 1a04fe77487d..5876da126b58 100644 --- a/tools/perf/tests/bpf.c +++ b/tools/perf/tests/bpf.c @@ -1,10 +1,14 @@ +#include <errno.h> #include <stdio.h> #include <sys/epoll.h> +#include <sys/types.h> +#include <sys/stat.h> #include <util/util.h> #include <util/bpf-loader.h> #include <util/evlist.h> #include <linux/bpf.h> #include <linux/filter.h> +#include <linux/kernel.h> #include <api/fs/fs.h> #include <bpf/bpf.h> #include "tests.h" diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c index e6d7876c94c2..9e08d297f1a9 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -3,8 +3,10 @@ * * Builtin regression testing command: ever growing number of sanity tests */ +#include <errno.h> #include <unistd.h> #include <string.h> +#include <sys/wait.h> #include "builtin.h" #include "hist.h" #include "intlist.h" @@ -13,6 +15,7 @@ #include "color.h" #include <subcmd/parse-options.h> #include "symbol.h" +#include <linux/kernel.h> static bool dont_fork; diff --git a/tools/perf/tests/clang.c b/tools/perf/tests/clang.c index f853e242a86c..c5bb2203f5a9 100644 --- a/tools/perf/tests/clang.c +++ b/tools/perf/tests/clang.c @@ -2,6 +2,7 @@ #include "debug.h" #include "util.h" #include "c++/clang-c.h" +#include <linux/kernel.h> static struct { int (*func)(void); diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c index d1f693041324..1f14e7612cbb 100644 --- a/tools/perf/tests/code-reading.c +++ b/tools/perf/tests/code-reading.c @@ -1,9 +1,12 @@ +#include <errno.h> +#include <linux/kernel.h> #include <linux/types.h> +#include <inttypes.h> #include <stdlib.h> #include <unistd.h> #include <stdio.h> -#include <ctype.h> #include <string.h> +#include <sys/param.h> #include "parse-events.h" #include "evlist.h" @@ -16,6 +19,8 @@ #include "tests.h" +#include "sane_ctype.h" + #define BUFSZ 1024 #define READLEN 128 diff --git a/tools/perf/tests/dso-data.c b/tools/perf/tests/dso-data.c index 13725e09ba22..8f08df5861cb 100644 --- a/tools/perf/tests/dso-data.c +++ b/tools/perf/tests/dso-data.c @@ -1,4 +1,6 @@ +#include <dirent.h> #include <stdlib.h> +#include <linux/kernel.h> #include <linux/types.h> #include <sys/stat.h> #include <fcntl.h> diff --git a/tools/perf/tests/dwarf-unwind.c b/tools/perf/tests/dwarf-unwind.c index 1046491de4b2..dfe5c89e2049 100644 --- a/tools/perf/tests/dwarf-unwind.c +++ b/tools/perf/tests/dwarf-unwind.c @@ -1,5 +1,6 @@ #include <linux/compiler.h> #include <linux/types.h> +#include <inttypes.h> #include <unistd.h> #include "tests.h" #include "debug.h" diff --git a/tools/perf/tests/event-times.c b/tools/perf/tests/event-times.c index 19ef77bd6eb4..634f20c631d8 100644 --- a/tools/perf/tests/event-times.c +++ b/tools/perf/tests/event-times.c @@ -1,5 +1,8 @@ #include <linux/compiler.h> +#include <errno.h> +#include <inttypes.h> #include <string.h> +#include <sys/wait.h> #include "tests.h" #include "evlist.h" #include "evsel.h" diff --git a/tools/perf/tests/evsel-roundtrip-name.c b/tools/perf/tests/evsel-roundtrip-name.c index 60926a1f6fd7..d2bea6f780f8 100644 --- a/tools/perf/tests/evsel-roundtrip-name.c +++ b/tools/perf/tests/evsel-roundtrip-name.c @@ -3,6 +3,8 @@ #include "parse-events.h" #include "tests.h" #include "debug.h" +#include <errno.h> +#include <linux/kernel.h> static int perf_evsel__roundtrip_cache_name_test(void) { diff --git a/tools/perf/tests/hists_common.c b/tools/perf/tests/hists_common.c index 6b21746d6eec..00b8dc50f3db 100644 --- a/tools/perf/tests/hists_common.c +++ b/tools/perf/tests/hists_common.c @@ -1,3 +1,4 @@ +#include <inttypes.h> #include "perf.h" #include "util/debug.h" #include "util/symbol.h" @@ -7,6 +8,7 @@ #include "util/machine.h" #include "util/thread.h" #include "tests/hists_common.h" +#include <linux/kernel.h> static struct { u32 pid; diff --git a/tools/perf/tests/hists_cumulate.c b/tools/perf/tests/hists_cumulate.c index 9fd54b79a788..70918b986568 100644 --- a/tools/perf/tests/hists_cumulate.c +++ b/tools/perf/tests/hists_cumulate.c @@ -9,6 +9,7 @@ #include "util/parse-events.h" #include "tests/tests.h" #include "tests/hists_common.h" +#include <linux/kernel.h> struct sample { u32 pid; diff --git a/tools/perf/tests/hists_filter.c b/tools/perf/tests/hists_filter.c index 62efb14f3a5a..f171b2da4899 100644 --- a/tools/perf/tests/hists_filter.c +++ b/tools/perf/tests/hists_filter.c @@ -9,6 +9,7 @@ #include "util/parse-events.h" #include "tests/tests.h" #include "tests/hists_common.h" +#include <linux/kernel.h> struct sample { u32 pid; diff --git a/tools/perf/tests/hists_link.c b/tools/perf/tests/hists_link.c index eddc7407ff8a..a26cbb79e988 100644 --- a/tools/perf/tests/hists_link.c +++ b/tools/perf/tests/hists_link.c @@ -9,6 +9,8 @@ #include "thread.h" #include "parse-events.h" #include "hists_common.h" +#include <errno.h> +#include <linux/kernel.h> struct sample { u32 pid; diff --git a/tools/perf/tests/hists_output.c b/tools/perf/tests/hists_output.c index 63c5efaba1b5..cdf0dde5fe97 100644 --- a/tools/perf/tests/hists_output.c +++ b/tools/perf/tests/hists_output.c @@ -9,6 +9,7 @@ #include "util/parse-events.h" #include "tests/tests.h" #include "tests/hists_common.h" +#include <linux/kernel.h> struct sample { u32 cpu; diff --git a/tools/perf/tests/is_printable_array.c b/tools/perf/tests/is_printable_array.c index 42e13393e502..a5192f6a20d7 100644 --- a/tools/perf/tests/is_printable_array.c +++ b/tools/perf/tests/is_printable_array.c @@ -1,7 +1,8 @@ #include <linux/compiler.h> +#include <linux/kernel.h> #include "tests.h" #include "debug.h" -#include "util.h" +#include "print_binary.h" int test__is_printable_array(int subtest __maybe_unused) { diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c index 634bce9caebd..15c770856aac 100644 --- a/tools/perf/tests/mmap-basic.c +++ b/tools/perf/tests/mmap-basic.c @@ -1,3 +1,5 @@ +#include <errno.h> +#include <inttypes.h> /* For the CLR_() macros */ #include <pthread.h> @@ -7,6 +9,7 @@ #include "cpumap.h" #include "tests.h" #include <linux/err.h> +#include <linux/kernel.h> /* * This test will generate random numbers of calls to some getpid syscalls, diff --git a/tools/perf/tests/mmap-thread-lookup.c b/tools/perf/tests/mmap-thread-lookup.c index 0c5ce44f723f..6ea4d8a5d26b 100644 --- a/tools/perf/tests/mmap-thread-lookup.c +++ b/tools/perf/tests/mmap-thread-lookup.c @@ -1,3 +1,4 @@ +#include <inttypes.h> #include <unistd.h> #include <sys/syscall.h> #include <sys/types.h> @@ -11,6 +12,7 @@ #include "thread_map.h" #include "symbol.h" #include "thread.h" +#include "util.h" #define THREADS 4 diff --git a/tools/perf/tests/openat-syscall-all-cpus.c b/tools/perf/tests/openat-syscall-all-cpus.c index c8d9592eb142..1a74dd9fd067 100644 --- a/tools/perf/tests/openat-syscall-all-cpus.c +++ b/tools/perf/tests/openat-syscall-all-cpus.c @@ -1,8 +1,14 @@ +#include <errno.h> +#include <inttypes.h> /* For the CPU_* macros */ #include <pthread.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> #include <api/fs/fs.h> #include <linux/err.h> +#include <api/fs/tracing_path.h> #include "evsel.h" #include "tests.h" #include "thread_map.h" diff --git a/tools/perf/tests/openat-syscall-tp-fields.c b/tools/perf/tests/openat-syscall-tp-fields.c index f52239fed361..9788fac91095 100644 --- a/tools/perf/tests/openat-syscall-tp-fields.c +++ b/tools/perf/tests/openat-syscall-tp-fields.c @@ -5,6 +5,7 @@ #include "thread_map.h" #include "tests.h" #include "debug.h" +#include <errno.h> #ifndef O_DIRECTORY #define O_DIRECTORY 00200000 diff --git a/tools/perf/tests/openat-syscall.c b/tools/perf/tests/openat-syscall.c index d7414128d7fe..e44506e21ee7 100644 --- a/tools/perf/tests/openat-syscall.c +++ b/tools/perf/tests/openat-syscall.c @@ -1,5 +1,10 @@ +#include <errno.h> +#include <inttypes.h> #include <api/fs/tracing_path.h> #include <linux/err.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> #include "thread_map.h" #include "evsel.h" #include "debug.h" diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c index 1dc838014422..7fad885491c5 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c @@ -1,4 +1,3 @@ - #include "parse-events.h" #include "evsel.h" #include "evlist.h" @@ -6,8 +5,15 @@ #include "tests.h" #include "debug.h" #include "util.h" +#include <dirent.h> +#include <errno.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <linux/kernel.h> #include <linux/hw_breakpoint.h> #include <api/fs/fs.h> +#include <api/fs/tracing_path.h> #define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \ PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD) diff --git a/tools/perf/tests/parse-no-sample-id-all.c b/tools/perf/tests/parse-no-sample-id-all.c index 65dcf48a92fb..c6207db09f12 100644 --- a/tools/perf/tests/parse-no-sample-id-all.c +++ b/tools/perf/tests/parse-no-sample-id-all.c @@ -1,3 +1,4 @@ +#include <linux/kernel.h> #include <linux/types.h> #include <stddef.h> diff --git a/tools/perf/tests/perf-record.c b/tools/perf/tests/perf-record.c index 87893f3ba5f1..d37cd9588cc0 100644 --- a/tools/perf/tests/perf-record.c +++ b/tools/perf/tests/perf-record.c @@ -1,3 +1,5 @@ +#include <errno.h> +#include <inttypes.h> /* For the CLR_() macros */ #include <pthread.h> diff --git a/tools/perf/tests/pmu.c b/tools/perf/tests/pmu.c index 1e2ba2602930..a6d7aef30030 100644 --- a/tools/perf/tests/pmu.c +++ b/tools/perf/tests/pmu.c @@ -2,6 +2,8 @@ #include "pmu.h" #include "util.h" #include "tests.h" +#include <errno.h> +#include <linux/kernel.h> /* Simulated format definitions. */ static struct test_format { diff --git a/tools/perf/tests/sample-parsing.c b/tools/perf/tests/sample-parsing.c index 5f23710b9fee..bac5c3885b3b 100644 --- a/tools/perf/tests/sample-parsing.c +++ b/tools/perf/tests/sample-parsing.c @@ -1,4 +1,6 @@ #include <stdbool.h> +#include <inttypes.h> +#include <linux/kernel.h> #include <linux/types.h> #include "util.h" diff --git a/tools/perf/tests/sdt.c b/tools/perf/tests/sdt.c index 26e5b7a0b839..f73b3c5e125d 100644 --- a/tools/perf/tests/sdt.c +++ b/tools/perf/tests/sdt.c @@ -1,3 +1,4 @@ +#include <errno.h> #include <stdio.h> #include <sys/epoll.h> #include <util/util.h> diff --git a/tools/perf/tests/sw-clock.c b/tools/perf/tests/sw-clock.c index 4c9fd046d57b..828494db4a19 100644 --- a/tools/perf/tests/sw-clock.c +++ b/tools/perf/tests/sw-clock.c @@ -1,3 +1,5 @@ +#include <errno.h> +#include <inttypes.h> #include <unistd.h> #include <stdlib.h> #include <signal.h> diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-tracking.c index 7ddbe267d0ac..65474fd80da7 100644 --- a/tools/perf/tests/switch-tracking.c +++ b/tools/perf/tests/switch-tracking.c @@ -1,5 +1,6 @@ #include <sys/time.h> #include <sys/prctl.h> +#include <errno.h> #include <time.h> #include <stdlib.h> diff --git a/tools/perf/tests/task-exit.c b/tools/perf/tests/task-exit.c index 01a5ba2788c6..32873ec91a4e 100644 --- a/tools/perf/tests/task-exit.c +++ b/tools/perf/tests/task-exit.c @@ -4,6 +4,7 @@ #include "cpumap.h" #include "tests.h" +#include <errno.h> #include <signal.h> static int exited; diff --git a/tools/perf/tests/unit_number__scnprintf.c b/tools/perf/tests/unit_number__scnprintf.c index 623c2aa53c4a..44589de084b8 100644 --- a/tools/perf/tests/unit_number__scnprintf.c +++ b/tools/perf/tests/unit_number__scnprintf.c @@ -1,7 +1,8 @@ +#include <inttypes.h> #include <linux/compiler.h> #include <linux/types.h> #include "tests.h" -#include "util.h" +#include "units.h" #include "debug.h" int test__unit_number__scnprint(int subtest __maybe_unused) diff --git a/tools/perf/tests/vmlinux-kallsyms.c b/tools/perf/tests/vmlinux-kallsyms.c index 862b043e5924..8456175fc234 100644 --- a/tools/perf/tests/vmlinux-kallsyms.c +++ b/tools/perf/tests/vmlinux-kallsyms.c @@ -1,5 +1,6 @@ #include <linux/compiler.h> #include <linux/rbtree.h> +#include <inttypes.h> #include <string.h> #include "map.h" #include "symbol.h" diff --git a/tools/perf/trace/beauty/signum.c b/tools/perf/trace/beauty/signum.c index d3b0b1fab077..fde8f2fc6558 100644 --- a/tools/perf/trace/beauty/signum.c +++ b/tools/perf/trace/beauty/signum.c @@ -1,3 +1,4 @@ +#include <signal.h> static size_t syscall_arg__scnprintf_signum(char *bf, size_t size, struct syscall_arg *arg) { diff --git a/tools/perf/ui/browser.c b/tools/perf/ui/browser.c index 9e47ccbe07f1..a4d3762cd825 100644 --- a/tools/perf/ui/browser.c +++ b/tools/perf/ui/browser.c @@ -1,4 +1,5 @@ #include "../util.h" +#include "../string2.h" #include "../config.h" #include "../../perf.h" #include "libslang.h" @@ -13,6 +14,7 @@ #include "helpline.h" #include "keysyms.h" #include "../color.h" +#include "sane_ctype.h" static int ui_browser__percent_color(struct ui_browser *browser, double percent, bool current) diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c index ba36aac340bc..d990ad08a3c6 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -9,7 +9,10 @@ #include "../../util/symbol.h" #include "../../util/evsel.h" #include "../../util/config.h" +#include <inttypes.h> #include <pthread.h> +#include <linux/kernel.h> +#include <sys/ttydefaults.h> struct disasm_line_samples { double percent; diff --git a/tools/perf/ui/browsers/header.c b/tools/perf/ui/browsers/header.c index edbeaaf31ace..e2c9390ff4c5 100644 --- a/tools/perf/ui/browsers/header.c +++ b/tools/perf/ui/browsers/header.c @@ -8,6 +8,8 @@ #include "util/header.h" #include "util/session.h" +#include <sys/ttydefaults.h> + static void ui_browser__argv_write(struct ui_browser *browser, void *entry, int row) { diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index da24072bb76e..69f4570bd4f9 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -1,7 +1,11 @@ +#include <dirent.h> +#include <errno.h> +#include <inttypes.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <linux/rbtree.h> +#include <sys/ttydefaults.h> #include "../../util/evsel.h" #include "../../util/evlist.h" @@ -10,6 +14,7 @@ #include "../../util/sort.h" #include "../../util/util.h" #include "../../util/top.h" +#include "../../util/thread.h" #include "../../arch/common.h" #include "../browsers/hists.h" @@ -18,6 +23,11 @@ #include "../ui.h" #include "map.h" #include "annotate.h" +#include "srcline.h" +#include "string2.h" +#include "units.h" + +#include "sane_ctype.h" extern void hist_browser__init_hpp(void); diff --git a/tools/perf/ui/browsers/map.c b/tools/perf/ui/browsers/map.c index 9ce142de536d..ffa5addf631d 100644 --- a/tools/perf/ui/browsers/map.c +++ b/tools/perf/ui/browsers/map.c @@ -11,6 +11,8 @@ #include "../keysyms.h" #include "map.h" +#include "sane_ctype.h" + struct map_browser { struct ui_browser b; struct map *map; diff --git a/tools/perf/ui/gtk/annotate.c b/tools/perf/ui/gtk/annotate.c index 8c9308ac30b7..e99ba86158d2 100644 --- a/tools/perf/ui/gtk/annotate.c +++ b/tools/perf/ui/gtk/annotate.c @@ -3,7 +3,8 @@ #include "util/annotate.h" #include "util/evsel.h" #include "ui/helpline.h" - +#include <inttypes.h> +#include <signal.h> enum { ANN_COL__PERCENT, diff --git a/tools/perf/ui/gtk/hists.c b/tools/perf/ui/gtk/hists.c index a4f02de7c1b5..e24f83957705 100644 --- a/tools/perf/ui/gtk/hists.c +++ b/tools/perf/ui/gtk/hists.c @@ -4,7 +4,9 @@ #include "../sort.h" #include "../hist.h" #include "../helpline.h" +#include "../string2.h" #include "gtk.h" +#include <signal.h> #define MAX_COLUMNS 32 diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c index 5d632dca672a..59addd52d9cd 100644 --- a/tools/perf/ui/hist.c +++ b/tools/perf/ui/hist.c @@ -1,3 +1,4 @@ +#include <inttypes.h> #include <math.h> #include <linux/compiler.h> diff --git a/tools/perf/ui/setup.c b/tools/perf/ui/setup.c index 50d13e58210f..5ea0b40c4fc2 100644 --- a/tools/perf/ui/setup.c +++ b/tools/perf/ui/setup.c @@ -4,6 +4,7 @@ #include "../util/cache.h" #include "../util/debug.h" #include "../util/hist.h" +#include "../util/util.h" pthread_mutex_t ui__lock = PTHREAD_MUTEX_INITIALIZER; void *perf_gtk_handle; diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c index d52d5f64ea89..42e432bd2eb4 100644 --- a/tools/perf/ui/stdio/hist.c +++ b/tools/perf/ui/stdio/hist.c @@ -4,7 +4,10 @@ #include "../../util/hist.h" #include "../../util/sort.h" #include "../../util/evsel.h" - +#include "../../util/srcline.h" +#include "../../util/string2.h" +#include "../../util/thread.h" +#include "../../util/sane_ctype.h" static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin) { diff --git a/tools/perf/ui/tui/setup.c b/tools/perf/ui/tui/setup.c index 4ea2ba861fc2..d9350a1da48b 100644 --- a/tools/perf/ui/tui/setup.c +++ b/tools/perf/ui/tui/setup.c @@ -1,6 +1,7 @@ #include <errno.h> #include <signal.h> #include <stdbool.h> +#include <linux/kernel.h> #ifdef HAVE_BACKTRACE_SUPPORT #include <execinfo.h> #endif diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 5c0ea11a8f0a..069583bdc670 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -16,6 +16,7 @@ libperf-y += llvm-utils.o libperf-y += parse-events.o libperf-y += perf_regs.o libperf-y += path.o +libperf-y += print_binary.o libperf-y += rbtree.o libperf-y += libstring.o libperf-y += bitmap.o @@ -88,6 +89,7 @@ libperf-y += help-unknown-cmd.o libperf-y += mem-events.o libperf-y += vsprintf.o libperf-y += drv_configs.o +libperf-y += units.o libperf-y += time-utils.o libperf-y += expr-bison.o diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 30498a2d4a6f..683f8340460c 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -7,6 +7,8 @@ * Released under the GPL v2. (and only v2, not any later version) */ +#include <errno.h> +#include <inttypes.h> #include "util.h" #include "ui/ui.h" #include "sort.h" @@ -18,12 +20,16 @@ #include "annotate.h" #include "evsel.h" #include "block-range.h" +#include "string2.h" #include "arch/common.h" #include <regex.h> #include <pthread.h> #include <linux/bitops.h> +#include <linux/kernel.h> #include <sys/utsname.h> +#include "sane_ctype.h" + const char *disassembler_style; const char *objdump_path; static regex_t file_lineno; diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c index 78bd632f144d..0daf63b9ee3e 100644 --- a/tools/perf/util/auxtrace.c +++ b/tools/perf/util/auxtrace.c @@ -13,10 +13,10 @@ * */ +#include <inttypes.h> #include <sys/types.h> #include <sys/mman.h> #include <stdbool.h> -#include <ctype.h> #include <string.h> #include <limits.h> #include <errno.h> @@ -46,7 +46,6 @@ #include "cpumap.h" #include "thread_map.h" #include "asm/bug.h" -#include "symbol/kallsyms.h" #include "auxtrace.h" #include <linux/hash.h> @@ -59,6 +58,9 @@ #include "intel-pt.h" #include "intel-bts.h" +#include "sane_ctype.h" +#include "symbol/kallsyms.h" + int auxtrace_mmap__mmap(struct auxtrace_mmap *mm, struct auxtrace_mmap_params *mp, void *userpg, int fd) diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h index 26fb1ee5746a..9f0de72d58e2 100644 --- a/tools/perf/util/auxtrace.h +++ b/tools/perf/util/auxtrace.h @@ -17,6 +17,7 @@ #define __PERF_AUXTRACE_H #include <sys/types.h> +#include <errno.h> #include <stdbool.h> #include <stddef.h> #include <linux/list.h> diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c index bc6bc7062eb4..4bd2d1d882af 100644 --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c @@ -9,7 +9,9 @@ #include <bpf/libbpf.h> #include <bpf/bpf.h> #include <linux/err.h> +#include <linux/kernel.h> #include <linux/string.h> +#include <errno.h> #include "perf.h" #include "debug.h" #include "bpf-loader.h" @@ -17,6 +19,7 @@ #include "probe-event.h" #include "probe-finder.h" // for MAX_PROBES #include "parse-events.h" +#include "strfilter.h" #include "llvm-utils.h" #include "c++/clang-c.h" diff --git a/tools/perf/util/bpf-loader.h b/tools/perf/util/bpf-loader.h index f2b737b225f2..48863867878b 100644 --- a/tools/perf/util/bpf-loader.h +++ b/tools/perf/util/bpf-loader.h @@ -85,6 +85,8 @@ int bpf__strerror_setup_stdout(struct perf_evlist *evlist, int err, char *buf, size_t size); #else +#include <errno.h> + static inline struct bpf_object * bpf__prepare_load(const char *filename __maybe_unused, bool source __maybe_unused) diff --git a/tools/perf/util/bpf-prologue.c b/tools/perf/util/bpf-prologue.c index 6cdbee119ceb..1356220a9f1b 100644 --- a/tools/perf/util/bpf-prologue.c +++ b/tools/perf/util/bpf-prologue.c @@ -12,6 +12,7 @@ #include "bpf-loader.h" #include "bpf-prologue.h" #include "probe-finder.h" +#include <errno.h> #include <dwarf-regs.h> #include <linux/filter.h> diff --git a/tools/perf/util/bpf-prologue.h b/tools/perf/util/bpf-prologue.h index d94cbea12899..ba564838375f 100644 --- a/tools/perf/util/bpf-prologue.h +++ b/tools/perf/util/bpf-prologue.h @@ -18,6 +18,8 @@ int bpf__gen_prologue(struct probe_trace_arg *args, int nargs, struct bpf_insn *new_prog, size_t *new_cnt, size_t cnt_space); #else +#include <errno.h> + static inline int bpf__gen_prologue(struct probe_trace_arg *args __maybe_unused, int nargs __maybe_unused, diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index 33af67530d30..168cc49654e7 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -7,18 +7,26 @@ * Copyright (C) 2009, 2010 Arnaldo Carvalho de Melo <acme@redhat.com> */ #include "util.h" +#include <dirent.h> +#include <errno.h> #include <stdio.h> +#include <sys/stat.h> +#include <sys/types.h> #include "build-id.h" #include "event.h" #include "symbol.h" +#include "thread.h" #include <linux/kernel.h> #include "debug.h" #include "session.h" #include "tool.h" #include "header.h" #include "vdso.h" +#include "path.h" #include "probe-file.h" +#include "strlist.h" +#include "sane_ctype.h" static bool no_buildid_cache; @@ -447,14 +455,14 @@ void disable_buildid_cache(void) } static bool lsdir_bid_head_filter(const char *name __maybe_unused, - struct dirent *d __maybe_unused) + struct dirent *d) { return (strlen(d->d_name) == 2) && isxdigit(d->d_name[0]) && isxdigit(d->d_name[1]); } static bool lsdir_bid_tail_filter(const char *name __maybe_unused, - struct dirent *d __maybe_unused) + struct dirent *d) { int i = 0; while (isxdigit(d->d_name[i]) && i < SBUILD_ID_SIZE - 3) diff --git a/tools/perf/util/build-id.h b/tools/perf/util/build-id.h index d27990610f9f..a96081121179 100644 --- a/tools/perf/util/build-id.h +++ b/tools/perf/util/build-id.h @@ -5,7 +5,6 @@ #define SBUILD_ID_SIZE (BUILD_ID_SIZE * 2 + 1) #include "tool.h" -#include "strlist.h" #include <linux/types.h> extern struct perf_tool build_id__mark_dso_hit_ops; @@ -34,6 +33,9 @@ char *build_id_cache__origname(const char *sbuild_id); char *build_id_cache__linkname(const char *sbuild_id, char *bf, size_t size); char *build_id_cache__cachedir(const char *sbuild_id, const char *name, bool is_kallsyms, bool is_vdso); + +struct strlist; + struct strlist *build_id_cache__list_all(bool validonly); char *build_id_cache__complement(const char *incomplete_sbuild_id); int build_id_cache__list_build_ids(const char *pathname, diff --git a/tools/perf/util/c++/clang-c.h b/tools/perf/util/c++/clang-c.h index 0eadd792ab1f..ccafcf72b37a 100644 --- a/tools/perf/util/c++/clang-c.h +++ b/tools/perf/util/c++/clang-c.h @@ -20,6 +20,7 @@ extern int perf_clang__compile_bpf(const char *filename, size_t *p_obj_buf_sz); #else +#include <errno.h> static inline void perf_clang__init(void) { } static inline void perf_clang__cleanup(void) { } diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index 2e5eff5abef0..81fc29ac798f 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c @@ -9,6 +9,7 @@ * */ +#include <inttypes.h> #include <stdlib.h> #include <stdio.h> #include <stdbool.h> @@ -23,6 +24,21 @@ #include "machine.h" #include "callchain.h" +#define CALLCHAIN_PARAM_DEFAULT \ + .mode = CHAIN_GRAPH_ABS, \ + .min_percent = 0.5, \ + .order = ORDER_CALLEE, \ + .key = CCKEY_FUNCTION, \ + .value = CCVAL_PERCENT, \ + +struct callchain_param callchain_param = { + CALLCHAIN_PARAM_DEFAULT +}; + +struct callchain_param callchain_param_default = { + CALLCHAIN_PARAM_DEFAULT +}; + __thread struct callchain_cursor callchain_cursor; int parse_callchain_record_opt(const char *arg, struct callchain_param *param) @@ -112,6 +128,32 @@ static int parse_callchain_value(const char *value) return -1; } +static int get_stack_size(const char *str, unsigned long *_size) +{ + char *endptr; + unsigned long size; + unsigned long max_size = round_down(USHRT_MAX, sizeof(u64)); + + size = strtoul(str, &endptr, 0); + + do { + if (*endptr) + break; + + size = round_up(size, sizeof(u64)); + if (!size || size > max_size) + break; + + *_size = size; + return 0; + + } while (0); + + pr_err("callchain: Incorrect stack dump size (max %ld): %s\n", + max_size, str); + return -1; +} + static int __parse_callchain_report_opt(const char *arg, bool allow_record_opt) { @@ -195,6 +237,68 @@ int parse_callchain_top_opt(const char *arg) return __parse_callchain_report_opt(arg, true); } +int parse_callchain_record(const char *arg, struct callchain_param *param) +{ + char *tok, *name, *saveptr = NULL; + char *buf; + int ret = -1; + + /* We need buffer that we know we can write to. */ + buf = malloc(strlen(arg) + 1); + if (!buf) + return -ENOMEM; + + strcpy(buf, arg); + + tok = strtok_r((char *)buf, ",", &saveptr); + name = tok ? : (char *)buf; + + do { + /* Framepointer style */ + if (!strncmp(name, "fp", sizeof("fp"))) { + if (!strtok_r(NULL, ",", &saveptr)) { + param->record_mode = CALLCHAIN_FP; + ret = 0; + } else + pr_err("callchain: No more arguments " + "needed for --call-graph fp\n"); + break; + + /* Dwarf style */ + } else if (!strncmp(name, "dwarf", sizeof("dwarf"))) { + const unsigned long default_stack_dump_size = 8192; + + ret = 0; + param->record_mode = CALLCHAIN_DWARF; + param->dump_size = default_stack_dump_size; + + tok = strtok_r(NULL, ",", &saveptr); + if (tok) { + unsigned long size = 0; + + ret = get_stack_size(tok, &size); + param->dump_size = size; + } + } else if (!strncmp(name, "lbr", sizeof("lbr"))) { + if (!strtok_r(NULL, ",", &saveptr)) { + param->record_mode = CALLCHAIN_LBR; + ret = 0; + } else + pr_err("callchain: No more arguments " + "needed for --call-graph lbr\n"); + break; + } else { + pr_err("callchain: Unknown --call-graph option " + "value: %s\n", arg); + break; + } + + } while (0); + + free(buf); + return ret; +} + int perf_callchain_config(const char *var, const char *value) { char *endptr; diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c index 86399eda3684..03347748f3fa 100644 --- a/tools/perf/util/cgroup.c +++ b/tools/perf/util/cgroup.c @@ -4,6 +4,7 @@ #include "evsel.h" #include "cgroup.h" #include "evlist.h" +#include <linux/stringify.h> int nr_cgroups; @@ -27,8 +28,8 @@ cgroupfs_find_mountpoint(char *buf, size_t maxlen) path_v1[0] = '\0'; path_v2[0] = '\0'; - while (fscanf(fp, "%*s %"STR(PATH_MAX)"s %"STR(PATH_MAX)"s %" - STR(PATH_MAX)"s %*d %*d\n", + while (fscanf(fp, "%*s %"__stringify(PATH_MAX)"s %"__stringify(PATH_MAX)"s %" + __stringify(PATH_MAX)"s %*d %*d\n", mountpoint, type, tokens) == 3) { if (!path_v1[0] && !strcmp(type, "cgroup")) { diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c index f0dcd0ee0afa..4b4f00df58a8 100644 --- a/tools/perf/util/cloexec.c +++ b/tools/perf/util/cloexec.c @@ -1,3 +1,4 @@ +#include <errno.h> #include <sched.h> #include "util.h" #include "../perf.h" diff --git a/tools/perf/util/color.h b/tools/perf/util/color.h index a93997f16dec..52122bcc3170 100644 --- a/tools/perf/util/color.h +++ b/tools/perf/util/color.h @@ -1,6 +1,8 @@ #ifndef __PERF_COLOR_H #define __PERF_COLOR_H +#include <stdio.h> + /* "\033[1;38;5;2xx;48;5;2xxm\0" is 23 bytes */ #define COLOR_MAXLEN 24 diff --git a/tools/perf/util/comm.c b/tools/perf/util/comm.c index 32837b6f7879..7bc981b6bf29 100644 --- a/tools/perf/util/comm.c +++ b/tools/perf/util/comm.c @@ -1,7 +1,9 @@ #include "comm.h" #include "util.h" +#include <errno.h> #include <stdlib.h> #include <stdio.h> +#include <string.h> #include <linux/refcount.h> struct comm_str { diff --git a/tools/perf/util/compress.h b/tools/perf/util/compress.h new file mode 100644 index 000000000000..67fd1bb7c2b7 --- /dev/null +++ b/tools/perf/util/compress.h @@ -0,0 +1,12 @@ +#ifndef PERF_COMPRESS_H +#define PERF_COMPRESS_H + +#ifdef HAVE_ZLIB_SUPPORT +int gzip_decompress_to_file(const char *input, int output_fd); +#endif + +#ifdef HAVE_LZMA_SUPPORT +int lzma_decompress_to_file(const char *input, int output_fd); +#endif + +#endif /* PERF_COMPRESS_H */ diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c index 7b01d59076d3..8d724f0fa5a8 100644 --- a/tools/perf/util/config.c +++ b/tools/perf/util/config.c @@ -8,12 +8,19 @@ * Copyright (C) Johannes Schindelin, 2005 * */ +#include <errno.h> +#include <sys/param.h> #include "util.h" #include "cache.h" #include <subcmd/exec-cmd.h> #include "util/hist.h" /* perf_hist_config */ #include "util/llvm-utils.h" /* perf_llvm_config */ #include "config.h" +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> + +#include "sane_ctype.h" #define MAXNAME (256) diff --git a/tools/perf/util/counts.c b/tools/perf/util/counts.c index e3fde313deb2..c4af82ab7808 100644 --- a/tools/perf/util/counts.c +++ b/tools/perf/util/counts.c @@ -1,6 +1,8 @@ +#include <errno.h> #include <stdlib.h> #include "evsel.h" #include "counts.h" +#include "util.h" struct perf_counts *perf_counts__new(int ncpus, int nthreads) { diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 061018b42393..37b3bb79ee08 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -3,11 +3,14 @@ #include "../perf.h" #include "cpumap.h" #include <assert.h> +#include <dirent.h> #include <stdio.h> #include <stdlib.h> #include <linux/bitmap.h> #include "asm/bug.h" +#include "sane_ctype.h" + static int max_cpu_num; static int max_present_cpu_num; static int max_node_num; diff --git a/tools/perf/util/ctype.c b/tools/perf/util/ctype.c index d4a5a21c2a7e..4b261c2ec0f1 100644 --- a/tools/perf/util/ctype.c +++ b/tools/perf/util/ctype.c @@ -3,7 +3,7 @@ * * No surprises, and works with signed and unsigned chars. */ -#include "util.h" +#include "sane_ctype.h" enum { S = GIT_SPACE, diff --git a/tools/perf/util/data-convert-bt.c b/tools/perf/util/data-convert-bt.c index 89ece2445713..89d50318833d 100644 --- a/tools/perf/util/data-convert-bt.c +++ b/tools/perf/util/data-convert-bt.c @@ -7,7 +7,10 @@ * Released under the GPL v2. (and only v2, not any later version) */ +#include <errno.h> +#include <inttypes.h> #include <linux/compiler.h> +#include <linux/kernel.h> #include <babeltrace/ctf-writer/writer.h> #include <babeltrace/ctf-writer/clock.h> #include <babeltrace/ctf-writer/stream.h> @@ -27,6 +30,7 @@ #include "evsel.h" #include "machine.h" #include "config.h" +#include "sane_ctype.h" #define pr_N(n, fmt, ...) \ eprintf(n, debug_data_convert, fmt, ##__VA_ARGS__) diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c index 60bfc9ca1e22..e84bbc8ec058 100644 --- a/tools/perf/util/data.c +++ b/tools/perf/util/data.c @@ -2,6 +2,7 @@ #include <linux/kernel.h> #include <sys/types.h> #include <sys/stat.h> +#include <errno.h> #include <unistd.h> #include <string.h> diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c index 03eb81f30d0d..a5b3777ffee6 100644 --- a/tools/perf/util/debug.c +++ b/tools/perf/util/debug.c @@ -2,19 +2,26 @@ #include "../perf.h" +#include <inttypes.h> #include <string.h> #include <stdarg.h> #include <stdio.h> +#include <sys/wait.h> #include <api/debug.h> #include <linux/time64.h> - +#ifdef HAVE_BACKTRACE_SUPPORT +#include <execinfo.h> +#endif #include "cache.h" #include "color.h" #include "event.h" #include "debug.h" +#include "print_binary.h" #include "util.h" #include "target.h" +#include "sane_ctype.h" + int verbose; bool dump_trace = false, quiet = false; int debug_ordered_events; @@ -244,3 +251,31 @@ void perf_debug_setup(void) { libapi_set_print(pr_warning_wrapper, pr_warning_wrapper, pr_debug_wrapper); } + +/* Obtain a backtrace and print it to stdout. */ +#ifdef HAVE_BACKTRACE_SUPPORT +void dump_stack(void) +{ + void *array[16]; + size_t size = backtrace(array, ARRAY_SIZE(array)); + char **strings = backtrace_symbols(array, size); + size_t i; + + printf("Obtained %zd stack frames.\n", size); + + for (i = 0; i < size; i++) + printf("%s\n", strings[i]); + + free(strings); +} +#else +void dump_stack(void) {} +#endif + +void sighandler_dump_stack(int sig) +{ + psignal(sig, "perf"); + dump_stack(); + signal(sig, SIG_DFL); + raise(sig); +} diff --git a/tools/perf/util/debug.h b/tools/perf/util/debug.h index 98832f5531d3..8a23ea1a71c7 100644 --- a/tools/perf/util/debug.h +++ b/tools/perf/util/debug.h @@ -56,4 +56,7 @@ int perf_debug_option(const char *str); void perf_debug_setup(void); int perf_quiet_option(void); +void dump_stack(void); +void sighandler_dump_stack(int sig); + #endif /* __PERF_DEBUG_H */ diff --git a/tools/perf/util/demangle-java.c b/tools/perf/util/demangle-java.c index 3e6062ab2cdd..cb66d334f532 100644 --- a/tools/perf/util/demangle-java.c +++ b/tools/perf/util/demangle-java.c @@ -7,6 +7,8 @@ #include "demangle-java.h" +#include "sane_ctype.h" + enum { MODE_PREFIX = 0, MODE_CLASS = 1, diff --git a/tools/perf/util/drv_configs.c b/tools/perf/util/drv_configs.c index 1647f285c629..eec754243f4d 100644 --- a/tools/perf/util/drv_configs.c +++ b/tools/perf/util/drv_configs.c @@ -17,6 +17,7 @@ #include "evlist.h" #include "evsel.h" #include "pmu.h" +#include <errno.h> static int perf_evsel__apply_drv_configs(struct perf_evsel *evsel, diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index 42db00d78573..a96a99d2369f 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c @@ -1,12 +1,20 @@ #include <asm/bug.h> +#include <linux/kernel.h> #include <sys/time.h> #include <sys/resource.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <errno.h> +#include "compress.h" +#include "path.h" #include "symbol.h" #include "dso.h" #include "machine.h" #include "auxtrace.h" #include "util.h" #include "debug.h" +#include "string2.h" #include "vdso.h" static const char * const debuglink_paths[] = { diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c index 41e068e94349..f5acda13dcfa 100644 --- a/tools/perf/util/dwarf-aux.c +++ b/tools/perf/util/dwarf-aux.c @@ -17,10 +17,13 @@ * */ +#include <errno.h> +#include <inttypes.h> #include <stdbool.h> #include "util.h" #include "debug.h" #include "dwarf-aux.h" +#include "string2.h" /** * cu_find_realpath - Find the realpath of the target file diff --git a/tools/perf/util/dwarf-regs.c b/tools/perf/util/dwarf-regs.c index 62bc4a86a970..c708395b3cb6 100644 --- a/tools/perf/util/dwarf-regs.c +++ b/tools/perf/util/dwarf-regs.c @@ -8,6 +8,7 @@ #include <debug.h> #include <dwarf-regs.h> #include <elf.h> +#include <linux/kernel.h> #ifndef EM_AARCH64 #define EM_AARCH64 183 /* ARM 64 bit */ diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index 075fc77286bf..9e21538c42ae 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -1,6 +1,7 @@ #include "cpumap.h" #include "env.h" #include "util.h" +#include <errno.h> struct perf_env perf_env; diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index 4d7e65fa9d86..142835c0ca0a 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c @@ -1,4 +1,11 @@ +#include <dirent.h> +#include <errno.h> +#include <inttypes.h> +#include <linux/kernel.h> #include <linux/types.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> #include <uapi/linux/mman.h> /* To get things like MAP_HUGETLB even on older libc headers */ #include <api/fs/fs.h> #include "event.h" @@ -6,10 +13,11 @@ #include "hist.h" #include "machine.h" #include "sort.h" -#include "string.h" +#include "string2.h" #include "strlist.h" #include "thread.h" #include "thread_map.h" +#include "sane_ctype.h" #include "symbol/kallsyms.h" #include "asm/bug.h" #include "stat.h" @@ -133,8 +141,15 @@ static int perf_event__get_comm_ids(pid_t pid, char *comm, size_t len, ppids = strstr(bf, "PPid:"); if (name) { + char *nl; + name += 5; /* strlen("Name:") */ - name = rtrim(ltrim(name)); + name = ltrim(name); + + nl = strchr(name, '\n'); + if (nl) + *nl = '\0'; + size = strlen(name); if (size >= len) size = len - 1; diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h index eb7a7b200737..db2de6413518 100644 --- a/tools/perf/util/event.h +++ b/tools/perf/util/event.h @@ -3,9 +3,9 @@ #include <limits.h> #include <stdio.h> +#include <linux/kernel.h> #include "../perf.h" -#include "map.h" #include "build-id.h" #include "perf_regs.h" diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 50420cd35446..46c0faf6c502 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -8,6 +8,8 @@ */ #include "util.h" #include <api/fs/fs.h> +#include <errno.h> +#include <inttypes.h> #include <poll.h> #include "cpumap.h" #include "thread_map.h" @@ -15,12 +17,15 @@ #include "evlist.h" #include "evsel.h" #include "debug.h" +#include "units.h" #include "asm/bug.h" +#include <signal.h> #include <unistd.h> #include "parse-events.h" #include <subcmd/parse-options.h> +#include <sys/ioctl.h> #include <sys/mman.h> #include <linux/bitops.h> diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 39942995f537..94cea4398a13 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -1,6 +1,7 @@ #ifndef __PERF_EVLIST_H #define __PERF_EVLIST_H 1 +#include <linux/kernel.h> #include <linux/refcount.h> #include <linux/list.h> #include <api/fd/array.h> @@ -10,6 +11,7 @@ #include "evsel.h" #include "util.h" #include "auxtrace.h" +#include <signal.h> #include <unistd.h> struct pollfd; diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 3779b9f3f134..0e879097adfb 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -8,12 +8,15 @@ */ #include <byteswap.h> +#include <errno.h> +#include <inttypes.h> #include <linux/bitops.h> #include <api/fs/tracing_path.h> #include <traceevent/event-parse.h> #include <linux/hw_breakpoint.h> #include <linux/perf_event.h> #include <linux/err.h> +#include <sys/ioctl.h> #include <sys/resource.h> #include "asm/bug.h" #include "callchain.h" @@ -30,6 +33,8 @@ #include "stat.h" #include "util/parse-branch-options.h" +#include "sane_ctype.h" + static struct { bool sample_id_all; bool exclude_guest; diff --git a/tools/perf/util/evsel_fprintf.c b/tools/perf/util/evsel_fprintf.c index 4ef5184819a0..e415aee6a245 100644 --- a/tools/perf/util/evsel_fprintf.c +++ b/tools/perf/util/evsel_fprintf.c @@ -1,9 +1,11 @@ +#include <inttypes.h> #include <stdio.h> #include <stdbool.h> #include <traceevent/event-parse.h> #include "evsel.h" #include "callchain.h" #include "map.h" +#include "strlist.h" #include "symbol.h" static int comma_fprintf(FILE *fp, bool *first, const char *fmt, ...) diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 2ccc7f06db79..948b2c5efb65 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -1,4 +1,8 @@ +#include <errno.h> +#include <inttypes.h> #include "util.h" +#include "string2.h" +#include <sys/param.h> #include <sys/types.h> #include <byteswap.h> #include <unistd.h> @@ -7,7 +11,10 @@ #include <linux/list.h> #include <linux/kernel.h> #include <linux/bitops.h> +#include <sys/stat.h> +#include <sys/types.h> #include <sys/utsname.h> +#include <unistd.h> #include "evlist.h" #include "evsel.h" @@ -26,6 +33,8 @@ #include <api/fs/fs.h> #include "asm/bug.h" +#include "sane_ctype.h" + /* * magic2 = "PERFILE2" * must be a numerical value to let the endianness diff --git a/tools/perf/util/help-unknown-cmd.c b/tools/perf/util/help-unknown-cmd.c index 34201440ac03..1c88ad6425b8 100644 --- a/tools/perf/util/help-unknown-cmd.c +++ b/tools/perf/util/help-unknown-cmd.c @@ -1,5 +1,6 @@ #include "cache.h" #include "config.h" +#include <poll.h> #include <stdio.h> #include <subcmd/help.h> #include "../builtin.h" diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 61bf304206fd..cf0186a088c1 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -8,8 +8,12 @@ #include "evlist.h" #include "evsel.h" #include "annotate.h" +#include "srcline.h" +#include "thread.h" #include "ui/progress.h" +#include <errno.h> #include <math.h> +#include <sys/param.h> static bool hists__filter_entry_by_dso(struct hists *hists, struct hist_entry *he); diff --git a/tools/perf/util/intel-bts.c b/tools/perf/util/intel-bts.c index 6c2eb5da4afc..b2834ac7b1f5 100644 --- a/tools/perf/util/intel-bts.c +++ b/tools/perf/util/intel-bts.c @@ -14,7 +14,9 @@ */ #include <endian.h> +#include <errno.h> #include <byteswap.h> +#include <inttypes.h> #include <linux/kernel.h> #include <linux/types.h> #include <linux/bitops.h> diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c index da20cd5612e9..bdd4a28c6cee 100644 --- a/tools/perf/util/intel-pt.c +++ b/tools/perf/util/intel-pt.c @@ -13,6 +13,7 @@ * */ +#include <inttypes.h> #include <stdio.h> #include <stdbool.h> #include <errno.h> diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c index c9a941ef0f6d..9084930e1757 100644 --- a/tools/perf/util/jitdump.c +++ b/tools/perf/util/jitdump.c @@ -1,5 +1,6 @@ #include <sys/sysmacros.h> #include <sys/types.h> +#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -9,13 +10,13 @@ #include <byteswap.h> #include <sys/stat.h> #include <sys/mman.h> +#include <linux/stringify.h> #include "util.h" #include "event.h" #include "debug.h" #include "evlist.h" #include "symbol.h" -#include "strlist.h" #include <elf.h> #include "tsc.h" @@ -25,6 +26,8 @@ #include "genelf.h" #include "../builtin.h" +#include "sane_ctype.h" + struct jit_buf_desc { struct perf_data_file *output; struct perf_session *session; @@ -181,7 +184,7 @@ jit_open(struct jit_buf_desc *jd, const char *name) jd->use_arch_timestamp); if (header.version > JITHEADER_VERSION) { - pr_err("wrong jitdump version %u, expected " STR(JITHEADER_VERSION), + pr_err("wrong jitdump version %u, expected " __stringify(JITHEADER_VERSION), header.version); goto error; } diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c index 824356488ce6..c6a15f204c03 100644 --- a/tools/perf/util/llvm-utils.c +++ b/tools/perf/util/llvm-utils.c @@ -12,6 +12,7 @@ #include "llvm-utils.h" #include "config.h" #include "util.h" +#include <sys/wait.h> #define CLANG_BPF_CMD_DEFAULT_TEMPLATE \ "$CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS "\ diff --git a/tools/perf/util/lzma.c b/tools/perf/util/lzma.c index 9ddea5cecd94..4ca7c5c6cdcd 100644 --- a/tools/perf/util/lzma.c +++ b/tools/perf/util/lzma.c @@ -1,6 +1,8 @@ +#include <errno.h> #include <lzma.h> #include <stdio.h> #include <linux/compiler.h> +#include "compress.h" #include "util.h" #include "debug.h" diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index dfc600446586..7a47f52ccfcc 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -1,3 +1,7 @@ +#include <dirent.h> +#include <errno.h> +#include <inttypes.h> +#include <regex.h> #include "callchain.h" #include "debug.h" #include "event.h" @@ -10,11 +14,16 @@ #include "thread.h" #include "vdso.h" #include <stdbool.h> -#include <symbol/kallsyms.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> #include "unwind.h" #include "linux/hash.h" #include "asm/bug.h" +#include "sane_ctype.h" +#include <symbol/kallsyms.h> + static void __machine__remove_thread(struct machine *machine, struct thread *th, bool lock); static void dsos__init(struct dsos *dsos) diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index c1870ac365a3..ebfa5d92358a 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -9,13 +9,13 @@ #include <uapi/linux/mman.h> /* To get things like MAP_HUGETLB even on older libc headers */ #include "map.h" #include "thread.h" -#include "strlist.h" #include "vdso.h" #include "build-id.h" #include "util.h" #include "debug.h" #include "machine.h" #include <linux/string.h> +#include "srcline.h" #include "unwind.h" static void __maps__insert(struct maps *maps, struct map *map); diff --git a/tools/perf/util/mem-events.c b/tools/perf/util/mem-events.c index 1d4ab53c60ca..06f5a3a4295c 100644 --- a/tools/perf/util/mem-events.c +++ b/tools/perf/util/mem-events.c @@ -6,6 +6,7 @@ #include <sys/stat.h> #include <unistd.h> #include <api/fs/fs.h> +#include <linux/kernel.h> #include "mem-events.h" #include "debug.h" #include "symbol.h" @@ -205,8 +206,8 @@ int perf_mem__lvl_scnprintf(char *out, size_t sz, struct mem_info *mem_info) static const char * const snoop_access[] = { "N/A", "None", - "Miss", "Hit", + "Miss", "HitM", }; diff --git a/tools/perf/util/namespaces.c b/tools/perf/util/namespaces.c index 2de8da64d90c..67dcbcc73c7d 100644 --- a/tools/perf/util/namespaces.c +++ b/tools/perf/util/namespaces.c @@ -11,6 +11,7 @@ #include "event.h" #include <stdlib.h> #include <stdio.h> +#include <string.h> struct namespaces *namespaces__new(struct namespaces_event *event) { diff --git a/tools/perf/util/ordered-events.c b/tools/perf/util/ordered-events.c index e70e935b1841..4de398cfb577 100644 --- a/tools/perf/util/ordered-events.c +++ b/tools/perf/util/ordered-events.c @@ -1,3 +1,5 @@ +#include <errno.h> +#include <inttypes.h> #include <linux/list.h> #include <linux/compiler.h> #include <linux/string.h> diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 6b498aea9fde..01e779b91c8e 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1,13 +1,18 @@ #include <linux/hw_breakpoint.h> #include <linux/err.h> -#include "util.h" +#include <dirent.h> +#include <errno.h> +#include <sys/ioctl.h> +#include <sys/param.h> +#include "term.h" #include "../perf.h" #include "evlist.h" #include "evsel.h" #include <subcmd/parse-options.h> #include "parse-events.h" #include <subcmd/exec-cmd.h> -#include "string.h" +#include "string2.h" +#include "strlist.h" #include "symbol.h" #include "cache.h" #include "header.h" diff --git a/tools/perf/util/path.c b/tools/perf/util/path.c index 7c7630be5a89..50ec3bc87a60 100644 --- a/tools/perf/util/path.c +++ b/tools/perf/util/path.c @@ -11,8 +11,13 @@ * which is what it's designed for. */ #include "cache.h" -#include "util.h" +#include "path.h" +#include <linux/kernel.h> #include <limits.h> +#include <stdio.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> static char bad_path[] = "/bad-path/"; /* @@ -50,3 +55,24 @@ char *mkpath(const char *fmt, ...) return bad_path; return cleanup_path(pathname); } + +int path__join(char *bf, size_t size, const char *path1, const char *path2) +{ + return scnprintf(bf, size, "%s%s%s", path1, path1[0] ? "/" : "", path2); +} + +int path__join3(char *bf, size_t size, const char *path1, const char *path2, const char *path3) +{ + return scnprintf(bf, size, "%s%s%s%s%s", path1, path1[0] ? "/" : "", + path2, path2[0] ? "/" : "", path3); +} + +bool is_regular_file(const char *file) +{ + struct stat st; + + if (stat(file, &st)) + return false; + + return S_ISREG(st.st_mode); +} diff --git a/tools/perf/util/path.h b/tools/perf/util/path.h new file mode 100644 index 000000000000..9a276a58e3c2 --- /dev/null +++ b/tools/perf/util/path.h @@ -0,0 +1,9 @@ +#ifndef _PERF_PATH_H +#define _PERF_PATH_H + +int path__join(char *bf, size_t size, const char *path1, const char *path2); +int path__join3(char *bf, size_t size, const char *path1, const char *path2, const char *path3); + +bool is_regular_file(const char *file); + +#endif /* _PERF_PATH_H */ diff --git a/tools/perf/util/perf-hooks.c b/tools/perf/util/perf-hooks.c index cb368306b12b..d55092964da2 100644 --- a/tools/perf/util/perf-hooks.c +++ b/tools/perf/util/perf-hooks.c @@ -9,6 +9,7 @@ #include <stdlib.h> #include <setjmp.h> #include <linux/err.h> +#include <linux/kernel.h> #include "util/util.h" #include "util/debug.h" #include "util/perf-hooks.h" diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 11c752561c55..ac16a9db1fb5 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1,6 +1,8 @@ #include <linux/list.h> #include <linux/compiler.h> #include <sys/types.h> +#include <errno.h> +#include <sys/stat.h> #include <unistd.h> #include <stdio.h> #include <stdbool.h> @@ -15,6 +17,7 @@ #include "header.h" #include "pmu-events/pmu-events.h" #include "cache.h" +#include "string2.h" struct perf_pmu_format { char *name; diff --git a/tools/perf/util/print_binary.c b/tools/perf/util/print_binary.c new file mode 100644 index 000000000000..e908177b9976 --- /dev/null +++ b/tools/perf/util/print_binary.c @@ -0,0 +1,55 @@ +#include "print_binary.h" +#include <linux/log2.h> +#include "sane_ctype.h" + +void print_binary(unsigned char *data, size_t len, + size_t bytes_per_line, print_binary_t printer, + void *extra) +{ + size_t i, j, mask; + + if (!printer) + return; + + bytes_per_line = roundup_pow_of_two(bytes_per_line); + mask = bytes_per_line - 1; + + printer(BINARY_PRINT_DATA_BEGIN, 0, extra); + for (i = 0; i < len; i++) { + if ((i & mask) == 0) { + printer(BINARY_PRINT_LINE_BEGIN, -1, extra); + printer(BINARY_PRINT_ADDR, i, extra); + } + + printer(BINARY_PRINT_NUM_DATA, data[i], extra); + + if (((i & mask) == mask) || i == len - 1) { + for (j = 0; j < mask-(i & mask); j++) + printer(BINARY_PRINT_NUM_PAD, -1, extra); + + printer(BINARY_PRINT_SEP, i, extra); + for (j = i & ~mask; j <= i; j++) + printer(BINARY_PRINT_CHAR_DATA, data[j], extra); + for (j = 0; j < mask-(i & mask); j++) + printer(BINARY_PRINT_CHAR_PAD, i, extra); + printer(BINARY_PRINT_LINE_END, -1, extra); + } + } + printer(BINARY_PRINT_DATA_END, -1, extra); +} + +int is_printable_array(char *p, unsigned int len) +{ + unsigned int i; + + if (!p || !len || p[len - 1] != 0) + return 0; + + len--; + + for (i = 0; i < len; i++) { + if (!isprint(p[i]) && !isspace(p[i])) + return 0; + } + return 1; +} diff --git a/tools/perf/util/print_binary.h b/tools/perf/util/print_binary.h new file mode 100644 index 000000000000..da0427263d2d --- /dev/null +++ b/tools/perf/util/print_binary.h @@ -0,0 +1,28 @@ +#ifndef PERF_PRINT_BINARY_H +#define PERF_PRINT_BINARY_H + +#include <stddef.h> + +enum binary_printer_ops { + BINARY_PRINT_DATA_BEGIN, + BINARY_PRINT_LINE_BEGIN, + BINARY_PRINT_ADDR, + BINARY_PRINT_NUM_DATA, + BINARY_PRINT_NUM_PAD, + BINARY_PRINT_SEP, + BINARY_PRINT_CHAR_DATA, + BINARY_PRINT_CHAR_PAD, + BINARY_PRINT_LINE_END, + BINARY_PRINT_DATA_END, +}; + +typedef void (*print_binary_t)(enum binary_printer_ops op, + unsigned int val, void *extra); + +void print_binary(unsigned char *data, size_t len, + size_t bytes_per_line, print_binary_t printer, + void *extra); + +int is_printable_array(char *p, unsigned int len); + +#endif /* PERF_PRINT_BINARY_H */ diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index e4b889444447..84e7e698411e 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -19,6 +19,7 @@ * */ +#include <inttypes.h> #include <sys/utsname.h> #include <sys/types.h> #include <sys/stat.h> @@ -35,6 +36,7 @@ #include "util.h" #include "event.h" #include "strlist.h" +#include "strfilter.h" #include "debug.h" #include "cache.h" #include "color.h" @@ -46,6 +48,9 @@ #include "probe-finder.h" #include "probe-file.h" #include "session.h" +#include "string2.h" + +#include "sane_ctype.h" #define PERFPROBE_GROUP "probe" diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h index 5d4e94061402..373842656fb6 100644 --- a/tools/perf/util/probe-event.h +++ b/tools/perf/util/probe-event.h @@ -3,8 +3,6 @@ #include <stdbool.h> #include "intlist.h" -#include "strlist.h" -#include "strfilter.h" /* Probe related configurations */ struct probe_conf { @@ -107,6 +105,8 @@ struct line_range { struct intlist *line_list; /* Visible lines */ }; +struct strlist; + /* List of variables */ struct variable_list { struct probe_trace_point point; /* Actual probepoint */ @@ -153,6 +153,9 @@ int convert_perf_probe_events(struct perf_probe_event *pevs, int npevs); int apply_perf_probe_events(struct perf_probe_event *pevs, int npevs); int show_probe_trace_events(struct perf_probe_event *pevs, int npevs); void cleanup_perf_probe_events(struct perf_probe_event *pevs, int npevs); + +struct strfilter; + int del_perf_probe_events(struct strfilter *filter); int show_perf_probe_event(const char *group, const char *event, diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c index 88714dec8912..d679389e627c 100644 --- a/tools/perf/util/probe-file.c +++ b/tools/perf/util/probe-file.c @@ -14,10 +14,15 @@ * GNU General Public License for more details. * */ +#include <errno.h> +#include <sys/stat.h> +#include <sys/types.h> #include <sys/uio.h> +#include <unistd.h> #include "util.h" #include "event.h" #include "strlist.h" +#include "strfilter.h" #include "debug.h" #include "cache.h" #include "color.h" @@ -28,6 +33,7 @@ #include "probe-file.h" #include "session.h" #include "perf_regs.h" +#include "string2.h" /* 4096 - 2 ('\n' + '\0') */ #define MAX_CMDLEN 4094 diff --git a/tools/perf/util/probe-file.h b/tools/perf/util/probe-file.h index dbf95a00864a..5ecc9d3925db 100644 --- a/tools/perf/util/probe-file.h +++ b/tools/perf/util/probe-file.h @@ -1,10 +1,11 @@ #ifndef __PROBE_FILE_H #define __PROBE_FILE_H -#include "strlist.h" -#include "strfilter.h" #include "probe-event.h" +struct strlist; +struct strfilter; + /* Cache of probe definitions */ struct probe_cache_entry { struct list_head node; @@ -41,6 +42,7 @@ int probe_file__open_both(int *kfd, int *ufd, int flag); struct strlist *probe_file__get_namelist(int fd); struct strlist *probe_file__get_rawlist(int fd); int probe_file__add_event(int fd, struct probe_trace_event *tev); + int probe_file__del_events(int fd, struct strfilter *filter); int probe_file__get_events(int fd, struct strfilter *filter, struct strlist *plist); diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c index 57cd268d4275..a5731de0e5eb 100644 --- a/tools/perf/util/probe-finder.c +++ b/tools/perf/util/probe-finder.c @@ -19,6 +19,7 @@ * */ +#include <inttypes.h> #include <sys/utsname.h> #include <sys/types.h> #include <sys/stat.h> @@ -37,9 +38,11 @@ #include "debug.h" #include "intlist.h" #include "util.h" +#include "strlist.h" #include "symbol.h" #include "probe-finder.h" #include "probe-file.h" +#include "string2.h" /* Kprobe tracer basic type is up to u64 */ #define MAX_BASIC_TYPE_BITS 64 diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h index 2956c5198652..27f061551012 100644 --- a/tools/perf/util/probe-finder.h +++ b/tools/perf/util/probe-finder.h @@ -2,9 +2,9 @@ #define _PROBE_FINDER_H #include <stdbool.h> -#include "util.h" #include "intlist.h" #include "probe-event.h" +#include "sane_ctype.h" #define MAX_PROBE_BUFFER 1024 #define MAX_PROBES 128 diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ext-sources index 0546a4304347..9f3b0d9754a8 100644 --- a/tools/perf/util/python-ext-sources +++ b/tools/perf/util/python-ext-sources @@ -21,8 +21,10 @@ util/cgroup.c util/parse-branch-options.c util/rblist.c util/counts.c +util/print_binary.c util/strlist.c util/trace-event.c ../lib/rbtree.c util/string.c util/symbol_fprintf.c +util/units.c diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index a5fbc012e3df..c129e99114ae 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -4,12 +4,26 @@ #include <poll.h> #include <linux/err.h> #include "evlist.h" +#include "callchain.h" #include "evsel.h" #include "event.h" #include "cpumap.h" +#include "print_binary.h" #include "thread_map.h" /* + * Provide these two so that we don't have to link against callchain.c and + * start dragging hist.c, etc. + */ +struct callchain_param callchain_param; + +int parse_callchain_record(const char *arg __maybe_unused, + struct callchain_param *param __maybe_unused) +{ + return 0; +} + +/* * Support debug printing even though util/debug.c is not linked. That means * implementing 'verbose' and 'eprintf'. */ diff --git a/tools/perf/util/quote.c b/tools/perf/util/quote.c index 293534c1a474..1ba8920151d8 100644 --- a/tools/perf/util/quote.c +++ b/tools/perf/util/quote.c @@ -1,3 +1,4 @@ +#include <errno.h> #include <stdlib.h> #include "strbuf.h" #include "quote.h" diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c index 98bf584853ea..d91bdf5a1aa4 100644 --- a/tools/perf/util/record.c +++ b/tools/perf/util/record.c @@ -2,6 +2,7 @@ #include "evsel.h" #include "cpumap.h" #include "parse-events.h" +#include <errno.h> #include <api/fs/fs.h> #include "util.h" #include "cloexec.h" diff --git a/tools/perf/util/sane_ctype.h b/tools/perf/util/sane_ctype.h new file mode 100644 index 000000000000..4308c22c22ad --- /dev/null +++ b/tools/perf/util/sane_ctype.h @@ -0,0 +1,51 @@ +#ifndef _PERF_SANE_CTYPE_H +#define _PERF_SANE_CTYPE_H + +extern const char *graph_line; +extern const char *graph_dotted_line; +extern const char *spaces; +extern const char *dots; + +/* Sane ctype - no locale, and works with signed chars */ +#undef isascii +#undef isspace +#undef isdigit +#undef isxdigit +#undef isalpha +#undef isprint +#undef isalnum +#undef islower +#undef isupper +#undef tolower +#undef toupper + +extern unsigned char sane_ctype[256]; +#define GIT_SPACE 0x01 +#define GIT_DIGIT 0x02 +#define GIT_ALPHA 0x04 +#define GIT_GLOB_SPECIAL 0x08 +#define GIT_REGEX_SPECIAL 0x10 +#define GIT_PRINT_EXTRA 0x20 +#define GIT_PRINT 0x3E +#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0) +#define isascii(x) (((x) & ~0x7f) == 0) +#define isspace(x) sane_istest(x,GIT_SPACE) +#define isdigit(x) sane_istest(x,GIT_DIGIT) +#define isxdigit(x) \ + (sane_istest(toupper(x), GIT_ALPHA | GIT_DIGIT) && toupper(x) < 'G') +#define isalpha(x) sane_istest(x,GIT_ALPHA) +#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT) +#define isprint(x) sane_istest(x,GIT_PRINT) +#define islower(x) (sane_istest(x,GIT_ALPHA) && (x & 0x20)) +#define isupper(x) (sane_istest(x,GIT_ALPHA) && !(x & 0x20)) +#define tolower(x) sane_case((unsigned char)(x), 0x20) +#define toupper(x) sane_case((unsigned char)(x), 0) + +static inline int sane_case(int x, int high) +{ + if (sane_istest(x, GIT_ALPHA)) + x = (x & ~0x20) | high; + return x; +} + +#endif /* _PERF_SANE_CTYPE_H */ diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c index dff043a29589..2b12bdb3ce33 100644 --- a/tools/perf/util/scripting-engines/trace-event-perl.c +++ b/tools/perf/util/scripting-engines/trace-event-perl.c @@ -19,6 +19,7 @@ * */ +#include <inttypes.h> #include <stdio.h> #include <stdlib.h> #include <string.h> diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 783326cfbaa6..9d92af7d0718 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -21,6 +21,7 @@ #include <Python.h> +#include <inttypes.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -45,6 +46,7 @@ #include "../call-path.h" #include "thread_map.h" #include "cpumap.h" +#include "print_binary.h" #include "stat.h" PyMODINIT_FUNC initperf_trace_context(void); diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 7b740a73e595..3041c6b98191 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1,3 +1,5 @@ +#include <errno.h> +#include <inttypes.h> #include <linux/kernel.h> #include <traceevent/event-parse.h> #include <api/fs/fs.h> @@ -17,6 +19,7 @@ #include "perf_regs.h" #include "asm/bug.h" #include "auxtrace.h" +#include "thread.h" #include "thread-stack.h" #include "stat.h" diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h index 4bd758553450..47b5e7dbcb18 100644 --- a/tools/perf/util/session.h +++ b/tools/perf/util/session.h @@ -5,14 +5,14 @@ #include "event.h" #include "header.h" #include "machine.h" -#include "symbol.h" -#include "thread.h" #include "data.h" #include "ordered-events.h" +#include <linux/kernel.h> #include <linux/rbtree.h> #include <linux/perf_event.h> struct ip_callchain; +struct symbol; struct thread; struct auxtrace; diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index 73f3ec1cf2a0..5762ae4e9e91 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c @@ -1,12 +1,18 @@ +#include <errno.h> +#include <inttypes.h> +#include <regex.h> #include <sys/mman.h> #include "sort.h" #include "hist.h" #include "comm.h" #include "symbol.h" +#include "thread.h" #include "evsel.h" #include "evlist.h" +#include "strlist.h" #include <traceevent/event-parse.h> #include "mem-events.h" +#include <linux/kernel.h> regex_t parent_regex; const char default_parent_pattern[] = "^sys_|^do_page_fault"; diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h index e35fb186d048..b7c75597e18f 100644 --- a/tools/perf/util/sort.h +++ b/tools/perf/util/sort.h @@ -2,7 +2,7 @@ #define __PERF_SORT_H #include "../builtin.h" -#include "util.h" +#include <regex.h> #include "color.h" #include <linux/list.h> @@ -11,7 +11,6 @@ #include "symbol.h" #include "string.h" #include "callchain.h" -#include "strlist.h" #include "values.h" #include "../perf.h" @@ -21,7 +20,9 @@ #include <subcmd/parse-options.h> #include "parse-events.h" #include "hist.h" -#include "thread.h" +#include "srcline.h" + +struct thread; extern regex_t parent_regex; extern const char *sort_order; diff --git a/tools/perf/util/srcline.c b/tools/perf/util/srcline.c index 778ccb5d99d1..df051a52393c 100644 --- a/tools/perf/util/srcline.c +++ b/tools/perf/util/srcline.c @@ -1,3 +1,4 @@ +#include <inttypes.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -8,6 +9,7 @@ #include "util/util.h" #include "util/debug.h" #include "util/callchain.h" +#include "srcline.h" #include "symbol.h" diff --git a/tools/perf/util/srcline.h b/tools/perf/util/srcline.h new file mode 100644 index 000000000000..7b52ba88676e --- /dev/null +++ b/tools/perf/util/srcline.h @@ -0,0 +1,34 @@ +#ifndef PERF_SRCLINE_H +#define PERF_SRCLINE_H + +#include <linux/list.h> +#include <linux/types.h> + +struct dso; +struct symbol; + +extern bool srcline_full_filename; +char *get_srcline(struct dso *dso, u64 addr, struct symbol *sym, + bool show_sym, bool show_addr); +char *__get_srcline(struct dso *dso, u64 addr, struct symbol *sym, + bool show_sym, bool show_addr, bool unwind_inlines); +void free_srcline(char *srcline); + +#define SRCLINE_UNKNOWN ((char *) "??:0") + +struct inline_list { + char *filename; + char *funcname; + unsigned int line_nr; + struct list_head list; +}; + +struct inline_node { + u64 addr; + struct list_head val; +}; + +struct inline_node *dso__parse_addr_inlines(struct dso *dso, u64 addr); +void inline_node__delete(struct inline_node *node); + +#endif /* PERF_SRCLINE_H */ diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 0d51334a9b46..c58174443dc1 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -1,3 +1,5 @@ +#include <errno.h> +#include <inttypes.h> #include <math.h> #include "stat.h" #include "evlist.h" diff --git a/tools/perf/util/strbuf.c b/tools/perf/util/strbuf.c index 817593908d47..e91b5e86f027 100644 --- a/tools/perf/util/strbuf.c +++ b/tools/perf/util/strbuf.c @@ -1,6 +1,7 @@ #include "debug.h" #include "util.h" #include <linux/kernel.h> +#include <errno.h> int prefixcmp(const char *str, const char *prefix) { diff --git a/tools/perf/util/strfilter.c b/tools/perf/util/strfilter.c index efb53772e0ec..4dc0af669a30 100644 --- a/tools/perf/util/strfilter.c +++ b/tools/perf/util/strfilter.c @@ -1,7 +1,10 @@ #include "util.h" -#include "string.h" +#include "string2.h" #include "strfilter.h" +#include <errno.h> +#include "sane_ctype.h" + /* Operators */ static const char *OP_and = "&"; /* Logical AND */ static const char *OP_or = "|"; /* Logical OR */ diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c index e8feb142c9c9..cca53b693a48 100644 --- a/tools/perf/util/string.c +++ b/tools/perf/util/string.c @@ -1,5 +1,9 @@ -#include "util.h" -#include "linux/string.h" +#include "string2.h" +#include <linux/kernel.h> +#include <linux/string.h> +#include <stdlib.h> + +#include "sane_ctype.h" #define K 1024LL /* @@ -99,8 +103,10 @@ static int count_argc(const char *str) void argv_free(char **argv) { char **p; - for (p = argv; *p; p++) - zfree(p); + for (p = argv; *p; p++) { + free(*p); + *p = NULL; + } free(argv); } @@ -120,7 +126,7 @@ void argv_free(char **argv) char **argv_split(const char *str, int *argcp) { int argc = count_argc(str); - char **argv = zalloc(sizeof(*argv) * (argc+1)); + char **argv = calloc(argc + 1, sizeof(*argv)); char **argvp; if (argv == NULL) @@ -377,7 +383,7 @@ char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints goto out_err_overflow; if (i > 0) - printed += snprintf(e + printed, size - printed, " %s ", or_and); + printed += scnprintf(e + printed, size - printed, " %s ", or_and); printed += scnprintf(e + printed, size - printed, "%s %s %d", var, eq_neq, ints[i]); } diff --git a/tools/perf/util/string2.h b/tools/perf/util/string2.h new file mode 100644 index 000000000000..2f619681bd6a --- /dev/null +++ b/tools/perf/util/string2.h @@ -0,0 +1,42 @@ +#ifndef PERF_STRING_H +#define PERF_STRING_H + +#include <linux/types.h> +#include <stddef.h> +#include <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 strglobmatch_nocase(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); + +char *ltrim(char *s); +char *rtrim(char *s); + +static inline char *trim(char *s) +{ + return ltrim(rtrim(s)); +} + +char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints); + +static inline char *asprintf_expr_in_ints(const char *var, size_t nints, int *ints) +{ + return asprintf_expr_inout_ints(var, true, nints, ints); +} + +static inline char *asprintf_expr_not_in_ints(const char *var, size_t nints, int *ints) +{ + return asprintf_expr_inout_ints(var, false, nints, ints); +} + + +#endif /* PERF_STRING_H */ diff --git a/tools/perf/util/strlist.c b/tools/perf/util/strlist.c index 0d3dfcb919b4..9de5434bb49e 100644 --- a/tools/perf/util/strlist.c +++ b/tools/perf/util/strlist.c @@ -10,6 +10,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <unistd.h> static struct rb_node *strlist__node_new(struct rblist *rblist, const void *entry) diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index d1a40bb642ff..e7ee47f7377a 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -10,8 +10,9 @@ #include "demangle-rust.h" #include "machine.h" #include "vdso.h" -#include <symbol/kallsyms.h> #include "debug.h" +#include "sane_ctype.h" +#include <symbol/kallsyms.h> #ifndef EM_AARCH64 #define EM_AARCH64 183 /* ARM 64 bit */ diff --git a/tools/perf/util/symbol-minimal.c b/tools/perf/util/symbol-minimal.c index 870ef0f0659c..40bf5d4c0bfd 100644 --- a/tools/perf/util/symbol-minimal.c +++ b/tools/perf/util/symbol-minimal.c @@ -1,6 +1,7 @@ #include "symbol.h" #include "util.h" +#include <errno.h> #include <stdio.h> #include <fcntl.h> #include <string.h> diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 9b4d8ba22fed..2cb7665e9973 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -3,6 +3,7 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> +#include <linux/kernel.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/param.h> @@ -18,6 +19,8 @@ #include "strlist.h" #include "intlist.h" #include "header.h" +#include "path.h" +#include "sane_ctype.h" #include <elf.h> #include <limits.h> diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index 5245d2fb1a0a..7acd70fce68e 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h @@ -13,7 +13,7 @@ #include <libgen.h> #include "build-id.h" #include "event.h" -#include "util.h" +#include "path.h" #ifdef HAVE_LIBELF_SUPPORT #include <libelf.h> diff --git a/tools/perf/util/term.c b/tools/perf/util/term.c index 90b47d8aa19c..8f254a74d97d 100644 --- a/tools/perf/util/term.c +++ b/tools/perf/util/term.c @@ -1,4 +1,8 @@ -#include "util.h" +#include "term.h" +#include <stdlib.h> +#include <termios.h> +#include <unistd.h> +#include <sys/ioctl.h> void get_term_dimensions(struct winsize *ws) { diff --git a/tools/perf/util/thread-stack.c b/tools/perf/util/thread-stack.c index d3301529f6a7..dd17d6a38d3a 100644 --- a/tools/perf/util/thread-stack.c +++ b/tools/perf/util/thread-stack.c @@ -15,6 +15,7 @@ #include <linux/rbtree.h> #include <linux/list.h> +#include <errno.h> #include "thread.h" #include "event.h" #include "machine.h" diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index dcdb87a5d0a1..378c418ca0c1 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c @@ -1,7 +1,9 @@ #include "../perf.h" +#include <errno.h> #include <stdlib.h> #include <stdio.h> #include <string.h> +#include <linux/kernel.h> #include "session.h" #include "thread.h" #include "thread-stack.h" diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c index 9026408ea55b..63ead7b06324 100644 --- a/tools/perf/util/thread_map.c +++ b/tools/perf/util/thread_map.c @@ -1,4 +1,5 @@ #include <dirent.h> +#include <errno.h> #include <limits.h> #include <stdbool.h> #include <stdlib.h> @@ -6,6 +7,7 @@ #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> +#include "string2.h" #include "strlist.h" #include <string.h> #include <api/fs/fs.h> diff --git a/tools/perf/util/time-utils.c b/tools/perf/util/time-utils.c index d1b21c72206d..5b5d0214debd 100644 --- a/tools/perf/util/time-utils.c +++ b/tools/perf/util/time-utils.c @@ -117,3 +117,28 @@ bool perf_time__skip_sample(struct perf_time_interval *ptime, u64 timestamp) return false; } + +int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz) +{ + u64 sec = timestamp / NSEC_PER_SEC; + u64 usec = (timestamp % NSEC_PER_SEC) / NSEC_PER_USEC; + + return scnprintf(buf, sz, "%"PRIu64".%06"PRIu64, sec, usec); +} + +int fetch_current_timestamp(char *buf, size_t sz) +{ + struct timeval tv; + struct tm tm; + char dt[32]; + + if (gettimeofday(&tv, NULL) || !localtime_r(&tv.tv_sec, &tm)) + return -1; + + if (!strftime(dt, sizeof(dt), "%Y%m%d%H%M%S", &tm)) + return -1; + + scnprintf(buf, sz, "%s%02u", dt, (unsigned)tv.tv_usec / 10000); + + return 0; +} diff --git a/tools/perf/util/time-utils.h b/tools/perf/util/time-utils.h index c1f197c4af6c..8656be08513b 100644 --- a/tools/perf/util/time-utils.h +++ b/tools/perf/util/time-utils.h @@ -1,6 +1,9 @@ #ifndef _TIME_UTILS_H_ #define _TIME_UTILS_H_ +#include <stddef.h> +#include <linux/types.h> + struct perf_time_interval { u64 start, end; }; @@ -11,4 +14,8 @@ int perf_time__parse_str(struct perf_time_interval *ptime, const char *ostr); bool perf_time__skip_sample(struct perf_time_interval *ptime, u64 timestamp); +int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz); + +int fetch_current_timestamp(char *buf, size_t sz); + #endif diff --git a/tools/perf/util/top.h b/tools/perf/util/top.h index b2940c88734a..9bdfb78a9a35 100644 --- a/tools/perf/util/top.h +++ b/tools/perf/util/top.h @@ -5,7 +5,7 @@ #include <linux/types.h> #include <stddef.h> #include <stdbool.h> -#include <termios.h> +#include <sys/ioctl.h> struct perf_evlist; struct perf_evsel; diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c index de0078e21408..746bbee645d9 100644 --- a/tools/perf/util/trace-event-parse.c +++ b/tools/perf/util/trace-event-parse.c @@ -21,13 +21,14 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <ctype.h> #include <errno.h> #include "../perf.h" #include "util.h" #include "trace-event.h" +#include "sane_ctype.h" + static int get_common_field(struct scripting_context *context, int *offset, int *size, const char *type) { diff --git a/tools/perf/util/units.c b/tools/perf/util/units.c new file mode 100644 index 000000000000..f6a2a3d117d5 --- /dev/null +++ b/tools/perf/util/units.c @@ -0,0 +1,39 @@ +#include "units.h" +#include <inttypes.h> +#include <linux/kernel.h> +#include <linux/time64.h> + +unsigned long convert_unit(unsigned long value, char *unit) +{ + *unit = ' '; + + if (value > 1000) { + value /= 1000; + *unit = 'K'; + } + + if (value > 1000) { + value /= 1000; + *unit = 'M'; + } + + if (value > 1000) { + value /= 1000; + *unit = 'G'; + } + + return value; +} + +int unit_number__scnprintf(char *buf, size_t size, u64 n) +{ + char unit[4] = "BKMG"; + int i = 0; + + while (((n / 1024) > 1) && (i < 3)) { + n /= 1024; + i++; + } + + return scnprintf(buf, size, "%" PRIu64 "%c", n, unit[i]); +} diff --git a/tools/perf/util/units.h b/tools/perf/util/units.h new file mode 100644 index 000000000000..3ed7774afaa9 --- /dev/null +++ b/tools/perf/util/units.h @@ -0,0 +1,10 @@ +#ifndef PERF_UNIT_H +#define PERF_UNIT_H + +#include <stddef.h> +#include <linux/types.h> + +unsigned long convert_unit(unsigned long value, char *unit); +int unit_number__scnprintf(char *buf, size_t size, u64 n); + +#endif /* PERF_UNIT_H */ diff --git a/tools/perf/util/unwind-libdw.c b/tools/perf/util/unwind-libdw.c index 783a53fb7a4e..f90e11a555b2 100644 --- a/tools/perf/util/unwind-libdw.c +++ b/tools/perf/util/unwind-libdw.c @@ -12,6 +12,7 @@ #include "event.h" #include "perf_regs.h" #include "callchain.h" +#include "util.h" static char *debuginfo_path; diff --git a/tools/perf/util/unwind-libdw.h b/tools/perf/util/unwind-libdw.h index 58328669ed16..4a2b269a7b3b 100644 --- a/tools/perf/util/unwind-libdw.h +++ b/tools/perf/util/unwind-libdw.h @@ -2,10 +2,12 @@ #define __PERF_UNWIND_LIBDW_H #include <elfutils/libdwfl.h> -#include "event.h" -#include "thread.h" #include "unwind.h" +struct machine; +struct perf_sample; +struct thread; + bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg); struct unwind_info { diff --git a/tools/perf/util/unwind-libunwind-local.c b/tools/perf/util/unwind-libunwind-local.c index bfb9b7987692..f8455bed6e65 100644 --- a/tools/perf/util/unwind-libunwind-local.c +++ b/tools/perf/util/unwind-libunwind-local.c @@ -16,8 +16,10 @@ */ #include <elf.h> +#include <errno.h> #include <gelf.h> #include <fcntl.h> +#include <inttypes.h> #include <string.h> #include <unistd.h> #include <sys/mman.h> diff --git a/tools/perf/util/unwind.h b/tools/perf/util/unwind.h index 61fb1e90ff51..bfbdcc6198c9 100644 --- a/tools/perf/util/unwind.h +++ b/tools/perf/util/unwind.h @@ -1,10 +1,13 @@ #ifndef __UNWIND_H #define __UNWIND_H +#include <linux/compiler.h> #include <linux/types.h> -#include "event.h" -#include "symbol.h" -#include "thread.h" + +struct map; +struct perf_sample; +struct symbol; +struct thread; struct unwind_entry { struct map *map; diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index 6097d87429e2..6450c75a6f5b 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c @@ -3,10 +3,11 @@ #include "debug.h" #include <api/fs/fs.h> #include <sys/mman.h> +#include <sys/stat.h> #include <sys/utsname.h> -#ifdef HAVE_BACKTRACE_SUPPORT -#include <execinfo.h> -#endif +#include <dirent.h> +#include <inttypes.h> +#include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -17,24 +18,8 @@ #include <linux/log2.h> #include <linux/time64.h> #include <unistd.h> -#include "callchain.h" #include "strlist.h" -#define CALLCHAIN_PARAM_DEFAULT \ - .mode = CHAIN_GRAPH_ABS, \ - .min_percent = 0.5, \ - .order = ORDER_CALLEE, \ - .key = CCKEY_FUNCTION, \ - .value = CCVAL_PERCENT, \ - -struct callchain_param callchain_param = { - CALLCHAIN_PARAM_DEFAULT -}; - -struct callchain_param callchain_param_default = { - CALLCHAIN_PARAM_DEFAULT -}; - /* * XXX We need to find a better place for these things... */ @@ -269,28 +254,6 @@ int copyfile(const char *from, const char *to) return copyfile_mode(from, to, 0755); } -unsigned long convert_unit(unsigned long value, char *unit) -{ - *unit = ' '; - - if (value > 1000) { - value /= 1000; - *unit = 'K'; - } - - if (value > 1000) { - value /= 1000; - *unit = 'M'; - } - - if (value > 1000) { - value /= 1000; - *unit = 'G'; - } - - return value; -} - static ssize_t ion(bool is_read, int fd, void *buf, size_t n) { void *buf_start = buf; @@ -372,42 +335,6 @@ int hex2u64(const char *ptr, u64 *long_val) return p - ptr; } -/* Obtain a backtrace and print it to stdout. */ -#ifdef HAVE_BACKTRACE_SUPPORT -void dump_stack(void) -{ - void *array[16]; - size_t size = backtrace(array, ARRAY_SIZE(array)); - char **strings = backtrace_symbols(array, size); - size_t i; - - printf("Obtained %zd stack frames.\n", size); - - for (i = 0; i < size; i++) - printf("%s\n", strings[i]); - - free(strings); -} -#else -void dump_stack(void) {} -#endif - -void sighandler_dump_stack(int sig) -{ - psignal(sig, "perf"); - dump_stack(); - signal(sig, SIG_DFL); - raise(sig); -} - -int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz) -{ - u64 sec = timestamp / NSEC_PER_SEC; - u64 usec = (timestamp % NSEC_PER_SEC) / NSEC_PER_USEC; - - return scnprintf(buf, sz, "%"PRIu64".%06"PRIu64, sec, usec); -} - unsigned long parse_tag_value(const char *str, struct parse_tag *tags) { struct parse_tag *i = tags; @@ -435,108 +362,6 @@ unsigned long parse_tag_value(const char *str, struct parse_tag *tags) return (unsigned long) -1; } -int get_stack_size(const char *str, unsigned long *_size) -{ - char *endptr; - unsigned long size; - unsigned long max_size = round_down(USHRT_MAX, sizeof(u64)); - - size = strtoul(str, &endptr, 0); - - do { - if (*endptr) - break; - - size = round_up(size, sizeof(u64)); - if (!size || size > max_size) - break; - - *_size = size; - return 0; - - } while (0); - - pr_err("callchain: Incorrect stack dump size (max %ld): %s\n", - max_size, str); - return -1; -} - -int parse_callchain_record(const char *arg, struct callchain_param *param) -{ - char *tok, *name, *saveptr = NULL; - char *buf; - int ret = -1; - - /* We need buffer that we know we can write to. */ - buf = malloc(strlen(arg) + 1); - if (!buf) - return -ENOMEM; - - strcpy(buf, arg); - - tok = strtok_r((char *)buf, ",", &saveptr); - name = tok ? : (char *)buf; - - do { - /* Framepointer style */ - if (!strncmp(name, "fp", sizeof("fp"))) { - if (!strtok_r(NULL, ",", &saveptr)) { - param->record_mode = CALLCHAIN_FP; - ret = 0; - } else - pr_err("callchain: No more arguments " - "needed for --call-graph fp\n"); - break; - - /* Dwarf style */ - } else if (!strncmp(name, "dwarf", sizeof("dwarf"))) { - const unsigned long default_stack_dump_size = 8192; - - ret = 0; - param->record_mode = CALLCHAIN_DWARF; - param->dump_size = default_stack_dump_size; - - tok = strtok_r(NULL, ",", &saveptr); - if (tok) { - unsigned long size = 0; - - ret = get_stack_size(tok, &size); - param->dump_size = size; - } - } else if (!strncmp(name, "lbr", sizeof("lbr"))) { - if (!strtok_r(NULL, ",", &saveptr)) { - param->record_mode = CALLCHAIN_LBR; - ret = 0; - } else - pr_err("callchain: No more arguments " - "needed for --call-graph lbr\n"); - break; - } else { - pr_err("callchain: Unknown --call-graph option " - "value: %s\n", arg); - break; - } - - } while (0); - - free(buf); - return ret; -} - -const char *get_filename_for_perf_kvm(void) -{ - const char *filename; - - if (perf_host && !perf_guest) - filename = strdup("perf.data.host"); - else if (!perf_host && perf_guest) - filename = strdup("perf.data.guest"); - else - filename = strdup("perf.data.kvm"); - - return filename; -} - int perf_event_paranoid(void) { int value; @@ -711,95 +536,3 @@ out: return tip; } - -bool is_regular_file(const char *file) -{ - struct stat st; - - if (stat(file, &st)) - return false; - - return S_ISREG(st.st_mode); -} - -int fetch_current_timestamp(char *buf, size_t sz) -{ - struct timeval tv; - struct tm tm; - char dt[32]; - - if (gettimeofday(&tv, NULL) || !localtime_r(&tv.tv_sec, &tm)) - return -1; - - if (!strftime(dt, sizeof(dt), "%Y%m%d%H%M%S", &tm)) - return -1; - - scnprintf(buf, sz, "%s%02u", dt, (unsigned)tv.tv_usec / 10000); - - return 0; -} - -void print_binary(unsigned char *data, size_t len, - size_t bytes_per_line, print_binary_t printer, - void *extra) -{ - size_t i, j, mask; - - if (!printer) - return; - - bytes_per_line = roundup_pow_of_two(bytes_per_line); - mask = bytes_per_line - 1; - - printer(BINARY_PRINT_DATA_BEGIN, 0, extra); - for (i = 0; i < len; i++) { - if ((i & mask) == 0) { - printer(BINARY_PRINT_LINE_BEGIN, -1, extra); - printer(BINARY_PRINT_ADDR, i, extra); - } - - printer(BINARY_PRINT_NUM_DATA, data[i], extra); - - if (((i & mask) == mask) || i == len - 1) { - for (j = 0; j < mask-(i & mask); j++) - printer(BINARY_PRINT_NUM_PAD, -1, extra); - - printer(BINARY_PRINT_SEP, i, extra); - for (j = i & ~mask; j <= i; j++) - printer(BINARY_PRINT_CHAR_DATA, data[j], extra); - for (j = 0; j < mask-(i & mask); j++) - printer(BINARY_PRINT_CHAR_PAD, i, extra); - printer(BINARY_PRINT_LINE_END, -1, extra); - } - } - printer(BINARY_PRINT_DATA_END, -1, extra); -} - -int is_printable_array(char *p, unsigned int len) -{ - unsigned int i; - - if (!p || !len || p[len - 1] != 0) - return 0; - - len--; - - for (i = 0; i < len; i++) { - if (!isprint(p[i]) && !isspace(p[i])) - return 0; - } - return 1; -} - -int unit_number__scnprintf(char *buf, size_t size, u64 n) -{ - char unit[4] = "BKMG"; - int i = 0; - - while (((n / 1024) > 1) && (i < 3)) { - n /= 1024; - i++; - } - - return scnprintf(buf, size, "%" PRIu64 "%c", n, unit[i]); -} diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index 7cf5752b38fd..3852b6d3270a 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h @@ -1,126 +1,21 @@ #ifndef GIT_COMPAT_UTIL_H #define GIT_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 <term.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/types.h> -#include <sys/ttydefaults.h> -#include <api/fs/tracing_path.h> -#include <termios.h> -#include <linux/bitops.h> -#include <termios.h> -#include "strlist.h" -extern const char *graph_line; -extern const char *graph_dotted_line; -extern const char *spaces; -extern const char *dots; extern char buildid_dir[]; -/* On most systems <limits.h> would have given us this, but - * not on some systems (e.g. GNU/Hurd). - */ -#ifndef PATH_MAX -#define PATH_MAX 4096 -#endif - -#ifndef PRIuMAX -#define PRIuMAX "llu" -#endif - -#ifndef PRIu32 -#define PRIu32 "u" -#endif - -#ifndef PRIx32 -#define PRIx32 "x" -#endif - -#ifndef PATH_SEP -#define PATH_SEP ':' -#endif - -#ifndef STRIP_EXTENSION -#define STRIP_EXTENSION "" -#endif - -#ifndef has_dos_drive_prefix -#define has_dos_drive_prefix(path) 0 -#endif - -#ifndef is_dir_sep -#define is_dir_sep(c) ((c) == '/') -#endif - #ifdef __GNUC__ #define NORETURN __attribute__((__noreturn__)) #else @@ -143,22 +38,6 @@ void set_warning_routine(void (*routine)(const char *err, va_list params)); int prefixcmp(const char *str, const char *prefix); void set_buildid_dir(const char *dir); -#ifdef __GLIBC_PREREQ -#if __GLIBC_PREREQ(2, 1) -#define HAVE_STRCHRNUL -#endif -#endif - -#ifndef HAVE_STRCHRNUL -#define strchrnul gitstrchrnul -static inline char *gitstrchrnul(const char *s, int c) -{ - while (*s && *s != c) - s++; - return (char *)s; -} -#endif - static inline void *zalloc(size_t size) { return calloc(1, size); @@ -166,47 +45,8 @@ static inline void *zalloc(size_t size) #define zfree(ptr) ({ free(*ptr); *ptr = NULL; }) -/* Sane ctype - no locale, and works with signed chars */ -#undef isascii -#undef isspace -#undef isdigit -#undef isxdigit -#undef isalpha -#undef isprint -#undef isalnum -#undef islower -#undef isupper -#undef tolower -#undef toupper - -extern unsigned char sane_ctype[256]; -#define GIT_SPACE 0x01 -#define GIT_DIGIT 0x02 -#define GIT_ALPHA 0x04 -#define GIT_GLOB_SPECIAL 0x08 -#define GIT_REGEX_SPECIAL 0x10 -#define GIT_PRINT_EXTRA 0x20 -#define GIT_PRINT 0x3E -#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0) -#define isascii(x) (((x) & ~0x7f) == 0) -#define isspace(x) sane_istest(x,GIT_SPACE) -#define isdigit(x) sane_istest(x,GIT_DIGIT) -#define isxdigit(x) \ - (sane_istest(toupper(x), GIT_ALPHA | GIT_DIGIT) && toupper(x) < 'G') -#define isalpha(x) sane_istest(x,GIT_ALPHA) -#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT) -#define isprint(x) sane_istest(x,GIT_PRINT) -#define islower(x) (sane_istest(x,GIT_ALPHA) && (x & 0x20)) -#define isupper(x) (sane_istest(x,GIT_ALPHA) && !(x & 0x20)) -#define tolower(x) sane_case((unsigned char)(x), 0x20) -#define toupper(x) sane_case((unsigned char)(x), 0) - -static inline int sane_case(int x, int high) -{ - if (sane_istest(x, GIT_ALPHA)) - x = (x & ~0x20) | high; - return x; -} +struct dirent; +struct strlist; int mkdir_p(char *path, mode_t mode); int rm_rf(const char *path); @@ -216,19 +56,6 @@ int copyfile(const char *from, const char *to); int copyfile_mode(const char *from, const char *to, mode_t mode); int copyfile_offset(int fromfd, loff_t from_ofs, int tofd, loff_t to_ofs, u64 size); -s64 perf_atoll(const char *str); -char **argv_split(const char *str, int *argcp); -void argv_free(char **argv); -bool strglobmatch(const char *str, const char *pat); -bool strglobmatch_nocase(const char *str, const char *pat); -bool strlazymatch(const char *str, const char *pat); -static inline bool strisglob(const char *str) -{ - return strpbrk(str, "*?[") != NULL; -} -int strtailcmp(const char *s1, const char *s2); -char *strxfrchar(char *s, char from, char to); -unsigned long convert_unit(unsigned long value, char *unit); ssize_t readn(int fd, void *buf, size_t n); ssize_t writen(int fd, void *buf, size_t n); @@ -236,23 +63,9 @@ struct perf_event_attr; void event_attr_init(struct perf_event_attr *attr); -#define _STR(x) #x -#define STR(x) _STR(x) - size_t hex_width(u64 v); int hex2u64(const char *ptr, u64 *val); -char *ltrim(char *s); -char *rtrim(char *s); - -static inline char *trim(char *s) -{ - return ltrim(rtrim(s)); -} - -void dump_stack(void); -void sighandler_dump_stack(int sig); - extern unsigned int page_size; extern int cacheline_size; extern int sysctl_perf_event_max_stack; @@ -265,63 +78,13 @@ struct parse_tag { unsigned long parse_tag_value(const char *str, struct parse_tag *tags); -#define SRCLINE_UNKNOWN ((char *) "??:0") - -static inline int path__join(char *bf, size_t size, - const char *path1, const char *path2) -{ - return scnprintf(bf, size, "%s%s%s", path1, path1[0] ? "/" : "", path2); -} - -static inline int path__join3(char *bf, size_t size, - const char *path1, const char *path2, - const char *path3) -{ - return scnprintf(bf, size, "%s%s%s%s%s", - path1, path1[0] ? "/" : "", - path2, path2[0] ? "/" : "", path3); -} - -struct dso; -struct symbol; - -extern bool srcline_full_filename; -char *get_srcline(struct dso *dso, u64 addr, struct symbol *sym, - bool show_sym, bool show_addr); -char *__get_srcline(struct dso *dso, u64 addr, struct symbol *sym, - bool show_sym, bool show_addr, bool unwind_inlines); -void free_srcline(char *srcline); - int perf_event_paranoid(void); void mem_bswap_64(void *src, int byte_size); void mem_bswap_32(void *src, int byte_size); -const char *get_filename_for_perf_kvm(void); bool find_process(const char *name); -#ifdef HAVE_ZLIB_SUPPORT -int gzip_decompress_to_file(const char *input, int output_fd); -#endif - -#ifdef HAVE_LZMA_SUPPORT -int lzma_decompress_to_file(const char *input, int output_fd); -#endif - -char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints); - -static inline char *asprintf_expr_in_ints(const char *var, size_t nints, int *ints) -{ - return asprintf_expr_inout_ints(var, true, nints, ints); -} - -static inline char *asprintf_expr_not_in_ints(const char *var, size_t nints, int *ints) -{ - return asprintf_expr_inout_ints(var, false, nints, ints); -} - -int get_stack_size(const char *str, unsigned long *_size); - int fetch_kernel_version(unsigned int *puint, char *str, size_t str_sz); #define KVER_VERSION(x) (((x) >> 16) & 0xff) @@ -331,53 +94,9 @@ int fetch_kernel_version(unsigned int *puint, #define KVER_PARAM(x) KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x) const char *perf_tip(const char *dirpath); -bool is_regular_file(const char *file); -int fetch_current_timestamp(char *buf, size_t sz); - -enum binary_printer_ops { - BINARY_PRINT_DATA_BEGIN, - BINARY_PRINT_LINE_BEGIN, - BINARY_PRINT_ADDR, - BINARY_PRINT_NUM_DATA, - BINARY_PRINT_NUM_PAD, - BINARY_PRINT_SEP, - BINARY_PRINT_CHAR_DATA, - BINARY_PRINT_CHAR_PAD, - BINARY_PRINT_LINE_END, - BINARY_PRINT_DATA_END, -}; - -typedef void (*print_binary_t)(enum binary_printer_ops, - unsigned int val, - void *extra); - -void print_binary(unsigned char *data, size_t len, - size_t bytes_per_line, print_binary_t printer, - void *extra); #ifndef HAVE_SCHED_GETCPU_SUPPORT int sched_getcpu(void); #endif -int is_printable_array(char *p, unsigned int len); - -int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz); - -int unit_number__scnprintf(char *buf, size_t size, u64 n); - -struct inline_list { - char *filename; - char *funcname; - unsigned int line_nr; - struct list_head list; -}; - -struct inline_node { - u64 addr; - struct list_head val; -}; - -struct inline_node *dso__parse_addr_inlines(struct dso *dso, u64 addr); -void inline_node__delete(struct inline_node *node); - #endif /* GIT_COMPAT_UTIL_H */ diff --git a/tools/perf/util/vdso.c b/tools/perf/util/vdso.c index 7bdcad484225..d3c39eec89a8 100644 --- a/tools/perf/util/vdso.c +++ b/tools/perf/util/vdso.c @@ -1,4 +1,4 @@ - +#include <errno.h> #include <unistd.h> #include <stdio.h> #include <string.h> diff --git a/tools/perf/util/xyarray.c b/tools/perf/util/xyarray.c index c10ba41ef3f6..7251fdbabced 100644 --- a/tools/perf/util/xyarray.c +++ b/tools/perf/util/xyarray.c @@ -1,5 +1,7 @@ #include "xyarray.h" #include "util.h" +#include <stdlib.h> +#include <string.h> struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size) { diff --git a/tools/perf/util/zlib.c b/tools/perf/util/zlib.c index 495a449fc25c..1329d843eb7b 100644 --- a/tools/perf/util/zlib.c +++ b/tools/perf/util/zlib.c @@ -4,6 +4,7 @@ #include <sys/mman.h> #include <zlib.h> +#include "util/compress.h" #include "util/util.h" #include "util/debug.h" |