-
-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
example: make goroutine trace example work (#95)
- Loading branch information
1 parent
7350959
commit c120bb4
Showing
7 changed files
with
110 additions
and
522 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
Oops, something went wrong.