Skip to content

Commit 4282e57

Browse files
authored
fix bug in frequency string parsing (#325)
* fix bug in frequency string parsing Signed-off-by: Harper, Jason M <[email protected]> * err msg Signed-off-by: Harper, Jason M <[email protected]> --------- Signed-off-by: Harper, Jason M <[email protected]>
1 parent 69aadee commit 4282e57

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

internal/report/table_helpers.go

+28-5
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,34 @@ func baseFrequencyFromOutput(outputs map[string]script.ScriptOutput) string {
195195
return ""
196196
}
197197

198-
func convertMsrToDecimals(msr string) (decVals []int, err error) {
198+
// convertHexStringToDecimals converts a hex string to a slice of decimal values.
199+
//
200+
// formats:
201+
// - "0x1212121212121212"
202+
// - "1212121212121212"
203+
// we need two hex characters for each decimal value
204+
// some input strings may need to be padded with a leading zero
205+
// always return a slice of 8 decimal values
206+
func convertHexStringToDecimals(hexStr string) (decVals []int, err error) {
207+
hexStr = strings.TrimPrefix(hexStr, "0x")
208+
hexStr = strings.TrimSpace(hexStr)
209+
// no more than 16 characters
210+
if len(hexStr) > 16 {
211+
err = fmt.Errorf("hex string too long: %s", hexStr)
212+
return
213+
}
214+
// pad up to 16 characters
215+
for range 16 - len(hexStr) {
216+
hexStr = "0" + hexStr
217+
}
199218
re := regexp.MustCompile(`[0-9a-fA-F][0-9a-fA-F]`)
200-
hexVals := re.FindAll([]byte(msr), -1)
219+
hexVals := re.FindAll([]byte(hexStr), -1)
201220
if hexVals == nil {
202-
err = fmt.Errorf("no hex values found in msr")
221+
err = fmt.Errorf("no hex values found in hex string")
222+
return
223+
}
224+
if len(hexVals) != 8 {
225+
err = fmt.Errorf("expected 8 hex values, got %d", len(hexVals))
203226
return
204227
}
205228
decVals = make([]int, len(hexVals))
@@ -251,7 +274,7 @@ func getSpecFrequencyBuckets(outputs map[string]script.ScriptOutput) ([][]string
251274
return nil, fmt.Errorf("unexpected output format")
252275
}
253276
// get list of buckets
254-
bucketCoreCounts, _ := convertMsrToDecimals(values[0])
277+
bucketCoreCounts, _ := convertHexStringToDecimals(values[0])
255278
// create buckets
256279
var totalCoreBuckets []string // only for multi-die architectures
257280
var dieCoreBuckets []string
@@ -286,7 +309,7 @@ func getSpecFrequencyBuckets(outputs map[string]script.ScriptOutput) ([][]string
286309
var freqs []int
287310
if isaHex != "0" {
288311
var err error
289-
freqs, err = convertMsrToDecimals(isaHex)
312+
freqs, err = convertHexStringToDecimals(isaHex)
290313
if err != nil {
291314
return nil, err
292315
}

version.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.6.0
1+
3.6.1

0 commit comments

Comments
 (0)