Skip to content

Commit 1dd8a24

Browse files
authored
fix turbostat output header identification (#390)
* fix turbostat output header identification Signed-off-by: Harper, Jason M <[email protected]> * refactor parseTurbostatOutput to simplify header line identification Signed-off-by: Harper, Jason M <[email protected]> --------- Signed-off-by: Harper, Jason M <[email protected]>
1 parent 92e4586 commit 1dd8a24

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

internal/report/table_helpers_turbostat.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package report
33
import (
44
"fmt"
55
"log/slog"
6+
"slices"
67
"strconv"
78
"strings"
89
"time"
@@ -53,9 +54,9 @@ func parseTurbostatOutput(output string) ([]map[string]string, error) {
5354
// parse the fields in the line
5455
fields := strings.Fields(line)
5556
// if this is a header line
56-
if len(fields) > 1 && (fields[0] == "CPU" || fields[0] == "Package" || fields[0] == "Core") {
57+
if len(fields) >= 1 && slices.Contains([]string{"package", "die", "node", "core", "cpu"}, strings.ToLower(fields[0])) {
5758
if len(headers) == 0 {
58-
headers = fields
59+
headers = fields // first line with a column name is the header
5960
} else {
6061
// bump the timestamp to the next interval
6162
if timeParsed && interval > 0 {
@@ -67,13 +68,12 @@ func parseTurbostatOutput(output string) ([]map[string]string, error) {
6768
if len(headers) == 0 {
6869
continue // skip data lines before first header
6970
}
70-
values := strings.Fields(line)
71-
if len(values) != len(headers) {
71+
if len(fields) != len(headers) {
7272
continue // skip core lines
7373
}
74-
row := make(map[string]string)
74+
row := make(map[string]string, len(headers))
7575
for i, h := range headers {
76-
row[h] = values[i]
76+
row[h] = fields[i]
7777
}
7878
// Add timestamp to row
7979
if timeParsed && interval > 0 {

0 commit comments

Comments
 (0)