diff --git a/cli/helpers.go b/cli/helpers.go index d5c06d3..2ce9a46 100644 --- a/cli/helpers.go +++ b/cli/helpers.go @@ -465,13 +465,19 @@ func discoverAvailableProfiles(tag, benchmarkName string) ([]string, error) { } func runTUI(_ *cobra.Command, _ []string) error { - benchNames, err := benchmark.DiscoverBenchmarks() + // Get current working directory for scope-aware benchmark discovery + currentDir, err := os.Getwd() + if err != nil { + return fmt.Errorf("failed to get current working directory: %w", err) + } + + benchNames, err := benchmark.DiscoverBenchmarks(currentDir) if err != nil { return fmt.Errorf("failed to discover benchmarks: %w", err) } if len(benchNames) == 0 { - return errors.New("no benchmarks found in this module (look for func BenchmarkXxx(b *testing.B) in *_test.go)") + return errors.New("no benchmarks found in this directory or its subdirectories (look for func BenchmarkXxx(b *testing.B) in *_test.go)") } var selectedBenches []string diff --git a/engine/benchmark/api.go b/engine/benchmark/api.go index 685b837..051d4c6 100644 --- a/engine/benchmark/api.go +++ b/engine/benchmark/api.go @@ -48,11 +48,23 @@ func RunBenchmarks(benchmarks, profiles []string, tag string, count int) error { // A benchmark is identified by functions matching: // // func BenchmarkXxx(b *testing.B) { ... } -func DiscoverBenchmarks() ([]string, error) { - root, err := internal.FindGoModuleRoot() - if err != nil { - return nil, fmt.Errorf("failed to locate module root: %w", err) +// +// If scope is provided, only searches within that directory and its subdirectories. +// If scope is empty, searches the entire module from the root. +func DiscoverBenchmarks(scope string) ([]string, error) { + var searchRoot string + var err error + + if scope != "" { + // Use the provided scope directory + searchRoot = scope + } else { + // Fall back to searching from module root + searchRoot, err = internal.FindGoModuleRoot() + if err != nil { + return nil, fmt.Errorf("failed to locate module root: %w", err) + } } - return scanForBenchmarks(root) + return scanForBenchmarks(searchRoot) }