From 1eeae89f5b1fcff41694b311fe699a65788cef6b Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 10 Apr 2025 22:30:16 +0300 Subject: can generate flamegraphs --- internal/flamegraph/counter.go | 21 +++++++++++++++++++++ internal/flamegraph/iordata.go | 10 +--------- 2 files changed, 22 insertions(+), 9 deletions(-) (limited to 'internal/flamegraph') diff --git a/internal/flamegraph/counter.go b/internal/flamegraph/counter.go index 96cfe06..6105136 100644 --- a/internal/flamegraph/counter.go +++ b/internal/flamegraph/counter.go @@ -1,5 +1,9 @@ package flamegraph +import ( + "fmt" +) + type Counter struct { Count uint64 Duration uint64 @@ -12,5 +16,22 @@ func (c Counter) add(other Counter) Counter { c.Duration += other.Duration c.DurationToPrev += other.DurationToPrev c.Bytes += other.Bytes + return c } + +func (c Counter) ValueByName(name string) uint64 { + // Convert the numbers to strings here + switch name { + case "count": + return c.Count + case "duration": + return c.Duration + case "durationToPrev": + return c.DurationToPrev + case "bytes": + return c.Bytes + default: + panic(fmt.Sprintln("No", name, "in count record")) + } +} diff --git a/internal/flamegraph/iordata.go b/internal/flamegraph/iordata.go index 6974329..cef01ff 100644 --- a/internal/flamegraph/iordata.go +++ b/internal/flamegraph/iordata.go @@ -198,7 +198,7 @@ type iterRecord struct { func (ir iterRecord) StringByName(name string) string { switch name { case "path": - return ir.path + return strings.Join(strings.Split(ir.path, "/"), ";/") case "comm": return ir.comm case "tracepoint": @@ -209,14 +209,6 @@ func (ir iterRecord) StringByName(name string) string { return fmt.Sprint(ir.tid) case "flags": return ir.flags.String() - case "count": - return fmt.Sprint(ir.cnt.Count) - case "duration": - return fmt.Sprint(ir.cnt.Duration) - case "durationToPrev": - return fmt.Sprint(ir.cnt.DurationToPrev) - case "bytes": - return fmt.Sprint(ir.cnt.Bytes) default: panic(fmt.Sprintln("No", name, "in record")) } -- cgit v1.2.3