Skip to content

Commit

Permalink
dashboard/app: fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tarasmadan committed Jul 17, 2024
1 parent 4fb5540 commit 0c8537d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 47 deletions.
35 changes: 12 additions & 23 deletions dashboard/app/graphs.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,31 +191,14 @@ func handleFoundBugsGraph(c context.Context, w http.ResponseWriter, r *http.Requ
}

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,
})
return handleHeatmap(c, w, r, "dir")
}

func handleSubsystemsCoverageHeatmap(c context.Context, w http.ResponseWriter, r *http.Request) error {
return handleHeatmap(c, w, r, "subsystems")
}

func handleHeatmap(c context.Context, w http.ResponseWriter, r *http.Request, heatmapType string) error {
hdr, err := commonHeader(c, r, w, "")
if err != nil {
return err
Expand All @@ -224,7 +207,13 @@ func handleSubsystemsCoverageHeatmap(c context.Context, w http.ResponseWriter, r
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 {
f := cover.DoHeatMapStyleBodyJS
switch heatmapType {
case "dir":
case "subsystems":
f = cover.DoSubsystemsHeatMapStyleBodyJS
}
if style, body, js, err = f("syzkaller", hdr.Namespace, dateFrom, dateTo); err != nil {
return fmt.Errorf("failed to generate heatmap: %w", err)
}
return serveTemplate(w, "custom_content.html", struct {
Expand Down
46 changes: 23 additions & 23 deletions pkg/cover/heatmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"fmt"
"html/template"
"io"
"log"
"sort"
"strings"

Expand Down Expand Up @@ -169,12 +168,30 @@ where namespace=$1 and dateto>=$2 and dateto<=$3
return res, nil
}

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)
func DoDirHeatMap(w io.Writer, projectID, ns string, dateFrom, dateTo civil.Date) error {
return DoHeatMap(w, projectID, ns, dateFrom, dateTo, "dir")
}

func DoSubsystemsHeatMap(w io.Writer, projectID, ns string, dateFrom, dateTo civil.Date) error {
return DoHeatMap(w, projectID, ns, dateFrom, dateTo, "subsystems")
}

func DoHeatMap(w io.Writer, projectID, ns string, dateFrom, dateTo civil.Date, hmType string) error {
var style template.CSS
var body, js template.HTML
var err error
switch hmType {
case "dir":
style, body, js, err = DoHeatMapStyleBodyJS(projectID, ns, dateFrom, dateTo)
if err != nil {
return fmt.Errorf("failed to DoHeatMapStyleAndBody() %w", err)
}
case "subsystems":
style, body, js, err = DoSubsystemsHeatMapStyleBodyJS(projectID, ns, dateFrom, dateTo)
if err != nil {
return fmt.Errorf("failed to DoSubsystemsHeatMapStyleBodyJS() %w", err)
}
}
log.Printf("%s", js)
return heatmapTemplate.Execute(w, struct {
Style template.CSS
Body template.HTML
Expand Down Expand Up @@ -249,23 +266,6 @@ func DoSubsystemsHeatMapStyleBodyJS(projectID, ns string, dateFrom, dateTo civil
template.HTML(js.Bytes()), nil
}

func DoSubsystemsHeatMap(w io.Writer, projectID, ns string, dateFrom, dateTo civil.Date) error {
style, body, js, err := DoSubsystemsHeatMapStyleBodyJS(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 approximateInstrumented(points int64) string {
dim := "_"
if points > 10000 {
Expand Down
2 changes: 1 addition & 1 deletion tools/syz-cover/syz-cover.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func toolBuildNsHeatmap() {
}
switch *flagNsHeatmapGroupBy {
case "dir":
if err = cover.DoHeatMap(buf, *flagProjectID, *flagNsHeatmap, dateFrom, dateTo); err != nil {
if err = cover.DoDirHeatMap(buf, *flagProjectID, *flagNsHeatmap, dateFrom, dateTo); err != nil {
tool.Fail(err)
}
case "subsystem":
Expand Down

0 comments on commit 0c8537d

Please sign in to comment.