aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/html
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2024-07-24 13:50:57 +0200
committerDmitry Vyukov <dvyukov@google.com>2024-07-24 14:39:45 +0000
commit63e964d2e8f81b4364fdd5fde9ffa74af9d04147 (patch)
tree2698626e468651c0af4fa7c540d9f92290a54885 /pkg/html
parentbd8900c38af45bfa8f8e451267d0e3548b68e295 (diff)
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.
Diffstat (limited to 'pkg/html')
-rw-r--r--pkg/html/pages/stats.go50
-rw-r--r--pkg/html/pages/stats_test.go17
2 files changed, 67 insertions, 0 deletions
diff --git a/pkg/html/pages/stats.go b/pkg/html/pages/stats.go
new file mode 100644
index 000000000..2682d28e9
--- /dev/null
+++ b/pkg/html/pages/stats.go
@@ -0,0 +1,50 @@
+// Copyright 2024 syzkaller project authors. All rights reserved.
+// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
+
+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}}
+
+ {{/* 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
new file mode 100644
index 000000000..a5dcce01d
--- /dev/null
+++ b/pkg/html/pages/stats_test.go
@@ -0,0 +1,17 @@
+// Copyright 2024 syzkaller project authors. All rights reserved.
+// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
+
+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 {
+ t.Fatal(err)
+ }
+}