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 | |
| parent | b3bbc7ae0ea6747686626d26d0e5484ed06f49fe (diff) | |
jo:x
| -rw-r--r-- | TODO.md | 6 | ||||
| -rw-r--r-- | internal/event/event.go | 1 | ||||
| -rw-r--r-- | internal/eventloop.go | 2 | ||||
| -rw-r--r-- | internal/flamegraph/flamegraph.go | 16 |
4 files changed, 9 insertions, 16 deletions
@@ -2,18 +2,14 @@ * Target OS is Rocky 9 and not Rocky 8 (can use a bhyve VM) * More filters - * By directory - * By directory sub-match - * By regex match of whole path * By syscall -* Output format so that it is compatible with the flamegraph grapher * Capture more tracepoints? See comments in tracepoints.c's header. * Automatic testing (integration tests) * Performance benchmark... ## FlameGraphs -What format? What to visualize on the stack axis? +More ideas ``` user;cmd_name;pid;tid;syscall_name count diff --git a/internal/event/event.go b/internal/event/event.go index 680ee62..9118f65 100644 --- a/internal/event/event.go +++ b/internal/event/event.go @@ -13,6 +13,7 @@ var poolOfEventPairs = sync.Pool{ New: func() interface{} { return &Pair{} }, } +// TODO: A way to get the open flags? Trace them as well? sync vs non-sync? type Event interface { String() string GetTraceId() TraceId diff --git a/internal/eventloop.go b/internal/eventloop.go index 11a184d..3963cf6 100644 --- a/internal/eventloop.go +++ b/internal/eventloop.go @@ -75,7 +75,7 @@ func (e *eventLoop) run(ctx context.Context, rawCh <-chan []byte) { for ev := range e.events(ctx, rawCh) { switch { case e.flags.FlamegraphEnable: - e.flamegraph.Add(ev) + e.flamegraph.Ch <- ev case e.flags.PprofEnable: ev.RecyclePrev() default: 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) |
