diff options
| author | Paul Buetow <paul@buetow.org> | 2024-02-15 10:40:15 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-02-16 00:23:24 +0200 |
| commit | cb70df2d4b17dd3d54d89a46e3aee22f3c131854 (patch) | |
| tree | 3c7210a4090139e9045a85bf73322b5002d1f573 /internal/ioriotng.go | |
| parent | 6d2ae77ccb31844c6c366911ee1b4bc43bd691f6 (diff) | |
switch from perf maps to ring buffer
Diffstat (limited to 'internal/ioriotng.go')
| -rw-r--r-- | internal/ioriotng.go | 57 |
1 files changed, 36 insertions, 21 deletions
diff --git a/internal/ioriotng.go b/internal/ioriotng.go index d840ea5..f368c09 100644 --- a/internal/ioriotng.go +++ b/internal/ioriotng.go @@ -6,15 +6,12 @@ import ( "bytes" "context" "encoding/binary" - "fmt" "log" "runtime" - "sync" "ioriotng/internal/debugfs" "ioriotng/internal/flags" "ioriotng/internal/tracepoints" - "ioriotng/internal/types" bpf "github.com/aquasecurity/libbpfgo" ) @@ -50,25 +47,43 @@ func Run(flags flags.Flags) { log.Fatal(err) } - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - var wg sync.WaitGroup - wg.Add(2) + ch := make(chan []byte) + rb, err := bpfModule.InitRingBuf("event_map", ch) + if err != nil { + log.Fatal(err) + } + rb.Poll(300) - go func() { - defer wg.Done() - for ev := range listenToEvents[types.FdEvent](ctx, bpfModule, "fd_event_map") { - fmt.Println(ev) - } - }() - go func() { - defer wg.Done() - for ev := range listenToEvents[types.OpenEvent](ctx, bpfModule, "open_event_map") { - fmt.Println(ev) - } - }() + for b := range ch { + /* + if binary.LittleEndian.Uint32(b) != 2021 { + log.Fatal("invalid data retrieved", len(b), b) + } + */ + log.Println("Ringbuf data received", len(b), b) + } + + /* + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + var wg sync.WaitGroup + wg.Add(2) + + go func() { + defer wg.Done() + for ev := range listenToEvents[types.FdEvent](ctx, bpfModule, "fd_event_map") { + fmt.Println(ev) + } + }() + go func() { + defer wg.Done() + for ev := range listenToEvents[types.OpenEvent](ctx, bpfModule, "open_event_map") { + fmt.Println(ev) + } + }() - wg.Wait() + wg.Wait() + */ log.Println("Good bye") } @@ -77,7 +92,7 @@ func listenToEvents[T BpfMapper](ctx context.Context, bpfModule *bpf.Module, map rawLostCh := make(chan uint64) // TODO: Of any use this channel? eventsCh := make(chan T) - pb, err := bpfModule.InitPerfBuf(mapName, rawEventsCh, rawLostCh, 4096) + pb, err := bpfModule.InitPerfBuf(mapName, rawEventsCh, rawLostCh, 1024) if err != nil { log.Fatal(err) } |
