aboutsummaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2024-11-07 16:01:06 +0100
committerDmitry Vyukov <dvyukov@google.com>2024-11-08 14:15:20 +0000
commit44b1e39faee03d3a5f496f66157a41f939e74286 (patch)
tree63c2bda8f4454ffb11a23c5cbdc6e8f8ba01ffc3 /pkg
parent0e6221e714759ad3d12fb1a94b62c5c607a4dbab (diff)
pkg/manager: wrap stats page with the common header
Add common manager HTML header to the stats page as well.
Diffstat (limited to 'pkg')
-rw-r--r--pkg/html/pages/stats.go89
-rw-r--r--pkg/html/pages/stats_test.go7
-rw-r--r--pkg/manager/http.go13
3 files changed, 63 insertions, 46 deletions
diff --git a/pkg/html/pages/stats.go b/pkg/html/pages/stats.go
index 2682d28e9..3bc60cc5d 100644
--- a/pkg/html/pages/stats.go
+++ b/pkg/html/pages/stats.go
@@ -3,48 +3,57 @@
package pages
-var StatsTemplate = Create(`
-<!doctype html>
-<html>
-<head>
- <title>syzkaller stats</title>
- <script type="text/javascript" src="https://www.google.com/jsapi"></script>
- <script type="text/javascript">
- google.load("visualization", "1", {packages:["corechart"]});
- google.setOnLoadCallback(function() {
- {{range $g := .}}
- new google.visualization. {{if $g.Stacked}} AreaChart {{else}} LineChart {{end}} (
- document.getElementById('div_{{$g.ID}}')).
- draw(google.visualization.arrayToDataTable([
- ["-" {{range $line := $g.Lines}} , '{{$line}}' {{end}}],
- {{range $p := $g.Points}} [ {{$p.X}} {{range $y := $p.Y}} , {{$y}} {{end}} ], {{end}}
- ]), {
- title: '{{$g.Title}}',
- titlePosition: 'in',
- width: "95%",
- height: "400",
- chartArea: {width: '95%', height: '85%'},
- legend: {position: 'in'},
- lineWidth: 2,
- focusTarget: "category",
- {{if $g.Stacked}} isStacked: true, {{end}}
- vAxis: {minValue: 1, textPosition: 'in', gridlines: {multiple: 1}, minorGridlines: {multiple: 1}},
- hAxis: {minValue: 1, textPosition: 'out', maxAlternation: 1, gridlines: {multiple: 1},
- minorGridlines: {multiple: 1}},
- })
- {{end}}
+import (
+ "bytes"
+ "fmt"
+ "html/template"
+
+ "github.com/google/syzkaller/pkg/stat"
+)
+
+func StatsHTML() (template.HTML, error) {
+ buf := new(bytes.Buffer)
+ data := stat.RenderGraphs()
+ if err := statsTemplate.Execute(buf, data); err != nil {
+ return "", fmt.Errorf("failed to execute stats template: %w", err)
+ }
+ return template.HTML(buf.String()), nil
+}
+
+var statsTemplate = Create(`
+<script type="text/javascript" src="https://www.google.com/jsapi"></script>
+<script type="text/javascript">
+ google.load("visualization", "1", {packages:["corechart"]});
+ google.setOnLoadCallback(function() {
+ {{range $g := .}}
+ new google.visualization. {{if $g.Stacked}} AreaChart {{else}} LineChart {{end}} (
+ document.getElementById('div_{{$g.ID}}')).
+ draw(google.visualization.arrayToDataTable([
+ ["-" {{range $line := $g.Lines}} , '{{$line}}' {{end}}],
+ {{range $p := $g.Points}} [ {{$p.X}} {{range $y := $p.Y}} , {{$y}} {{end}} ], {{end}}
+ ]), {
+ title: '{{$g.Title}}',
+ titlePosition: 'in',
+ width: "95%",
+ height: "400",
+ chartArea: {width: '95%', height: '85%'},
+ legend: {position: 'in'},
+ lineWidth: 2,
+ focusTarget: "category",
+ {{if $g.Stacked}} isStacked: true, {{end}}
+ vAxis: {minValue: 1, textPosition: 'in', gridlines: {multiple: 1}, minorGridlines: {multiple: 1}},
+ hAxis: {minValue: 1, textPosition: 'out', maxAlternation: 1, gridlines: {multiple: 1},
+ minorGridlines: {multiple: 1}},
+ })
+ {{end}}
+
+ {{/* Preserve vertical scroll position after page reloads. Otherwise it's random. */}}
+ window.scroll(0, window.location.hash.substring(1));
+ document.onscroll = function(e) { window.location.hash = Math.round(window.scrollY); };
+ });
+</script>
- {{/* Preserve vertical scroll position after page reloads. Otherwise it's random. */}}
- window.scroll(0, window.location.hash.substring(1));
- document.onscroll = function(e) { window.location.hash = Math.round(window.scrollY); };
- });
- </script>
- {{HEAD}}
-</head>
-<body>
{{range $g := .}}
<div id="div_{{$g.ID}}"></div>
{{end}}
-</body>
-</html>
`)
diff --git a/pkg/html/pages/stats_test.go b/pkg/html/pages/stats_test.go
index a5dcce01d..141651188 100644
--- a/pkg/html/pages/stats_test.go
+++ b/pkg/html/pages/stats_test.go
@@ -4,14 +4,11 @@
package pages
import (
- "io"
"testing"
-
- "github.com/google/syzkaller/pkg/stat"
)
-func TestStatsTemplate(t *testing.T) {
- if err := StatsTemplate.Execute(io.Discard, stat.RenderGraphs()); err != nil {
+func TestStatsHTML(t *testing.T) {
+ if _, err := StatsHTML(); err != nil {
t.Fatal(err)
}
}
diff --git a/pkg/manager/http.go b/pkg/manager/http.go
index 05972ba3d..6a1ed664a 100644
--- a/pkg/manager/http.go
+++ b/pkg/manager/http.go
@@ -218,7 +218,16 @@ func (serv *HTTPServer) httpSyscalls(w http.ResponseWriter, r *http.Request) {
}
func (serv *HTTPServer) httpStats(w http.ResponseWriter, r *http.Request) {
- executeTemplate(w, pages.StatsTemplate, stat.RenderGraphs())
+ html, err := pages.StatsHTML()
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+ data := &UITextPage{
+ UIPageHeader: serv.pageHeader(r, "stats"),
+ HTML: html,
+ }
+ executeTemplate(w, textTemplate, data)
}
func (serv *HTTPServer) httpVMs(w http.ResponseWriter, r *http.Request) {
@@ -1390,8 +1399,10 @@ var jobListTemplate = createPage(UIJobList{}, `
type UITextPage struct {
UIPageHeader
Text []byte
+ HTML template.HTML
}
var textTemplate = createPage(UITextPage{}, `
+{{.HTML}}
<pre>{{printf "%s" .Text}}</pre>
`)