From 63e964d2e8f81b4364fdd5fde9ffa74af9d04147 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Wed, 24 Jul 2024 13:50:57 +0200 Subject: pkg/stat: don't depend on pkg/html/pages It's useful to collect stats in low-level packages like prog, but pkg/html/pages recursively depend on prog, so currently it's impossible. Make pkg/stat not dependent on pkg/html/pages. --- pkg/stat/set.go | 92 ++++++++++++++------------------------------------------- 1 file changed, 22 insertions(+), 70 deletions(-) (limited to 'pkg/stat/set.go') diff --git a/pkg/stat/set.go b/pkg/stat/set.go index 4f8f75375..4982362d9 100644 --- a/pkg/stat/set.go +++ b/pkg/stat/set.go @@ -4,7 +4,6 @@ package stat import ( - "bytes" "fmt" "reflect" "sort" @@ -14,7 +13,6 @@ import ( "time" "github.com/VividCortex/gohistogram" - "github.com/google/syzkaller/pkg/html/pages" "github.com/prometheus/client_golang/prometheus" ) @@ -28,7 +26,7 @@ import ( // // stat.New("metric name", "metric description", LenOf(mySlice, rwMutex)) // -// Metric visualization code uses Collect/RenderHTML functions to obtain values of all registered metrics. +// Metric visualization code uses Collect/RenderGraphs functions to obtain values of all registered metrics. type UI struct { Name string @@ -47,8 +45,8 @@ func Collect(level Level) []UI { return global.Collect(level) } -func RenderHTML() ([]byte, error) { - return global.RenderHTML() +func RenderGraphs() []UIGraph { + return global.RenderGraphs() } var global = newSet(256, true) @@ -391,22 +389,24 @@ func (s *set) compress() { } } -func (s *set) RenderHTML() ([]byte, error) { +type UIGraph struct { + ID int + Title string + Stacked bool + Level Level + Lines []string + Points []UIPoint +} + +type UIPoint struct { + X int + Y []float64 +} + +func (s *set) RenderGraphs() []UIGraph { s.mu.Lock() defer s.mu.Unlock() - type Point struct { - X int - Y []float64 - } - type Graph struct { - ID int - Title string - Stacked bool - Level Level - Lines []string - Points []Point - } - var graphs []Graph + var graphs []UIGraph tick := s.historyScale * int(tickPeriod.Seconds()) for title, graph := range s.graphs { if len(graph.lines) == 0 { @@ -419,12 +419,12 @@ func (s *set) RenderHTML() ([]byte, error) { sort.Slice(lines, func(i, j int) bool { return lines[i].order < lines[j].order }) - g := Graph{ + g := UIGraph{ ID: len(graphs), Title: title, Stacked: graph.stacked, Level: graph.level, - Points: make([]Point, s.historyPos), + Points: make([]UIPoint, s.historyPos), } for i := 0; i < s.historyPos; i++ { g.Points[i].X = i * tick @@ -456,53 +456,5 @@ func (s *set) RenderHTML() ([]byte, error) { } return graphs[i].Title < graphs[j].Title }) - buf := new(bytes.Buffer) - err := htmlTemplate.Execute(buf, graphs) - return buf.Bytes(), err + return graphs } - -var htmlTemplate = pages.Create(` - - - - syzkaller stats - - - {{HEAD}} - - -{{range $g := .}} -
-{{end}} - - -`) -- cgit mrf-deployment