Skip to content

Commit

Permalink
Stack_Analyzer: adapted to lib (linuxkerneltravel#814)
Browse files Browse the repository at this point in the history
* adapted to lib

Signed-off-by: legendlliu <[email protected]>

* update docs

Signed-off-by: legendlliu <[email protected]>

* remove child submodule

Signed-off-by: legendlliu <[email protected]>

* update action

Signed-off-by: legendlliu <[email protected]>

* update Makefile

Signed-off-by: LiuLingze <[email protected]>

* adapt mem mod to local vmlinux

Signed-off-by: LiuLingze <[email protected]>

---------

Signed-off-by: legendlliu <[email protected]>
Signed-off-by: LiuLingze <[email protected]>
Co-authored-by: legendlliu <[email protected]>
  • Loading branch information
GorilaMond and legendlliu committed Jun 3, 2024
1 parent a27fd36 commit 995eed9
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ebpf_stack_analyser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

- name: Install native lib dependencies
run: |
git submodule update --init --recursive eBPF_Supermarket/Stack_Analyser/ MagicEyes/
git submodule update --init --recursive eBPF_Supermarket/lib/ MagicEyes/
sudo apt install clang libelf1 libelf-dev zlib1g-dev
- name: Compile test examples
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@
[submodule "eBPF_Supermarket/CPU_Subsystem/libbpf"]
path = eBPF_Supermarket/CPU_Subsystem/libbpf
url = https://github.com/libbpf/libbpf.git
[submodule "eBPF_Supermarket/Stack_Analyser/libbpf-bootstrap"]
path = eBPF_Supermarket/Stack_Analyser/libbpf-bootstrap
url = https://github.com/libbpf/libbpf-bootstrap.git
[submodule "eBPF_Supermarket/Network_Subsystem/net_manager/lib/libbpf"]
path = eBPF_Supermarket/Network_Subsystem/net_manager/lib/libbpf
url = https://github.com/libbpf/libbpf.git
Expand Down
22 changes: 18 additions & 4 deletions eBPF_Supermarket/Stack_Analyser/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
OUTPUT := .output
BPF_SKEL := bpf_skel
CLANG ?= clang
LIBBPF_SRC := $(abspath libbpf-bootstrap/libbpf/src)
BPFTOOL_SRC := $(abspath libbpf-bootstrap/bpftool/src)
CXX := clang
LIB := ../lib
LIBBPF_ROOT := $(abspath $(LIB)/libbpf)
LIBBPF_SRC := $(LIBBPF_ROOT)/src
BPFTOOL_SRC := $(abspath $(LIB)/bpftool/src)
LIBBPF_OBJ := $(abspath $(OUTPUT)/libbpf.a)
BPFTOOL_OUTPUT ?= $(abspath $(OUTPUT)/bpftool)
BPFTOOL ?= $(BPFTOOL_OUTPUT)/bootstrap/bpftool
Expand All @@ -31,11 +34,12 @@ ARCH ?= $(shell uname -m | sed 's/x86_64/x86/' \
| sed 's/mips.*/mips/' \
| sed 's/riscv64/riscv/' \
| sed 's/loongarch64/loongarch/')
VMLINUX := libbpf-bootstrap/vmlinux/$(ARCH)/vmlinux.h

VMLINUX := $(LIB)/vmlinux.h
# 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./include -I./$(OUTPUT) -I./$(BPF_SKEL) -I./libbpf-bootstrap/libbpf/include/uapi -I$(dir $(VMLINUX))
INCLUDES := -I./include -I./$(OUTPUT) -I./$(BPF_SKEL) -I$(LIBBPF_ROOT)/include/uapi -I$(dir $(VMLINUX))
CFLAGS := -Og -Wall
ALL_LDFLAGS := $(LDFLAGS) $(EXTRA_LDFLAGS)

Expand Down Expand Up @@ -85,6 +89,16 @@ clean:
$(call msg,CLEAN)
$(Q)rm -rf $(OUTPUT) $(TARGETS) $(BPF_SKEL)

init:
$(call msg,INIT,$(LIB))
$(Q)git submodule update --init --recursive ../lib/

$(LIBBPF_SRC) $(BPFTOOL_SRC): init

$(VMLINUX):
$(call msg,BTFDUMP,$@)
$(Q)bpftool btf dump file /sys/kernel/btf/vmlinux format c > $@

$(OUTPUT) $(OUTPUT)/libbpf $(BPFTOOL_OUTPUT) $(BPF_SKEL):
$(call msg,MKDIR,$@)
$(Q)mkdir -p $@
Expand Down
23 changes: 18 additions & 5 deletions eBPF_Supermarket/Stack_Analyser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,34 @@ Stack_Analyzer是一个基于eBPF的按照指定时间间隔(默认为5s)来

## 编译要求

Ubuntu下需要安装一下依赖,其他发行版类似
初始化并更新libbpf和bpftool的代码仓库:

```shell
$ git submodule update --init --recursive
$ apt install clang libelf1 libelf-dev zlib1g-dev
git submodule update --init --recursive ../lib/*
```
需要安装一下依赖:

g++-10以上,clang-12以上
Ubuntu下

```shell
sudo apt update
sudo apt install -y clang libelf1 libelf-dev zlib1g-dev bpftool
```

CentOS下

```shell
sudo dnf install clang elfutils-libelf elfutils-libelf-devel zlib-devel bpftool
```

clang-12以上

# 使用方法

## 工具编译

```shell
$ make
$ make -j$(nproc)
```

## 命令使用方法
Expand Down
2 changes: 1 addition & 1 deletion eBPF_Supermarket/Stack_Analyser/bpf/memleak.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ int memleak__mm_page_free(struct trace_event_raw_mm_page_free *ctx)
SEC("tracepoint/percpu/percpu_alloc_percpu")
int memleak__percpu_alloc_percpu(struct trace_event_raw_percpu_alloc_percpu *ctx)
{
gen_alloc_enter(ctx->bytes_alloc);
gen_alloc_enter(ctx->size);

return gen_alloc_exit2(ctx, (u64)(ctx->ptr));
}
Expand Down
1 change: 0 additions & 1 deletion eBPF_Supermarket/Stack_Analyser/libbpf-bootstrap
Submodule libbpf-bootstrap deleted from b0c823

0 comments on commit 995eed9

Please sign in to comment.