Skip to content

Commit 5274276

Browse files
authored
fix: pad core frequencies to length of frequency buckets (#548)
* fix: pad core frequencies to length of frequency buckets Signed-off-by: Harper, Jason M <[email protected]> * fix: add index range check for isa frequencies in getSpecFrequencyBuckets Signed-off-by: Harper, Jason M <[email protected]> --------- Signed-off-by: Harper, Jason M <[email protected]>
1 parent a45b256 commit 5274276

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

internal/report/table_helpers.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,18 @@ func getBucketSizesFromHex(hex string) ([]int, error) {
217217
return bucketSizes, nil
218218
}
219219

220+
// padFrequencies adds items to the frequencies slice until it reaches the desired length.
221+
// The value of the added items is the same as the last item in the original slice.
222+
func padFrequencies(freqs []int, desiredLength int) ([]int, error) {
223+
if len(freqs) == 0 {
224+
return nil, fmt.Errorf("cannot pad empty frequencies slice")
225+
}
226+
for len(freqs) < desiredLength {
227+
freqs = append(freqs, freqs[len(freqs)-1])
228+
}
229+
return freqs, nil
230+
}
231+
220232
// getSpecFrequencyBuckets
221233
// returns slice of rows
222234
// first row is header
@@ -304,6 +316,12 @@ func getSpecFrequencyBuckets(outputs map[string]script.ScriptOutput) ([][]string
304316
freqs[i] = 0
305317
}
306318
}
319+
if len(freqs) != len(bucketCoreCounts) {
320+
freqs, err = padFrequencies(freqs, len(bucketCoreCounts))
321+
if err != nil {
322+
return nil, fmt.Errorf("failed to pad frequencies: %w", err)
323+
}
324+
}
307325
for _, freq := range freqs {
308326
// convert freq to GHz
309327
freqf := float64(freq) / 10.0
@@ -339,6 +357,9 @@ func getSpecFrequencyBuckets(outputs map[string]script.ScriptOutput) ([][]string
339357
if isaFreqs[0] == "0.0" {
340358
continue
341359
} else {
360+
if i >= len(isaFreqs) {
361+
return nil, fmt.Errorf("index out of range for isa frequencies")
362+
}
342363
row = append(row, isaFreqs[i])
343364
}
344365
}

0 commit comments

Comments
 (0)