Skip to content

Commit c120bb4

Browse files
authored
example: make goroutine trace example work (#95)
1 parent 7350959 commit c120bb4

File tree

7 files changed

+110
-522
lines changed

7 files changed

+110
-522
lines changed

src/31-goroutine/Makefile

-141
This file was deleted.

src/31-goroutine/README.md

+28-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,33 @@
11
# goroutine trace
22

3-
TODO: make this work and implement the documentation
3+
**UNFINISHED YET**: The offset of goid field is hardcoded. It was only tested on the bundled `go-server-http`. It MAY NOT WORK on other go programs.
4+
5+
The bundled fo program was compiled using go 1.17.0. The executable and source could be found at folder `go-server-http`.
6+
7+
This example traces the state switch of goroutines, and prints the corresponding state, goid, pid and tgid.
8+
9+
```console
10+
root@mnfe-pve:~/bpf-developer-tutorial/src/31-goroutine# ecc goroutine.bpf.c goroutine.h
11+
INFO [ecc_rs::bpf_compiler] Compiling bpf object...
12+
INFO [ecc_rs::bpf_compiler] Generating export types...
13+
INFO [ecc_rs::bpf_compiler] Generating package json..
14+
INFO [ecc_rs::bpf_compiler] Packing ebpf object and config into package.json...
15+
root@mnfe-pve:~/bpf-developer-tutorial/src/31-goroutine# ecli-rs run package.json
16+
INFO [faerie::elf] strtab: 0x6fb symtab 0x738 relocs 0x780 sh_offset 0x780
17+
INFO [bpf_loader_lib::skeleton::preload::section_loader] User didn't specify custom value for variable __eunomia_dummy_goroutine_execute_data_ptr, use the default one in ELF
18+
TIME STATE GOID PID TGID
19+
INFO [bpf_loader_lib::skeleton] Running ebpf program...
20+
21:00:47 DEAD(6) 0 2542844 2542844
21+
21:00:47 RUNNABLE(1) 0 2542844 2542844
22+
21:00:47 DEAD(6) 0 2542844 2542844
23+
21:00:47 RUNNING(2) 1 2542844 2542844
24+
21:00:47 DEAD(6) 0 2542844 2542844
25+
21:00:47 RUNNABLE(1) 0 2542844 2542844
26+
21:00:47 RUNNABLE(1) 1 2542844 2542844
27+
21:00:47 RUNNING(2) 2 2542847 2542844
28+
21:00:47 WAITING(4) 2 2542847 2542844
29+
....
30+
```
431

5-
Modify from https://github.com/deepflowio/deepflow
632

733
This example is provided as GPL license

src/31-goroutine/README_en.md

-7
This file was deleted.

src/31-goroutine/go-server-http/main

5.83 MB
Binary file not shown.
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package main
2+
3+
import (
4+
"crypto/rand"
5+
"fmt"
6+
"log"
7+
"net/http"
8+
"os"
9+
"strconv"
10+
)
11+
12+
var http_body []byte
13+
14+
func handler(w http.ResponseWriter, r *http.Request) {
15+
w.Write(http_body)
16+
}
17+
18+
func main() {
19+
args := os.Args
20+
if len(args) > 1 {
21+
body_len, _ := strconv.ParseInt(args[1], 10, 64)
22+
http_body = make([]byte, body_len)
23+
rand.Read(http_body)
24+
fmt.Println("Body set to", body_len, "bytes of random stuff")
25+
} else {
26+
http_body = []byte("Hello,World!")
27+
}
28+
http.HandleFunc("/", handler)
29+
fmt.Println("Server started!")
30+
err := http.ListenAndServe(":447", nil)
31+
if err != nil {
32+
log.Fatalf("Failed to start server: %v", err)
33+
}
34+
}

0 commit comments

Comments
 (0)