build: stop tracking generated tutorial artifacts (#215)

* build: stop tracking generated tutorial artifacts

* build: avoid duplicating the goroutine offset

---------

Co-authored-by: LinuxDev9002 <i@littlefisher.me>
This commit is contained in:
云微
2026-07-14 06:32:13 -07:00
committed by GitHub
parent 964b65b53d
commit 929aec4441
10 changed files with 66 additions and 102939 deletions

View File

@@ -18,6 +18,10 @@ jobs:
- uses: actions/checkout@v7
with:
submodules: 'recursive'
- uses: actions/setup-go@v6
with:
go-version: '1.17.13'
cache: false
- name: install deps
run: sudo apt install clang llvm-14-dev llvm
- name: install ecc and ecli
@@ -85,5 +89,7 @@ jobs:
sudo timeout -s 2 3 ./ecli run src/25-signal/package.json || if [ $? = 124 ]; then exit 0; else exit $?; fi
- name: test 31 goroutine
run: |
./ecc src/31-goroutine/goroutine.bpf.c src/31-goroutine/goroutine.h
# todo
make -C src/31-goroutine/go-server-http
go tool nm src/31-goroutine/go-server-http/main | \
awk '$3 == "runtime.casgstatus" { found = 1 } END { exit !found }'
./ecc src/31-goroutine/goroutine.bpf.c src/31-goroutine/goroutine.h

5
.gitignore vendored
View File

@@ -1,6 +1,9 @@
# Prerequisites
*.d
# Backup files
*.bak
# Object files
*.o
*.ko
@@ -68,4 +71,4 @@ ecli-server
ecc
ecli
.vscode/
.vscode/

View File

@@ -6,3 +6,4 @@ package.json
package.yaml
ecli
goroutine
/go-server-http/main

View File

@@ -75,21 +75,31 @@ char LICENSE[] SEC("license") = "GPL";
## Running the Program
To run this tracing program, follow these steps:
Run the following commands from `src/31-goroutine`. The eBPF program attaches to
`./go-server-http/main`, so the target binary is generated locally rather than
stored in Git. Use Go 1.17.13 to match the checked-in `GOID_OFFSET` value; verify
the offset before tracing a binary built with another Go version.
1. **Compile the eBPF Code**: Compile the eBPF program using a compiler like `ecc` (eBPF Compiler Collection) and generate a package that can be loaded by an eBPF loader.
1. **Build and start the target program**: Keep the HTTP server running, then use a second terminal for the remaining commands.
```bash
make -C go-server-http
sudo ./go-server-http/main
```
2. **Compile the eBPF Code**: Compile the eBPF program using a compiler like `ecc` (eBPF Compiler Collection) and generate a package that can be loaded by an eBPF loader.
```bash
ecc goroutine.bpf.c goroutine.h
```
2. **Run the eBPF Program**: Use an eBPF loader to run the compiled eBPF program.
3. **Run the eBPF Program**: Use an eBPF loader to run the compiled eBPF program.
```bash
ecli-rs run package.json
```
3. **Output**: The program will output the state transitions of goroutines along with their `goid`, `pid`, and `tgid`. Here’s an example of the output:
4. **Output**: The program will output the state transitions of goroutines along with their `goid`, `pid`, and `tgid`. Here’s an example of the output:
```console
TIME STATE GOID PID TGID

View File

@@ -73,21 +73,31 @@ char LICENSE[] SEC("license") = "GPL";
## 运行程序
要运行此跟踪程序,请按照以下步骤操作:
请从 `src/31-goroutine` 目录运行以下命令。eBPF 程序会附加到
`./go-server-http/main`,因此目标二进制文件应在本地生成,不再存储在 Git
中。请使用 Go 1.17.13 以匹配当前 `GOID_OFFSET`;如果使用其他 Go 版本构建,
请先重新验证该偏移量。
1. **编译 eBPF 代码**:使用类似 `ecc`(eBPF 编译集合)这样的编译器编译 eBPF 程序,并生成一个可以由 eBPF 加载器加载的包。
1. **构建并启动目标程序**:保持 HTTP 服务运行,然后在另一个终端执行后续命令。
```bash
make -C go-server-http
sudo ./go-server-http/main
```
2. **编译 eBPF 代码**:使用类似 `ecc`(eBPF 编译集合)这样的编译器编译 eBPF 程序,并生成一个可以由 eBPF 加载器加载的包。
```bash
ecc goroutine.bpf.c goroutine.h
```
2. **运行 eBPF 程序**:使用 eBPF 加载器运行编译后的 eBPF 程序。
3. **运行 eBPF 程序**:使用 eBPF 加载器运行编译后的 eBPF 程序。
```bash
ecli-rs run package.json
```
3. **输出**:程序将输出协程的状态转换及其 `goid`、`pid` 和 `tgid`。以下是一个示例输出:
4. **输出**:程序将输出协程的状态转换及其 `goid`、`pid` 和 `tgid`。以下是一个示例输出:
```console
TIME STATE GOID PID TGID

View File

@@ -0,0 +1,16 @@
GO ?= go
BINARY := main
.PHONY: all clean
all: $(BINARY)
$(BINARY): main.go
@version="$$($(GO) version)"; \
case "$$version" in \
*" go1.17."*) ;; \
*) echo "warning: the goroutine goid offset was validated with Go 1.17; verify it for $$version" >&2 ;; \
esac
$(GO) build -o $@ $<
clean:
rm -f $(BINARY)

Binary file not shown.

View File

@@ -25,6 +25,7 @@ CFLAGS := -g -Wall
ALL_LDFLAGS := $(LDFLAGS) $(EXTRA_LDFLAGS)
APPS = xdp_lb
NO_DOCKER_BPF_OBJ := no-docker/xdp_pass.o
CARGO ?= $(shell which cargo)
ifeq ($(strip $(CARGO)),)
@@ -69,12 +70,12 @@ $(call allow-override,CC,$(CROSS_COMPILE)cc)
$(call allow-override,LD,$(CROSS_COMPILE)ld)
.PHONY: all
all: $(APPS)
all: $(APPS) $(NO_DOCKER_BPF_OBJ)
.PHONY: clean
clean:
$(call msg,CLEAN)
$(Q)rm -rf $(OUTPUT) $(APPS)
$(Q)rm -rf $(OUTPUT) $(APPS) $(NO_DOCKER_BPF_OBJ)
$(OUTPUT) $(OUTPUT)/libbpf $(BPFTOOL_OUTPUT):
$(call msg,MKDIR,$@)
@@ -113,6 +114,12 @@ $(OUTPUT)/%.bpf.o: %.bpf.c $(LIBBPF_OBJ) $(wildcard %.h) $(VMLINUX) | $(OUTPUT)
-c $(filter %.c,$^) -o $(patsubst %.bpf.o,%.tmp.bpf.o,$@)
$(Q)$(BPFTOOL) gen object $@ $(patsubst %.bpf.o,%.tmp.bpf.o,$@)
$(NO_DOCKER_BPF_OBJ): no-docker/xdp_pass.c $(LIBBPF_OBJ) $(VMLINUX)
$(call msg,BPF,$@)
$(Q)$(CLANG) -O2 -target bpf -D__TARGET_ARCH_$(ARCH) \
$(INCLUDES) $(CLANG_BPF_SYS_INCLUDES) \
-c $< -o $@
# Generate BPF skeletons
$(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o | $(OUTPUT) $(BPFTOOL)
$(call msg,GEN-SKEL,$@)

File diff suppressed because it is too large Load Diff