Skip to content
This repository was archived by the owner on Sep 1, 2026. It is now read-only.

cmd: introduce profiling options - #516

Merged
lzap merged 2 commits into
osbuild:mainfrom
lzap:pprof-opts1
May 21, 2026
Merged

lzap merged 2 commits into
osbuild:mainfrom
lzap:pprof-opts1

Conversation

@lzap

@lzap lzap commented May 13, 2026

Copy link
Copy Markdown
Contributor

Add persistent flags --memprofile, --memprofile-goroutine, and --memprofile-rate. Heap and goroutine profiles are written in Go pprof format when the process exits, including on command failure, so runs can be analyzed with the toolchain from go.mod (e.g. go tool pprof).

When profiling is off, allocation sampling is not enabled for the image-builder CLI: MemProfileRate is reset at the start of run() and stays zero unless a command sets --memprofile, in which case MemProfileRate follows --memprofile-rate (-1 means Go's default 524288).

image-builder -v manifest ... --memprofile /tmp/heap.pprof \
    --memprofile-goroutine /tmp/goroutine.pprof
go tool pprof -http=:8080 /tmp/heap.pprof

@lzap
lzap requested a review from a team as a code owner May 13, 2026 08:31
@croissanne

croissanne commented May 13, 2026 •

Copy link
Copy Markdown
Member

Would it make sense to use build tags here? That way we can add them for debug builds and stuff. I'm not sure if we want to have these flags be part of our release builds.

@supakeen supakeen left a comment

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.

I'd like to have these things but like @croissanne says they should be behind a build flag/tag so we don't ship this in production executables.

@lzap

lzap commented May 14, 2026

Copy link
Copy Markdown
Contributor Author

Sure, rebased.

Comment thread cmd/image-builder/memprofile.go Resolved
brlane-rht
brlane-rht previously approved these changes May 14, 2026

@brlane-rht brlane-rht left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good other than my one small comment.

@lzap

lzap commented May 14, 2026

Copy link
Copy Markdown
Contributor Author

Rebased your suggestion, also added a bit of documentation to each method.

@brlane-rht brlane-rht left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good.

@supakeen
supakeen added this pull request to the merge queue May 20, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 20, 2026
@supakeen

supakeen commented May 20, 2026 •

Copy link
Copy Markdown
Member

Will need a rebase on #520 which contains the fix for CI. Let's do that after it hits main so we don't lose acks here.

lzap and others added 2 commits May 21, 2026 13:35
After json.Indent fills a bytes.Buffer, stream the buffer to the output writer with WriteTo instead of fmt.Fprintf(..., pretty.String()). That avoids allocating a second copy of the entire indented manifest as a string, which matters for large manifests.

Co-authored-by: Cursor <[email protected]>
These are only available when building with the DEBUG=1 make target.
@lzap

lzap commented May 21, 2026

Copy link
Copy Markdown
Contributor Author

Rebased.

@lzap
lzap enabled auto-merge May 21, 2026 11:36
@lzap
lzap added this pull request to the merge queue May 21, 2026
Merged via the queue into osbuild:main with commit 0e02b05 May 21, 2026
39 checks passed
@lzap
lzap deleted the pprof-opts1 branch May 21, 2026 12:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants