Skip to content

pprof: take cpu and memory profiles by setting environment variables#2746

Merged
crazy-max merged 1 commit into
docker:masterfrom
jsternberg:buildx-profiles
Oct 25, 2024
Merged

pprof: take cpu and memory profiles by setting environment variables#2746
crazy-max merged 1 commit into
docker:masterfrom
jsternberg:buildx-profiles

Conversation

@jsternberg
Copy link
Copy Markdown
Collaborator

When run in standalone mode, the environment variables DOCKER_BUILDX_CPU_PROFILE and DOCKER_BUILDX_MEM_PROFILE will cause profiles to be written by the CLI.

Comment thread cmd/buildx/debug.go Outdated
}

func setupCPUProfile(ctx context.Context) (stop func()) {
if cpuProfile := os.Getenv("DOCKER_BUILDX_CPU_PROFILE"); cpuProfile != "" {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done. I also added a snippet to capture the log when this is run as a plugin too. It was previously just for standalone runs.

@dvdksn
Copy link
Copy Markdown
Contributor

dvdksn commented Oct 22, 2024

is this for 0.18.0?

Copy link
Copy Markdown
Member

@tonistiigi tonistiigi left a comment

Choose a reason for hiding this comment

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

There are couple of places in commands package that call os.Exit() directly and would skip these defers. Can be follow-up but needs tracking issue then.

Comment thread cmd/buildx/main.go Outdated
}

func runStandalone(cmd *command.DockerCli) error {
stopProfiles := setupDebugProfiles(context.TODO())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not call this from main() directly to avoid duplicate calls.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This can also be a single defer line

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is just a style thing. I find this easier to read.

@thompson-shaun thompson-shaun modified the milestones: v0.18.0, v0.19.0 Oct 23, 2024
When run in standalone mode, the environment variables
`DOCKER_BUILDX_CPU_PROFILE` and `DOCKER_BUILDX_MEM_PROFILE` will cause
profiles to be written by the CLI.

Signed-off-by: Jonathan A. Sternberg <[email protected]>
@jsternberg
Copy link
Copy Markdown
Collaborator Author

Refactored the run into a single function that calls runStandalone or runPlugin. The main reason for duplicating that code was because of the calls to os.Exit in the main function. We can tackle that with a future clean up since there are also some other places that I think call os.Exit when they shouldn't.

@crazy-max crazy-max merged commit 658ed58 into docker:master Oct 25, 2024
@thompson-shaun thompson-shaun modified the milestones: v0.19.0, v0.18.0 Oct 25, 2024
@crazy-max
Copy link
Copy Markdown
Member

@dvdksn For docs follow-up we could add docker/docs#21214 to contributing docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants