Skip to content

Commit ebab930

Browse files
committed
add support for customized "no data found" message for any table
1 parent 0f0d72b commit ebab930

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

internal/report/html.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,11 @@ func createHtmlReport(allTableValues []TableValues, targetName string) (out []by
200200
sb.WriteString(fmt.Sprintf("<h2 id=\"%[1]s\">%[1]s</h2>\n", html.EscapeString(tableValues.Name)))
201201
// if there's no data in the table, print a message and continue
202202
if len(tableValues.Fields) == 0 || len(tableValues.Fields[0].Values) == 0 {
203-
sb.WriteString("<p>" + noDataFound + "</p>\n")
203+
msg := noDataFound
204+
if tableValues.NoDataFound != "" {
205+
msg = tableValues.NoDataFound
206+
}
207+
sb.WriteString("<p>" + msg + "</p>\n")
204208
continue
205209
}
206210
// render the tables

internal/report/html_flamegraph.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,11 @@ func renderFlameGraph(header string, tableValues TableValues, field string) (out
160160
folded := tableValues.Fields[fieldIdx].Values[0]
161161
if folded == "" {
162162
out += `<div class="fgheader clearfix"><h3 class="text-muted">` + header + `</h3></div>`
163-
out += noDataFound
163+
msg := noDataFound
164+
if tableValues.NoDataFound != "" {
165+
msg = tableValues.NoDataFound
166+
}
167+
out += msg
164168
return
165169
}
166170
jsonStacks, err := convertFoldedToJSON(folded)

internal/report/report.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ func createTextReport(allTableValues []TableValues) (out []byte, err error) {
104104
}
105105
sb.WriteString("\n")
106106
if len(tableValues.Fields) == 0 || len(tableValues.Fields[0].Values) == 0 {
107-
sb.WriteString(noDataFound + "\n\n")
107+
msg := noDataFound
108+
if tableValues.NoDataFound != "" {
109+
msg = tableValues.NoDataFound
110+
}
111+
sb.WriteString(msg + "\n\n")
108112
continue
109113
}
110114
// custom renderer defined?
@@ -238,7 +242,11 @@ func renderXlsxTable(tableValues TableValues, f *excelize.File, sheetName string
238242
_ = f.SetCellStyle(sheetName, cellName(col, *row), cellName(col, *row), tableNameStyle)
239243
*row++
240244
if len(tableValues.Fields) == 0 || len(tableValues.Fields[0].Values) == 0 {
241-
_ = f.SetCellValue(sheetName, cellName(col, *row), noDataFound)
245+
msg := noDataFound
246+
if tableValues.NoDataFound != "" {
247+
msg = tableValues.NoDataFound
248+
}
249+
_ = f.SetCellValue(sheetName, cellName(col, *row), msg)
242250
*row += 2
243251
return
244252
}
@@ -308,7 +316,11 @@ func renderXlsxTableMultiTarget(tableIdx int, allTargetsTableValues [][]TableVal
308316

309317
// if no data found, print a message and skip to the next target
310318
if len(allTargetsTableValues[targetIdx][tableIdx].Fields) == 0 || len(allTargetsTableValues[targetIdx][tableIdx].Fields[0].Values) == 0 {
311-
_ = f.SetCellValue(sheetName, cellName(col, *row), noDataFound)
319+
msg := noDataFound
320+
if allTargetsTableValues[targetIdx][tableIdx].NoDataFound != "" {
321+
msg = allTargetsTableValues[targetIdx][tableIdx].NoDataFound
322+
}
323+
_ = f.SetCellValue(sheetName, cellName(col, *row), msg)
312324
*row += 2
313325
continue
314326
}

internal/report/table_defs.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ type TableDefinition struct {
3535
Name string
3636
ScriptNames []string
3737
// Fields function is called to retrieve field values from the script outputs
38-
FieldsFunc FieldsRetriever
39-
MenuLabel string // add to tables that will be displayed in the menu
40-
HasRows bool // table is meant to be displayed in row form, i.e., a field may have multiple values
38+
FieldsFunc FieldsRetriever
39+
MenuLabel string // add to tables that will be displayed in the menu
40+
HasRows bool // table is meant to be displayed in row form, i.e., a field may have multiple values
41+
NoDataFound string // message to display when no data is found
4142
// render functions are used to override the default rendering behavior
4243
HTMLTableRendererFunc HTMLTableRenderer
4344
HTMLMultiTargetTableRendererFunc HTMLMultiTargetTableRenderer
@@ -523,6 +524,7 @@ var tableDefinitions = map[string]TableDefinition{
523524
ScriptNames: []string{
524525
script.MemoryBandwidthAndLatencyScriptName,
525526
},
527+
NoDataFound: "No memory latency data found. Please see the GitHub repository README for instructions on how to install Intel Memory Latency Checker (mlc).",
526528
FieldsFunc: memoryLatencyTableValues,
527529
HTMLTableRendererFunc: memoryLatencyTableHtmlRenderer,
528530
HTMLMultiTargetTableRendererFunc: memoryLatencyTableMultiTargetHtmlRenderer},
@@ -533,7 +535,8 @@ var tableDefinitions = map[string]TableDefinition{
533535
ScriptNames: []string{
534536
script.NumaBandwidthScriptName,
535537
},
536-
FieldsFunc: numaBandwidthTableValues},
538+
NoDataFound: "No NUMA bandwidth data found. Please see the GitHub repository README for instructions on how to install Intel Memory Latency Checker (mlc).",
539+
FieldsFunc: numaBandwidthTableValues},
537540
//
538541
// telemetry tables
539542
//

0 commit comments

Comments
 (0)