diff options
| author | Paul Buetow <paul@buetow.org> | 2025-03-15 00:02:52 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-03-15 00:02:52 +0200 |
| commit | 191a8716a52a761f38550d4e58b14b9f5594d8ae (patch) | |
| tree | 46a2d5ec70b42e9698d1ef8948cb272a6f69e91d /internal/flamegraph | |
| parent | b3bbc7ae0ea6747686626d26d0e5484ed06f49fe (diff) | |
jo:x
Diffstat (limited to 'internal/flamegraph')
| -rw-r--r-- | internal/flamegraph/flamegraph.go | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/internal/flamegraph/flamegraph.go b/internal/flamegraph/flamegraph.go index dc1af53..5e808b3 100644 --- a/internal/flamegraph/flamegraph.go +++ b/internal/flamegraph/flamegraph.go @@ -16,19 +16,20 @@ type counter struct { duration uint64 } +// TODO: Add Command in path! Make it configurable? comm/syscall/path, or path/syscall/comm, etc... // TODO: Idea, show time spent between the syscalls (off syscalls) as well, but in a different color // TODO: Profile for CPU usage. If too slow, can fan out into multiple maps and // then merge at the end the maps. type Flamegraph struct { collapsed map[string]map[types.TraceId]counter - inCh chan *event.Pair + Ch chan *event.Pair Done chan struct{} } func New() Flamegraph { return Flamegraph{ collapsed: make(map[string]map[types.TraceId]counter), - inCh: make(chan *event.Pair, 4096), + Ch: make(chan *event.Pair, 4096), Done: make(chan struct{}), } } @@ -37,8 +38,7 @@ func (f Flamegraph) Start(ctx context.Context) { go func() { for { select { - case ev := <-f.inCh: - // filePath := path.Dir(ev.File.Name()) + case ev := <-f.Ch: filePath := ev.File.Name() pathMap, ok := f.collapsed[filePath] if !ok { @@ -59,7 +59,7 @@ func (f Flamegraph) Start(ctx context.Context) { case <-ctx.Done(): defer close(f.Done) fmt.Println("Flamegraph processed last event") - f.dump() + f.dumpCollapsed() return default: time.Sleep(time.Millisecond * 10) @@ -69,11 +69,7 @@ func (f Flamegraph) Start(ctx context.Context) { }() } -func (f Flamegraph) Add(ev *event.Pair) { - f.inCh <- ev -} - -func (f Flamegraph) dump() { +func (f Flamegraph) dumpCollapsed() { var wg sync.WaitGroup wg.Add(4) |
