@@ -11,6 +11,7 @@ package main
1111
1212import (
1313 "context"
14+ "flag"
1415 "fmt"
1516 "log"
1617 "math"
@@ -91,6 +92,7 @@ type StableRegion struct {
9192}
9293
9394type EnergyStats struct {
95+ Project string
9496 Benchmark string
9597 Measurement string
9698 PatchVersion string
@@ -119,6 +121,13 @@ func main() {
119121 log .Fatal ("could not get VERSION_ID" )
120122 }
121123
124+ // TODO (GODRIVER-3102): Map each project to a unique performance context,
125+ // necessary for project switching to work since it's required for querying the stable region.
126+ project := flag .String ("project" , "mongo-go-driver" , "specify the name of an existing Evergreen project" )
127+ if project == nil {
128+ log .Fatalf ("must provide project" )
129+ }
130+
122131 // Connect to analytics node
123132 client , err := mongo .Connect (options .Client ().ApplyURI (uri ))
124133 if err != nil {
@@ -148,7 +157,7 @@ func main() {
148157 findCtx , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
149158 defer cancel ()
150159
151- patchRawData , err := findRawData (findCtx , version , db .Collection (rawResultsColl ))
160+ patchRawData , err := findRawData (findCtx , * project , version , db .Collection (rawResultsColl ))
152161 if err != nil {
153162 log .Fatalf ("Error getting raw data: %v" , err )
154163 }
@@ -160,9 +169,9 @@ func main() {
160169 log .Println (generatePRComment (allEnergyStats , version ))
161170}
162171
163- func findRawData (ctx context.Context , version string , coll * mongo.Collection ) ([]RawData , error ) {
172+ func findRawData (ctx context.Context , project string , version string , coll * mongo.Collection ) ([]RawData , error ) {
164173 filter := bson.D {
165- {"info.project" , "mongo-go-driver" },
174+ {"info.project" , project },
166175 {"info.version" , version },
167176 {"info.variant" , "perf" },
168177 {"info.task_name" , "perf" },
@@ -199,9 +208,9 @@ func findRawData(ctx context.Context, version string, coll *mongo.Collection) ([
199208}
200209
201210// Find the most recent stable region of the mainline version for a specific test/measurement
202- func findLastStableRegion (testname string , measurement string , coll * mongo.Collection ) (* StableRegion , error ) {
211+ func findLastStableRegion (project string , testname string , measurement string , coll * mongo.Collection ) (* StableRegion , error ) {
203212 filter := bson.D {
204- {"time_series_info.project" , "mongo-go-driver" },
213+ {"time_series_info.project" , project },
205214 {"time_series_info.variant" , "perf" },
206215 {"time_series_info.task" , "perf" },
207216 {"time_series_info.test" , testname },
@@ -229,10 +238,11 @@ func getEnergyStatsForOneBenchmark(rd RawData, coll *mongo.Collection) ([]*Energ
229238 var energyStats []* EnergyStats
230239
231240 for i := range rd .Rollups .Stats {
241+ project := rd .Info .Project
232242 measName := rd .Rollups .Stats [i ].Name
233243 measVal := rd .Rollups .Stats [i ].Val
234244
235- stableRegion , err := findLastStableRegion (testname , measName , coll )
245+ stableRegion , err := findLastStableRegion (project , testname , measName , coll )
236246 if err != nil {
237247 log .Fatalf (
238248 "Error finding last stable region for test %q, measurement %q: %v" ,
@@ -244,10 +254,10 @@ func getEnergyStatsForOneBenchmark(rd RawData, coll *mongo.Collection) ([]*Energ
244254
245255 // The performance analyzer compares the measurement value from the patch to a stable region that succeeds the latest change point.
246256 // For example, if there were 5 measurements since the last change point, then the stable region is the 5 latest values for the measurement.
247- stabilityRegionVec := mat .NewDense (len (stableRegion .Values ), 1 , stableRegion .Values )
257+ stableRegionVec := mat .NewDense (len (stableRegion .Values ), 1 , stableRegion .Values )
248258 measValVec := mat .NewDense (1 , 1 , []float64 {measVal }) // singleton
249259
250- estat , tstat , hscore , err := getEnergyStatistics (stabilityRegionVec , measValVec )
260+ estat , tstat , hscore , err := getEnergyStatistics (stableRegionVec , measValVec )
251261 var zscore float64
252262 var pChange float64
253263 if err != nil {
@@ -261,6 +271,7 @@ func getEnergyStatsForOneBenchmark(rd RawData, coll *mongo.Collection) ([]*Energ
261271 }
262272
263273 es := EnergyStats {
274+ Project : project ,
264275 Benchmark : testname ,
265276 Measurement : measName ,
266277 PatchVersion : rd .Info .Version ,
0 commit comments