Skip to content

Commit 2a73974

Browse files
committed
Rename values for clarity
1 parent c50b3ea commit 2a73974

File tree

1 file changed

+54
-49
lines changed

1 file changed

+54
-49
lines changed

internal/cmd/perfcomp/main.go

Lines changed: 54 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ import (
2525
)
2626

2727
type OverrideInfo struct {
28-
OverrideMainline bool `bson:"override_mainline"`
29-
BaseOrder interface{} `bson:"base_order"`
30-
Reason interface{} `bson:"reason"`
31-
User interface{} `bson:"user"`
28+
OverrideMainline bool `bson:"override_mainline"`
29+
BaseOrder any `bson:"base_order"`
30+
Reason any `bson:"reason"`
31+
User any `bson:"user"`
3232
}
3333

3434
type Info struct {
@@ -41,14 +41,14 @@ type Info struct {
4141
Execution int64 `bson:"execution"`
4242
Mainline bool `bson:"mainline"`
4343
OverrideInfo OverrideInfo
44-
TestName string `bson:"test_name"`
45-
Args map[string]interface{} `bson:"args"`
44+
TestName string `bson:"test_name"`
45+
Args map[string]any `bson:"args"`
4646
}
4747

4848
type Stat struct {
49-
Name string `bson:"name"`
50-
Val float64 `bson:"val"`
51-
Metadata interface{} `bson:"metadata"`
49+
Name string `bson:"name"`
50+
Val float64 `bson:"val"`
51+
Metadata any `bson:"metadata"`
5252
}
5353

5454
type Rollups struct {
@@ -57,45 +57,45 @@ type Rollups struct {
5757

5858
type RawData struct {
5959
Info Info
60-
CreatedAt interface{} `bson:"created_at"`
61-
CompletedAt interface{} `bson:"completed_at"`
60+
CreatedAt any `bson:"created_at"`
61+
CompletedAt any `bson:"completed_at"`
6262
Rollups Rollups
6363
FailedRollupAttempts int64 `bson:"failed_rollup_attempts"`
6464
}
6565

6666
type TimeSeriesInfo struct {
67-
Project string `bson:"project"`
68-
Variant string `bson:"variant"`
69-
Task string `bson:"task"`
70-
Test string `bson:"test"`
71-
Measurement string `bson:"measurement"`
72-
Args map[string]interface{} `bson:"args"`
67+
Project string `bson:"project"`
68+
Variant string `bson:"variant"`
69+
Task string `bson:"task"`
70+
Test string `bson:"test"`
71+
Measurement string `bson:"measurement"`
72+
Args map[string]any `bson:"args"`
7373
}
7474

7575
type StableRegion struct {
7676
TimeSeriesInfo TimeSeriesInfo
77-
Start interface{} `bson:"start"`
78-
End interface{} `bson:"end"`
79-
Values []float64 `bson:"values"`
80-
StartOrder int64 `bson:"start_order"`
81-
EndOrder int64 `bson:"end_order"`
82-
Mean float64 `bson:"mean"`
83-
Std float64 `bson:"std"`
84-
Median float64 `bson:"median"`
85-
Max float64 `bson:"max"`
86-
Min float64 `bson:"min"`
87-
CoefficientOfVariation float64 `bson:"coefficient_of_variation"`
88-
LastSuccessfulUpdate interface{} `bson:"last_successful_update"`
89-
Last bool `bson:"last"`
90-
Contexts []interface{} `bson:"contexts"`
77+
Start any `bson:"start"`
78+
End any `bson:"end"`
79+
Values []float64 `bson:"values"`
80+
StartOrder int64 `bson:"start_order"`
81+
EndOrder int64 `bson:"end_order"`
82+
Mean float64 `bson:"mean"`
83+
Std float64 `bson:"std"`
84+
Median float64 `bson:"median"`
85+
Max float64 `bson:"max"`
86+
Min float64 `bson:"min"`
87+
CoefficientOfVariation float64 `bson:"coefficient_of_variation"`
88+
LastSuccessfulUpdate any `bson:"last_successful_update"`
89+
Last bool `bson:"last"`
90+
Contexts []any `bson:"contexts"`
9191
}
9292

9393
type EnergyStats struct {
9494
Benchmark string
9595
Measurement string
9696
PatchVersion string
9797
StableRegion StableRegion
98-
PatchValues []float64
98+
MeasurementVal float64
9999
PercentChange float64
100100
EnergyStatistic float64
101101
TestStatistic float64
@@ -221,43 +221,48 @@ func getEnergyStatsForOneBenchmark(rd RawData, coll *mongo.Collection) ([]*Energ
221221
var energyStats []*EnergyStats
222222

223223
for i := range rd.Rollups.Stats {
224-
measurement := rd.Rollups.Stats[i].Name
225-
patchVal := []float64{rd.Rollups.Stats[i].Val}
224+
measName := rd.Rollups.Stats[i].Name
225+
measVal := rd.Rollups.Stats[i].Val
226226

227-
stableRegion, err := findLastStableRegion(testname, measurement, coll)
227+
stableRegion, err := findLastStableRegion(testname, measName, coll)
228228
if err != nil {
229229
log.Fatalf(
230230
"Error finding last stable region for test %q, measurement %q: %v",
231231
testname,
232-
measurement,
232+
measName,
233233
err,
234234
)
235235
}
236236

237-
var z float64
237+
// The performance analyzer compares the measurement value from the patch to a stable region that succeeds the latest change point.
238+
// For example, if there were 5 measurements since the last change point, then the stable region is the 5 latest values for the measurement.
239+
stabilityRegionVec := mat.NewDense(len(stableRegion.Values), 1, stableRegion.Values)
240+
measValVec := mat.NewDense(1, 1, []float64{measVal}) // singleton
241+
242+
estat, tstat, hscore, err := getEnergyStatistics(stabilityRegionVec, measValVec)
243+
var zscore float64
238244
var pChange float64
239-
e, t, h, err := getEnergyStatistics(mat.NewDense(len(stableRegion.Values), 1, stableRegion.Values), mat.NewDense(1, 1, patchVal))
240245
if err != nil {
241-
log.Printf("Could not calculate energy stats for test %q, measurement %q: %v", testname, measurement, err)
242-
z = 0
246+
log.Printf("Could not calculate energy stats for test %q, measurement %q: %v", testname, measName, err)
247+
zscore = 0
243248
pChange = 0
244249
} else {
245-
z = getZScore(patchVal[0], stableRegion.Mean, stableRegion.Std)
246-
pChange = getPercentageChange(patchVal[0], stableRegion.Mean)
250+
zscore = getZScore(measVal, stableRegion.Mean, stableRegion.Std)
251+
pChange = getPercentageChange(measVal, stableRegion.Mean)
247252

248253
}
249254

250255
es := EnergyStats{
251256
Benchmark: testname,
252-
Measurement: measurement,
257+
Measurement: measName,
253258
PatchVersion: rd.Info.Version,
254259
StableRegion: *stableRegion,
255-
PatchValues: patchVal,
260+
MeasurementVal: measVal,
256261
PercentChange: pChange,
257-
EnergyStatistic: e,
258-
TestStatistic: t,
259-
HScore: h,
260-
ZScore: z,
262+
EnergyStatistic: estat,
263+
TestStatistic: tstat,
264+
HScore: hscore,
265+
ZScore: zscore,
261266
}
262267
energyStats = append(energyStats, &es)
263268
}
@@ -287,7 +292,7 @@ func generatePRComment(energyStats []*EnergyStats, version string) string {
287292
for _, es := range energyStats {
288293
if math.Abs(es.ZScore) > 1.96 {
289294
testCount += 1
290-
fmt.Fprintf(&comment, "| %s | %s | %.4f | %.4f | %.4f | Avg: %.4f, Med: %.4f, Stdev: %.4f | %.4f |\n", es.Benchmark, es.Measurement, es.HScore, es.ZScore, es.PercentChange, es.StableRegion.Mean, es.StableRegion.Median, es.StableRegion.Std, es.PatchValues[0])
295+
fmt.Fprintf(&comment, "| %s | %s | %.4f | %.4f | %.4f | Avg: %.4f, Med: %.4f, Stdev: %.4f | %.4f |\n", es.Benchmark, es.Measurement, es.HScore, es.ZScore, es.PercentChange, es.StableRegion.Mean, es.StableRegion.Median, es.StableRegion.Std, es.MeasurementVal)
291296
}
292297
}
293298

0 commit comments

Comments
 (0)