diff --git a/pkg/web/web.go b/pkg/web/web.go index 320f11b..477577d 100644 --- a/pkg/web/web.go +++ b/pkg/web/web.go @@ -21,6 +21,7 @@ import ( "fmt" "image/color" "io" + "sort" "strings" "text/template" "time" @@ -35,38 +36,66 @@ var ganttTemplate = ` -

SlowJam for {{ .Duration}} ({{ .TL.Samples }} samples) - full | simple

-
+

SlowJam for {{ .Duration}} ({{ .TL.Samples }} samples, {{ len .TL.Goroutines }} goroutines) - full | simple

+
+
+
+
` @@ -80,6 +109,7 @@ func Render(w io.Writer, tl *stackparse.Timeline) error { "Creator": creator, "Height": height, "Color": callColor, + "Sorted": sorted, } t, err := template.New("timeline").Funcs(fmap).Parse(ganttTemplate) @@ -107,6 +137,21 @@ func milliseconds(d time.Duration) string { return fmt.Sprintf("%d", d.Milliseconds()) } +func sorted(grs map[int]*stackparse.GoroutineTimeline) []*stackparse.GoroutineTimeline { + rt := []*stackparse.GoroutineTimeline{} + ids := []int{} + for id := range grs { + ids = append(ids, id) + } + sort.Ints(ids) + for _, id := range ids { + if gr := grs[id]; gr != nil { + rt = append(rt, gr) + } + } + return rt +} + func creator(s *stack.Signature) string { c := s.CreatedBy.Func.PkgDotName() if c == "" {