diff options
| author | Paul Buetow <paul@buetow.org> | 2025-03-29 11:25:27 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-03-29 11:25:27 +0200 |
| commit | 8a34be1f4fffca90d74e2092c7bc5a6af02392c4 (patch) | |
| tree | f003dc1b8d95a31bf8d01c786e98a5a622ac43cd /internal/flamegraph/worker.go | |
| parent | 5f1b3be8ac4013ac7cf5041de339317defeb75ce (diff) | |
fix
Diffstat (limited to 'internal/flamegraph/worker.go')
| -rw-r--r-- | internal/flamegraph/worker.go | 71 |
1 files changed, 49 insertions, 22 deletions
diff --git a/internal/flamegraph/worker.go b/internal/flamegraph/worker.go index d10e0bf..6c2b9cd 100644 --- a/internal/flamegraph/worker.go +++ b/internal/flamegraph/worker.go @@ -10,42 +10,29 @@ import ( type worker struct { collapsed collapsed - id iorData + iod iorData done chan struct{} } func newWorker() worker { return worker{ - collapsed: make(collapsed), // TODO: Retire - id: newIorData(), // TODO: Implement fully + collapsed: make(collapsed), // COLLAPSED: Retire ocne newIorData implemented + iod: newIorData(), } } -// 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: - var filePath string - if ev.File == nil { - filePath = "N:file" - } else { - 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 + // var filePath string + // if ev.File == nil { + // filePath = "N:file" + // } else { + // filePath = ev.File.Name() + // } ev.Recycle() default: @@ -58,3 +45,43 @@ func (w worker) run(ctx context.Context, wg *sync.WaitGroup, ch <-chan *event.Pa } } } + +// TODO: Retire collapsed +func (w worker) runCollapsed(ctx context.Context, wg *sync.WaitGroup, ch <-chan *event.Pair) { + { + defer wg.Done() + + for { + select { + case ev := <-ch: + var filePath string + if ev.File == nil { + filePath = "N:file" + } else { + filePath = ev.File.Name() + } + pathMap, ok := w.collapsed[filePath] + if !ok { + pathMap = make(map[types.TraceId]collapsedCounter) + } + + traceId := ev.EnterEv.GetTraceId() + cnt := pathMap[traceId] + cnt.count++ + cnt.duration += ev.Duration + pathMap[traceId] = cnt + + w.collapsed[filePath] = pathMap + ev.Recycle() + + default: + select { + case <-ctx.Done(): + return + default: + time.Sleep(time.Millisecond * 10) + } + } + } + } +} |
