summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-03-14 22:58:10 +0200
committerPaul Buetow <paul@buetow.org>2025-03-14 22:58:10 +0200
commit3edde70ef17d23a3f2fcb0fac11a50e8810ab943 (patch)
tree677a865082872147ebf75426f2192d1ac2ff2f6a /internal
parent1827045051c46db54662e1b4b710504da438f1d1 (diff)
fixed a bug with the filepath
Diffstat (limited to 'internal')
-rw-r--r--internal/eventloop.go7
-rw-r--r--internal/flamegraph/flamegraph.go5
2 files changed, 11 insertions, 1 deletions
diff --git a/internal/eventloop.go b/internal/eventloop.go
index fca5958..1e7fea6 100644
--- a/internal/eventloop.go
+++ b/internal/eventloop.go
@@ -3,6 +3,7 @@ package internal
import "C"
import (
+ "bytes"
"context"
"fmt"
"os"
@@ -178,7 +179,11 @@ func (e *eventLoop) syscallExit(exitEv event.Event, ch chan<- *event.Pair) {
openEv := ev.EnterEv.(*OpenEvent)
fd := int32(ev.ExitEv.(*RetEvent).Ret)
- file := file.NewFd(fd, string(openEv.Filename[:]))
+ // It's from an array, so only create string from array until first 0 byte
+ // TODO: This could speed up the path filter as well
+ // TODO: Hopefully, this won't cause a panic when the filename is as long as the array itself
+ filePath := string(openEv.Filename[:bytes.IndexByte(openEv.Filename[:], 0)])
+ file := file.NewFd(fd, filePath)
if fd >= 0 {
e.files[fd] = file
}
diff --git a/internal/flamegraph/flamegraph.go b/internal/flamegraph/flamegraph.go
index c543320..9e15889 100644
--- a/internal/flamegraph/flamegraph.go
+++ b/internal/flamegraph/flamegraph.go
@@ -18,6 +18,8 @@ type counter struct {
// 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 {
+ // TODO: Keep al lthe individual files at the leaf in a map as well.
+ // And when dumped, only dump the N "highest" and summarize the other ones.
collapsed map[string]map[types.TraceId]counter
inCh chan *event.Pair
Done chan struct{}
@@ -36,6 +38,7 @@ func (f Flamegraph) Start(ctx context.Context) {
for {
select {
case ev := <-f.inCh:
+ // filePath := path.Dir(ev.File.Name())
filePath := ev.File.Name()
pathMap, ok := f.collapsed[filePath]
if !ok {
@@ -50,6 +53,7 @@ func (f Flamegraph) Start(ctx context.Context) {
f.collapsed[filePath] = pathMap
ev.RecyclePrev()
+
default:
select {
case <-ctx.Done():
@@ -101,6 +105,7 @@ func (f Flamegraph) dumpBy(outfile string, syscallAtTop bool, by func(counter) u
sb.WriteString("/")
}
sb.WriteString(part)
+ fmt.Println("DEBUG part", i, part, len(part))
}
for traceId, cnt := range value {