cmd: introduce profiling options#516
Conversation
|
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
left a comment
There was a problem hiding this comment.
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.
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 <cursoragent@cursor.com>
|
Sure, rebased. |
| f.IntVar(&memProfileRateOpt, "memprofile-rate", -1, "when --memprofile is set, sets runtime.MemProfileRate for allocation sampling (-1 uses Go's default 524288; 0 samples only live heap at exit with minimal runtime overhead)") | ||
| } | ||
|
|
||
| func memProfilePersistentPreRun(_ *cobra.Command, _ []string) { |
There was a problem hiding this comment.
This is a bit hard to read. It looks like the rate is always 0 unless memProfilePath is used, so memProfileGoroutinePath doesn't matter. I'd unconditionally set it to 0 first, then override that with the if memProfilePath != "" { block.
brlane-rht
left a comment
There was a problem hiding this comment.
Looks good other than my one small comment.
These are only available when building with the DEBUG=1 make target.
|
Rebased your suggestion, also added a bit of documentation to each method. |
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).