Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dashboard/app: link heatmap generation #5055

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions dashboard/app/graphs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main
import (
"context"
"fmt"
"html/template"
"net/http"
"net/url"
"regexp"
Expand All @@ -14,6 +15,7 @@ import (
"time"

"cloud.google.com/go/civil"
"github.com/google/syzkaller/pkg/cover"
db "google.golang.org/appengine/v2/datastore"
)

Expand Down Expand Up @@ -188,6 +190,31 @@ func handleFoundBugsGraph(c context.Context, w http.ResponseWriter, r *http.Requ
return serveTemplate(w, "graph_histogram.html", data)
}

func handleCoverageHeatmap(c context.Context, w http.ResponseWriter, r *http.Request) error {
hdr, err := commonHeader(c, r, w, "")
if err != nil {
return err
}
dateFrom := civil.DateOf(time.Now().Add(-14 * 24 * time.Hour))
dateTo := civil.DateOf(time.Now())
var style template.CSS
var body, js template.HTML
if style, body, js, err = cover.DoHeatMapStyleBodyJS("syzkaller", hdr.Namespace, dateFrom, dateTo); err != nil {
return fmt.Errorf("failed to generate heatmap: %w", err)
}
return serveTemplate(w, "custom_content.html", struct {
Header *uiHeader
Style template.CSS
Body template.HTML
JS template.HTML
}{
Header: hdr,
Style: style,
Body: body,
JS: js,
})
}

func handleCoverageGraph(c context.Context, w http.ResponseWriter, r *http.Request) error {
hdr, err := commonHeader(c, r, w, "")
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions dashboard/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func initHTTPHandlers() {
http.Handle("/"+ns+"/graph/found-bugs", handlerWrapper(handleFoundBugsGraph))
if nsConfig.Coverage != nil {
http.Handle("/"+ns+"/graph/coverage", handlerWrapper(handleCoverageGraph))
http.Handle("/"+ns+"/graph/coverage_heatmap", handlerWrapper(handleCoverageHeatmap))
}
http.Handle("/"+ns+"/repos", handlerWrapper(handleRepos))
http.Handle("/"+ns+"/bug-summaries", handlerWrapper(handleBugSummaries))
Expand Down
21 changes: 21 additions & 0 deletions dashboard/app/templates/custom_content.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{/*
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.
*/}}

<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
{{template "head" .Header}}
tarasmadan marked this conversation as resolved.
Show resolved Hide resolved
<style>
{{ .Style }}
</style>
<title>syzbot</title>
</head>
<body>
{{template "header" .Header}}
{{ .Body }}
</body>
{{ .JS }}
</html>
1 change: 1 addition & 0 deletions dashboard/app/templates/templates.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ <h1><a href="/{{$.Namespace}}">syzbot</a></h1>
<button class="dropbtn"><span style="color:DarkOrange;">📈</span>Coverage</button>
<div class="dropdown-content navigation_tab{{if eq .URLPath (printf "/%v/graph/coverage" $.Namespace)}}_selected{{end}}">
<a href="/{{$.Namespace}}/graph/coverage">Total</a>
<a href="/{{$.Namespace}}/graph/coverage_heatmap">Heatmap</a>
</div>
</div>
{{end}}
Expand Down
36 changes: 34 additions & 2 deletions pkg/cover/heatmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
package cover

import (
"bytes"
"context"
_ "embed"
"fmt"
"html/template"
"io"
"log"
"sort"
"strings"

Expand Down Expand Up @@ -168,12 +170,42 @@ where namespace=$1 and dateto>=$2 and dateto<=$3
}

func DoHeatMap(w io.Writer, projectID, ns string, dateFrom, dateTo civil.Date) error {
style, body, js, err := DoHeatMapStyleBodyJS(projectID, ns, dateFrom, dateTo)
if err != nil {
return fmt.Errorf("failed to DoHeatMapStyleAndBody() %w", err)
}
log.Printf("%s", js)
return heatmapTemplate.Execute(w, struct {
Style template.CSS
Body template.HTML
JS template.HTML
}{
Style: style,
Body: body,
JS: js,
})
}

func DoHeatMapStyleBodyJS(projectID, ns string, dateFrom, dateTo civil.Date,
) (template.CSS, template.HTML, template.HTML, error) {
covAndDates, err := filesCoverageAndDates(context.Background(), projectID, ns, dateFrom, dateTo)
if err != nil {
panic(err)
return "", "", "", fmt.Errorf("failed to filesCoverageAndDates: %w", err)
}
templateData := filesCoverageToTemplateData(covAndDates)
return heatmapTemplate.Execute(w, templateData)
var styles, body, js bytes.Buffer
if err := heatmapTemplate.ExecuteTemplate(&styles, "style", templateData); err != nil {
return "", "", "", fmt.Errorf("failed to get styles: %w", err)
}
if err := heatmapTemplate.ExecuteTemplate(&body, "body", templateData); err != nil {
return "", "", "", fmt.Errorf("failed to get body: %w", err)
}
if err := heatmapTemplate.ExecuteTemplate(&js, "js", templateData); err != nil {
return "", "", "", fmt.Errorf("failed to get js: %w", err)
}
return template.CSS(styles.String()),
template.HTML(body.String()),
template.HTML(js.Bytes()), nil
}

func DoSubsystemsHeatMap(w io.Writer, projectID, ns string, dateFrom, dateTo civil.Date) error {
Expand Down
172 changes: 92 additions & 80 deletions pkg/cover/templates/heatmap.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,88 +3,16 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
ul {
list-style-type: none;
padding-left: 0px;
}
.first_column {
display: inline-block;
width: 250px;
}
.date_column {
display: inline-block;
width: 50px;
}
.instrumented_column {
display: inline-block;
width: 70px;
text-align: right;
}
.tree_depth_0 {width: 0px;}
.tree_depth_1 {width: 20px;}
.tree_depth_2 {width: 40px;}
.tree_depth_3 {width: 60px;}
.tree_depth_4 {width: 80px;}
.tree_depth_5 {width: 100px;}
.tree_depth_6 {width: 120px;}
.tree_depth_7 {width: 140px;}

.bold {font-weight: bold;}
.hover:hover {
background: #ffff99;
}
.caret {
cursor: pointer;
user-select: none;
}
.caret::before {
color: black;
content: "\25B6";
display: inline-block;
margin-right: 3px;
}
.caret-down::before {
transform: rotate(90deg);
}
.nested {
display: none;
}
.active {
display: block;
}
{{ .Style }}
</style>
</head>
<body>
<div>
<ul id="collapsible-list">
<li>
<div class="first_column bold">
date
</div>
{{ range $date := .Dates }}
<div class="date_column bold">
{{ $date }}
</div>
{{ end }}
</li>
<li>
<div class="first_column bold">
total covered
</div>
{{ range $cov := .Root.Coverage }}
<div class="date_column">
{{ $cov }}%
</div>
{{ end }}
<div class="instrumented_column">
of {{ approxInstr .Root.LastDayInstrumented }} blocks
</div>
</li>
<br>
{{template "dir" .Root}}
</ul>
</div>
{{ .Body }}
</body>
{{ .JS }}
</html>

{{ define "js" }}
<script>
var togglers = document.getElementsByClassName("caret");
for (var i = 0; i < togglers.length; i++) {
Expand All @@ -93,8 +21,92 @@
this.parentElement.parentElement.parentElement.querySelector(".nested").classList.toggle("active");
});
}
</script>
</html>
</script>
{{ end }}

{{ define "style" }}
ul {
list-style-type: none;
padding-left: 0px;
}
.first_column {
display: inline-block;
width: 250px;
}
.date_column {
display: inline-block;
width: 50px;
}
.instrumented_column {
display: inline-block;
width: 70px;
text-align: right;
}
.tree_depth_0 {width: 0px;}
.tree_depth_1 {width: 20px;}
.tree_depth_2 {width: 40px;}
.tree_depth_3 {width: 60px;}
.tree_depth_4 {width: 80px;}
.tree_depth_5 {width: 100px;}
.tree_depth_6 {width: 120px;}
.tree_depth_7 {width: 140px;}

.bold {font-weight: bold;}
.hover:hover {
background: #ffff99;
}
.caret {
cursor: pointer;
user-select: none;
}
.caret::before {
color: black;
content: "\25B6";
display: inline-block;
margin-right: 3px;
}
.caret-down::before {
transform: rotate(90deg);
}
.nested {
display: none;
}
.active {
display: block;
}
{{ end }}

{{ define "body" }}
<div>
<ul id="collapsible-list">
<li>
<div class="first_column bold">
date
</div>
{{ range $date := .Dates }}
<div class="date_column bold">
{{ $date }}
</div>
{{ end }}
</li>
<li>
<div class="first_column bold">
total covered
</div>
{{ range $cov := .Root.Coverage }}
<div class="date_column">
{{ $cov }}%
</div>
{{ end }}
<div class="instrumented_column">
of {{ approxInstr .Root.LastDayInstrumented }} blocks
</div>
</li>
<br>
{{template "dir" .Root}}
</ul>
</div>
{{ end }}

{{define "dir"}}
{{range $child := .Items}}
Expand Down
Loading