Created
May 11, 2020 18:58
-
-
Save grantseltzer/76468d7e9ab4644170d15d1a4ae39d99 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 parseMe(a int, b bool, c float32) { | |
// some code | |
} | |
func main() { | |
parseMe(1, true, 96.69) | |
} |
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 = ` | |
#include <uapi/linux/ptrace.h> | |
BPF_PERF_OUTPUT(events); | |
inline int get_arguments(struct pt_regs *ctx) { | |
void* stackAddr = (void*)ctx->sp; | |
long argument1; | |
bpf_probe_read(&argument1, sizeof(argument1), stackAddr+8); | |
events.perf_submit(ctx, &argument1, sizeof(argument1)); | |
char argument2; | |
bpf_probe_read(&argument2, sizeof(argument2), stackAddr+16); | |
events.perf_submit(ctx, &argument2, sizeof(argument2)); | |
float argument3; | |
bpf_probe_read(&argument3, sizeof(argument3), stackAddr+17); | |
events.perf_submit(ctx, &argument3, sizeof(argument3)); | |
} | |
` | |
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.parseMe", 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
This code doesn't seem to work for getting the parameters in the method. Do you know where do I get the parameters in a method?