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 ( ...@@ -15,7 +15,7 @@ import (
"strings" "strings"
"unicode" "unicode"
"golang.org/x/perf/analysis/internal/benchstat" "golang.org/x/perf/benchstat"
"golang.org/x/perf/storage/benchfmt" "golang.org/x/perf/storage/benchfmt"
"golang.org/x/perf/storage/query" "golang.org/x/perf/storage/query"
) )
...@@ -52,7 +52,7 @@ func (g *resultGroup) add(res *benchfmt.Result) { ...@@ -52,7 +52,7 @@ func (g *resultGroup) add(res *benchfmt.Result) {
} }
// splitOn returns a new set of groups sharing a common value for key. // 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) groups := make(map[string]*resultGroup)
var values []string var values []string
for _, res := range g.results { for _, res := range g.results {
...@@ -69,7 +69,7 @@ func (g *resultGroup) splitOn(key string) []*resultGroup { ...@@ -69,7 +69,7 @@ func (g *resultGroup) splitOn(key string) []*resultGroup {
for _, value := range values { for _, value := range values {
out = append(out, groups[value]) out = append(out, groups[value])
} }
return out return values, out
} }
// valueSet is a set of values and the number of results with each value. // 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 { ...@@ -264,19 +264,23 @@ func (a *App) compareQuery(q string) *compareData {
group := groups[0] group := groups[0]
// Matching a single upload with multiple files -> split by file // Matching a single upload with multiple files -> split by file
if len(group.LabelValues["upload"]) == 1 && len(group.LabelValues["upload-part"]) > 1 { 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 buf bytes.Buffer
var results [][]*benchfmt.Result // Compute benchstat
for _, g := range groups { c := new(benchstat.Collection)
results = append(results, g.results) for i, g := range groups {
c.AddResults(queries[i], g.results)
} }
benchstat.Run(&buf, results, &benchstat.Options{ benchstat.FormatHTML(&buf, c.Tables())
HTML: true,
})
// Prepare struct for template. // Prepare struct for template.
labels := make(map[string]bool) labels := make(map[string]bool)
......
...@@ -39,13 +39,6 @@ td.count { ...@@ -39,13 +39,6 @@ td.count {
border-collapse: collapse; border-collapse: collapse;
border-bottom: 1px solid black; 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 { #labels > tbody > tr:last-child > th, #labels > tbody > tr:last-child > td {
padding-bottom: 1em; padding-bottom: 1em;
} }
...@@ -66,6 +59,15 @@ table.benchstat td, table.benchstat th { ...@@ -66,6 +59,15 @@ table.benchstat td, table.benchstat th {
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; 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> </style>
</head> </head>
<body> <body>
......
This diff is collapsed.
...@@ -11,22 +11,20 @@ import ( ...@@ -11,22 +11,20 @@ import (
) )
var htmlTemplate = template.Must(template.New("").Funcs(htmlFuncs).Parse(` var htmlTemplate = template.Must(template.New("").Funcs(htmlFuncs).Parse(`
{{- if . -}}
{{with index . 0}} {{with index . 0}}
<table class='benchstat {{if .OldNewDelta}}oldnew{{end}}'> <table class='benchstat {{if .OldNewDelta}}oldnew{{end}}'>
{{if .OldNewDelta -}} {{if eq (len .Configs) 1}}
{{- else if eq (len .Configs) 1}}
{{- else -}} {{- else -}}
<tr class='configs'><th>{{range .Configs}}<th>{{.}}{{end}} <tr class='configs'><th>{{range .Configs}}<th>{{.}}{{end}}
{{end}} {{end}}
{{end}} {{end}}
{{- range $i, $table := .}} {{- range $i, $table := .}}
<tbody> <tbody>
{{if .OldNewDelta -}} {{if eq (len .Configs) 1}}
<tr><th><th>old {{.Metric}}<th>new {{.Metric}}<th>delta<th>
{{else if eq (len .Configs) 1}}
<tr><th><th>{{.Metric}} <tr><th><th>{{.Metric}}
{{else -}} {{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 -}} {{end}}{{range $row := $table.Rows -}}
{{if $table.OldNewDelta -}} {{if $table.OldNewDelta -}}
<tr class='{{if eq .Change 1}}better{{else if eq .Change -1}}worse{{else}}unchanged{{end}}'> <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(` ...@@ -39,6 +37,7 @@ var htmlTemplate = template.Must(template.New("").Funcs(htmlFuncs).Parse(`
</tbody> </tbody>
{{end}} {{end}}
</table> </table>
{{end -}}
`)) `))
var htmlFuncs = template.FuncMap{ var htmlFuncs = template.FuncMap{
......
...@@ -76,7 +76,7 @@ func (c *Collection) Tables() []*Table { ...@@ -76,7 +76,7 @@ func (c *Collection) Tables() []*Table {
new := c.Metrics[k1] new := c.Metrics[k1]
// If one is missing, omit row entirely. // If one is missing, omit row entirely.
// TODO: Control this better. // TODO: Control this better.
if old == new || new == nil { if old == nil || new == nil {
continue continue
} }
pval, testerr := deltaTest(old, new) 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