Skip to content

Commit

Permalink
Add TotalDuration to benchmark report (#3223)
Browse files Browse the repository at this point in the history
  • Loading branch information
manno authored Jan 20, 2025
1 parent 9aa34b3 commit 046d1c4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
6 changes: 3 additions & 3 deletions benchmarks/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ var _ = Context("Benchmarks Deploy", func() {
cluster := &v1alpha1.Cluster{}
err := k8sClient.Get(ctx, client.ObjectKey{Namespace: workspace, Name: c.Name}, cluster)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(cluster.Status.Summary.DesiredReady).To(Equal(n*50 + 1))
// we expect the agent to be ready as well
g.Expect(cluster.Status.Summary.Ready).To(Equal(n*50 + 1))
// +1 because we expect the agent to be ready as well
g.Expect(cluster.Status.Summary.DesiredReady).To(Equal(50 + 1))
g.Expect(cluster.Status.Summary.Ready).To(Equal(50 + 1))
}
}).Should(Succeed())
}, gm.Style("{{bold}}"))
Expand Down
41 changes: 27 additions & 14 deletions benchmarks/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import (
type Summary struct {
Description string
Experiments map[string]Experiment
Setup map[string]Measurement
Setup map[string]Row
}

type Measurement struct {
type Row struct {
Value float64
Type gm.MeasurementType
PrecisionBundle gm.PrecisionBundle
Expand All @@ -30,9 +30,9 @@ type Measurement struct {

// Experiment is a set of measurements, like from 50-gitrepo-1-bundle
// Measurements from the report are one dimensional, as most experiments don't
// use sampling
// use sampling. Each measurement will result in one row.
type Experiment struct {
Measurements map[string]Measurement
Rows map[string]Row
}

// ColorableString for ReportEntry to use
Expand All @@ -42,7 +42,7 @@ func (s Summary) ColorableString() string {
for _, k := range keys {
v := s.Experiments[k]
sb += fmt.Sprintf("{{green}}%s{{/}}\n", k)
t2 := newTable(v.Measurements)
t2 := newTable(v.Rows)
sb += t2.Render()
sb += "\n"
}
Expand All @@ -60,17 +60,17 @@ func (s Summary) String() string {
return fmt.Sprintf("%s\n%s\n%s\n", s.Description, prettyPrint(s.Setup), prettyPrint(s.Experiments))
}

func newTable(measurements map[string]Measurement) *table.Table {
func newTable(rows map[string]Row) *table.Table {
t := table.NewTable()
t.AppendRow(table.R(
table.C("Measurement"), table.C("Value"), table.C("Unit"),
table.Divider("="),
"{{bold}}",
))

keys := slices.Sorted(maps.Keys(measurements))
keys := slices.Sorted(maps.Keys(rows))
for _, k := range keys {
m := measurements[k]
m := rows[k]

r := table.R(m.Style)
t.AppendRow(r)
Expand All @@ -83,10 +83,17 @@ func newTable(measurements map[string]Measurement) *table.Table {
return t
}

// New builds a printable table from the ginkgo.Report.
func New(r ginkgo.Report) (*Summary, bool) {
s := &Summary{
Experiments: map[string]Experiment{},
Setup: map[string]Measurement{},
Setup: map[string]Row{},
}

total := Row{
Type: gm.MeasurementTypeDuration,
Style: "{{bold}}",
PrecisionBundle: gm.DefaultPrecisionBundle,
}

for _, specReport := range r.SpecReports {
Expand All @@ -102,7 +109,7 @@ func New(r ginkgo.Report) (*Summary, bool) {
for _, entry := range specReport.ReportEntries {

e := Experiment{
Measurements: map[string]Measurement{},
Rows: map[string]Row{},
}

raw := entry.GetRawValue()
Expand All @@ -118,19 +125,23 @@ func New(r ginkgo.Report) (*Summary, bool) {
continue
}

tmp, ok := e.Measurements[name]
if name == "TotalDuration" {
total.Value += v
}

tmp, ok := e.Rows[name]
if ok {
tmp.Value += v
} else {
tmp = Measurement{
tmp = Row{
Value: v,
Type: m.Type,
PrecisionBundle: m.PrecisionBundle,
Style: m.Style,
Units: m.Units,
}
}
e.Measurements[name] = tmp
e.Rows[name] = tmp
}
s.Experiments[entry.Name] = e
}
Expand Down Expand Up @@ -164,7 +175,7 @@ func New(r ginkgo.Report) (*Summary, bool) {
if ok {
tmp.Value += v
} else {
tmp = Measurement{
tmp = Row{
Value: v,
Type: m.Type,
PrecisionBundle: m.PrecisionBundle,
Expand All @@ -186,6 +197,8 @@ func New(r ginkgo.Report) (*Summary, bool) {
break
}

s.Setup["TotalDuration"] = total

return s, true
}

Expand Down

0 comments on commit 046d1c4

Please # to comment.