Skip to content

Commit

Permalink
match l3 cache when num instnaces not in lscpu output
Browse files Browse the repository at this point in the history
  • Loading branch information
harp-intel committed Dec 10, 2024
1 parent 02552bb commit bcc0059
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions internal/report/table_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,25 +434,34 @@ func prefetchersFromOutput(outputs map[string]script.ScriptOutput) string {
// get L3 per instance in MB from lscpu
// known lscpu output formats for L3 cache:
//
// L3 cache: 576 MiB (2 instances)
// L3 cache: 576 MiB (2 instances)
// L3 cache: 210 MiB
func getL3LscpuMB(outputs map[string]script.ScriptOutput) (val float64, err error) {
var instances int
l3Lscpu := valFromRegexSubmatch(outputs[script.LscpuScriptName].Stdout, `^L3 cache.*:\s*(.+?)$`)
re := regexp.MustCompile(`(\d+\.?\d*)\s*(\w+)\s+\((\d+) instance[s]*\)`) // match known formats
match := re.FindStringSubmatch(l3Lscpu)
if len(match) == 0 {
err = fmt.Errorf("unknown L3 format in lscpu: %s", l3Lscpu)
return
if match != nil {
instances, err = strconv.Atoi(match[3])
if err != nil {
err = fmt.Errorf("failed to parse L3 instances from lscpu: %s, %v", l3Lscpu, err)
return
}
} else {
// try regex without the instance count
re = regexp.MustCompile(`(\d+\.?\d*)\s*(\w+)`)
match = re.FindStringSubmatch(l3Lscpu)
if match == nil {
err = fmt.Errorf("unknown L3 format in lscpu: %s", l3Lscpu)
return
}
instances = 1
}
l3SizeNoUnit, err := strconv.ParseFloat(match[1], 64)
if err != nil {
err = fmt.Errorf("failed to parse L3 size from lscpu: %s, %v", l3Lscpu, err)
return
}
instances, err := strconv.Atoi(match[3])
if err != nil {
err = fmt.Errorf("failed to parse L3 instances from lscpu: %s, %v", l3Lscpu, err)
return
}
units := match[2]
if strings.ToLower(units[:1]) == "m" {
val = l3SizeNoUnit / float64(instances)
Expand Down

0 comments on commit bcc0059

Please sign in to comment.