| 1 |
package report |
| 2 |
|
| 3 |
import ( |
| 4 |
_ "embed" |
| 5 |
"html/template" |
| 6 |
"strings" |
| 7 |
) |
| 8 |
|
| 9 |
// page.html is the page of the report. The results are in the page as JSON, and the charts are drawn from them in |
| 10 |
// the browser, so that the reader chooses the machine, the condition, the operation and the metric. |
| 11 |
// |
| 12 |
//go:embed page.html |
| 13 |
var pageHTML string |
| 14 |
|
| 15 |
var pageTemplate = template.Must(template.New("page").Parse(pageHTML)) |
| 16 |
|
| 17 |
// pageData is what the page is rendered from. |
| 18 |
type pageData struct { |
| 19 |
Generated string `json:"generated"` |
| 20 |
GoVersion string `json:"goVersion"` |
| 21 |
Commit string `json:"commit"` |
| 22 |
ShortCommit string `json:"shortCommit"` |
| 23 |
Repository string `json:"repository"` |
| 24 |
RunURL string `json:"runURL"` |
| 25 |
Source string `json:"source"` |
| 26 |
Attestations string `json:"attestations"` |
| 27 |
Libraries []Library `json:"libraries"` |
| 28 |
Categories []pageCategory `json:"categories"` |
| 29 |
Conditions []Condition `json:"conditions"` |
| 30 |
Payloads []Payload `json:"payloads"` |
| 31 |
Configs []Config `json:"configs"` |
| 32 |
Runs []pageRun `json:"runs"` |
| 33 |
Probes []pageProbe `json:"probes"` |
| 34 |
} |
| 35 |
|
| 36 |
type pageCategory struct { |
| 37 |
Category |
| 38 |
// Requires are the descriptions of the probes the category requires. |
| 39 |
Requires []string `json:"requires"` |
| 40 |
} |
| 41 |
|
| 42 |
type pageRun struct { |
| 43 |
Arch string `json:"arch"` |
| 44 |
CPU string `json:"cpu"` |
| 45 |
Features []string `json:"features"` |
| 46 |
GOOS string `json:"goos"` |
| 47 |
File string `json:"file"` |
| 48 |
BenchTime string `json:"benchTime"` |
| 49 |
Rounds int `json:"rounds"` |
| 50 |
// Differs are the required probes each configuration fails, by configuration. |
| 51 |
Differs map[string][]ProbeResult `json:"differs"` |
| 52 |
// Skips are the probes which a configuration is only informed of, of a category which requires none, and |
| 53 |
// which it fails: what it does differently from encoding/json. |
| 54 |
Skips map[string][]ProbeResult `json:"skips"` |
| 55 |
Differences []Exclusion `json:"differences"` |
| 56 |
Exclusions []Exclusion `json:"exclusions"` |
| 57 |
Results []Result `json:"results"` |
| 58 |
} |
| 59 |
|
| 60 |
// pageProbe is a probe and what every configuration did on it, on the first machine. |
| 61 |
type pageProbe struct { |
| 62 |
ID string `json:"id"` |
| 63 |
Description string `json:"description"` |
| 64 |
Results map[string]ProbeResult `json:"results"` |
| 65 |
} |
| 66 |
|
| 67 |
// HTML renders the page of the runs. |
| 68 |
func (s *Site) HTML() (string, error) { |
| 69 |
s.sortRuns() |
| 70 |
d := pageData{Attestations: s.Attestations} |
| 71 |
if len(s.Runs) > 0 { |
| 72 |
r := s.Runs[0] |
| 73 |
d.Generated = r.GeneratedAt.Format("2006-01-02 15:04 UTC") |
| 74 |
d.GoVersion, d.Commit, d.Repository, d.RunURL = r.GoVersion, r.Commit, r.Repository, r.RunURL |
| 75 |
d.ShortCommit = r.Commit |
| 76 |
if len(d.ShortCommit) > 7 { |
| 77 |
d.ShortCommit = d.ShortCommit[:7] |
| 78 |
} |
| 79 |
if r.Repository != "" && r.Commit != "" { |
| 80 |
d.Source = "https://github.com/" + r.Repository + "/blob/" + r.Commit + "/benchmarks/report_test.go" |
| 81 |
} |
| 82 |
d.Libraries, d.Conditions, d.Payloads, d.Configs = r.Libraries, r.Conditions, r.Payloads, r.Configs |
| 83 |
for _, c := range r.Categories { |
| 84 |
d.Categories = append(d.Categories, pageCategory{Category: c, Requires: probesOf(r, c.ID)}) |
| 85 |
} |
| 86 |
index := map[string]int{} |
| 87 |
for _, p := range r.Probes { |
| 88 |
i, ok := index[p.Probe] |
| 89 |
if !ok { |
| 90 |
i = len(d.Probes) |
| 91 |
index[p.Probe] = i |
| 92 |
d.Probes = append(d.Probes, pageProbe{ID: p.Probe, Description: p.Description, Results: map[string]ProbeResult{}}) |
| 93 |
} |
| 94 |
d.Probes[i].Results[p.Config] = p |
| 95 |
} |
| 96 |
} |
| 97 |
for i, r := range s.Runs { |
| 98 |
pr := pageRun{ |
| 99 |
Arch: r.GOARCH, CPU: r.CPU, Features: r.CPUFeatures, GOOS: r.GOOS, BenchTime: r.BenchTime, Rounds: r.Rounds, |
| 100 |
Differs: map[string][]ProbeResult{}, Skips: map[string][]ProbeResult{}, |
| 101 |
Differences: r.Differences, Exclusions: r.Exclusions, Results: r.Results, |
| 102 |
} |
| 103 |
if i < len(s.Files) { |
| 104 |
pr.File = s.Files[i] |
| 105 |
} |
| 106 |
for _, c := range r.Configs { |
| 107 |
if f := failedProbes(r, c.ID); len(f) > 0 { |
| 108 |
pr.Differs[c.ID] = f |
| 109 |
} |
| 110 |
for _, p := range r.Probes { |
| 111 |
if p.Config == c.ID && !p.Required && !p.Passed { |
| 112 |
pr.Skips[c.ID] = append(pr.Skips[c.ID], p) |
| 113 |
} |
| 114 |
} |
| 115 |
} |
| 116 |
d.Runs = append(d.Runs, pr) |
| 117 |
} |
| 118 |
var b strings.Builder |
| 119 |
err := pageTemplate.Execute(&b, d) |
| 120 |
return b.String(), err |
| 121 |
} |