Skip to content

Commit

Permalink
Merge pull request linuxkerneltravel#631 from zhangzihengya/develop
Browse files Browse the repository at this point in the history
proc_image项目:用开发好的新框架工具替换旧版本工具 & 相应的修改readme和流水线
  • Loading branch information
chenamy2017 authored Dec 27, 2023
2 parents acadb5f + c69f820 commit b4a1f19
Show file tree
Hide file tree
Showing 21 changed files with 669 additions and 2,512 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/eBPF_proc_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,11 @@ jobs:
cd eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/tools
make keytime_image
sudo ./keytime_image -t 1
- name: Run proc_image
run: |
cd eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image
make proc_image
sudo ./proc_image -t 1
- name: Run new_proc_image
run: |
cd eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/developing
make proc_image
sudo ./proc_image -a -p 1 -t 1
- name: Run mutex_test
Expand Down
47 changes: 12 additions & 35 deletions eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,15 @@ ARCH ?= $(shell uname -m | sed 's/x86_64/x86/' \
| sed 's/mips.*/mips/' \
| sed 's/riscv64/riscv/' \
| sed 's/loongarch64/loongarch/')
VMLINUX := ../vmlinux/$(ARCH)/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$(OUTPUT) -I../libbpf/include/uapi -I$(dir $(VMLINUX)) -I$(LIBBLAZESYM_INC)
INCLUDES := -I$(OUTPUT) -I../libbpf/include/uapi -I$(LIBBLAZESYM_INC) -I./include
CFLAGS := -g -Wall
ALL_LDFLAGS := $(LDFLAGS) $(EXTRA_LDFLAGS)

APPS = proc_image

CARGO ?= $(shell which cargo)
ifeq ($(strip $(CARGO)),)
BZS_APPS :=
else
BZS_APPS := profile
APPS += $(BZS_APPS)
# Required by libblazesym
ALL_LDFLAGS += -lrt -ldl -lpthread -lm
endif
APPS = resource_image lock_image syscall_image keytime_image
TARGETS = proc_image

# Get Clang's default includes on this system. We'll explicitly add these dirs
# to the includes list when compiling with `-target bpf` because otherwise some
Expand Down Expand Up @@ -87,12 +77,12 @@ $(call allow-override,CC,$(CROSS_COMPILE)cc)
$(call allow-override,LD,$(CROSS_COMPILE)ld)

.PHONY: all
all: $(APPS)
all: $(TARGETS)

.PHONY: clean
clean:
$(call msg,CLEAN)
$(Q)rm -rf $(OUTPUT) $(APPS)
$(Q)rm -rf $(OUTPUT) $(TARGETS)

$(OUTPUT) $(OUTPUT)/libbpf $(BPFTOOL_OUTPUT):
$(call msg,MKDIR,$@)
Expand All @@ -111,42 +101,29 @@ $(BPFTOOL): | $(BPFTOOL_OUTPUT)
$(call msg,BPFTOOL,$@)
$(Q)$(MAKE) ARCH= CROSS_COMPILE= OUTPUT=$(BPFTOOL_OUTPUT)/ -C $(BPFTOOL_SRC) bootstrap


$(LIBBLAZESYM_SRC)/target/release/libblazesym.a::
$(Q)cd $(LIBBLAZESYM_SRC) && $(CARGO) build --release

$(LIBBLAZESYM_OBJ): $(LIBBLAZESYM_SRC)/target/release/libblazesym.a | $(OUTPUT)
$(call msg,LIB, $@)
$(Q)cp $(LIBBLAZESYM_SRC)/target/release/libblazesym.a $@

# Build BPF code
$(OUTPUT)/%.bpf.o: %.bpf.c $(LIBBPF_OBJ) $(wildcard %.h) $(VMLINUX) | $(OUTPUT) $(BPFTOOL)
$(OUTPUT)/%.bpf.o: bpf/%.bpf.c $(LIBBPF_OBJ) $(wildcard %.h) $(VMLINUX) | $(OUTPUT) $(BPFTOOL)
$(call msg,BPF,$@)
$(Q)$(CLANG) -g -O2 -target bpf -D__TARGET_ARCH_$(ARCH) \
$(INCLUDES) $(CLANG_BPF_SYS_INCLUDES) \
-c $(filter %.c,$^) -o $(patsubst %.bpf.o,%.tmp.bpf.o,$@)
$(Q)$(BPFTOOL) gen object $@ $(patsubst %.bpf.o,%.tmp.bpf.o,$@)

