Skip to content

Conversation

matthewdale
Copy link
Collaborator

Summary

Add a script etc/profile-test.sh that makes profiling and tracing Go tests and benchmarks easier.

Background & Motivation

The command syntax is identical to go test, but you replace go test with etc/profile-test.sh.

E.g.

❯ etc/profile-test.sh -timeout 30s -run ^TestRetryableReadsProse$ go.mongodb.org/mongo-driver/v2/internal/integration -v
1) cpu
2) mem
3) block
4) mutex
5) trace
Choose a profile type: 1
Writing cpu profile to /var/folders/jm/nk3y7g2d0539mxh5bhdcnhcm0000gp/T/tmp.WwVNvAewwl
=== RUN   TestRetryableReadsProse
=== RUN   TestRetryableReadsProse/PoolClearedError_retryability
=== RUN   TestRetryableReadsProse/retrying_in_sharded_cluster
    mongotest.go:112: skipping due to environmental constraints: topology kind "single" does not match any of the required kinds ["sharded"]
--- PASS: TestRetryableReadsProse (1.52s)
    --- PASS: TestRetryableReadsProse/PoolClearedError_retryability (1.52s)
    --- SKIP: TestRetryableReadsProse/retrying_in_sharded_cluster (0.00s)
PASS
ok      go.mongodb.org/mongo-driver/v2/internal/integration     1.945s
Serving web UI on http://localhost:58230

@matthewdale matthewdale requested a review from a team as a code owner September 30, 2025 04:45
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds a convenience script to simplify profiling and tracing Go tests and benchmarks by providing an interactive menu to select profile types and automatically generating temporary files for the output.

  • Introduces etc/profile-test.sh script that wraps go test with profiling capabilities
  • Provides interactive selection between cpu, memory, block, mutex profiling and tracing
  • Automatically creates temporary files and launches appropriate visualization tools

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

mongodb-drivers-pr-bot bot commented Sep 30, 2025

🧪 Performance Results

Commit SHA: 80c3f56

The following benchmark tests for version 68dbf491ef4ed80007e12bd1 had statistically significant changes (i.e., |z-score| > 1.96):

Benchmark Measurement % Change Patch Value Stable Region H-Score Z-Score
BenchmarkBSONDeepDocumentDecoding ops_per_second_min -30.8527 1373.4547 Avg: 1986.2742
Med: 1997.3144
Stdev: 168.7916
0.8643 -3.6306
BenchmarkMultiInsertSmallDocument total_mem_allocs 13.4019 2567633.0000 Avg: 2264189.3048
Med: 2235986.0000
Stdev: 115210.4092
0.8133 2.6338
BenchmarkSmallDocInsertOne total_bytes_allocated -13.2574 30273544.0000 Avg: 34900447.7241
Med: 35905872.0000
Stdev: 2262444.8240
0.7370 -2.0451
BenchmarkSmallDocInsertOne total_mem_allocs -12.9123 401132.0000 Avg: 460606.8276
Med: 474042.0000
Stdev: 29792.7532
0.7315 -1.9963
BenchmarkSingleFindOneByID total_mem_allocs -12.5149 1470096.0000 Avg: 1680395.0000
Med: 1709315.0000
Stdev: 85152.6241
0.8151 -2.4697
BenchmarkSingleFindOneByID total_bytes_allocated -12.5116 91465160.0000 Avg: 104545421.7143
Med: 106372280.0000
Stdev: 5363152.0498
0.8120 -2.4389
BenchmarkMultiInsertSmallDocument total_time_seconds 12.0679 1.1888 Avg: 1.0608
Med: 1.0467
Stdev: 0.0453
0.8275 2.8232
BenchmarkMultiInsertSmallDocument total_bytes_allocated 9.9103 489975872.0000 Avg: 445796119.6098
Med: 444907096.0000
Stdev: 14329521.9959
0.8323 3.0831
BenchmarkSmallDocInsertOne total_time_seconds -9.3380 1.0740 Avg: 1.1846
Med: 1.1849
Stdev: 0.0227
0.8901 -4.8702
BenchmarkSingleRunCommand total_time_seconds -6.3541 1.0461 Avg: 1.1171
Med: 1.1180
Stdev: 0.0350
0.7292 -2.0297
BenchmarkBSONFullDocumentEncoding total_time_seconds -1.9004 1.1721 Avg: 1.1948
Med: 1.1944
Stdev: 0.0084
0.7978 -2.7128
BenchmarkSingleRunCommand allocated_bytes_per_op -0.1423 12180.0000 Avg: 12197.3556
Med: 12197.0000
Stdev: 5.4404
0.8331 -3.1901

For a comprehensive view of all microbenchmark results for this PR's commit, please check out the Evergreen perf task for this patch.

Copy link
Contributor

API Change Report

No changes found!

Copy link
Collaborator

@qingyang-hu qingyang-hu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is a good approach. We can polish the script along the way. However, what are your thoughts on combining this one with "run-goleak-test.sh", or putting both in a tests sub-folder?

@matthewdale matthewdale added review-priority-low Low Priority PR for Review: within 3 business days ignore-for-release labels Sep 30, 2025
@matthewdale
Copy link
Collaborator Author

matthewdale commented Sep 30, 2025

@qingyang-hu The "run-goleak-test.sh" script doesn't support running any test like "profile-test.sh" does; it only runs the tests in the "internal/test/goleak" submodule. I'm not sure combining them would make sense.

I do think we should move most of the scripts in the "etc/" directory into the ".evergreen/" directory, but we should do that in another PR.

@matthewdale matthewdale requested a review from Copilot September 30, 2025 15:17
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@matthewdale matthewdale merged commit f8c0ec0 into mongodb:master Oct 2, 2025
33 of 35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ignore-for-release review-priority-low Low Priority PR for Review: within 3 business days
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants