Skip to content

Commit 431b7f1

Browse files
committed
refactor and move frequency functions into new source file, plus more
Signed-off-by: Harper, Jason M <[email protected]>
1 parent 22bb007 commit 431b7f1

8 files changed

+1077
-968
lines changed

internal/report/table_helpers.go

Lines changed: 1 addition & 567 deletions
Large diffs are not rendered by default.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package report
2+
3+
import (
4+
"fmt"
5+
"perfspect/internal/script"
6+
"regexp"
7+
"strings"
8+
)
9+
10+
// Copyright (C) 2021-2025 Intel Corporation
11+
// SPDX-License-Identifier: BSD-3-Clause
12+
13+
func acceleratorNames() []string {
14+
var names []string
15+
for _, accel := range acceleratorDefinitions {
16+
names = append(names, accel.Name)
17+
}
18+
return names
19+
}
20+
21+
func acceleratorCountsFromOutput(outputs map[string]script.ScriptOutput) []string {
22+
var counts []string
23+
lshw := outputs[script.LshwScriptName].Stdout
24+
for _, accel := range acceleratorDefinitions {
25+
regex := fmt.Sprintf("%s:%s", accel.MfgID, accel.DevID)
26+
re := regexp.MustCompile(regex)
27+
count := len(re.FindAllString(lshw, -1))
28+
counts = append(counts, fmt.Sprintf("%d", count))
29+
}
30+
return counts
31+
}
32+
33+
func acceleratorWorkQueuesFromOutput(outputs map[string]script.ScriptOutput) []string {
34+
var queues []string
35+
for _, accel := range acceleratorDefinitions {
36+
if accel.Name == "IAA" || accel.Name == "DSA" {
37+
var scriptName string
38+
if accel.Name == "IAA" {
39+
scriptName = script.IaaDevicesScriptName
40+
} else {
41+
scriptName = script.DsaDevicesScriptName
42+
}
43+
devices := outputs[scriptName].Stdout
44+
lines := strings.Split(devices, "\n")
45+
// get non-empty lines
46+
var nonEmptyLines []string
47+
for _, line := range lines {
48+
if strings.TrimSpace(line) != "" {
49+
nonEmptyLines = append(nonEmptyLines, line)
50+
}
51+
}
52+
if len(nonEmptyLines) == 0 {
53+
queues = append(queues, "None")
54+
} else {
55+
queues = append(queues, strings.Join(nonEmptyLines, ", "))
56+
}
57+
} else {
58+
queues = append(queues, "N/A")
59+
}
60+
}
61+
return queues
62+
}
63+
64+
func acceleratorFullNamesFromYaml() []string {
65+
var fullNames []string
66+
for _, accel := range acceleratorDefinitions {
67+
fullNames = append(fullNames, accel.FullName)
68+
}
69+
return fullNames
70+
}
71+
72+
func acceleratorDescriptionsFromYaml() []string {
73+
var descriptions []string
74+
for _, accel := range acceleratorDefinitions {
75+
descriptions = append(descriptions, accel.Description)
76+
}
77+
return descriptions
78+
}
79+
80+
func acceleratorSummaryFromOutput(outputs map[string]script.ScriptOutput) string {
81+
var summary []string
82+
accelerators := acceleratorNames()
83+
counts := acceleratorCountsFromOutput(outputs)
84+
for i, name := range accelerators {
85+
if strings.Contains(name, "chipset") { // skip "QAT (on chipset)" in this table
86+
continue
87+
} else if strings.Contains(name, "CPU") { // rename "QAT (on CPU) to simply "QAT"
88+
name = "QAT"
89+
}
90+
summary = append(summary, fmt.Sprintf("%s %s [0]", name, counts[i]))
91+
}
92+
return strings.Join(summary, ", ")
93+
}

0 commit comments

Comments
 (0)