# Generate BPF skeletons
$(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o | $(OUTPUT) $(BPFTOOL)
.PHONY: $(APPS)
$(APPS): %: $(OUTPUT)/%.bpf.o | $(OUTPUT) $(BPFTOOL)
$(call msg,GEN-SKEL,$@)
$(Q)$(BPFTOOL) gen skeleton $< > $@
$(Q)$(BPFTOOL) gen skeleton $< > $(OUTPUT)/$@.skel.h

# Build user-space code
$(patsubst %,$(OUTPUT)/%.o,$(APPS)): %.o: %.skel.h

$(OUTPUT)/%.o: %.c $(wildcard %.h) | $(OUTPUT)
$(OUTPUT)/$(TARGETS).o: $(TARGETS).c $(APPS) | $(OUTPUT)
$(call msg,CC,$@)
$(Q)$(CC) $(CFLAGS) $(INCLUDES) -c $(filter %.c,$^) -o $@

$(patsubst %,$(OUTPUT)/%.o,$(BZS_APPS)): $(LIBBLAZESYM_OBJ)

$(BZS_APPS): $(LIBBLAZESYM_OBJ)

# Build application binary
$(APPS): %: $(OUTPUT)/%.o $(LIBBPF_OBJ) | $(OUTPUT)
$(TARGETS): %: $(OUTPUT)/%.o $(LIBBPF_OBJ) | $(OUTPUT)
$(call msg,BINARY,$@)
$(Q)$(CC) $(CFLAGS) $^ $(ALL_LDFLAGS) -lelf -lz -o $@
$(Q)$(CC) $^ $(ALL_LDFLAGS) -lstdc++ -lelf -lz -o $@

# delete failed targets
.DELETE_ON_ERROR:
Expand Down
21 changes: 6 additions & 15 deletions eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,13 @@ proc_image 工具的参数信息:
| -------------------- | ------------------------------------------------- |
| -p, --pid=PID | 指定跟踪进程的pid,默认为0号进程 |
| -t, --time=TIME-SEC | 设置程序的最大运行时间(0表示无限),默认一直运行 |
| -C, --cpuid=CPUID | 为每CPU进程设置,其他进程不需要设置该参数 |
| -c, --cputime | 统计进程上下CPU时间信息 |
| -e, --execve | 对进程execve关键时间点进行画像 |
| -E, --exit | 对进程exit关键时间点进行画像 |
| -c, --cpuid=CPUID | 为每CPU进程设置,其他进程不需要设置该参数 |
| -r, --resource | 采集进程的资源使用情况,包括CPU利用率、内存利用率、每秒读写字节数(可持续开发) |
| -s, --syscall | 采集进程在on_CPU时间段内的系统调用序列 |
| -l, --lock | 采集进程持有的用户态锁信息,包括用户态互斥锁、用户态读写锁(可持续开发) |
| -q, --quote | 在参数周围添加引号(") |
| -K, --keytime | 对进程的关键时间点进行画像,即execve和exit |
| -m, --user-mutex | 对进程的用户态互斥锁进行画像 |
| -M, --kernel-mutex | 对进程的内核态互斥锁进行画像 |
| -r, --user-rwlock-rd | 对进程用户态读模式下的读写锁进行画像 |
| -w, --user-rwlock-wr | 对进程用户态写模式下的读写锁进行画像 |
| -L, --lock | 对进程的各种锁进行画像 |
| -f, --fork | 对fork出来的子进程进行画像 |
| -F, --vfork | 对vfork出来的子进程进行画像 |
| -T, --newthread | 对pthread_create出来的新线程进行画像 |
| -S, --child | 对新创建进程和线程进行画像 |
| -A, --all | 开启所有的功能 |
| -k, --keytime | 采集进程关键时间点的相关信息,包括execve、exit、fork、vfork、pthread_create |
| -a, --all | 启动所有的采集进程数据的功能 |
| -h, --help | 显示帮助信息 |

## 四、tools
Expand Down
132 changes: 0 additions & 132 deletions eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/developing/Makefile

This file was deleted.

This file was deleted.

Loading

0 comments on commit b4a1f19

Please sign in to comment.