summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-02-10 20:13:40 +0200
committerPaul Buetow <paul@buetow.org>2024-02-10 20:13:40 +0200
commit8ec79e38f30738701c1ca48f5cfa724b41f866f6 (patch)
tree1b2a910c73cad82e3813b623fecdd7bdfc15569c /main.go
parent0a5b56cec0be16a6a8627ec8548b9e80a243af96 (diff)
add opids
Diffstat (limited to 'main.go')
-rw-r--r--main.go29
1 files changed, 17 insertions, 12 deletions
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():