From fb52ac6a554a1b7610d105e9bbb2e0bab68cf438 Mon Sep 17 00:00:00 2001 From: Julian Knutsen Date: Tue, 28 Jul 2026 22:17:13 -0700 Subject: [PATCH] refactor(cli): rename CPU profiling flag (#5126) Free the conventional --profile namespace for named database profiles while retaining the existing CPU and trace behavior under --cpu-profile. Agent-Signature: codex-gpt-5.6-terra-high on behalf of CI Bot Refs: bd-ugz Co-authored-by: CI Bot --- .gitignore | 2 +- cmd/bd/cpu_profile_test.go | 19 +++++++++++++++++++ cmd/bd/main.go | 6 +++--- 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 cmd/bd/cpu_profile_test.go diff --git a/.gitignore b/.gitignore index a321cc3ba..c5d2e31b2 100644 --- a/.gitignore +++ b/.gitignore @@ -101,7 +101,7 @@ __pycache__/ .Python .envrc -# Performance profiling files (benchmarks, bd doctor --perf, and bd --profile) +# Performance profiling files (benchmarks, bd doctor --perf, and bd --cpu-profile) *.prof *.out beads-perf-*.prof diff --git a/cmd/bd/cpu_profile_test.go b/cmd/bd/cpu_profile_test.go new file mode 100644 index 000000000..5d74046a1 --- /dev/null +++ b/cmd/bd/cpu_profile_test.go @@ -0,0 +1,19 @@ +package main + +import "testing" + +func TestCPUProfileFlagRegistered(t *testing.T) { + flag := rootCmd.PersistentFlags().Lookup("cpu-profile") + if flag == nil { + t.Fatal("--cpu-profile persistent flag is not registered") + } + if got, want := flag.Value.Type(), "bool"; got != want { + t.Errorf("--cpu-profile flag type = %q, want %q", got, want) + } + if got, want := flag.Usage, "Generate CPU profile for performance analysis"; got != want { + t.Errorf("--cpu-profile usage = %q, want %q", got, want) + } + if old := rootCmd.PersistentFlags().Lookup("profile"); old != nil { + t.Error("--profile must not remain registered as the CPU profiling flag") + } +} diff --git a/cmd/bd/main.go b/cmd/bd/main.go index 732cc1a53..52d7d0603 100644 --- a/cmd/bd/main.go +++ b/cmd/bd/main.go @@ -87,7 +87,7 @@ var ( storeIsReadOnly bool // Track if store was opened read-only (for staleness checks) ignoreSchemaSkew bool // Proceed despite forward schema drift lockTimeout = 30 * time.Second // Dolt open timeout (fixed default) - profileEnabled bool + cpuProfileEnabled bool profileFile *os.File traceFile *os.File memProfilePath string @@ -683,7 +683,7 @@ func init() { rootCmd.PersistentFlags().BoolVar(&readonlyMode, "readonly", false, "Read-only mode: block write operations (for worker sandboxes)") rootCmd.PersistentFlags().BoolVar(&globalFlag, "global", false, "Use the global shared-server database (beads_global)") rootCmd.PersistentFlags().StringVar(&doltAutoCommit, "dolt-auto-commit", "", "Dolt auto-commit policy (off|on|batch). 'on': commit after each write. 'batch': defer commits to bd dolt commit; uncommitted changes persist in the working set until then. SIGTERM/SIGHUP flush pending batch commits. Default: off. Override via config key dolt.auto-commit") - rootCmd.PersistentFlags().BoolVar(&profileEnabled, "profile", false, "Generate CPU profile for performance analysis") + rootCmd.PersistentFlags().BoolVar(&cpuProfileEnabled, "cpu-profile", false, "Generate CPU profile for performance analysis") rootCmd.PersistentFlags().StringVar(&memProfilePath, "mem-profile", "", "Write heap profile to FILE on exit (also respects BEADS_MEM_PROFILE)") rootCmd.PersistentFlags().BoolVarP(&verboseFlag, "verbose", "v", false, "Enable verbose/debug output") rootCmd.PersistentFlags().BoolVarP(&quietFlag, "quiet", "q", false, "Suppress non-essential output (errors only)") @@ -1060,7 +1060,7 @@ var rootCmd = &cobra.Command{ } // Performance profiling setup - if profileEnabled { + if cpuProfileEnabled { timestamp := time.Now().Format("20060102-150405") if f, _ := os.Create(fmt.Sprintf("bd-profile-%s-%s.prof", cmd.Name(), timestamp)); f != nil { profileFile = f