summaryrefslogtreecommitdiff
path: root/internal/eventloop.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-03-18 22:46:36 +0200
committerPaul Buetow <paul@buetow.org>2025-03-18 22:46:36 +0200
commit20d955d01b8f3de554a53539a86a8add8d39091b (patch)
treee194dddddb76893856cc433ccbff97d0babb88ec /internal/eventloop.go
parentdbcd2f6dc2a4b842ebcfa5dbfc7990befa27267c (diff)
fix data race
Diffstat (limited to 'internal/eventloop.go')
-rw-r--r--internal/eventloop.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/internal/eventloop.go b/internal/eventloop.go
index 2c1607b..ff00671 100644
--- a/internal/eventloop.go
+++ b/internal/eventloop.go
@@ -31,6 +31,7 @@ type eventLoop struct {
numSyscalls uint
numSyscallsAfterFilter uint
startTime time.Time
+ done chan struct{}
}
func newEventLoop(flags flags.Flags) *eventLoop {
@@ -42,11 +43,13 @@ func newEventLoop(flags flags.Flags) *eventLoop {
comms: make(map[uint32]string),
prevPairs: make(map[uint32]*event.Pair),
flamegraph: flamegraph.New(),
+ done: make(chan struct{}),
}
}
// TODO: Could use the table from the gos project to display the stats here
func (e *eventLoop) stats() string {
+ <-e.done
duration := time.Since(e.startTime)
return "Statistics:\n" +
@@ -59,6 +62,8 @@ func (e *eventLoop) stats() string {
}
func (e *eventLoop) run(ctx context.Context, rawCh <-chan []byte) {
+ defer close(e.done)
+
if e.flags.FlamegraphEnable {
fmt.Println("Collecting flame graph stats, press Ctrl+C to stop")
e.flamegraph.Start(ctx)
@@ -95,6 +100,7 @@ func (e *eventLoop) events(ctx context.Context, rawCh <-chan []byte) <-chan *eve
go func() {
defer close(ch)
+
for raw := range rawCh {
select {
case <-ctx.Done():