Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ out/

# Temp files
x.*
*.out
*.test

diagnose-*/

Expand Down
17 changes: 16 additions & 1 deletion internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"context"
"os"
"os/signal"
"runtime"
"runtime/pprof"
"syscall"

"charm.land/fang/v2"
Expand Down Expand Up @@ -40,6 +42,8 @@ func NewRootCommand(runnerOpts hooks.RunOptions) *cobra.Command {

rootCmd.PersistentFlags().
Bool("ai-output", !term.IsTerminal(os.Stdout.Fd()), "Use sparse output for agent tooling (and robotic humans)")
rootCmd.PersistentFlags().String("memprofile", "", "write memory profile to this file")
_ = rootCmd.PersistentFlags().MarkHidden("memprofile")
hooks.RegisterPersistentFlags(rootCmd.PersistentFlags())

gotestsumCmd := newGotestsumCmd(runnerOpts)
Expand Down Expand Up @@ -88,5 +92,16 @@ func runExecute(opts ...hooks.Option) error {
// Root forwards unknown flags (including go test -v) to go test; fang's -v is version.
fang.WithoutVersion(),
}
return fang.Execute(ctx, rootCmd, fangOpts...)
err := fang.Execute(ctx, rootCmd, fangOpts...)

if memprofile, _ := rootCmd.Flags().GetString("memprofile"); memprofile != "" {
f, createErr := os.Create(memprofile) //nolint:gosec // G304: memprofile path requested by user
if createErr == nil {
runtime.GC() // Get up-to-date statistics
_ = pprof.WriteHeapProfile(f)
_ = f.Close()
}
}

return err
}
Loading
Loading