-
Notifications
You must be signed in to change notification settings - Fork 651
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
Add a tracepoint example and a percpu example #402
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is adding a full example to demonstrate per-CPU maps the best way to go? There is a lot of code here that has nothing to do with per-CPU maps which the user has to ignore.
There is already an example of per CPU map usage here: https://pkg.go.dev/github.com/cilium/ebpf#example-Map-PerCPU How can we make that more discoverable? Maybe you saw it but it didn't help?
examples/.gitignore
Outdated
@@ -0,0 +1,3 @@ | |||
*.o |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we gitignore the artefacts it's not possible to go install
or go run
the examples, which I think is kind of neat.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing out this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lmb Hi, after thinking carefully, I still think we should ignore all these intermediate files and instruct users on how to compile and build step by step. After all, go run -exec sudo
hides many details.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lmb hello 😃
examples/README.md
Outdated
@@ -12,3 +12,12 @@ | |||
cd ebpf/examples/ | |||
go run -exec sudo [./kprobe, ./uretprobe, ./tracepoint, ...] | |||
``` | |||
|
|||
## How to compile |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This kind of duplicates the section above, is it necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I will merge them.
examples/kprobe_percpu/main.go
Outdated
// +build linux | ||
|
||
// This program demonstrates attaching an eBPF program to a kernel symbol. | ||
// The eBPF program will be attached to the start of the sys_execve |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mention the use of a per CPU map instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😅 I overlooked these lines.
Yes. This example uses pure Go to manipulate the percpu map, but I think a C example is also necessary for users who want to put the main logic in C files. |
849de67
to
9a36214
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some small stuff, but otherwise I think this is good to merge. The percpu example is more verbose than I'd like, but we can fix that in a follow up.
d7077eb
to
9dde01c
Compare
This name should be more distinguishable. Signed-off-by: Hao Lee <haolee@didiglobal.com>
This example uses C language to implement the handler, which should be more straightforward than the existing pure-go implementation. Signed-off-by: Hao Lee <haolee@didiglobal.com>
Signed-off-by: Hao Lee <haolee@didiglobal.com>
😅 Thanks! |
No description provided.