Skip to content

example: make goroutine trace example work #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
141 changes: 0 additions & 141 deletions src/31-goroutine/Makefile

This file was deleted.

30 changes: 28 additions & 2 deletions src/31-goroutine/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,33 @@
# goroutine trace

TODO: make this work and implement the documentation
**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.

The bundled fo program was compiled using go 1.17.0. The executable and source could be found at folder `go-server-http`.

This example traces the state switch of goroutines, and prints the corresponding state goid, pid and tgid.

```console
root@mnfe-pve:~/bpf-developer-tutorial/src/31-goroutine# ecc goroutine.bpf.c goroutine.h
INFO [ecc_rs::bpf_compiler] Compiling bpf object...
INFO [ecc_rs::bpf_compiler] Generating export types...
INFO [ecc_rs::bpf_compiler] Generating package json..
INFO [ecc_rs::bpf_compiler] Packing ebpf object and config into package.json...
root@mnfe-pve:~/bpf-developer-tutorial/src/31-goroutine# ecli-rs run package.json
INFO [faerie::elf] strtab: 0x6fb symtab 0x738 relocs 0x780 sh_offset 0x780
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
TIME STATE GOID PID TGID
INFO [bpf_loader_lib::skeleton] Running ebpf program...
21:00:47 DEAD(6) 0 2542844 2542844
21:00:47 RUNNABLE(1) 0 2542844 2542844
21:00:47 DEAD(6) 0 2542844 2542844
21:00:47 RUNNING(2) 1 2542844 2542844
21:00:47 DEAD(6) 0 2542844 2542844
21:00:47 RUNNABLE(1) 0 2542844 2542844
21:00:47 RUNNABLE(1) 1 2542844 2542844
21:00:47 RUNNING(2) 2 2542847 2542844
21:00:47 WAITING(4) 2 2542847 2542844
....
```

Modify from https://github.com/deepflowio/deepflow

This example is provided as GPL license
7 changes: 0 additions & 7 deletions src/31-goroutine/README_en.md

This file was deleted.

Binary file added src/31-goroutine/go-server-http/main
Binary file not shown.
34 changes: 34 additions & 0 deletions src/31-goroutine/go-server-http/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package main

import (
"crypto/rand"
"fmt"
"log"
"net/http"
"os"
"strconv"
)

var http_body []byte

func handler(w http.ResponseWriter, r *http.Request) {
w.Write(http_body)
}

func main() {
args := os.Args
if len(args) > 1 {
body_len, _ := strconv.ParseInt(args[1], 10, 64)
http_body = make([]byte, body_len)
rand.Read(http_body)
fmt.Println("Body set to", body_len, "bytes of random stuff")
} else {
http_body = []byte("Hello,World!")
}
http.HandleFunc("/", handler)
fmt.Println("Server started!")
err := http.ListenAndServe(":447", nil)
if err != nil {
log.Fatalf("Failed to start server: %v", err)
}
}
Loading