Skip to content
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
44 changes: 40 additions & 4 deletions cmd/metrics/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 1 addition & 8 deletions cmd/metrics/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"os"
"path/filepath"
"perfspect/internal/cpus"
"regexp"
"slices"
"strconv"
texttemplate "text/template" // nosemgrep
Expand Down Expand Up @@ -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)
Expand Down