Last active
July 9, 2021 11:33
-
-
Save grantseltzer/468471da422568cdc0647751c5c08014 to your computer and use it in GitHub Desktop.
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
package main | |
//go:noinline | |
func simpleFunction(x int) { | |
// some code | |
} | |
func main() { | |
simpleFunction(99) | |
} |
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
package main | |
import ( | |
"fmt" | |
"log" | |
"os" | |
"os/signal" | |
"github.com/iovisor/gobpf/bcc" | |
) | |
const eBPF_Program = ` | |
inline int get_arguments(struct pt_regs *ctx) { | |
void* stackAddr = (void*)ctx->sp; | |
long parameter_value; | |
bpf_probe_read(¶meter_value, sizeof(parameter_value), stackAddr+8); | |
events.perf_submit(ctx, ¶meter_value, sizeof(parameter_value)); | |
} | |
` | |
func main() { | |
bpfModule := bcc.NewModule(eBPF_Program, []string{}) | |
uprobeFd, err := bpfModule.LoadUprobe("get_arguments") | |
if err != nil { | |
log.Fatal(err) | |
} | |
err = bpfModule.AttachUprobe(os.Args[1], "main.test", uprobeFd, -1) | |
if err != nil { | |
log.Fatal(err) | |
} | |
table := bcc.NewTable(bpfModule.TableId("events"), bpfModule) | |
channel := make(chan []byte) | |
perfMap, err := bcc.InitPerfMap(table, channel) | |
if err != nil { | |
log.Fatal(err) | |
} | |
c := make(chan os.Signal, 1) | |
signal.Notify(c, os.Interrupt) | |
go func() { | |
for { | |
value := <-channel | |
fmt.Println(string(value)) | |
} | |
}() | |
perfMap.Start() | |
<-c | |
perfMap.Stop() | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment