From 6d369858369352ca788c70f54b0697de7bba4ce8 Mon Sep 17 00:00:00 2001 From: "Harper, Jason M" Date: Fri, 21 Nov 2025 11:07:05 -0800 Subject: [PATCH 1/2] eliminate duplicate uncore events across groups as this causes perf to misreport event values Signed-off-by: Harper, Jason M --- cmd/metrics/loader_perfmon_group_uncore.go | 51 +++++++++++++++++----- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/cmd/metrics/loader_perfmon_group_uncore.go b/cmd/metrics/loader_perfmon_group_uncore.go index 38451ec5..1996befe 100644 --- a/cmd/metrics/loader_perfmon_group_uncore.go +++ b/cmd/metrics/loader_perfmon_group_uncore.go @@ -201,20 +201,49 @@ func (group UncoreGroup) StringForPerf() (string, error) { } func MergeUncoreGroups(uncoreGroups []UncoreGroup) ([]UncoreGroup, error) { - i := 0 - for i < len(uncoreGroups) { // this style of for loop is used to allow for removal of elements - j := i + 1 - for j < len(uncoreGroups) { // len(coreGroups) is recalculated on each iteration - tmpGroup := uncoreGroups[i].Copy() // Copy the group to avoid modifying the original - if err := tmpGroup.Merge(uncoreGroups[j]); err == nil { - uncoreGroups[i] = tmpGroup // Update the group at index i with the merged group - // remove the group at index j - uncoreGroups = append(uncoreGroups[:j], uncoreGroups[j+1:]...) + // First, eliminate duplicate events across groups (only needs to be done once) + seenEvents := make(map[string]int) // map of event name to group index where it first appears + for i := range uncoreGroups { + for j := range uncoreGroups[i].GeneralPurposeCounters { + event := uncoreGroups[i].GeneralPurposeCounters[j] + if event.IsEmpty() { + continue + } + + if firstGroupIdx, exists := seenEvents[event.EventName]; exists { + // Event already exists in another group, remove from current group + slog.Debug("removing duplicate uncore event from group", + slog.String("event", event.EventName), + slog.Int("firstGroup", firstGroupIdx), + slog.Int("currentGroup", i)) + uncoreGroups[i].GeneralPurposeCounters[j] = UncoreEvent{} } else { - j++ // Cannot merge these groups, try the next pair + // First time seeing this event, record it + seenEvents[event.EventName] = i } } - i++ + } + + // Then, keep merging until no more merges are possible + merged := true + for merged { + merged = false + i := 0 + for i < len(uncoreGroups) { + j := i + 1 + for j < len(uncoreGroups) { + tmpGroup := uncoreGroups[i].Copy() + if err := tmpGroup.Merge(uncoreGroups[j]); err == nil { + uncoreGroups[i] = tmpGroup + // remove the group at index j + uncoreGroups = append(uncoreGroups[:j], uncoreGroups[j+1:]...) + merged = true // mark that we made a change + } else { + j++ + } + } + i++ + } } return uncoreGroups, nil } From 3d546dc794ff95a769bebc59c784f25b1fdd5f21 Mon Sep 17 00:00:00 2001 From: "Harper, Jason M" Date: Fri, 21 Nov 2025 15:39:51 -0800 Subject: [PATCH 2/2] bump version to 3.12.1 Signed-off-by: Harper, Jason M --- version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.txt b/version.txt index 92536a9e..171a6a93 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -3.12.0 +3.12.1