Skip to content

Commit 3e87d2a

Browse files
committed
Set up pipeline to generate perf comp comment during a PR run
1 parent 6eda007 commit 3e87d2a

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

.evergreen/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ functions:
292292
binary: bash
293293
env:
294294
VERSION_ID: ${version_id}
295+
BASE_SHA: "${revision}"
296+
HEAD_SHA: "${github_commit}"
295297
include_expansions_in_env: [PERF_URI_PRIVATE_ENDPOINT]
296298
args: [*task-runner, perf-pr-comment]
297299

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ internal/cmd/compilecheck/compilecheck.so
3838
api-report.md
3939
api-report.txt
4040

41+
# Ignore perf report files
42+
perf-report.md
43+
perf-report.txt
44+
4145
# Ignore secrets files
4246
secrets-expansion.yml
4347
secrets-export.sh

etc/perf-pr-comment.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@
44

55
set -eux
66

7+
# Generate perf report.
78
pushd ./internal/cmd/perfcomp >/dev/null || exist
8-
GOWORK=off go run main.go --project="mongo-go-driver" ${VERSION_ID}
9+
GOWORK=off go run main.go --project="mongo-go-driver" ${VERSION_ID} > ./parseperfcomp/perf-report.txt
910
popd >/dev/null
11+
12+
if [[ -n "${BASE_SHA+set}" && -n "${HEAD_SHA+set}" && "$BASE_SHA" != "$HEAD_SHA" ]]; then
13+
# Parse and generate perf comparison comment.
14+
go run ./internal/cmd/perfcomp/parseperfcomp/main.go
15+
# Make the PR comment.
16+
# target=$DRIVERS_TOOLS/.evergreen/github_app/create_or_modify_comment.sh
17+
# bash $target -m "## 👋GoDriver Performance" -c "$(pwd)/perf-report.md" -h $HEAD_SHA -o "mongodb" -n "mongo-go-driver"
18+
else
19+
# Skip comment if it isn't a PR run.
20+
echo "Skipping Perf PR comment"
21+
fi
22+
23+
rm ./internal/cmd/perfcomp/parseperfcomp/perf-report.txt

internal/cmd/perfcomp/main.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,19 @@ func main() {
166166
if err != nil {
167167
log.Fatalf("Error getting energy statistics: %v", err)
168168
}
169-
log.Println(generatePRComment(allEnergyStats, version))
169+
170+
// Log energy stats output
171+
prComment := generatePRComment(allEnergyStats, version)
172+
log.Println("👋GoDriver Performance")
173+
log.Println(prComment)
174+
175+
// Save for PR comment if it is a PR run
176+
commitSHA := os.Getenv("HEAD_SHA")
177+
if commitSHA != "" {
178+
fmt.Printf("Version ID: %s\n", version)
179+
fmt.Printf("Commit SHA: %s\n", commitSHA) // Use fmt to print to stdout
180+
fmt.Println(prComment)
181+
}
170182
}
171183

172184
func findRawData(ctx context.Context, project string, version string, coll *mongo.Collection) ([]RawData, error) {
@@ -305,8 +317,7 @@ func getEnergyStatsForAllBenchMarks(ctx context.Context, patchRawData []RawData,
305317

306318
func generatePRComment(energyStats []*EnergyStats, version string) string {
307319
var comment strings.Builder
308-
comment.WriteString("# 👋GoDriver Performance\n")
309-
fmt.Fprintf(&comment, "The following benchmark tests for version %s had statistically significant changes (i.e., |z-score| > 1.96):\n", version)
320+
fmt.Fprintf(&comment, "The following benchmark tests for version %s had statistically significant changes (i.e., |z-score| > 1.96):\n\n", version)
310321

311322
w := tabwriter.NewWriter(&comment, 0, 0, 1, ' ', 0)
312323
fmt.Fprintln(w, "| Benchmark\t| Measurement\t| H-Score\t| Z-Score\t| % Change\t| Stable Reg\t| Patch Value\t|")
@@ -323,8 +334,7 @@ func generatePRComment(energyStats []*EnergyStats, version string) string {
323334

324335
if testCount == 0 {
325336
comment.Reset()
326-
comment.WriteString("# 👋GoDriver Performance\n")
327-
comment.WriteString("There were no significant changes to the performance to report.")
337+
fmt.Fprintf(&comment, "There were no significant changes to the performance to report for version %s.\n", version)
328338
}
329339

330340
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.*")

0 commit comments

Comments
 (0)