diff options
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/eventloop.go | 7 | ||||
| -rw-r--r-- | internal/flamegraph/flamegraph.go | 5 |
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 { |
