Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for customized "no data found" message for any table #156

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion internal/report/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,11 @@ func createHtmlReport(allTableValues []TableValues, targetName string) (out []by
sb.WriteString(fmt.Sprintf("<h2 id=\"%[1]s\">%[1]s</h2>\n", html.EscapeString(tableValues.Name)))
// if there's no data in the table, print a message and continue
if len(tableValues.Fields) == 0 || len(tableValues.Fields[0].Values) == 0 {
sb.WriteString("<p>" + noDataFound + "</p>\n")
msg := noDataFound
if tableValues.NoDataFound != "" {
msg = tableValues.NoDataFound
}
sb.WriteString("<p>" + msg + "</p>\n")
continue
}
// render the tables
Expand Down
6 changes: 5 additions & 1 deletion internal/report/html_flamegraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ func renderFlameGraph(header string, tableValues TableValues, field string) (out
folded := tableValues.Fields[fieldIdx].Values[0]
if folded == "" {
out += `<div class="fgheader clearfix"><h3 class="text-muted">` + header + `</h3></div>`
out += noDataFound
msg := noDataFound
if tableValues.NoDataFound != "" {
msg = tableValues.NoDataFound
}
out += msg
return
}
jsonStacks, err := convertFoldedToJSON(folded)
Expand Down
18 changes: 15 additions & 3 deletions internal/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ func createTextReport(allTableValues []TableValues) (out []byte, err error) {
}
sb.WriteString("\n")
if len(tableValues.Fields) == 0 || len(tableValues.Fields[0].Values) == 0 {
sb.WriteString(noDataFound + "\n\n")
msg := noDataFound
if tableValues.NoDataFound != "" {
msg = tableValues.NoDataFound
}
sb.WriteString(msg + "\n\n")
continue
}
// custom renderer defined?
Expand Down Expand Up @@ -238,7 +242,11 @@ func renderXlsxTable(tableValues TableValues, f *excelize.File, sheetName string
_ = f.SetCellStyle(sheetName, cellName(col, *row), cellName(col, *row), tableNameStyle)
*row++
if len(tableValues.Fields) == 0 || len(tableValues.Fields[0].Values) == 0 {
_ = f.SetCellValue(sheetName, cellName(col, *row), noDataFound)
msg := noDataFound
if tableValues.NoDataFound != "" {
msg = tableValues.NoDataFound
}
_ = f.SetCellValue(sheetName, cellName(col, *row), msg)
*row += 2
return
}
Expand Down Expand Up @@ -308,7 +316,11 @@ func renderXlsxTableMultiTarget(tableIdx int, allTargetsTableValues [][]TableVal

// if no data found, print a message and skip to the next target
if len(allTargetsTableValues[targetIdx][tableIdx].Fields) == 0 || len(allTargetsTableValues[targetIdx][tableIdx].Fields[0].Values) == 0 {
_ = f.SetCellValue(sheetName, cellName(col, *row), noDataFound)
msg := noDataFound
if allTargetsTableValues[targetIdx][tableIdx].NoDataFound != "" {
msg = allTargetsTableValues[targetIdx][tableIdx].NoDataFound
}
_ = f.SetCellValue(sheetName, cellName(col, *row), msg)
*row += 2
continue
}
Expand Down
11 changes: 7 additions & 4 deletions internal/report/table_defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ type TableDefinition struct {
Name string
ScriptNames []string
// Fields function is called to retrieve field values from the script outputs
FieldsFunc FieldsRetriever
MenuLabel string // add to tables that will be displayed in the menu
HasRows bool // table is meant to be displayed in row form, i.e., a field may have multiple values
FieldsFunc FieldsRetriever
MenuLabel string // add to tables that will be displayed in the menu
HasRows bool // table is meant to be displayed in row form, i.e., a field may have multiple values
NoDataFound string // message to display when no data is found
// render functions are used to override the default rendering behavior
HTMLTableRendererFunc HTMLTableRenderer
HTMLMultiTargetTableRendererFunc HTMLMultiTargetTableRenderer
Expand Down Expand Up @@ -523,6 +524,7 @@ var tableDefinitions = map[string]TableDefinition{
ScriptNames: []string{
script.MemoryBandwidthAndLatencyScriptName,
},
NoDataFound: "No memory latency data found. Please see the GitHub repository README for instructions on how to install Intel Memory Latency Checker (mlc).",
FieldsFunc: memoryLatencyTableValues,
HTMLTableRendererFunc: memoryLatencyTableHtmlRenderer,
HTMLMultiTargetTableRendererFunc: memoryLatencyTableMultiTargetHtmlRenderer},
Expand All @@ -533,7 +535,8 @@ var tableDefinitions = map[string]TableDefinition{
ScriptNames: []string{
script.NumaBandwidthScriptName,
},
FieldsFunc: numaBandwidthTableValues},
NoDataFound: "No NUMA bandwidth data found. Please see the GitHub repository README for instructions on how to install Intel Memory Latency Checker (mlc).",
FieldsFunc: numaBandwidthTableValues},
//
// telemetry tables
//
Expand Down
Loading