Commit d8b5297f authored by Thomas Gleixner's avatar Thomas Gleixner

Merge tag 'perf-core-for-mingo-5.1-20190321' of...

Merge tag 'perf-core-for-mingo-5.1-20190321' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/urgent

Pull perf/core improvements and fixes from Arnaldo:

BPF:

  Song Liu:

  - Add support for annotating BPF programs, using the PERF_RECORD_BPF_EVENT
    and PERF_RECORD_KSYMBOL recently added to the kernel and plugging
    binutils's libopcodes disassembly of BPF programs with the existing
    annotation interfaces in 'perf annotate', 'perf report' and 'perf top'
    various output formats (--stdio, --stdio2, --tui).

perf list:

  Andi Kleen:

  - Filter metrics when using substring search.

perf record:

  Andi Kleen:

  - Allow to limit number of reported perf.data files

  - Clarify help for --switch-output.

perf report:

  Andi Kleen

  - Indicate JITed code better.

  - Show all sort keys in help output.

perf script:

  Andi Kleen:

  - Support relative time.

perf stat:

  Andi Kleen:

  - Improve scaling.

General:

  Changbin Du:

  - Fix some mostly error path memory and reference count leaks found
    using gcc's ASan and UBSan.

Vendor events:

  Mamatha Inamdar:

  - Remove P8 HW events which are not supported.
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parents 4a98be82 f8dfeae0
This diff is collapsed.
...@@ -66,7 +66,8 @@ FEATURE_TESTS_BASIC := \ ...@@ -66,7 +66,8 @@ FEATURE_TESTS_BASIC := \
sched_getcpu \ sched_getcpu \
sdt \ sdt \
setns \ setns \
libaio libaio \
disassembler-four-args
# FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list # FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list
# of all feature tests # of all feature tests
...@@ -118,7 +119,8 @@ FEATURE_DISPLAY ?= \ ...@@ -118,7 +119,8 @@ FEATURE_DISPLAY ?= \
lzma \ lzma \
get_cpuid \ get_cpuid \
bpf \ bpf \
libaio libaio \
disassembler-four-args
# Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features. # Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features.
# If in the future we need per-feature checks/flags for features not # If in the future we need per-feature checks/flags for features not
......
...@@ -178,6 +178,10 @@ ...@@ -178,6 +178,10 @@
# include "test-reallocarray.c" # include "test-reallocarray.c"
#undef main #undef main
#define main main_test_disassembler_four_args
# include "test-disassembler-four-args.c"
#undef main
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
main_test_libpython(); main_test_libpython();
...@@ -219,6 +223,7 @@ int main(int argc, char *argv[]) ...@@ -219,6 +223,7 @@ int main(int argc, char *argv[])
main_test_setns(); main_test_setns();
main_test_libaio(); main_test_libaio();
main_test_reallocarray(); main_test_reallocarray();
main_test_disassembler_four_args();
return 0; return 0;
} }
...@@ -112,6 +112,11 @@ void libbpf_print(enum libbpf_print_level level, const char *format, ...) ...@@ -112,6 +112,11 @@ void libbpf_print(enum libbpf_print_level level, const char *format, ...)
# define LIBBPF_ELF_C_READ_MMAP ELF_C_READ # define LIBBPF_ELF_C_READ_MMAP ELF_C_READ
#endif #endif
static inline __u64 ptr_to_u64(const void *ptr)
{
return (__u64) (unsigned long) ptr;
}
struct bpf_capabilities { struct bpf_capabilities {
/* v4.14: kernel support for program & map names. */ /* v4.14: kernel support for program & map names. */
__u32 name:1; __u32 name:1;
...@@ -622,7 +627,7 @@ bpf_object__init_maps(struct bpf_object *obj, int flags) ...@@ -622,7 +627,7 @@ bpf_object__init_maps(struct bpf_object *obj, int flags)
bool strict = !(flags & MAPS_RELAX_COMPAT); bool strict = !(flags & MAPS_RELAX_COMPAT);
int i, map_idx, map_def_sz, nr_maps = 0; int i, map_idx, map_def_sz, nr_maps = 0;
Elf_Scn *scn; Elf_Scn *scn;
Elf_Data *data; Elf_Data *data = NULL;
Elf_Data *symbols = obj->efile.symbols; Elf_Data *symbols = obj->efile.symbols;
if (obj->efile.maps_shndx < 0) if (obj->efile.maps_shndx < 0)
...@@ -2999,3 +3004,249 @@ bpf_perf_event_read_simple(void *mmap_mem, size_t mmap_size, size_t page_size, ...@@ -2999,3 +3004,249 @@ bpf_perf_event_read_simple(void *mmap_mem, size_t mmap_size, size_t page_size,
ring_buffer_write_tail(header, data_tail); ring_buffer_write_tail(header, data_tail);
return ret; return ret;
} }
struct bpf_prog_info_array_desc {
int array_offset; /* e.g. offset of jited_prog_insns */
int count_offset; /* e.g. offset of jited_prog_len */
int size_offset; /* > 0: offset of rec size,
* < 0: fix size of -size_offset
*/
};
static struct bpf_prog_info_array_desc bpf_prog_info_array_desc[] = {
[BPF_PROG_INFO_JITED_INSNS] = {
offsetof(struct bpf_prog_info, jited_prog_insns),
offsetof(struct bpf_prog_info, jited_prog_len),
-1,
},
[BPF_PROG_INFO_XLATED_INSNS] = {
offsetof(struct bpf_prog_info, xlated_prog_insns),
offsetof(struct bpf_prog_info, xlated_prog_len),
-1,
},
[BPF_PROG_INFO_MAP_IDS] = {
offsetof(struct bpf_prog_info, map_ids),
offsetof(struct bpf_prog_info, nr_map_ids),
-(int)sizeof(__u32),
},
[BPF_PROG_INFO_JITED_KSYMS] = {
offsetof(struct bpf_prog_info, jited_ksyms),
offsetof(struct bpf_prog_info, nr_jited_ksyms),
-(int)sizeof(__u64),
},
[BPF_PROG_INFO_JITED_FUNC_LENS] = {
offsetof(struct bpf_prog_info, jited_func_lens),
offsetof(struct bpf_prog_info, nr_jited_func_lens),
-(int)sizeof(__u32),
},
[BPF_PROG_INFO_FUNC_INFO] = {
offsetof(struct bpf_prog_info, func_info),
offsetof(struct bpf_prog_info, nr_func_info),
offsetof(struct bpf_prog_info, func_info_rec_size),
},
[BPF_PROG_INFO_LINE_INFO] = {
offsetof(struct bpf_prog_info, line_info),
offsetof(struct bpf_prog_info, nr_line_info),
offsetof(struct bpf_prog_info, line_info_rec_size),
},
[BPF_PROG_INFO_JITED_LINE_INFO] = {
offsetof(struct bpf_prog_info, jited_line_info),
offsetof(struct bpf_prog_info, nr_jited_line_info),
offsetof(struct bpf_prog_info, jited_line_info_rec_size),
},
[BPF_PROG_INFO_PROG_TAGS] = {
offsetof(struct bpf_prog_info, prog_tags),
offsetof(struct bpf_prog_info, nr_prog_tags),
-(int)sizeof(__u8) * BPF_TAG_SIZE,
},
};
static __u32 bpf_prog_info_read_offset_u32(struct bpf_prog_info *info, int offset)
{
__u32 *array = (__u32 *)info;
if (offset >= 0)
return array[offset / sizeof(__u32)];
return -(int)offset;
}
static __u64 bpf_prog_info_read_offset_u64(struct bpf_prog_info *info, int offset)
{
__u64 *array = (__u64 *)info;
if (offset >= 0)
return array[offset / sizeof(__u64)];
return -(int)offset;
}
static void bpf_prog_info_set_offset_u32(struct bpf_prog_info *info, int offset,
__u32 val)
{
__u32 *array = (__u32 *)info;
if (offset >= 0)
array[offset / sizeof(__u32)] = val;
}
static void bpf_prog_info_set_offset_u64(struct bpf_prog_info *info, int offset,
__u64 val)
{
__u64 *array = (__u64 *)info;
if (offset >= 0)
array[offset / sizeof(__u64)] = val;
}
struct bpf_prog_info_linear *
bpf_program__get_prog_info_linear(int fd, __u64 arrays)
{
struct bpf_prog_info_linear *info_linear;
struct bpf_prog_info info = {};
__u32 info_len = sizeof(info);
__u32 data_len = 0;
int i, err;
void *ptr;
if (arrays >> BPF_PROG_INFO_LAST_ARRAY)
return ERR_PTR(-EINVAL);
/* step 1: get array dimensions */
err = bpf_obj_get_info_by_fd(fd, &info, &info_len);
if (err) {
pr_debug("can't get prog info: %s", strerror(errno));
return ERR_PTR(-EFAULT);
}
/* step 2: calculate total size of all arrays */
for (i = BPF_PROG_INFO_FIRST_ARRAY; i < BPF_PROG_INFO_LAST_ARRAY; ++i) {
bool include_array = (arrays & (1UL << i)) > 0;
struct bpf_prog_info_array_desc *desc;
__u32 count, size;
desc = bpf_prog_info_array_desc + i;
/* kernel is too old to support this field */
if (info_len < desc->array_offset + sizeof(__u32) ||
info_len < desc->count_offset + sizeof(__u32) ||
(desc->size_offset > 0 && info_len < desc->size_offset))
include_array = false;
if (!include_array) {
arrays &= ~(1UL << i); /* clear the bit */
continue;
}
count = bpf_prog_info_read_offset_u32(&info, desc->count_offset);
size = bpf_prog_info_read_offset_u32(&info, desc->size_offset);
data_len += count * size;
}
/* step 3: allocate continuous memory */
data_len = roundup(data_len, sizeof(__u64));
info_linear = malloc(sizeof(struct bpf_prog_info_linear) + data_len);
if (!info_linear)
return ERR_PTR(-ENOMEM);
/* step 4: fill data to info_linear->info */
info_linear->arrays = arrays;
memset(&info_linear->info, 0, sizeof(info));
ptr = info_linear->data;
for (i = BPF_PROG_INFO_FIRST_ARRAY; i < BPF_PROG_INFO_LAST_ARRAY; ++i) {
struct bpf_prog_info_array_desc *desc;
__u32 count, size;
if ((arrays & (1UL << i)) == 0)
continue;
desc = bpf_prog_info_array_desc + i;
count = bpf_prog_info_read_offset_u32(&info, desc->count_offset);
size = bpf_prog_info_read_offset_u32(&info, desc->size_offset);
bpf_prog_info_set_offset_u32(&info_linear->info,
desc->count_offset, count);
bpf_prog_info_set_offset_u32(&info_linear->info,
desc->size_offset, size);
bpf_prog_info_set_offset_u64(&info_linear->info,
desc->array_offset,
ptr_to_u64(ptr));
ptr += count * size;
}
/* step 5: call syscall again to get required arrays */
err = bpf_obj_get_info_by_fd(fd, &info_linear->info, &info_len);
if (err) {
pr_debug("can't get prog info: %s", strerror(errno));
free(info_linear);
return ERR_PTR(-EFAULT);
}
/* step 6: verify the data */
for (i = BPF_PROG_INFO_FIRST_ARRAY; i < BPF_PROG_INFO_LAST_ARRAY; ++i) {
struct bpf_prog_info_array_desc *desc;
__u32 v1, v2;
if ((arrays & (1UL << i)) == 0)
continue;
desc = bpf_prog_info_array_desc + i;
v1 = bpf_prog_info_read_offset_u32(&info, desc->count_offset);
v2 = bpf_prog_info_read_offset_u32(&info_linear->info,
desc->count_offset);
if (v1 != v2)
pr_warning("%s: mismatch in element count\n", __func__);
v1 = bpf_prog_info_read_offset_u32(&info, desc->size_offset);
v2 = bpf_prog_info_read_offset_u32(&info_linear->info,
desc->size_offset);
if (v1 != v2)
pr_warning("%s: mismatch in rec size\n", __func__);
}
/* step 7: update info_len and data_len */
info_linear->info_len = sizeof(struct bpf_prog_info);
info_linear->data_len = data_len;
return info_linear;
}
void bpf_program__bpil_addr_to_offs(struct bpf_prog_info_linear *info_linear)
{
int i;
for (i = BPF_PROG_INFO_FIRST_ARRAY; i < BPF_PROG_INFO_LAST_ARRAY; ++i) {
struct bpf_prog_info_array_desc *desc;
__u64 addr, offs;
if ((info_linear->arrays & (1UL << i)) == 0)
continue;
desc = bpf_prog_info_array_desc + i;
addr = bpf_prog_info_read_offset_u64(&info_linear->info,
desc->array_offset);
offs = addr - ptr_to_u64(info_linear->data);
bpf_prog_info_set_offset_u64(&info_linear->info,
desc->array_offset, offs);
}
}
void bpf_program__bpil_offs_to_addr(struct bpf_prog_info_linear *info_linear)
{
int i;
for (i = BPF_PROG_INFO_FIRST_ARRAY; i < BPF_PROG_INFO_LAST_ARRAY; ++i) {
struct bpf_prog_info_array_desc *desc;
__u64 addr, offs;
if ((info_linear->arrays & (1UL << i)) == 0)
continue;
desc = bpf_prog_info_array_desc + i;
offs = bpf_prog_info_read_offset_u64(&info_linear->info,
desc->array_offset);
addr = offs + ptr_to_u64(info_linear->data);
bpf_prog_info_set_offset_u64(&info_linear->info,
desc->array_offset, addr);
}
}
...@@ -378,6 +378,69 @@ LIBBPF_API bool bpf_probe_map_type(enum bpf_map_type map_type, __u32 ifindex); ...@@ -378,6 +378,69 @@ LIBBPF_API bool bpf_probe_map_type(enum bpf_map_type map_type, __u32 ifindex);
LIBBPF_API bool bpf_probe_helper(enum bpf_func_id id, LIBBPF_API bool bpf_probe_helper(enum bpf_func_id id,
enum bpf_prog_type prog_type, __u32 ifindex); enum bpf_prog_type prog_type, __u32 ifindex);
/*
* Get bpf_prog_info in continuous memory
*
* struct bpf_prog_info has multiple arrays. The user has option to choose
* arrays to fetch from kernel. The following APIs provide an uniform way to
* fetch these data. All arrays in bpf_prog_info are stored in a single
* continuous memory region. This makes it easy to store the info in a
* file.
*
* Before writing bpf_prog_info_linear to files, it is necessary to
* translate pointers in bpf_prog_info to offsets. Helper functions
* bpf_program__bpil_addr_to_offs() and bpf_program__bpil_offs_to_addr()
* are introduced to switch between pointers and offsets.
*
* Examples:
* # To fetch map_ids and prog_tags:
* __u64 arrays = (1UL << BPF_PROG_INFO_MAP_IDS) |
* (1UL << BPF_PROG_INFO_PROG_TAGS);
* struct bpf_prog_info_linear *info_linear =
* bpf_program__get_prog_info_linear(fd, arrays);
*
* # To save data in file
* bpf_program__bpil_addr_to_offs(info_linear);
* write(f, info_linear, sizeof(*info_linear) + info_linear->data_len);
*
* # To read data from file
* read(f, info_linear, <proper_size>);
* bpf_program__bpil_offs_to_addr(info_linear);
*/
enum bpf_prog_info_array {
BPF_PROG_INFO_FIRST_ARRAY = 0,
BPF_PROG_INFO_JITED_INSNS = 0,
BPF_PROG_INFO_XLATED_INSNS,
BPF_PROG_INFO_MAP_IDS,
BPF_PROG_INFO_JITED_KSYMS,
BPF_PROG_INFO_JITED_FUNC_LENS,
BPF_PROG_INFO_FUNC_INFO,
BPF_PROG_INFO_LINE_INFO,
BPF_PROG_INFO_JITED_LINE_INFO,
BPF_PROG_INFO_PROG_TAGS,
BPF_PROG_INFO_LAST_ARRAY,
};
struct bpf_prog_info_linear {
/* size of struct bpf_prog_info, when the tool is compiled */
__u32 info_len;
/* total bytes allocated for data, round up to 8 bytes */
__u32 data_len;
/* which arrays are included in data */
__u64 arrays;
struct bpf_prog_info info;
__u8 data[];
};
LIBBPF_API struct bpf_prog_info_linear *
bpf_program__get_prog_info_linear(int fd, __u64 arrays);
LIBBPF_API void
bpf_program__bpil_addr_to_offs(struct bpf_prog_info_linear *info_linear);
LIBBPF_API void
bpf_program__bpil_offs_to_addr(struct bpf_prog_info_linear *info_linear);
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */
#endif #endif
......
...@@ -153,4 +153,7 @@ LIBBPF_0.0.2 { ...@@ -153,4 +153,7 @@ LIBBPF_0.0.2 {
xsk_socket__delete; xsk_socket__delete;
xsk_umem__fd; xsk_umem__fd;
xsk_socket__fd; xsk_socket__fd;
bpf_program__get_prog_info_linear;
bpf_program__bpil_addr_to_offs;
bpf_program__bpil_offs_to_addr;
} LIBBPF_0.0.1; } LIBBPF_0.0.1;
...@@ -47,3 +47,27 @@ Those objects are then used in final linking: ...@@ -47,3 +47,27 @@ Those objects are then used in final linking:
NOTE this description is omitting other libraries involved, only NOTE this description is omitting other libraries involved, only
focusing on build framework outcomes focusing on build framework outcomes
3) Build with ASan or UBSan
==========================
$ cd tools/perf
$ make DESTDIR=/usr
$ make DESTDIR=/usr install
AddressSanitizer (or ASan) is a GCC feature that detects memory corruption bugs
such as buffer overflows and memory leaks.
$ cd tools/perf
$ make DEBUG=1 EXTRA_CFLAGS='-fno-omit-frame-pointer -fsanitize=address'
$ ASAN_OPTIONS=log_path=asan.log ./perf record -a
ASan outputs all detected issues into a log file named 'asan.log.<pid>'.
UndefinedBehaviorSanitizer (or UBSan) is a fast undefined behavior detector
supported by GCC. UBSan detects undefined behaviors of programs at runtime.
$ cd tools/perf
$ make DEBUG=1 EXTRA_CFLAGS='-fno-omit-frame-pointer -fsanitize=undefined'
$ UBSAN_OPTIONS=print_stacktrace=1 ./perf record -a
If UBSan detects any problem at runtime, it outputs a “runtime error:” message.
...@@ -114,7 +114,7 @@ Given a $HOME/.perfconfig like this: ...@@ -114,7 +114,7 @@ Given a $HOME/.perfconfig like this:
[report] [report]
# Defaults # Defaults
sort-order = comm,dso,symbol sort_order = comm,dso,symbol
percent-limit = 0 percent-limit = 0
queue-size = 0 queue-size = 0
children = true children = true
......
...@@ -495,6 +495,10 @@ overhead. You can still switch them on with: ...@@ -495,6 +495,10 @@ overhead. You can still switch them on with:
--switch-output --no-no-buildid --no-no-buildid-cache --switch-output --no-no-buildid --no-no-buildid-cache
--switch-max-files=N::
When rotating perf.data with --switch-output, only keep N files.
--dry-run:: --dry-run::
Parse options then exit. --dry-run can be used to detect errors in cmdline Parse options then exit. --dry-run can be used to detect errors in cmdline
options. options.
......
...@@ -380,6 +380,9 @@ include::itrace.txt[] ...@@ -380,6 +380,9 @@ include::itrace.txt[]
Set the maximum number of program blocks to print with brstackasm for Set the maximum number of program blocks to print with brstackasm for
each sample. each sample.
--reltime::
Print time stamps relative to trace start.
--per-event-dump:: --per-event-dump::
Create per event files with a "perf.data.EVENT.dump" name instead of Create per event files with a "perf.data.EVENT.dump" name instead of
printing to stdout, useful, for instance, for generating flamegraphs. printing to stdout, useful, for instance, for generating flamegraphs.
......
...@@ -72,9 +72,8 @@ report:: ...@@ -72,9 +72,8 @@ report::
--all-cpus:: --all-cpus::
system-wide collection from all CPUs (default if no target is specified) system-wide collection from all CPUs (default if no target is specified)
-c:: --no-scale::
--scale:: Don't scale/normalize counter values
scale/normalize counter values
-d:: -d::
--detailed:: --detailed::
......
...@@ -227,6 +227,8 @@ FEATURE_CHECK_LDFLAGS-libpython-version := $(PYTHON_EMBED_LDOPTS) ...@@ -227,6 +227,8 @@ FEATURE_CHECK_LDFLAGS-libpython-version := $(PYTHON_EMBED_LDOPTS)
FEATURE_CHECK_LDFLAGS-libaio = -lrt FEATURE_CHECK_LDFLAGS-libaio = -lrt
FEATURE_CHECK_LDFLAGS-disassembler-four-args = -lbfd -lopcodes
CFLAGS += -fno-omit-frame-pointer CFLAGS += -fno-omit-frame-pointer
CFLAGS += -ggdb3 CFLAGS += -ggdb3
CFLAGS += -funwind-tables CFLAGS += -funwind-tables
...@@ -713,7 +715,7 @@ else ...@@ -713,7 +715,7 @@ else
endif endif
ifeq ($(feature-libbfd), 1) ifeq ($(feature-libbfd), 1)
EXTLIBS += -lbfd EXTLIBS += -lbfd -lopcodes
else else
# we are on a system that requires -liberty and (maybe) -lz # we are on a system that requires -liberty and (maybe) -lz
# to link against -lbfd; test each case individually here # to link against -lbfd; test each case individually here
...@@ -724,12 +726,15 @@ else ...@@ -724,12 +726,15 @@ else
$(call feature_check,libbfd-liberty-z) $(call feature_check,libbfd-liberty-z)
ifeq ($(feature-libbfd-liberty), 1) ifeq ($(feature-libbfd-liberty), 1)
EXTLIBS += -lbfd -liberty EXTLIBS += -lbfd -lopcodes -liberty
FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -ldl
else else
ifeq ($(feature-libbfd-liberty-z), 1) ifeq ($(feature-libbfd-liberty-z), 1)
EXTLIBS += -lbfd -liberty -lz EXTLIBS += -lbfd -lopcodes -liberty -lz
FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -lz -ldl
endif endif
endif endif
$(call feature_check,disassembler-four-args)
endif endif
ifdef NO_DEMANGLE ifdef NO_DEMANGLE
...@@ -808,6 +813,10 @@ ifdef HAVE_KVM_STAT_SUPPORT ...@@ -808,6 +813,10 @@ ifdef HAVE_KVM_STAT_SUPPORT
CFLAGS += -DHAVE_KVM_STAT_SUPPORT CFLAGS += -DHAVE_KVM_STAT_SUPPORT
endif endif
ifeq ($(feature-disassembler-four-args), 1)
CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
endif
ifeq (${IS_64_BIT}, 1) ifeq (${IS_64_BIT}, 1)
ifndef NO_PERF_READ_VDSO32 ifndef NO_PERF_READ_VDSO32
$(call feature_check,compile-32) $(call feature_check,compile-32)
......
...@@ -224,7 +224,7 @@ static int do_threads(struct worker *worker, struct cpu_map *cpu) ...@@ -224,7 +224,7 @@ static int do_threads(struct worker *worker, struct cpu_map *cpu)
pthread_attr_t thread_attr, *attrp = NULL; pthread_attr_t thread_attr, *attrp = NULL;
cpu_set_t cpuset; cpu_set_t cpuset;
unsigned int i, j; unsigned int i, j;
int ret; int ret = 0;
if (!noaffinity) if (!noaffinity)
pthread_attr_init(&thread_attr); pthread_attr_init(&thread_attr);
......
...@@ -293,7 +293,7 @@ static int do_threads(struct worker *worker, struct cpu_map *cpu) ...@@ -293,7 +293,7 @@ static int do_threads(struct worker *worker, struct cpu_map *cpu)
pthread_attr_t thread_attr, *attrp = NULL; pthread_attr_t thread_attr, *attrp = NULL;
cpu_set_t cpuset; cpu_set_t cpuset;
unsigned int i, j; unsigned int i, j;
int ret, events = EPOLLIN; int ret = 0, events = EPOLLIN;
if (oneshot) if (oneshot)
events |= EPOLLONESHOT; events |= EPOLLONESHOT;
......
...@@ -119,7 +119,7 @@ int cmd_list(int argc, const char **argv) ...@@ -119,7 +119,7 @@ int cmd_list(int argc, const char **argv)
details_flag); details_flag);
print_tracepoint_events(NULL, s, raw_dump); print_tracepoint_events(NULL, s, raw_dump);
print_sdt_events(NULL, s, raw_dump); print_sdt_events(NULL, s, raw_dump);
metricgroup__print(true, true, NULL, raw_dump, details_flag); metricgroup__print(true, true, s, raw_dump, details_flag);
free(s); free(s);
} }
} }
......
...@@ -62,6 +62,9 @@ struct switch_output { ...@@ -62,6 +62,9 @@ struct switch_output {
unsigned long time; unsigned long time;
const char *str; const char *str;
bool set; bool set;
char **filenames;
int num_files;
int cur_file;
}; };
struct record { struct record {
...@@ -892,6 +895,7 @@ record__switch_output(struct record *rec, bool at_exit) ...@@ -892,6 +895,7 @@ record__switch_output(struct record *rec, bool at_exit)
{ {
struct perf_data *data = &rec->data; struct perf_data *data = &rec->data;
int fd, err; int fd, err;
char *new_filename;
/* Same Size: "2015122520103046"*/ /* Same Size: "2015122520103046"*/
char timestamp[] = "InvalidTimestamp"; char timestamp[] = "InvalidTimestamp";
...@@ -912,7 +916,7 @@ record__switch_output(struct record *rec, bool at_exit) ...@@ -912,7 +916,7 @@ record__switch_output(struct record *rec, bool at_exit)
fd = perf_data__switch(data, timestamp, fd = perf_data__switch(data, timestamp,
rec->session->header.data_offset, rec->session->header.data_offset,
at_exit); at_exit, &new_filename);
if (fd >= 0 && !at_exit) { if (fd >= 0 && !at_exit) {
rec->bytes_written = 0; rec->bytes_written = 0;
rec->session->header.data_size = 0; rec->session->header.data_size = 0;
...@@ -922,6 +926,21 @@ record__switch_output(struct record *rec, bool at_exit) ...@@ -922,6 +926,21 @@ record__switch_output(struct record *rec, bool at_exit)
fprintf(stderr, "[ perf record: Dump %s.%s ]\n", fprintf(stderr, "[ perf record: Dump %s.%s ]\n",
data->path, timestamp); data->path, timestamp);
if (rec->switch_output.num_files) {
int n = rec->switch_output.cur_file + 1;
if (n >= rec->switch_output.num_files)
n = 0;
rec->switch_output.cur_file = n;
if (rec->switch_output.filenames[n]) {
remove(rec->switch_output.filenames[n]);
free(rec->switch_output.filenames[n]);
}
rec->switch_output.filenames[n] = new_filename;
} else {
free(new_filename);
}
/* Output tracking events */ /* Output tracking events */
if (!at_exit) { if (!at_exit) {
record__synthesize(rec, false); record__synthesize(rec, false);
...@@ -1095,7 +1114,7 @@ static int record__synthesize(struct record *rec, bool tail) ...@@ -1095,7 +1114,7 @@ static int record__synthesize(struct record *rec, bool tail)
return err; return err;
} }
err = perf_event__synthesize_bpf_events(tool, process_synthesized_event, err = perf_event__synthesize_bpf_events(session, process_synthesized_event,
machine, opts); machine, opts);
if (err < 0) if (err < 0)
pr_warning("Couldn't synthesize bpf events.\n"); pr_warning("Couldn't synthesize bpf events.\n");
...@@ -1118,6 +1137,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) ...@@ -1118,6 +1137,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
struct perf_data *data = &rec->data; struct perf_data *data = &rec->data;
struct perf_session *session; struct perf_session *session;
bool disabled = false, draining = false; bool disabled = false, draining = false;
struct perf_evlist *sb_evlist = NULL;
int fd; int fd;
atexit(record__sig_exit); atexit(record__sig_exit);
...@@ -1218,6 +1238,14 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) ...@@ -1218,6 +1238,14 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
goto out_child; goto out_child;
} }
if (!opts->no_bpf_event)
bpf_event__add_sb_event(&sb_evlist, &session->header.env);
if (perf_evlist__start_sb_thread(sb_evlist, &rec->opts.target)) {
pr_debug("Couldn't start the BPF side band thread:\nBPF programs starting from now on won't be annotatable\n");
opts->no_bpf_event = true;
}
err = record__synthesize(rec, false); err = record__synthesize(rec, false);
if (err < 0) if (err < 0)
goto out_child; goto out_child;
...@@ -1468,6 +1496,9 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) ...@@ -1468,6 +1496,9 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
out_delete_session: out_delete_session:
perf_session__delete(session); perf_session__delete(session);
if (!opts->no_bpf_event)
perf_evlist__stop_sb_thread(sb_evlist);
return status; return status;
} }
...@@ -1872,7 +1903,7 @@ static struct option __record_options[] = { ...@@ -1872,7 +1903,7 @@ static struct option __record_options[] = {
OPT_BOOLEAN(0, "tail-synthesize", &record.opts.tail_synthesize, OPT_BOOLEAN(0, "tail-synthesize", &record.opts.tail_synthesize,
"synthesize non-sample events at the end of output"), "synthesize non-sample events at the end of output"),
OPT_BOOLEAN(0, "overwrite", &record.opts.overwrite, "use overwrite mode"), OPT_BOOLEAN(0, "overwrite", &record.opts.overwrite, "use overwrite mode"),
OPT_BOOLEAN(0, "bpf-event", &record.opts.bpf_event, "record bpf events"), OPT_BOOLEAN(0, "no-bpf-event", &record.opts.no_bpf_event, "record bpf events"),
OPT_BOOLEAN(0, "strict-freq", &record.opts.strict_freq, OPT_BOOLEAN(0, "strict-freq", &record.opts.strict_freq,
"Fail if the specified frequency can't be used"), "Fail if the specified frequency can't be used"),
OPT_CALLBACK('F', "freq", &record.opts, "freq or 'max'", OPT_CALLBACK('F', "freq", &record.opts, "freq or 'max'",
...@@ -1970,9 +2001,11 @@ static struct option __record_options[] = { ...@@ -1970,9 +2001,11 @@ static struct option __record_options[] = {
OPT_BOOLEAN(0, "timestamp-boundary", &record.timestamp_boundary, OPT_BOOLEAN(0, "timestamp-boundary", &record.timestamp_boundary,
"Record timestamp boundary (time of first/last samples)"), "Record timestamp boundary (time of first/last samples)"),
OPT_STRING_OPTARG_SET(0, "switch-output", &record.switch_output.str, OPT_STRING_OPTARG_SET(0, "switch-output", &record.switch_output.str,
&record.switch_output.set, "signal,size,time", &record.switch_output.set, "signal or size[BKMG] or time[smhd]",
"Switch output when receive SIGUSR2 or cross size,time threshold", "Switch output when receiving SIGUSR2 (signal) or cross a size or time threshold",
"signal"), "signal"),
OPT_INTEGER(0, "switch-max-files", &record.switch_output.num_files,
"Limit number of switch output generated files"),
OPT_BOOLEAN(0, "dry-run", &dry_run, OPT_BOOLEAN(0, "dry-run", &dry_run,
"Parse options then exit"), "Parse options then exit"),
#ifdef HAVE_AIO_SUPPORT #ifdef HAVE_AIO_SUPPORT
...@@ -2059,6 +2092,13 @@ int cmd_record(int argc, const char **argv) ...@@ -2059,6 +2092,13 @@ int cmd_record(int argc, const char **argv)
alarm(rec->switch_output.time); alarm(rec->switch_output.time);
} }
if (rec->switch_output.num_files) {
rec->switch_output.filenames = calloc(sizeof(char *),
rec->switch_output.num_files);
if (!rec->switch_output.filenames)
return -EINVAL;
}
/* /*
* Allow aliases to facilitate the lookup of symbols for address * Allow aliases to facilitate the lookup of symbols for address
* filters. Refer to auxtrace_parse_filters(). * filters. Refer to auxtrace_parse_filters().
......
...@@ -1083,10 +1083,9 @@ int cmd_report(int argc, const char **argv) ...@@ -1083,10 +1083,9 @@ int cmd_report(int argc, const char **argv)
OPT_BOOLEAN(0, "header-only", &report.header_only, OPT_BOOLEAN(0, "header-only", &report.header_only,
"Show only data header."), "Show only data header."),
OPT_STRING('s', "sort", &sort_order, "key[,key2...]", OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
"sort by key(s): pid, comm, dso, symbol, parent, cpu, srcline, ..." sort_help("sort by key(s):")),
" Please refer the man page for the complete list."),
OPT_STRING('F', "fields", &field_order, "key[,keys...]", OPT_STRING('F', "fields", &field_order, "key[,keys...]",
"output field(s): overhead, period, sample plus all of sort keys"), sort_help("output field(s): overhead period sample ")),
OPT_BOOLEAN(0, "show-cpu-utilization", &symbol_conf.show_cpu_utilization, OPT_BOOLEAN(0, "show-cpu-utilization", &symbol_conf.show_cpu_utilization,
"Show sample percentage for different cpu modes"), "Show sample percentage for different cpu modes"),
OPT_BOOLEAN_FLAG(0, "showcpuutilization", &symbol_conf.show_cpu_utilization, OPT_BOOLEAN_FLAG(0, "showcpuutilization", &symbol_conf.show_cpu_utilization,
......
...@@ -53,6 +53,8 @@ ...@@ -53,6 +53,8 @@
static char const *script_name; static char const *script_name;
static char const *generate_script_lang; static char const *generate_script_lang;
static bool reltime;
static u64 initial_time;
static bool debug_mode; static bool debug_mode;
static u64 last_timestamp; static u64 last_timestamp;
static u64 nr_unordered; static u64 nr_unordered;
...@@ -686,7 +688,13 @@ static int perf_sample__fprintf_start(struct perf_sample *sample, ...@@ -686,7 +688,13 @@ static int perf_sample__fprintf_start(struct perf_sample *sample,
} }
if (PRINT_FIELD(TIME)) { if (PRINT_FIELD(TIME)) {
nsecs = sample->time; u64 t = sample->time;
if (reltime) {
if (!initial_time)
initial_time = sample->time;
t = sample->time - initial_time;
}
nsecs = t;
secs = nsecs / NSEC_PER_SEC; secs = nsecs / NSEC_PER_SEC;
nsecs -= secs * NSEC_PER_SEC; nsecs -= secs * NSEC_PER_SEC;
...@@ -694,7 +702,7 @@ static int perf_sample__fprintf_start(struct perf_sample *sample, ...@@ -694,7 +702,7 @@ static int perf_sample__fprintf_start(struct perf_sample *sample,
printed += fprintf(fp, "%5lu.%09llu: ", secs, nsecs); printed += fprintf(fp, "%5lu.%09llu: ", secs, nsecs);
else { else {
char sample_time[32]; char sample_time[32];
timestamp__scnprintf_usec(sample->time, sample_time, sizeof(sample_time)); timestamp__scnprintf_usec(t, sample_time, sizeof(sample_time));
printed += fprintf(fp, "%12s: ", sample_time); printed += fprintf(fp, "%12s: ", sample_time);
} }
} }
...@@ -3413,6 +3421,7 @@ int cmd_script(int argc, const char **argv) ...@@ -3413,6 +3421,7 @@ int cmd_script(int argc, const char **argv)
"Set the maximum stack depth when parsing the callchain, " "Set the maximum stack depth when parsing the callchain, "
"anything beyond the specified depth will be ignored. " "anything beyond the specified depth will be ignored. "
"Default: kernel.perf_event_max_stack or " __stringify(PERF_MAX_STACK_DEPTH)), "Default: kernel.perf_event_max_stack or " __stringify(PERF_MAX_STACK_DEPTH)),
OPT_BOOLEAN(0, "reltime", &reltime, "Show time stamps relative to start"),
OPT_BOOLEAN('I', "show-info", &show_full_info, OPT_BOOLEAN('I', "show-info", &show_full_info,
"display extended information from perf.data file"), "display extended information from perf.data file"),
OPT_BOOLEAN('\0', "show-kernel-path", &symbol_conf.show_kernel_path, OPT_BOOLEAN('\0', "show-kernel-path", &symbol_conf.show_kernel_path,
...@@ -3487,6 +3496,11 @@ int cmd_script(int argc, const char **argv) ...@@ -3487,6 +3496,11 @@ int cmd_script(int argc, const char **argv)
} }
} }
if (script.time_str && reltime) {
fprintf(stderr, "Don't combine --reltime with --time\n");
return -1;
}
if (itrace_synth_opts.callchain && if (itrace_synth_opts.callchain &&
itrace_synth_opts.callchain_sz > scripting_max_stack) itrace_synth_opts.callchain_sz > scripting_max_stack)
scripting_max_stack = itrace_synth_opts.callchain_sz; scripting_max_stack = itrace_synth_opts.callchain_sz;
......
...@@ -718,7 +718,8 @@ static struct option stat_options[] = { ...@@ -718,7 +718,8 @@ static struct option stat_options[] = {
"system-wide collection from all CPUs"), "system-wide collection from all CPUs"),
OPT_BOOLEAN('g', "group", &group, OPT_BOOLEAN('g', "group", &group,
"put the counters into a counter group"), "put the counters into a counter group"),
OPT_BOOLEAN('c', "scale", &stat_config.scale, "scale/normalize counters"), OPT_BOOLEAN(0, "scale", &stat_config.scale,
"Use --no-scale to disable counter scaling for multiplexing"),
OPT_INCR('v', "verbose", &verbose, OPT_INCR('v', "verbose", &verbose,
"be more verbose (show counter open errors, etc)"), "be more verbose (show counter open errors, etc)"),
OPT_INTEGER('r', "repeat", &stat_config.run_count, OPT_INTEGER('r', "repeat", &stat_config.run_count,
......
...@@ -1189,30 +1189,26 @@ static int __cmd_top(struct perf_top *top) ...@@ -1189,30 +1189,26 @@ static int __cmd_top(struct perf_top *top)
pthread_t thread, thread_process; pthread_t thread, thread_process;
int ret; int ret;
top->session = perf_session__new(NULL, false, NULL);
if (top->session == NULL)
return -1;
if (!top->annotation_opts.objdump_path) { if (!top->annotation_opts.objdump_path) {
ret = perf_env__lookup_objdump(&top->session->header.env, ret = perf_env__lookup_objdump(&top->session->header.env,
&top->annotation_opts.objdump_path); &top->annotation_opts.objdump_path);
if (ret) if (ret)
goto out_delete; return ret;
} }
ret = callchain_param__setup_sample_type(&callchain_param); ret = callchain_param__setup_sample_type(&callchain_param);
if (ret) if (ret)
goto out_delete; return ret;
if (perf_session__register_idle_thread(top->session) < 0) if (perf_session__register_idle_thread(top->session) < 0)
goto out_delete; return ret;
if (top->nr_threads_synthesize > 1) if (top->nr_threads_synthesize > 1)
perf_set_multithreaded(); perf_set_multithreaded();
init_process_thread(top); init_process_thread(top);
ret = perf_event__synthesize_bpf_events(&top->tool, perf_event__process, ret = perf_event__synthesize_bpf_events(top->session, perf_event__process,
&top->session->machines.host, &top->session->machines.host,
&top->record_opts); &top->record_opts);
if (ret < 0) if (ret < 0)
...@@ -1227,13 +1223,18 @@ static int __cmd_top(struct perf_top *top) ...@@ -1227,13 +1223,18 @@ static int __cmd_top(struct perf_top *top)
if (perf_hpp_list.socket) { if (perf_hpp_list.socket) {
ret = perf_env__read_cpu_topology_map(&perf_env); ret = perf_env__read_cpu_topology_map(&perf_env);
if (ret < 0) if (ret < 0) {
goto out_err_cpu_topo; char errbuf[BUFSIZ];
const char *err = str_error_r(-ret, errbuf, sizeof(errbuf));
ui__error("Could not read the CPU topology map: %s\n", err);
return ret;
}
} }
ret = perf_top__start_counters(top); ret = perf_top__start_counters(top);
if (ret) if (ret)
goto out_delete; return ret;
top->session->evlist = top->evlist; top->session->evlist = top->evlist;
perf_session__set_id_hdr_size(top->session); perf_session__set_id_hdr_size(top->session);
...@@ -1252,7 +1253,7 @@ static int __cmd_top(struct perf_top *top) ...@@ -1252,7 +1253,7 @@ static int __cmd_top(struct perf_top *top)
ret = -1; ret = -1;
if (pthread_create(&thread_process, NULL, process_thread, top)) { if (pthread_create(&thread_process, NULL, process_thread, top)) {
ui__error("Could not create process thread.\n"); ui__error("Could not create process thread.\n");
goto out_delete; return ret;
} }
if (pthread_create(&thread, NULL, (use_browser > 0 ? display_thread_tui : if (pthread_create(&thread, NULL, (use_browser > 0 ? display_thread_tui :
...@@ -1296,19 +1297,7 @@ static int __cmd_top(struct perf_top *top) ...@@ -1296,19 +1297,7 @@ static int __cmd_top(struct perf_top *top)
out_join_thread: out_join_thread:
pthread_cond_signal(&top->qe.cond); pthread_cond_signal(&top->qe.cond);
pthread_join(thread_process, NULL); pthread_join(thread_process, NULL);
out_delete:
perf_session__delete(top->session);
top->session = NULL;
return ret; return ret;
out_err_cpu_topo: {
char errbuf[BUFSIZ];
const char *err = str_error_r(-ret, errbuf, sizeof(errbuf));
ui__error("Could not read the CPU topology map: %s\n", err);
goto out_delete;
}
} }
static int static int
...@@ -1480,6 +1469,7 @@ int cmd_top(int argc, const char **argv) ...@@ -1480,6 +1469,7 @@ int cmd_top(int argc, const char **argv)
"Display raw encoding of assembly instructions (default)"), "Display raw encoding of assembly instructions (default)"),
OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel, OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel,
"Enable kernel symbol demangling"), "Enable kernel symbol demangling"),
OPT_BOOLEAN(0, "no-bpf-event", &top.record_opts.no_bpf_event, "do not record bpf events"),
OPT_STRING(0, "objdump", &top.annotation_opts.objdump_path, "path", OPT_STRING(0, "objdump", &top.annotation_opts.objdump_path, "path",
"objdump binary to use for disassembly and annotations"), "objdump binary to use for disassembly and annotations"),
OPT_STRING('M', "disassembler-style", &top.annotation_opts.disassembler_style, "disassembler style", OPT_STRING('M', "disassembler-style", &top.annotation_opts.disassembler_style, "disassembler style",
...@@ -1511,6 +1501,7 @@ int cmd_top(int argc, const char **argv) ...@@ -1511,6 +1501,7 @@ int cmd_top(int argc, const char **argv)
"number of thread to run event synthesize"), "number of thread to run event synthesize"),
OPT_END() OPT_END()
}; };
struct perf_evlist *sb_evlist = NULL;
const char * const top_usage[] = { const char * const top_usage[] = {
"perf top [<options>]", "perf top [<options>]",
NULL NULL
...@@ -1628,8 +1619,9 @@ int cmd_top(int argc, const char **argv) ...@@ -1628,8 +1619,9 @@ int cmd_top(int argc, const char **argv)
annotation_config__init(); annotation_config__init();
symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL); symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL);
if (symbol__init(NULL) < 0) status = symbol__init(NULL);
return -1; if (status < 0)
goto out_delete_evlist;
sort__setup_elide(stdout); sort__setup_elide(stdout);
...@@ -1639,10 +1631,28 @@ int cmd_top(int argc, const char **argv) ...@@ -1639,10 +1631,28 @@ int cmd_top(int argc, const char **argv)
signal(SIGWINCH, winch_sig); signal(SIGWINCH, winch_sig);
} }
top.session = perf_session__new(NULL, false, NULL);
if (top.session == NULL) {
status = -1;
goto out_delete_evlist;
}
if (!top.record_opts.no_bpf_event)
bpf_event__add_sb_event(&sb_evlist, &perf_env);
if (perf_evlist__start_sb_thread(sb_evlist, target)) {
pr_debug("Couldn't start the BPF side band thread:\nBPF programs starting from now on won't be annotatable\n");
opts->no_bpf_event = true;
}
status = __cmd_top(&top); status = __cmd_top(&top);
if (!opts->no_bpf_event)
perf_evlist__stop_sb_thread(sb_evlist);
out_delete_evlist: out_delete_evlist:
perf_evlist__delete(top.evlist); perf_evlist__delete(top.evlist);
perf_session__delete(top.session);
return status; return status;
} }
...@@ -298,6 +298,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) ...@@ -298,6 +298,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
use_pager = 1; use_pager = 1;
commit_pager_choice(); commit_pager_choice();
perf_env__init(&perf_env);
perf_env__set_cmdline(&perf_env, argc, argv); perf_env__set_cmdline(&perf_env, argc, argv);
status = p->fn(argc, argv); status = p->fn(argc, argv);
perf_config__exit(); perf_config__exit();
......
...@@ -66,7 +66,7 @@ struct record_opts { ...@@ -66,7 +66,7 @@ struct record_opts {
bool ignore_missing_thread; bool ignore_missing_thread;
bool strict_freq; bool strict_freq;
bool sample_id; bool sample_id;
bool bpf_event; bool no_bpf_event;
unsigned int freq; unsigned int freq;
unsigned int mmap_pages; unsigned int mmap_pages;
unsigned int auxtrace_mmap_pages; unsigned int auxtrace_mmap_pages;
......
[config] [config]
command = record command = record
args = -C 0 kill >/dev/null 2>&1 args = --no-bpf-event -C 0 kill >/dev/null 2>&1
ret = 1 ret = 1
[event:base-record] [event:base-record]
......
[config] [config]
command = record command = record
args = kill >/dev/null 2>&1 args = --no-bpf-event kill >/dev/null 2>&1
ret = 1 ret = 1
[event:base-record] [event:base-record]
[config] [config]
command = record command = record
args = -b kill >/dev/null 2>&1 args = --no-bpf-event -b kill >/dev/null 2>&1
ret = 1 ret = 1
[event:base-record] [event:base-record]
......
[config] [config]
command = record command = record
args = -j any kill >/dev/null 2>&1 args = --no-bpf-event -j any kill >/dev/null 2>&1
ret = 1 ret = 1
[event:base-record] [event:base-record]
......
[config] [config]
command = record command = record
args = -j any_call kill >/dev/null 2>&1 args = --no-bpf-event -j any_call kill >/dev/null 2>&1
ret = 1 ret = 1
[event:base-record] [event:base-record]
......
[config] [config]
command = record command = record
args = -j any_ret kill >/dev/null 2>&1 args = --no-bpf-event -j any_ret kill >/dev/null 2>&1
ret = 1 ret = 1
[event:base-record] [event:base-record]
......
[config] [config]
command = record command = record
args = -j hv kill >/dev/null 2>&1 args = --no-bpf-event -j hv kill >/dev/null 2>&1
ret = 1 ret = 1
[event:base-record] [event:base-record]
......
[config] [config]
command = record command = record
args = -j ind_call kill >/dev/null 2>&1 args = --no-bpf-event -j ind_call kill >/dev/null 2>&1
ret = 1 ret = 1
[event:base-record] [event:base-record]
......
[config] [config]
command = record command = record
args = -j k kill >/dev/null 2>&1 args = --no-bpf-event -j k kill >/dev/null 2>&1
ret = 1 ret = 1
[event:base-record] [event:base-record]
......
[config] [config]
command = record command = record
args = -j u kill >/dev/null 2>&1 args = --no-bpf-event -j u kill >/dev/null 2>&1
ret = 1 ret = 1
[event:base-record] [event:base-record]
......
[config] [config]
command = record command = record
args = -c 123 kill >/dev/null 2>&1 args = --no-bpf-event -c 123 kill >/dev/null 2>&1
ret = 1 ret = 1
[event:base-record] [event:base-record]
......
[config] [config]
command = record command = record
args = -d kill >/dev/null 2>&1 args = --no-bpf-event -d kill >/dev/null 2>&1
ret = 1 ret = 1
[event:base-record] [event:base-record]
......
[config] [config]
command = record command = record
args = -F 100 kill >/dev/null 2>&1 args = --no-bpf-event -F 100 kill >/dev/null 2>&1
ret = 1 ret = 1
[event:base-record] [event:base-record]
......
[config] [config]
command = record command = record
args = -g kill >/dev/null 2>&1 args = --no-bpf-event -g kill >/dev/null 2>&1
ret = 1 ret = 1
[event:base-record] [event:base-record]
......
[config] [config]
command = record command = record
args = --call-graph dwarf -- kill >/dev/null 2>&1 args = --no-bpf-event --call-graph dwarf -- kill >/dev/null 2>&1
ret = 1 ret = 1
[event:base-record] [event:base-record]
......
[config] [config]
command = record command = record
args = --call-graph fp kill >/dev/null 2>&1 args = --no-bpf-event --call-graph fp kill >/dev/null 2>&1
ret = 1 ret = 1
[event:base-record] [event:base-record]
......
[config] [config]
command = record command = record
args = --group -e cycles,instructions kill >/dev/null 2>&1 args = --no-bpf-event --group -e cycles,instructions kill >/dev/null 2>&1
ret = 1 ret = 1
[event-1:base-record] [event-1:base-record]
......
[config] [config]
command = record command = record
args = -e '{cycles,cache-misses}:S' kill >/dev/null 2>&1 args = --no-bpf-event -e '{cycles,cache-misses}:S' kill >/dev/null 2>&1
ret = 1 ret = 1
[event-1:base-record] [event-1:base-record]
......
[config] [config]
command = record command = record
args = -e '{cycles,instructions}' kill >/dev/null 2>&1 args = --no-bpf-event -e '{cycles,instructions}' kill >/dev/null 2>&1
ret = 1 ret = 1
[event-1:base-record] [event-1:base-record]
......
[config] [config]
command = record command = record
args = --no-buffering kill >/dev/null 2>&1 args = --no-bpf-event --no-buffering kill >/dev/null 2>&1
ret = 1 ret = 1
[event:base-record] [event:base-record]
......
[config] [config]
command = record command = record
args = -i kill >/dev/null 2>&1 args = --no-bpf-event -i kill >/dev/null 2>&1
ret = 1 ret = 1
[event:base-record] [event:base-record]
......
[config] [config]
command = record command = record
args = -n kill >/dev/null 2>&1 args = --no-bpf-event -n kill >/dev/null 2>&1
ret = 1 ret = 1
[event:base-record] [event:base-record]
......
[config] [config]
command = record command = record
args = -c 100 -P kill >/dev/null 2>&1 args = --no-bpf-event -c 100 -P kill >/dev/null 2>&1
ret = 1 ret = 1
[event:base-record] [event:base-record]
......
[config] [config]
command = record command = record
args = -R kill >/dev/null 2>&1 args = --no-bpf-event -R kill >/dev/null 2>&1
ret = 1 ret = 1
[event:base-record] [event:base-record]
......
...@@ -18,7 +18,7 @@ static void testcase(void) ...@@ -18,7 +18,7 @@ static void testcase(void)
int i; int i;
for (i = 0; i < NR_ITERS; i++) { for (i = 0; i < NR_ITERS; i++) {
char proc_name[10]; char proc_name[15];
snprintf(proc_name, sizeof(proc_name), "p:%d\n", i); snprintf(proc_name, sizeof(proc_name), "p:%d\n", i);
prctl(PR_SET_NAME, proc_name); prctl(PR_SET_NAME, proc_name);
......
...@@ -85,5 +85,6 @@ int test__perf_evsel__tp_sched_test(struct test *test __maybe_unused, int subtes ...@@ -85,5 +85,6 @@ int test__perf_evsel__tp_sched_test(struct test *test __maybe_unused, int subtes
if (perf_evsel__test_field(evsel, "target_cpu", 4, true)) if (perf_evsel__test_field(evsel, "target_cpu", 4, true))
ret = -1; ret = -1;
perf_evsel__delete(evsel);
return ret; return ret;
} }
...@@ -19,7 +19,7 @@ int test__expr(struct test *t __maybe_unused, int subtest __maybe_unused) ...@@ -19,7 +19,7 @@ int test__expr(struct test *t __maybe_unused, int subtest __maybe_unused)
const char *p; const char *p;
const char **other; const char **other;
double val; double val;
int ret; int i, ret;
struct parse_ctx ctx; struct parse_ctx ctx;
int num_other; int num_other;
...@@ -56,6 +56,9 @@ int test__expr(struct test *t __maybe_unused, int subtest __maybe_unused) ...@@ -56,6 +56,9 @@ int test__expr(struct test *t __maybe_unused, int subtest __maybe_unused)
TEST_ASSERT_VAL("find other", !strcmp(other[1], "BAZ")); TEST_ASSERT_VAL("find other", !strcmp(other[1], "BAZ"));
TEST_ASSERT_VAL("find other", !strcmp(other[2], "BOZO")); TEST_ASSERT_VAL("find other", !strcmp(other[2], "BOZO"));
TEST_ASSERT_VAL("find other", other[3] == NULL); TEST_ASSERT_VAL("find other", other[3] == NULL);
for (i = 0; i < num_other; i++)
free((void *)other[i]);
free((void *)other); free((void *)other);
return 0; return 0;
......
...@@ -45,7 +45,7 @@ int test__openat_syscall_event_on_all_cpus(struct test *test __maybe_unused, int ...@@ -45,7 +45,7 @@ int test__openat_syscall_event_on_all_cpus(struct test *test __maybe_unused, int
if (IS_ERR(evsel)) { if (IS_ERR(evsel)) {
tracing_path__strerror_open_tp(errno, errbuf, sizeof(errbuf), "syscalls", "sys_enter_openat"); tracing_path__strerror_open_tp(errno, errbuf, sizeof(errbuf), "syscalls", "sys_enter_openat");
pr_debug("%s\n", errbuf); pr_debug("%s\n", errbuf);
goto out_thread_map_delete; goto out_cpu_map_delete;
} }
if (perf_evsel__open(evsel, cpus, threads) < 0) { if (perf_evsel__open(evsel, cpus, threads) < 0) {
...@@ -119,6 +119,8 @@ int test__openat_syscall_event_on_all_cpus(struct test *test __maybe_unused, int ...@@ -119,6 +119,8 @@ int test__openat_syscall_event_on_all_cpus(struct test *test __maybe_unused, int
perf_evsel__close_fd(evsel); perf_evsel__close_fd(evsel);
out_evsel_delete: out_evsel_delete:
perf_evsel__delete(evsel); perf_evsel__delete(evsel);
out_cpu_map_delete:
cpu_map__put(cpus);
out_thread_map_delete: out_thread_map_delete:
thread_map__put(threads); thread_map__put(threads);
return err; return err;
......
...@@ -10,6 +10,10 @@ ...@@ -10,6 +10,10 @@
#include <errno.h> #include <errno.h>
#include <inttypes.h> #include <inttypes.h>
#include <libgen.h> #include <libgen.h>
#include <bpf/bpf.h>
#include <bpf/btf.h>
#include <bpf/libbpf.h>
#include <linux/btf.h>
#include "util.h" #include "util.h"
#include "ui/ui.h" #include "ui/ui.h"
#include "sort.h" #include "sort.h"
...@@ -24,6 +28,7 @@ ...@@ -24,6 +28,7 @@
#include "annotate.h" #include "annotate.h"
#include "evsel.h" #include "evsel.h"
#include "evlist.h" #include "evlist.h"
#include "bpf-event.h"
#include "block-range.h" #include "block-range.h"
#include "string2.h" #include "string2.h"
#include "arch/common.h" #include "arch/common.h"
...@@ -31,6 +36,7 @@ ...@@ -31,6 +36,7 @@
#include <pthread.h> #include <pthread.h>
#include <linux/bitops.h> #include <linux/bitops.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <bpf/libbpf.h>
/* FIXME: For the HE_COLORSET */ /* FIXME: For the HE_COLORSET */
#include "ui/browser.h" #include "ui/browser.h"
...@@ -1615,6 +1621,9 @@ int symbol__strerror_disassemble(struct symbol *sym __maybe_unused, struct map * ...@@ -1615,6 +1621,9 @@ int symbol__strerror_disassemble(struct symbol *sym __maybe_unused, struct map *
" --vmlinux vmlinux\n", build_id_msg ?: ""); " --vmlinux vmlinux\n", build_id_msg ?: "");
} }
break; break;
case SYMBOL_ANNOTATE_ERRNO__NO_LIBOPCODES_FOR_BPF:
scnprintf(buf, buflen, "Please link with binutils's libopcode to enable BPF annotation");
break;
default: default:
scnprintf(buf, buflen, "Internal error: Invalid %d error code\n", errnum); scnprintf(buf, buflen, "Internal error: Invalid %d error code\n", errnum);
break; break;
...@@ -1674,6 +1683,156 @@ static int dso__disassemble_filename(struct dso *dso, char *filename, size_t fil ...@@ -1674,6 +1683,156 @@ static int dso__disassemble_filename(struct dso *dso, char *filename, size_t fil
return 0; return 0;
} }
#if defined(HAVE_LIBBFD_SUPPORT) && defined(HAVE_LIBBPF_SUPPORT)
#define PACKAGE "perf"
#include <bfd.h>
#include <dis-asm.h>
static int symbol__disassemble_bpf(struct symbol *sym,
struct annotate_args *args)
{
struct annotation *notes = symbol__annotation(sym);
struct annotation_options *opts = args->options;
struct bpf_prog_info_linear *info_linear;
struct bpf_prog_linfo *prog_linfo = NULL;
struct bpf_prog_info_node *info_node;
int len = sym->end - sym->start;
disassembler_ftype disassemble;
struct map *map = args->ms.map;
struct disassemble_info info;
struct dso *dso = map->dso;
int pc = 0, count, sub_id;
struct btf *btf = NULL;
char tpath[PATH_MAX];
size_t buf_size;
int nr_skip = 0;
int ret = -1;
char *buf;
bfd *bfdf;
FILE *s;
if (dso->binary_type != DSO_BINARY_TYPE__BPF_PROG_INFO)
return -1;
pr_debug("%s: handling sym %s addr %lx len %lx\n", __func__,
sym->name, sym->start, sym->end - sym->start);
memset(tpath, 0, sizeof(tpath));
perf_exe(tpath, sizeof(tpath));
bfdf = bfd_openr(tpath, NULL);
assert(bfdf);
assert(bfd_check_format(bfdf, bfd_object));
s = open_memstream(&buf, &buf_size);
if (!s)
goto out;
init_disassemble_info(&info, s,
(fprintf_ftype) fprintf);
info.arch = bfd_get_arch(bfdf);
info.mach = bfd_get_mach(bfdf);
info_node = perf_env__find_bpf_prog_info(dso->bpf_prog.env,
dso->bpf_prog.id);
if (!info_node)
goto out;
info_linear = info_node->info_linear;
sub_id = dso->bpf_prog.sub_id;
info.buffer = (void *)(info_linear->info.jited_prog_insns);
info.buffer_length = info_linear->info.jited_prog_len;
if (info_linear->info.nr_line_info)
prog_linfo = bpf_prog_linfo__new(&info_linear->info);
if (info_linear->info.btf_id) {
struct btf_node *node;
node = perf_env__find_btf(dso->bpf_prog.env,
info_linear->info.btf_id);
if (node)
btf = btf__new((__u8 *)(node->data),
node->data_size);
}
disassemble_init_for_target(&info);
#ifdef DISASM_FOUR_ARGS_SIGNATURE
disassemble = disassembler(info.arch,
bfd_big_endian(bfdf),
info.mach,
bfdf);
#else
disassemble = disassembler(bfdf);
#endif
assert(disassemble);
fflush(s);
do {
const struct bpf_line_info *linfo = NULL;
struct disasm_line *dl;
size_t prev_buf_size;
const char *srcline;
u64 addr;
addr = pc + ((u64 *)(info_linear->info.jited_ksyms))[sub_id];
count = disassemble(pc, &info);
if (prog_linfo)
linfo = bpf_prog_linfo__lfind_addr_func(prog_linfo,
addr, sub_id,
nr_skip);
if (linfo && btf) {
srcline = btf__name_by_offset(btf, linfo->line_off);
nr_skip++;
} else
srcline = NULL;
fprintf(s, "\n");
prev_buf_size = buf_size;
fflush(s);
if (!opts->hide_src_code && srcline) {
args->offset = -1;
args->line = strdup(srcline);
args->line_nr = 0;
args->ms.sym = sym;
dl = disasm_line__new(args);
if (dl) {
annotation_line__add(&dl->al,
&notes->src->source);
}
}
args->offset = pc;
args->line = buf + prev_buf_size;
args->line_nr = 0;
args->ms.sym = sym;
dl = disasm_line__new(args);
if (dl)
annotation_line__add(&dl->al, &notes->src->source);
pc += count;
} while (count > 0 && pc < len);
ret = 0;
out:
free(prog_linfo);
free(btf);
fclose(s);
bfd_close(bfdf);
return ret;
}
#else // defined(HAVE_LIBBFD_SUPPORT) && defined(HAVE_LIBBPF_SUPPORT)
static int symbol__disassemble_bpf(struct symbol *sym __maybe_unused,
struct annotate_args *args __maybe_unused)
{
return SYMBOL_ANNOTATE_ERRNO__NO_LIBOPCODES_FOR_BPF;
}
#endif // defined(HAVE_LIBBFD_SUPPORT) && defined(HAVE_LIBBPF_SUPPORT)
static int symbol__disassemble(struct symbol *sym, struct annotate_args *args) static int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
{ {
struct annotation_options *opts = args->options; struct annotation_options *opts = args->options;
...@@ -1701,7 +1860,9 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args) ...@@ -1701,7 +1860,9 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
pr_debug("annotating [%p] %30s : [%p] %30s\n", pr_debug("annotating [%p] %30s : [%p] %30s\n",
dso, dso->long_name, sym, sym->name); dso, dso->long_name, sym, sym->name);
if (dso__is_kcore(dso)) { if (dso->binary_type == DSO_BINARY_TYPE__BPF_PROG_INFO) {
return symbol__disassemble_bpf(sym, args);
} else if (dso__is_kcore(dso)) {
kce.kcore_filename = symfs_filename; kce.kcore_filename = symfs_filename;
kce.addr = map__rip_2objdump(map, sym->start); kce.addr = map__rip_2objdump(map, sym->start);
kce.offs = sym->start; kce.offs = sym->start;
......
...@@ -369,6 +369,7 @@ enum symbol_disassemble_errno { ...@@ -369,6 +369,7 @@ enum symbol_disassemble_errno {
__SYMBOL_ANNOTATE_ERRNO__START = -10000, __SYMBOL_ANNOTATE_ERRNO__START = -10000,
SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX = __SYMBOL_ANNOTATE_ERRNO__START, SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX = __SYMBOL_ANNOTATE_ERRNO__START,
SYMBOL_ANNOTATE_ERRNO__NO_LIBOPCODES_FOR_BPF,
__SYMBOL_ANNOTATE_ERRNO__END, __SYMBOL_ANNOTATE_ERRNO__END,
}; };
......
This diff is collapsed.
...@@ -3,22 +3,45 @@ ...@@ -3,22 +3,45 @@
#define __PERF_BPF_EVENT_H #define __PERF_BPF_EVENT_H
#include <linux/compiler.h> #include <linux/compiler.h>
#include <linux/rbtree.h>
#include <pthread.h>
#include <api/fd/array.h>
#include "event.h" #include "event.h"
#include <stdio.h>
struct machine; struct machine;
union perf_event; union perf_event;
struct perf_env;
struct perf_sample; struct perf_sample;
struct perf_tool;
struct record_opts; struct record_opts;
struct evlist;
struct target;
struct bpf_prog_info_node {
struct bpf_prog_info_linear *info_linear;
struct rb_node rb_node;
};
struct btf_node {
struct rb_node rb_node;
u32 id;
u32 data_size;
char data[];
};
#ifdef HAVE_LIBBPF_SUPPORT #ifdef HAVE_LIBBPF_SUPPORT
int machine__process_bpf_event(struct machine *machine, union perf_event *event, int machine__process_bpf_event(struct machine *machine, union perf_event *event,
struct perf_sample *sample); struct perf_sample *sample);
int perf_event__synthesize_bpf_events(struct perf_tool *tool, int perf_event__synthesize_bpf_events(struct perf_session *session,
perf_event__handler_t process, perf_event__handler_t process,
struct machine *machine, struct machine *machine,
struct record_opts *opts); struct record_opts *opts);
int bpf_event__add_sb_event(struct perf_evlist **evlist,
struct perf_env *env);
void bpf_event__print_bpf_prog_info(struct bpf_prog_info *info,
struct perf_env *env,
FILE *fp);
#else #else
static inline int machine__process_bpf_event(struct machine *machine __maybe_unused, static inline int machine__process_bpf_event(struct machine *machine __maybe_unused,
union perf_event *event __maybe_unused, union perf_event *event __maybe_unused,
...@@ -27,12 +50,25 @@ static inline int machine__process_bpf_event(struct machine *machine __maybe_unu ...@@ -27,12 +50,25 @@ static inline int machine__process_bpf_event(struct machine *machine __maybe_unu
return 0; return 0;
} }
static inline int perf_event__synthesize_bpf_events(struct perf_tool *tool __maybe_unused, static inline int perf_event__synthesize_bpf_events(struct perf_session *session __maybe_unused,
perf_event__handler_t process __maybe_unused, perf_event__handler_t process __maybe_unused,
struct machine *machine __maybe_unused, struct machine *machine __maybe_unused,
struct record_opts *opts __maybe_unused) struct record_opts *opts __maybe_unused)
{ {
return 0; return 0;
} }
static inline int bpf_event__add_sb_event(struct perf_evlist **evlist __maybe_unused,
struct perf_env *env __maybe_unused)
{
return 0;
}
static inline void bpf_event__print_bpf_prog_info(struct bpf_prog_info *info __maybe_unused,
struct perf_env *env __maybe_unused,
FILE *fp __maybe_unused)
{
}
#endif // HAVE_LIBBPF_SUPPORT #endif // HAVE_LIBBPF_SUPPORT
#endif #endif
...@@ -185,6 +185,7 @@ char *build_id_cache__linkname(const char *sbuild_id, char *bf, size_t size) ...@@ -185,6 +185,7 @@ char *build_id_cache__linkname(const char *sbuild_id, char *bf, size_t size)
return bf; return bf;
} }
/* The caller is responsible to free the returned buffer. */
char *build_id_cache__origname(const char *sbuild_id) char *build_id_cache__origname(const char *sbuild_id)
{ {
char *linkname; char *linkname;
......
...@@ -633,11 +633,10 @@ static int collect_config(const char *var, const char *value, ...@@ -633,11 +633,10 @@ static int collect_config(const char *var, const char *value,
} }
ret = set_value(item, value); ret = set_value(item, value);
return ret;
out_free: out_free:
free(key); free(key);
return -1; return ret;
} }
int perf_config_set__collect(struct perf_config_set *set, const char *file_name, int perf_config_set__collect(struct perf_config_set *set, const char *file_name,
......
...@@ -361,9 +361,9 @@ ssize_t perf_data__write(struct perf_data *data, ...@@ -361,9 +361,9 @@ ssize_t perf_data__write(struct perf_data *data,
int perf_data__switch(struct perf_data *data, int perf_data__switch(struct perf_data *data,
const char *postfix, const char *postfix,
size_t pos, bool at_exit) size_t pos, bool at_exit,
char **new_filepath)
{ {
char *new_filepath;
int ret; int ret;
if (check_pipe(data)) if (check_pipe(data))
...@@ -371,15 +371,15 @@ int perf_data__switch(struct perf_data *data, ...@@ -371,15 +371,15 @@ int perf_data__switch(struct perf_data *data,
if (perf_data__is_read(data)) if (perf_data__is_read(data))
return -EINVAL; return -EINVAL;
if (asprintf(&new_filepath, "%s.%s", data->path, postfix) < 0) if (asprintf(new_filepath, "%s.%s", data->path, postfix) < 0)
return -ENOMEM; return -ENOMEM;
/* /*
* Only fire a warning, don't return error, continue fill * Only fire a warning, don't return error, continue fill
* original file. * original file.
*/ */
if (rename(data->path, new_filepath)) if (rename(data->path, *new_filepath))
pr_warning("Failed to rename %s to %s\n", data->path, new_filepath); pr_warning("Failed to rename %s to %s\n", data->path, *new_filepath);
if (!at_exit) { if (!at_exit) {
close(data->file.fd); close(data->file.fd);
...@@ -396,7 +396,6 @@ int perf_data__switch(struct perf_data *data, ...@@ -396,7 +396,6 @@ int perf_data__switch(struct perf_data *data,
} }
ret = data->file.fd; ret = data->file.fd;
out: out:
free(new_filepath);
return ret; return ret;
} }
......
...@@ -70,7 +70,7 @@ ssize_t perf_data_file__write(struct perf_data_file *file, ...@@ -70,7 +70,7 @@ ssize_t perf_data_file__write(struct perf_data_file *file,
*/ */
int perf_data__switch(struct perf_data *data, int perf_data__switch(struct perf_data *data,
const char *postfix, const char *postfix,
size_t pos, bool at_exit); size_t pos, bool at_exit, char **new_filepath);
int perf_data__create_dir(struct perf_data *data, int nr); int perf_data__create_dir(struct perf_data *data, int nr);
int perf_data__open_dir(struct perf_data *data); int perf_data__open_dir(struct perf_data *data);
......
...@@ -184,6 +184,7 @@ int dso__read_binary_type_filename(const struct dso *dso, ...@@ -184,6 +184,7 @@ int dso__read_binary_type_filename(const struct dso *dso,
case DSO_BINARY_TYPE__KALLSYMS: case DSO_BINARY_TYPE__KALLSYMS:
case DSO_BINARY_TYPE__GUEST_KALLSYMS: case DSO_BINARY_TYPE__GUEST_KALLSYMS:
case DSO_BINARY_TYPE__JAVA_JIT: case DSO_BINARY_TYPE__JAVA_JIT:
case DSO_BINARY_TYPE__BPF_PROG_INFO:
case DSO_BINARY_TYPE__NOT_FOUND: case DSO_BINARY_TYPE__NOT_FOUND:
ret = -1; ret = -1;
break; break;
...@@ -1141,28 +1142,34 @@ void dso__set_short_name(struct dso *dso, const char *name, bool name_allocated) ...@@ -1141,28 +1142,34 @@ void dso__set_short_name(struct dso *dso, const char *name, bool name_allocated)
static void dso__set_basename(struct dso *dso) static void dso__set_basename(struct dso *dso)
{ {
/* char *base, *lname;
* basename() may modify path buffer, so we must pass int tid;
* a copy.
*/
char *base, *lname = strdup(dso->long_name);
if (!lname) if (sscanf(dso->long_name, "/tmp/perf-%d.map", &tid) == 1) {
return; if (asprintf(&base, "[JIT] tid %d", tid) < 0)
return;
/* } else {
* basename() may return a pointer to internal /*
* storage which is reused in subsequent calls * basename() may modify path buffer, so we must pass
* so copy the result. * a copy.
*/ */
base = strdup(basename(lname)); lname = strdup(dso->long_name);
if (!lname)
return;
free(lname); /*
* basename() may return a pointer to internal
* storage which is reused in subsequent calls
* so copy the result.
*/
base = strdup(basename(lname));
if (!base) free(lname);
return;
dso__set_short_name(dso, base, true); if (!base)
return;
}
dso__set_short_name(dso, base, true);
} }
int dso__name_len(const struct dso *dso) int dso__name_len(const struct dso *dso)
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
struct machine; struct machine;
struct map; struct map;
struct perf_env;
enum dso_binary_type { enum dso_binary_type {
DSO_BINARY_TYPE__KALLSYMS = 0, DSO_BINARY_TYPE__KALLSYMS = 0,
...@@ -35,6 +36,7 @@ enum dso_binary_type { ...@@ -35,6 +36,7 @@ enum dso_binary_type {
DSO_BINARY_TYPE__KCORE, DSO_BINARY_TYPE__KCORE,
DSO_BINARY_TYPE__GUEST_KCORE, DSO_BINARY_TYPE__GUEST_KCORE,
DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO, DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO,
DSO_BINARY_TYPE__BPF_PROG_INFO,
DSO_BINARY_TYPE__NOT_FOUND, DSO_BINARY_TYPE__NOT_FOUND,
}; };
...@@ -189,6 +191,12 @@ struct dso { ...@@ -189,6 +191,12 @@ struct dso {
u64 debug_frame_offset; u64 debug_frame_offset;
u64 eh_frame_hdr_offset; u64 eh_frame_hdr_offset;
} data; } data;
/* bpf prog information */
struct {
u32 id;
u32 sub_id;
struct perf_env *env;
} bpf_prog;
union { /* Tool specific area */ union { /* Tool specific area */
void *priv; void *priv;
......
...@@ -3,15 +3,163 @@ ...@@ -3,15 +3,163 @@
#include "env.h" #include "env.h"
#include "sane_ctype.h" #include "sane_ctype.h"
#include "util.h" #include "util.h"
#include "bpf-event.h"
#include <errno.h> #include <errno.h>
#include <sys/utsname.h> #include <sys/utsname.h>
#include <bpf/libbpf.h>
struct perf_env perf_env; struct perf_env perf_env;
void perf_env__insert_bpf_prog_info(struct perf_env *env,
struct bpf_prog_info_node *info_node)
{
__u32 prog_id = info_node->info_linear->info.id;
struct bpf_prog_info_node *node;
struct rb_node *parent = NULL;
struct rb_node **p;
down_write(&env->bpf_progs.lock);
p = &env->bpf_progs.infos.rb_node;
while (*p != NULL) {
parent = *p;
node = rb_entry(parent, struct bpf_prog_info_node, rb_node);
if (prog_id < node->info_linear->info.id) {
p = &(*p)->rb_left;
} else if (prog_id > node->info_linear->info.id) {
p = &(*p)->rb_right;
} else {
pr_debug("duplicated bpf prog info %u\n", prog_id);
goto out;
}
}
rb_link_node(&info_node->rb_node, parent, p);
rb_insert_color(&info_node->rb_node, &env->bpf_progs.infos);
env->bpf_progs.infos_cnt++;
out:
up_write(&env->bpf_progs.lock);
}
struct bpf_prog_info_node *perf_env__find_bpf_prog_info(struct perf_env *env,
__u32 prog_id)
{
struct bpf_prog_info_node *node = NULL;
struct rb_node *n;
down_read(&env->bpf_progs.lock);
n = env->bpf_progs.infos.rb_node;
while (n) {
node = rb_entry(n, struct bpf_prog_info_node, rb_node);
if (prog_id < node->info_linear->info.id)
n = n->rb_left;
else if (prog_id > node->info_linear->info.id)
n = n->rb_right;
else
break;
}
up_read(&env->bpf_progs.lock);
return node;
}
void perf_env__insert_btf(struct perf_env *env, struct btf_node *btf_node)
{
struct rb_node *parent = NULL;
__u32 btf_id = btf_node->id;
struct btf_node *node;
struct rb_node **p;
down_write(&env->bpf_progs.lock);
p = &env->bpf_progs.btfs.rb_node;
while (*p != NULL) {
parent = *p;
node = rb_entry(parent, struct btf_node, rb_node);
if (btf_id < node->id) {
p = &(*p)->rb_left;
} else if (btf_id > node->id) {
p = &(*p)->rb_right;
} else {
pr_debug("duplicated btf %u\n", btf_id);
goto out;
}
}
rb_link_node(&btf_node->rb_node, parent, p);
rb_insert_color(&btf_node->rb_node, &env->bpf_progs.btfs);
env->bpf_progs.btfs_cnt++;
out:
up_write(&env->bpf_progs.lock);
}
struct btf_node *perf_env__find_btf(struct perf_env *env, __u32 btf_id)
{
struct btf_node *node = NULL;
struct rb_node *n;
down_read(&env->bpf_progs.lock);
n = env->bpf_progs.btfs.rb_node;
while (n) {
node = rb_entry(n, struct btf_node, rb_node);
if (btf_id < node->id)
n = n->rb_left;
else if (btf_id > node->id)
n = n->rb_right;
else
break;
}
up_read(&env->bpf_progs.lock);
return node;
}
/* purge data in bpf_progs.infos tree */
static void perf_env__purge_bpf(struct perf_env *env)
{
struct rb_root *root;
struct rb_node *next;
down_write(&env->bpf_progs.lock);
root = &env->bpf_progs.infos;
next = rb_first(root);
while (next) {
struct bpf_prog_info_node *node;
node = rb_entry(next, struct bpf_prog_info_node, rb_node);
next = rb_next(&node->rb_node);
rb_erase(&node->rb_node, root);
free(node);
}
env->bpf_progs.infos_cnt = 0;
root = &env->bpf_progs.btfs;
next = rb_first(root);
while (next) {
struct btf_node *node;
node = rb_entry(next, struct btf_node, rb_node);
next = rb_next(&node->rb_node);
rb_erase(&node->rb_node, root);
free(node);
}
env->bpf_progs.btfs_cnt = 0;
up_write(&env->bpf_progs.lock);
}
void perf_env__exit(struct perf_env *env) void perf_env__exit(struct perf_env *env)
{ {
int i; int i;
perf_env__purge_bpf(env);
zfree(&env->hostname); zfree(&env->hostname);
zfree(&env->os_release); zfree(&env->os_release);
zfree(&env->version); zfree(&env->version);
...@@ -38,6 +186,13 @@ void perf_env__exit(struct perf_env *env) ...@@ -38,6 +186,13 @@ void perf_env__exit(struct perf_env *env)
zfree(&env->memory_nodes); zfree(&env->memory_nodes);
} }
void perf_env__init(struct perf_env *env)
{
env->bpf_progs.infos = RB_ROOT;
env->bpf_progs.btfs = RB_ROOT;
init_rwsem(&env->bpf_progs.lock);
}
int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[]) int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[])
{ {
int i; int i;
......
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
#define __PERF_ENV_H #define __PERF_ENV_H
#include <linux/types.h> #include <linux/types.h>
#include <linux/rbtree.h>
#include "cpumap.h" #include "cpumap.h"
#include "rwsem.h"
struct cpu_topology_map { struct cpu_topology_map {
int socket_id; int socket_id;
...@@ -64,8 +66,23 @@ struct perf_env { ...@@ -64,8 +66,23 @@ struct perf_env {
struct memory_node *memory_nodes; struct memory_node *memory_nodes;
unsigned long long memory_bsize; unsigned long long memory_bsize;
u64 clockid_res_ns; u64 clockid_res_ns;
/*
* bpf_info_lock protects bpf rbtrees. This is needed because the
* trees are accessed by different threads in perf-top
*/
struct {
struct rw_semaphore lock;
struct rb_root infos;
u32 infos_cnt;
struct rb_root btfs;
u32 btfs_cnt;
} bpf_progs;
}; };
struct bpf_prog_info_node;
struct btf_node;
extern struct perf_env perf_env; extern struct perf_env perf_env;
void perf_env__exit(struct perf_env *env); void perf_env__exit(struct perf_env *env);
...@@ -80,4 +97,11 @@ const char *perf_env__arch(struct perf_env *env); ...@@ -80,4 +97,11 @@ const char *perf_env__arch(struct perf_env *env);
const char *perf_env__raw_arch(struct perf_env *env); const char *perf_env__raw_arch(struct perf_env *env);
int perf_env__nr_cpus_avail(struct perf_env *env); int perf_env__nr_cpus_avail(struct perf_env *env);
void perf_env__init(struct perf_env *env);
void perf_env__insert_bpf_prog_info(struct perf_env *env,
struct bpf_prog_info_node *info_node);
struct bpf_prog_info_node *perf_env__find_bpf_prog_info(struct perf_env *env,
__u32 prog_id);
void perf_env__insert_btf(struct perf_env *env, struct btf_node *btf_node);
struct btf_node *perf_env__find_btf(struct perf_env *env, __u32 btf_id);
#endif /* __PERF_ENV_H */ #endif /* __PERF_ENV_H */
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "debug.h" #include "debug.h"
#include "units.h" #include "units.h"
#include "asm/bug.h" #include "asm/bug.h"
#include "bpf-event.h"
#include <signal.h> #include <signal.h>
#include <unistd.h> #include <unistd.h>
...@@ -1856,3 +1857,121 @@ struct perf_evsel *perf_evlist__reset_weak_group(struct perf_evlist *evsel_list, ...@@ -1856,3 +1857,121 @@ struct perf_evsel *perf_evlist__reset_weak_group(struct perf_evlist *evsel_list,
} }
return leader; return leader;
} }
int perf_evlist__add_sb_event(struct perf_evlist **evlist,
struct perf_event_attr *attr,
perf_evsel__sb_cb_t cb,
void *data)
{
struct perf_evsel *evsel;
bool new_evlist = (*evlist) == NULL;
if (*evlist == NULL)
*evlist = perf_evlist__new();
if (*evlist == NULL)
return -1;
if (!attr->sample_id_all) {
pr_warning("enabling sample_id_all for all side band events\n");
attr->sample_id_all = 1;
}
evsel = perf_evsel__new_idx(attr, (*evlist)->nr_entries);
if (!evsel)
goto out_err;
evsel->side_band.cb = cb;
evsel->side_band.data = data;
perf_evlist__add(*evlist, evsel);
return 0;
out_err:
if (new_evlist) {
perf_evlist__delete(*evlist);
*evlist = NULL;
}
return -1;
}
static void *perf_evlist__poll_thread(void *arg)
{
struct perf_evlist *evlist = arg;
bool draining = false;
int i;
while (draining || !(evlist->thread.done)) {
if (draining)
draining = false;
else if (evlist->thread.done)
draining = true;
if (!draining)
perf_evlist__poll(evlist, 1000);
for (i = 0; i < evlist->nr_mmaps; i++) {
struct perf_mmap *map = &evlist->mmap[i];
union perf_event *event;
if (perf_mmap__read_init(map))
continue;
while ((event = perf_mmap__read_event(map)) != NULL) {
struct perf_evsel *evsel = perf_evlist__event2evsel(evlist, event);
if (evsel && evsel->side_band.cb)
evsel->side_band.cb(event, evsel->side_band.data);
else
pr_warning("cannot locate proper evsel for the side band event\n");
perf_mmap__consume(map);
}
perf_mmap__read_done(map);
}
}
return NULL;
}
int perf_evlist__start_sb_thread(struct perf_evlist *evlist,
struct target *target)
{
struct perf_evsel *counter;
if (!evlist)
return 0;
if (perf_evlist__create_maps(evlist, target))
goto out_delete_evlist;
evlist__for_each_entry(evlist, counter) {
if (perf_evsel__open(counter, evlist->cpus,
evlist->threads) < 0)
goto out_delete_evlist;
}
if (perf_evlist__mmap(evlist, UINT_MAX))
goto out_delete_evlist;
evlist__for_each_entry(evlist, counter) {
if (perf_evsel__enable(counter))
goto out_delete_evlist;
}
evlist->thread.done = 0;
if (pthread_create(&evlist->thread.th, NULL, perf_evlist__poll_thread, evlist))
goto out_delete_evlist;
return 0;
out_delete_evlist:
perf_evlist__delete(evlist);
evlist = NULL;
return -1;
}
void perf_evlist__stop_sb_thread(struct perf_evlist *evlist)
{
if (!evlist)
return;
evlist->thread.done = 1;
pthread_join(evlist->thread.th, NULL);
perf_evlist__delete(evlist);
}
...@@ -54,6 +54,10 @@ struct perf_evlist { ...@@ -54,6 +54,10 @@ struct perf_evlist {
struct perf_sample *sample); struct perf_sample *sample);
u64 first_sample_time; u64 first_sample_time;
u64 last_sample_time; u64 last_sample_time;
struct {
pthread_t th;
volatile int done;
} thread;
}; };
struct perf_evsel_str_handler { struct perf_evsel_str_handler {
...@@ -87,6 +91,14 @@ int __perf_evlist__add_default_attrs(struct perf_evlist *evlist, ...@@ -87,6 +91,14 @@ int __perf_evlist__add_default_attrs(struct perf_evlist *evlist,
int perf_evlist__add_dummy(struct perf_evlist *evlist); int perf_evlist__add_dummy(struct perf_evlist *evlist);
int perf_evlist__add_sb_event(struct perf_evlist **evlist,
struct perf_event_attr *attr,
perf_evsel__sb_cb_t cb,
void *data);
int perf_evlist__start_sb_thread(struct perf_evlist *evlist,
struct target *target);
void perf_evlist__stop_sb_thread(struct perf_evlist *evlist);
int perf_evlist__add_newtp(struct perf_evlist *evlist, int perf_evlist__add_newtp(struct perf_evlist *evlist,
const char *sys, const char *name, void *handler); const char *sys, const char *name, void *handler);
......
...@@ -1036,7 +1036,7 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts, ...@@ -1036,7 +1036,7 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts,
attr->mmap2 = track && !perf_missing_features.mmap2; attr->mmap2 = track && !perf_missing_features.mmap2;
attr->comm = track; attr->comm = track;
attr->ksymbol = track && !perf_missing_features.ksymbol; attr->ksymbol = track && !perf_missing_features.ksymbol;
attr->bpf_event = track && opts->bpf_event && attr->bpf_event = track && !opts->no_bpf_event &&
!perf_missing_features.bpf_event; !perf_missing_features.bpf_event;
if (opts->record_namespaces) if (opts->record_namespaces)
...@@ -1292,6 +1292,7 @@ void perf_evsel__exit(struct perf_evsel *evsel) ...@@ -1292,6 +1292,7 @@ void perf_evsel__exit(struct perf_evsel *evsel)
{ {
assert(list_empty(&evsel->node)); assert(list_empty(&evsel->node));
assert(evsel->evlist == NULL); assert(evsel->evlist == NULL);
perf_evsel__free_counts(evsel);
perf_evsel__free_fd(evsel); perf_evsel__free_fd(evsel);
perf_evsel__free_id(evsel); perf_evsel__free_id(evsel);
perf_evsel__free_config_terms(evsel); perf_evsel__free_config_terms(evsel);
...@@ -1342,10 +1343,9 @@ void perf_counts_values__scale(struct perf_counts_values *count, ...@@ -1342,10 +1343,9 @@ void perf_counts_values__scale(struct perf_counts_values *count,
count->val = 0; count->val = 0;
} else if (count->run < count->ena) { } else if (count->run < count->ena) {
scaled = 1; scaled = 1;
count->val = (u64)((double) count->val * count->ena / count->run + 0.5); count->val = (u64)((double) count->val * count->ena / count->run);
} }
} else }
count->ena = count->run = 0;
if (pscaled) if (pscaled)
*pscaled = scaled; *pscaled = scaled;
......
...@@ -73,6 +73,8 @@ struct perf_evsel_config_term { ...@@ -73,6 +73,8 @@ struct perf_evsel_config_term {
struct perf_stat_evsel; struct perf_stat_evsel;
typedef int (perf_evsel__sb_cb_t)(union perf_event *event, void *data);
/** struct perf_evsel - event selector /** struct perf_evsel - event selector
* *
* @evlist - evlist this evsel is in, if it is in one. * @evlist - evlist this evsel is in, if it is in one.
...@@ -151,6 +153,10 @@ struct perf_evsel { ...@@ -151,6 +153,10 @@ struct perf_evsel {
bool collect_stat; bool collect_stat;
bool weak_group; bool weak_group;
const char *pmu_name; const char *pmu_name;
struct {
perf_evsel__sb_cb_t *cb;
void *data;
} side_band;
}; };
union u64_swap { union u64_swap {
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <sys/utsname.h> #include <sys/utsname.h>
#include <linux/time64.h> #include <linux/time64.h>
#include <dirent.h> #include <dirent.h>
#include <bpf/libbpf.h>
#include "evlist.h" #include "evlist.h"
#include "evsel.h" #include "evsel.h"
...@@ -40,6 +41,7 @@ ...@@ -40,6 +41,7 @@
#include "time-utils.h" #include "time-utils.h"
#include "units.h" #include "units.h"
#include "cputopo.h" #include "cputopo.h"
#include "bpf-event.h"
#include "sane_ctype.h" #include "sane_ctype.h"
...@@ -876,6 +878,89 @@ static int write_dir_format(struct feat_fd *ff, ...@@ -876,6 +878,89 @@ static int write_dir_format(struct feat_fd *ff,
return do_write(ff, &data->dir.version, sizeof(data->dir.version)); return do_write(ff, &data->dir.version, sizeof(data->dir.version));
} }
#ifdef HAVE_LIBBPF_SUPPORT
static int write_bpf_prog_info(struct feat_fd *ff,
struct perf_evlist *evlist __maybe_unused)
{
struct perf_env *env = &ff->ph->env;
struct rb_root *root;
struct rb_node *next;
int ret;
down_read(&env->bpf_progs.lock);
ret = do_write(ff, &env->bpf_progs.infos_cnt,
sizeof(env->bpf_progs.infos_cnt));
if (ret < 0)
goto out;
root = &env->bpf_progs.infos;
next = rb_first(root);
while (next) {
struct bpf_prog_info_node *node;
size_t len;
node = rb_entry(next, struct bpf_prog_info_node, rb_node);
next = rb_next(&node->rb_node);
len = sizeof(struct bpf_prog_info_linear) +
node->info_linear->data_len;
/* before writing to file, translate address to offset */
bpf_program__bpil_addr_to_offs(node->info_linear);
ret = do_write(ff, node->info_linear, len);
/*
* translate back to address even when do_write() fails,
* so that this function never changes the data.
*/
bpf_program__bpil_offs_to_addr(node->info_linear);
if (ret < 0)
goto out;
}
out:
up_read(&env->bpf_progs.lock);
return ret;
}
#else // HAVE_LIBBPF_SUPPORT
static int write_bpf_prog_info(struct feat_fd *ff __maybe_unused,
struct perf_evlist *evlist __maybe_unused)
{
return 0;
}
#endif // HAVE_LIBBPF_SUPPORT
static int write_bpf_btf(struct feat_fd *ff,
struct perf_evlist *evlist __maybe_unused)
{
struct perf_env *env = &ff->ph->env;
struct rb_root *root;
struct rb_node *next;
int ret;
down_read(&env->bpf_progs.lock);
ret = do_write(ff, &env->bpf_progs.btfs_cnt,
sizeof(env->bpf_progs.btfs_cnt));
if (ret < 0)
goto out;
root = &env->bpf_progs.btfs;
next = rb_first(root);
while (next) {
struct btf_node *node;
node = rb_entry(next, struct btf_node, rb_node);
next = rb_next(&node->rb_node);
ret = do_write(ff, &node->id,
sizeof(u32) * 2 + node->data_size);
if (ret < 0)
goto out;
}
out:
up_read(&env->bpf_progs.lock);
return ret;
}
static int cpu_cache_level__sort(const void *a, const void *b) static int cpu_cache_level__sort(const void *a, const void *b)
{ {
struct cpu_cache_level *cache_a = (struct cpu_cache_level *)a; struct cpu_cache_level *cache_a = (struct cpu_cache_level *)a;
...@@ -1367,6 +1452,52 @@ static void print_dir_format(struct feat_fd *ff, FILE *fp) ...@@ -1367,6 +1452,52 @@ static void print_dir_format(struct feat_fd *ff, FILE *fp)
fprintf(fp, "# directory data version : %"PRIu64"\n", data->dir.version); fprintf(fp, "# directory data version : %"PRIu64"\n", data->dir.version);
} }
static void print_bpf_prog_info(struct feat_fd *ff, FILE *fp)
{
struct perf_env *env = &ff->ph->env;
struct rb_root *root;
struct rb_node *next;
down_read(&env->bpf_progs.lock);
root = &env->bpf_progs.infos;
next = rb_first(root);
while (next) {
struct bpf_prog_info_node *node;
node = rb_entry(next, struct bpf_prog_info_node, rb_node);
next = rb_next(&node->rb_node);
bpf_event__print_bpf_prog_info(&node->info_linear->info,
env, fp);
}
up_read(&env->bpf_progs.lock);
}
static void print_bpf_btf(struct feat_fd *ff, FILE *fp)
{
struct perf_env *env = &ff->ph->env;
struct rb_root *root;
struct rb_node *next;
down_read(&env->bpf_progs.lock);
root = &env->bpf_progs.btfs;
next = rb_first(root);
while (next) {
struct btf_node *node;
node = rb_entry(next, struct btf_node, rb_node);
next = rb_next(&node->rb_node);
fprintf(fp, "# btf info of id %u\n", node->id);
}
up_read(&env->bpf_progs.lock);
}
static void free_event_desc(struct perf_evsel *events) static void free_event_desc(struct perf_evsel *events)
{ {
struct perf_evsel *evsel; struct perf_evsel *evsel;
...@@ -2414,6 +2545,124 @@ static int process_dir_format(struct feat_fd *ff, ...@@ -2414,6 +2545,124 @@ static int process_dir_format(struct feat_fd *ff,
return do_read_u64(ff, &data->dir.version); return do_read_u64(ff, &data->dir.version);
} }
#ifdef HAVE_LIBBPF_SUPPORT
static int process_bpf_prog_info(struct feat_fd *ff, void *data __maybe_unused)
{
struct bpf_prog_info_linear *info_linear;
struct bpf_prog_info_node *info_node;
struct perf_env *env = &ff->ph->env;
u32 count, i;
int err = -1;
if (ff->ph->needs_swap) {
pr_warning("interpreting bpf_prog_info from systems with endianity is not yet supported\n");
return 0;
}
if (do_read_u32(ff, &count))
return -1;
down_write(&env->bpf_progs.lock);
for (i = 0; i < count; ++i) {
u32 info_len, data_len;
info_linear = NULL;
info_node = NULL;
if (do_read_u32(ff, &info_len))
goto out;
if (do_read_u32(ff, &data_len))
goto out;
if (info_len > sizeof(struct bpf_prog_info)) {
pr_warning("detected invalid bpf_prog_info\n");
goto out;
}
info_linear = malloc(sizeof(struct bpf_prog_info_linear) +
data_len);
if (!info_linear)
goto out;
info_linear->info_len = sizeof(struct bpf_prog_info);
info_linear->data_len = data_len;
if (do_read_u64(ff, (u64 *)(&info_linear->arrays)))
goto out;
if (__do_read(ff, &info_linear->info, info_len))
goto out;
if (info_len < sizeof(struct bpf_prog_info))
memset(((void *)(&info_linear->info)) + info_len, 0,
sizeof(struct bpf_prog_info) - info_len);
if (__do_read(ff, info_linear->data, data_len))
goto out;
info_node = malloc(sizeof(struct bpf_prog_info_node));
if (!info_node)
goto out;
/* after reading from file, translate offset to address */
bpf_program__bpil_offs_to_addr(info_linear);
info_node->info_linear = info_linear;
perf_env__insert_bpf_prog_info(env, info_node);
}
return 0;
out:
free(info_linear);
free(info_node);
up_write(&env->bpf_progs.lock);
return err;
}
#else // HAVE_LIBBPF_SUPPORT
static int process_bpf_prog_info(struct feat_fd *ff __maybe_unused, void *data __maybe_unused)
{
return 0;
}
#endif // HAVE_LIBBPF_SUPPORT
static int process_bpf_btf(struct feat_fd *ff, void *data __maybe_unused)
{
struct perf_env *env = &ff->ph->env;
u32 count, i;
if (ff->ph->needs_swap) {
pr_warning("interpreting btf from systems with endianity is not yet supported\n");
return 0;
}
if (do_read_u32(ff, &count))
return -1;
down_write(&env->bpf_progs.lock);
for (i = 0; i < count; ++i) {
struct btf_node *node;
u32 id, data_size;
if (do_read_u32(ff, &id))
return -1;
if (do_read_u32(ff, &data_size))
return -1;
node = malloc(sizeof(struct btf_node) + data_size);
if (!node)
return -1;
node->id = id;
node->data_size = data_size;
if (__do_read(ff, node->data, data_size)) {
free(node);
return -1;
}
perf_env__insert_btf(env, node);
}
up_write(&env->bpf_progs.lock);
return 0;
}
struct feature_ops { struct feature_ops {
int (*write)(struct feat_fd *ff, struct perf_evlist *evlist); int (*write)(struct feat_fd *ff, struct perf_evlist *evlist);
void (*print)(struct feat_fd *ff, FILE *fp); void (*print)(struct feat_fd *ff, FILE *fp);
...@@ -2474,7 +2723,9 @@ static const struct feature_ops feat_ops[HEADER_LAST_FEATURE] = { ...@@ -2474,7 +2723,9 @@ static const struct feature_ops feat_ops[HEADER_LAST_FEATURE] = {
FEAT_OPR(SAMPLE_TIME, sample_time, false), FEAT_OPR(SAMPLE_TIME, sample_time, false),
FEAT_OPR(MEM_TOPOLOGY, mem_topology, true), FEAT_OPR(MEM_TOPOLOGY, mem_topology, true),
FEAT_OPR(CLOCKID, clockid, false), FEAT_OPR(CLOCKID, clockid, false),
FEAT_OPN(DIR_FORMAT, dir_format, false) FEAT_OPN(DIR_FORMAT, dir_format, false),
FEAT_OPR(BPF_PROG_INFO, bpf_prog_info, false),
FEAT_OPR(BPF_BTF, bpf_btf, false),
}; };
struct header_print_data { struct header_print_data {
......
...@@ -40,6 +40,8 @@ enum { ...@@ -40,6 +40,8 @@ enum {
HEADER_MEM_TOPOLOGY, HEADER_MEM_TOPOLOGY,
HEADER_CLOCKID, HEADER_CLOCKID,
HEADER_DIR_FORMAT, HEADER_DIR_FORMAT,
HEADER_BPF_PROG_INFO,
HEADER_BPF_BTF,
HEADER_LAST_FEATURE, HEADER_LAST_FEATURE,
HEADER_FEAT_BITS = 256, HEADER_FEAT_BITS = 256,
}; };
......
...@@ -1111,8 +1111,10 @@ int hist_entry_iter__add(struct hist_entry_iter *iter, struct addr_location *al, ...@@ -1111,8 +1111,10 @@ int hist_entry_iter__add(struct hist_entry_iter *iter, struct addr_location *al,
err = sample__resolve_callchain(iter->sample, &callchain_cursor, &iter->parent, err = sample__resolve_callchain(iter->sample, &callchain_cursor, &iter->parent,
iter->evsel, al, max_stack_depth); iter->evsel, al, max_stack_depth);
if (err) if (err) {
map__put(alm);
return err; return err;
}
err = iter->ops->prepare_entry(iter, al); err = iter->ops->prepare_entry(iter, al);
if (err) if (err)
......
...@@ -577,10 +577,25 @@ static void __maps__purge(struct maps *maps) ...@@ -577,10 +577,25 @@ static void __maps__purge(struct maps *maps)
} }
} }
static void __maps__purge_names(struct maps *maps)
{
struct rb_root *root = &maps->names;
struct rb_node *next = rb_first(root);
while (next) {
struct map *pos = rb_entry(next, struct map, rb_node_name);
next = rb_next(&pos->rb_node_name);
rb_erase_init(&pos->rb_node_name, root);
map__put(pos);
}
}
static void maps__exit(struct maps *maps) static void maps__exit(struct maps *maps)
{ {
down_write(&maps->lock); down_write(&maps->lock);
__maps__purge(maps); __maps__purge(maps);
__maps__purge_names(maps);
up_write(&maps->lock); up_write(&maps->lock);
} }
...@@ -917,6 +932,9 @@ static void __maps__remove(struct maps *maps, struct map *map) ...@@ -917,6 +932,9 @@ static void __maps__remove(struct maps *maps, struct map *map)
{ {
rb_erase_init(&map->rb_node, &maps->entries); rb_erase_init(&map->rb_node, &maps->entries);
map__put(map); map__put(map);
rb_erase_init(&map->rb_node_name, &maps->names);
map__put(map);
} }
void maps__remove(struct maps *maps, struct map *map) void maps__remove(struct maps *maps, struct map *map)
......
...@@ -270,6 +270,8 @@ static int __ordered_events__flush(struct ordered_events *oe, enum oe_flush how, ...@@ -270,6 +270,8 @@ static int __ordered_events__flush(struct ordered_events *oe, enum oe_flush how,
"FINAL", "FINAL",
"ROUND", "ROUND",
"HALF ", "HALF ",
"TOP ",
"TIME ",
}; };
int err; int err;
bool show_progress = false; bool show_progress = false;
......
...@@ -2271,6 +2271,7 @@ static bool is_event_supported(u8 type, unsigned config) ...@@ -2271,6 +2271,7 @@ static bool is_event_supported(u8 type, unsigned config)
perf_evsel__delete(evsel); perf_evsel__delete(evsel);
} }
thread_map__put(tmap);
return ret; return ret;
} }
...@@ -2341,6 +2342,7 @@ void print_sdt_events(const char *subsys_glob, const char *event_glob, ...@@ -2341,6 +2342,7 @@ void print_sdt_events(const char *subsys_glob, const char *event_glob,
printf(" %-50s [%s]\n", buf, "SDT event"); printf(" %-50s [%s]\n", buf, "SDT event");
free(buf); free(buf);
} }
free(path);
} else } else
printf(" %-50s [%s]\n", nd->s, "SDT event"); printf(" %-50s [%s]\n", nd->s, "SDT event");
if (nd2) { if (nd2) {
......
...@@ -132,6 +132,7 @@ struct perf_session *perf_session__new(struct perf_data *data, ...@@ -132,6 +132,7 @@ struct perf_session *perf_session__new(struct perf_data *data,
ordered_events__init(&session->ordered_events, ordered_events__init(&session->ordered_events,
ordered_events__deliver_event, NULL); ordered_events__deliver_event, NULL);
perf_env__init(&session->header.env);
if (data) { if (data) {
if (perf_data__open(data)) if (perf_data__open(data))
goto out_delete; goto out_delete;
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "evsel.h" #include "evsel.h"
#include "evlist.h" #include "evlist.h"
#include "strlist.h" #include "strlist.h"
#include "strbuf.h"
#include <traceevent/event-parse.h> #include <traceevent/event-parse.h>
#include "mem-events.h" #include "mem-events.h"
#include "annotate.h" #include "annotate.h"
...@@ -3107,3 +3108,54 @@ void reset_output_field(void) ...@@ -3107,3 +3108,54 @@ void reset_output_field(void)
reset_dimensions(); reset_dimensions();
perf_hpp__reset_output_field(&perf_hpp_list); perf_hpp__reset_output_field(&perf_hpp_list);
} }
#define INDENT (3*8 + 1)
static void add_key(struct strbuf *sb, const char *str, int *llen)
{
if (*llen >= 75) {
strbuf_addstr(sb, "\n\t\t\t ");
*llen = INDENT;
}
strbuf_addf(sb, " %s", str);
*llen += strlen(str) + 1;
}
static void add_sort_string(struct strbuf *sb, struct sort_dimension *s, int n,
int *llen)
{
int i;
for (i = 0; i < n; i++)
add_key(sb, s[i].name, llen);
}
static void add_hpp_sort_string(struct strbuf *sb, struct hpp_dimension *s, int n,
int *llen)
{
int i;
for (i = 0; i < n; i++)
add_key(sb, s[i].name, llen);
}
const char *sort_help(const char *prefix)
{
struct strbuf sb;
char *s;
int len = strlen(prefix) + INDENT;
strbuf_init(&sb, 300);
strbuf_addstr(&sb, prefix);
add_hpp_sort_string(&sb, hpp_sort_dimensions,
ARRAY_SIZE(hpp_sort_dimensions), &len);
add_sort_string(&sb, common_sort_dimensions,
ARRAY_SIZE(common_sort_dimensions), &len);
add_sort_string(&sb, bstack_sort_dimensions,
ARRAY_SIZE(bstack_sort_dimensions), &len);
add_sort_string(&sb, memory_sort_dimensions,
ARRAY_SIZE(memory_sort_dimensions), &len);
s = strbuf_detach(&sb, NULL);
strbuf_release(&sb);
return s;
}
...@@ -296,6 +296,8 @@ void reset_output_field(void); ...@@ -296,6 +296,8 @@ void reset_output_field(void);
void sort__setup_elide(FILE *fp); void sort__setup_elide(FILE *fp);
void perf_hpp__set_elide(int idx, bool elide); void perf_hpp__set_elide(int idx, bool elide);
const char *sort_help(const char *prefix);
int report_parse_ignore_callees_opt(const struct option *opt, const char *arg, int unset); int report_parse_ignore_callees_opt(const struct option *opt, const char *arg, int unset);
bool is_strict_order(const char *order); bool is_strict_order(const char *order);
......
...@@ -291,10 +291,8 @@ process_counter_values(struct perf_stat_config *config, struct perf_evsel *evsel ...@@ -291,10 +291,8 @@ process_counter_values(struct perf_stat_config *config, struct perf_evsel *evsel
break; break;
case AGGR_GLOBAL: case AGGR_GLOBAL:
aggr->val += count->val; aggr->val += count->val;
if (config->scale) { aggr->ena += count->ena;
aggr->ena += count->ena; aggr->run += count->run;
aggr->run += count->run;
}
case AGGR_UNSET: case AGGR_UNSET:
default: default:
break; break;
...@@ -442,10 +440,8 @@ int create_perf_stat_counter(struct perf_evsel *evsel, ...@@ -442,10 +440,8 @@ int create_perf_stat_counter(struct perf_evsel *evsel,
struct perf_event_attr *attr = &evsel->attr; struct perf_event_attr *attr = &evsel->attr;
struct perf_evsel *leader = evsel->leader; struct perf_evsel *leader = evsel->leader;
if (config->scale) { attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_TOTAL_TIME_RUNNING;
PERF_FORMAT_TOTAL_TIME_RUNNING;
}
/* /*
* The event is part of non trivial group, let's enable * The event is part of non trivial group, let's enable
......
...@@ -1455,6 +1455,7 @@ static bool dso__is_compatible_symtab_type(struct dso *dso, bool kmod, ...@@ -1455,6 +1455,7 @@ static bool dso__is_compatible_symtab_type(struct dso *dso, bool kmod,
case DSO_BINARY_TYPE__BUILD_ID_CACHE_DEBUGINFO: case DSO_BINARY_TYPE__BUILD_ID_CACHE_DEBUGINFO:
return true; return true;
case DSO_BINARY_TYPE__BPF_PROG_INFO:
case DSO_BINARY_TYPE__NOT_FOUND: case DSO_BINARY_TYPE__NOT_FOUND:
default: default:
return false; return false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment