From 8ec79e38f30738701c1ca48f5cfa724b41f866f6 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 10 Feb 2024 20:13:40 +0200 Subject: add opids --- main.go | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 48e4f95..941af2f 100644 --- a/main.go +++ b/main.go @@ -21,28 +21,28 @@ type BpfMapper interface { } type openEvent struct { - FD int32 - SyscallID int32 - TID uint32 - Filename [256]byte - Comm [16]byte + FD int32 + OpID int32 + TID uint32 + Filename [256]byte + Comm [16]byte } func (e openEvent) String() string { filename := e.Filename[:] comm := e.Comm[:] - return fmt.Sprintf("syscall:%d tid:%v fd:%v filename:%s, comm:%s", - e.SyscallID, e.TID, e.FD, string(filename), string(comm)) + return fmt.Sprintf("opId:%d tid:%v fd:%v filename:%s, comm:%s", + e.OpID, e.TID, e.FD, string(filename), string(comm)) } type fdEvent struct { - FD int32 - SyscallID int32 - TID uint32 + FD int32 + OpID int32 + TID uint32 } func (e fdEvent) String() string { - return fmt.Sprintf("syscall:%d tid:%v fd:%v", e.SyscallID, e.TID, e.FD) + return fmt.Sprintf("opId:%d tid:%v fd:%v", e.OpID, e.TID, e.FD) } func resizeMap(module *bpf.Module, name string, size uint32) error { @@ -69,10 +69,15 @@ func main() { } defer bpfModule.Close() + // Todo, could build a eventListener struct, which is generic. if err = resizeMap(bpfModule, "open_event_map", 8192*10); err != nil { log.Fatal(err) } + if err = resizeMap(bpfModule, "fd_event_map", 8192*10); err != nil { + log.Fatal(err) + } + err = bpfModule.BPFLoadObject() if err != nil { log.Fatal(err) @@ -115,7 +120,6 @@ func listenToEvents[T BpfMapper](ctx context.Context, bpfModule *bpf.Module, map eventsCh := make(chan T) pb, err := bpfModule.InitPerfBuf(mapName, rawEventsCh, rawLostCh, 1) - pb.Poll(pollSize) if err != nil { log.Fatal(err) } @@ -126,6 +130,7 @@ func listenToEvents[T BpfMapper](ctx context.Context, bpfModule *bpf.Module, map pb.Close() close(eventsCh) }() + pb.Poll(pollSize) for { select { case <-ctx.Done(): -- cgit v1.2.3