Skip to content

Add option to launch test with pprof profiling enabled #889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 21, 2025

Conversation

weswigham
Copy link
Member

I imagine this is a useful launch task/flag for tracing slow tests - basically just pulled from the go docs.

Verified

This commit was signed with the committer’s verified signature.
weswigham Wesley Wigham
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

This PR adds an option to launch tests with pprof profiling enabled, enabling developers to trace slow tests.

  • Introduces a global cpuprofile flag and integrates CPU profiling logic in runSingleConfigTest.
  • Adds a new launch configuration template in VSCode to run tests with profiling enabled.

Reviewed Changes

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

File Description
internal/testrunner/compiler_runner.go Adds cpuprofile flag and integrates pprof profiling within tests.
.vscode/launch.template.json Adds a launch configuration for running submodule tests with profiling.

func (r *CompilerBaselineRunner) runSingleConfigTest(t *testing.T, testName string, test *compilerFileBasedTest, config *harnessutil.NamedTestConfiguration) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on compiling test "+test.filename)

payload := makeUnitsFromTest(test.content, test.filename)
compilerTest := newCompilerTest(t, testName, test.filename, &payload, config)

if *cpuprofile != "" {
Copy link
Preview

Copilot AI May 20, 2025

Choose a reason for hiding this comment

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

Using pprof.StartCPUProfile within a parallel test (set with t.Parallel()) may lead to concurrent invocations, which is not thread-safe as only one profile can run at a time. Consider restricting profiling to serial execution or adding synchronization to prevent overlapping profiling sessions.

Copilot uses AI. Check for mistakes.

Copy link
Member Author

@weswigham weswigham May 20, 2025

Choose a reason for hiding this comment

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

Probably correct, but the expectation is you'll only invoke the test runner with profiling on for a single test, so.... 🤷

Verified

This commit was signed with the committer’s verified signature.
weswigham Wesley Wigham
@jakebailey
Copy link
Member

You actually don't need to do this manually; go test has it built in. I test with:

go test -cpuprofile=cpu.out -memprofile=mem.out ./internal/testrunner

@weswigham
Copy link
Member Author

Oh, excellent - I'll swap to a launch task for that, then.

Verified

This commit was signed with the committer’s verified signature.
weswigham Wesley Wigham

Verified

This commit was signed with the committer’s verified signature.
weswigham Wesley Wigham
@weswigham weswigham added this pull request to the merge queue May 21, 2025
Merged via the queue into microsoft:main with commit 5cae442 May 21, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants