@@ -6,17 +6,19 @@ import (
66 "log/slog"
77
88 "github.com/AlexsanderHamir/prof/args"
9+ "github.com/AlexsanderHamir/prof/benchmark"
910 "github.com/AlexsanderHamir/prof/collector"
1011 "github.com/AlexsanderHamir/prof/config"
12+ "github.com/AlexsanderHamir/prof/shared"
1113 "github.com/AlexsanderHamir/prof/tracker"
1214 "github.com/AlexsanderHamir/prof/version"
1315 "github.com/spf13/cobra"
1416)
1517
1618var (
1719 // Root command flags.
18- benchmarks string
19- profiles string
20+ benchmarks [] string
21+ profiles [] string
2022 tag string
2123 count int
2224
@@ -48,16 +50,16 @@ func CreateRootCmd() *cobra.Command {
4850func createManualCmd () * cobra.Command {
4951 manualCmd := & cobra.Command {
5052 Use : "manual" ,
51- Short : "Receives profile files and performs data collection and organization." ,
53+ Short : "Receives profile files and performs data collection and organization. (doesn't wrap go test) " ,
5254 Args : cobra .MinimumNArgs (1 ),
53- Example : "prof manual cpu.prof memory.prof block.prof" ,
55+ Example : "prof manual --tag tagName cpu.prof memory.prof block.prof mutex .prof" ,
5456 RunE : func (_ * cobra.Command , args []string ) error {
5557 return collector .RunCollector (args , tag )
5658 },
5759 }
5860
5961 tagFlag := "tag"
60- manualCmd .Flags ().StringVar (& tag , tagFlag , "" , "Tag for organization " )
62+ manualCmd .Flags ().StringVar (& tag , tagFlag , "" , "The tag is used to organize the results " )
6163 _ = manualCmd .MarkFlagRequired (tagFlag )
6264
6365 return manualCmd
@@ -68,8 +70,7 @@ func createRunCmd() *cobra.Command {
6870 profileFlag := "profiles"
6971 tagFlag := "tag"
7072 countFlag := "count"
71- example := fmt .Sprintf (`prof run --%s "[BenchmarkGenPool]" --%s "[cpu,memory]" --%s 10 --%s "tag1"` ,
72- benchFlag , profileFlag , countFlag , tagFlag )
73+ example := fmt .Sprintf (`prof run --%s BenchmarkGenPool --%s cpu,memory --%s 10 --%s "tag1"` , benchFlag , profileFlag , countFlag , tagFlag )
7374
7475 runCmd := & cobra.Command {
7576 Use : "run" ,
@@ -78,9 +79,9 @@ func createRunCmd() *cobra.Command {
7879 Example : example ,
7980 }
8081
81- runCmd .Flags ().StringVar (& benchmarks , benchFlag , "" , `Benchmarks to run (e.g., "[BenchmarkGenPool]")"` )
82- runCmd .Flags ().StringVar (& profiles , profileFlag , "" , `Profiles to use (e.g., "[cpu,memory,mutex]")` )
83- runCmd .Flags ().StringVar (& tag , tagFlag , "" , "Tag for the run " )
82+ runCmd .Flags ().StringSliceVar (& benchmarks , benchFlag , [] string {} , `Benchmarks to run (e.g., "[BenchmarkGenPool]")"` )
83+ runCmd .Flags ().StringSliceVar (& profiles , profileFlag , [] string {} , `Profiles to use (e.g., "[cpu,memory,mutex]")` )
84+ runCmd .Flags ().StringVar (& tag , tagFlag , "" , "The tag is used to organize the results " )
8485 runCmd .Flags ().IntVar (& count , countFlag , 0 , "Number of runs" )
8586
8687 _ = runCmd .MarkFlagRequired (benchFlag )
@@ -153,34 +154,33 @@ func Execute() error {
153154}
154155
155156func runBenchmarks (_ * cobra.Command , _ []string ) error {
156- if benchmarks == "" || profiles == "" || tag == "" || count == 0 {
157- return errors .New ("missing required arguments. Use --help for usage information " )
157+ if len ( benchmarks ) == 0 {
158+ return errors .New ("benchmarks flag is empty " )
158159 }
159160
160- cfg , err := config .LoadFromFile ("config_template.json" )
161- if err != nil {
162- cfg = & config.Config {}
161+ if len (profiles ) == 0 {
162+ return errors .New ("profiles flag is empty" )
163163 }
164164
165- benchmarkList , profileList , err := parseAndValidateBenchmarkParams ( benchmarks , profiles )
165+ cfg , err := config . LoadFromFile ( shared . ConfigFilename )
166166 if err != nil {
167- return fmt . Errorf ( "failed to parse benchmark config: %w" , err )
167+ cfg = & config. Config {}
168168 }
169169
170- if err = setupDirectories (tag , benchmarkList , profileList ); err != nil {
170+ if err = benchmark . SetupDirectories (tag , benchmarks , profiles ); err != nil {
171171 return fmt .Errorf ("failed to setup directories: %w" , err )
172172 }
173173
174174 benchArgs := & args.BenchArgs {
175- Benchmarks : benchmarkList ,
176- Profiles : profileList ,
175+ Benchmarks : benchmarks ,
176+ Profiles : profiles ,
177177 Count : count ,
178178 Tag : tag ,
179179 }
180180
181181 printConfiguration (benchArgs , cfg .FunctionFilter )
182182
183- if err = runBencAndGetProfiles (benchArgs , cfg .FunctionFilter ); err != nil {
183+ if err = runBenchAndGetProfiles (benchArgs , cfg .FunctionFilter ); err != nil {
184184 return err
185185 }
186186
@@ -202,10 +202,6 @@ func runSetup(_ *cobra.Command, _ []string) error {
202202
203203// runTrack handles the track command execution
204204func runTrack (_ * cobra.Command , _ []string ) error {
205- if ! validProfiles [profileType ] {
206- return fmt .Errorf ("invalid profile type '%s'. Valid types: cpu, memory, mutex, block" , profileType )
207- }
208-
209205 validFormats := map [string ]bool {
210206 "summary" : true ,
211207 "detailed" : true ,
@@ -215,20 +211,13 @@ func runTrack(_ *cobra.Command, _ []string) error {
215211 return fmt .Errorf ("invalid output format '%s'. Valid formats: summary, detailed" , outputFormat )
216212 }
217213
218- // Call the tracker API
219- report , err := tracker .CheckPerformanceDifferences (
220- baselineTag ,
221- currentTag ,
222- benchmarkName ,
223- profileType ,
224- )
225-
214+ report , err := tracker .CheckPerformanceDifferences (baselineTag , currentTag , benchmarkName , profileType )
226215 if err != nil {
227216 return fmt .Errorf ("failed to track performance differences: %w" , err )
228217 }
229218
230- // Display results based on output format
231- if len ( report . FunctionChanges ) == 0 {
219+ noFunctionChanges := len ( report . FunctionChanges ) == 0
220+ if noFunctionChanges {
232221 slog .Info ("No function changes detected between the two runs" )
233222 return nil
234223 }
0 commit comments