in analysis/app/compare.go [301:371]
func (a *App) compareQuery(ctx context.Context, q string) *compareData {
if len(q) == 0 {
return &compareData{}
}
groups, err := a.fetchCompareResults(ctx, q)
if err != nil {
return &compareData{
Q: q,
Error: err.Error(),
}
}
var buf bytes.Buffer
// Compute benchstat
c := &benchstat.Collection{
AddGeoMean: true,
SplitBy: nil,
}
for _, label := range []string{"buildlet", "pkg", "goos", "goarch"} {
for _, g := range groups {
if len(g.LabelValues[label]) > 1 {
c.SplitBy = append(c.SplitBy, label)
break
}
}
}
for _, g := range groups {
c.AddResults(g.Q, g.results)
}
benchstat.FormatHTML(&buf, c.Tables())
// Prepare struct for template.
labels := make(map[string]bool)
// commonLabels are the key: value of every label that has an
// identical value on every result.
commonLabels := make(benchfmt.Labels)
// Scan the first group for common labels.
for k, vs := range groups[0].LabelValues {
if len(vs) == 1 {
for v := range vs {
commonLabels[k] = v
}
}
}
// Remove any labels not common in later groups.
for _, g := range groups[1:] {
for k, v := range commonLabels {
if len(g.LabelValues[k]) != 1 || g.LabelValues[k][v] == 0 {
delete(commonLabels, k)
}
}
}
// List all labels present and not in commonLabels.
for _, g := range groups {
for k := range g.LabelValues {
if commonLabels[k] != "" {
continue
}
labels[k] = true
}
}
data := &compareData{
Q: q,
Benchstat: template.HTML(buf.String()),
Groups: groups,
Labels: labels,
CommonLabels: commonLabels,
}
return data
}