Skip to content
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

Set stack to cache since BPF_F_REUSE_STACKID is not set by default #14

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions ebpf/event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ type eventHandler struct {
func (h *eventHandler) run(ctx context.Context) {
var event bpfEvent
// To delete stack_addresses that is not used recently.
stackIdCache := expirable.NewLRU[int32, struct{}](
stackIdCache := expirable.NewLRU[int32, []*proc.Function](
32, // cache size
func(key int32, _ struct{}) {
func(key int32, _ []*proc.Function) {
slog.Debug("delete stack_addresses", slog.Int("stack_id", int(key)))
if err := h.objs.StackAddresses.Delete(key); err != nil {
slog.Debug("Failed to delete stack_addresses", slog.Any("error", err))
Expand All @@ -46,18 +46,24 @@ func (h *eventHandler) run(ctx context.Context) {
slog.Warn("Failed to read bpf ring buffer", slog.Any("error", err))
continue
}
stack, err := h.lookupStack(ctx, event.StackId)
if err != nil {
slog.Warn(err.Error())
continue
var stack []*proc.Function
var ok bool
var err error
stack, ok = stackIdCache.Get(event.StackId)
if !ok {
stack, err = h.lookupStack(ctx, event.StackId)
if err != nil {
slog.Warn(err.Error())
continue
}
}
h.sendGoroutine(goroutine{
Id: event.GoroutineId,
ObservedAt: time.Now(),
Stack: stack,
Exit: event.Exit,
})
_ = stackIdCache.Add(event.StackId, struct{}{})
_ = stackIdCache.Add(event.StackId, stack)
}
}

Expand Down