diff --git a/cmd/metrics/metadata.go b/cmd/metrics/metadata.go index 51d6c6f1..6ee13d3a 100644 --- a/cmd/metrics/metadata.go +++ b/cmd/metrics/metadata.go @@ -401,10 +401,46 @@ func getMetadataScripts(noRoot bool, noSystemSummary bool, numGPCounters int) (m Superuser: !noRoot, }, { - Name: "perf supported events", - ScriptTemplate: "perf list", - Superuser: !noRoot, - Depends: []string{"perf"}, + Name: "perf supported events", + ScriptTemplate: `# Parse perf list JSON output to extract Hardware events and cstate/power events +perf list --json 2>/dev/null | awk ' +BEGIN { + in_hardware_event = 0 + event_name = "" +} + +# Capture EventName +/"EventName":/ { + # Extract the value between quotes after "EventName": + line = $0 + sub(/.*"EventName": "/, "", line) + sub(/".*/, "", line) + event_name = line +} + +# Check if EventType is Hardware event +/"EventType": "Hardware event"/ { + in_hardware_event = 1 +} + +# At end of object (closing brace), check if we should print +/^}/ { + if (in_hardware_event || + event_name ~ /^cstate_core\// || + event_name ~ /^cstate_pkg\// || + event_name ~ /^power\//) { + if (event_name != "") { + print event_name + } + } + # Reset for next object + in_hardware_event = 0 + event_name = "" +} +' # end of awk +`, + Superuser: !noRoot, + Depends: []string{"perf"}, }, { Name: "list uncore devices", diff --git a/cmd/metrics/summary.go b/cmd/metrics/summary.go index 2b27b867..c08a231c 100644 --- a/cmd/metrics/summary.go +++ b/cmd/metrics/summary.go @@ -16,7 +16,6 @@ import ( "os" "path/filepath" "perfspect/internal/cpus" - "regexp" "slices" "strconv" texttemplate "text/template" // nosemgrep @@ -628,13 +627,7 @@ func (mg *MetricGroup) loadHTMLTemplateValues(metadata Metadata, metricDefinitio if err != nil { return } - // remove PerfSupportedEvents from json - re := regexp.MustCompile(`"PerfSupportedEvents":".*?",`) - jsonMetadataPurged := re.ReplaceAll(jsonMetadata, []byte("")) - // remove SystemSummaryFields from json - re = regexp.MustCompile(`,"SystemSummaryFields":\[\[.*?\]\]`) - jsonMetadataPurged = re.ReplaceAll(jsonMetadataPurged, []byte("")) - templateVals["METADATA"] = string(jsonMetadataPurged) + templateVals["METADATA"] = string(jsonMetadata) // system info tab jsonSystemInfo, err := json.Marshal(metadata.SystemSummaryFields)