@@ -2,15 +2,11 @@ package cli
22
33import (
44 "fmt"
5- "os"
6- "path/filepath"
75 "strconv"
8- "strings"
96
107 "github.com/AlecAivazis/survey/v2"
118
129 "github.com/AlexsanderHamir/prof/engine/tracker"
13- "github.com/AlexsanderHamir/prof/internal"
1410)
1511
1612// getTrackSelections collects all user selections interactively
@@ -143,99 +139,3 @@ func selectRegressionThreshold(selections *tracker.Selections) error {
143139
144140 return nil
145141}
146-
147- // setGlobalTrackingVariables sets the global CLI variables for tracking
148- func setGlobalTrackingVariables (selections * tracker.Selections ) {
149- Baseline = selections .Baseline
150- Current = selections .Current
151- benchmarkName = selections .BenchmarkName
152- profileType = selections .ProfileType
153- outputFormat = selections .OutputFormat
154- failOnRegression = selections .UseThreshold
155- regressionThreshold = selections .RegressionThreshold
156- }
157-
158- // discoverAvailableTags scans the bench directory for existing tags
159- func discoverAvailableTags () ([]string , error ) {
160- root , err := internal .FindGoModuleRoot ()
161- if err != nil {
162- return nil , fmt .Errorf ("failed to locate module root: %w" , err )
163- }
164-
165- benchDir := filepath .Join (root , internal .MainDirOutput )
166- entries , err := os .ReadDir (benchDir )
167- if err != nil {
168- if os .IsNotExist (err ) {
169- return []string {}, nil
170- }
171- return nil , fmt .Errorf ("failed to read bench directory: %w" , err )
172- }
173-
174- var tags []string
175- for _ , entry := range entries {
176- if entry .IsDir () {
177- tags = append (tags , entry .Name ())
178- }
179- }
180-
181- return tags , nil
182- }
183-
184- // discoverAvailableBenchmarks scans a specific tag directory for available benchmarks
185- func discoverAvailableBenchmarks (tag string ) ([]string , error ) {
186- root , err := internal .FindGoModuleRoot ()
187- if err != nil {
188- return nil , fmt .Errorf ("failed to locate module root: %w" , err )
189- }
190-
191- benchDir := filepath .Join (root , internal .MainDirOutput , tag , internal .ProfileTextDir )
192- entries , err := os .ReadDir (benchDir )
193- if err != nil {
194- if os .IsNotExist (err ) {
195- return []string {}, nil
196- }
197- return nil , fmt .Errorf ("failed to read benchmark directory for tag %s: %w" , tag , err )
198- }
199-
200- var availableBenchmarks []string
201- for _ , entry := range entries {
202- if entry .IsDir () {
203- availableBenchmarks = append (availableBenchmarks , entry .Name ())
204- }
205- }
206-
207- return availableBenchmarks , nil
208- }
209-
210- // discoverAvailableProfiles scans a specific tag and benchmark for available profile types
211- func discoverAvailableProfiles (tag , benchmarkName string ) ([]string , error ) {
212- root , err := internal .FindGoModuleRoot ()
213- if err != nil {
214- return nil , fmt .Errorf ("failed to locate module root: %w" , err )
215- }
216-
217- benchDir := filepath .Join (root , internal .MainDirOutput , tag , internal .ProfileTextDir , benchmarkName )
218- entries , err := os .ReadDir (benchDir )
219- if err != nil {
220- if os .IsNotExist (err ) {
221- return []string {}, nil
222- }
223- return nil , fmt .Errorf ("failed to read profile directory for tag %s, benchmark %s: %w" , tag , benchmarkName , err )
224- }
225-
226- var availableProfiles []string
227- for _ , entry := range entries {
228- if ! entry .IsDir () && strings .HasSuffix (entry .Name (), ".txt" ) {
229- // Extract profile type from filename like "BenchmarkName_cpu.txt"
230- name := entry .Name ()
231- if strings .HasPrefix (name , benchmarkName + "_" ) {
232- profileTypeName := strings .TrimSuffix (strings .TrimPrefix (name , benchmarkName + "_" ), ".txt" )
233- if profileTypeName == "cpu" || profileTypeName == "memory" || profileTypeName == "mutex" || profileTypeName == "block" {
234- availableProfiles = append (availableProfiles , profileTypeName )
235- }
236- }
237- }
238- }
239-
240- return availableProfiles , nil
241- }
0 commit comments