Skip to content

Commit a4a3b4e

Browse files
committed
fix: pad core frequencies to length of frequency buckets
Signed-off-by: Harper, Jason M <[email protected]>
1 parent a220a3e commit a4a3b4e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

internal/report/table_helpers.go

Lines changed: 18 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

0 commit comments

Comments
 (0)