Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions profiler/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ BPFTOOL ?= $(abspath ../tools/bpftool)
LIBBPF_SRC := $(abspath ../libbpf/src)
LIBBPF_OBJ := $(abspath $(OUTPUT)/libbpf.a)
ARCH := $(shell uname -m | sed 's/x86_64/x86/' | sed 's/aarch64/arm64/' | sed 's/ppc64le/powerpc/' | sed 's/mips.*/mips/')
VMLINUX := $(ARCH)/$(ARCH)/vmlinux.h
VMLINUX := ../vmlinux/$(ARCH)/
HELPERS := $(abspath ../helpers)
# Use our own libbpf API headers and Linux UAPI headers distributed with
# libbpf to avoid dependency on system-wide headers, which could be missing or
# outdated
INCLUDES := -I$(OUTPUT) -I../libbpf/include/uapi -I$(dir $(VMLINUX)) -I$(HELPERS)
INCLUDES := -I$(OUTPUT) -I../libbpf/include/uapi -I$(VMLINUX) -I$(HELPERS)
CFLAGS := -g -Wall # -fsanitize=address

APPS = profile
Expand Down Expand Up @@ -45,7 +45,7 @@ all: $(APPS)

$(VMLINUX):
$(Q)wget https://github.com/yunwei37/apisix-profiler/releases/download/vmlinux/vmlinux.tar
$(Q)tar -xvf vmlinux.tar ../
$(Q)tar -xvf vmlinux.tar -C ../
$(Q)rm vmlinux.tar

.PHONY: clean
Expand Down
16 changes: 12 additions & 4 deletions profiler/stack_printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,20 @@ static bool read_batch_counts_map(int fd, struct key_ext_t *items, __u32 *count)
__u32 vals[*count];
struct stack_key keys[*count];

//BPF_F_LOCK
const struct bpf_map_batch_opts batch_opts = {
.sz = sizeof(struct stack_key),
.elem_flags = BPF_F_LOCK,
};


while (n_read < *count && !err)
{
n = *count - n_read;
err = bpf_map_lookup_batch(fd, &in, &out, keys + n_read,
vals + n_read, &n, NULL);
err = bpf_map_lookup_batch(fd, &in, &out,
keys + n_read * sizeof(stack_key),
vals + n_read,
&n, &batch_opts);
if (err && errno != ENOENT)
{
/* we want to propagate EINVAL upper, so that
Expand Down Expand Up @@ -90,7 +99,6 @@ static bool read_counts_map(int fd, struct key_ext_t *items, __u32 *count)
struct stack_key *lookup_key = &empty;
int i = 0;
int err;

if (batch_map_ops)
{
bool ok = read_batch_counts_map(fd, items, count);
Expand Down Expand Up @@ -324,7 +332,7 @@ void print_stack_trace(struct ksyms *ksyms, struct syms_cache *syms_cache,

if (stack_id_err(k->kern_stack_id))
printf(";[Missed Kernel Stack]");
for (std::size_t j = nr_kip - 1; j >= 0; j--)
for (int j = nr_kip - 1; j >= 0; j--)
{
ksym = ksyms__map_addr(ksyms, kip[j]);
printf(";%s", ksym ? ksym->name : "[unknown]");
Expand Down