Skip to content

Commit 1ec634f

Browse files
committed
formatted comment output
1 parent f49e5b3 commit 1ec634f

File tree

2 files changed

+74
-43
lines changed

2 files changed

+74
-43
lines changed

.evergreen/config.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ functions:
291291
params:
292292
binary: bash
293293
env:
294-
COMMIT: "${github_commit}"
295294
VERSION_ID: ${version_id}
296295
include_expansions_in_env: [perf_uri_private_endpoint]
297296
args: [*task-runner, perf-pr-comment]

internal/cmd/perfcomp/main.go

Lines changed: 74 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ package main
88

99
import (
1010
"context"
11-
"errors"
1211
"fmt"
1312
"log"
1413
"os"
14+
"strings"
1515
"time"
1616

1717
"go.mongodb.org/mongo-driver/v2/bson"
@@ -51,15 +51,40 @@ type RawData struct {
5151
FailedRollupAttempts int64 `bson:"failed_rollup_attempts"`
5252
}
5353

54+
type StableRegion struct {
55+
TimeSeriesInfo struct {
56+
Project string `bson:"project"`
57+
Variant string `bson:"variant"`
58+
Task string `bson:"task"`
59+
Test string `bson:"test"`
60+
Measurement string `bson:"measurement"`
61+
Args map[string]interface{} `bson:"args"`
62+
}
63+
Start interface{} `bson:"start"`
64+
End interface{} `bson:"end"`
65+
Values []float64 `bson:"values"`
66+
StartOrder int64 `bson:"start_order"`
67+
EndOrder int64 `bson:"end_order"`
68+
Mean float64 `bson:"mean"`
69+
Std float64 `bson:"std"`
70+
Median float64 `bson:"median"`
71+
Max float64 `bson:"max"`
72+
Min float64 `bson:"min"`
73+
CoefficientOfVariation float64 `bson:"coefficient_of_variation"`
74+
LastSuccessfulUpdate interface{} `bson:"last_successful_update"`
75+
Last bool `bson:"last"`
76+
Contexts []interface{} `bson:"contexts"`
77+
}
78+
5479
type EnergyStats struct {
55-
Benchmark string
56-
Measurement string
57-
PatchVersion string
58-
StableRegionValues []float64
59-
PatchValues []float64
60-
E float64
61-
T float64
62-
H float64
80+
Benchmark string
81+
Measurement string
82+
PatchVersion string
83+
StableRegion StableRegion
84+
PatchValues []float64
85+
E float64
86+
T float64
87+
H float64
6388
}
6489

6590
func main() {
@@ -98,9 +123,7 @@ func main() {
98123
if err4 != nil {
99124
log.Panicf("Error getting raw data: %v", err4)
100125
}
101-
for _, es := range allEnergyStats {
102-
fmt.Printf("%s | %s | E: %f | T: %f | H: %f\n", es.Benchmark, es.Measurement, es.E, es.T, es.H)
103-
}
126+
fmt.Println(generatePRComment(allEnergyStats, version))
104127

105128
// Disconnect client
106129
err0 := client.Disconnect(context.Background())
@@ -147,7 +170,7 @@ func findRawData(version string, coll *mongo.Collection) ([]RawData, error) {
147170
return rawData, nil
148171
}
149172

150-
func findLastStableRegion(testname string, measurement string, coll *mongo.Collection) ([]float64, error) {
173+
func findLastStableRegion(testname string, measurement string, coll *mongo.Collection) (*StableRegion, error) {
151174
filter := bson.D{
152175
{"time_series_info.project", "mongo-go-driver"},
153176
{"time_series_info.variant", "perf"},
@@ -157,33 +180,19 @@ func findLastStableRegion(testname string, measurement string, coll *mongo.Colle
157180
{"last", true},
158181
{"contexts", []string{"GoDriver perf (h-score)"}},
159182
}
160-
projection := bson.D{
161-
{"values", 1},
162-
}
163-
findOptions := options.FindOne().SetSort(bson.D{{"end", -1}}).SetProjection(projection)
183+
184+
findOptions := options.FindOne().SetSort(bson.D{{"end", -1}})
164185

165186
findCtx, cancel := context.WithTimeout(context.Background(), 180*time.Second)
166187
defer cancel()
167188

168-
var result bson.M
169-
err := coll.FindOne(findCtx, filter, findOptions).Decode(&result)
189+
var sr *StableRegion
190+
err := coll.FindOne(findCtx, filter, findOptions).Decode(&sr)
170191
if err != nil {
171192
return nil, err
172193
}
173194

174-
valuesSlice, ok := result["values"].(bson.A)
175-
if !ok {
176-
return nil, errors.New("values is not of type bson.A")
177-
}
178-
var values []float64
179-
for _, v := range valuesSlice {
180-
number, ok := v.(float64)
181-
if !ok {
182-
return nil, errors.New("value is not float64")
183-
}
184-
values = append(values, number)
185-
}
186-
return values, nil
195+
return sr, nil
187196
}
188197

189198
// For a specific test and measurement
@@ -194,20 +203,20 @@ func getEnergyStatsForOneBenchmark(rd RawData, coll *mongo.Collection) ([]*Energ
194203
for i := range rd.Rollups.Stats {
195204
measurement := rd.Rollups.Stats[i].Name
196205
patchVal := []float64{rd.Rollups.Stats[i].Val}
197-
stableRegionVals, err := findLastStableRegion(testname, measurement, coll)
206+
stableRegion, err := findLastStableRegion(testname, measurement, coll)
198207
if err != nil {
199208
return nil, err
200209
}
201-
e, t, h := GetEnergyStatistics(mat.NewDense(len(stableRegionVals), 1, stableRegionVals), mat.NewDense(1, 1, patchVal))
210+
e, t, h := GetEnergyStatistics(mat.NewDense(len(stableRegion.Values), 1, stableRegion.Values), mat.NewDense(1, 1, patchVal))
202211
es := EnergyStats{
203-
Benchmark: testname,
204-
Measurement: measurement,
205-
PatchVersion: rd.Info.Version,
206-
StableRegionValues: stableRegionVals,
207-
PatchValues: patchVal,
208-
E: e,
209-
T: t,
210-
H: h,
212+
Benchmark: testname,
213+
Measurement: measurement,
214+
PatchVersion: rd.Info.Version,
215+
StableRegion: *stableRegion,
216+
PatchValues: patchVal,
217+
E: e,
218+
T: t,
219+
H: h,
211220
}
212221
energyStats = append(energyStats, &es)
213222
}
@@ -226,3 +235,26 @@ func getEnergyStatsForAllBenchMarks(patchRawData []RawData, coll *mongo.Collecti
226235
}
227236
return allEnergyStats, nil
228237
}
238+
239+
func generatePRComment(energyStats []*EnergyStats, version string) string {
240+
241+
var comment strings.Builder
242+
var testCount int64
243+
244+
comment.WriteString("# 👋GoDriver Performance\n")
245+
fmt.Fprintf(&comment, "The following benchmark tests for version %s had statistically significant changes (i.e., h-score > 0.6):\n", version)
246+
comment.WriteString("| Benchmark | Measurement | H-Score | Stable Reg Avg,Med,Std | Patch Value |\n| --- | --- | --- | --- | --- |\n")
247+
for _, es := range energyStats {
248+
testCount += 1
249+
if es.H > 0.6 {
250+
fmt.Fprintf(&comment, "| %s | %s | %.4f | %.4f,%.4f,%.4f | %.4f |\n", es.Benchmark, es.Measurement, es.H, es.StableRegion.Mean, es.StableRegion.Median, es.StableRegion.Std, es.PatchValues[0])
251+
}
252+
}
253+
254+
if testCount == 0 {
255+
comment.WriteString("There were no significant changes to the performance to report.")
256+
}
257+
comment.WriteString("\n*For a comprehensive view of all microbenchmark results for this PR's commit, please check out the Evergreen perf task for this patch.*")
258+
259+
return comment.String()
260+
}

0 commit comments

Comments
 (0)