summaryrefslogtreecommitdiff
path: root/internal/eventloop.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-18 08:51:33 +0200
committerPaul Buetow <paul@buetow.org>2026-03-18 08:51:33 +0200
commit6ab80599c8f8ba688a0415ecbeb03e494ef31f04 (patch)
treec0c831f29bddb1754629eb337f5ec8bc9efae983 /internal/eventloop.go
parentd8ef4ac43d3039c3d583c1ac20c7dca6b69a6c92 (diff)
refactor: replace reflect.TypeOf dispatch in exit handlers with type switch (task 432)
The exitHandlers map keyed by reflect.Type was a reflection-based dispatch table that incurred allocation and reflection overhead on every event pair in the hot processing path. Replace it with a plain type switch in handleTracepointExit, which the compiler resolves statically. Removes: initExitHandlers, typeKey, mustBeType, newTypedExitHandler, exitHandlerRegistry, the exitHandlers struct field, and the tracepointExitHandler type alias — all dead after the switch. Fixes a pre-existing uint→uint64 mismatch in stats(). Updates tests to target the new default branch directly. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'internal/eventloop.go')
-rw-r--r--internal/eventloop.go26
1 files changed, 16 insertions, 10 deletions
diff --git a/internal/eventloop.go b/internal/eventloop.go
index f15c344..b7fe230 100644
--- a/internal/eventloop.go
+++ b/internal/eventloop.go
@@ -1,10 +1,7 @@
package internal
-import "C"
-
import (
"fmt"
- "reflect"
"time"
"ior/internal/event"
@@ -38,7 +35,6 @@ type eventLoopConfig struct {
}
type rawEventHandler func(raw []byte, ch chan<- *event.Pair)
-type tracepointExitHandler func(ep *event.Pair) bool
type eventLoop struct {
filter globalfilter.Filter
@@ -51,7 +47,6 @@ type eventLoop struct {
commResolver *commResolver
prevPairTimes map[uint32]uint64 // Previous event's time (to calculate time differences between two events)
rawHandlers map[types.EventType]rawEventHandler
- exitHandlers map[reflect.Type]tracepointExitHandler
printCb func(ep *event.Pair) // Callback to print the event
warningCb func(message string) // Optional callback for non-fatal event processing warnings
cfg eventLoopConfig
@@ -86,13 +81,11 @@ func newEventLoop(cfg eventLoopConfig) (*eventLoop, error) {
commResolver: commState,
prevPairTimes: make(map[uint32]uint64),
rawHandlers: make(map[types.EventType]rawEventHandler),
- exitHandlers: make(map[reflect.Type]tracepointExitHandler),
printCb: func(ep *event.Pair) { fmt.Println(ep); ep.Recycle() },
cfg: cfg,
done: make(chan struct{}),
}
el.initRawHandlers()
- el.initExitHandlers()
el.configureOutputCallback()
el.seedTrackedPidComm()
return el, nil
@@ -167,6 +160,19 @@ func (e *eventLoop) stats() string {
<-e.done
duration := time.Since(e.startTime)
+ secs := duration.Seconds()
+ // Guard against division by zero when called immediately after start.
+ rate := func(n uint64) float64 {
+ if secs <= 0 {
+ return 0
+ }
+ return float64(n) / secs
+ }
+ mismatchPct := 0.0
+ if e.numTracepoints > 0 {
+ mismatchPct = (float64(e.numTracepointMismatches) / float64(e.numTracepoints)) * 100
+ }
+
stats := fmt.Sprintf(
"Statistics:\n"+
"\tduration: %v\n"+
@@ -174,9 +180,9 @@ func (e *eventLoop) stats() string {
"\tsyscalls: %d (%.2f/s)\n"+
"\tsyscalls after filter: %d (%.2f/s)\n",
duration,
- e.numTracepoints, float64(e.numTracepoints)/duration.Seconds(), e.numTracepointMismatches, (float64(e.numTracepointMismatches)/float64(e.numTracepoints))*100,
- e.numSyscalls, float64(e.numSyscalls)/duration.Seconds(),
- e.numSyscallsAfterFilter, float64(e.numSyscallsAfterFilter)/duration.Seconds(),
+ e.numTracepoints, rate(uint64(e.numTracepoints)), e.numTracepointMismatches, mismatchPct,
+ e.numSyscalls, rate(uint64(e.numSyscalls)),
+ e.numSyscallsAfterFilter, rate(uint64(e.numSyscallsAfterFilter)),
)
return stats