Commit 0210f859 authored by Russ Cox's avatar Russ Cox Committed by Quentin Smith

analysis/app: convert to new benchstat library

Change-Id: I80e47f05530260b09dd92a04ddbf4799731ee99c
Reviewed-on: https://go-review.googlesource.com/35944
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: default avatarQuentin Smith <quentin@golang.org>
parent f01f51ba
......@@ -15,7 +15,7 @@ import (
"strings"
"unicode"
"golang.org/x/perf/analysis/internal/benchstat"
"golang.org/x/perf/benchstat"
"golang.org/x/perf/storage/benchfmt"
"golang.org/x/perf/storage/query"
)
......@@ -52,7 +52,7 @@ func (g *resultGroup) add(res *benchfmt.Result) {
}
// splitOn returns a new set of groups sharing a common value for key.
func (g *resultGroup) splitOn(key string) []*resultGroup {
func (g *resultGroup) splitOn(key string) ([]string, []*resultGroup) {
groups := make(map[string]*resultGroup)
var values []string
for _, res := range g.results {
......@@ -69,7 +69,7 @@ func (g *resultGroup) splitOn(key string) []*resultGroup {
for _, value := range values {
out = append(out, groups[value])
}
return out
return values, out
}
// valueSet is a set of values and the number of results with each value.
......@@ -264,19 +264,23 @@ func (a *App) compareQuery(q string) *compareData {
group := groups[0]
// Matching a single upload with multiple files -> split by file
if len(group.LabelValues["upload"]) == 1 && len(group.LabelValues["upload-part"]) > 1 {
groups = group.splitOn("upload-part")
var values []string
values, groups = group.splitOn("upload-part")
q := make([]string, len(values))
for i, v := range values {
q[i] = "upload-part:" + v
}
queries = q
}
}
// Compute benchstat
var buf bytes.Buffer
var results [][]*benchfmt.Result
for _, g := range groups {
results = append(results, g.results)
// Compute benchstat
c := new(benchstat.Collection)
for i, g := range groups {
c.AddResults(queries[i], g.results)
}
benchstat.Run(&buf, results, &benchstat.Options{
HTML: true,
})
benchstat.FormatHTML(&buf, c.Tables())
// Prepare struct for template.
labels := make(map[string]bool)
......
......@@ -39,13 +39,6 @@ td.count {
border-collapse: collapse;
border-bottom: 1px solid black;
}
table.benchstat {
border-collapse: collapse;
}
table.benchstat td, table.benchstat th {
padding-right: 2px;
padding-bottom: 2px;
}
#labels > tbody > tr:last-child > th, #labels > tbody > tr:last-child > td {
padding-bottom: 1em;
}
......@@ -66,6 +59,15 @@ table.benchstat td, table.benchstat th {
overflow: hidden;
text-overflow: ellipsis;
}
.benchstat { border-collapse: collapse; }
.benchstat th:nth-child(1) { text-align: left; }
.benchstat tbody td:nth-child(1n+2):not(.note) { text-align: right; padding: 0em 1em; }
.benchstat tr:not(.configs) th { border-top: 1px solid #666; border-bottom: 1px solid #ccc; }
.benchstat .nodelta { text-align: center !important; }
.benchstat .better td.delta { font-weight: bold; }
.benchstat .worse td.delta { font-weight: bold; color: #c00; }
</style>
</head>
<body>
......
This diff is collapsed.
......@@ -11,22 +11,20 @@ import (
)
var htmlTemplate = template.Must(template.New("").Funcs(htmlFuncs).Parse(`
{{- if . -}}
{{with index . 0}}
<table class='benchstat {{if .OldNewDelta}}oldnew{{end}}'>
{{if .OldNewDelta -}}
{{- else if eq (len .Configs) 1}}
{{if eq (len .Configs) 1}}
{{- else -}}
<tr class='configs'><th>{{range .Configs}}<th>{{.}}{{end}}
{{end}}
{{end}}
{{- range $i, $table := .}}
<tbody>
{{if .OldNewDelta -}}
<tr><th><th>old {{.Metric}}<th>new {{.Metric}}<th>delta<th>
{{else if eq (len .Configs) 1}}
{{if eq (len .Configs) 1}}
<tr><th><th>{{.Metric}}
{{else -}}
<tr><th><th colspan='{{len .Configs}}' class='metric'>{{.Metric}}
<tr><th><th colspan='{{len .Configs}}' class='metric'>{{.Metric}}{{if .OldNewDelta}}<th>delta{{end}}
{{end}}{{range $row := $table.Rows -}}
{{if $table.OldNewDelta -}}
<tr class='{{if eq .Change 1}}better{{else if eq .Change -1}}worse{{else}}unchanged{{end}}'>
......@@ -39,6 +37,7 @@ var htmlTemplate = template.Must(template.New("").Funcs(htmlFuncs).Parse(`
</tbody>
{{end}}
</table>
{{end -}}
`))
var htmlFuncs = template.FuncMap{
......
......@@ -76,7 +76,7 @@ func (c *Collection) Tables() []*Table {
new := c.Metrics[k1]
// If one is missing, omit row entirely.
// TODO: Control this better.
if old == new || new == nil {
if old == nil || new == nil {
continue
}
pval, testerr := deltaTest(old, new)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment