-
Notifications
You must be signed in to change notification settings - Fork 670
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
example: demonstrate tracepoint usage #190
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.
LGTM, should we remove the other example?
example_tracepoint_test.go
Outdated
panic(fmt.Errorf("failed to attach eBPF to tracepoint: %v", err)) | ||
} | ||
|
||
<-ctx.Done() |
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.
Does the program ever print any output? Since the goroutine is locked to the thread, nothing else can run on it and invoke open, right?
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.
yes - right. It's the very same output/setup as in example_program_test.go
before.
example_tracepoint_test.go
Outdated
"github.com/cilium/ebpf/asm" | ||
ringbuffer "github.com/cilium/ebpf/perf" | ||
|
||
"github.com/elastic/go-perf" |
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 guess this means the package will be included in the go.mod? Probably acceptable.
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.
yes. It adds github.com/elastic/go-perf
in go.mod
. Added this as well now.
dd0d9cf
to
df7b9a7
Compare
Sorry for the long radio silence! I've discovered one unfortunate side-effect: |
Good poind :+1 https://blog.golang.org/examples states that examples are executed as part of |
ok - I checked |
I think that would be very sad :( Maybe golang/go#36460 will help, do you mind if we keep this open until 1.16 lands and we try again, with an updated go.mod? The alternative would be to set up an examples repository. |
Keeping the PR open for the moment is fine for me :) |
@florianl I had an idea: maybe we can use a sub-Go-Module in an examples folder? That would have its own go.mod / go.sum so it wouldn't pollute the main module IIUC. |
df7b9a7
to
5d66b59
Compare
Good idea 👍 |
One of the downsides of the nested module is that we have to manually bump the Another downside is that invoking Finally, I think it should be convention that WDYT? |
cc @ti-mo I think you had ideas for examples as well? |
e4437a2
to
6610ed0
Compare
5915a41
to
20cfa81
Compare
Signed-off-by: Florian Lehner <dev@der-flo.net>
20cfa81
to
a8dbc7a
Compare
a8dbc7a
to
a8964d2
Compare
Sorry, missed this cc. This submodule thing actually looks like it could be a good approach for including (both userspace and kernelspace) samples in the lib without polluting the main |
panic(fmt.Errorf("failed to restore original rlimit: %v", err)) | ||
} | ||
|
||
runtime.LockOSThread() |
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.
Since this is a sample, documenting why we need to lock an OS thread would be nice. Is this required?
Signed-off-by: Florian Lehner dev@der-flo.net
This PR adds an example on how a third party package can be used to attach an eBPF program to a tracepoint.