summaryrefslogtreecommitdiff
path: root/internal/flamegraph/worker.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-03-18 22:25:27 +0200
committerPaul Buetow <paul@buetow.org>2025-03-18 22:25:27 +0200
commit6010e057e2d0593a6c6b50f4c7aee301a86a478a (patch)
treee8018323e426477fb41e938538f25c4e7df4fce3 /internal/flamegraph/worker.go
parent000891ad475c89d88874d4290728857ecbe53a7d (diff)
workers are parallelized now
Diffstat (limited to 'internal/flamegraph/worker.go')
-rw-r--r--internal/flamegraph/worker.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/internal/flamegraph/worker.go b/internal/flamegraph/worker.go
new file mode 100644
index 0000000..e590163
--- /dev/null
+++ b/internal/flamegraph/worker.go
@@ -0,0 +1,52 @@
+package flamegraph
+
+import (
+ "context"
+ "ior/internal/event"
+ "ior/internal/types"
+ "sync"
+ "time"
+)
+
+type worker struct {
+ collapsed collapsed
+ done chan struct{}
+}
+
+func newWorker() worker {
+ return worker{collapsed: make(collapsed)}
+}
+
+// Run until ch is closed or has no more events and ctx is done.
+func (w worker) run(ctx context.Context, wg *sync.WaitGroup, ch <-chan *event.Pair) {
+ defer wg.Done()
+
+ for {
+ select {
+ case ev := <-ch:
+ filePath := ev.File.Name()
+ pathMap, ok := w.collapsed[filePath]
+ if !ok {
+ pathMap = make(map[types.TraceId]counter)
+ }
+
+ traceId := ev.EnterEv.GetTraceId()
+ cnt := pathMap[traceId]
+ cnt.count++
+ cnt.duration += ev.Duration
+ pathMap[traceId] = cnt
+
+ w.collapsed[filePath] = pathMap
+ // TODO: Enable Go race detector
+ ev.Recycle()
+
+ default:
+ select {
+ case <-ctx.Done():
+ return
+ default:
+ time.Sleep(time.Millisecond * 10)
+ }
+ }
+ }
+}