Skip to content

Commit ec00baf

Browse files
Merge pull request #70 from AlexsanderHamir/refactors
Implements Parts of #67
2 parents fdd94d9 + df6e8cf commit ec00baf

33 files changed

+96
-1440
lines changed

cli/helpers.go

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ var (
2525
count int
2626

2727
// Track command flags.
28-
baselineTag string
29-
currentTag string
28+
Baseline string
29+
Current string
3030
benchmarkName string
3131
profileType string
3232
outputFormat string
@@ -117,13 +117,13 @@ func createTrackCmd() *cobra.Command {
117117

118118
func createTrackAutoCmd() *cobra.Command {
119119
baseTagFlag := "base"
120-
currentTagFlag := "current"
120+
currentFlag := "current"
121121
benchNameFlag := "bench-name"
122122
profileTypeFlag := "profile-type"
123123
outputFormatFlag := "output-format"
124124
failFlag := "fail-on-regression"
125125
thresholdFlag := "regression-threshold"
126-
example := fmt.Sprintf(`prof track auto --%s "tag1" --%s "tag2" --%s "cpu" --%s "BenchmarkGenPool" --%s "summary"`, baseTagFlag, currentTagFlag, profileTypeFlag, benchNameFlag, outputFormatFlag)
126+
example := fmt.Sprintf(`prof track auto --%s "tag1" --%s "tag2" --%s "cpu" --%s "BenchmarkGenPool" --%s "summary"`, baseTagFlag, currentFlag, profileTypeFlag, benchNameFlag, outputFormatFlag)
127127
longExplanation := fmt.Sprintf("This command only works if the %s command was used to collect and organize the benchmark and profile data, as it expects a specific directory structure generated by that process.", internal.AUTOCMD)
128128
shortExplanation := "If prof auto was used to collect the data, track auto can be used to analyze it, you just have to pass the tag name."
129129

@@ -134,8 +134,8 @@ func createTrackAutoCmd() *cobra.Command {
134134
RunE: func(_ *cobra.Command, _ []string) error {
135135
selections := &tracker.Selections{
136136
OutputFormat: outputFormat,
137-
BaselineTag: baselineTag,
138-
CurrentTag: currentTag,
137+
Baseline: Baseline,
138+
Current: Current,
139139
ProfileType: profileType,
140140
BenchmarkName: benchmarkName,
141141
RegressionThreshold: regressionThreshold,
@@ -146,16 +146,16 @@ func createTrackAutoCmd() *cobra.Command {
146146
Example: example,
147147
}
148148

149-
cmd.Flags().StringVar(&baselineTag, baseTagFlag, "", "Name of the baseline tag")
150-
cmd.Flags().StringVar(&currentTag, currentTagFlag, "", "Name of the current tag")
149+
cmd.Flags().StringVar(&Baseline, baseTagFlag, "", "Name of the baseline tag")
150+
cmd.Flags().StringVar(&Current, currentFlag, "", "Name of the current tag")
151151
cmd.Flags().StringVar(&benchmarkName, benchNameFlag, "", "Name of the benchmark")
152152
cmd.Flags().StringVar(&profileType, profileTypeFlag, "", "Profile type (cpu, memory, mutex, block)")
153153
cmd.Flags().StringVar(&outputFormat, outputFormatFlag, "detailed", `Output format: "summary" or "detailed"`)
154154
cmd.Flags().BoolVar(&failOnRegression, failFlag, false, "Exit with non-zero code if regression exceeds threshold")
155155
cmd.Flags().Float64Var(&regressionThreshold, thresholdFlag, 0.0, "Fail when worst flat regression exceeds this percent (e.g., 5.0)")
156156

157157
_ = cmd.MarkFlagRequired(baseTagFlag)
158-
_ = cmd.MarkFlagRequired(currentTagFlag)
158+
_ = cmd.MarkFlagRequired(currentFlag)
159159
_ = cmd.MarkFlagRequired(benchNameFlag)
160160
_ = cmd.MarkFlagRequired(profileTypeFlag)
161161

@@ -176,8 +176,8 @@ func createTrackManualCmd() *cobra.Command {
176176
RunE: func(_ *cobra.Command, _ []string) error {
177177
selections := &tracker.Selections{
178178
OutputFormat: outputFormat,
179-
BaselineTag: baselineTag,
180-
CurrentTag: currentTag,
179+
Baseline: Baseline,
180+
Current: Current,
181181
ProfileType: profileType,
182182
BenchmarkName: benchmarkName,
183183
RegressionThreshold: regressionThreshold,
@@ -189,8 +189,8 @@ func createTrackManualCmd() *cobra.Command {
189189
Example: example,
190190
}
191191

192-
cmd.Flags().StringVar(&baselineTag, baseFlag, "", "Name of the baseline tag")
193-
cmd.Flags().StringVar(&currentTag, currentFlag, "", "Name of the current tag")
192+
cmd.Flags().StringVar(&Baseline, baseFlag, "", "Name of the baseline tag")
193+
cmd.Flags().StringVar(&Current, currentFlag, "", "Name of the current tag")
194194
cmd.Flags().StringVar(&outputFormat, outputFormatFlag, "", "Output format choice choice")
195195
cmd.Flags().BoolVar(&failOnRegression, failFlag, false, "Exit with non-zero code if regression exceeds threshold")
196196
cmd.Flags().Float64Var(&regressionThreshold, thresholdFlag, 0.0, "Fail when worst flat regression exceeds this percent (e.g., 5.0)")
@@ -225,24 +225,24 @@ func getTrackSelections(tags []string) (*tracker.Selections, error) {
225225
Options: tags,
226226
PageSize: tuiPageSize,
227227
}
228-
if err := survey.AskOne(baselinePrompt, &selections.BaselineTag, survey.WithValidator(survey.Required)); err != nil {
228+
if err := survey.AskOne(baselinePrompt, &selections.Baseline, survey.WithValidator(survey.Required)); err != nil {
229229
return nil, err
230230
}
231231

232232
// Select current tag (filter out baseline)
233-
var currentTagOptions []string
233+
var currentOptions []string
234234
for _, tag := range tags {
235-
if tag != selections.BaselineTag {
236-
currentTagOptions = append(currentTagOptions, tag)
235+
if tag != selections.Baseline {
236+
currentOptions = append(currentOptions, tag)
237237
}
238238
}
239239

240240
currentPrompt := &survey.Select{
241241
Message: "Select current tag (the 'after' version) [Press Enter to select]:",
242-
Options: currentTagOptions,
242+
Options: currentOptions,
243243
PageSize: tuiPageSize,
244244
}
245-
if err := survey.AskOne(currentPrompt, &selections.CurrentTag, survey.WithValidator(survey.Required)); err != nil {
245+
if err := survey.AskOne(currentPrompt, &selections.Current, survey.WithValidator(survey.Required)); err != nil {
246246
return nil, err
247247
}
248248

@@ -271,12 +271,12 @@ func getTrackSelections(tags []string) (*tracker.Selections, error) {
271271

272272
// selectBenchmark discovers and selects a benchmark
273273
func selectBenchmark(selections *tracker.Selections) error {
274-
availableBenchmarks, err := discoverAvailableBenchmarks(selections.BaselineTag)
274+
availableBenchmarks, err := discoverAvailableBenchmarks(selections.Baseline)
275275
if err != nil {
276-
return fmt.Errorf("failed to discover benchmarks for tag %s: %w", selections.BaselineTag, err)
276+
return fmt.Errorf("failed to discover benchmarks for tag %s: %w", selections.Baseline, err)
277277
}
278278
if len(availableBenchmarks) == 0 {
279-
return fmt.Errorf("no benchmarks found for tag %s", selections.BaselineTag)
279+
return fmt.Errorf("no benchmarks found for tag %s", selections.Baseline)
280280
}
281281

282282
benchPrompt := &survey.Select{
@@ -289,12 +289,12 @@ func selectBenchmark(selections *tracker.Selections) error {
289289

290290
// selectProfileType discovers and selects a profile type
291291
func selectProfileType(selections *tracker.Selections) error {
292-
availableProfiles, err := discoverAvailableProfiles(selections.BaselineTag, selections.BenchmarkName)
292+
availableProfiles, err := discoverAvailableProfiles(selections.Baseline, selections.BenchmarkName)
293293
if err != nil {
294-
return fmt.Errorf("failed to discover profiles for tag %s, benchmark %s: %w", selections.BaselineTag, selections.BenchmarkName, err)
294+
return fmt.Errorf("failed to discover profiles for tag %s, benchmark %s: %w", selections.Baseline, selections.BenchmarkName, err)
295295
}
296296
if len(availableProfiles) == 0 {
297-
return fmt.Errorf("no profiles found for tag %s, benchmark %s", selections.BaselineTag, selections.BenchmarkName)
297+
return fmt.Errorf("no profiles found for tag %s, benchmark %s", selections.Baseline, selections.BenchmarkName)
298298
}
299299

300300
profilePrompt := &survey.Select{
@@ -348,8 +348,8 @@ func selectRegressionThreshold(selections *tracker.Selections) error {
348348

349349
// setGlobalTrackingVariables sets the global CLI variables for tracking
350350
func setGlobalTrackingVariables(selections *tracker.Selections) {
351-
baselineTag = selections.BaselineTag
352-
currentTag = selections.CurrentTag
351+
Baseline = selections.Baseline
352+
Current = selections.Current
353353
benchmarkName = selections.BenchmarkName
354354
profileType = selections.ProfileType
355355
outputFormat = selections.OutputFormat
@@ -540,7 +540,7 @@ func runTUITrackAuto(_ *cobra.Command, _ []string) error {
540540

541541
// Now run the actual tracking command
542542
fmt.Printf("\n🚀 Running: prof track auto --base %s --current %s --bench-name %s --profile-type %s --output-format %s",
543-
selections.BaselineTag, selections.CurrentTag, selections.BenchmarkName, selections.ProfileType, selections.OutputFormat)
543+
selections.Baseline, selections.Current, selections.BenchmarkName, selections.ProfileType, selections.OutputFormat)
544544
if selections.UseThreshold {
545545
fmt.Printf(" --fail-on-regression --regression-threshold %.1f", selections.RegressionThreshold)
546546
}

engine/benchmark/helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ func collectProfileFunctions(args *internal.CollectionArgs) error {
464464
return fmt.Errorf("failed to create output directory: %w", err)
465465
}
466466

467-
functions, err := parser.GetAllFunctionNames(paths.ProfileTextFile, args.BenchmarkConfig)
467+
functions, err := parser.GetAllFunctionNamesV2(paths.ProfileBinaryFile, args.BenchmarkConfig)
468468
if err != nil {
469469
return fmt.Errorf("failed to extract function names: %w", err)
470470
}

engine/collector/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func RunCollector(files []string, tag string) error {
5454
return err
5555
}
5656

57-
if err = collectFunctions(outputTextFilePath, profileDirPath, fullBinaryPath, functionFilter); err != nil {
57+
if err = collectFunctions(profileDirPath, fullBinaryPath, functionFilter); err != nil {
5858
return fmt.Errorf("collectFunctions failed: %w", err)
5959
}
6060
}

engine/collector/helpers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ func getFunctionPprofContent(function, binaryFile, outputFile string) error {
4343
return nil
4444
}
4545

46-
func collectFunctions(outputTextFilePath, profileDirPath, fullBinaryPath string, functionFilter internal.FunctionFilter) error {
46+
func collectFunctions(profileDirPath, fullBinaryPath string, functionFilter internal.FunctionFilter) error {
4747
var functions []string
48-
functions, err := parser.GetAllFunctionNames(outputTextFilePath, functionFilter)
48+
functions, err := parser.GetAllFunctionNamesV2(fullBinaryPath, functionFilter)
4949
if err != nil {
5050
return fmt.Errorf("failed to extract function names: %w", err)
5151
}

engine/tracker/api.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99

1010
// trackAutoSelections holds all the user selections for tracking
1111
type Selections struct {
12-
BaselineTag string
13-
CurrentTag string
12+
Baseline string
13+
Current string
1414
BenchmarkName string
1515
ProfileType string
1616
OutputFormat string
@@ -88,16 +88,16 @@ func RunTrackManual(selections *Selections) error {
8888

8989
// CheckPerformanceDifferences creates the profile report by comparing data from prof's auto run.
9090
func CheckPerformanceDifferences(selections *Selections) (*ProfileChangeReport, error) {
91-
textFilePathBaseLine, textFilePathCurrent := chooseFileLocations(selections)
91+
binFilePathBaseLine, binFilePathCurrent := chooseFileLocations(selections)
9292

93-
lineObjsBaseline, err := parser.TurnLinesIntoObjects(textFilePathBaseLine)
93+
lineObjsBaseline, err := parser.TurnLinesIntoObjectsV2(binFilePathBaseLine)
9494
if err != nil {
95-
return nil, fmt.Errorf("couldn't get objs for path: %s, error: %w", textFilePathBaseLine, err)
95+
return nil, fmt.Errorf("couldn't get objs for path: %s, error: %w", binFilePathBaseLine, err)
9696
}
9797

98-
lineObjsCurrent, err := parser.TurnLinesIntoObjects(textFilePathCurrent)
98+
lineObjsCurrent, err := parser.TurnLinesIntoObjectsV2(binFilePathCurrent)
9999
if err != nil {
100-
return nil, fmt.Errorf("couldn't get objs for path: %s, error: %w", textFilePathCurrent, err)
100+
return nil, fmt.Errorf("couldn't get objs for path: %s, error: %w", binFilePathCurrent, err)
101101
}
102102

103103
matchingMap := createMapFromLineObjects(lineObjsBaseline)

engine/tracker/helpers.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,22 +147,22 @@ func (cr *FunctionChangeResult) writeImpactAssessment(report *strings.Builder) {
147147
report.WriteString("\n")
148148
}
149149

150-
func getTextFilesLocations(selections *Selections) (string, string) {
151-
fileName := fmt.Sprintf("%s_%s.txt", selections.BenchmarkName, selections.ProfileType)
152-
textFilePath1BaseLine := filepath.Join(internal.MainDirOutput, selections.BaselineTag, internal.ProfileTextDir, selections.BenchmarkName, fileName)
153-
textFilePath2Current := filepath.Join(internal.MainDirOutput, selections.CurrentTag, internal.ProfileTextDir, selections.BenchmarkName, fileName)
150+
func getBinFilesLocations(selections *Selections) (string, string) {
151+
fileName := fmt.Sprintf("%s_%s.out", selections.BenchmarkName, selections.ProfileType)
152+
binFilePath1BaseLine := filepath.Join(internal.MainDirOutput, selections.Baseline, internal.ProfileBinDir, selections.BenchmarkName, fileName)
153+
binFilePath2Current := filepath.Join(internal.MainDirOutput, selections.Current, internal.ProfileBinDir, selections.BenchmarkName, fileName)
154154

155-
return textFilePath1BaseLine, textFilePath2Current
155+
return binFilePath1BaseLine, binFilePath2Current
156156
}
157157

158158
func chooseFileLocations(selections *Selections) (string, string) {
159159
var textFilePathBaseLine, textFilePathCurrent string
160160

161161
if selections.IsManual {
162-
textFilePathBaseLine = selections.BaselineTag
163-
textFilePathCurrent = selections.CurrentTag
162+
textFilePathBaseLine = selections.Baseline
163+
textFilePathCurrent = selections.Current
164164
} else {
165-
textFilePathBaseLine, textFilePathCurrent = getTextFilesLocations(selections)
165+
textFilePathBaseLine, textFilePathCurrent = getBinFilesLocations(selections)
166166
}
167167

168168
return textFilePathBaseLine, textFilePathCurrent
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)